three.core.js 737 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083
  1. /**
  2. * @license
  3. * Copyright 2010-2025 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '173dev';
  7. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  8. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  9. const CullFaceNone = 0;
  10. const CullFaceBack = 1;
  11. const CullFaceFront = 2;
  12. const CullFaceFrontBack = 3;
  13. const BasicShadowMap = 0;
  14. const PCFShadowMap = 1;
  15. const PCFSoftShadowMap = 2;
  16. const VSMShadowMap = 3;
  17. const FrontSide = 0;
  18. const BackSide = 1;
  19. const DoubleSide = 2;
  20. const NoBlending = 0;
  21. const NormalBlending = 1;
  22. const AdditiveBlending = 2;
  23. const SubtractiveBlending = 3;
  24. const MultiplyBlending = 4;
  25. const CustomBlending = 5;
  26. const AddEquation = 100;
  27. const SubtractEquation = 101;
  28. const ReverseSubtractEquation = 102;
  29. const MinEquation = 103;
  30. const MaxEquation = 104;
  31. const ZeroFactor = 200;
  32. const OneFactor = 201;
  33. const SrcColorFactor = 202;
  34. const OneMinusSrcColorFactor = 203;
  35. const SrcAlphaFactor = 204;
  36. const OneMinusSrcAlphaFactor = 205;
  37. const DstAlphaFactor = 206;
  38. const OneMinusDstAlphaFactor = 207;
  39. const DstColorFactor = 208;
  40. const OneMinusDstColorFactor = 209;
  41. const SrcAlphaSaturateFactor = 210;
  42. const ConstantColorFactor = 211;
  43. const OneMinusConstantColorFactor = 212;
  44. const ConstantAlphaFactor = 213;
  45. const OneMinusConstantAlphaFactor = 214;
  46. const NeverDepth = 0;
  47. const AlwaysDepth = 1;
  48. const LessDepth = 2;
  49. const LessEqualDepth = 3;
  50. const EqualDepth = 4;
  51. const GreaterEqualDepth = 5;
  52. const GreaterDepth = 6;
  53. const NotEqualDepth = 7;
  54. const MultiplyOperation = 0;
  55. const MixOperation = 1;
  56. const AddOperation = 2;
  57. const NoToneMapping = 0;
  58. const LinearToneMapping = 1;
  59. const ReinhardToneMapping = 2;
  60. const CineonToneMapping = 3;
  61. const ACESFilmicToneMapping = 4;
  62. const CustomToneMapping = 5;
  63. const AgXToneMapping = 6;
  64. const NeutralToneMapping = 7;
  65. const AttachedBindMode = 'attached';
  66. const DetachedBindMode = 'detached';
  67. const UVMapping = 300;
  68. const CubeReflectionMapping = 301;
  69. const CubeRefractionMapping = 302;
  70. const EquirectangularReflectionMapping = 303;
  71. const EquirectangularRefractionMapping = 304;
  72. const CubeUVReflectionMapping = 306;
  73. const RepeatWrapping = 1000;
  74. const ClampToEdgeWrapping = 1001;
  75. const MirroredRepeatWrapping = 1002;
  76. const NearestFilter = 1003;
  77. const NearestMipmapNearestFilter = 1004;
  78. const NearestMipMapNearestFilter = 1004;
  79. const NearestMipmapLinearFilter = 1005;
  80. const NearestMipMapLinearFilter = 1005;
  81. const LinearFilter = 1006;
  82. const LinearMipmapNearestFilter = 1007;
  83. const LinearMipMapNearestFilter = 1007;
  84. const LinearMipmapLinearFilter = 1008;
  85. const LinearMipMapLinearFilter = 1008;
  86. const UnsignedByteType = 1009;
  87. const ByteType = 1010;
  88. const ShortType = 1011;
  89. const UnsignedShortType = 1012;
  90. const IntType = 1013;
  91. const UnsignedIntType = 1014;
  92. const FloatType = 1015;
  93. const HalfFloatType = 1016;
  94. const UnsignedShort4444Type = 1017;
  95. const UnsignedShort5551Type = 1018;
  96. const UnsignedInt248Type = 1020;
  97. const UnsignedInt5999Type = 35902;
  98. const AlphaFormat = 1021;
  99. const RGBFormat = 1022;
  100. const RGBAFormat = 1023;
  101. const LuminanceFormat = 1024;
  102. const LuminanceAlphaFormat = 1025;
  103. const DepthFormat = 1026;
  104. const DepthStencilFormat = 1027;
  105. const RedFormat = 1028;
  106. const RedIntegerFormat = 1029;
  107. const RGFormat = 1030;
  108. const RGIntegerFormat = 1031;
  109. const RGBIntegerFormat = 1032;
  110. const RGBAIntegerFormat = 1033;
  111. const RGB_S3TC_DXT1_Format = 33776;
  112. const RGBA_S3TC_DXT1_Format = 33777;
  113. const RGBA_S3TC_DXT3_Format = 33778;
  114. const RGBA_S3TC_DXT5_Format = 33779;
  115. const RGB_PVRTC_4BPPV1_Format = 35840;
  116. const RGB_PVRTC_2BPPV1_Format = 35841;
  117. const RGBA_PVRTC_4BPPV1_Format = 35842;
  118. const RGBA_PVRTC_2BPPV1_Format = 35843;
  119. const RGB_ETC1_Format = 36196;
  120. const RGB_ETC2_Format = 37492;
  121. const RGBA_ETC2_EAC_Format = 37496;
  122. const RGBA_ASTC_4x4_Format = 37808;
  123. const RGBA_ASTC_5x4_Format = 37809;
  124. const RGBA_ASTC_5x5_Format = 37810;
  125. const RGBA_ASTC_6x5_Format = 37811;
  126. const RGBA_ASTC_6x6_Format = 37812;
  127. const RGBA_ASTC_8x5_Format = 37813;
  128. const RGBA_ASTC_8x6_Format = 37814;
  129. const RGBA_ASTC_8x8_Format = 37815;
  130. const RGBA_ASTC_10x5_Format = 37816;
  131. const RGBA_ASTC_10x6_Format = 37817;
  132. const RGBA_ASTC_10x8_Format = 37818;
  133. const RGBA_ASTC_10x10_Format = 37819;
  134. const RGBA_ASTC_12x10_Format = 37820;
  135. const RGBA_ASTC_12x12_Format = 37821;
  136. const RGBA_BPTC_Format = 36492;
  137. const RGB_BPTC_SIGNED_Format = 36494;
  138. const RGB_BPTC_UNSIGNED_Format = 36495;
  139. const RED_RGTC1_Format = 36283;
  140. const SIGNED_RED_RGTC1_Format = 36284;
  141. const RED_GREEN_RGTC2_Format = 36285;
  142. const SIGNED_RED_GREEN_RGTC2_Format = 36286;
  143. const LoopOnce = 2200;
  144. const LoopRepeat = 2201;
  145. const LoopPingPong = 2202;
  146. const InterpolateDiscrete = 2300;
  147. const InterpolateLinear = 2301;
  148. const InterpolateSmooth = 2302;
  149. const ZeroCurvatureEnding = 2400;
  150. const ZeroSlopeEnding = 2401;
  151. const WrapAroundEnding = 2402;
  152. const NormalAnimationBlendMode = 2500;
  153. const AdditiveAnimationBlendMode = 2501;
  154. const TrianglesDrawMode = 0;
  155. const TriangleStripDrawMode = 1;
  156. const TriangleFanDrawMode = 2;
  157. const BasicDepthPacking = 3200;
  158. const RGBADepthPacking = 3201;
  159. const RGBDepthPacking = 3202;
  160. const RGDepthPacking = 3203;
  161. const TangentSpaceNormalMap = 0;
  162. const ObjectSpaceNormalMap = 1;
  163. // Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available.
  164. const NoColorSpace = '';
  165. const SRGBColorSpace = 'srgb';
  166. const LinearSRGBColorSpace = 'srgb-linear';
  167. const LinearTransfer = 'linear';
  168. const SRGBTransfer = 'srgb';
  169. const ZeroStencilOp = 0;
  170. const KeepStencilOp = 7680;
  171. const ReplaceStencilOp = 7681;
  172. const IncrementStencilOp = 7682;
  173. const DecrementStencilOp = 7683;
  174. const IncrementWrapStencilOp = 34055;
  175. const DecrementWrapStencilOp = 34056;
  176. const InvertStencilOp = 5386;
  177. const NeverStencilFunc = 512;
  178. const LessStencilFunc = 513;
  179. const EqualStencilFunc = 514;
  180. const LessEqualStencilFunc = 515;
  181. const GreaterStencilFunc = 516;
  182. const NotEqualStencilFunc = 517;
  183. const GreaterEqualStencilFunc = 518;
  184. const AlwaysStencilFunc = 519;
  185. const NeverCompare = 512;
  186. const LessCompare = 513;
  187. const EqualCompare = 514;
  188. const LessEqualCompare = 515;
  189. const GreaterCompare = 516;
  190. const NotEqualCompare = 517;
  191. const GreaterEqualCompare = 518;
  192. const AlwaysCompare = 519;
  193. const StaticDrawUsage = 35044;
  194. const DynamicDrawUsage = 35048;
  195. const StreamDrawUsage = 35040;
  196. const StaticReadUsage = 35045;
  197. const DynamicReadUsage = 35049;
  198. const StreamReadUsage = 35041;
  199. const StaticCopyUsage = 35046;
  200. const DynamicCopyUsage = 35050;
  201. const StreamCopyUsage = 35042;
  202. const GLSL1 = '100';
  203. const GLSL3 = '300 es';
  204. const WebGLCoordinateSystem = 2000;
  205. const WebGPUCoordinateSystem = 2001;
  206. /**
  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 Data3DTexture directly.
  2000. //
  2001. // const texture = new THREE.Data3DTexture( 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. let _id$2 = 0;
  6032. class BufferAttribute {
  6033. constructor( array, itemSize, normalized = false ) {
  6034. if ( Array.isArray( array ) ) {
  6035. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6036. }
  6037. this.isBufferAttribute = true;
  6038. Object.defineProperty( this, 'id', { value: _id$2 ++ } );
  6039. this.name = '';
  6040. this.array = array;
  6041. this.itemSize = itemSize;
  6042. this.count = array !== undefined ? array.length / itemSize : 0;
  6043. this.normalized = normalized;
  6044. this.usage = StaticDrawUsage;
  6045. this.updateRanges = [];
  6046. this.gpuType = FloatType;
  6047. this.version = 0;
  6048. }
  6049. onUploadCallback() {}
  6050. set needsUpdate( value ) {
  6051. if ( value === true ) this.version ++;
  6052. }
  6053. setUsage( value ) {
  6054. this.usage = value;
  6055. return this;
  6056. }
  6057. addUpdateRange( start, count ) {
  6058. this.updateRanges.push( { start, count } );
  6059. }
  6060. clearUpdateRanges() {
  6061. this.updateRanges.length = 0;
  6062. }
  6063. copy( source ) {
  6064. this.name = source.name;
  6065. this.array = new source.array.constructor( source.array );
  6066. this.itemSize = source.itemSize;
  6067. this.count = source.count;
  6068. this.normalized = source.normalized;
  6069. this.usage = source.usage;
  6070. this.gpuType = source.gpuType;
  6071. return this;
  6072. }
  6073. copyAt( index1, attribute, index2 ) {
  6074. index1 *= this.itemSize;
  6075. index2 *= attribute.itemSize;
  6076. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  6077. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6078. }
  6079. return this;
  6080. }
  6081. copyArray( array ) {
  6082. this.array.set( array );
  6083. return this;
  6084. }
  6085. applyMatrix3( m ) {
  6086. if ( this.itemSize === 2 ) {
  6087. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6088. _vector2$1.fromBufferAttribute( this, i );
  6089. _vector2$1.applyMatrix3( m );
  6090. this.setXY( i, _vector2$1.x, _vector2$1.y );
  6091. }
  6092. } else if ( this.itemSize === 3 ) {
  6093. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6094. _vector$9.fromBufferAttribute( this, i );
  6095. _vector$9.applyMatrix3( m );
  6096. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6097. }
  6098. }
  6099. return this;
  6100. }
  6101. applyMatrix4( m ) {
  6102. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6103. _vector$9.fromBufferAttribute( this, i );
  6104. _vector$9.applyMatrix4( m );
  6105. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6106. }
  6107. return this;
  6108. }
  6109. applyNormalMatrix( m ) {
  6110. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6111. _vector$9.fromBufferAttribute( this, i );
  6112. _vector$9.applyNormalMatrix( m );
  6113. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6114. }
  6115. return this;
  6116. }
  6117. transformDirection( m ) {
  6118. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6119. _vector$9.fromBufferAttribute( this, i );
  6120. _vector$9.transformDirection( m );
  6121. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6122. }
  6123. return this;
  6124. }
  6125. set( value, offset = 0 ) {
  6126. // Matching BufferAttribute constructor, do not normalize the array.
  6127. this.array.set( value, offset );
  6128. return this;
  6129. }
  6130. getComponent( index, component ) {
  6131. let value = this.array[ index * this.itemSize + component ];
  6132. if ( this.normalized ) value = denormalize( value, this.array );
  6133. return value;
  6134. }
  6135. setComponent( index, component, value ) {
  6136. if ( this.normalized ) value = normalize( value, this.array );
  6137. this.array[ index * this.itemSize + component ] = value;
  6138. return this;
  6139. }
  6140. getX( index ) {
  6141. let x = this.array[ index * this.itemSize ];
  6142. if ( this.normalized ) x = denormalize( x, this.array );
  6143. return x;
  6144. }
  6145. setX( index, x ) {
  6146. if ( this.normalized ) x = normalize( x, this.array );
  6147. this.array[ index * this.itemSize ] = x;
  6148. return this;
  6149. }
  6150. getY( index ) {
  6151. let y = this.array[ index * this.itemSize + 1 ];
  6152. if ( this.normalized ) y = denormalize( y, this.array );
  6153. return y;
  6154. }
  6155. setY( index, y ) {
  6156. if ( this.normalized ) y = normalize( y, this.array );
  6157. this.array[ index * this.itemSize + 1 ] = y;
  6158. return this;
  6159. }
  6160. getZ( index ) {
  6161. let z = this.array[ index * this.itemSize + 2 ];
  6162. if ( this.normalized ) z = denormalize( z, this.array );
  6163. return z;
  6164. }
  6165. setZ( index, z ) {
  6166. if ( this.normalized ) z = normalize( z, this.array );
  6167. this.array[ index * this.itemSize + 2 ] = z;
  6168. return this;
  6169. }
  6170. getW( index ) {
  6171. let w = this.array[ index * this.itemSize + 3 ];
  6172. if ( this.normalized ) w = denormalize( w, this.array );
  6173. return w;
  6174. }
  6175. setW( index, w ) {
  6176. if ( this.normalized ) w = normalize( w, this.array );
  6177. this.array[ index * this.itemSize + 3 ] = w;
  6178. return this;
  6179. }
  6180. setXY( index, x, y ) {
  6181. index *= this.itemSize;
  6182. if ( this.normalized ) {
  6183. x = normalize( x, this.array );
  6184. y = normalize( y, this.array );
  6185. }
  6186. this.array[ index + 0 ] = x;
  6187. this.array[ index + 1 ] = y;
  6188. return this;
  6189. }
  6190. setXYZ( index, x, y, z ) {
  6191. index *= this.itemSize;
  6192. if ( this.normalized ) {
  6193. x = normalize( x, this.array );
  6194. y = normalize( y, this.array );
  6195. z = normalize( z, this.array );
  6196. }
  6197. this.array[ index + 0 ] = x;
  6198. this.array[ index + 1 ] = y;
  6199. this.array[ index + 2 ] = z;
  6200. return this;
  6201. }
  6202. setXYZW( index, x, y, z, w ) {
  6203. index *= this.itemSize;
  6204. if ( this.normalized ) {
  6205. x = normalize( x, this.array );
  6206. y = normalize( y, this.array );
  6207. z = normalize( z, this.array );
  6208. w = normalize( w, this.array );
  6209. }
  6210. this.array[ index + 0 ] = x;
  6211. this.array[ index + 1 ] = y;
  6212. this.array[ index + 2 ] = z;
  6213. this.array[ index + 3 ] = w;
  6214. return this;
  6215. }
  6216. onUpload( callback ) {
  6217. this.onUploadCallback = callback;
  6218. return this;
  6219. }
  6220. clone() {
  6221. return new this.constructor( this.array, this.itemSize ).copy( this );
  6222. }
  6223. toJSON() {
  6224. const data = {
  6225. itemSize: this.itemSize,
  6226. type: this.array.constructor.name,
  6227. array: Array.from( this.array ),
  6228. normalized: this.normalized
  6229. };
  6230. if ( this.name !== '' ) data.name = this.name;
  6231. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  6232. return data;
  6233. }
  6234. }
  6235. //
  6236. class Int8BufferAttribute extends BufferAttribute {
  6237. constructor( array, itemSize, normalized ) {
  6238. super( new Int8Array( array ), itemSize, normalized );
  6239. }
  6240. }
  6241. class Uint8BufferAttribute extends BufferAttribute {
  6242. constructor( array, itemSize, normalized ) {
  6243. super( new Uint8Array( array ), itemSize, normalized );
  6244. }
  6245. }
  6246. class Uint8ClampedBufferAttribute extends BufferAttribute {
  6247. constructor( array, itemSize, normalized ) {
  6248. super( new Uint8ClampedArray( array ), itemSize, normalized );
  6249. }
  6250. }
  6251. class Int16BufferAttribute extends BufferAttribute {
  6252. constructor( array, itemSize, normalized ) {
  6253. super( new Int16Array( array ), itemSize, normalized );
  6254. }
  6255. }
  6256. class Uint16BufferAttribute extends BufferAttribute {
  6257. constructor( array, itemSize, normalized ) {
  6258. super( new Uint16Array( array ), itemSize, normalized );
  6259. }
  6260. }
  6261. class Int32BufferAttribute extends BufferAttribute {
  6262. constructor( array, itemSize, normalized ) {
  6263. super( new Int32Array( array ), itemSize, normalized );
  6264. }
  6265. }
  6266. class Uint32BufferAttribute extends BufferAttribute {
  6267. constructor( array, itemSize, normalized ) {
  6268. super( new Uint32Array( array ), itemSize, normalized );
  6269. }
  6270. }
  6271. class Float16BufferAttribute extends BufferAttribute {
  6272. constructor( array, itemSize, normalized ) {
  6273. super( new Uint16Array( array ), itemSize, normalized );
  6274. this.isFloat16BufferAttribute = true;
  6275. }
  6276. getX( index ) {
  6277. let x = fromHalfFloat( this.array[ index * this.itemSize ] );
  6278. if ( this.normalized ) x = denormalize( x, this.array );
  6279. return x;
  6280. }
  6281. setX( index, x ) {
  6282. if ( this.normalized ) x = normalize( x, this.array );
  6283. this.array[ index * this.itemSize ] = toHalfFloat( x );
  6284. return this;
  6285. }
  6286. getY( index ) {
  6287. let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
  6288. if ( this.normalized ) y = denormalize( y, this.array );
  6289. return y;
  6290. }
  6291. setY( index, y ) {
  6292. if ( this.normalized ) y = normalize( y, this.array );
  6293. this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
  6294. return this;
  6295. }
  6296. getZ( index ) {
  6297. let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
  6298. if ( this.normalized ) z = denormalize( z, this.array );
  6299. return z;
  6300. }
  6301. setZ( index, z ) {
  6302. if ( this.normalized ) z = normalize( z, this.array );
  6303. this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
  6304. return this;
  6305. }
  6306. getW( index ) {
  6307. let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
  6308. if ( this.normalized ) w = denormalize( w, this.array );
  6309. return w;
  6310. }
  6311. setW( index, w ) {
  6312. if ( this.normalized ) w = normalize( w, this.array );
  6313. this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
  6314. return this;
  6315. }
  6316. setXY( index, x, y ) {
  6317. index *= this.itemSize;
  6318. if ( this.normalized ) {
  6319. x = normalize( x, this.array );
  6320. y = normalize( y, this.array );
  6321. }
  6322. this.array[ index + 0 ] = toHalfFloat( x );
  6323. this.array[ index + 1 ] = toHalfFloat( y );
  6324. return this;
  6325. }
  6326. setXYZ( index, x, y, z ) {
  6327. index *= this.itemSize;
  6328. if ( this.normalized ) {
  6329. x = normalize( x, this.array );
  6330. y = normalize( y, this.array );
  6331. z = normalize( z, this.array );
  6332. }
  6333. this.array[ index + 0 ] = toHalfFloat( x );
  6334. this.array[ index + 1 ] = toHalfFloat( y );
  6335. this.array[ index + 2 ] = toHalfFloat( z );
  6336. return this;
  6337. }
  6338. setXYZW( index, x, y, z, w ) {
  6339. index *= this.itemSize;
  6340. if ( this.normalized ) {
  6341. x = normalize( x, this.array );
  6342. y = normalize( y, this.array );
  6343. z = normalize( z, this.array );
  6344. w = normalize( w, this.array );
  6345. }
  6346. this.array[ index + 0 ] = toHalfFloat( x );
  6347. this.array[ index + 1 ] = toHalfFloat( y );
  6348. this.array[ index + 2 ] = toHalfFloat( z );
  6349. this.array[ index + 3 ] = toHalfFloat( w );
  6350. return this;
  6351. }
  6352. }
  6353. class Float32BufferAttribute extends BufferAttribute {
  6354. constructor( array, itemSize, normalized ) {
  6355. super( new Float32Array( array ), itemSize, normalized );
  6356. }
  6357. }
  6358. let _id$1 = 0;
  6359. const _m1 = /*@__PURE__*/ new Matrix4();
  6360. const _obj = /*@__PURE__*/ new Object3D();
  6361. const _offset = /*@__PURE__*/ new Vector3();
  6362. const _box$2 = /*@__PURE__*/ new Box3();
  6363. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  6364. const _vector$8 = /*@__PURE__*/ new Vector3();
  6365. class BufferGeometry extends EventDispatcher {
  6366. constructor() {
  6367. super();
  6368. this.isBufferGeometry = true;
  6369. Object.defineProperty( this, 'id', { value: _id$1 ++ } );
  6370. this.uuid = generateUUID();
  6371. this.name = '';
  6372. this.type = 'BufferGeometry';
  6373. this.index = null;
  6374. this.indirect = null;
  6375. this.attributes = {};
  6376. this.morphAttributes = {};
  6377. this.morphTargetsRelative = false;
  6378. this.groups = [];
  6379. this.boundingBox = null;
  6380. this.boundingSphere = null;
  6381. this.drawRange = { start: 0, count: Infinity };
  6382. this.userData = {};
  6383. }
  6384. getIndex() {
  6385. return this.index;
  6386. }
  6387. setIndex( index ) {
  6388. if ( Array.isArray( index ) ) {
  6389. this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6390. } else {
  6391. this.index = index;
  6392. }
  6393. return this;
  6394. }
  6395. setIndirect( indirect ) {
  6396. this.indirect = indirect;
  6397. return this;
  6398. }
  6399. getIndirect() {
  6400. return this.indirect;
  6401. }
  6402. getAttribute( name ) {
  6403. return this.attributes[ name ];
  6404. }
  6405. setAttribute( name, attribute ) {
  6406. this.attributes[ name ] = attribute;
  6407. return this;
  6408. }
  6409. deleteAttribute( name ) {
  6410. delete this.attributes[ name ];
  6411. return this;
  6412. }
  6413. hasAttribute( name ) {
  6414. return this.attributes[ name ] !== undefined;
  6415. }
  6416. addGroup( start, count, materialIndex = 0 ) {
  6417. this.groups.push( {
  6418. start: start,
  6419. count: count,
  6420. materialIndex: materialIndex
  6421. } );
  6422. }
  6423. clearGroups() {
  6424. this.groups = [];
  6425. }
  6426. setDrawRange( start, count ) {
  6427. this.drawRange.start = start;
  6428. this.drawRange.count = count;
  6429. }
  6430. applyMatrix4( matrix ) {
  6431. const position = this.attributes.position;
  6432. if ( position !== undefined ) {
  6433. position.applyMatrix4( matrix );
  6434. position.needsUpdate = true;
  6435. }
  6436. const normal = this.attributes.normal;
  6437. if ( normal !== undefined ) {
  6438. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6439. normal.applyNormalMatrix( normalMatrix );
  6440. normal.needsUpdate = true;
  6441. }
  6442. const tangent = this.attributes.tangent;
  6443. if ( tangent !== undefined ) {
  6444. tangent.transformDirection( matrix );
  6445. tangent.needsUpdate = true;
  6446. }
  6447. if ( this.boundingBox !== null ) {
  6448. this.computeBoundingBox();
  6449. }
  6450. if ( this.boundingSphere !== null ) {
  6451. this.computeBoundingSphere();
  6452. }
  6453. return this;
  6454. }
  6455. applyQuaternion( q ) {
  6456. _m1.makeRotationFromQuaternion( q );
  6457. this.applyMatrix4( _m1 );
  6458. return this;
  6459. }
  6460. rotateX( angle ) {
  6461. // rotate geometry around world x-axis
  6462. _m1.makeRotationX( angle );
  6463. this.applyMatrix4( _m1 );
  6464. return this;
  6465. }
  6466. rotateY( angle ) {
  6467. // rotate geometry around world y-axis
  6468. _m1.makeRotationY( angle );
  6469. this.applyMatrix4( _m1 );
  6470. return this;
  6471. }
  6472. rotateZ( angle ) {
  6473. // rotate geometry around world z-axis
  6474. _m1.makeRotationZ( angle );
  6475. this.applyMatrix4( _m1 );
  6476. return this;
  6477. }
  6478. translate( x, y, z ) {
  6479. // translate geometry
  6480. _m1.makeTranslation( x, y, z );
  6481. this.applyMatrix4( _m1 );
  6482. return this;
  6483. }
  6484. scale( x, y, z ) {
  6485. // scale geometry
  6486. _m1.makeScale( x, y, z );
  6487. this.applyMatrix4( _m1 );
  6488. return this;
  6489. }
  6490. lookAt( vector ) {
  6491. _obj.lookAt( vector );
  6492. _obj.updateMatrix();
  6493. this.applyMatrix4( _obj.matrix );
  6494. return this;
  6495. }
  6496. center() {
  6497. this.computeBoundingBox();
  6498. this.boundingBox.getCenter( _offset ).negate();
  6499. this.translate( _offset.x, _offset.y, _offset.z );
  6500. return this;
  6501. }
  6502. setFromPoints( points ) {
  6503. const positionAttribute = this.getAttribute( 'position' );
  6504. if ( positionAttribute === undefined ) {
  6505. const position = [];
  6506. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6507. const point = points[ i ];
  6508. position.push( point.x, point.y, point.z || 0 );
  6509. }
  6510. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6511. } else {
  6512. const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size
  6513. for ( let i = 0; i < l; i ++ ) {
  6514. const point = points[ i ];
  6515. positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
  6516. }
  6517. if ( points.length > positionAttribute.count ) {
  6518. console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
  6519. }
  6520. positionAttribute.needsUpdate = true;
  6521. }
  6522. return this;
  6523. }
  6524. computeBoundingBox() {
  6525. if ( this.boundingBox === null ) {
  6526. this.boundingBox = new Box3();
  6527. }
  6528. const position = this.attributes.position;
  6529. const morphAttributesPosition = this.morphAttributes.position;
  6530. if ( position && position.isGLBufferAttribute ) {
  6531. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
  6532. this.boundingBox.set(
  6533. new Vector3( - Infinity, - Infinity, - Infinity ),
  6534. new Vector3( + Infinity, + Infinity, + Infinity )
  6535. );
  6536. return;
  6537. }
  6538. if ( position !== undefined ) {
  6539. this.boundingBox.setFromBufferAttribute( position );
  6540. // process morph attributes if present
  6541. if ( morphAttributesPosition ) {
  6542. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6543. const morphAttribute = morphAttributesPosition[ i ];
  6544. _box$2.setFromBufferAttribute( morphAttribute );
  6545. if ( this.morphTargetsRelative ) {
  6546. _vector$8.addVectors( this.boundingBox.min, _box$2.min );
  6547. this.boundingBox.expandByPoint( _vector$8 );
  6548. _vector$8.addVectors( this.boundingBox.max, _box$2.max );
  6549. this.boundingBox.expandByPoint( _vector$8 );
  6550. } else {
  6551. this.boundingBox.expandByPoint( _box$2.min );
  6552. this.boundingBox.expandByPoint( _box$2.max );
  6553. }
  6554. }
  6555. }
  6556. } else {
  6557. this.boundingBox.makeEmpty();
  6558. }
  6559. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6560. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6561. }
  6562. }
  6563. computeBoundingSphere() {
  6564. if ( this.boundingSphere === null ) {
  6565. this.boundingSphere = new Sphere();
  6566. }
  6567. const position = this.attributes.position;
  6568. const morphAttributesPosition = this.morphAttributes.position;
  6569. if ( position && position.isGLBufferAttribute ) {
  6570. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
  6571. this.boundingSphere.set( new Vector3(), Infinity );
  6572. return;
  6573. }
  6574. if ( position ) {
  6575. // first, find the center of the bounding sphere
  6576. const center = this.boundingSphere.center;
  6577. _box$2.setFromBufferAttribute( position );
  6578. // process morph attributes if present
  6579. if ( morphAttributesPosition ) {
  6580. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6581. const morphAttribute = morphAttributesPosition[ i ];
  6582. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6583. if ( this.morphTargetsRelative ) {
  6584. _vector$8.addVectors( _box$2.min, _boxMorphTargets.min );
  6585. _box$2.expandByPoint( _vector$8 );
  6586. _vector$8.addVectors( _box$2.max, _boxMorphTargets.max );
  6587. _box$2.expandByPoint( _vector$8 );
  6588. } else {
  6589. _box$2.expandByPoint( _boxMorphTargets.min );
  6590. _box$2.expandByPoint( _boxMorphTargets.max );
  6591. }
  6592. }
  6593. }
  6594. _box$2.getCenter( center );
  6595. // second, try to find a boundingSphere with a radius smaller than the
  6596. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6597. let maxRadiusSq = 0;
  6598. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6599. _vector$8.fromBufferAttribute( position, i );
  6600. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6601. }
  6602. // process morph attributes if present
  6603. if ( morphAttributesPosition ) {
  6604. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6605. const morphAttribute = morphAttributesPosition[ i ];
  6606. const morphTargetsRelative = this.morphTargetsRelative;
  6607. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6608. _vector$8.fromBufferAttribute( morphAttribute, j );
  6609. if ( morphTargetsRelative ) {
  6610. _offset.fromBufferAttribute( position, j );
  6611. _vector$8.add( _offset );
  6612. }
  6613. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6614. }
  6615. }
  6616. }
  6617. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6618. if ( isNaN( this.boundingSphere.radius ) ) {
  6619. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6620. }
  6621. }
  6622. }
  6623. computeTangents() {
  6624. const index = this.index;
  6625. const attributes = this.attributes;
  6626. // based on http://www.terathon.com/code/tangent.html
  6627. // (per vertex tangents)
  6628. if ( index === null ||
  6629. attributes.position === undefined ||
  6630. attributes.normal === undefined ||
  6631. attributes.uv === undefined ) {
  6632. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  6633. return;
  6634. }
  6635. const positionAttribute = attributes.position;
  6636. const normalAttribute = attributes.normal;
  6637. const uvAttribute = attributes.uv;
  6638. if ( this.hasAttribute( 'tangent' ) === false ) {
  6639. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
  6640. }
  6641. const tangentAttribute = this.getAttribute( 'tangent' );
  6642. const tan1 = [], tan2 = [];
  6643. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  6644. tan1[ i ] = new Vector3();
  6645. tan2[ i ] = new Vector3();
  6646. }
  6647. const vA = new Vector3(),
  6648. vB = new Vector3(),
  6649. vC = new Vector3(),
  6650. uvA = new Vector2(),
  6651. uvB = new Vector2(),
  6652. uvC = new Vector2(),
  6653. sdir = new Vector3(),
  6654. tdir = new Vector3();
  6655. function handleTriangle( a, b, c ) {
  6656. vA.fromBufferAttribute( positionAttribute, a );
  6657. vB.fromBufferAttribute( positionAttribute, b );
  6658. vC.fromBufferAttribute( positionAttribute, c );
  6659. uvA.fromBufferAttribute( uvAttribute, a );
  6660. uvB.fromBufferAttribute( uvAttribute, b );
  6661. uvC.fromBufferAttribute( uvAttribute, c );
  6662. vB.sub( vA );
  6663. vC.sub( vA );
  6664. uvB.sub( uvA );
  6665. uvC.sub( uvA );
  6666. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6667. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6668. if ( ! isFinite( r ) ) return;
  6669. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6670. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6671. tan1[ a ].add( sdir );
  6672. tan1[ b ].add( sdir );
  6673. tan1[ c ].add( sdir );
  6674. tan2[ a ].add( tdir );
  6675. tan2[ b ].add( tdir );
  6676. tan2[ c ].add( tdir );
  6677. }
  6678. let groups = this.groups;
  6679. if ( groups.length === 0 ) {
  6680. groups = [ {
  6681. start: 0,
  6682. count: index.count
  6683. } ];
  6684. }
  6685. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6686. const group = groups[ i ];
  6687. const start = group.start;
  6688. const count = group.count;
  6689. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6690. handleTriangle(
  6691. index.getX( j + 0 ),
  6692. index.getX( j + 1 ),
  6693. index.getX( j + 2 )
  6694. );
  6695. }
  6696. }
  6697. const tmp = new Vector3(), tmp2 = new Vector3();
  6698. const n = new Vector3(), n2 = new Vector3();
  6699. function handleVertex( v ) {
  6700. n.fromBufferAttribute( normalAttribute, v );
  6701. n2.copy( n );
  6702. const t = tan1[ v ];
  6703. // Gram-Schmidt orthogonalize
  6704. tmp.copy( t );
  6705. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6706. // Calculate handedness
  6707. tmp2.crossVectors( n2, t );
  6708. const test = tmp2.dot( tan2[ v ] );
  6709. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6710. tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
  6711. }
  6712. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6713. const group = groups[ i ];
  6714. const start = group.start;
  6715. const count = group.count;
  6716. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6717. handleVertex( index.getX( j + 0 ) );
  6718. handleVertex( index.getX( j + 1 ) );
  6719. handleVertex( index.getX( j + 2 ) );
  6720. }
  6721. }
  6722. }
  6723. computeVertexNormals() {
  6724. const index = this.index;
  6725. const positionAttribute = this.getAttribute( 'position' );
  6726. if ( positionAttribute !== undefined ) {
  6727. let normalAttribute = this.getAttribute( 'normal' );
  6728. if ( normalAttribute === undefined ) {
  6729. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6730. this.setAttribute( 'normal', normalAttribute );
  6731. } else {
  6732. // reset existing normals to zero
  6733. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6734. normalAttribute.setXYZ( i, 0, 0, 0 );
  6735. }
  6736. }
  6737. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6738. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6739. const cb = new Vector3(), ab = new Vector3();
  6740. // indexed elements
  6741. if ( index ) {
  6742. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6743. const vA = index.getX( i + 0 );
  6744. const vB = index.getX( i + 1 );
  6745. const vC = index.getX( i + 2 );
  6746. pA.fromBufferAttribute( positionAttribute, vA );
  6747. pB.fromBufferAttribute( positionAttribute, vB );
  6748. pC.fromBufferAttribute( positionAttribute, vC );
  6749. cb.subVectors( pC, pB );
  6750. ab.subVectors( pA, pB );
  6751. cb.cross( ab );
  6752. nA.fromBufferAttribute( normalAttribute, vA );
  6753. nB.fromBufferAttribute( normalAttribute, vB );
  6754. nC.fromBufferAttribute( normalAttribute, vC );
  6755. nA.add( cb );
  6756. nB.add( cb );
  6757. nC.add( cb );
  6758. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6759. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6760. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6761. }
  6762. } else {
  6763. // non-indexed elements (unconnected triangle soup)
  6764. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6765. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6766. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6767. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6768. cb.subVectors( pC, pB );
  6769. ab.subVectors( pA, pB );
  6770. cb.cross( ab );
  6771. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6772. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6773. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6774. }
  6775. }
  6776. this.normalizeNormals();
  6777. normalAttribute.needsUpdate = true;
  6778. }
  6779. }
  6780. normalizeNormals() {
  6781. const normals = this.attributes.normal;
  6782. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6783. _vector$8.fromBufferAttribute( normals, i );
  6784. _vector$8.normalize();
  6785. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6786. }
  6787. }
  6788. toNonIndexed() {
  6789. function convertBufferAttribute( attribute, indices ) {
  6790. const array = attribute.array;
  6791. const itemSize = attribute.itemSize;
  6792. const normalized = attribute.normalized;
  6793. const array2 = new array.constructor( indices.length * itemSize );
  6794. let index = 0, index2 = 0;
  6795. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6796. if ( attribute.isInterleavedBufferAttribute ) {
  6797. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6798. } else {
  6799. index = indices[ i ] * itemSize;
  6800. }
  6801. for ( let j = 0; j < itemSize; j ++ ) {
  6802. array2[ index2 ++ ] = array[ index ++ ];
  6803. }
  6804. }
  6805. return new BufferAttribute( array2, itemSize, normalized );
  6806. }
  6807. //
  6808. if ( this.index === null ) {
  6809. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6810. return this;
  6811. }
  6812. const geometry2 = new BufferGeometry();
  6813. const indices = this.index.array;
  6814. const attributes = this.attributes;
  6815. // attributes
  6816. for ( const name in attributes ) {
  6817. const attribute = attributes[ name ];
  6818. const newAttribute = convertBufferAttribute( attribute, indices );
  6819. geometry2.setAttribute( name, newAttribute );
  6820. }
  6821. // morph attributes
  6822. const morphAttributes = this.morphAttributes;
  6823. for ( const name in morphAttributes ) {
  6824. const morphArray = [];
  6825. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6826. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6827. const attribute = morphAttribute[ i ];
  6828. const newAttribute = convertBufferAttribute( attribute, indices );
  6829. morphArray.push( newAttribute );
  6830. }
  6831. geometry2.morphAttributes[ name ] = morphArray;
  6832. }
  6833. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6834. // groups
  6835. const groups = this.groups;
  6836. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6837. const group = groups[ i ];
  6838. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6839. }
  6840. return geometry2;
  6841. }
  6842. toJSON() {
  6843. const data = {
  6844. metadata: {
  6845. version: 4.6,
  6846. type: 'BufferGeometry',
  6847. generator: 'BufferGeometry.toJSON'
  6848. }
  6849. };
  6850. // standard BufferGeometry serialization
  6851. data.uuid = this.uuid;
  6852. data.type = this.type;
  6853. if ( this.name !== '' ) data.name = this.name;
  6854. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6855. if ( this.parameters !== undefined ) {
  6856. const parameters = this.parameters;
  6857. for ( const key in parameters ) {
  6858. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6859. }
  6860. return data;
  6861. }
  6862. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6863. data.data = { attributes: {} };
  6864. const index = this.index;
  6865. if ( index !== null ) {
  6866. data.data.index = {
  6867. type: index.array.constructor.name,
  6868. array: Array.prototype.slice.call( index.array )
  6869. };
  6870. }
  6871. const attributes = this.attributes;
  6872. for ( const key in attributes ) {
  6873. const attribute = attributes[ key ];
  6874. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6875. }
  6876. const morphAttributes = {};
  6877. let hasMorphAttributes = false;
  6878. for ( const key in this.morphAttributes ) {
  6879. const attributeArray = this.morphAttributes[ key ];
  6880. const array = [];
  6881. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6882. const attribute = attributeArray[ i ];
  6883. array.push( attribute.toJSON( data.data ) );
  6884. }
  6885. if ( array.length > 0 ) {
  6886. morphAttributes[ key ] = array;
  6887. hasMorphAttributes = true;
  6888. }
  6889. }
  6890. if ( hasMorphAttributes ) {
  6891. data.data.morphAttributes = morphAttributes;
  6892. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6893. }
  6894. const groups = this.groups;
  6895. if ( groups.length > 0 ) {
  6896. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6897. }
  6898. const boundingSphere = this.boundingSphere;
  6899. if ( boundingSphere !== null ) {
  6900. data.data.boundingSphere = {
  6901. center: boundingSphere.center.toArray(),
  6902. radius: boundingSphere.radius
  6903. };
  6904. }
  6905. return data;
  6906. }
  6907. clone() {
  6908. return new this.constructor().copy( this );
  6909. }
  6910. copy( source ) {
  6911. // reset
  6912. this.index = null;
  6913. this.attributes = {};
  6914. this.morphAttributes = {};
  6915. this.groups = [];
  6916. this.boundingBox = null;
  6917. this.boundingSphere = null;
  6918. // used for storing cloned, shared data
  6919. const data = {};
  6920. // name
  6921. this.name = source.name;
  6922. // index
  6923. const index = source.index;
  6924. if ( index !== null ) {
  6925. this.setIndex( index.clone( data ) );
  6926. }
  6927. // attributes
  6928. const attributes = source.attributes;
  6929. for ( const name in attributes ) {
  6930. const attribute = attributes[ name ];
  6931. this.setAttribute( name, attribute.clone( data ) );
  6932. }
  6933. // morph attributes
  6934. const morphAttributes = source.morphAttributes;
  6935. for ( const name in morphAttributes ) {
  6936. const array = [];
  6937. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6938. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6939. array.push( morphAttribute[ i ].clone( data ) );
  6940. }
  6941. this.morphAttributes[ name ] = array;
  6942. }
  6943. this.morphTargetsRelative = source.morphTargetsRelative;
  6944. // groups
  6945. const groups = source.groups;
  6946. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6947. const group = groups[ i ];
  6948. this.addGroup( group.start, group.count, group.materialIndex );
  6949. }
  6950. // bounding box
  6951. const boundingBox = source.boundingBox;
  6952. if ( boundingBox !== null ) {
  6953. this.boundingBox = boundingBox.clone();
  6954. }
  6955. // bounding sphere
  6956. const boundingSphere = source.boundingSphere;
  6957. if ( boundingSphere !== null ) {
  6958. this.boundingSphere = boundingSphere.clone();
  6959. }
  6960. // draw range
  6961. this.drawRange.start = source.drawRange.start;
  6962. this.drawRange.count = source.drawRange.count;
  6963. // user data
  6964. this.userData = source.userData;
  6965. return this;
  6966. }
  6967. dispose() {
  6968. this.dispatchEvent( { type: 'dispose' } );
  6969. }
  6970. }
  6971. const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();
  6972. const _ray$3 = /*@__PURE__*/ new Ray();
  6973. const _sphere$6 = /*@__PURE__*/ new Sphere();
  6974. const _sphereHitAt = /*@__PURE__*/ new Vector3();
  6975. const _vA$1 = /*@__PURE__*/ new Vector3();
  6976. const _vB$1 = /*@__PURE__*/ new Vector3();
  6977. const _vC$1 = /*@__PURE__*/ new Vector3();
  6978. const _tempA = /*@__PURE__*/ new Vector3();
  6979. const _morphA = /*@__PURE__*/ new Vector3();
  6980. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6981. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6982. class Mesh extends Object3D {
  6983. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6984. super();
  6985. this.isMesh = true;
  6986. this.type = 'Mesh';
  6987. this.geometry = geometry;
  6988. this.material = material;
  6989. this.updateMorphTargets();
  6990. }
  6991. copy( source, recursive ) {
  6992. super.copy( source, recursive );
  6993. if ( source.morphTargetInfluences !== undefined ) {
  6994. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6995. }
  6996. if ( source.morphTargetDictionary !== undefined ) {
  6997. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6998. }
  6999. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  7000. this.geometry = source.geometry;
  7001. return this;
  7002. }
  7003. updateMorphTargets() {
  7004. const geometry = this.geometry;
  7005. const morphAttributes = geometry.morphAttributes;
  7006. const keys = Object.keys( morphAttributes );
  7007. if ( keys.length > 0 ) {
  7008. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  7009. if ( morphAttribute !== undefined ) {
  7010. this.morphTargetInfluences = [];
  7011. this.morphTargetDictionary = {};
  7012. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  7013. const name = morphAttribute[ m ].name || String( m );
  7014. this.morphTargetInfluences.push( 0 );
  7015. this.morphTargetDictionary[ name ] = m;
  7016. }
  7017. }
  7018. }
  7019. }
  7020. getVertexPosition( index, target ) {
  7021. const geometry = this.geometry;
  7022. const position = geometry.attributes.position;
  7023. const morphPosition = geometry.morphAttributes.position;
  7024. const morphTargetsRelative = geometry.morphTargetsRelative;
  7025. target.fromBufferAttribute( position, index );
  7026. const morphInfluences = this.morphTargetInfluences;
  7027. if ( morphPosition && morphInfluences ) {
  7028. _morphA.set( 0, 0, 0 );
  7029. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  7030. const influence = morphInfluences[ i ];
  7031. const morphAttribute = morphPosition[ i ];
  7032. if ( influence === 0 ) continue;
  7033. _tempA.fromBufferAttribute( morphAttribute, index );
  7034. if ( morphTargetsRelative ) {
  7035. _morphA.addScaledVector( _tempA, influence );
  7036. } else {
  7037. _morphA.addScaledVector( _tempA.sub( target ), influence );
  7038. }
  7039. }
  7040. target.add( _morphA );
  7041. }
  7042. return target;
  7043. }
  7044. raycast( raycaster, intersects ) {
  7045. const geometry = this.geometry;
  7046. const material = this.material;
  7047. const matrixWorld = this.matrixWorld;
  7048. if ( material === undefined ) return;
  7049. // test with bounding sphere in world space
  7050. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7051. _sphere$6.copy( geometry.boundingSphere );
  7052. _sphere$6.applyMatrix4( matrixWorld );
  7053. // check distance from ray origin to bounding sphere
  7054. _ray$3.copy( raycaster.ray ).recast( raycaster.near );
  7055. if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {
  7056. if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;
  7057. if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;
  7058. }
  7059. // convert ray to local space of mesh
  7060. _inverseMatrix$3.copy( matrixWorld ).invert();
  7061. _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );
  7062. // test with bounding box in local space
  7063. if ( geometry.boundingBox !== null ) {
  7064. if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;
  7065. }
  7066. // test for intersections with geometry
  7067. this._computeIntersections( raycaster, intersects, _ray$3 );
  7068. }
  7069. _computeIntersections( raycaster, intersects, rayLocalSpace ) {
  7070. let intersection;
  7071. const geometry = this.geometry;
  7072. const material = this.material;
  7073. const index = geometry.index;
  7074. const position = geometry.attributes.position;
  7075. const uv = geometry.attributes.uv;
  7076. const uv1 = geometry.attributes.uv1;
  7077. const normal = geometry.attributes.normal;
  7078. const groups = geometry.groups;
  7079. const drawRange = geometry.drawRange;
  7080. if ( index !== null ) {
  7081. // indexed buffer geometry
  7082. if ( Array.isArray( material ) ) {
  7083. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7084. const group = groups[ i ];
  7085. const groupMaterial = material[ group.materialIndex ];
  7086. const start = Math.max( group.start, drawRange.start );
  7087. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7088. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7089. const a = index.getX( j );
  7090. const b = index.getX( j + 1 );
  7091. const c = index.getX( j + 2 );
  7092. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7093. if ( intersection ) {
  7094. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  7095. intersection.face.materialIndex = group.materialIndex;
  7096. intersects.push( intersection );
  7097. }
  7098. }
  7099. }
  7100. } else {
  7101. const start = Math.max( 0, drawRange.start );
  7102. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  7103. for ( let i = start, il = end; i < il; i += 3 ) {
  7104. const a = index.getX( i );
  7105. const b = index.getX( i + 1 );
  7106. const c = index.getX( i + 2 );
  7107. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7108. if ( intersection ) {
  7109. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  7110. intersects.push( intersection );
  7111. }
  7112. }
  7113. }
  7114. } else if ( position !== undefined ) {
  7115. // non-indexed buffer geometry
  7116. if ( Array.isArray( material ) ) {
  7117. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7118. const group = groups[ i ];
  7119. const groupMaterial = material[ group.materialIndex ];
  7120. const start = Math.max( group.start, drawRange.start );
  7121. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7122. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7123. const a = j;
  7124. const b = j + 1;
  7125. const c = j + 2;
  7126. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7127. if ( intersection ) {
  7128. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  7129. intersection.face.materialIndex = group.materialIndex;
  7130. intersects.push( intersection );
  7131. }
  7132. }
  7133. }
  7134. } else {
  7135. const start = Math.max( 0, drawRange.start );
  7136. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  7137. for ( let i = start, il = end; i < il; i += 3 ) {
  7138. const a = i;
  7139. const b = i + 1;
  7140. const c = i + 2;
  7141. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7142. if ( intersection ) {
  7143. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  7144. intersects.push( intersection );
  7145. }
  7146. }
  7147. }
  7148. }
  7149. }
  7150. }
  7151. function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {
  7152. let intersect;
  7153. if ( material.side === BackSide ) {
  7154. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  7155. } else {
  7156. intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );
  7157. }
  7158. if ( intersect === null ) return null;
  7159. _intersectionPointWorld.copy( point );
  7160. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  7161. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  7162. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  7163. return {
  7164. distance: distance,
  7165. point: _intersectionPointWorld.clone(),
  7166. object: object
  7167. };
  7168. }
  7169. function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {
  7170. object.getVertexPosition( a, _vA$1 );
  7171. object.getVertexPosition( b, _vB$1 );
  7172. object.getVertexPosition( c, _vC$1 );
  7173. const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  7174. if ( intersection ) {
  7175. const barycoord = new Vector3();
  7176. Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
  7177. if ( uv ) {
  7178. intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
  7179. }
  7180. if ( uv1 ) {
  7181. intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
  7182. }
  7183. if ( normal ) {
  7184. intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
  7185. if ( intersection.normal.dot( ray.direction ) > 0 ) {
  7186. intersection.normal.multiplyScalar( - 1 );
  7187. }
  7188. }
  7189. const face = {
  7190. a: a,
  7191. b: b,
  7192. c: c,
  7193. normal: new Vector3(),
  7194. materialIndex: 0
  7195. };
  7196. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  7197. intersection.face = face;
  7198. intersection.barycoord = barycoord;
  7199. }
  7200. return intersection;
  7201. }
  7202. class BoxGeometry extends BufferGeometry {
  7203. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  7204. super();
  7205. this.type = 'BoxGeometry';
  7206. this.parameters = {
  7207. width: width,
  7208. height: height,
  7209. depth: depth,
  7210. widthSegments: widthSegments,
  7211. heightSegments: heightSegments,
  7212. depthSegments: depthSegments
  7213. };
  7214. const scope = this;
  7215. // segments
  7216. widthSegments = Math.floor( widthSegments );
  7217. heightSegments = Math.floor( heightSegments );
  7218. depthSegments = Math.floor( depthSegments );
  7219. // buffers
  7220. const indices = [];
  7221. const vertices = [];
  7222. const normals = [];
  7223. const uvs = [];
  7224. // helper variables
  7225. let numberOfVertices = 0;
  7226. let groupStart = 0;
  7227. // build each side of the box geometry
  7228. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7229. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7230. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7231. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7232. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7233. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7234. // build geometry
  7235. this.setIndex( indices );
  7236. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7237. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7238. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7239. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7240. const segmentWidth = width / gridX;
  7241. const segmentHeight = height / gridY;
  7242. const widthHalf = width / 2;
  7243. const heightHalf = height / 2;
  7244. const depthHalf = depth / 2;
  7245. const gridX1 = gridX + 1;
  7246. const gridY1 = gridY + 1;
  7247. let vertexCounter = 0;
  7248. let groupCount = 0;
  7249. const vector = new Vector3();
  7250. // generate vertices, normals and uvs
  7251. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7252. const y = iy * segmentHeight - heightHalf;
  7253. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7254. const x = ix * segmentWidth - widthHalf;
  7255. // set values to correct vector component
  7256. vector[ u ] = x * udir;
  7257. vector[ v ] = y * vdir;
  7258. vector[ w ] = depthHalf;
  7259. // now apply vector to vertex buffer
  7260. vertices.push( vector.x, vector.y, vector.z );
  7261. // set values to correct vector component
  7262. vector[ u ] = 0;
  7263. vector[ v ] = 0;
  7264. vector[ w ] = depth > 0 ? 1 : - 1;
  7265. // now apply vector to normal buffer
  7266. normals.push( vector.x, vector.y, vector.z );
  7267. // uvs
  7268. uvs.push( ix / gridX );
  7269. uvs.push( 1 - ( iy / gridY ) );
  7270. // counters
  7271. vertexCounter += 1;
  7272. }
  7273. }
  7274. // indices
  7275. // 1. you need three indices to draw a single face
  7276. // 2. a single segment consists of two faces
  7277. // 3. so we need to generate six (2*3) indices per segment
  7278. for ( let iy = 0; iy < gridY; iy ++ ) {
  7279. for ( let ix = 0; ix < gridX; ix ++ ) {
  7280. const a = numberOfVertices + ix + gridX1 * iy;
  7281. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7282. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7283. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7284. // faces
  7285. indices.push( a, b, d );
  7286. indices.push( b, c, d );
  7287. // increase counter
  7288. groupCount += 6;
  7289. }
  7290. }
  7291. // add a group to the geometry. this will ensure multi material support
  7292. scope.addGroup( groupStart, groupCount, materialIndex );
  7293. // calculate new start value for groups
  7294. groupStart += groupCount;
  7295. // update total number of vertices
  7296. numberOfVertices += vertexCounter;
  7297. }
  7298. }
  7299. copy( source ) {
  7300. super.copy( source );
  7301. this.parameters = Object.assign( {}, source.parameters );
  7302. return this;
  7303. }
  7304. static fromJSON( data ) {
  7305. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  7306. }
  7307. }
  7308. /**
  7309. * Uniform Utilities
  7310. */
  7311. function cloneUniforms( src ) {
  7312. const dst = {};
  7313. for ( const u in src ) {
  7314. dst[ u ] = {};
  7315. for ( const p in src[ u ] ) {
  7316. const property = src[ u ][ p ];
  7317. if ( property && ( property.isColor ||
  7318. property.isMatrix3 || property.isMatrix4 ||
  7319. property.isVector2 || property.isVector3 || property.isVector4 ||
  7320. property.isTexture || property.isQuaternion ) ) {
  7321. if ( property.isRenderTargetTexture ) {
  7322. console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );
  7323. dst[ u ][ p ] = null;
  7324. } else {
  7325. dst[ u ][ p ] = property.clone();
  7326. }
  7327. } else if ( Array.isArray( property ) ) {
  7328. dst[ u ][ p ] = property.slice();
  7329. } else {
  7330. dst[ u ][ p ] = property;
  7331. }
  7332. }
  7333. }
  7334. return dst;
  7335. }
  7336. function mergeUniforms( uniforms ) {
  7337. const merged = {};
  7338. for ( let u = 0; u < uniforms.length; u ++ ) {
  7339. const tmp = cloneUniforms( uniforms[ u ] );
  7340. for ( const p in tmp ) {
  7341. merged[ p ] = tmp[ p ];
  7342. }
  7343. }
  7344. return merged;
  7345. }
  7346. function cloneUniformsGroups( src ) {
  7347. const dst = [];
  7348. for ( let u = 0; u < src.length; u ++ ) {
  7349. dst.push( src[ u ].clone() );
  7350. }
  7351. return dst;
  7352. }
  7353. function getUnlitUniformColorSpace( renderer ) {
  7354. const currentRenderTarget = renderer.getRenderTarget();
  7355. if ( currentRenderTarget === null ) {
  7356. // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
  7357. return renderer.outputColorSpace;
  7358. }
  7359. // https://github.com/mrdoob/three.js/issues/27868
  7360. if ( currentRenderTarget.isXRRenderTarget === true ) {
  7361. return currentRenderTarget.texture.colorSpace;
  7362. }
  7363. return ColorManagement.workingColorSpace;
  7364. }
  7365. // Legacy
  7366. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7367. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7368. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7369. class ShaderMaterial extends Material {
  7370. constructor( parameters ) {
  7371. super();
  7372. this.isShaderMaterial = true;
  7373. this.type = 'ShaderMaterial';
  7374. this.defines = {};
  7375. this.uniforms = {};
  7376. this.uniformsGroups = [];
  7377. this.vertexShader = default_vertex;
  7378. this.fragmentShader = default_fragment;
  7379. this.linewidth = 1;
  7380. this.wireframe = false;
  7381. this.wireframeLinewidth = 1;
  7382. this.fog = false; // set to use scene fog
  7383. this.lights = false; // set to use scene lights
  7384. this.clipping = false; // set to use user-defined clipping planes
  7385. this.forceSinglePass = true;
  7386. this.extensions = {
  7387. clipCullDistance: false, // set to use vertex shader clipping
  7388. multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID
  7389. };
  7390. // When rendered geometry doesn't include these attributes but the material does,
  7391. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7392. this.defaultAttributeValues = {
  7393. 'color': [ 1, 1, 1 ],
  7394. 'uv': [ 0, 0 ],
  7395. 'uv1': [ 0, 0 ]
  7396. };
  7397. this.index0AttributeName = undefined;
  7398. this.uniformsNeedUpdate = false;
  7399. this.glslVersion = null;
  7400. if ( parameters !== undefined ) {
  7401. this.setValues( parameters );
  7402. }
  7403. }
  7404. copy( source ) {
  7405. super.copy( source );
  7406. this.fragmentShader = source.fragmentShader;
  7407. this.vertexShader = source.vertexShader;
  7408. this.uniforms = cloneUniforms( source.uniforms );
  7409. this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );
  7410. this.defines = Object.assign( {}, source.defines );
  7411. this.wireframe = source.wireframe;
  7412. this.wireframeLinewidth = source.wireframeLinewidth;
  7413. this.fog = source.fog;
  7414. this.lights = source.lights;
  7415. this.clipping = source.clipping;
  7416. this.extensions = Object.assign( {}, source.extensions );
  7417. this.glslVersion = source.glslVersion;
  7418. return this;
  7419. }
  7420. toJSON( meta ) {
  7421. const data = super.toJSON( meta );
  7422. data.glslVersion = this.glslVersion;
  7423. data.uniforms = {};
  7424. for ( const name in this.uniforms ) {
  7425. const uniform = this.uniforms[ name ];
  7426. const value = uniform.value;
  7427. if ( value && value.isTexture ) {
  7428. data.uniforms[ name ] = {
  7429. type: 't',
  7430. value: value.toJSON( meta ).uuid
  7431. };
  7432. } else if ( value && value.isColor ) {
  7433. data.uniforms[ name ] = {
  7434. type: 'c',
  7435. value: value.getHex()
  7436. };
  7437. } else if ( value && value.isVector2 ) {
  7438. data.uniforms[ name ] = {
  7439. type: 'v2',
  7440. value: value.toArray()
  7441. };
  7442. } else if ( value && value.isVector3 ) {
  7443. data.uniforms[ name ] = {
  7444. type: 'v3',
  7445. value: value.toArray()
  7446. };
  7447. } else if ( value && value.isVector4 ) {
  7448. data.uniforms[ name ] = {
  7449. type: 'v4',
  7450. value: value.toArray()
  7451. };
  7452. } else if ( value && value.isMatrix3 ) {
  7453. data.uniforms[ name ] = {
  7454. type: 'm3',
  7455. value: value.toArray()
  7456. };
  7457. } else if ( value && value.isMatrix4 ) {
  7458. data.uniforms[ name ] = {
  7459. type: 'm4',
  7460. value: value.toArray()
  7461. };
  7462. } else {
  7463. data.uniforms[ name ] = {
  7464. value: value
  7465. };
  7466. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7467. }
  7468. }
  7469. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7470. data.vertexShader = this.vertexShader;
  7471. data.fragmentShader = this.fragmentShader;
  7472. data.lights = this.lights;
  7473. data.clipping = this.clipping;
  7474. const extensions = {};
  7475. for ( const key in this.extensions ) {
  7476. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7477. }
  7478. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7479. return data;
  7480. }
  7481. }
  7482. class Camera extends Object3D {
  7483. constructor() {
  7484. super();
  7485. this.isCamera = true;
  7486. this.type = 'Camera';
  7487. this.matrixWorldInverse = new Matrix4();
  7488. this.projectionMatrix = new Matrix4();
  7489. this.projectionMatrixInverse = new Matrix4();
  7490. this.coordinateSystem = WebGLCoordinateSystem;
  7491. }
  7492. copy( source, recursive ) {
  7493. super.copy( source, recursive );
  7494. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7495. this.projectionMatrix.copy( source.projectionMatrix );
  7496. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7497. this.coordinateSystem = source.coordinateSystem;
  7498. return this;
  7499. }
  7500. getWorldDirection( target ) {
  7501. return super.getWorldDirection( target ).negate();
  7502. }
  7503. updateMatrixWorld( force ) {
  7504. super.updateMatrixWorld( force );
  7505. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7506. }
  7507. updateWorldMatrix( updateParents, updateChildren ) {
  7508. super.updateWorldMatrix( updateParents, updateChildren );
  7509. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7510. }
  7511. clone() {
  7512. return new this.constructor().copy( this );
  7513. }
  7514. }
  7515. const _v3$1 = /*@__PURE__*/ new Vector3();
  7516. const _minTarget = /*@__PURE__*/ new Vector2();
  7517. const _maxTarget = /*@__PURE__*/ new Vector2();
  7518. class PerspectiveCamera extends Camera {
  7519. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7520. super();
  7521. this.isPerspectiveCamera = true;
  7522. this.type = 'PerspectiveCamera';
  7523. this.fov = fov;
  7524. this.zoom = 1;
  7525. this.near = near;
  7526. this.far = far;
  7527. this.focus = 10;
  7528. this.aspect = aspect;
  7529. this.view = null;
  7530. this.filmGauge = 35; // width of the film (default in millimeters)
  7531. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7532. this.updateProjectionMatrix();
  7533. }
  7534. copy( source, recursive ) {
  7535. super.copy( source, recursive );
  7536. this.fov = source.fov;
  7537. this.zoom = source.zoom;
  7538. this.near = source.near;
  7539. this.far = source.far;
  7540. this.focus = source.focus;
  7541. this.aspect = source.aspect;
  7542. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7543. this.filmGauge = source.filmGauge;
  7544. this.filmOffset = source.filmOffset;
  7545. return this;
  7546. }
  7547. /**
  7548. * Sets the FOV by focal length in respect to the current .filmGauge.
  7549. *
  7550. * The default film gauge is 35, so that the focal length can be specified for
  7551. * a 35mm (full frame) camera.
  7552. *
  7553. * @param {number} focalLength - Values for focal length and film gauge must have the same unit.
  7554. */
  7555. setFocalLength( focalLength ) {
  7556. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7557. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7558. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  7559. this.updateProjectionMatrix();
  7560. }
  7561. /**
  7562. * Calculates the focal length from the current .fov and .filmGauge.
  7563. *
  7564. * @returns {number}
  7565. */
  7566. getFocalLength() {
  7567. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  7568. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7569. }
  7570. getEffectiveFOV() {
  7571. return RAD2DEG * 2 * Math.atan(
  7572. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7573. }
  7574. getFilmWidth() {
  7575. // film not completely covered in portrait format (aspect < 1)
  7576. return this.filmGauge * Math.min( this.aspect, 1 );
  7577. }
  7578. getFilmHeight() {
  7579. // film not completely covered in landscape format (aspect > 1)
  7580. return this.filmGauge / Math.max( this.aspect, 1 );
  7581. }
  7582. /**
  7583. * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  7584. * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  7585. *
  7586. * @param {number} distance
  7587. * @param {Vector2} minTarget
  7588. * @param {Vector2} maxTarget
  7589. */
  7590. getViewBounds( distance, minTarget, maxTarget ) {
  7591. _v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7592. minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7593. _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7594. maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7595. }
  7596. /**
  7597. * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  7598. *
  7599. * @param {number} distance
  7600. * @param {Vector2} target - Vector2 target used to store result where x is width and y is height.
  7601. * @returns {Vector2}
  7602. */
  7603. getViewSize( distance, target ) {
  7604. this.getViewBounds( distance, _minTarget, _maxTarget );
  7605. return target.subVectors( _maxTarget, _minTarget );
  7606. }
  7607. /**
  7608. * Sets an offset in a larger frustum. This is useful for multi-window or
  7609. * multi-monitor/multi-machine setups.
  7610. *
  7611. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7612. * the monitors are in grid like this
  7613. *
  7614. * +---+---+---+
  7615. * | A | B | C |
  7616. * +---+---+---+
  7617. * | D | E | F |
  7618. * +---+---+---+
  7619. *
  7620. * then for each monitor you would call it like this
  7621. *
  7622. * const w = 1920;
  7623. * const h = 1080;
  7624. * const fullWidth = w * 3;
  7625. * const fullHeight = h * 2;
  7626. *
  7627. * --A--
  7628. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7629. * --B--
  7630. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7631. * --C--
  7632. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7633. * --D--
  7634. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7635. * --E--
  7636. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7637. * --F--
  7638. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7639. *
  7640. * Note there is no reason monitors have to be the same size or in a grid.
  7641. *
  7642. * @param {number} fullWidth
  7643. * @param {number} fullHeight
  7644. * @param {number} x
  7645. * @param {number} y
  7646. * @param {number} width
  7647. * @param {number} height
  7648. */
  7649. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  7650. this.aspect = fullWidth / fullHeight;
  7651. if ( this.view === null ) {
  7652. this.view = {
  7653. enabled: true,
  7654. fullWidth: 1,
  7655. fullHeight: 1,
  7656. offsetX: 0,
  7657. offsetY: 0,
  7658. width: 1,
  7659. height: 1
  7660. };
  7661. }
  7662. this.view.enabled = true;
  7663. this.view.fullWidth = fullWidth;
  7664. this.view.fullHeight = fullHeight;
  7665. this.view.offsetX = x;
  7666. this.view.offsetY = y;
  7667. this.view.width = width;
  7668. this.view.height = height;
  7669. this.updateProjectionMatrix();
  7670. }
  7671. clearViewOffset() {
  7672. if ( this.view !== null ) {
  7673. this.view.enabled = false;
  7674. }
  7675. this.updateProjectionMatrix();
  7676. }
  7677. updateProjectionMatrix() {
  7678. const near = this.near;
  7679. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7680. let height = 2 * top;
  7681. let width = this.aspect * height;
  7682. let left = - 0.5 * width;
  7683. const view = this.view;
  7684. if ( this.view !== null && this.view.enabled ) {
  7685. const fullWidth = view.fullWidth,
  7686. fullHeight = view.fullHeight;
  7687. left += view.offsetX * width / fullWidth;
  7688. top -= view.offsetY * height / fullHeight;
  7689. width *= view.width / fullWidth;
  7690. height *= view.height / fullHeight;
  7691. }
  7692. const skew = this.filmOffset;
  7693. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7694. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
  7695. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7696. }
  7697. toJSON( meta ) {
  7698. const data = super.toJSON( meta );
  7699. data.object.fov = this.fov;
  7700. data.object.zoom = this.zoom;
  7701. data.object.near = this.near;
  7702. data.object.far = this.far;
  7703. data.object.focus = this.focus;
  7704. data.object.aspect = this.aspect;
  7705. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7706. data.object.filmGauge = this.filmGauge;
  7707. data.object.filmOffset = this.filmOffset;
  7708. return data;
  7709. }
  7710. }
  7711. const fov = - 90; // negative fov is not an error
  7712. const aspect = 1;
  7713. class CubeCamera extends Object3D {
  7714. constructor( near, far, renderTarget ) {
  7715. super();
  7716. this.type = 'CubeCamera';
  7717. this.renderTarget = renderTarget;
  7718. this.coordinateSystem = null;
  7719. this.activeMipmapLevel = 0;
  7720. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7721. cameraPX.layers = this.layers;
  7722. this.add( cameraPX );
  7723. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7724. cameraNX.layers = this.layers;
  7725. this.add( cameraNX );
  7726. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7727. cameraPY.layers = this.layers;
  7728. this.add( cameraPY );
  7729. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7730. cameraNY.layers = this.layers;
  7731. this.add( cameraNY );
  7732. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7733. cameraPZ.layers = this.layers;
  7734. this.add( cameraPZ );
  7735. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7736. cameraNZ.layers = this.layers;
  7737. this.add( cameraNZ );
  7738. }
  7739. updateCoordinateSystem() {
  7740. const coordinateSystem = this.coordinateSystem;
  7741. const cameras = this.children.concat();
  7742. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
  7743. for ( const camera of cameras ) this.remove( camera );
  7744. if ( coordinateSystem === WebGLCoordinateSystem ) {
  7745. cameraPX.up.set( 0, 1, 0 );
  7746. cameraPX.lookAt( 1, 0, 0 );
  7747. cameraNX.up.set( 0, 1, 0 );
  7748. cameraNX.lookAt( - 1, 0, 0 );
  7749. cameraPY.up.set( 0, 0, - 1 );
  7750. cameraPY.lookAt( 0, 1, 0 );
  7751. cameraNY.up.set( 0, 0, 1 );
  7752. cameraNY.lookAt( 0, - 1, 0 );
  7753. cameraPZ.up.set( 0, 1, 0 );
  7754. cameraPZ.lookAt( 0, 0, 1 );
  7755. cameraNZ.up.set( 0, 1, 0 );
  7756. cameraNZ.lookAt( 0, 0, - 1 );
  7757. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  7758. cameraPX.up.set( 0, - 1, 0 );
  7759. cameraPX.lookAt( - 1, 0, 0 );
  7760. cameraNX.up.set( 0, - 1, 0 );
  7761. cameraNX.lookAt( 1, 0, 0 );
  7762. cameraPY.up.set( 0, 0, 1 );
  7763. cameraPY.lookAt( 0, 1, 0 );
  7764. cameraNY.up.set( 0, 0, - 1 );
  7765. cameraNY.lookAt( 0, - 1, 0 );
  7766. cameraPZ.up.set( 0, - 1, 0 );
  7767. cameraPZ.lookAt( 0, 0, 1 );
  7768. cameraNZ.up.set( 0, - 1, 0 );
  7769. cameraNZ.lookAt( 0, 0, - 1 );
  7770. } else {
  7771. throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
  7772. }
  7773. for ( const camera of cameras ) {
  7774. this.add( camera );
  7775. camera.updateMatrixWorld();
  7776. }
  7777. }
  7778. update( renderer, scene ) {
  7779. if ( this.parent === null ) this.updateMatrixWorld();
  7780. const { renderTarget, activeMipmapLevel } = this;
  7781. if ( this.coordinateSystem !== renderer.coordinateSystem ) {
  7782. this.coordinateSystem = renderer.coordinateSystem;
  7783. this.updateCoordinateSystem();
  7784. }
  7785. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7786. const currentRenderTarget = renderer.getRenderTarget();
  7787. const currentActiveCubeFace = renderer.getActiveCubeFace();
  7788. const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
  7789. const currentXrEnabled = renderer.xr.enabled;
  7790. renderer.xr.enabled = false;
  7791. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7792. renderTarget.texture.generateMipmaps = false;
  7793. renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
  7794. renderer.render( scene, cameraPX );
  7795. renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
  7796. renderer.render( scene, cameraNX );
  7797. renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
  7798. renderer.render( scene, cameraPY );
  7799. renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
  7800. renderer.render( scene, cameraNY );
  7801. renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
  7802. renderer.render( scene, cameraPZ );
  7803. // mipmaps are generated during the last call of render()
  7804. // at this point, all sides of the cube render target are defined
  7805. renderTarget.texture.generateMipmaps = generateMipmaps;
  7806. renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
  7807. renderer.render( scene, cameraNZ );
  7808. renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
  7809. renderer.xr.enabled = currentXrEnabled;
  7810. renderTarget.texture.needsPMREMUpdate = true;
  7811. }
  7812. }
  7813. class CubeTexture extends Texture {
  7814. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {
  7815. images = images !== undefined ? images : [];
  7816. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7817. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  7818. this.isCubeTexture = true;
  7819. this.flipY = false;
  7820. }
  7821. get images() {
  7822. return this.image;
  7823. }
  7824. set images( value ) {
  7825. this.image = value;
  7826. }
  7827. }
  7828. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7829. constructor( size = 1, options = {} ) {
  7830. super( size, size, options );
  7831. this.isWebGLCubeRenderTarget = true;
  7832. const image = { width: size, height: size, depth: 1 };
  7833. const images = [ image, image, image, image, image, image ];
  7834. this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  7835. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7836. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7837. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7838. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7839. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7840. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7841. this.texture.isRenderTargetTexture = true;
  7842. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7843. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7844. }
  7845. fromEquirectangularTexture( renderer, texture ) {
  7846. this.texture.type = texture.type;
  7847. this.texture.colorSpace = texture.colorSpace;
  7848. this.texture.generateMipmaps = texture.generateMipmaps;
  7849. this.texture.minFilter = texture.minFilter;
  7850. this.texture.magFilter = texture.magFilter;
  7851. const shader = {
  7852. uniforms: {
  7853. tEquirect: { value: null },
  7854. },
  7855. vertexShader: /* glsl */`
  7856. varying vec3 vWorldDirection;
  7857. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7858. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7859. }
  7860. void main() {
  7861. vWorldDirection = transformDirection( position, modelMatrix );
  7862. #include <begin_vertex>
  7863. #include <project_vertex>
  7864. }
  7865. `,
  7866. fragmentShader: /* glsl */`
  7867. uniform sampler2D tEquirect;
  7868. varying vec3 vWorldDirection;
  7869. #include <common>
  7870. void main() {
  7871. vec3 direction = normalize( vWorldDirection );
  7872. vec2 sampleUV = equirectUv( direction );
  7873. gl_FragColor = texture2D( tEquirect, sampleUV );
  7874. }
  7875. `
  7876. };
  7877. const geometry = new BoxGeometry( 5, 5, 5 );
  7878. const material = new ShaderMaterial( {
  7879. name: 'CubemapFromEquirect',
  7880. uniforms: cloneUniforms( shader.uniforms ),
  7881. vertexShader: shader.vertexShader,
  7882. fragmentShader: shader.fragmentShader,
  7883. side: BackSide,
  7884. blending: NoBlending
  7885. } );
  7886. material.uniforms.tEquirect.value = texture;
  7887. const mesh = new Mesh( geometry, material );
  7888. const currentMinFilter = texture.minFilter;
  7889. // Avoid blurred poles
  7890. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7891. const camera = new CubeCamera( 1, 10, this );
  7892. camera.update( renderer, mesh );
  7893. texture.minFilter = currentMinFilter;
  7894. mesh.geometry.dispose();
  7895. mesh.material.dispose();
  7896. return this;
  7897. }
  7898. clear( renderer, color, depth, stencil ) {
  7899. const currentRenderTarget = renderer.getRenderTarget();
  7900. for ( let i = 0; i < 6; i ++ ) {
  7901. renderer.setRenderTarget( this, i );
  7902. renderer.clear( color, depth, stencil );
  7903. }
  7904. renderer.setRenderTarget( currentRenderTarget );
  7905. }
  7906. }
  7907. class FogExp2 {
  7908. constructor( color, density = 0.00025 ) {
  7909. this.isFogExp2 = true;
  7910. this.name = '';
  7911. this.color = new Color( color );
  7912. this.density = density;
  7913. }
  7914. clone() {
  7915. return new FogExp2( this.color, this.density );
  7916. }
  7917. toJSON( /* meta */ ) {
  7918. return {
  7919. type: 'FogExp2',
  7920. name: this.name,
  7921. color: this.color.getHex(),
  7922. density: this.density
  7923. };
  7924. }
  7925. }
  7926. class Fog {
  7927. constructor( color, near = 1, far = 1000 ) {
  7928. this.isFog = true;
  7929. this.name = '';
  7930. this.color = new Color( color );
  7931. this.near = near;
  7932. this.far = far;
  7933. }
  7934. clone() {
  7935. return new Fog( this.color, this.near, this.far );
  7936. }
  7937. toJSON( /* meta */ ) {
  7938. return {
  7939. type: 'Fog',
  7940. name: this.name,
  7941. color: this.color.getHex(),
  7942. near: this.near,
  7943. far: this.far
  7944. };
  7945. }
  7946. }
  7947. class Scene extends Object3D {
  7948. constructor() {
  7949. super();
  7950. this.isScene = true;
  7951. this.type = 'Scene';
  7952. this.background = null;
  7953. this.environment = null;
  7954. this.fog = null;
  7955. this.backgroundBlurriness = 0;
  7956. this.backgroundIntensity = 1;
  7957. this.backgroundRotation = new Euler();
  7958. this.environmentIntensity = 1;
  7959. this.environmentRotation = new Euler();
  7960. this.overrideMaterial = null;
  7961. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  7962. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
  7963. }
  7964. }
  7965. copy( source, recursive ) {
  7966. super.copy( source, recursive );
  7967. if ( source.background !== null ) this.background = source.background.clone();
  7968. if ( source.environment !== null ) this.environment = source.environment.clone();
  7969. if ( source.fog !== null ) this.fog = source.fog.clone();
  7970. this.backgroundBlurriness = source.backgroundBlurriness;
  7971. this.backgroundIntensity = source.backgroundIntensity;
  7972. this.backgroundRotation.copy( source.backgroundRotation );
  7973. this.environmentIntensity = source.environmentIntensity;
  7974. this.environmentRotation.copy( source.environmentRotation );
  7975. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  7976. this.matrixAutoUpdate = source.matrixAutoUpdate;
  7977. return this;
  7978. }
  7979. toJSON( meta ) {
  7980. const data = super.toJSON( meta );
  7981. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  7982. if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
  7983. if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
  7984. data.object.backgroundRotation = this.backgroundRotation.toArray();
  7985. if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
  7986. data.object.environmentRotation = this.environmentRotation.toArray();
  7987. return data;
  7988. }
  7989. }
  7990. class InterleavedBuffer {
  7991. constructor( array, stride ) {
  7992. this.isInterleavedBuffer = true;
  7993. this.array = array;
  7994. this.stride = stride;
  7995. this.count = array !== undefined ? array.length / stride : 0;
  7996. this.usage = StaticDrawUsage;
  7997. this.updateRanges = [];
  7998. this.version = 0;
  7999. this.uuid = generateUUID();
  8000. }
  8001. onUploadCallback() {}
  8002. set needsUpdate( value ) {
  8003. if ( value === true ) this.version ++;
  8004. }
  8005. setUsage( value ) {
  8006. this.usage = value;
  8007. return this;
  8008. }
  8009. addUpdateRange( start, count ) {
  8010. this.updateRanges.push( { start, count } );
  8011. }
  8012. clearUpdateRanges() {
  8013. this.updateRanges.length = 0;
  8014. }
  8015. copy( source ) {
  8016. this.array = new source.array.constructor( source.array );
  8017. this.count = source.count;
  8018. this.stride = source.stride;
  8019. this.usage = source.usage;
  8020. return this;
  8021. }
  8022. copyAt( index1, attribute, index2 ) {
  8023. index1 *= this.stride;
  8024. index2 *= attribute.stride;
  8025. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  8026. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  8027. }
  8028. return this;
  8029. }
  8030. set( value, offset = 0 ) {
  8031. this.array.set( value, offset );
  8032. return this;
  8033. }
  8034. clone( data ) {
  8035. if ( data.arrayBuffers === undefined ) {
  8036. data.arrayBuffers = {};
  8037. }
  8038. if ( this.array.buffer._uuid === undefined ) {
  8039. this.array.buffer._uuid = generateUUID();
  8040. }
  8041. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8042. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  8043. }
  8044. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  8045. const ib = new this.constructor( array, this.stride );
  8046. ib.setUsage( this.usage );
  8047. return ib;
  8048. }
  8049. onUpload( callback ) {
  8050. this.onUploadCallback = callback;
  8051. return this;
  8052. }
  8053. toJSON( data ) {
  8054. if ( data.arrayBuffers === undefined ) {
  8055. data.arrayBuffers = {};
  8056. }
  8057. // generate UUID for array buffer if necessary
  8058. if ( this.array.buffer._uuid === undefined ) {
  8059. this.array.buffer._uuid = generateUUID();
  8060. }
  8061. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8062. data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
  8063. }
  8064. //
  8065. return {
  8066. uuid: this.uuid,
  8067. buffer: this.array.buffer._uuid,
  8068. type: this.array.constructor.name,
  8069. stride: this.stride
  8070. };
  8071. }
  8072. }
  8073. const _vector$7 = /*@__PURE__*/ new Vector3();
  8074. class InterleavedBufferAttribute {
  8075. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  8076. this.isInterleavedBufferAttribute = true;
  8077. this.name = '';
  8078. this.data = interleavedBuffer;
  8079. this.itemSize = itemSize;
  8080. this.offset = offset;
  8081. this.normalized = normalized;
  8082. }
  8083. get count() {
  8084. return this.data.count;
  8085. }
  8086. get array() {
  8087. return this.data.array;
  8088. }
  8089. set needsUpdate( value ) {
  8090. this.data.needsUpdate = value;
  8091. }
  8092. applyMatrix4( m ) {
  8093. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  8094. _vector$7.fromBufferAttribute( this, i );
  8095. _vector$7.applyMatrix4( m );
  8096. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8097. }
  8098. return this;
  8099. }
  8100. applyNormalMatrix( m ) {
  8101. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8102. _vector$7.fromBufferAttribute( this, i );
  8103. _vector$7.applyNormalMatrix( m );
  8104. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8105. }
  8106. return this;
  8107. }
  8108. transformDirection( m ) {
  8109. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8110. _vector$7.fromBufferAttribute( this, i );
  8111. _vector$7.transformDirection( m );
  8112. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8113. }
  8114. return this;
  8115. }
  8116. getComponent( index, component ) {
  8117. let value = this.array[ index * this.data.stride + this.offset + component ];
  8118. if ( this.normalized ) value = denormalize( value, this.array );
  8119. return value;
  8120. }
  8121. setComponent( index, component, value ) {
  8122. if ( this.normalized ) value = normalize( value, this.array );
  8123. this.data.array[ index * this.data.stride + this.offset + component ] = value;
  8124. return this;
  8125. }
  8126. setX( index, x ) {
  8127. if ( this.normalized ) x = normalize( x, this.array );
  8128. this.data.array[ index * this.data.stride + this.offset ] = x;
  8129. return this;
  8130. }
  8131. setY( index, y ) {
  8132. if ( this.normalized ) y = normalize( y, this.array );
  8133. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  8134. return this;
  8135. }
  8136. setZ( index, z ) {
  8137. if ( this.normalized ) z = normalize( z, this.array );
  8138. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  8139. return this;
  8140. }
  8141. setW( index, w ) {
  8142. if ( this.normalized ) w = normalize( w, this.array );
  8143. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  8144. return this;
  8145. }
  8146. getX( index ) {
  8147. let x = this.data.array[ index * this.data.stride + this.offset ];
  8148. if ( this.normalized ) x = denormalize( x, this.array );
  8149. return x;
  8150. }
  8151. getY( index ) {
  8152. let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
  8153. if ( this.normalized ) y = denormalize( y, this.array );
  8154. return y;
  8155. }
  8156. getZ( index ) {
  8157. let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
  8158. if ( this.normalized ) z = denormalize( z, this.array );
  8159. return z;
  8160. }
  8161. getW( index ) {
  8162. let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
  8163. if ( this.normalized ) w = denormalize( w, this.array );
  8164. return w;
  8165. }
  8166. setXY( index, x, y ) {
  8167. index = index * this.data.stride + this.offset;
  8168. if ( this.normalized ) {
  8169. x = normalize( x, this.array );
  8170. y = normalize( y, this.array );
  8171. }
  8172. this.data.array[ index + 0 ] = x;
  8173. this.data.array[ index + 1 ] = y;
  8174. return this;
  8175. }
  8176. setXYZ( index, x, y, z ) {
  8177. index = index * this.data.stride + this.offset;
  8178. if ( this.normalized ) {
  8179. x = normalize( x, this.array );
  8180. y = normalize( y, this.array );
  8181. z = normalize( z, this.array );
  8182. }
  8183. this.data.array[ index + 0 ] = x;
  8184. this.data.array[ index + 1 ] = y;
  8185. this.data.array[ index + 2 ] = z;
  8186. return this;
  8187. }
  8188. setXYZW( index, x, y, z, w ) {
  8189. index = index * this.data.stride + this.offset;
  8190. if ( this.normalized ) {
  8191. x = normalize( x, this.array );
  8192. y = normalize( y, this.array );
  8193. z = normalize( z, this.array );
  8194. w = normalize( w, this.array );
  8195. }
  8196. this.data.array[ index + 0 ] = x;
  8197. this.data.array[ index + 1 ] = y;
  8198. this.data.array[ index + 2 ] = z;
  8199. this.data.array[ index + 3 ] = w;
  8200. return this;
  8201. }
  8202. clone( data ) {
  8203. if ( data === undefined ) {
  8204. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
  8205. const array = [];
  8206. for ( let i = 0; i < this.count; i ++ ) {
  8207. const index = i * this.data.stride + this.offset;
  8208. for ( let j = 0; j < this.itemSize; j ++ ) {
  8209. array.push( this.data.array[ index + j ] );
  8210. }
  8211. }
  8212. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  8213. } else {
  8214. if ( data.interleavedBuffers === undefined ) {
  8215. data.interleavedBuffers = {};
  8216. }
  8217. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8218. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  8219. }
  8220. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  8221. }
  8222. }
  8223. toJSON( data ) {
  8224. if ( data === undefined ) {
  8225. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
  8226. const array = [];
  8227. for ( let i = 0; i < this.count; i ++ ) {
  8228. const index = i * this.data.stride + this.offset;
  8229. for ( let j = 0; j < this.itemSize; j ++ ) {
  8230. array.push( this.data.array[ index + j ] );
  8231. }
  8232. }
  8233. // de-interleave data and save it as an ordinary buffer attribute for now
  8234. return {
  8235. itemSize: this.itemSize,
  8236. type: this.array.constructor.name,
  8237. array: array,
  8238. normalized: this.normalized
  8239. };
  8240. } else {
  8241. // save as true interleaved attribute
  8242. if ( data.interleavedBuffers === undefined ) {
  8243. data.interleavedBuffers = {};
  8244. }
  8245. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8246. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  8247. }
  8248. return {
  8249. isInterleavedBufferAttribute: true,
  8250. itemSize: this.itemSize,
  8251. data: this.data.uuid,
  8252. offset: this.offset,
  8253. normalized: this.normalized
  8254. };
  8255. }
  8256. }
  8257. }
  8258. class SpriteMaterial extends Material {
  8259. constructor( parameters ) {
  8260. super();
  8261. this.isSpriteMaterial = true;
  8262. this.type = 'SpriteMaterial';
  8263. this.color = new Color( 0xffffff );
  8264. this.map = null;
  8265. this.alphaMap = null;
  8266. this.rotation = 0;
  8267. this.sizeAttenuation = true;
  8268. this.transparent = true;
  8269. this.fog = true;
  8270. this.setValues( parameters );
  8271. }
  8272. copy( source ) {
  8273. super.copy( source );
  8274. this.color.copy( source.color );
  8275. this.map = source.map;
  8276. this.alphaMap = source.alphaMap;
  8277. this.rotation = source.rotation;
  8278. this.sizeAttenuation = source.sizeAttenuation;
  8279. this.fog = source.fog;
  8280. return this;
  8281. }
  8282. }
  8283. let _geometry;
  8284. const _intersectPoint = /*@__PURE__*/ new Vector3();
  8285. const _worldScale = /*@__PURE__*/ new Vector3();
  8286. const _mvPosition = /*@__PURE__*/ new Vector3();
  8287. const _alignedPosition = /*@__PURE__*/ new Vector2();
  8288. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  8289. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  8290. const _vA = /*@__PURE__*/ new Vector3();
  8291. const _vB = /*@__PURE__*/ new Vector3();
  8292. const _vC = /*@__PURE__*/ new Vector3();
  8293. const _uvA = /*@__PURE__*/ new Vector2();
  8294. const _uvB = /*@__PURE__*/ new Vector2();
  8295. const _uvC = /*@__PURE__*/ new Vector2();
  8296. class Sprite extends Object3D {
  8297. constructor( material = new SpriteMaterial() ) {
  8298. super();
  8299. this.isSprite = true;
  8300. this.type = 'Sprite';
  8301. if ( _geometry === undefined ) {
  8302. _geometry = new BufferGeometry();
  8303. const float32Array = new Float32Array( [
  8304. - 0.5, - 0.5, 0, 0, 0,
  8305. 0.5, - 0.5, 0, 1, 0,
  8306. 0.5, 0.5, 0, 1, 1,
  8307. - 0.5, 0.5, 0, 0, 1
  8308. ] );
  8309. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  8310. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  8311. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  8312. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  8313. }
  8314. this.geometry = _geometry;
  8315. this.material = material;
  8316. this.center = new Vector2( 0.5, 0.5 );
  8317. }
  8318. raycast( raycaster, intersects ) {
  8319. if ( raycaster.camera === null ) {
  8320. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  8321. }
  8322. _worldScale.setFromMatrixScale( this.matrixWorld );
  8323. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  8324. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  8325. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  8326. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  8327. _worldScale.multiplyScalar( - _mvPosition.z );
  8328. }
  8329. const rotation = this.material.rotation;
  8330. let sin, cos;
  8331. if ( rotation !== 0 ) {
  8332. cos = Math.cos( rotation );
  8333. sin = Math.sin( rotation );
  8334. }
  8335. const center = this.center;
  8336. transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8337. transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8338. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8339. _uvA.set( 0, 0 );
  8340. _uvB.set( 1, 0 );
  8341. _uvC.set( 1, 1 );
  8342. // check first triangle
  8343. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  8344. if ( intersect === null ) {
  8345. // check second triangle
  8346. transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8347. _uvB.set( 0, 1 );
  8348. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  8349. if ( intersect === null ) {
  8350. return;
  8351. }
  8352. }
  8353. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  8354. if ( distance < raycaster.near || distance > raycaster.far ) return;
  8355. intersects.push( {
  8356. distance: distance,
  8357. point: _intersectPoint.clone(),
  8358. uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  8359. face: null,
  8360. object: this
  8361. } );
  8362. }
  8363. copy( source, recursive ) {
  8364. super.copy( source, recursive );
  8365. if ( source.center !== undefined ) this.center.copy( source.center );
  8366. this.material = source.material;
  8367. return this;
  8368. }
  8369. }
  8370. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  8371. // compute position in camera space
  8372. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  8373. // to check if rotation is not zero
  8374. if ( sin !== undefined ) {
  8375. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  8376. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  8377. } else {
  8378. _rotatedPosition.copy( _alignedPosition );
  8379. }
  8380. vertexPosition.copy( mvPosition );
  8381. vertexPosition.x += _rotatedPosition.x;
  8382. vertexPosition.y += _rotatedPosition.y;
  8383. // transform to world space
  8384. vertexPosition.applyMatrix4( _viewWorldMatrix );
  8385. }
  8386. const _v1$2 = /*@__PURE__*/ new Vector3();
  8387. const _v2$1 = /*@__PURE__*/ new Vector3();
  8388. class LOD extends Object3D {
  8389. constructor() {
  8390. super();
  8391. this._currentLevel = 0;
  8392. this.type = 'LOD';
  8393. Object.defineProperties( this, {
  8394. levels: {
  8395. enumerable: true,
  8396. value: []
  8397. },
  8398. isLOD: {
  8399. value: true,
  8400. }
  8401. } );
  8402. this.autoUpdate = true;
  8403. }
  8404. copy( source ) {
  8405. super.copy( source, false );
  8406. const levels = source.levels;
  8407. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8408. const level = levels[ i ];
  8409. this.addLevel( level.object.clone(), level.distance, level.hysteresis );
  8410. }
  8411. this.autoUpdate = source.autoUpdate;
  8412. return this;
  8413. }
  8414. addLevel( object, distance = 0, hysteresis = 0 ) {
  8415. distance = Math.abs( distance );
  8416. const levels = this.levels;
  8417. let l;
  8418. for ( l = 0; l < levels.length; l ++ ) {
  8419. if ( distance < levels[ l ].distance ) {
  8420. break;
  8421. }
  8422. }
  8423. levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } );
  8424. this.add( object );
  8425. return this;
  8426. }
  8427. removeLevel( distance ) {
  8428. const levels = this.levels;
  8429. for ( let i = 0; i < levels.length; i ++ ) {
  8430. if ( levels[ i ].distance === distance ) {
  8431. const removedElements = levels.splice( i, 1 );
  8432. this.remove( removedElements[ 0 ].object );
  8433. return true;
  8434. }
  8435. }
  8436. return false;
  8437. }
  8438. getCurrentLevel() {
  8439. return this._currentLevel;
  8440. }
  8441. getObjectForDistance( distance ) {
  8442. const levels = this.levels;
  8443. if ( levels.length > 0 ) {
  8444. let i, l;
  8445. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8446. let levelDistance = levels[ i ].distance;
  8447. if ( levels[ i ].object.visible ) {
  8448. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8449. }
  8450. if ( distance < levelDistance ) {
  8451. break;
  8452. }
  8453. }
  8454. return levels[ i - 1 ].object;
  8455. }
  8456. return null;
  8457. }
  8458. raycast( raycaster, intersects ) {
  8459. const levels = this.levels;
  8460. if ( levels.length > 0 ) {
  8461. _v1$2.setFromMatrixPosition( this.matrixWorld );
  8462. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  8463. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  8464. }
  8465. }
  8466. update( camera ) {
  8467. const levels = this.levels;
  8468. if ( levels.length > 1 ) {
  8469. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  8470. _v2$1.setFromMatrixPosition( this.matrixWorld );
  8471. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  8472. levels[ 0 ].object.visible = true;
  8473. let i, l;
  8474. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8475. let levelDistance = levels[ i ].distance;
  8476. if ( levels[ i ].object.visible ) {
  8477. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8478. }
  8479. if ( distance >= levelDistance ) {
  8480. levels[ i - 1 ].object.visible = false;
  8481. levels[ i ].object.visible = true;
  8482. } else {
  8483. break;
  8484. }
  8485. }
  8486. this._currentLevel = i - 1;
  8487. for ( ; i < l; i ++ ) {
  8488. levels[ i ].object.visible = false;
  8489. }
  8490. }
  8491. }
  8492. toJSON( meta ) {
  8493. const data = super.toJSON( meta );
  8494. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  8495. data.object.levels = [];
  8496. const levels = this.levels;
  8497. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8498. const level = levels[ i ];
  8499. data.object.levels.push( {
  8500. object: level.object.uuid,
  8501. distance: level.distance,
  8502. hysteresis: level.hysteresis
  8503. } );
  8504. }
  8505. return data;
  8506. }
  8507. }
  8508. const _basePosition = /*@__PURE__*/ new Vector3();
  8509. const _skinIndex = /*@__PURE__*/ new Vector4();
  8510. const _skinWeight = /*@__PURE__*/ new Vector4();
  8511. const _vector3 = /*@__PURE__*/ new Vector3();
  8512. const _matrix4 = /*@__PURE__*/ new Matrix4();
  8513. const _vertex = /*@__PURE__*/ new Vector3();
  8514. const _sphere$5 = /*@__PURE__*/ new Sphere();
  8515. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  8516. const _ray$2 = /*@__PURE__*/ new Ray();
  8517. class SkinnedMesh extends Mesh {
  8518. constructor( geometry, material ) {
  8519. super( geometry, material );
  8520. this.isSkinnedMesh = true;
  8521. this.type = 'SkinnedMesh';
  8522. this.bindMode = AttachedBindMode;
  8523. this.bindMatrix = new Matrix4();
  8524. this.bindMatrixInverse = new Matrix4();
  8525. this.boundingBox = null;
  8526. this.boundingSphere = null;
  8527. }
  8528. computeBoundingBox() {
  8529. const geometry = this.geometry;
  8530. if ( this.boundingBox === null ) {
  8531. this.boundingBox = new Box3();
  8532. }
  8533. this.boundingBox.makeEmpty();
  8534. const positionAttribute = geometry.getAttribute( 'position' );
  8535. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8536. this.getVertexPosition( i, _vertex );
  8537. this.boundingBox.expandByPoint( _vertex );
  8538. }
  8539. }
  8540. computeBoundingSphere() {
  8541. const geometry = this.geometry;
  8542. if ( this.boundingSphere === null ) {
  8543. this.boundingSphere = new Sphere();
  8544. }
  8545. this.boundingSphere.makeEmpty();
  8546. const positionAttribute = geometry.getAttribute( 'position' );
  8547. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8548. this.getVertexPosition( i, _vertex );
  8549. this.boundingSphere.expandByPoint( _vertex );
  8550. }
  8551. }
  8552. copy( source, recursive ) {
  8553. super.copy( source, recursive );
  8554. this.bindMode = source.bindMode;
  8555. this.bindMatrix.copy( source.bindMatrix );
  8556. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  8557. this.skeleton = source.skeleton;
  8558. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8559. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8560. return this;
  8561. }
  8562. raycast( raycaster, intersects ) {
  8563. const material = this.material;
  8564. const matrixWorld = this.matrixWorld;
  8565. if ( material === undefined ) return;
  8566. // test with bounding sphere in world space
  8567. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8568. _sphere$5.copy( this.boundingSphere );
  8569. _sphere$5.applyMatrix4( matrixWorld );
  8570. if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return;
  8571. // convert ray to local space of skinned mesh
  8572. _inverseMatrix$2.copy( matrixWorld ).invert();
  8573. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  8574. // test with bounding box in local space
  8575. if ( this.boundingBox !== null ) {
  8576. if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return;
  8577. }
  8578. // test for intersections with geometry
  8579. this._computeIntersections( raycaster, intersects, _ray$2 );
  8580. }
  8581. getVertexPosition( index, target ) {
  8582. super.getVertexPosition( index, target );
  8583. this.applyBoneTransform( index, target );
  8584. return target;
  8585. }
  8586. bind( skeleton, bindMatrix ) {
  8587. this.skeleton = skeleton;
  8588. if ( bindMatrix === undefined ) {
  8589. this.updateMatrixWorld( true );
  8590. this.skeleton.calculateInverses();
  8591. bindMatrix = this.matrixWorld;
  8592. }
  8593. this.bindMatrix.copy( bindMatrix );
  8594. this.bindMatrixInverse.copy( bindMatrix ).invert();
  8595. }
  8596. pose() {
  8597. this.skeleton.pose();
  8598. }
  8599. normalizeSkinWeights() {
  8600. const vector = new Vector4();
  8601. const skinWeight = this.geometry.attributes.skinWeight;
  8602. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  8603. vector.fromBufferAttribute( skinWeight, i );
  8604. const scale = 1.0 / vector.manhattanLength();
  8605. if ( scale !== Infinity ) {
  8606. vector.multiplyScalar( scale );
  8607. } else {
  8608. vector.set( 1, 0, 0, 0 ); // do something reasonable
  8609. }
  8610. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  8611. }
  8612. }
  8613. updateMatrixWorld( force ) {
  8614. super.updateMatrixWorld( force );
  8615. if ( this.bindMode === AttachedBindMode ) {
  8616. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  8617. } else if ( this.bindMode === DetachedBindMode ) {
  8618. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  8619. } else {
  8620. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  8621. }
  8622. }
  8623. applyBoneTransform( index, vector ) {
  8624. const skeleton = this.skeleton;
  8625. const geometry = this.geometry;
  8626. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  8627. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  8628. _basePosition.copy( vector ).applyMatrix4( this.bindMatrix );
  8629. vector.set( 0, 0, 0 );
  8630. for ( let i = 0; i < 4; i ++ ) {
  8631. const weight = _skinWeight.getComponent( i );
  8632. if ( weight !== 0 ) {
  8633. const boneIndex = _skinIndex.getComponent( i );
  8634. _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  8635. vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight );
  8636. }
  8637. }
  8638. return vector.applyMatrix4( this.bindMatrixInverse );
  8639. }
  8640. }
  8641. class Bone extends Object3D {
  8642. constructor() {
  8643. super();
  8644. this.isBone = true;
  8645. this.type = 'Bone';
  8646. }
  8647. }
  8648. class DataTexture extends Texture {
  8649. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  8650. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  8651. this.isDataTexture = true;
  8652. this.image = { data: data, width: width, height: height };
  8653. this.generateMipmaps = false;
  8654. this.flipY = false;
  8655. this.unpackAlignment = 1;
  8656. }
  8657. }
  8658. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  8659. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  8660. class Skeleton {
  8661. constructor( bones = [], boneInverses = [] ) {
  8662. this.uuid = generateUUID();
  8663. this.bones = bones.slice( 0 );
  8664. this.boneInverses = boneInverses;
  8665. this.boneMatrices = null;
  8666. this.boneTexture = null;
  8667. this.init();
  8668. }
  8669. init() {
  8670. const bones = this.bones;
  8671. const boneInverses = this.boneInverses;
  8672. this.boneMatrices = new Float32Array( bones.length * 16 );
  8673. // calculate inverse bone matrices if necessary
  8674. if ( boneInverses.length === 0 ) {
  8675. this.calculateInverses();
  8676. } else {
  8677. // handle special case
  8678. if ( bones.length !== boneInverses.length ) {
  8679. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  8680. this.boneInverses = [];
  8681. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8682. this.boneInverses.push( new Matrix4() );
  8683. }
  8684. }
  8685. }
  8686. }
  8687. calculateInverses() {
  8688. this.boneInverses.length = 0;
  8689. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8690. const inverse = new Matrix4();
  8691. if ( this.bones[ i ] ) {
  8692. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  8693. }
  8694. this.boneInverses.push( inverse );
  8695. }
  8696. }
  8697. pose() {
  8698. // recover the bind-time world matrices
  8699. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8700. const bone = this.bones[ i ];
  8701. if ( bone ) {
  8702. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  8703. }
  8704. }
  8705. // compute the local matrices, positions, rotations and scales
  8706. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8707. const bone = this.bones[ i ];
  8708. if ( bone ) {
  8709. if ( bone.parent && bone.parent.isBone ) {
  8710. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  8711. bone.matrix.multiply( bone.matrixWorld );
  8712. } else {
  8713. bone.matrix.copy( bone.matrixWorld );
  8714. }
  8715. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  8716. }
  8717. }
  8718. }
  8719. update() {
  8720. const bones = this.bones;
  8721. const boneInverses = this.boneInverses;
  8722. const boneMatrices = this.boneMatrices;
  8723. const boneTexture = this.boneTexture;
  8724. // flatten bone matrices to array
  8725. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  8726. // compute the offset between the current and the original transform
  8727. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  8728. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  8729. _offsetMatrix.toArray( boneMatrices, i * 16 );
  8730. }
  8731. if ( boneTexture !== null ) {
  8732. boneTexture.needsUpdate = true;
  8733. }
  8734. }
  8735. clone() {
  8736. return new Skeleton( this.bones, this.boneInverses );
  8737. }
  8738. computeBoneTexture() {
  8739. // layout (1 matrix = 4 pixels)
  8740. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  8741. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  8742. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  8743. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  8744. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  8745. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  8746. size = Math.ceil( size / 4 ) * 4;
  8747. size = Math.max( size, 4 );
  8748. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  8749. boneMatrices.set( this.boneMatrices ); // copy current values
  8750. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  8751. boneTexture.needsUpdate = true;
  8752. this.boneMatrices = boneMatrices;
  8753. this.boneTexture = boneTexture;
  8754. return this;
  8755. }
  8756. getBoneByName( name ) {
  8757. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8758. const bone = this.bones[ i ];
  8759. if ( bone.name === name ) {
  8760. return bone;
  8761. }
  8762. }
  8763. return undefined;
  8764. }
  8765. dispose( ) {
  8766. if ( this.boneTexture !== null ) {
  8767. this.boneTexture.dispose();
  8768. this.boneTexture = null;
  8769. }
  8770. }
  8771. fromJSON( json, bones ) {
  8772. this.uuid = json.uuid;
  8773. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  8774. const uuid = json.bones[ i ];
  8775. let bone = bones[ uuid ];
  8776. if ( bone === undefined ) {
  8777. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  8778. bone = new Bone();
  8779. }
  8780. this.bones.push( bone );
  8781. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  8782. }
  8783. this.init();
  8784. return this;
  8785. }
  8786. toJSON() {
  8787. const data = {
  8788. metadata: {
  8789. version: 4.6,
  8790. type: 'Skeleton',
  8791. generator: 'Skeleton.toJSON'
  8792. },
  8793. bones: [],
  8794. boneInverses: []
  8795. };
  8796. data.uuid = this.uuid;
  8797. const bones = this.bones;
  8798. const boneInverses = this.boneInverses;
  8799. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  8800. const bone = bones[ i ];
  8801. data.bones.push( bone.uuid );
  8802. const boneInverse = boneInverses[ i ];
  8803. data.boneInverses.push( boneInverse.toArray() );
  8804. }
  8805. return data;
  8806. }
  8807. }
  8808. class InstancedBufferAttribute extends BufferAttribute {
  8809. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  8810. super( array, itemSize, normalized );
  8811. this.isInstancedBufferAttribute = true;
  8812. this.meshPerAttribute = meshPerAttribute;
  8813. }
  8814. copy( source ) {
  8815. super.copy( source );
  8816. this.meshPerAttribute = source.meshPerAttribute;
  8817. return this;
  8818. }
  8819. toJSON() {
  8820. const data = super.toJSON();
  8821. data.meshPerAttribute = this.meshPerAttribute;
  8822. data.isInstancedBufferAttribute = true;
  8823. return data;
  8824. }
  8825. }
  8826. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  8827. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  8828. const _instanceIntersects = [];
  8829. const _box3 = /*@__PURE__*/ new Box3();
  8830. const _identity = /*@__PURE__*/ new Matrix4();
  8831. const _mesh$1 = /*@__PURE__*/ new Mesh();
  8832. const _sphere$4 = /*@__PURE__*/ new Sphere();
  8833. class InstancedMesh extends Mesh {
  8834. constructor( geometry, material, count ) {
  8835. super( geometry, material );
  8836. this.isInstancedMesh = true;
  8837. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  8838. this.instanceColor = null;
  8839. this.morphTexture = null;
  8840. this.count = count;
  8841. this.boundingBox = null;
  8842. this.boundingSphere = null;
  8843. for ( let i = 0; i < count; i ++ ) {
  8844. this.setMatrixAt( i, _identity );
  8845. }
  8846. }
  8847. computeBoundingBox() {
  8848. const geometry = this.geometry;
  8849. const count = this.count;
  8850. if ( this.boundingBox === null ) {
  8851. this.boundingBox = new Box3();
  8852. }
  8853. if ( geometry.boundingBox === null ) {
  8854. geometry.computeBoundingBox();
  8855. }
  8856. this.boundingBox.makeEmpty();
  8857. for ( let i = 0; i < count; i ++ ) {
  8858. this.getMatrixAt( i, _instanceLocalMatrix );
  8859. _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
  8860. this.boundingBox.union( _box3 );
  8861. }
  8862. }
  8863. computeBoundingSphere() {
  8864. const geometry = this.geometry;
  8865. const count = this.count;
  8866. if ( this.boundingSphere === null ) {
  8867. this.boundingSphere = new Sphere();
  8868. }
  8869. if ( geometry.boundingSphere === null ) {
  8870. geometry.computeBoundingSphere();
  8871. }
  8872. this.boundingSphere.makeEmpty();
  8873. for ( let i = 0; i < count; i ++ ) {
  8874. this.getMatrixAt( i, _instanceLocalMatrix );
  8875. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
  8876. this.boundingSphere.union( _sphere$4 );
  8877. }
  8878. }
  8879. copy( source, recursive ) {
  8880. super.copy( source, recursive );
  8881. this.instanceMatrix.copy( source.instanceMatrix );
  8882. if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
  8883. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  8884. this.count = source.count;
  8885. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8886. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8887. return this;
  8888. }
  8889. getColorAt( index, color ) {
  8890. color.fromArray( this.instanceColor.array, index * 3 );
  8891. }
  8892. getMatrixAt( index, matrix ) {
  8893. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  8894. }
  8895. getMorphAt( index, object ) {
  8896. const objectInfluences = object.morphTargetInfluences;
  8897. const array = this.morphTexture.source.data.data;
  8898. const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
  8899. const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
  8900. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8901. objectInfluences[ i ] = array[ dataIndex + i ];
  8902. }
  8903. }
  8904. raycast( raycaster, intersects ) {
  8905. const matrixWorld = this.matrixWorld;
  8906. const raycastTimes = this.count;
  8907. _mesh$1.geometry = this.geometry;
  8908. _mesh$1.material = this.material;
  8909. if ( _mesh$1.material === undefined ) return;
  8910. // test with bounding sphere first
  8911. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8912. _sphere$4.copy( this.boundingSphere );
  8913. _sphere$4.applyMatrix4( matrixWorld );
  8914. if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return;
  8915. // now test each instance
  8916. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  8917. // calculate the world matrix for each instance
  8918. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  8919. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  8920. // the mesh represents this single instance
  8921. _mesh$1.matrixWorld = _instanceWorldMatrix;
  8922. _mesh$1.raycast( raycaster, _instanceIntersects );
  8923. // process the result of raycast
  8924. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  8925. const intersect = _instanceIntersects[ i ];
  8926. intersect.instanceId = instanceId;
  8927. intersect.object = this;
  8928. intersects.push( intersect );
  8929. }
  8930. _instanceIntersects.length = 0;
  8931. }
  8932. }
  8933. setColorAt( index, color ) {
  8934. if ( this.instanceColor === null ) {
  8935. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 );
  8936. }
  8937. color.toArray( this.instanceColor.array, index * 3 );
  8938. }
  8939. setMatrixAt( index, matrix ) {
  8940. matrix.toArray( this.instanceMatrix.array, index * 16 );
  8941. }
  8942. setMorphAt( index, object ) {
  8943. const objectInfluences = object.morphTargetInfluences;
  8944. const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
  8945. if ( this.morphTexture === null ) {
  8946. this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
  8947. }
  8948. const array = this.morphTexture.source.data.data;
  8949. let morphInfluencesSum = 0;
  8950. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8951. morphInfluencesSum += objectInfluences[ i ];
  8952. }
  8953. const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  8954. const dataIndex = len * index;
  8955. array[ dataIndex ] = morphBaseInfluence;
  8956. array.set( objectInfluences, dataIndex + 1 );
  8957. }
  8958. updateMorphTargets() {
  8959. }
  8960. dispose() {
  8961. this.dispatchEvent( { type: 'dispose' } );
  8962. if ( this.morphTexture !== null ) {
  8963. this.morphTexture.dispose();
  8964. this.morphTexture = null;
  8965. }
  8966. return this;
  8967. }
  8968. }
  8969. const _vector1 = /*@__PURE__*/ new Vector3();
  8970. const _vector2 = /*@__PURE__*/ new Vector3();
  8971. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  8972. class Plane {
  8973. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  8974. this.isPlane = true;
  8975. // normal is assumed to be normalized
  8976. this.normal = normal;
  8977. this.constant = constant;
  8978. }
  8979. set( normal, constant ) {
  8980. this.normal.copy( normal );
  8981. this.constant = constant;
  8982. return this;
  8983. }
  8984. setComponents( x, y, z, w ) {
  8985. this.normal.set( x, y, z );
  8986. this.constant = w;
  8987. return this;
  8988. }
  8989. setFromNormalAndCoplanarPoint( normal, point ) {
  8990. this.normal.copy( normal );
  8991. this.constant = - point.dot( this.normal );
  8992. return this;
  8993. }
  8994. setFromCoplanarPoints( a, b, c ) {
  8995. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8996. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8997. this.setFromNormalAndCoplanarPoint( normal, a );
  8998. return this;
  8999. }
  9000. copy( plane ) {
  9001. this.normal.copy( plane.normal );
  9002. this.constant = plane.constant;
  9003. return this;
  9004. }
  9005. normalize() {
  9006. // Note: will lead to a divide by zero if the plane is invalid.
  9007. const inverseNormalLength = 1.0 / this.normal.length();
  9008. this.normal.multiplyScalar( inverseNormalLength );
  9009. this.constant *= inverseNormalLength;
  9010. return this;
  9011. }
  9012. negate() {
  9013. this.constant *= - 1;
  9014. this.normal.negate();
  9015. return this;
  9016. }
  9017. distanceToPoint( point ) {
  9018. return this.normal.dot( point ) + this.constant;
  9019. }
  9020. distanceToSphere( sphere ) {
  9021. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9022. }
  9023. projectPoint( point, target ) {
  9024. return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );
  9025. }
  9026. intersectLine( line, target ) {
  9027. const direction = line.delta( _vector1 );
  9028. const denominator = this.normal.dot( direction );
  9029. if ( denominator === 0 ) {
  9030. // line is coplanar, return origin
  9031. if ( this.distanceToPoint( line.start ) === 0 ) {
  9032. return target.copy( line.start );
  9033. }
  9034. // Unsure if this is the correct method to handle this case.
  9035. return null;
  9036. }
  9037. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9038. if ( t < 0 || t > 1 ) {
  9039. return null;
  9040. }
  9041. return target.copy( line.start ).addScaledVector( direction, t );
  9042. }
  9043. intersectsLine( line ) {
  9044. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9045. const startSign = this.distanceToPoint( line.start );
  9046. const endSign = this.distanceToPoint( line.end );
  9047. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9048. }
  9049. intersectsBox( box ) {
  9050. return box.intersectsPlane( this );
  9051. }
  9052. intersectsSphere( sphere ) {
  9053. return sphere.intersectsPlane( this );
  9054. }
  9055. coplanarPoint( target ) {
  9056. return target.copy( this.normal ).multiplyScalar( - this.constant );
  9057. }
  9058. applyMatrix4( matrix, optionalNormalMatrix ) {
  9059. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  9060. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  9061. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9062. this.constant = - referencePoint.dot( normal );
  9063. return this;
  9064. }
  9065. translate( offset ) {
  9066. this.constant -= offset.dot( this.normal );
  9067. return this;
  9068. }
  9069. equals( plane ) {
  9070. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9071. }
  9072. clone() {
  9073. return new this.constructor().copy( this );
  9074. }
  9075. }
  9076. const _sphere$3 = /*@__PURE__*/ new Sphere();
  9077. const _vector$6 = /*@__PURE__*/ new Vector3();
  9078. class Frustum {
  9079. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  9080. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  9081. }
  9082. set( p0, p1, p2, p3, p4, p5 ) {
  9083. const planes = this.planes;
  9084. planes[ 0 ].copy( p0 );
  9085. planes[ 1 ].copy( p1 );
  9086. planes[ 2 ].copy( p2 );
  9087. planes[ 3 ].copy( p3 );
  9088. planes[ 4 ].copy( p4 );
  9089. planes[ 5 ].copy( p5 );
  9090. return this;
  9091. }
  9092. copy( frustum ) {
  9093. const planes = this.planes;
  9094. for ( let i = 0; i < 6; i ++ ) {
  9095. planes[ i ].copy( frustum.planes[ i ] );
  9096. }
  9097. return this;
  9098. }
  9099. setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
  9100. const planes = this.planes;
  9101. const me = m.elements;
  9102. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  9103. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  9104. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  9105. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  9106. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  9107. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  9108. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  9109. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  9110. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  9111. if ( coordinateSystem === WebGLCoordinateSystem ) {
  9112. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  9113. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  9114. planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
  9115. } else {
  9116. throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
  9117. }
  9118. return this;
  9119. }
  9120. intersectsObject( object ) {
  9121. if ( object.boundingSphere !== undefined ) {
  9122. if ( object.boundingSphere === null ) object.computeBoundingSphere();
  9123. _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );
  9124. } else {
  9125. const geometry = object.geometry;
  9126. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9127. _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  9128. }
  9129. return this.intersectsSphere( _sphere$3 );
  9130. }
  9131. intersectsSprite( sprite ) {
  9132. _sphere$3.center.set( 0, 0, 0 );
  9133. _sphere$3.radius = 0.7071067811865476;
  9134. _sphere$3.applyMatrix4( sprite.matrixWorld );
  9135. return this.intersectsSphere( _sphere$3 );
  9136. }
  9137. intersectsSphere( sphere ) {
  9138. const planes = this.planes;
  9139. const center = sphere.center;
  9140. const negRadius = - sphere.radius;
  9141. for ( let i = 0; i < 6; i ++ ) {
  9142. const distance = planes[ i ].distanceToPoint( center );
  9143. if ( distance < negRadius ) {
  9144. return false;
  9145. }
  9146. }
  9147. return true;
  9148. }
  9149. intersectsBox( box ) {
  9150. const planes = this.planes;
  9151. for ( let i = 0; i < 6; i ++ ) {
  9152. const plane = planes[ i ];
  9153. // corner at max distance
  9154. _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  9155. _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  9156. _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  9157. if ( plane.distanceToPoint( _vector$6 ) < 0 ) {
  9158. return false;
  9159. }
  9160. }
  9161. return true;
  9162. }
  9163. containsPoint( point ) {
  9164. const planes = this.planes;
  9165. for ( let i = 0; i < 6; i ++ ) {
  9166. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  9167. return false;
  9168. }
  9169. }
  9170. return true;
  9171. }
  9172. clone() {
  9173. return new this.constructor().copy( this );
  9174. }
  9175. }
  9176. function ascIdSort( a, b ) {
  9177. return a - b;
  9178. }
  9179. function sortOpaque( a, b ) {
  9180. return a.z - b.z;
  9181. }
  9182. function sortTransparent( a, b ) {
  9183. return b.z - a.z;
  9184. }
  9185. class MultiDrawRenderList {
  9186. constructor() {
  9187. this.index = 0;
  9188. this.pool = [];
  9189. this.list = [];
  9190. }
  9191. push( start, count, z, index ) {
  9192. const pool = this.pool;
  9193. const list = this.list;
  9194. if ( this.index >= pool.length ) {
  9195. pool.push( {
  9196. start: - 1,
  9197. count: - 1,
  9198. z: - 1,
  9199. index: - 1,
  9200. } );
  9201. }
  9202. const item = pool[ this.index ];
  9203. list.push( item );
  9204. this.index ++;
  9205. item.start = start;
  9206. item.count = count;
  9207. item.z = z;
  9208. item.index = index;
  9209. }
  9210. reset() {
  9211. this.list.length = 0;
  9212. this.index = 0;
  9213. }
  9214. }
  9215. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  9216. const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
  9217. const _frustum = /*@__PURE__*/ new Frustum();
  9218. const _box$1 = /*@__PURE__*/ new Box3();
  9219. const _sphere$2 = /*@__PURE__*/ new Sphere();
  9220. const _vector$5 = /*@__PURE__*/ new Vector3();
  9221. const _forward = /*@__PURE__*/ new Vector3();
  9222. const _temp = /*@__PURE__*/ new Vector3();
  9223. const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
  9224. const _mesh = /*@__PURE__*/ new Mesh();
  9225. const _batchIntersects = [];
  9226. // copies data from attribute "src" into "target" starting at "targetOffset"
  9227. function copyAttributeData( src, target, targetOffset = 0 ) {
  9228. const itemSize = target.itemSize;
  9229. if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
  9230. // use the component getters and setters if the array data cannot
  9231. // be copied directly
  9232. const vertexCount = src.count;
  9233. for ( let i = 0; i < vertexCount; i ++ ) {
  9234. for ( let c = 0; c < itemSize; c ++ ) {
  9235. target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
  9236. }
  9237. }
  9238. } else {
  9239. // faster copy approach using typed array set function
  9240. target.array.set( src.array, targetOffset * itemSize );
  9241. }
  9242. target.needsUpdate = true;
  9243. }
  9244. // safely copies array contents to a potentially smaller array
  9245. function copyArrayContents( src, target ) {
  9246. if ( src.constructor !== target.constructor ) {
  9247. // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
  9248. const len = Math.min( src.length, target.length );
  9249. for ( let i = 0; i < len; i ++ ) {
  9250. target[ i ] = src[ i ];
  9251. }
  9252. } else {
  9253. // if the arrays use the same data layout we can use a fast block copy
  9254. const len = Math.min( src.length, target.length );
  9255. target.set( new src.constructor( src.buffer, 0, len ) );
  9256. }
  9257. }
  9258. class BatchedMesh extends Mesh {
  9259. get maxInstanceCount() {
  9260. return this._maxInstanceCount;
  9261. }
  9262. get instanceCount() {
  9263. return this._instanceInfo.length - this._availableInstanceIds.length;
  9264. }
  9265. get unusedVertexCount() {
  9266. return this._maxVertexCount - this._nextVertexStart;
  9267. }
  9268. get unusedIndexCount() {
  9269. return this._maxIndexCount - this._nextIndexStart;
  9270. }
  9271. constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
  9272. super( new BufferGeometry(), material );
  9273. this.isBatchedMesh = true;
  9274. this.perObjectFrustumCulled = true;
  9275. this.sortObjects = true;
  9276. this.boundingBox = null;
  9277. this.boundingSphere = null;
  9278. this.customSort = null;
  9279. // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
  9280. this._instanceInfo = [];
  9281. this._geometryInfo = [];
  9282. // instance, geometry ids that have been set as inactive, and are available to be overwritten
  9283. this._availableInstanceIds = [];
  9284. this._availableGeometryIds = [];
  9285. // used to track where the next point is that geometry should be inserted
  9286. this._nextIndexStart = 0;
  9287. this._nextVertexStart = 0;
  9288. this._geometryCount = 0;
  9289. // flags
  9290. this._visibilityChanged = true;
  9291. this._geometryInitialized = false;
  9292. // cached user options
  9293. this._maxInstanceCount = maxInstanceCount;
  9294. this._maxVertexCount = maxVertexCount;
  9295. this._maxIndexCount = maxIndexCount;
  9296. // buffers for multi draw
  9297. this._multiDrawCounts = new Int32Array( maxInstanceCount );
  9298. this._multiDrawStarts = new Int32Array( maxInstanceCount );
  9299. this._multiDrawCount = 0;
  9300. this._multiDrawInstances = null;
  9301. // Local matrix per geometry by using data texture
  9302. this._matricesTexture = null;
  9303. this._indirectTexture = null;
  9304. this._colorsTexture = null;
  9305. this._initMatricesTexture();
  9306. this._initIndirectTexture();
  9307. }
  9308. _initMatricesTexture() {
  9309. // layout (1 matrix = 4 pixels)
  9310. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9311. // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
  9312. // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
  9313. // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
  9314. // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
  9315. let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix
  9316. size = Math.ceil( size / 4 ) * 4;
  9317. size = Math.max( size, 4 );
  9318. const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  9319. const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
  9320. this._matricesTexture = matricesTexture;
  9321. }
  9322. _initIndirectTexture() {
  9323. let size = Math.sqrt( this._maxInstanceCount );
  9324. size = Math.ceil( size );
  9325. const indirectArray = new Uint32Array( size * size );
  9326. const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType );
  9327. this._indirectTexture = indirectTexture;
  9328. }
  9329. _initColorsTexture() {
  9330. let size = Math.sqrt( this._maxInstanceCount );
  9331. size = Math.ceil( size );
  9332. // 4 floats per RGBA pixel initialized to white
  9333. const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
  9334. const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
  9335. colorsTexture.colorSpace = ColorManagement.workingColorSpace;
  9336. this._colorsTexture = colorsTexture;
  9337. }
  9338. _initializeGeometry( reference ) {
  9339. const geometry = this.geometry;
  9340. const maxVertexCount = this._maxVertexCount;
  9341. const maxIndexCount = this._maxIndexCount;
  9342. if ( this._geometryInitialized === false ) {
  9343. for ( const attributeName in reference.attributes ) {
  9344. const srcAttribute = reference.getAttribute( attributeName );
  9345. const { array, itemSize, normalized } = srcAttribute;
  9346. const dstArray = new array.constructor( maxVertexCount * itemSize );
  9347. const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized );
  9348. geometry.setAttribute( attributeName, dstAttribute );
  9349. }
  9350. if ( reference.getIndex() !== null ) {
  9351. // Reserve last u16 index for primitive restart.
  9352. const indexArray = maxVertexCount > 65535
  9353. ? new Uint32Array( maxIndexCount )
  9354. : new Uint16Array( maxIndexCount );
  9355. geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
  9356. }
  9357. this._geometryInitialized = true;
  9358. }
  9359. }
  9360. // Make sure the geometry is compatible with the existing combined geometry attributes
  9361. _validateGeometry( geometry ) {
  9362. // check to ensure the geometries are using consistent attributes and indices
  9363. const batchGeometry = this.geometry;
  9364. if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
  9365. throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
  9366. }
  9367. for ( const attributeName in batchGeometry.attributes ) {
  9368. if ( ! geometry.hasAttribute( attributeName ) ) {
  9369. throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
  9370. }
  9371. const srcAttribute = geometry.getAttribute( attributeName );
  9372. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9373. if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
  9374. throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
  9375. }
  9376. }
  9377. }
  9378. validateInstanceId( instanceId ) {
  9379. const instanceInfo = this._instanceInfo;
  9380. if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
  9381. throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
  9382. }
  9383. }
  9384. validateGeometryId( geometryId ) {
  9385. const geometryInfoList = this._geometryInfo;
  9386. if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9387. throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
  9388. }
  9389. }
  9390. setCustomSort( func ) {
  9391. this.customSort = func;
  9392. return this;
  9393. }
  9394. computeBoundingBox() {
  9395. if ( this.boundingBox === null ) {
  9396. this.boundingBox = new Box3();
  9397. }
  9398. const boundingBox = this.boundingBox;
  9399. const instanceInfo = this._instanceInfo;
  9400. boundingBox.makeEmpty();
  9401. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9402. if ( instanceInfo[ i ].active === false ) continue;
  9403. const geometryId = instanceInfo[ i ].geometryIndex;
  9404. this.getMatrixAt( i, _matrix$1 );
  9405. this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
  9406. boundingBox.union( _box$1 );
  9407. }
  9408. }
  9409. computeBoundingSphere() {
  9410. if ( this.boundingSphere === null ) {
  9411. this.boundingSphere = new Sphere();
  9412. }
  9413. const boundingSphere = this.boundingSphere;
  9414. const instanceInfo = this._instanceInfo;
  9415. boundingSphere.makeEmpty();
  9416. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9417. if ( instanceInfo[ i ].active === false ) continue;
  9418. const geometryId = instanceInfo[ i ].geometryIndex;
  9419. this.getMatrixAt( i, _matrix$1 );
  9420. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9421. boundingSphere.union( _sphere$2 );
  9422. }
  9423. }
  9424. addInstance( geometryId ) {
  9425. const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
  9426. // ensure we're not over geometry
  9427. if ( atCapacity && this._availableInstanceIds.length === 0 ) {
  9428. throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
  9429. }
  9430. const instanceInfo = {
  9431. visible: true,
  9432. active: true,
  9433. geometryIndex: geometryId,
  9434. };
  9435. let drawId = null;
  9436. // Prioritize using previously freed instance ids
  9437. if ( this._availableInstanceIds.length > 0 ) {
  9438. this._availableInstanceIds.sort( ascIdSort );
  9439. drawId = this._availableInstanceIds.shift();
  9440. this._instanceInfo[ drawId ] = instanceInfo;
  9441. } else {
  9442. drawId = this._instanceInfo.length;
  9443. this._instanceInfo.push( instanceInfo );
  9444. }
  9445. const matricesTexture = this._matricesTexture;
  9446. _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
  9447. matricesTexture.needsUpdate = true;
  9448. const colorsTexture = this._colorsTexture;
  9449. if ( colorsTexture ) {
  9450. _whiteColor.toArray( colorsTexture.image.data, drawId * 4 );
  9451. colorsTexture.needsUpdate = true;
  9452. }
  9453. this._visibilityChanged = true;
  9454. return drawId;
  9455. }
  9456. addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
  9457. this._initializeGeometry( geometry );
  9458. this._validateGeometry( geometry );
  9459. const geometryInfo = {
  9460. // geometry information
  9461. vertexStart: - 1,
  9462. vertexCount: - 1,
  9463. reservedVertexCount: - 1,
  9464. indexStart: - 1,
  9465. indexCount: - 1,
  9466. reservedIndexCount: - 1,
  9467. // draw range information
  9468. start: - 1,
  9469. count: - 1,
  9470. // state
  9471. boundingBox: null,
  9472. boundingSphere: null,
  9473. active: true,
  9474. };
  9475. const geometryInfoList = this._geometryInfo;
  9476. geometryInfo.vertexStart = this._nextVertexStart;
  9477. geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
  9478. const index = geometry.getIndex();
  9479. const hasIndex = index !== null;
  9480. if ( hasIndex ) {
  9481. geometryInfo.indexStart = this._nextIndexStart;
  9482. geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
  9483. }
  9484. if (
  9485. geometryInfo.indexStart !== - 1 &&
  9486. geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
  9487. geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
  9488. ) {
  9489. throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
  9490. }
  9491. // update id
  9492. let geometryId;
  9493. if ( this._availableGeometryIds.length > 0 ) {
  9494. this._availableGeometryIds.sort( ascIdSort );
  9495. geometryId = this._availableGeometryIds.shift();
  9496. geometryInfoList[ geometryId ] = geometryInfo;
  9497. } else {
  9498. geometryId = this._geometryCount;
  9499. this._geometryCount ++;
  9500. geometryInfoList.push( geometryInfo );
  9501. }
  9502. // update the geometry
  9503. this.setGeometryAt( geometryId, geometry );
  9504. // increment the next geometry position
  9505. this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
  9506. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9507. return geometryId;
  9508. }
  9509. setGeometryAt( geometryId, geometry ) {
  9510. if ( geometryId >= this._geometryCount ) {
  9511. throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
  9512. }
  9513. this._validateGeometry( geometry );
  9514. const batchGeometry = this.geometry;
  9515. const hasIndex = batchGeometry.getIndex() !== null;
  9516. const dstIndex = batchGeometry.getIndex();
  9517. const srcIndex = geometry.getIndex();
  9518. const geometryInfo = this._geometryInfo[ geometryId ];
  9519. if (
  9520. hasIndex &&
  9521. srcIndex.count > geometryInfo.reservedIndexCount ||
  9522. geometry.attributes.position.count > geometryInfo.reservedVertexCount
  9523. ) {
  9524. throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
  9525. }
  9526. // copy geometry buffer data over
  9527. const vertexStart = geometryInfo.vertexStart;
  9528. const reservedVertexCount = geometryInfo.reservedVertexCount;
  9529. geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
  9530. for ( const attributeName in batchGeometry.attributes ) {
  9531. // copy attribute data
  9532. const srcAttribute = geometry.getAttribute( attributeName );
  9533. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9534. copyAttributeData( srcAttribute, dstAttribute, vertexStart );
  9535. // fill the rest in with zeroes
  9536. const itemSize = srcAttribute.itemSize;
  9537. for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
  9538. const index = vertexStart + i;
  9539. for ( let c = 0; c < itemSize; c ++ ) {
  9540. dstAttribute.setComponent( index, c, 0 );
  9541. }
  9542. }
  9543. dstAttribute.needsUpdate = true;
  9544. dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
  9545. }
  9546. // copy index
  9547. if ( hasIndex ) {
  9548. const indexStart = geometryInfo.indexStart;
  9549. const reservedIndexCount = geometryInfo.reservedIndexCount;
  9550. geometryInfo.indexCount = geometry.getIndex().count;
  9551. // copy index data over
  9552. for ( let i = 0; i < srcIndex.count; i ++ ) {
  9553. dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) );
  9554. }
  9555. // fill the rest in with zeroes
  9556. for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
  9557. dstIndex.setX( indexStart + i, vertexStart );
  9558. }
  9559. dstIndex.needsUpdate = true;
  9560. dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
  9561. }
  9562. // update the draw range
  9563. geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9564. geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
  9565. // store the bounding boxes
  9566. geometryInfo.boundingBox = null;
  9567. if ( geometry.boundingBox !== null ) {
  9568. geometryInfo.boundingBox = geometry.boundingBox.clone();
  9569. }
  9570. geometryInfo.boundingSphere = null;
  9571. if ( geometry.boundingSphere !== null ) {
  9572. geometryInfo.boundingSphere = geometry.boundingSphere.clone();
  9573. }
  9574. this._visibilityChanged = true;
  9575. return geometryId;
  9576. }
  9577. deleteGeometry( geometryId ) {
  9578. const geometryInfoList = this._geometryInfo;
  9579. if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9580. return this;
  9581. }
  9582. // delete any instances associated with this geometry
  9583. const instanceInfo = this._instanceInfo;
  9584. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9585. if ( instanceInfo[ i ].active && instanceInfo[ i ].geometryIndex === geometryId ) {
  9586. this.deleteInstance( i );
  9587. }
  9588. }
  9589. geometryInfoList[ geometryId ].active = false;
  9590. this._availableGeometryIds.push( geometryId );
  9591. this._visibilityChanged = true;
  9592. return this;
  9593. }
  9594. deleteInstance( instanceId ) {
  9595. this.validateInstanceId( instanceId );
  9596. this._instanceInfo[ instanceId ].active = false;
  9597. this._availableInstanceIds.push( instanceId );
  9598. this._visibilityChanged = true;
  9599. return this;
  9600. }
  9601. optimize() {
  9602. // track the next indices to copy data to
  9603. let nextVertexStart = 0;
  9604. let nextIndexStart = 0;
  9605. // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
  9606. // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
  9607. const geometryInfoList = this._geometryInfo;
  9608. const indices = geometryInfoList
  9609. .map( ( e, i ) => i )
  9610. .sort( ( a, b ) => {
  9611. return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
  9612. } );
  9613. const geometry = this.geometry;
  9614. for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
  9615. // if a geometry range is inactive then don't copy anything
  9616. const index = indices[ i ];
  9617. const geometryInfo = geometryInfoList[ index ];
  9618. if ( geometryInfo.active === false ) {
  9619. continue;
  9620. }
  9621. // if a geometry contains an index buffer then shift it, as well
  9622. if ( geometry.index !== null ) {
  9623. if ( geometryInfo.indexStart !== nextIndexStart ) {
  9624. const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
  9625. const index = geometry.index;
  9626. const array = index.array;
  9627. // shift the index pointers based on how the vertex data will shift
  9628. // adjusting the index must happen first so the original vertex start value is available
  9629. const elementDelta = nextVertexStart - vertexStart;
  9630. for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
  9631. array[ j ] = array[ j ] + elementDelta;
  9632. }
  9633. index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
  9634. index.addUpdateRange( nextIndexStart, reservedIndexCount );
  9635. geometryInfo.indexStart = nextIndexStart;
  9636. }
  9637. nextIndexStart += geometryInfo.reservedIndexCount;
  9638. }
  9639. // if a geometry needs to be moved then copy attribute data to overwrite unused space
  9640. if ( geometryInfo.vertexStart !== nextVertexStart ) {
  9641. const { vertexStart, reservedVertexCount } = geometryInfo;
  9642. const attributes = geometry.attributes;
  9643. for ( const key in attributes ) {
  9644. const attribute = attributes[ key ];
  9645. const { array, itemSize } = attribute;
  9646. array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
  9647. attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
  9648. }
  9649. geometryInfo.vertexStart = nextVertexStart;
  9650. }
  9651. nextVertexStart += geometryInfo.reservedVertexCount;
  9652. geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9653. // step the next geometry points to the shifted position
  9654. this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
  9655. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9656. }
  9657. return this;
  9658. }
  9659. // get bounding box and compute it if it doesn't exist
  9660. getBoundingBoxAt( geometryId, target ) {
  9661. if ( geometryId >= this._geometryCount ) {
  9662. return null;
  9663. }
  9664. // compute bounding box
  9665. const geometry = this.geometry;
  9666. const geometryInfo = this._geometryInfo[ geometryId ];
  9667. if ( geometryInfo.boundingBox === null ) {
  9668. const box = new Box3();
  9669. const index = geometry.index;
  9670. const position = geometry.attributes.position;
  9671. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9672. let iv = i;
  9673. if ( index ) {
  9674. iv = index.getX( iv );
  9675. }
  9676. box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) );
  9677. }
  9678. geometryInfo.boundingBox = box;
  9679. }
  9680. target.copy( geometryInfo.boundingBox );
  9681. return target;
  9682. }
  9683. // get bounding sphere and compute it if it doesn't exist
  9684. getBoundingSphereAt( geometryId, target ) {
  9685. if ( geometryId >= this._geometryCount ) {
  9686. return null;
  9687. }
  9688. // compute bounding sphere
  9689. const geometry = this.geometry;
  9690. const geometryInfo = this._geometryInfo[ geometryId ];
  9691. if ( geometryInfo.boundingSphere === null ) {
  9692. const sphere = new Sphere();
  9693. this.getBoundingBoxAt( geometryId, _box$1 );
  9694. _box$1.getCenter( sphere.center );
  9695. const index = geometry.index;
  9696. const position = geometry.attributes.position;
  9697. let maxRadiusSq = 0;
  9698. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9699. let iv = i;
  9700. if ( index ) {
  9701. iv = index.getX( iv );
  9702. }
  9703. _vector$5.fromBufferAttribute( position, iv );
  9704. maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) );
  9705. }
  9706. sphere.radius = Math.sqrt( maxRadiusSq );
  9707. geometryInfo.boundingSphere = sphere;
  9708. }
  9709. target.copy( geometryInfo.boundingSphere );
  9710. return target;
  9711. }
  9712. setMatrixAt( instanceId, matrix ) {
  9713. this.validateInstanceId( instanceId );
  9714. const matricesTexture = this._matricesTexture;
  9715. const matricesArray = this._matricesTexture.image.data;
  9716. matrix.toArray( matricesArray, instanceId * 16 );
  9717. matricesTexture.needsUpdate = true;
  9718. return this;
  9719. }
  9720. getMatrixAt( instanceId, matrix ) {
  9721. this.validateInstanceId( instanceId );
  9722. return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
  9723. }
  9724. setColorAt( instanceId, color ) {
  9725. this.validateInstanceId( instanceId );
  9726. if ( this._colorsTexture === null ) {
  9727. this._initColorsTexture();
  9728. }
  9729. color.toArray( this._colorsTexture.image.data, instanceId * 4 );
  9730. this._colorsTexture.needsUpdate = true;
  9731. return this;
  9732. }
  9733. getColorAt( instanceId, color ) {
  9734. this.validateInstanceId( instanceId );
  9735. return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
  9736. }
  9737. setVisibleAt( instanceId, value ) {
  9738. this.validateInstanceId( instanceId );
  9739. if ( this._instanceInfo[ instanceId ].visible === value ) {
  9740. return this;
  9741. }
  9742. this._instanceInfo[ instanceId ].visible = value;
  9743. this._visibilityChanged = true;
  9744. return this;
  9745. }
  9746. getVisibleAt( instanceId ) {
  9747. this.validateInstanceId( instanceId );
  9748. return this._instanceInfo[ instanceId ].visible;
  9749. }
  9750. setGeometryIdAt( instanceId, geometryId ) {
  9751. this.validateInstanceId( instanceId );
  9752. this.validateGeometryId( geometryId );
  9753. this._instanceInfo[ instanceId ].geometryIndex = geometryId;
  9754. return this;
  9755. }
  9756. getGeometryIdAt( instanceId ) {
  9757. this.validateInstanceId( instanceId );
  9758. return this._instanceInfo[ instanceId ].geometryIndex;
  9759. }
  9760. getGeometryRangeAt( geometryId, target = {} ) {
  9761. this.validateGeometryId( geometryId );
  9762. const geometryInfo = this._geometryInfo[ geometryId ];
  9763. target.vertexStart = geometryInfo.vertexStart;
  9764. target.vertexCount = geometryInfo.vertexCount;
  9765. target.reservedVertexCount = geometryInfo.reservedVertexCount;
  9766. target.indexStart = geometryInfo.indexStart;
  9767. target.indexCount = geometryInfo.indexCount;
  9768. target.reservedIndexCount = geometryInfo.reservedIndexCount;
  9769. target.start = geometryInfo.start;
  9770. target.count = geometryInfo.count;
  9771. return target;
  9772. }
  9773. setInstanceCount( maxInstanceCount ) {
  9774. // shrink the available instances as much as possible
  9775. const availableInstanceIds = this._availableInstanceIds;
  9776. const instanceInfo = this._instanceInfo;
  9777. availableInstanceIds.sort( ascIdSort );
  9778. while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
  9779. instanceInfo.pop();
  9780. availableInstanceIds.pop();
  9781. }
  9782. // throw an error if it can't be shrunk to the desired size
  9783. if ( maxInstanceCount < instanceInfo.length ) {
  9784. throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
  9785. }
  9786. // copy the multi draw counts
  9787. const multiDrawCounts = new Int32Array( maxInstanceCount );
  9788. const multiDrawStarts = new Int32Array( maxInstanceCount );
  9789. copyArrayContents( this._multiDrawCounts, multiDrawCounts );
  9790. copyArrayContents( this._multiDrawStarts, multiDrawStarts );
  9791. this._multiDrawCounts = multiDrawCounts;
  9792. this._multiDrawStarts = multiDrawStarts;
  9793. this._maxInstanceCount = maxInstanceCount;
  9794. // update texture data for instance sampling
  9795. const indirectTexture = this._indirectTexture;
  9796. const matricesTexture = this._matricesTexture;
  9797. const colorsTexture = this._colorsTexture;
  9798. indirectTexture.dispose();
  9799. this._initIndirectTexture();
  9800. copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
  9801. matricesTexture.dispose();
  9802. this._initMatricesTexture();
  9803. copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
  9804. if ( colorsTexture ) {
  9805. colorsTexture.dispose();
  9806. this._initColorsTexture();
  9807. copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
  9808. }
  9809. }
  9810. setGeometrySize( maxVertexCount, maxIndexCount ) {
  9811. // Check if we can shrink to the requested vertex attribute size
  9812. const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
  9813. const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
  9814. if ( requiredVertexLength > maxVertexCount ) {
  9815. throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9816. }
  9817. // Check if we can shrink to the requested index attribute size
  9818. if ( this.geometry.index ) {
  9819. const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
  9820. if ( requiredIndexLength > maxIndexCount ) {
  9821. throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9822. }
  9823. }
  9824. //
  9825. // dispose of the previous geometry
  9826. const oldGeometry = this.geometry;
  9827. oldGeometry.dispose();
  9828. // recreate the geometry needed based on the previous variant
  9829. this._maxVertexCount = maxVertexCount;
  9830. this._maxIndexCount = maxIndexCount;
  9831. if ( this._geometryInitialized ) {
  9832. this._geometryInitialized = false;
  9833. this.geometry = new BufferGeometry();
  9834. this._initializeGeometry( oldGeometry );
  9835. }
  9836. // copy data from the previous geometry
  9837. const geometry = this.geometry;
  9838. if ( oldGeometry.index ) {
  9839. copyArrayContents( oldGeometry.index.array, geometry.index.array );
  9840. }
  9841. for ( const key in oldGeometry.attributes ) {
  9842. copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
  9843. }
  9844. }
  9845. raycast( raycaster, intersects ) {
  9846. const instanceInfo = this._instanceInfo;
  9847. const geometryInfoList = this._geometryInfo;
  9848. const matrixWorld = this.matrixWorld;
  9849. const batchGeometry = this.geometry;
  9850. // iterate over each geometry
  9851. _mesh.material = this.material;
  9852. _mesh.geometry.index = batchGeometry.index;
  9853. _mesh.geometry.attributes = batchGeometry.attributes;
  9854. if ( _mesh.geometry.boundingBox === null ) {
  9855. _mesh.geometry.boundingBox = new Box3();
  9856. }
  9857. if ( _mesh.geometry.boundingSphere === null ) {
  9858. _mesh.geometry.boundingSphere = new Sphere();
  9859. }
  9860. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9861. if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
  9862. continue;
  9863. }
  9864. const geometryId = instanceInfo[ i ].geometryIndex;
  9865. const geometryInfo = geometryInfoList[ geometryId ];
  9866. _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
  9867. // get the intersects
  9868. this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
  9869. this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
  9870. this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
  9871. _mesh.raycast( raycaster, _batchIntersects );
  9872. // add batch id to the intersects
  9873. for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) {
  9874. const intersect = _batchIntersects[ j ];
  9875. intersect.object = this;
  9876. intersect.batchId = i;
  9877. intersects.push( intersect );
  9878. }
  9879. _batchIntersects.length = 0;
  9880. }
  9881. _mesh.material = null;
  9882. _mesh.geometry.index = null;
  9883. _mesh.geometry.attributes = {};
  9884. _mesh.geometry.setDrawRange( 0, Infinity );
  9885. }
  9886. copy( source ) {
  9887. super.copy( source );
  9888. this.geometry = source.geometry.clone();
  9889. this.perObjectFrustumCulled = source.perObjectFrustumCulled;
  9890. this.sortObjects = source.sortObjects;
  9891. this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
  9892. this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
  9893. this._geometryInfo = source._geometryInfo.map( info => ( {
  9894. ...info,
  9895. boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
  9896. boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
  9897. } ) );
  9898. this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
  9899. this._maxInstanceCount = source._maxInstanceCount;
  9900. this._maxVertexCount = source._maxVertexCount;
  9901. this._maxIndexCount = source._maxIndexCount;
  9902. this._geometryInitialized = source._geometryInitialized;
  9903. this._geometryCount = source._geometryCount;
  9904. this._multiDrawCounts = source._multiDrawCounts.slice();
  9905. this._multiDrawStarts = source._multiDrawStarts.slice();
  9906. this._matricesTexture = source._matricesTexture.clone();
  9907. this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
  9908. if ( this._colorsTexture !== null ) {
  9909. this._colorsTexture = source._colorsTexture.clone();
  9910. this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
  9911. }
  9912. return this;
  9913. }
  9914. dispose() {
  9915. // Assuming the geometry is not shared with other meshes
  9916. this.geometry.dispose();
  9917. this._matricesTexture.dispose();
  9918. this._matricesTexture = null;
  9919. this._indirectTexture.dispose();
  9920. this._indirectTexture = null;
  9921. if ( this._colorsTexture !== null ) {
  9922. this._colorsTexture.dispose();
  9923. this._colorsTexture = null;
  9924. }
  9925. return this;
  9926. }
  9927. onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
  9928. // if visibility has not changed and frustum culling and object sorting is not required
  9929. // then skip iterating over all items
  9930. if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) {
  9931. return;
  9932. }
  9933. // the indexed version of the multi draw function requires specifying the start
  9934. // offset in bytes.
  9935. const index = geometry.getIndex();
  9936. const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
  9937. const instanceInfo = this._instanceInfo;
  9938. const multiDrawStarts = this._multiDrawStarts;
  9939. const multiDrawCounts = this._multiDrawCounts;
  9940. const geometryInfoList = this._geometryInfo;
  9941. const perObjectFrustumCulled = this.perObjectFrustumCulled;
  9942. const indirectTexture = this._indirectTexture;
  9943. const indirectArray = indirectTexture.image.data;
  9944. // prepare the frustum in the local frame
  9945. if ( perObjectFrustumCulled ) {
  9946. _matrix$1
  9947. .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
  9948. .multiply( this.matrixWorld );
  9949. _frustum.setFromProjectionMatrix(
  9950. _matrix$1,
  9951. renderer.coordinateSystem
  9952. );
  9953. }
  9954. let multiDrawCount = 0;
  9955. if ( this.sortObjects ) {
  9956. // get the camera position in the local frame
  9957. _matrix$1.copy( this.matrixWorld ).invert();
  9958. _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
  9959. _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
  9960. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9961. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9962. const geometryId = instanceInfo[ i ].geometryIndex;
  9963. // get the bounds in world space
  9964. this.getMatrixAt( i, _matrix$1 );
  9965. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9966. // determine whether the batched geometry is within the frustum
  9967. let culled = false;
  9968. if ( perObjectFrustumCulled ) {
  9969. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9970. }
  9971. if ( ! culled ) {
  9972. // get the distance from camera used for sorting
  9973. const geometryInfo = geometryInfoList[ geometryId ];
  9974. const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
  9975. _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
  9976. }
  9977. }
  9978. }
  9979. // Sort the draw ranges and prep for rendering
  9980. const list = _renderList.list;
  9981. const customSort = this.customSort;
  9982. if ( customSort === null ) {
  9983. list.sort( material.transparent ? sortTransparent : sortOpaque );
  9984. } else {
  9985. customSort.call( this, list, camera );
  9986. }
  9987. for ( let i = 0, l = list.length; i < l; i ++ ) {
  9988. const item = list[ i ];
  9989. multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
  9990. multiDrawCounts[ multiDrawCount ] = item.count;
  9991. indirectArray[ multiDrawCount ] = item.index;
  9992. multiDrawCount ++;
  9993. }
  9994. _renderList.reset();
  9995. } else {
  9996. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9997. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9998. const geometryId = instanceInfo[ i ].geometryIndex;
  9999. // determine whether the batched geometry is within the frustum
  10000. let culled = false;
  10001. if ( perObjectFrustumCulled ) {
  10002. // get the bounds in world space
  10003. this.getMatrixAt( i, _matrix$1 );
  10004. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  10005. culled = ! _frustum.intersectsSphere( _sphere$2 );
  10006. }
  10007. if ( ! culled ) {
  10008. const geometryInfo = geometryInfoList[ geometryId ];
  10009. multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
  10010. multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
  10011. indirectArray[ multiDrawCount ] = i;
  10012. multiDrawCount ++;
  10013. }
  10014. }
  10015. }
  10016. }
  10017. indirectTexture.needsUpdate = true;
  10018. this._multiDrawCount = multiDrawCount;
  10019. this._visibilityChanged = false;
  10020. }
  10021. onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) {
  10022. this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial );
  10023. }
  10024. }
  10025. class LineBasicMaterial extends Material {
  10026. constructor( parameters ) {
  10027. super();
  10028. this.isLineBasicMaterial = true;
  10029. this.type = 'LineBasicMaterial';
  10030. this.color = new Color( 0xffffff );
  10031. this.map = null;
  10032. this.linewidth = 1;
  10033. this.linecap = 'round';
  10034. this.linejoin = 'round';
  10035. this.fog = true;
  10036. this.setValues( parameters );
  10037. }
  10038. copy( source ) {
  10039. super.copy( source );
  10040. this.color.copy( source.color );
  10041. this.map = source.map;
  10042. this.linewidth = source.linewidth;
  10043. this.linecap = source.linecap;
  10044. this.linejoin = source.linejoin;
  10045. this.fog = source.fog;
  10046. return this;
  10047. }
  10048. }
  10049. const _vStart = /*@__PURE__*/ new Vector3();
  10050. const _vEnd = /*@__PURE__*/ new Vector3();
  10051. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  10052. const _ray$1 = /*@__PURE__*/ new Ray();
  10053. const _sphere$1 = /*@__PURE__*/ new Sphere();
  10054. const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
  10055. const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
  10056. class Line extends Object3D {
  10057. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  10058. super();
  10059. this.isLine = true;
  10060. this.type = 'Line';
  10061. this.geometry = geometry;
  10062. this.material = material;
  10063. this.updateMorphTargets();
  10064. }
  10065. copy( source, recursive ) {
  10066. super.copy( source, recursive );
  10067. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10068. this.geometry = source.geometry;
  10069. return this;
  10070. }
  10071. computeLineDistances() {
  10072. const geometry = this.geometry;
  10073. // we assume non-indexed geometry
  10074. if ( geometry.index === null ) {
  10075. const positionAttribute = geometry.attributes.position;
  10076. const lineDistances = [ 0 ];
  10077. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  10078. _vStart.fromBufferAttribute( positionAttribute, i - 1 );
  10079. _vEnd.fromBufferAttribute( positionAttribute, i );
  10080. lineDistances[ i ] = lineDistances[ i - 1 ];
  10081. lineDistances[ i ] += _vStart.distanceTo( _vEnd );
  10082. }
  10083. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10084. } else {
  10085. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10086. }
  10087. return this;
  10088. }
  10089. raycast( raycaster, intersects ) {
  10090. const geometry = this.geometry;
  10091. const matrixWorld = this.matrixWorld;
  10092. const threshold = raycaster.params.Line.threshold;
  10093. const drawRange = geometry.drawRange;
  10094. // Checking boundingSphere distance to ray
  10095. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10096. _sphere$1.copy( geometry.boundingSphere );
  10097. _sphere$1.applyMatrix4( matrixWorld );
  10098. _sphere$1.radius += threshold;
  10099. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  10100. //
  10101. _inverseMatrix$1.copy( matrixWorld ).invert();
  10102. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  10103. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10104. const localThresholdSq = localThreshold * localThreshold;
  10105. const step = this.isLineSegments ? 2 : 1;
  10106. const index = geometry.index;
  10107. const attributes = geometry.attributes;
  10108. const positionAttribute = attributes.position;
  10109. if ( index !== null ) {
  10110. const start = Math.max( 0, drawRange.start );
  10111. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10112. for ( let i = start, l = end - 1; i < l; i += step ) {
  10113. const a = index.getX( i );
  10114. const b = index.getX( i + 1 );
  10115. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10116. if ( intersect ) {
  10117. intersects.push( intersect );
  10118. }
  10119. }
  10120. if ( this.isLineLoop ) {
  10121. const a = index.getX( end - 1 );
  10122. const b = index.getX( start );
  10123. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10124. if ( intersect ) {
  10125. intersects.push( intersect );
  10126. }
  10127. }
  10128. } else {
  10129. const start = Math.max( 0, drawRange.start );
  10130. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10131. for ( let i = start, l = end - 1; i < l; i += step ) {
  10132. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
  10133. if ( intersect ) {
  10134. intersects.push( intersect );
  10135. }
  10136. }
  10137. if ( this.isLineLoop ) {
  10138. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
  10139. if ( intersect ) {
  10140. intersects.push( intersect );
  10141. }
  10142. }
  10143. }
  10144. }
  10145. updateMorphTargets() {
  10146. const geometry = this.geometry;
  10147. const morphAttributes = geometry.morphAttributes;
  10148. const keys = Object.keys( morphAttributes );
  10149. if ( keys.length > 0 ) {
  10150. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10151. if ( morphAttribute !== undefined ) {
  10152. this.morphTargetInfluences = [];
  10153. this.morphTargetDictionary = {};
  10154. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10155. const name = morphAttribute[ m ].name || String( m );
  10156. this.morphTargetInfluences.push( 0 );
  10157. this.morphTargetDictionary[ name ] = m;
  10158. }
  10159. }
  10160. }
  10161. }
  10162. }
  10163. function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
  10164. const positionAttribute = object.geometry.attributes.position;
  10165. _vStart.fromBufferAttribute( positionAttribute, a );
  10166. _vEnd.fromBufferAttribute( positionAttribute, b );
  10167. const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
  10168. if ( distSq > thresholdSq ) return;
  10169. _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
  10170. const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
  10171. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10172. return {
  10173. distance: distance,
  10174. // What do we want? intersection point on the ray or on the segment??
  10175. // point: raycaster.ray.at( distance ),
  10176. point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
  10177. index: a,
  10178. face: null,
  10179. faceIndex: null,
  10180. barycoord: null,
  10181. object: object
  10182. };
  10183. }
  10184. const _start = /*@__PURE__*/ new Vector3();
  10185. const _end = /*@__PURE__*/ new Vector3();
  10186. class LineSegments extends Line {
  10187. constructor( geometry, material ) {
  10188. super( geometry, material );
  10189. this.isLineSegments = true;
  10190. this.type = 'LineSegments';
  10191. }
  10192. computeLineDistances() {
  10193. const geometry = this.geometry;
  10194. // we assume non-indexed geometry
  10195. if ( geometry.index === null ) {
  10196. const positionAttribute = geometry.attributes.position;
  10197. const lineDistances = [];
  10198. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  10199. _start.fromBufferAttribute( positionAttribute, i );
  10200. _end.fromBufferAttribute( positionAttribute, i + 1 );
  10201. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  10202. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  10203. }
  10204. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10205. } else {
  10206. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10207. }
  10208. return this;
  10209. }
  10210. }
  10211. class LineLoop extends Line {
  10212. constructor( geometry, material ) {
  10213. super( geometry, material );
  10214. this.isLineLoop = true;
  10215. this.type = 'LineLoop';
  10216. }
  10217. }
  10218. class PointsMaterial extends Material {
  10219. constructor( parameters ) {
  10220. super();
  10221. this.isPointsMaterial = true;
  10222. this.type = 'PointsMaterial';
  10223. this.color = new Color( 0xffffff );
  10224. this.map = null;
  10225. this.alphaMap = null;
  10226. this.size = 1;
  10227. this.sizeAttenuation = true;
  10228. this.fog = true;
  10229. this.setValues( parameters );
  10230. }
  10231. copy( source ) {
  10232. super.copy( source );
  10233. this.color.copy( source.color );
  10234. this.map = source.map;
  10235. this.alphaMap = source.alphaMap;
  10236. this.size = source.size;
  10237. this.sizeAttenuation = source.sizeAttenuation;
  10238. this.fog = source.fog;
  10239. return this;
  10240. }
  10241. }
  10242. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  10243. const _ray = /*@__PURE__*/ new Ray();
  10244. const _sphere = /*@__PURE__*/ new Sphere();
  10245. const _position$2 = /*@__PURE__*/ new Vector3();
  10246. class Points extends Object3D {
  10247. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  10248. super();
  10249. this.isPoints = true;
  10250. this.type = 'Points';
  10251. this.geometry = geometry;
  10252. this.material = material;
  10253. this.updateMorphTargets();
  10254. }
  10255. copy( source, recursive ) {
  10256. super.copy( source, recursive );
  10257. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10258. this.geometry = source.geometry;
  10259. return this;
  10260. }
  10261. raycast( raycaster, intersects ) {
  10262. const geometry = this.geometry;
  10263. const matrixWorld = this.matrixWorld;
  10264. const threshold = raycaster.params.Points.threshold;
  10265. const drawRange = geometry.drawRange;
  10266. // Checking boundingSphere distance to ray
  10267. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10268. _sphere.copy( geometry.boundingSphere );
  10269. _sphere.applyMatrix4( matrixWorld );
  10270. _sphere.radius += threshold;
  10271. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  10272. //
  10273. _inverseMatrix.copy( matrixWorld ).invert();
  10274. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  10275. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10276. const localThresholdSq = localThreshold * localThreshold;
  10277. const index = geometry.index;
  10278. const attributes = geometry.attributes;
  10279. const positionAttribute = attributes.position;
  10280. if ( index !== null ) {
  10281. const start = Math.max( 0, drawRange.start );
  10282. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10283. for ( let i = start, il = end; i < il; i ++ ) {
  10284. const a = index.getX( i );
  10285. _position$2.fromBufferAttribute( positionAttribute, a );
  10286. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10287. }
  10288. } else {
  10289. const start = Math.max( 0, drawRange.start );
  10290. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10291. for ( let i = start, l = end; i < l; i ++ ) {
  10292. _position$2.fromBufferAttribute( positionAttribute, i );
  10293. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10294. }
  10295. }
  10296. }
  10297. updateMorphTargets() {
  10298. const geometry = this.geometry;
  10299. const morphAttributes = geometry.morphAttributes;
  10300. const keys = Object.keys( morphAttributes );
  10301. if ( keys.length > 0 ) {
  10302. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10303. if ( morphAttribute !== undefined ) {
  10304. this.morphTargetInfluences = [];
  10305. this.morphTargetDictionary = {};
  10306. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10307. const name = morphAttribute[ m ].name || String( m );
  10308. this.morphTargetInfluences.push( 0 );
  10309. this.morphTargetDictionary[ name ] = m;
  10310. }
  10311. }
  10312. }
  10313. }
  10314. }
  10315. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  10316. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  10317. if ( rayPointDistanceSq < localThresholdSq ) {
  10318. const intersectPoint = new Vector3();
  10319. _ray.closestPointToPoint( point, intersectPoint );
  10320. intersectPoint.applyMatrix4( matrixWorld );
  10321. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10322. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10323. intersects.push( {
  10324. distance: distance,
  10325. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10326. point: intersectPoint,
  10327. index: index,
  10328. face: null,
  10329. faceIndex: null,
  10330. barycoord: null,
  10331. object: object
  10332. } );
  10333. }
  10334. }
  10335. class Group extends Object3D {
  10336. constructor() {
  10337. super();
  10338. this.isGroup = true;
  10339. this.type = 'Group';
  10340. }
  10341. }
  10342. class VideoTexture extends Texture {
  10343. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10344. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10345. this.isVideoTexture = true;
  10346. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  10347. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  10348. this.generateMipmaps = false;
  10349. const scope = this;
  10350. function updateVideo() {
  10351. scope.needsUpdate = true;
  10352. video.requestVideoFrameCallback( updateVideo );
  10353. }
  10354. if ( 'requestVideoFrameCallback' in video ) {
  10355. video.requestVideoFrameCallback( updateVideo );
  10356. }
  10357. }
  10358. clone() {
  10359. return new this.constructor( this.image ).copy( this );
  10360. }
  10361. update() {
  10362. const video = this.image;
  10363. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  10364. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  10365. this.needsUpdate = true;
  10366. }
  10367. }
  10368. }
  10369. class VideoFrameTexture extends VideoTexture {
  10370. constructor( mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10371. super( {}, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10372. }
  10373. update() {
  10374. // overwrites `VideoTexture.update()` with an empty method since
  10375. // this type of texture is updated via `setFrame()`.
  10376. }
  10377. clone() {
  10378. return new this.constructor().copy( this ); // restoring Texture.clone()
  10379. }
  10380. setFrame( frame ) {
  10381. this.image = frame;
  10382. this.needsUpdate = true;
  10383. }
  10384. }
  10385. class FramebufferTexture extends Texture {
  10386. constructor( width, height ) {
  10387. super( { width, height } );
  10388. this.isFramebufferTexture = true;
  10389. this.magFilter = NearestFilter;
  10390. this.minFilter = NearestFilter;
  10391. this.generateMipmaps = false;
  10392. this.needsUpdate = true;
  10393. }
  10394. }
  10395. class CompressedTexture extends Texture {
  10396. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {
  10397. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  10398. this.isCompressedTexture = true;
  10399. this.image = { width: width, height: height };
  10400. this.mipmaps = mipmaps;
  10401. // no flipping for cube textures
  10402. // (also flipping doesn't work for compressed textures )
  10403. this.flipY = false;
  10404. // can't generate mipmaps for compressed textures
  10405. // mips must be embedded in DDS files
  10406. this.generateMipmaps = false;
  10407. }
  10408. }
  10409. class CompressedArrayTexture extends CompressedTexture {
  10410. constructor( mipmaps, width, height, depth, format, type ) {
  10411. super( mipmaps, width, height, format, type );
  10412. this.isCompressedArrayTexture = true;
  10413. this.image.depth = depth;
  10414. this.wrapR = ClampToEdgeWrapping;
  10415. this.layerUpdates = new Set();
  10416. }
  10417. addLayerUpdate( layerIndex ) {
  10418. this.layerUpdates.add( layerIndex );
  10419. }
  10420. clearLayerUpdates() {
  10421. this.layerUpdates.clear();
  10422. }
  10423. }
  10424. class CompressedCubeTexture extends CompressedTexture {
  10425. constructor( images, format, type ) {
  10426. super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
  10427. this.isCompressedCubeTexture = true;
  10428. this.isCubeTexture = true;
  10429. this.image = images;
  10430. }
  10431. }
  10432. class CanvasTexture extends Texture {
  10433. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10434. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10435. this.isCanvasTexture = true;
  10436. this.needsUpdate = true;
  10437. }
  10438. }
  10439. class DepthTexture extends Texture {
  10440. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
  10441. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  10442. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  10443. }
  10444. if ( type === undefined && format === DepthFormat ) type = UnsignedIntType;
  10445. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  10446. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10447. this.isDepthTexture = true;
  10448. this.image = { width: width, height: height };
  10449. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  10450. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  10451. this.flipY = false;
  10452. this.generateMipmaps = false;
  10453. this.compareFunction = null;
  10454. }
  10455. copy( source ) {
  10456. super.copy( source );
  10457. this.compareFunction = source.compareFunction;
  10458. return this;
  10459. }
  10460. toJSON( meta ) {
  10461. const data = super.toJSON( meta );
  10462. if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
  10463. return data;
  10464. }
  10465. }
  10466. /**
  10467. * Extensible curve object.
  10468. *
  10469. * Some common of curve methods:
  10470. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  10471. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  10472. * .getPoints(), .getSpacedPoints()
  10473. * .getLength()
  10474. * .updateArcLengths()
  10475. *
  10476. * This following curves inherit from THREE.Curve:
  10477. *
  10478. * -- 2D curves --
  10479. * THREE.ArcCurve
  10480. * THREE.CubicBezierCurve
  10481. * THREE.EllipseCurve
  10482. * THREE.LineCurve
  10483. * THREE.QuadraticBezierCurve
  10484. * THREE.SplineCurve
  10485. *
  10486. * -- 3D curves --
  10487. * THREE.CatmullRomCurve3
  10488. * THREE.CubicBezierCurve3
  10489. * THREE.LineCurve3
  10490. * THREE.QuadraticBezierCurve3
  10491. *
  10492. * A series of curves can be represented as a THREE.CurvePath.
  10493. *
  10494. **/
  10495. class Curve {
  10496. constructor() {
  10497. this.type = 'Curve';
  10498. this.arcLengthDivisions = 200;
  10499. }
  10500. // Virtual base class method to overwrite and implement in subclasses
  10501. // - t [0 .. 1]
  10502. getPoint( /* t, optionalTarget */ ) {
  10503. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  10504. return null;
  10505. }
  10506. // Get point at relative position in curve according to arc length
  10507. // - u [0 .. 1]
  10508. getPointAt( u, optionalTarget ) {
  10509. const t = this.getUtoTmapping( u );
  10510. return this.getPoint( t, optionalTarget );
  10511. }
  10512. // Get sequence of points using getPoint( t )
  10513. getPoints( divisions = 5 ) {
  10514. const points = [];
  10515. for ( let d = 0; d <= divisions; d ++ ) {
  10516. points.push( this.getPoint( d / divisions ) );
  10517. }
  10518. return points;
  10519. }
  10520. // Get sequence of points using getPointAt( u )
  10521. getSpacedPoints( divisions = 5 ) {
  10522. const points = [];
  10523. for ( let d = 0; d <= divisions; d ++ ) {
  10524. points.push( this.getPointAt( d / divisions ) );
  10525. }
  10526. return points;
  10527. }
  10528. // Get total curve arc length
  10529. getLength() {
  10530. const lengths = this.getLengths();
  10531. return lengths[ lengths.length - 1 ];
  10532. }
  10533. // Get list of cumulative segment lengths
  10534. getLengths( divisions = this.arcLengthDivisions ) {
  10535. if ( this.cacheArcLengths &&
  10536. ( this.cacheArcLengths.length === divisions + 1 ) &&
  10537. ! this.needsUpdate ) {
  10538. return this.cacheArcLengths;
  10539. }
  10540. this.needsUpdate = false;
  10541. const cache = [];
  10542. let current, last = this.getPoint( 0 );
  10543. let sum = 0;
  10544. cache.push( 0 );
  10545. for ( let p = 1; p <= divisions; p ++ ) {
  10546. current = this.getPoint( p / divisions );
  10547. sum += current.distanceTo( last );
  10548. cache.push( sum );
  10549. last = current;
  10550. }
  10551. this.cacheArcLengths = cache;
  10552. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  10553. }
  10554. updateArcLengths() {
  10555. this.needsUpdate = true;
  10556. this.getLengths();
  10557. }
  10558. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  10559. getUtoTmapping( u, distance ) {
  10560. const arcLengths = this.getLengths();
  10561. let i = 0;
  10562. const il = arcLengths.length;
  10563. let targetArcLength; // The targeted u distance value to get
  10564. if ( distance ) {
  10565. targetArcLength = distance;
  10566. } else {
  10567. targetArcLength = u * arcLengths[ il - 1 ];
  10568. }
  10569. // binary search for the index with largest value smaller than target u distance
  10570. let low = 0, high = il - 1, comparison;
  10571. while ( low <= high ) {
  10572. 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
  10573. comparison = arcLengths[ i ] - targetArcLength;
  10574. if ( comparison < 0 ) {
  10575. low = i + 1;
  10576. } else if ( comparison > 0 ) {
  10577. high = i - 1;
  10578. } else {
  10579. high = i;
  10580. break;
  10581. // DONE
  10582. }
  10583. }
  10584. i = high;
  10585. if ( arcLengths[ i ] === targetArcLength ) {
  10586. return i / ( il - 1 );
  10587. }
  10588. // we could get finer grain at lengths, or use simple interpolation between two points
  10589. const lengthBefore = arcLengths[ i ];
  10590. const lengthAfter = arcLengths[ i + 1 ];
  10591. const segmentLength = lengthAfter - lengthBefore;
  10592. // determine where we are between the 'before' and 'after' points
  10593. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  10594. // add that fractional amount to t
  10595. const t = ( i + segmentFraction ) / ( il - 1 );
  10596. return t;
  10597. }
  10598. // Returns a unit vector tangent at t
  10599. // In case any sub curve does not implement its tangent derivation,
  10600. // 2 points a small delta apart will be used to find its gradient
  10601. // which seems to give a reasonable approximation
  10602. getTangent( t, optionalTarget ) {
  10603. const delta = 0.0001;
  10604. let t1 = t - delta;
  10605. let t2 = t + delta;
  10606. // Capping in case of danger
  10607. if ( t1 < 0 ) t1 = 0;
  10608. if ( t2 > 1 ) t2 = 1;
  10609. const pt1 = this.getPoint( t1 );
  10610. const pt2 = this.getPoint( t2 );
  10611. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  10612. tangent.copy( pt2 ).sub( pt1 ).normalize();
  10613. return tangent;
  10614. }
  10615. getTangentAt( u, optionalTarget ) {
  10616. const t = this.getUtoTmapping( u );
  10617. return this.getTangent( t, optionalTarget );
  10618. }
  10619. computeFrenetFrames( segments, closed ) {
  10620. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  10621. const normal = new Vector3();
  10622. const tangents = [];
  10623. const normals = [];
  10624. const binormals = [];
  10625. const vec = new Vector3();
  10626. const mat = new Matrix4();
  10627. // compute the tangent vectors for each segment on the curve
  10628. for ( let i = 0; i <= segments; i ++ ) {
  10629. const u = i / segments;
  10630. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  10631. }
  10632. // select an initial normal vector perpendicular to the first tangent vector,
  10633. // and in the direction of the minimum tangent xyz component
  10634. normals[ 0 ] = new Vector3();
  10635. binormals[ 0 ] = new Vector3();
  10636. let min = Number.MAX_VALUE;
  10637. const tx = Math.abs( tangents[ 0 ].x );
  10638. const ty = Math.abs( tangents[ 0 ].y );
  10639. const tz = Math.abs( tangents[ 0 ].z );
  10640. if ( tx <= min ) {
  10641. min = tx;
  10642. normal.set( 1, 0, 0 );
  10643. }
  10644. if ( ty <= min ) {
  10645. min = ty;
  10646. normal.set( 0, 1, 0 );
  10647. }
  10648. if ( tz <= min ) {
  10649. normal.set( 0, 0, 1 );
  10650. }
  10651. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  10652. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  10653. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  10654. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  10655. for ( let i = 1; i <= segments; i ++ ) {
  10656. normals[ i ] = normals[ i - 1 ].clone();
  10657. binormals[ i ] = binormals[ i - 1 ].clone();
  10658. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  10659. if ( vec.length() > Number.EPSILON ) {
  10660. vec.normalize();
  10661. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  10662. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  10663. }
  10664. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10665. }
  10666. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  10667. if ( closed === true ) {
  10668. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  10669. theta /= segments;
  10670. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  10671. theta = - theta;
  10672. }
  10673. for ( let i = 1; i <= segments; i ++ ) {
  10674. // twist a little...
  10675. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  10676. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10677. }
  10678. }
  10679. return {
  10680. tangents: tangents,
  10681. normals: normals,
  10682. binormals: binormals
  10683. };
  10684. }
  10685. clone() {
  10686. return new this.constructor().copy( this );
  10687. }
  10688. copy( source ) {
  10689. this.arcLengthDivisions = source.arcLengthDivisions;
  10690. return this;
  10691. }
  10692. toJSON() {
  10693. const data = {
  10694. metadata: {
  10695. version: 4.6,
  10696. type: 'Curve',
  10697. generator: 'Curve.toJSON'
  10698. }
  10699. };
  10700. data.arcLengthDivisions = this.arcLengthDivisions;
  10701. data.type = this.type;
  10702. return data;
  10703. }
  10704. fromJSON( json ) {
  10705. this.arcLengthDivisions = json.arcLengthDivisions;
  10706. return this;
  10707. }
  10708. }
  10709. class EllipseCurve extends Curve {
  10710. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  10711. super();
  10712. this.isEllipseCurve = true;
  10713. this.type = 'EllipseCurve';
  10714. this.aX = aX;
  10715. this.aY = aY;
  10716. this.xRadius = xRadius;
  10717. this.yRadius = yRadius;
  10718. this.aStartAngle = aStartAngle;
  10719. this.aEndAngle = aEndAngle;
  10720. this.aClockwise = aClockwise;
  10721. this.aRotation = aRotation;
  10722. }
  10723. getPoint( t, optionalTarget = new Vector2() ) {
  10724. const point = optionalTarget;
  10725. const twoPi = Math.PI * 2;
  10726. let deltaAngle = this.aEndAngle - this.aStartAngle;
  10727. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  10728. // ensures that deltaAngle is 0 .. 2 PI
  10729. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  10730. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  10731. if ( deltaAngle < Number.EPSILON ) {
  10732. if ( samePoints ) {
  10733. deltaAngle = 0;
  10734. } else {
  10735. deltaAngle = twoPi;
  10736. }
  10737. }
  10738. if ( this.aClockwise === true && ! samePoints ) {
  10739. if ( deltaAngle === twoPi ) {
  10740. deltaAngle = - twoPi;
  10741. } else {
  10742. deltaAngle = deltaAngle - twoPi;
  10743. }
  10744. }
  10745. const angle = this.aStartAngle + t * deltaAngle;
  10746. let x = this.aX + this.xRadius * Math.cos( angle );
  10747. let y = this.aY + this.yRadius * Math.sin( angle );
  10748. if ( this.aRotation !== 0 ) {
  10749. const cos = Math.cos( this.aRotation );
  10750. const sin = Math.sin( this.aRotation );
  10751. const tx = x - this.aX;
  10752. const ty = y - this.aY;
  10753. // Rotate the point about the center of the ellipse.
  10754. x = tx * cos - ty * sin + this.aX;
  10755. y = tx * sin + ty * cos + this.aY;
  10756. }
  10757. return point.set( x, y );
  10758. }
  10759. copy( source ) {
  10760. super.copy( source );
  10761. this.aX = source.aX;
  10762. this.aY = source.aY;
  10763. this.xRadius = source.xRadius;
  10764. this.yRadius = source.yRadius;
  10765. this.aStartAngle = source.aStartAngle;
  10766. this.aEndAngle = source.aEndAngle;
  10767. this.aClockwise = source.aClockwise;
  10768. this.aRotation = source.aRotation;
  10769. return this;
  10770. }
  10771. toJSON() {
  10772. const data = super.toJSON();
  10773. data.aX = this.aX;
  10774. data.aY = this.aY;
  10775. data.xRadius = this.xRadius;
  10776. data.yRadius = this.yRadius;
  10777. data.aStartAngle = this.aStartAngle;
  10778. data.aEndAngle = this.aEndAngle;
  10779. data.aClockwise = this.aClockwise;
  10780. data.aRotation = this.aRotation;
  10781. return data;
  10782. }
  10783. fromJSON( json ) {
  10784. super.fromJSON( json );
  10785. this.aX = json.aX;
  10786. this.aY = json.aY;
  10787. this.xRadius = json.xRadius;
  10788. this.yRadius = json.yRadius;
  10789. this.aStartAngle = json.aStartAngle;
  10790. this.aEndAngle = json.aEndAngle;
  10791. this.aClockwise = json.aClockwise;
  10792. this.aRotation = json.aRotation;
  10793. return this;
  10794. }
  10795. }
  10796. class ArcCurve extends EllipseCurve {
  10797. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  10798. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  10799. this.isArcCurve = true;
  10800. this.type = 'ArcCurve';
  10801. }
  10802. }
  10803. /**
  10804. * Centripetal CatmullRom Curve - which is useful for avoiding
  10805. * cusps and self-intersections in non-uniform catmull rom curves.
  10806. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  10807. *
  10808. * curve.type accepts centripetal(default), chordal and catmullrom
  10809. * curve.tension is used for catmullrom which defaults to 0.5
  10810. */
  10811. /*
  10812. Based on an optimized c++ solution in
  10813. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  10814. - http://ideone.com/NoEbVM
  10815. This CubicPoly class could be used for reusing some variables and calculations,
  10816. but for three.js curve use, it could be possible inlined and flatten into a single function call
  10817. which can be placed in CurveUtils.
  10818. */
  10819. function CubicPoly() {
  10820. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  10821. /*
  10822. * Compute coefficients for a cubic polynomial
  10823. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  10824. * such that
  10825. * p(0) = x0, p(1) = x1
  10826. * and
  10827. * p'(0) = t0, p'(1) = t1.
  10828. */
  10829. function init( x0, x1, t0, t1 ) {
  10830. c0 = x0;
  10831. c1 = t0;
  10832. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  10833. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  10834. }
  10835. return {
  10836. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  10837. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  10838. },
  10839. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  10840. // compute tangents when parameterized in [t1,t2]
  10841. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  10842. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  10843. // rescale tangents for parametrization in [0,1]
  10844. t1 *= dt1;
  10845. t2 *= dt1;
  10846. init( x1, x2, t1, t2 );
  10847. },
  10848. calc: function ( t ) {
  10849. const t2 = t * t;
  10850. const t3 = t2 * t;
  10851. return c0 + c1 * t + c2 * t2 + c3 * t3;
  10852. }
  10853. };
  10854. }
  10855. //
  10856. const tmp = /*@__PURE__*/ new Vector3();
  10857. const px = /*@__PURE__*/ new CubicPoly();
  10858. const py = /*@__PURE__*/ new CubicPoly();
  10859. const pz = /*@__PURE__*/ new CubicPoly();
  10860. class CatmullRomCurve3 extends Curve {
  10861. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  10862. super();
  10863. this.isCatmullRomCurve3 = true;
  10864. this.type = 'CatmullRomCurve3';
  10865. this.points = points;
  10866. this.closed = closed;
  10867. this.curveType = curveType;
  10868. this.tension = tension;
  10869. }
  10870. getPoint( t, optionalTarget = new Vector3() ) {
  10871. const point = optionalTarget;
  10872. const points = this.points;
  10873. const l = points.length;
  10874. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  10875. let intPoint = Math.floor( p );
  10876. let weight = p - intPoint;
  10877. if ( this.closed ) {
  10878. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  10879. } else if ( weight === 0 && intPoint === l - 1 ) {
  10880. intPoint = l - 2;
  10881. weight = 1;
  10882. }
  10883. let p0, p3; // 4 points (p1 & p2 defined below)
  10884. if ( this.closed || intPoint > 0 ) {
  10885. p0 = points[ ( intPoint - 1 ) % l ];
  10886. } else {
  10887. // extrapolate first point
  10888. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  10889. p0 = tmp;
  10890. }
  10891. const p1 = points[ intPoint % l ];
  10892. const p2 = points[ ( intPoint + 1 ) % l ];
  10893. if ( this.closed || intPoint + 2 < l ) {
  10894. p3 = points[ ( intPoint + 2 ) % l ];
  10895. } else {
  10896. // extrapolate last point
  10897. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  10898. p3 = tmp;
  10899. }
  10900. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  10901. // init Centripetal / Chordal Catmull-Rom
  10902. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  10903. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  10904. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  10905. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  10906. // safety check for repeated points
  10907. if ( dt1 < 1e-4 ) dt1 = 1.0;
  10908. if ( dt0 < 1e-4 ) dt0 = dt1;
  10909. if ( dt2 < 1e-4 ) dt2 = dt1;
  10910. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  10911. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  10912. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  10913. } else if ( this.curveType === 'catmullrom' ) {
  10914. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  10915. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  10916. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  10917. }
  10918. point.set(
  10919. px.calc( weight ),
  10920. py.calc( weight ),
  10921. pz.calc( weight )
  10922. );
  10923. return point;
  10924. }
  10925. copy( source ) {
  10926. super.copy( source );
  10927. this.points = [];
  10928. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  10929. const point = source.points[ i ];
  10930. this.points.push( point.clone() );
  10931. }
  10932. this.closed = source.closed;
  10933. this.curveType = source.curveType;
  10934. this.tension = source.tension;
  10935. return this;
  10936. }
  10937. toJSON() {
  10938. const data = super.toJSON();
  10939. data.points = [];
  10940. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  10941. const point = this.points[ i ];
  10942. data.points.push( point.toArray() );
  10943. }
  10944. data.closed = this.closed;
  10945. data.curveType = this.curveType;
  10946. data.tension = this.tension;
  10947. return data;
  10948. }
  10949. fromJSON( json ) {
  10950. super.fromJSON( json );
  10951. this.points = [];
  10952. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  10953. const point = json.points[ i ];
  10954. this.points.push( new Vector3().fromArray( point ) );
  10955. }
  10956. this.closed = json.closed;
  10957. this.curveType = json.curveType;
  10958. this.tension = json.tension;
  10959. return this;
  10960. }
  10961. }
  10962. /**
  10963. * Bezier Curves formulas obtained from
  10964. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
  10965. */
  10966. function CatmullRom( t, p0, p1, p2, p3 ) {
  10967. const v0 = ( p2 - p0 ) * 0.5;
  10968. const v1 = ( p3 - p1 ) * 0.5;
  10969. const t2 = t * t;
  10970. const t3 = t * t2;
  10971. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  10972. }
  10973. //
  10974. function QuadraticBezierP0( t, p ) {
  10975. const k = 1 - t;
  10976. return k * k * p;
  10977. }
  10978. function QuadraticBezierP1( t, p ) {
  10979. return 2 * ( 1 - t ) * t * p;
  10980. }
  10981. function QuadraticBezierP2( t, p ) {
  10982. return t * t * p;
  10983. }
  10984. function QuadraticBezier( t, p0, p1, p2 ) {
  10985. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  10986. QuadraticBezierP2( t, p2 );
  10987. }
  10988. //
  10989. function CubicBezierP0( t, p ) {
  10990. const k = 1 - t;
  10991. return k * k * k * p;
  10992. }
  10993. function CubicBezierP1( t, p ) {
  10994. const k = 1 - t;
  10995. return 3 * k * k * t * p;
  10996. }
  10997. function CubicBezierP2( t, p ) {
  10998. return 3 * ( 1 - t ) * t * t * p;
  10999. }
  11000. function CubicBezierP3( t, p ) {
  11001. return t * t * t * p;
  11002. }
  11003. function CubicBezier( t, p0, p1, p2, p3 ) {
  11004. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  11005. CubicBezierP3( t, p3 );
  11006. }
  11007. class CubicBezierCurve extends Curve {
  11008. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  11009. super();
  11010. this.isCubicBezierCurve = true;
  11011. this.type = 'CubicBezierCurve';
  11012. this.v0 = v0;
  11013. this.v1 = v1;
  11014. this.v2 = v2;
  11015. this.v3 = v3;
  11016. }
  11017. getPoint( t, optionalTarget = new Vector2() ) {
  11018. const point = optionalTarget;
  11019. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11020. point.set(
  11021. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11022. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  11023. );
  11024. return point;
  11025. }
  11026. copy( source ) {
  11027. super.copy( source );
  11028. this.v0.copy( source.v0 );
  11029. this.v1.copy( source.v1 );
  11030. this.v2.copy( source.v2 );
  11031. this.v3.copy( source.v3 );
  11032. return this;
  11033. }
  11034. toJSON() {
  11035. const data = super.toJSON();
  11036. data.v0 = this.v0.toArray();
  11037. data.v1 = this.v1.toArray();
  11038. data.v2 = this.v2.toArray();
  11039. data.v3 = this.v3.toArray();
  11040. return data;
  11041. }
  11042. fromJSON( json ) {
  11043. super.fromJSON( json );
  11044. this.v0.fromArray( json.v0 );
  11045. this.v1.fromArray( json.v1 );
  11046. this.v2.fromArray( json.v2 );
  11047. this.v3.fromArray( json.v3 );
  11048. return this;
  11049. }
  11050. }
  11051. class CubicBezierCurve3 extends Curve {
  11052. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  11053. super();
  11054. this.isCubicBezierCurve3 = true;
  11055. this.type = 'CubicBezierCurve3';
  11056. this.v0 = v0;
  11057. this.v1 = v1;
  11058. this.v2 = v2;
  11059. this.v3 = v3;
  11060. }
  11061. getPoint( t, optionalTarget = new Vector3() ) {
  11062. const point = optionalTarget;
  11063. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11064. point.set(
  11065. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11066. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  11067. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  11068. );
  11069. return point;
  11070. }
  11071. copy( source ) {
  11072. super.copy( source );
  11073. this.v0.copy( source.v0 );
  11074. this.v1.copy( source.v1 );
  11075. this.v2.copy( source.v2 );
  11076. this.v3.copy( source.v3 );
  11077. return this;
  11078. }
  11079. toJSON() {
  11080. const data = super.toJSON();
  11081. data.v0 = this.v0.toArray();
  11082. data.v1 = this.v1.toArray();
  11083. data.v2 = this.v2.toArray();
  11084. data.v3 = this.v3.toArray();
  11085. return data;
  11086. }
  11087. fromJSON( json ) {
  11088. super.fromJSON( json );
  11089. this.v0.fromArray( json.v0 );
  11090. this.v1.fromArray( json.v1 );
  11091. this.v2.fromArray( json.v2 );
  11092. this.v3.fromArray( json.v3 );
  11093. return this;
  11094. }
  11095. }
  11096. class LineCurve extends Curve {
  11097. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  11098. super();
  11099. this.isLineCurve = true;
  11100. this.type = 'LineCurve';
  11101. this.v1 = v1;
  11102. this.v2 = v2;
  11103. }
  11104. getPoint( t, optionalTarget = new Vector2() ) {
  11105. const point = optionalTarget;
  11106. if ( t === 1 ) {
  11107. point.copy( this.v2 );
  11108. } else {
  11109. point.copy( this.v2 ).sub( this.v1 );
  11110. point.multiplyScalar( t ).add( this.v1 );
  11111. }
  11112. return point;
  11113. }
  11114. // Line curve is linear, so we can overwrite default getPointAt
  11115. getPointAt( u, optionalTarget ) {
  11116. return this.getPoint( u, optionalTarget );
  11117. }
  11118. getTangent( t, optionalTarget = new Vector2() ) {
  11119. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11120. }
  11121. getTangentAt( u, optionalTarget ) {
  11122. return this.getTangent( u, optionalTarget );
  11123. }
  11124. copy( source ) {
  11125. super.copy( source );
  11126. this.v1.copy( source.v1 );
  11127. this.v2.copy( source.v2 );
  11128. return this;
  11129. }
  11130. toJSON() {
  11131. const data = super.toJSON();
  11132. data.v1 = this.v1.toArray();
  11133. data.v2 = this.v2.toArray();
  11134. return data;
  11135. }
  11136. fromJSON( json ) {
  11137. super.fromJSON( json );
  11138. this.v1.fromArray( json.v1 );
  11139. this.v2.fromArray( json.v2 );
  11140. return this;
  11141. }
  11142. }
  11143. class LineCurve3 extends Curve {
  11144. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  11145. super();
  11146. this.isLineCurve3 = true;
  11147. this.type = 'LineCurve3';
  11148. this.v1 = v1;
  11149. this.v2 = v2;
  11150. }
  11151. getPoint( t, optionalTarget = new Vector3() ) {
  11152. const point = optionalTarget;
  11153. if ( t === 1 ) {
  11154. point.copy( this.v2 );
  11155. } else {
  11156. point.copy( this.v2 ).sub( this.v1 );
  11157. point.multiplyScalar( t ).add( this.v1 );
  11158. }
  11159. return point;
  11160. }
  11161. // Line curve is linear, so we can overwrite default getPointAt
  11162. getPointAt( u, optionalTarget ) {
  11163. return this.getPoint( u, optionalTarget );
  11164. }
  11165. getTangent( t, optionalTarget = new Vector3() ) {
  11166. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11167. }
  11168. getTangentAt( u, optionalTarget ) {
  11169. return this.getTangent( u, optionalTarget );
  11170. }
  11171. copy( source ) {
  11172. super.copy( source );
  11173. this.v1.copy( source.v1 );
  11174. this.v2.copy( source.v2 );
  11175. return this;
  11176. }
  11177. toJSON() {
  11178. const data = super.toJSON();
  11179. data.v1 = this.v1.toArray();
  11180. data.v2 = this.v2.toArray();
  11181. return data;
  11182. }
  11183. fromJSON( json ) {
  11184. super.fromJSON( json );
  11185. this.v1.fromArray( json.v1 );
  11186. this.v2.fromArray( json.v2 );
  11187. return this;
  11188. }
  11189. }
  11190. class QuadraticBezierCurve extends Curve {
  11191. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  11192. super();
  11193. this.isQuadraticBezierCurve = true;
  11194. this.type = 'QuadraticBezierCurve';
  11195. this.v0 = v0;
  11196. this.v1 = v1;
  11197. this.v2 = v2;
  11198. }
  11199. getPoint( t, optionalTarget = new Vector2() ) {
  11200. const point = optionalTarget;
  11201. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11202. point.set(
  11203. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11204. QuadraticBezier( t, v0.y, v1.y, v2.y )
  11205. );
  11206. return point;
  11207. }
  11208. copy( source ) {
  11209. super.copy( source );
  11210. this.v0.copy( source.v0 );
  11211. this.v1.copy( source.v1 );
  11212. this.v2.copy( source.v2 );
  11213. return this;
  11214. }
  11215. toJSON() {
  11216. const data = super.toJSON();
  11217. data.v0 = this.v0.toArray();
  11218. data.v1 = this.v1.toArray();
  11219. data.v2 = this.v2.toArray();
  11220. return data;
  11221. }
  11222. fromJSON( json ) {
  11223. super.fromJSON( json );
  11224. this.v0.fromArray( json.v0 );
  11225. this.v1.fromArray( json.v1 );
  11226. this.v2.fromArray( json.v2 );
  11227. return this;
  11228. }
  11229. }
  11230. class QuadraticBezierCurve3 extends Curve {
  11231. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  11232. super();
  11233. this.isQuadraticBezierCurve3 = true;
  11234. this.type = 'QuadraticBezierCurve3';
  11235. this.v0 = v0;
  11236. this.v1 = v1;
  11237. this.v2 = v2;
  11238. }
  11239. getPoint( t, optionalTarget = new Vector3() ) {
  11240. const point = optionalTarget;
  11241. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11242. point.set(
  11243. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11244. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  11245. QuadraticBezier( t, v0.z, v1.z, v2.z )
  11246. );
  11247. return point;
  11248. }
  11249. copy( source ) {
  11250. super.copy( source );
  11251. this.v0.copy( source.v0 );
  11252. this.v1.copy( source.v1 );
  11253. this.v2.copy( source.v2 );
  11254. return this;
  11255. }
  11256. toJSON() {
  11257. const data = super.toJSON();
  11258. data.v0 = this.v0.toArray();
  11259. data.v1 = this.v1.toArray();
  11260. data.v2 = this.v2.toArray();
  11261. return data;
  11262. }
  11263. fromJSON( json ) {
  11264. super.fromJSON( json );
  11265. this.v0.fromArray( json.v0 );
  11266. this.v1.fromArray( json.v1 );
  11267. this.v2.fromArray( json.v2 );
  11268. return this;
  11269. }
  11270. }
  11271. class SplineCurve extends Curve {
  11272. constructor( points = [] ) {
  11273. super();
  11274. this.isSplineCurve = true;
  11275. this.type = 'SplineCurve';
  11276. this.points = points;
  11277. }
  11278. getPoint( t, optionalTarget = new Vector2() ) {
  11279. const point = optionalTarget;
  11280. const points = this.points;
  11281. const p = ( points.length - 1 ) * t;
  11282. const intPoint = Math.floor( p );
  11283. const weight = p - intPoint;
  11284. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  11285. const p1 = points[ intPoint ];
  11286. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  11287. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  11288. point.set(
  11289. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  11290. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  11291. );
  11292. return point;
  11293. }
  11294. copy( source ) {
  11295. super.copy( source );
  11296. this.points = [];
  11297. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11298. const point = source.points[ i ];
  11299. this.points.push( point.clone() );
  11300. }
  11301. return this;
  11302. }
  11303. toJSON() {
  11304. const data = super.toJSON();
  11305. data.points = [];
  11306. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11307. const point = this.points[ i ];
  11308. data.points.push( point.toArray() );
  11309. }
  11310. return data;
  11311. }
  11312. fromJSON( json ) {
  11313. super.fromJSON( json );
  11314. this.points = [];
  11315. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11316. const point = json.points[ i ];
  11317. this.points.push( new Vector2().fromArray( point ) );
  11318. }
  11319. return this;
  11320. }
  11321. }
  11322. var Curves = /*#__PURE__*/Object.freeze({
  11323. __proto__: null,
  11324. ArcCurve: ArcCurve,
  11325. CatmullRomCurve3: CatmullRomCurve3,
  11326. CubicBezierCurve: CubicBezierCurve,
  11327. CubicBezierCurve3: CubicBezierCurve3,
  11328. EllipseCurve: EllipseCurve,
  11329. LineCurve: LineCurve,
  11330. LineCurve3: LineCurve3,
  11331. QuadraticBezierCurve: QuadraticBezierCurve,
  11332. QuadraticBezierCurve3: QuadraticBezierCurve3,
  11333. SplineCurve: SplineCurve
  11334. });
  11335. /**************************************************************
  11336. * Curved Path - a curve path is simply a array of connected
  11337. * curves, but retains the api of a curve
  11338. **************************************************************/
  11339. class CurvePath extends Curve {
  11340. constructor() {
  11341. super();
  11342. this.type = 'CurvePath';
  11343. this.curves = [];
  11344. this.autoClose = false; // Automatically closes the path
  11345. }
  11346. add( curve ) {
  11347. this.curves.push( curve );
  11348. }
  11349. closePath() {
  11350. // Add a line curve if start and end of lines are not connected
  11351. const startPoint = this.curves[ 0 ].getPoint( 0 );
  11352. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  11353. if ( ! startPoint.equals( endPoint ) ) {
  11354. const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
  11355. this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
  11356. }
  11357. return this;
  11358. }
  11359. // To get accurate point with reference to
  11360. // entire path distance at time t,
  11361. // following has to be done:
  11362. // 1. Length of each sub path have to be known
  11363. // 2. Locate and identify type of curve
  11364. // 3. Get t for the curve
  11365. // 4. Return curve.getPointAt(t')
  11366. getPoint( t, optionalTarget ) {
  11367. const d = t * this.getLength();
  11368. const curveLengths = this.getCurveLengths();
  11369. let i = 0;
  11370. // To think about boundaries points.
  11371. while ( i < curveLengths.length ) {
  11372. if ( curveLengths[ i ] >= d ) {
  11373. const diff = curveLengths[ i ] - d;
  11374. const curve = this.curves[ i ];
  11375. const segmentLength = curve.getLength();
  11376. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  11377. return curve.getPointAt( u, optionalTarget );
  11378. }
  11379. i ++;
  11380. }
  11381. return null;
  11382. // loop where sum != 0, sum > d , sum+1 <d
  11383. }
  11384. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11385. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11386. // getPoint() depends on getLength
  11387. getLength() {
  11388. const lens = this.getCurveLengths();
  11389. return lens[ lens.length - 1 ];
  11390. }
  11391. // cacheLengths must be recalculated.
  11392. updateArcLengths() {
  11393. this.needsUpdate = true;
  11394. this.cacheLengths = null;
  11395. this.getCurveLengths();
  11396. }
  11397. // Compute lengths and cache them
  11398. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11399. getCurveLengths() {
  11400. // We use cache values if curves and cache array are same length
  11401. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  11402. return this.cacheLengths;
  11403. }
  11404. // Get length of sub-curve
  11405. // Push sums into cached array
  11406. const lengths = [];
  11407. let sums = 0;
  11408. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11409. sums += this.curves[ i ].getLength();
  11410. lengths.push( sums );
  11411. }
  11412. this.cacheLengths = lengths;
  11413. return lengths;
  11414. }
  11415. getSpacedPoints( divisions = 40 ) {
  11416. const points = [];
  11417. for ( let i = 0; i <= divisions; i ++ ) {
  11418. points.push( this.getPoint( i / divisions ) );
  11419. }
  11420. if ( this.autoClose ) {
  11421. points.push( points[ 0 ] );
  11422. }
  11423. return points;
  11424. }
  11425. getPoints( divisions = 12 ) {
  11426. const points = [];
  11427. let last;
  11428. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  11429. const curve = curves[ i ];
  11430. const resolution = curve.isEllipseCurve ? divisions * 2
  11431. : ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
  11432. : curve.isSplineCurve ? divisions * curve.points.length
  11433. : divisions;
  11434. const pts = curve.getPoints( resolution );
  11435. for ( let j = 0; j < pts.length; j ++ ) {
  11436. const point = pts[ j ];
  11437. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  11438. points.push( point );
  11439. last = point;
  11440. }
  11441. }
  11442. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  11443. points.push( points[ 0 ] );
  11444. }
  11445. return points;
  11446. }
  11447. copy( source ) {
  11448. super.copy( source );
  11449. this.curves = [];
  11450. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  11451. const curve = source.curves[ i ];
  11452. this.curves.push( curve.clone() );
  11453. }
  11454. this.autoClose = source.autoClose;
  11455. return this;
  11456. }
  11457. toJSON() {
  11458. const data = super.toJSON();
  11459. data.autoClose = this.autoClose;
  11460. data.curves = [];
  11461. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11462. const curve = this.curves[ i ];
  11463. data.curves.push( curve.toJSON() );
  11464. }
  11465. return data;
  11466. }
  11467. fromJSON( json ) {
  11468. super.fromJSON( json );
  11469. this.autoClose = json.autoClose;
  11470. this.curves = [];
  11471. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  11472. const curve = json.curves[ i ];
  11473. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  11474. }
  11475. return this;
  11476. }
  11477. }
  11478. class Path extends CurvePath {
  11479. constructor( points ) {
  11480. super();
  11481. this.type = 'Path';
  11482. this.currentPoint = new Vector2();
  11483. if ( points ) {
  11484. this.setFromPoints( points );
  11485. }
  11486. }
  11487. setFromPoints( points ) {
  11488. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  11489. for ( let i = 1, l = points.length; i < l; i ++ ) {
  11490. this.lineTo( points[ i ].x, points[ i ].y );
  11491. }
  11492. return this;
  11493. }
  11494. moveTo( x, y ) {
  11495. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  11496. return this;
  11497. }
  11498. lineTo( x, y ) {
  11499. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  11500. this.curves.push( curve );
  11501. this.currentPoint.set( x, y );
  11502. return this;
  11503. }
  11504. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  11505. const curve = new QuadraticBezierCurve(
  11506. this.currentPoint.clone(),
  11507. new Vector2( aCPx, aCPy ),
  11508. new Vector2( aX, aY )
  11509. );
  11510. this.curves.push( curve );
  11511. this.currentPoint.set( aX, aY );
  11512. return this;
  11513. }
  11514. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  11515. const curve = new CubicBezierCurve(
  11516. this.currentPoint.clone(),
  11517. new Vector2( aCP1x, aCP1y ),
  11518. new Vector2( aCP2x, aCP2y ),
  11519. new Vector2( aX, aY )
  11520. );
  11521. this.curves.push( curve );
  11522. this.currentPoint.set( aX, aY );
  11523. return this;
  11524. }
  11525. splineThru( pts /*Array of Vector*/ ) {
  11526. const npts = [ this.currentPoint.clone() ].concat( pts );
  11527. const curve = new SplineCurve( npts );
  11528. this.curves.push( curve );
  11529. this.currentPoint.copy( pts[ pts.length - 1 ] );
  11530. return this;
  11531. }
  11532. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11533. const x0 = this.currentPoint.x;
  11534. const y0 = this.currentPoint.y;
  11535. this.absarc( aX + x0, aY + y0, aRadius,
  11536. aStartAngle, aEndAngle, aClockwise );
  11537. return this;
  11538. }
  11539. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11540. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  11541. return this;
  11542. }
  11543. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11544. const x0 = this.currentPoint.x;
  11545. const y0 = this.currentPoint.y;
  11546. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11547. return this;
  11548. }
  11549. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11550. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11551. if ( this.curves.length > 0 ) {
  11552. // if a previous curve is present, attempt to join
  11553. const firstPoint = curve.getPoint( 0 );
  11554. if ( ! firstPoint.equals( this.currentPoint ) ) {
  11555. this.lineTo( firstPoint.x, firstPoint.y );
  11556. }
  11557. }
  11558. this.curves.push( curve );
  11559. const lastPoint = curve.getPoint( 1 );
  11560. this.currentPoint.copy( lastPoint );
  11561. return this;
  11562. }
  11563. copy( source ) {
  11564. super.copy( source );
  11565. this.currentPoint.copy( source.currentPoint );
  11566. return this;
  11567. }
  11568. toJSON() {
  11569. const data = super.toJSON();
  11570. data.currentPoint = this.currentPoint.toArray();
  11571. return data;
  11572. }
  11573. fromJSON( json ) {
  11574. super.fromJSON( json );
  11575. this.currentPoint.fromArray( json.currentPoint );
  11576. return this;
  11577. }
  11578. }
  11579. class LatheGeometry extends BufferGeometry {
  11580. 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 ) {
  11581. super();
  11582. this.type = 'LatheGeometry';
  11583. this.parameters = {
  11584. points: points,
  11585. segments: segments,
  11586. phiStart: phiStart,
  11587. phiLength: phiLength
  11588. };
  11589. segments = Math.floor( segments );
  11590. // clamp phiLength so it's in range of [ 0, 2PI ]
  11591. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  11592. // buffers
  11593. const indices = [];
  11594. const vertices = [];
  11595. const uvs = [];
  11596. const initNormals = [];
  11597. const normals = [];
  11598. // helper variables
  11599. const inverseSegments = 1.0 / segments;
  11600. const vertex = new Vector3();
  11601. const uv = new Vector2();
  11602. const normal = new Vector3();
  11603. const curNormal = new Vector3();
  11604. const prevNormal = new Vector3();
  11605. let dx = 0;
  11606. let dy = 0;
  11607. // pre-compute normals for initial "meridian"
  11608. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11609. switch ( j ) {
  11610. case 0: // special handling for 1st vertex on path
  11611. dx = points[ j + 1 ].x - points[ j ].x;
  11612. dy = points[ j + 1 ].y - points[ j ].y;
  11613. normal.x = dy * 1.0;
  11614. normal.y = - dx;
  11615. normal.z = dy * 0.0;
  11616. prevNormal.copy( normal );
  11617. normal.normalize();
  11618. initNormals.push( normal.x, normal.y, normal.z );
  11619. break;
  11620. case ( points.length - 1 ): // special handling for last Vertex on path
  11621. initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
  11622. break;
  11623. default: // default handling for all vertices in between
  11624. dx = points[ j + 1 ].x - points[ j ].x;
  11625. dy = points[ j + 1 ].y - points[ j ].y;
  11626. normal.x = dy * 1.0;
  11627. normal.y = - dx;
  11628. normal.z = dy * 0.0;
  11629. curNormal.copy( normal );
  11630. normal.x += prevNormal.x;
  11631. normal.y += prevNormal.y;
  11632. normal.z += prevNormal.z;
  11633. normal.normalize();
  11634. initNormals.push( normal.x, normal.y, normal.z );
  11635. prevNormal.copy( curNormal );
  11636. }
  11637. }
  11638. // generate vertices, uvs and normals
  11639. for ( let i = 0; i <= segments; i ++ ) {
  11640. const phi = phiStart + i * inverseSegments * phiLength;
  11641. const sin = Math.sin( phi );
  11642. const cos = Math.cos( phi );
  11643. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11644. // vertex
  11645. vertex.x = points[ j ].x * sin;
  11646. vertex.y = points[ j ].y;
  11647. vertex.z = points[ j ].x * cos;
  11648. vertices.push( vertex.x, vertex.y, vertex.z );
  11649. // uv
  11650. uv.x = i / segments;
  11651. uv.y = j / ( points.length - 1 );
  11652. uvs.push( uv.x, uv.y );
  11653. // normal
  11654. const x = initNormals[ 3 * j + 0 ] * sin;
  11655. const y = initNormals[ 3 * j + 1 ];
  11656. const z = initNormals[ 3 * j + 0 ] * cos;
  11657. normals.push( x, y, z );
  11658. }
  11659. }
  11660. // indices
  11661. for ( let i = 0; i < segments; i ++ ) {
  11662. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  11663. const base = j + i * points.length;
  11664. const a = base;
  11665. const b = base + points.length;
  11666. const c = base + points.length + 1;
  11667. const d = base + 1;
  11668. // faces
  11669. indices.push( a, b, d );
  11670. indices.push( c, d, b );
  11671. }
  11672. }
  11673. // build geometry
  11674. this.setIndex( indices );
  11675. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11676. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11677. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11678. }
  11679. copy( source ) {
  11680. super.copy( source );
  11681. this.parameters = Object.assign( {}, source.parameters );
  11682. return this;
  11683. }
  11684. static fromJSON( data ) {
  11685. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  11686. }
  11687. }
  11688. class CapsuleGeometry extends LatheGeometry {
  11689. constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
  11690. const path = new Path();
  11691. path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
  11692. path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
  11693. super( path.getPoints( capSegments ), radialSegments );
  11694. this.type = 'CapsuleGeometry';
  11695. this.parameters = {
  11696. radius: radius,
  11697. length: length,
  11698. capSegments: capSegments,
  11699. radialSegments: radialSegments,
  11700. };
  11701. }
  11702. static fromJSON( data ) {
  11703. return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
  11704. }
  11705. }
  11706. class CircleGeometry extends BufferGeometry {
  11707. constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11708. super();
  11709. this.type = 'CircleGeometry';
  11710. this.parameters = {
  11711. radius: radius,
  11712. segments: segments,
  11713. thetaStart: thetaStart,
  11714. thetaLength: thetaLength
  11715. };
  11716. segments = Math.max( 3, segments );
  11717. // buffers
  11718. const indices = [];
  11719. const vertices = [];
  11720. const normals = [];
  11721. const uvs = [];
  11722. // helper variables
  11723. const vertex = new Vector3();
  11724. const uv = new Vector2();
  11725. // center point
  11726. vertices.push( 0, 0, 0 );
  11727. normals.push( 0, 0, 1 );
  11728. uvs.push( 0.5, 0.5 );
  11729. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  11730. const segment = thetaStart + s / segments * thetaLength;
  11731. // vertex
  11732. vertex.x = radius * Math.cos( segment );
  11733. vertex.y = radius * Math.sin( segment );
  11734. vertices.push( vertex.x, vertex.y, vertex.z );
  11735. // normal
  11736. normals.push( 0, 0, 1 );
  11737. // uvs
  11738. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  11739. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  11740. uvs.push( uv.x, uv.y );
  11741. }
  11742. // indices
  11743. for ( let i = 1; i <= segments; i ++ ) {
  11744. indices.push( i, i + 1, 0 );
  11745. }
  11746. // build geometry
  11747. this.setIndex( indices );
  11748. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11749. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11750. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11751. }
  11752. copy( source ) {
  11753. super.copy( source );
  11754. this.parameters = Object.assign( {}, source.parameters );
  11755. return this;
  11756. }
  11757. static fromJSON( data ) {
  11758. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  11759. }
  11760. }
  11761. class CylinderGeometry extends BufferGeometry {
  11762. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11763. super();
  11764. this.type = 'CylinderGeometry';
  11765. this.parameters = {
  11766. radiusTop: radiusTop,
  11767. radiusBottom: radiusBottom,
  11768. height: height,
  11769. radialSegments: radialSegments,
  11770. heightSegments: heightSegments,
  11771. openEnded: openEnded,
  11772. thetaStart: thetaStart,
  11773. thetaLength: thetaLength
  11774. };
  11775. const scope = this;
  11776. radialSegments = Math.floor( radialSegments );
  11777. heightSegments = Math.floor( heightSegments );
  11778. // buffers
  11779. const indices = [];
  11780. const vertices = [];
  11781. const normals = [];
  11782. const uvs = [];
  11783. // helper variables
  11784. let index = 0;
  11785. const indexArray = [];
  11786. const halfHeight = height / 2;
  11787. let groupStart = 0;
  11788. // generate geometry
  11789. generateTorso();
  11790. if ( openEnded === false ) {
  11791. if ( radiusTop > 0 ) generateCap( true );
  11792. if ( radiusBottom > 0 ) generateCap( false );
  11793. }
  11794. // build geometry
  11795. this.setIndex( indices );
  11796. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11797. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11798. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11799. function generateTorso() {
  11800. const normal = new Vector3();
  11801. const vertex = new Vector3();
  11802. let groupCount = 0;
  11803. // this will be used to calculate the normal
  11804. const slope = ( radiusBottom - radiusTop ) / height;
  11805. // generate vertices, normals and uvs
  11806. for ( let y = 0; y <= heightSegments; y ++ ) {
  11807. const indexRow = [];
  11808. const v = y / heightSegments;
  11809. // calculate the radius of the current row
  11810. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  11811. for ( let x = 0; x <= radialSegments; x ++ ) {
  11812. const u = x / radialSegments;
  11813. const theta = u * thetaLength + thetaStart;
  11814. const sinTheta = Math.sin( theta );
  11815. const cosTheta = Math.cos( theta );
  11816. // vertex
  11817. vertex.x = radius * sinTheta;
  11818. vertex.y = - v * height + halfHeight;
  11819. vertex.z = radius * cosTheta;
  11820. vertices.push( vertex.x, vertex.y, vertex.z );
  11821. // normal
  11822. normal.set( sinTheta, slope, cosTheta ).normalize();
  11823. normals.push( normal.x, normal.y, normal.z );
  11824. // uv
  11825. uvs.push( u, 1 - v );
  11826. // save index of vertex in respective row
  11827. indexRow.push( index ++ );
  11828. }
  11829. // now save vertices of the row in our index array
  11830. indexArray.push( indexRow );
  11831. }
  11832. // generate indices
  11833. for ( let x = 0; x < radialSegments; x ++ ) {
  11834. for ( let y = 0; y < heightSegments; y ++ ) {
  11835. // we use the index array to access the correct indices
  11836. const a = indexArray[ y ][ x ];
  11837. const b = indexArray[ y + 1 ][ x ];
  11838. const c = indexArray[ y + 1 ][ x + 1 ];
  11839. const d = indexArray[ y ][ x + 1 ];
  11840. // faces
  11841. if ( radiusTop > 0 || y !== 0 ) {
  11842. indices.push( a, b, d );
  11843. groupCount += 3;
  11844. }
  11845. if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
  11846. indices.push( b, c, d );
  11847. groupCount += 3;
  11848. }
  11849. }
  11850. }
  11851. // add a group to the geometry. this will ensure multi material support
  11852. scope.addGroup( groupStart, groupCount, 0 );
  11853. // calculate new start value for groups
  11854. groupStart += groupCount;
  11855. }
  11856. function generateCap( top ) {
  11857. // save the index of the first center vertex
  11858. const centerIndexStart = index;
  11859. const uv = new Vector2();
  11860. const vertex = new Vector3();
  11861. let groupCount = 0;
  11862. const radius = ( top === true ) ? radiusTop : radiusBottom;
  11863. const sign = ( top === true ) ? 1 : - 1;
  11864. // first we generate the center vertex data of the cap.
  11865. // because the geometry needs one set of uvs per face,
  11866. // we must generate a center vertex per face/segment
  11867. for ( let x = 1; x <= radialSegments; x ++ ) {
  11868. // vertex
  11869. vertices.push( 0, halfHeight * sign, 0 );
  11870. // normal
  11871. normals.push( 0, sign, 0 );
  11872. // uv
  11873. uvs.push( 0.5, 0.5 );
  11874. // increase index
  11875. index ++;
  11876. }
  11877. // save the index of the last center vertex
  11878. const centerIndexEnd = index;
  11879. // now we generate the surrounding vertices, normals and uvs
  11880. for ( let x = 0; x <= radialSegments; x ++ ) {
  11881. const u = x / radialSegments;
  11882. const theta = u * thetaLength + thetaStart;
  11883. const cosTheta = Math.cos( theta );
  11884. const sinTheta = Math.sin( theta );
  11885. // vertex
  11886. vertex.x = radius * sinTheta;
  11887. vertex.y = halfHeight * sign;
  11888. vertex.z = radius * cosTheta;
  11889. vertices.push( vertex.x, vertex.y, vertex.z );
  11890. // normal
  11891. normals.push( 0, sign, 0 );
  11892. // uv
  11893. uv.x = ( cosTheta * 0.5 ) + 0.5;
  11894. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  11895. uvs.push( uv.x, uv.y );
  11896. // increase index
  11897. index ++;
  11898. }
  11899. // generate indices
  11900. for ( let x = 0; x < radialSegments; x ++ ) {
  11901. const c = centerIndexStart + x;
  11902. const i = centerIndexEnd + x;
  11903. if ( top === true ) {
  11904. // face top
  11905. indices.push( i, i + 1, c );
  11906. } else {
  11907. // face bottom
  11908. indices.push( i + 1, i, c );
  11909. }
  11910. groupCount += 3;
  11911. }
  11912. // add a group to the geometry. this will ensure multi material support
  11913. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  11914. // calculate new start value for groups
  11915. groupStart += groupCount;
  11916. }
  11917. }
  11918. copy( source ) {
  11919. super.copy( source );
  11920. this.parameters = Object.assign( {}, source.parameters );
  11921. return this;
  11922. }
  11923. static fromJSON( data ) {
  11924. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11925. }
  11926. }
  11927. class ConeGeometry extends CylinderGeometry {
  11928. constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11929. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  11930. this.type = 'ConeGeometry';
  11931. this.parameters = {
  11932. radius: radius,
  11933. height: height,
  11934. radialSegments: radialSegments,
  11935. heightSegments: heightSegments,
  11936. openEnded: openEnded,
  11937. thetaStart: thetaStart,
  11938. thetaLength: thetaLength
  11939. };
  11940. }
  11941. static fromJSON( data ) {
  11942. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11943. }
  11944. }
  11945. class PolyhedronGeometry extends BufferGeometry {
  11946. constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
  11947. super();
  11948. this.type = 'PolyhedronGeometry';
  11949. this.parameters = {
  11950. vertices: vertices,
  11951. indices: indices,
  11952. radius: radius,
  11953. detail: detail
  11954. };
  11955. // default buffer data
  11956. const vertexBuffer = [];
  11957. const uvBuffer = [];
  11958. // the subdivision creates the vertex buffer data
  11959. subdivide( detail );
  11960. // all vertices should lie on a conceptual sphere with a given radius
  11961. applyRadius( radius );
  11962. // finally, create the uv data
  11963. generateUVs();
  11964. // build non-indexed geometry
  11965. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  11966. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  11967. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  11968. if ( detail === 0 ) {
  11969. this.computeVertexNormals(); // flat normals
  11970. } else {
  11971. this.normalizeNormals(); // smooth normals
  11972. }
  11973. // helper functions
  11974. function subdivide( detail ) {
  11975. const a = new Vector3();
  11976. const b = new Vector3();
  11977. const c = new Vector3();
  11978. // iterate over all faces and apply a subdivision with the given detail value
  11979. for ( let i = 0; i < indices.length; i += 3 ) {
  11980. // get the vertices of the face
  11981. getVertexByIndex( indices[ i + 0 ], a );
  11982. getVertexByIndex( indices[ i + 1 ], b );
  11983. getVertexByIndex( indices[ i + 2 ], c );
  11984. // perform subdivision
  11985. subdivideFace( a, b, c, detail );
  11986. }
  11987. }
  11988. function subdivideFace( a, b, c, detail ) {
  11989. const cols = detail + 1;
  11990. // we use this multidimensional array as a data structure for creating the subdivision
  11991. const v = [];
  11992. // construct all of the vertices for this subdivision
  11993. for ( let i = 0; i <= cols; i ++ ) {
  11994. v[ i ] = [];
  11995. const aj = a.clone().lerp( c, i / cols );
  11996. const bj = b.clone().lerp( c, i / cols );
  11997. const rows = cols - i;
  11998. for ( let j = 0; j <= rows; j ++ ) {
  11999. if ( j === 0 && i === cols ) {
  12000. v[ i ][ j ] = aj;
  12001. } else {
  12002. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  12003. }
  12004. }
  12005. }
  12006. // construct all of the faces
  12007. for ( let i = 0; i < cols; i ++ ) {
  12008. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  12009. const k = Math.floor( j / 2 );
  12010. if ( j % 2 === 0 ) {
  12011. pushVertex( v[ i ][ k + 1 ] );
  12012. pushVertex( v[ i + 1 ][ k ] );
  12013. pushVertex( v[ i ][ k ] );
  12014. } else {
  12015. pushVertex( v[ i ][ k + 1 ] );
  12016. pushVertex( v[ i + 1 ][ k + 1 ] );
  12017. pushVertex( v[ i + 1 ][ k ] );
  12018. }
  12019. }
  12020. }
  12021. }
  12022. function applyRadius( radius ) {
  12023. const vertex = new Vector3();
  12024. // iterate over the entire buffer and apply the radius to each vertex
  12025. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  12026. vertex.x = vertexBuffer[ i + 0 ];
  12027. vertex.y = vertexBuffer[ i + 1 ];
  12028. vertex.z = vertexBuffer[ i + 2 ];
  12029. vertex.normalize().multiplyScalar( radius );
  12030. vertexBuffer[ i + 0 ] = vertex.x;
  12031. vertexBuffer[ i + 1 ] = vertex.y;
  12032. vertexBuffer[ i + 2 ] = vertex.z;
  12033. }
  12034. }
  12035. function generateUVs() {
  12036. const vertex = new Vector3();
  12037. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  12038. vertex.x = vertexBuffer[ i + 0 ];
  12039. vertex.y = vertexBuffer[ i + 1 ];
  12040. vertex.z = vertexBuffer[ i + 2 ];
  12041. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  12042. const v = inclination( vertex ) / Math.PI + 0.5;
  12043. uvBuffer.push( u, 1 - v );
  12044. }
  12045. correctUVs();
  12046. correctSeam();
  12047. }
  12048. function correctSeam() {
  12049. // handle case when face straddles the seam, see #3269
  12050. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  12051. // uv data of a single face
  12052. const x0 = uvBuffer[ i + 0 ];
  12053. const x1 = uvBuffer[ i + 2 ];
  12054. const x2 = uvBuffer[ i + 4 ];
  12055. const max = Math.max( x0, x1, x2 );
  12056. const min = Math.min( x0, x1, x2 );
  12057. // 0.9 is somewhat arbitrary
  12058. if ( max > 0.9 && min < 0.1 ) {
  12059. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  12060. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  12061. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  12062. }
  12063. }
  12064. }
  12065. function pushVertex( vertex ) {
  12066. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  12067. }
  12068. function getVertexByIndex( index, vertex ) {
  12069. const stride = index * 3;
  12070. vertex.x = vertices[ stride + 0 ];
  12071. vertex.y = vertices[ stride + 1 ];
  12072. vertex.z = vertices[ stride + 2 ];
  12073. }
  12074. function correctUVs() {
  12075. const a = new Vector3();
  12076. const b = new Vector3();
  12077. const c = new Vector3();
  12078. const centroid = new Vector3();
  12079. const uvA = new Vector2();
  12080. const uvB = new Vector2();
  12081. const uvC = new Vector2();
  12082. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  12083. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  12084. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  12085. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  12086. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  12087. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  12088. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  12089. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  12090. const azi = azimuth( centroid );
  12091. correctUV( uvA, j + 0, a, azi );
  12092. correctUV( uvB, j + 2, b, azi );
  12093. correctUV( uvC, j + 4, c, azi );
  12094. }
  12095. }
  12096. function correctUV( uv, stride, vector, azimuth ) {
  12097. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  12098. uvBuffer[ stride ] = uv.x - 1;
  12099. }
  12100. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  12101. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  12102. }
  12103. }
  12104. // Angle around the Y axis, counter-clockwise when looking from above.
  12105. function azimuth( vector ) {
  12106. return Math.atan2( vector.z, - vector.x );
  12107. }
  12108. // Angle above the XZ plane.
  12109. function inclination( vector ) {
  12110. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  12111. }
  12112. }
  12113. copy( source ) {
  12114. super.copy( source );
  12115. this.parameters = Object.assign( {}, source.parameters );
  12116. return this;
  12117. }
  12118. static fromJSON( data ) {
  12119. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  12120. }
  12121. }
  12122. class DodecahedronGeometry extends PolyhedronGeometry {
  12123. constructor( radius = 1, detail = 0 ) {
  12124. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  12125. const r = 1 / t;
  12126. const vertices = [
  12127. // (±1, ±1, ±1)
  12128. - 1, - 1, - 1, - 1, - 1, 1,
  12129. - 1, 1, - 1, - 1, 1, 1,
  12130. 1, - 1, - 1, 1, - 1, 1,
  12131. 1, 1, - 1, 1, 1, 1,
  12132. // (0, ±1/φ, ±φ)
  12133. 0, - r, - t, 0, - r, t,
  12134. 0, r, - t, 0, r, t,
  12135. // (±1/φ, ±φ, 0)
  12136. - r, - t, 0, - r, t, 0,
  12137. r, - t, 0, r, t, 0,
  12138. // (±φ, 0, ±1/φ)
  12139. - t, 0, - r, t, 0, - r,
  12140. - t, 0, r, t, 0, r
  12141. ];
  12142. const indices = [
  12143. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  12144. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  12145. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  12146. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  12147. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  12148. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  12149. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  12150. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  12151. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  12152. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  12153. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  12154. 1, 12, 14, 1, 14, 5, 1, 5, 9
  12155. ];
  12156. super( vertices, indices, radius, detail );
  12157. this.type = 'DodecahedronGeometry';
  12158. this.parameters = {
  12159. radius: radius,
  12160. detail: detail
  12161. };
  12162. }
  12163. static fromJSON( data ) {
  12164. return new DodecahedronGeometry( data.radius, data.detail );
  12165. }
  12166. }
  12167. const _v0 = /*@__PURE__*/ new Vector3();
  12168. const _v1$1 = /*@__PURE__*/ new Vector3();
  12169. const _normal = /*@__PURE__*/ new Vector3();
  12170. const _triangle = /*@__PURE__*/ new Triangle();
  12171. class EdgesGeometry extends BufferGeometry {
  12172. constructor( geometry = null, thresholdAngle = 1 ) {
  12173. super();
  12174. this.type = 'EdgesGeometry';
  12175. this.parameters = {
  12176. geometry: geometry,
  12177. thresholdAngle: thresholdAngle
  12178. };
  12179. if ( geometry !== null ) {
  12180. const precisionPoints = 4;
  12181. const precision = Math.pow( 10, precisionPoints );
  12182. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  12183. const indexAttr = geometry.getIndex();
  12184. const positionAttr = geometry.getAttribute( 'position' );
  12185. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  12186. const indexArr = [ 0, 0, 0 ];
  12187. const vertKeys = [ 'a', 'b', 'c' ];
  12188. const hashes = new Array( 3 );
  12189. const edgeData = {};
  12190. const vertices = [];
  12191. for ( let i = 0; i < indexCount; i += 3 ) {
  12192. if ( indexAttr ) {
  12193. indexArr[ 0 ] = indexAttr.getX( i );
  12194. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  12195. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  12196. } else {
  12197. indexArr[ 0 ] = i;
  12198. indexArr[ 1 ] = i + 1;
  12199. indexArr[ 2 ] = i + 2;
  12200. }
  12201. const { a, b, c } = _triangle;
  12202. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  12203. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  12204. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  12205. _triangle.getNormal( _normal );
  12206. // create hashes for the edge from the vertices
  12207. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  12208. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  12209. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  12210. // skip degenerate triangles
  12211. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  12212. continue;
  12213. }
  12214. // iterate over every edge
  12215. for ( let j = 0; j < 3; j ++ ) {
  12216. // get the first and next vertex making up the edge
  12217. const jNext = ( j + 1 ) % 3;
  12218. const vecHash0 = hashes[ j ];
  12219. const vecHash1 = hashes[ jNext ];
  12220. const v0 = _triangle[ vertKeys[ j ] ];
  12221. const v1 = _triangle[ vertKeys[ jNext ] ];
  12222. const hash = `${ vecHash0 }_${ vecHash1 }`;
  12223. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  12224. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  12225. // if we found a sibling edge add it into the vertex array if
  12226. // it meets the angle threshold and delete the edge from the map.
  12227. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  12228. vertices.push( v0.x, v0.y, v0.z );
  12229. vertices.push( v1.x, v1.y, v1.z );
  12230. }
  12231. edgeData[ reverseHash ] = null;
  12232. } else if ( ! ( hash in edgeData ) ) {
  12233. // if we've already got an edge here then skip adding a new one
  12234. edgeData[ hash ] = {
  12235. index0: indexArr[ j ],
  12236. index1: indexArr[ jNext ],
  12237. normal: _normal.clone(),
  12238. };
  12239. }
  12240. }
  12241. }
  12242. // iterate over all remaining, unmatched edges and add them to the vertex array
  12243. for ( const key in edgeData ) {
  12244. if ( edgeData[ key ] ) {
  12245. const { index0, index1 } = edgeData[ key ];
  12246. _v0.fromBufferAttribute( positionAttr, index0 );
  12247. _v1$1.fromBufferAttribute( positionAttr, index1 );
  12248. vertices.push( _v0.x, _v0.y, _v0.z );
  12249. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  12250. }
  12251. }
  12252. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  12253. }
  12254. }
  12255. copy( source ) {
  12256. super.copy( source );
  12257. this.parameters = Object.assign( {}, source.parameters );
  12258. return this;
  12259. }
  12260. }
  12261. class Shape extends Path {
  12262. constructor( points ) {
  12263. super( points );
  12264. this.uuid = generateUUID();
  12265. this.type = 'Shape';
  12266. this.holes = [];
  12267. }
  12268. getPointsHoles( divisions ) {
  12269. const holesPts = [];
  12270. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12271. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  12272. }
  12273. return holesPts;
  12274. }
  12275. // get points of shape and holes (keypoints based on segments parameter)
  12276. extractPoints( divisions ) {
  12277. return {
  12278. shape: this.getPoints( divisions ),
  12279. holes: this.getPointsHoles( divisions )
  12280. };
  12281. }
  12282. copy( source ) {
  12283. super.copy( source );
  12284. this.holes = [];
  12285. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  12286. const hole = source.holes[ i ];
  12287. this.holes.push( hole.clone() );
  12288. }
  12289. return this;
  12290. }
  12291. toJSON() {
  12292. const data = super.toJSON();
  12293. data.uuid = this.uuid;
  12294. data.holes = [];
  12295. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12296. const hole = this.holes[ i ];
  12297. data.holes.push( hole.toJSON() );
  12298. }
  12299. return data;
  12300. }
  12301. fromJSON( json ) {
  12302. super.fromJSON( json );
  12303. this.uuid = json.uuid;
  12304. this.holes = [];
  12305. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  12306. const hole = json.holes[ i ];
  12307. this.holes.push( new Path().fromJSON( hole ) );
  12308. }
  12309. return this;
  12310. }
  12311. }
  12312. /**
  12313. * Port from https://github.com/mapbox/earcut (v2.2.4)
  12314. */
  12315. const Earcut = {
  12316. triangulate: function ( data, holeIndices, dim = 2 ) {
  12317. const hasHoles = holeIndices && holeIndices.length;
  12318. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  12319. let outerNode = linkedList( data, 0, outerLen, dim, true );
  12320. const triangles = [];
  12321. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  12322. let minX, minY, maxX, maxY, x, y, invSize;
  12323. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  12324. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  12325. if ( data.length > 80 * dim ) {
  12326. minX = maxX = data[ 0 ];
  12327. minY = maxY = data[ 1 ];
  12328. for ( let i = dim; i < outerLen; i += dim ) {
  12329. x = data[ i ];
  12330. y = data[ i + 1 ];
  12331. if ( x < minX ) minX = x;
  12332. if ( y < minY ) minY = y;
  12333. if ( x > maxX ) maxX = x;
  12334. if ( y > maxY ) maxY = y;
  12335. }
  12336. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  12337. invSize = Math.max( maxX - minX, maxY - minY );
  12338. invSize = invSize !== 0 ? 32767 / invSize : 0;
  12339. }
  12340. earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 );
  12341. return triangles;
  12342. }
  12343. };
  12344. // create a circular doubly linked list from polygon points in the specified winding order
  12345. function linkedList( data, start, end, dim, clockwise ) {
  12346. let i, last;
  12347. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  12348. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12349. } else {
  12350. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12351. }
  12352. if ( last && equals( last, last.next ) ) {
  12353. removeNode( last );
  12354. last = last.next;
  12355. }
  12356. return last;
  12357. }
  12358. // eliminate colinear or duplicate points
  12359. function filterPoints( start, end ) {
  12360. if ( ! start ) return start;
  12361. if ( ! end ) end = start;
  12362. let p = start,
  12363. again;
  12364. do {
  12365. again = false;
  12366. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  12367. removeNode( p );
  12368. p = end = p.prev;
  12369. if ( p === p.next ) break;
  12370. again = true;
  12371. } else {
  12372. p = p.next;
  12373. }
  12374. } while ( again || p !== end );
  12375. return end;
  12376. }
  12377. // main ear slicing loop which triangulates a polygon (given as a linked list)
  12378. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  12379. if ( ! ear ) return;
  12380. // interlink polygon nodes in z-order
  12381. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  12382. let stop = ear,
  12383. prev, next;
  12384. // iterate through ears, slicing them one by one
  12385. while ( ear.prev !== ear.next ) {
  12386. prev = ear.prev;
  12387. next = ear.next;
  12388. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  12389. // cut off the triangle
  12390. triangles.push( prev.i / dim | 0 );
  12391. triangles.push( ear.i / dim | 0 );
  12392. triangles.push( next.i / dim | 0 );
  12393. removeNode( ear );
  12394. // skipping the next vertex leads to less sliver triangles
  12395. ear = next.next;
  12396. stop = next.next;
  12397. continue;
  12398. }
  12399. ear = next;
  12400. // if we looped through the whole remaining polygon and can't find any more ears
  12401. if ( ear === stop ) {
  12402. // try filtering points and slicing again
  12403. if ( ! pass ) {
  12404. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  12405. // if this didn't work, try curing all small self-intersections locally
  12406. } else if ( pass === 1 ) {
  12407. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  12408. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  12409. // as a last resort, try splitting the remaining polygon into two
  12410. } else if ( pass === 2 ) {
  12411. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  12412. }
  12413. break;
  12414. }
  12415. }
  12416. }
  12417. // check whether a polygon node forms a valid ear with adjacent nodes
  12418. function isEar( ear ) {
  12419. const a = ear.prev,
  12420. b = ear,
  12421. c = ear.next;
  12422. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12423. // now make sure we don't have other points inside the potential ear
  12424. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12425. // triangle bbox; min & max are calculated like this for speed
  12426. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12427. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12428. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12429. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12430. let p = c.next;
  12431. while ( p !== a ) {
  12432. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  12433. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) &&
  12434. area( p.prev, p, p.next ) >= 0 ) return false;
  12435. p = p.next;
  12436. }
  12437. return true;
  12438. }
  12439. function isEarHashed( ear, minX, minY, invSize ) {
  12440. const a = ear.prev,
  12441. b = ear,
  12442. c = ear.next;
  12443. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12444. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12445. // triangle bbox; min & max are calculated like this for speed
  12446. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12447. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12448. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12449. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12450. // z-order range for the current triangle bbox;
  12451. const minZ = zOrder( x0, y0, minX, minY, invSize ),
  12452. maxZ = zOrder( x1, y1, minX, minY, invSize );
  12453. let p = ear.prevZ,
  12454. n = ear.nextZ;
  12455. // look for points inside the triangle in both directions
  12456. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  12457. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12458. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12459. p = p.prevZ;
  12460. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12461. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12462. n = n.nextZ;
  12463. }
  12464. // look for remaining points in decreasing z-order
  12465. while ( p && p.z >= minZ ) {
  12466. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12467. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12468. p = p.prevZ;
  12469. }
  12470. // look for remaining points in increasing z-order
  12471. while ( n && n.z <= maxZ ) {
  12472. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12473. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12474. n = n.nextZ;
  12475. }
  12476. return true;
  12477. }
  12478. // go through all polygon nodes and cure small local self-intersections
  12479. function cureLocalIntersections( start, triangles, dim ) {
  12480. let p = start;
  12481. do {
  12482. const a = p.prev,
  12483. b = p.next.next;
  12484. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  12485. triangles.push( a.i / dim | 0 );
  12486. triangles.push( p.i / dim | 0 );
  12487. triangles.push( b.i / dim | 0 );
  12488. // remove two nodes involved
  12489. removeNode( p );
  12490. removeNode( p.next );
  12491. p = start = b;
  12492. }
  12493. p = p.next;
  12494. } while ( p !== start );
  12495. return filterPoints( p );
  12496. }
  12497. // try splitting polygon into two and triangulate them independently
  12498. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  12499. // look for a valid diagonal that divides the polygon into two
  12500. let a = start;
  12501. do {
  12502. let b = a.next.next;
  12503. while ( b !== a.prev ) {
  12504. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  12505. // split the polygon in two by the diagonal
  12506. let c = splitPolygon( a, b );
  12507. // filter colinear points around the cuts
  12508. a = filterPoints( a, a.next );
  12509. c = filterPoints( c, c.next );
  12510. // run earcut on each half
  12511. earcutLinked( a, triangles, dim, minX, minY, invSize, 0 );
  12512. earcutLinked( c, triangles, dim, minX, minY, invSize, 0 );
  12513. return;
  12514. }
  12515. b = b.next;
  12516. }
  12517. a = a.next;
  12518. } while ( a !== start );
  12519. }
  12520. // link every hole into the outer loop, producing a single-ring polygon without holes
  12521. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  12522. const queue = [];
  12523. let i, len, start, end, list;
  12524. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  12525. start = holeIndices[ i ] * dim;
  12526. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  12527. list = linkedList( data, start, end, dim, false );
  12528. if ( list === list.next ) list.steiner = true;
  12529. queue.push( getLeftmost( list ) );
  12530. }
  12531. queue.sort( compareX );
  12532. // process holes from left to right
  12533. for ( i = 0; i < queue.length; i ++ ) {
  12534. outerNode = eliminateHole( queue[ i ], outerNode );
  12535. }
  12536. return outerNode;
  12537. }
  12538. function compareX( a, b ) {
  12539. return a.x - b.x;
  12540. }
  12541. // find a bridge between vertices that connects hole with an outer ring and link it
  12542. function eliminateHole( hole, outerNode ) {
  12543. const bridge = findHoleBridge( hole, outerNode );
  12544. if ( ! bridge ) {
  12545. return outerNode;
  12546. }
  12547. const bridgeReverse = splitPolygon( bridge, hole );
  12548. // filter collinear points around the cuts
  12549. filterPoints( bridgeReverse, bridgeReverse.next );
  12550. return filterPoints( bridge, bridge.next );
  12551. }
  12552. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  12553. function findHoleBridge( hole, outerNode ) {
  12554. let p = outerNode,
  12555. qx = - Infinity,
  12556. m;
  12557. const hx = hole.x, hy = hole.y;
  12558. // find a segment intersected by a ray from the hole's leftmost point to the left;
  12559. // segment's endpoint with lesser x will be potential connection point
  12560. do {
  12561. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  12562. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  12563. if ( x <= hx && x > qx ) {
  12564. qx = x;
  12565. m = p.x < p.next.x ? p : p.next;
  12566. if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint
  12567. }
  12568. }
  12569. p = p.next;
  12570. } while ( p !== outerNode );
  12571. if ( ! m ) return null;
  12572. // look for points inside the triangle of hole point, segment intersection and endpoint;
  12573. // if there are no points found, we have a valid connection;
  12574. // otherwise choose the point of the minimum angle with the ray as connection point
  12575. const stop = m,
  12576. mx = m.x,
  12577. my = m.y;
  12578. let tanMin = Infinity, tan;
  12579. p = m;
  12580. do {
  12581. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  12582. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  12583. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  12584. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  12585. m = p;
  12586. tanMin = tan;
  12587. }
  12588. }
  12589. p = p.next;
  12590. } while ( p !== stop );
  12591. return m;
  12592. }
  12593. // whether sector in vertex m contains sector in vertex p in the same coordinates
  12594. function sectorContainsSector( m, p ) {
  12595. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  12596. }
  12597. // interlink polygon nodes in z-order
  12598. function indexCurve( start, minX, minY, invSize ) {
  12599. let p = start;
  12600. do {
  12601. if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  12602. p.prevZ = p.prev;
  12603. p.nextZ = p.next;
  12604. p = p.next;
  12605. } while ( p !== start );
  12606. p.prevZ.nextZ = null;
  12607. p.prevZ = null;
  12608. sortLinked( p );
  12609. }
  12610. // Simon Tatham's linked list merge sort algorithm
  12611. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  12612. function sortLinked( list ) {
  12613. let i, p, q, e, tail, numMerges, pSize, qSize,
  12614. inSize = 1;
  12615. do {
  12616. p = list;
  12617. list = null;
  12618. tail = null;
  12619. numMerges = 0;
  12620. while ( p ) {
  12621. numMerges ++;
  12622. q = p;
  12623. pSize = 0;
  12624. for ( i = 0; i < inSize; i ++ ) {
  12625. pSize ++;
  12626. q = q.nextZ;
  12627. if ( ! q ) break;
  12628. }
  12629. qSize = inSize;
  12630. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  12631. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  12632. e = p;
  12633. p = p.nextZ;
  12634. pSize --;
  12635. } else {
  12636. e = q;
  12637. q = q.nextZ;
  12638. qSize --;
  12639. }
  12640. if ( tail ) tail.nextZ = e;
  12641. else list = e;
  12642. e.prevZ = tail;
  12643. tail = e;
  12644. }
  12645. p = q;
  12646. }
  12647. tail.nextZ = null;
  12648. inSize *= 2;
  12649. } while ( numMerges > 1 );
  12650. return list;
  12651. }
  12652. // z-order of a point given coords and inverse of the longer side of data bbox
  12653. function zOrder( x, y, minX, minY, invSize ) {
  12654. // coords are transformed into non-negative 15-bit integer range
  12655. x = ( x - minX ) * invSize | 0;
  12656. y = ( y - minY ) * invSize | 0;
  12657. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  12658. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  12659. x = ( x | ( x << 2 ) ) & 0x33333333;
  12660. x = ( x | ( x << 1 ) ) & 0x55555555;
  12661. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  12662. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  12663. y = ( y | ( y << 2 ) ) & 0x33333333;
  12664. y = ( y | ( y << 1 ) ) & 0x55555555;
  12665. return x | ( y << 1 );
  12666. }
  12667. // find the leftmost node of a polygon ring
  12668. function getLeftmost( start ) {
  12669. let p = start,
  12670. leftmost = start;
  12671. do {
  12672. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  12673. p = p.next;
  12674. } while ( p !== start );
  12675. return leftmost;
  12676. }
  12677. // check if a point lies within a convex triangle
  12678. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  12679. return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) &&
  12680. ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) &&
  12681. ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py );
  12682. }
  12683. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  12684. function isValidDiagonal( a, b ) {
  12685. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // doesn't intersect other edges
  12686. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  12687. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  12688. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  12689. }
  12690. // signed area of a triangle
  12691. function area( p, q, r ) {
  12692. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  12693. }
  12694. // check if two points are equal
  12695. function equals( p1, p2 ) {
  12696. return p1.x === p2.x && p1.y === p2.y;
  12697. }
  12698. // check if two segments intersect
  12699. function intersects( p1, q1, p2, q2 ) {
  12700. const o1 = sign( area( p1, q1, p2 ) );
  12701. const o2 = sign( area( p1, q1, q2 ) );
  12702. const o3 = sign( area( p2, q2, p1 ) );
  12703. const o4 = sign( area( p2, q2, q1 ) );
  12704. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  12705. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  12706. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  12707. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  12708. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  12709. return false;
  12710. }
  12711. // for collinear points p, q, r, check if point q lies on segment pr
  12712. function onSegment( p, q, r ) {
  12713. 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 );
  12714. }
  12715. function sign( num ) {
  12716. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  12717. }
  12718. // check if a polygon diagonal intersects any polygon segments
  12719. function intersectsPolygon( a, b ) {
  12720. let p = a;
  12721. do {
  12722. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  12723. intersects( p, p.next, a, b ) ) return true;
  12724. p = p.next;
  12725. } while ( p !== a );
  12726. return false;
  12727. }
  12728. // check if a polygon diagonal is locally inside the polygon
  12729. function locallyInside( a, b ) {
  12730. return area( a.prev, a, a.next ) < 0 ?
  12731. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  12732. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  12733. }
  12734. // check if the middle point of a polygon diagonal is inside the polygon
  12735. function middleInside( a, b ) {
  12736. let p = a,
  12737. inside = false;
  12738. const px = ( a.x + b.x ) / 2,
  12739. py = ( a.y + b.y ) / 2;
  12740. do {
  12741. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  12742. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  12743. inside = ! inside;
  12744. p = p.next;
  12745. } while ( p !== a );
  12746. return inside;
  12747. }
  12748. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  12749. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  12750. function splitPolygon( a, b ) {
  12751. const a2 = new Node( a.i, a.x, a.y ),
  12752. b2 = new Node( b.i, b.x, b.y ),
  12753. an = a.next,
  12754. bp = b.prev;
  12755. a.next = b;
  12756. b.prev = a;
  12757. a2.next = an;
  12758. an.prev = a2;
  12759. b2.next = a2;
  12760. a2.prev = b2;
  12761. bp.next = b2;
  12762. b2.prev = bp;
  12763. return b2;
  12764. }
  12765. // create a node and optionally link it with previous one (in a circular doubly linked list)
  12766. function insertNode( i, x, y, last ) {
  12767. const p = new Node( i, x, y );
  12768. if ( ! last ) {
  12769. p.prev = p;
  12770. p.next = p;
  12771. } else {
  12772. p.next = last.next;
  12773. p.prev = last;
  12774. last.next.prev = p;
  12775. last.next = p;
  12776. }
  12777. return p;
  12778. }
  12779. function removeNode( p ) {
  12780. p.next.prev = p.prev;
  12781. p.prev.next = p.next;
  12782. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  12783. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  12784. }
  12785. function Node( i, x, y ) {
  12786. // vertex index in coordinates array
  12787. this.i = i;
  12788. // vertex coordinates
  12789. this.x = x;
  12790. this.y = y;
  12791. // previous and next vertex nodes in a polygon ring
  12792. this.prev = null;
  12793. this.next = null;
  12794. // z-order curve value
  12795. this.z = 0;
  12796. // previous and next nodes in z-order
  12797. this.prevZ = null;
  12798. this.nextZ = null;
  12799. // indicates whether this is a steiner point
  12800. this.steiner = false;
  12801. }
  12802. function signedArea( data, start, end, dim ) {
  12803. let sum = 0;
  12804. for ( let i = start, j = end - dim; i < end; i += dim ) {
  12805. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  12806. j = i;
  12807. }
  12808. return sum;
  12809. }
  12810. class ShapeUtils {
  12811. // calculate area of the contour polygon
  12812. static area( contour ) {
  12813. const n = contour.length;
  12814. let a = 0.0;
  12815. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  12816. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  12817. }
  12818. return a * 0.5;
  12819. }
  12820. static isClockWise( pts ) {
  12821. return ShapeUtils.area( pts ) < 0;
  12822. }
  12823. static triangulateShape( contour, holes ) {
  12824. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  12825. const holeIndices = []; // array of hole indices
  12826. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  12827. removeDupEndPts( contour );
  12828. addContour( vertices, contour );
  12829. //
  12830. let holeIndex = contour.length;
  12831. holes.forEach( removeDupEndPts );
  12832. for ( let i = 0; i < holes.length; i ++ ) {
  12833. holeIndices.push( holeIndex );
  12834. holeIndex += holes[ i ].length;
  12835. addContour( vertices, holes[ i ] );
  12836. }
  12837. //
  12838. const triangles = Earcut.triangulate( vertices, holeIndices );
  12839. //
  12840. for ( let i = 0; i < triangles.length; i += 3 ) {
  12841. faces.push( triangles.slice( i, i + 3 ) );
  12842. }
  12843. return faces;
  12844. }
  12845. }
  12846. function removeDupEndPts( points ) {
  12847. const l = points.length;
  12848. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  12849. points.pop();
  12850. }
  12851. }
  12852. function addContour( vertices, contour ) {
  12853. for ( let i = 0; i < contour.length; i ++ ) {
  12854. vertices.push( contour[ i ].x );
  12855. vertices.push( contour[ i ].y );
  12856. }
  12857. }
  12858. /**
  12859. * Creates extruded geometry from a path shape.
  12860. *
  12861. * parameters = {
  12862. *
  12863. * curveSegments: <int>, // number of points on the curves
  12864. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  12865. * depth: <float>, // Depth to extrude the shape
  12866. *
  12867. * bevelEnabled: <bool>, // turn on bevel
  12868. * bevelThickness: <float>, // how deep into the original shape bevel goes
  12869. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  12870. * bevelOffset: <float>, // how far from shape outline does bevel start
  12871. * bevelSegments: <int>, // number of bevel layers
  12872. *
  12873. * extrudePath: <THREE.Curve> // curve to extrude shape along
  12874. *
  12875. * UVGenerator: <Object> // object that provides UV generator functions
  12876. *
  12877. * }
  12878. */
  12879. class ExtrudeGeometry extends BufferGeometry {
  12880. 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 = {} ) {
  12881. super();
  12882. this.type = 'ExtrudeGeometry';
  12883. this.parameters = {
  12884. shapes: shapes,
  12885. options: options
  12886. };
  12887. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  12888. const scope = this;
  12889. const verticesArray = [];
  12890. const uvArray = [];
  12891. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  12892. const shape = shapes[ i ];
  12893. addShape( shape );
  12894. }
  12895. // build geometry
  12896. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  12897. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  12898. this.computeVertexNormals();
  12899. // functions
  12900. function addShape( shape ) {
  12901. const placeholder = [];
  12902. // options
  12903. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  12904. const steps = options.steps !== undefined ? options.steps : 1;
  12905. const depth = options.depth !== undefined ? options.depth : 1;
  12906. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  12907. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
  12908. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
  12909. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  12910. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  12911. const extrudePath = options.extrudePath;
  12912. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  12913. //
  12914. let extrudePts, extrudeByPath = false;
  12915. let splineTube, binormal, normal, position2;
  12916. if ( extrudePath ) {
  12917. extrudePts = extrudePath.getSpacedPoints( steps );
  12918. extrudeByPath = true;
  12919. bevelEnabled = false; // bevels not supported for path extrusion
  12920. // SETUP TNB variables
  12921. // TODO1 - have a .isClosed in spline?
  12922. splineTube = extrudePath.computeFrenetFrames( steps, false );
  12923. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  12924. binormal = new Vector3();
  12925. normal = new Vector3();
  12926. position2 = new Vector3();
  12927. }
  12928. // Safeguards if bevels are not enabled
  12929. if ( ! bevelEnabled ) {
  12930. bevelSegments = 0;
  12931. bevelThickness = 0;
  12932. bevelSize = 0;
  12933. bevelOffset = 0;
  12934. }
  12935. // Variables initialization
  12936. const shapePoints = shape.extractPoints( curveSegments );
  12937. let vertices = shapePoints.shape;
  12938. const holes = shapePoints.holes;
  12939. const reverse = ! ShapeUtils.isClockWise( vertices );
  12940. if ( reverse ) {
  12941. vertices = vertices.reverse();
  12942. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  12943. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12944. const ahole = holes[ h ];
  12945. if ( ShapeUtils.isClockWise( ahole ) ) {
  12946. holes[ h ] = ahole.reverse();
  12947. }
  12948. }
  12949. }
  12950. const faces = ShapeUtils.triangulateShape( vertices, holes );
  12951. /* Vertices */
  12952. const contour = vertices; // vertices has all points but contour has only points of circumference
  12953. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12954. const ahole = holes[ h ];
  12955. vertices = vertices.concat( ahole );
  12956. }
  12957. function scalePt2( pt, vec, size ) {
  12958. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  12959. return pt.clone().addScaledVector( vec, size );
  12960. }
  12961. const vlen = vertices.length, flen = faces.length;
  12962. // Find directions for point movement
  12963. function getBevelVec( inPt, inPrev, inNext ) {
  12964. // computes for inPt the corresponding point inPt' on a new contour
  12965. // shifted by 1 unit (length of normalized vector) to the left
  12966. // if we walk along contour clockwise, this new contour is outside the old one
  12967. //
  12968. // inPt' is the intersection of the two lines parallel to the two
  12969. // adjacent edges of inPt at a distance of 1 unit on the left side.
  12970. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  12971. // good reading for geometry algorithms (here: line-line intersection)
  12972. // http://geomalgorithms.com/a05-_intersect-1.html
  12973. const v_prev_x = inPt.x - inPrev.x,
  12974. v_prev_y = inPt.y - inPrev.y;
  12975. const v_next_x = inNext.x - inPt.x,
  12976. v_next_y = inNext.y - inPt.y;
  12977. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  12978. // check for collinear edges
  12979. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12980. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  12981. // not collinear
  12982. // length of vectors for normalizing
  12983. const v_prev_len = Math.sqrt( v_prev_lensq );
  12984. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  12985. // shift adjacent points by unit vectors to the left
  12986. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  12987. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  12988. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  12989. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  12990. // scaling factor for v_prev to intersection point
  12991. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  12992. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  12993. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12994. // vector from inPt to intersection point
  12995. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  12996. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  12997. // Don't normalize!, otherwise sharp corners become ugly
  12998. // but prevent crazy spikes
  12999. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  13000. if ( v_trans_lensq <= 2 ) {
  13001. return new Vector2( v_trans_x, v_trans_y );
  13002. } else {
  13003. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  13004. }
  13005. } else {
  13006. // handle special case of collinear edges
  13007. let direction_eq = false; // assumes: opposite
  13008. if ( v_prev_x > Number.EPSILON ) {
  13009. if ( v_next_x > Number.EPSILON ) {
  13010. direction_eq = true;
  13011. }
  13012. } else {
  13013. if ( v_prev_x < - Number.EPSILON ) {
  13014. if ( v_next_x < - Number.EPSILON ) {
  13015. direction_eq = true;
  13016. }
  13017. } else {
  13018. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  13019. direction_eq = true;
  13020. }
  13021. }
  13022. }
  13023. if ( direction_eq ) {
  13024. // console.log("Warning: lines are a straight sequence");
  13025. v_trans_x = - v_prev_y;
  13026. v_trans_y = v_prev_x;
  13027. shrink_by = Math.sqrt( v_prev_lensq );
  13028. } else {
  13029. // console.log("Warning: lines are a straight spike");
  13030. v_trans_x = v_prev_x;
  13031. v_trans_y = v_prev_y;
  13032. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  13033. }
  13034. }
  13035. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  13036. }
  13037. const contourMovements = [];
  13038. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13039. if ( j === il ) j = 0;
  13040. if ( k === il ) k = 0;
  13041. // (j)---(i)---(k)
  13042. // console.log('i,j,k', i, j , k)
  13043. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  13044. }
  13045. const holesMovements = [];
  13046. let oneHoleMovements, verticesMovements = contourMovements.concat();
  13047. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13048. const ahole = holes[ h ];
  13049. oneHoleMovements = [];
  13050. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13051. if ( j === il ) j = 0;
  13052. if ( k === il ) k = 0;
  13053. // (j)---(i)---(k)
  13054. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  13055. }
  13056. holesMovements.push( oneHoleMovements );
  13057. verticesMovements = verticesMovements.concat( oneHoleMovements );
  13058. }
  13059. // Loop bevelSegments, 1 for the front, 1 for the back
  13060. for ( let b = 0; b < bevelSegments; b ++ ) {
  13061. //for ( b = bevelSegments; b > 0; b -- ) {
  13062. const t = b / bevelSegments;
  13063. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13064. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13065. // contract shape
  13066. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13067. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13068. v( vert.x, vert.y, - z );
  13069. }
  13070. // expand holes
  13071. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13072. const ahole = holes[ h ];
  13073. oneHoleMovements = holesMovements[ h ];
  13074. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13075. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13076. v( vert.x, vert.y, - z );
  13077. }
  13078. }
  13079. }
  13080. const bs = bevelSize + bevelOffset;
  13081. // Back facing vertices
  13082. for ( let i = 0; i < vlen; i ++ ) {
  13083. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13084. if ( ! extrudeByPath ) {
  13085. v( vert.x, vert.y, 0 );
  13086. } else {
  13087. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  13088. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  13089. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  13090. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  13091. v( position2.x, position2.y, position2.z );
  13092. }
  13093. }
  13094. // Add stepped vertices...
  13095. // Including front facing vertices
  13096. for ( let s = 1; s <= steps; s ++ ) {
  13097. for ( let i = 0; i < vlen; i ++ ) {
  13098. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13099. if ( ! extrudeByPath ) {
  13100. v( vert.x, vert.y, depth / steps * s );
  13101. } else {
  13102. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  13103. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  13104. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  13105. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  13106. v( position2.x, position2.y, position2.z );
  13107. }
  13108. }
  13109. }
  13110. // Add bevel segments planes
  13111. //for ( b = 1; b <= bevelSegments; b ++ ) {
  13112. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  13113. const t = b / bevelSegments;
  13114. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13115. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13116. // contract shape
  13117. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13118. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13119. v( vert.x, vert.y, depth + z );
  13120. }
  13121. // expand holes
  13122. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13123. const ahole = holes[ h ];
  13124. oneHoleMovements = holesMovements[ h ];
  13125. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13126. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13127. if ( ! extrudeByPath ) {
  13128. v( vert.x, vert.y, depth + z );
  13129. } else {
  13130. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  13131. }
  13132. }
  13133. }
  13134. }
  13135. /* Faces */
  13136. // Top and bottom faces
  13137. buildLidFaces();
  13138. // Sides faces
  13139. buildSideFaces();
  13140. ///// Internal functions
  13141. function buildLidFaces() {
  13142. const start = verticesArray.length / 3;
  13143. if ( bevelEnabled ) {
  13144. let layer = 0; // steps + 1
  13145. let offset = vlen * layer;
  13146. // Bottom faces
  13147. for ( let i = 0; i < flen; i ++ ) {
  13148. const face = faces[ i ];
  13149. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  13150. }
  13151. layer = steps + bevelSegments * 2;
  13152. offset = vlen * layer;
  13153. // Top faces
  13154. for ( let i = 0; i < flen; i ++ ) {
  13155. const face = faces[ i ];
  13156. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  13157. }
  13158. } else {
  13159. // Bottom faces
  13160. for ( let i = 0; i < flen; i ++ ) {
  13161. const face = faces[ i ];
  13162. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  13163. }
  13164. // Top faces
  13165. for ( let i = 0; i < flen; i ++ ) {
  13166. const face = faces[ i ];
  13167. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  13168. }
  13169. }
  13170. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  13171. }
  13172. // Create faces for the z-sides of the shape
  13173. function buildSideFaces() {
  13174. const start = verticesArray.length / 3;
  13175. let layeroffset = 0;
  13176. sidewalls( contour, layeroffset );
  13177. layeroffset += contour.length;
  13178. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13179. const ahole = holes[ h ];
  13180. sidewalls( ahole, layeroffset );
  13181. //, true
  13182. layeroffset += ahole.length;
  13183. }
  13184. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  13185. }
  13186. function sidewalls( contour, layeroffset ) {
  13187. let i = contour.length;
  13188. while ( -- i >= 0 ) {
  13189. const j = i;
  13190. let k = i - 1;
  13191. if ( k < 0 ) k = contour.length - 1;
  13192. //console.log('b', i,j, i-1, k,vertices.length);
  13193. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  13194. const slen1 = vlen * s;
  13195. const slen2 = vlen * ( s + 1 );
  13196. const a = layeroffset + j + slen1,
  13197. b = layeroffset + k + slen1,
  13198. c = layeroffset + k + slen2,
  13199. d = layeroffset + j + slen2;
  13200. f4( a, b, c, d );
  13201. }
  13202. }
  13203. }
  13204. function v( x, y, z ) {
  13205. placeholder.push( x );
  13206. placeholder.push( y );
  13207. placeholder.push( z );
  13208. }
  13209. function f3( a, b, c ) {
  13210. addVertex( a );
  13211. addVertex( b );
  13212. addVertex( c );
  13213. const nextIndex = verticesArray.length / 3;
  13214. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13215. addUV( uvs[ 0 ] );
  13216. addUV( uvs[ 1 ] );
  13217. addUV( uvs[ 2 ] );
  13218. }
  13219. function f4( a, b, c, d ) {
  13220. addVertex( a );
  13221. addVertex( b );
  13222. addVertex( d );
  13223. addVertex( b );
  13224. addVertex( c );
  13225. addVertex( d );
  13226. const nextIndex = verticesArray.length / 3;
  13227. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13228. addUV( uvs[ 0 ] );
  13229. addUV( uvs[ 1 ] );
  13230. addUV( uvs[ 3 ] );
  13231. addUV( uvs[ 1 ] );
  13232. addUV( uvs[ 2 ] );
  13233. addUV( uvs[ 3 ] );
  13234. }
  13235. function addVertex( index ) {
  13236. verticesArray.push( placeholder[ index * 3 + 0 ] );
  13237. verticesArray.push( placeholder[ index * 3 + 1 ] );
  13238. verticesArray.push( placeholder[ index * 3 + 2 ] );
  13239. }
  13240. function addUV( vector2 ) {
  13241. uvArray.push( vector2.x );
  13242. uvArray.push( vector2.y );
  13243. }
  13244. }
  13245. }
  13246. copy( source ) {
  13247. super.copy( source );
  13248. this.parameters = Object.assign( {}, source.parameters );
  13249. return this;
  13250. }
  13251. toJSON() {
  13252. const data = super.toJSON();
  13253. const shapes = this.parameters.shapes;
  13254. const options = this.parameters.options;
  13255. return toJSON$1( shapes, options, data );
  13256. }
  13257. static fromJSON( data, shapes ) {
  13258. const geometryShapes = [];
  13259. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13260. const shape = shapes[ data.shapes[ j ] ];
  13261. geometryShapes.push( shape );
  13262. }
  13263. const extrudePath = data.options.extrudePath;
  13264. if ( extrudePath !== undefined ) {
  13265. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  13266. }
  13267. return new ExtrudeGeometry( geometryShapes, data.options );
  13268. }
  13269. }
  13270. const WorldUVGenerator = {
  13271. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  13272. const a_x = vertices[ indexA * 3 ];
  13273. const a_y = vertices[ indexA * 3 + 1 ];
  13274. const b_x = vertices[ indexB * 3 ];
  13275. const b_y = vertices[ indexB * 3 + 1 ];
  13276. const c_x = vertices[ indexC * 3 ];
  13277. const c_y = vertices[ indexC * 3 + 1 ];
  13278. return [
  13279. new Vector2( a_x, a_y ),
  13280. new Vector2( b_x, b_y ),
  13281. new Vector2( c_x, c_y )
  13282. ];
  13283. },
  13284. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  13285. const a_x = vertices[ indexA * 3 ];
  13286. const a_y = vertices[ indexA * 3 + 1 ];
  13287. const a_z = vertices[ indexA * 3 + 2 ];
  13288. const b_x = vertices[ indexB * 3 ];
  13289. const b_y = vertices[ indexB * 3 + 1 ];
  13290. const b_z = vertices[ indexB * 3 + 2 ];
  13291. const c_x = vertices[ indexC * 3 ];
  13292. const c_y = vertices[ indexC * 3 + 1 ];
  13293. const c_z = vertices[ indexC * 3 + 2 ];
  13294. const d_x = vertices[ indexD * 3 ];
  13295. const d_y = vertices[ indexD * 3 + 1 ];
  13296. const d_z = vertices[ indexD * 3 + 2 ];
  13297. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  13298. return [
  13299. new Vector2( a_x, 1 - a_z ),
  13300. new Vector2( b_x, 1 - b_z ),
  13301. new Vector2( c_x, 1 - c_z ),
  13302. new Vector2( d_x, 1 - d_z )
  13303. ];
  13304. } else {
  13305. return [
  13306. new Vector2( a_y, 1 - a_z ),
  13307. new Vector2( b_y, 1 - b_z ),
  13308. new Vector2( c_y, 1 - c_z ),
  13309. new Vector2( d_y, 1 - d_z )
  13310. ];
  13311. }
  13312. }
  13313. };
  13314. function toJSON$1( shapes, options, data ) {
  13315. data.shapes = [];
  13316. if ( Array.isArray( shapes ) ) {
  13317. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13318. const shape = shapes[ i ];
  13319. data.shapes.push( shape.uuid );
  13320. }
  13321. } else {
  13322. data.shapes.push( shapes.uuid );
  13323. }
  13324. data.options = Object.assign( {}, options );
  13325. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  13326. return data;
  13327. }
  13328. class IcosahedronGeometry extends PolyhedronGeometry {
  13329. constructor( radius = 1, detail = 0 ) {
  13330. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  13331. const vertices = [
  13332. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  13333. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  13334. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  13335. ];
  13336. const indices = [
  13337. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  13338. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  13339. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  13340. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  13341. ];
  13342. super( vertices, indices, radius, detail );
  13343. this.type = 'IcosahedronGeometry';
  13344. this.parameters = {
  13345. radius: radius,
  13346. detail: detail
  13347. };
  13348. }
  13349. static fromJSON( data ) {
  13350. return new IcosahedronGeometry( data.radius, data.detail );
  13351. }
  13352. }
  13353. class OctahedronGeometry extends PolyhedronGeometry {
  13354. constructor( radius = 1, detail = 0 ) {
  13355. const vertices = [
  13356. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  13357. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  13358. ];
  13359. const indices = [
  13360. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  13361. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  13362. 1, 3, 4, 1, 4, 2
  13363. ];
  13364. super( vertices, indices, radius, detail );
  13365. this.type = 'OctahedronGeometry';
  13366. this.parameters = {
  13367. radius: radius,
  13368. detail: detail
  13369. };
  13370. }
  13371. static fromJSON( data ) {
  13372. return new OctahedronGeometry( data.radius, data.detail );
  13373. }
  13374. }
  13375. class PlaneGeometry extends BufferGeometry {
  13376. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  13377. super();
  13378. this.type = 'PlaneGeometry';
  13379. this.parameters = {
  13380. width: width,
  13381. height: height,
  13382. widthSegments: widthSegments,
  13383. heightSegments: heightSegments
  13384. };
  13385. const width_half = width / 2;
  13386. const height_half = height / 2;
  13387. const gridX = Math.floor( widthSegments );
  13388. const gridY = Math.floor( heightSegments );
  13389. const gridX1 = gridX + 1;
  13390. const gridY1 = gridY + 1;
  13391. const segment_width = width / gridX;
  13392. const segment_height = height / gridY;
  13393. //
  13394. const indices = [];
  13395. const vertices = [];
  13396. const normals = [];
  13397. const uvs = [];
  13398. for ( let iy = 0; iy < gridY1; iy ++ ) {
  13399. const y = iy * segment_height - height_half;
  13400. for ( let ix = 0; ix < gridX1; ix ++ ) {
  13401. const x = ix * segment_width - width_half;
  13402. vertices.push( x, - y, 0 );
  13403. normals.push( 0, 0, 1 );
  13404. uvs.push( ix / gridX );
  13405. uvs.push( 1 - ( iy / gridY ) );
  13406. }
  13407. }
  13408. for ( let iy = 0; iy < gridY; iy ++ ) {
  13409. for ( let ix = 0; ix < gridX; ix ++ ) {
  13410. const a = ix + gridX1 * iy;
  13411. const b = ix + gridX1 * ( iy + 1 );
  13412. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  13413. const d = ( ix + 1 ) + gridX1 * iy;
  13414. indices.push( a, b, d );
  13415. indices.push( b, c, d );
  13416. }
  13417. }
  13418. this.setIndex( indices );
  13419. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13420. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13421. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13422. }
  13423. copy( source ) {
  13424. super.copy( source );
  13425. this.parameters = Object.assign( {}, source.parameters );
  13426. return this;
  13427. }
  13428. static fromJSON( data ) {
  13429. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  13430. }
  13431. }
  13432. class RingGeometry extends BufferGeometry {
  13433. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  13434. super();
  13435. this.type = 'RingGeometry';
  13436. this.parameters = {
  13437. innerRadius: innerRadius,
  13438. outerRadius: outerRadius,
  13439. thetaSegments: thetaSegments,
  13440. phiSegments: phiSegments,
  13441. thetaStart: thetaStart,
  13442. thetaLength: thetaLength
  13443. };
  13444. thetaSegments = Math.max( 3, thetaSegments );
  13445. phiSegments = Math.max( 1, phiSegments );
  13446. // buffers
  13447. const indices = [];
  13448. const vertices = [];
  13449. const normals = [];
  13450. const uvs = [];
  13451. // some helper variables
  13452. let radius = innerRadius;
  13453. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  13454. const vertex = new Vector3();
  13455. const uv = new Vector2();
  13456. // generate vertices, normals and uvs
  13457. for ( let j = 0; j <= phiSegments; j ++ ) {
  13458. for ( let i = 0; i <= thetaSegments; i ++ ) {
  13459. // values are generate from the inside of the ring to the outside
  13460. const segment = thetaStart + i / thetaSegments * thetaLength;
  13461. // vertex
  13462. vertex.x = radius * Math.cos( segment );
  13463. vertex.y = radius * Math.sin( segment );
  13464. vertices.push( vertex.x, vertex.y, vertex.z );
  13465. // normal
  13466. normals.push( 0, 0, 1 );
  13467. // uv
  13468. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  13469. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  13470. uvs.push( uv.x, uv.y );
  13471. }
  13472. // increase the radius for next row of vertices
  13473. radius += radiusStep;
  13474. }
  13475. // indices
  13476. for ( let j = 0; j < phiSegments; j ++ ) {
  13477. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  13478. for ( let i = 0; i < thetaSegments; i ++ ) {
  13479. const segment = i + thetaSegmentLevel;
  13480. const a = segment;
  13481. const b = segment + thetaSegments + 1;
  13482. const c = segment + thetaSegments + 2;
  13483. const d = segment + 1;
  13484. // faces
  13485. indices.push( a, b, d );
  13486. indices.push( b, c, d );
  13487. }
  13488. }
  13489. // build geometry
  13490. this.setIndex( indices );
  13491. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13492. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13493. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13494. }
  13495. copy( source ) {
  13496. super.copy( source );
  13497. this.parameters = Object.assign( {}, source.parameters );
  13498. return this;
  13499. }
  13500. static fromJSON( data ) {
  13501. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  13502. }
  13503. }
  13504. class ShapeGeometry extends BufferGeometry {
  13505. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
  13506. super();
  13507. this.type = 'ShapeGeometry';
  13508. this.parameters = {
  13509. shapes: shapes,
  13510. curveSegments: curveSegments
  13511. };
  13512. // buffers
  13513. const indices = [];
  13514. const vertices = [];
  13515. const normals = [];
  13516. const uvs = [];
  13517. // helper variables
  13518. let groupStart = 0;
  13519. let groupCount = 0;
  13520. // allow single and array values for "shapes" parameter
  13521. if ( Array.isArray( shapes ) === false ) {
  13522. addShape( shapes );
  13523. } else {
  13524. for ( let i = 0; i < shapes.length; i ++ ) {
  13525. addShape( shapes[ i ] );
  13526. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  13527. groupStart += groupCount;
  13528. groupCount = 0;
  13529. }
  13530. }
  13531. // build geometry
  13532. this.setIndex( indices );
  13533. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13534. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13535. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13536. // helper functions
  13537. function addShape( shape ) {
  13538. const indexOffset = vertices.length / 3;
  13539. const points = shape.extractPoints( curveSegments );
  13540. let shapeVertices = points.shape;
  13541. const shapeHoles = points.holes;
  13542. // check direction of vertices
  13543. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  13544. shapeVertices = shapeVertices.reverse();
  13545. }
  13546. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13547. const shapeHole = shapeHoles[ i ];
  13548. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  13549. shapeHoles[ i ] = shapeHole.reverse();
  13550. }
  13551. }
  13552. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  13553. // join vertices of inner and outer paths to a single array
  13554. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13555. const shapeHole = shapeHoles[ i ];
  13556. shapeVertices = shapeVertices.concat( shapeHole );
  13557. }
  13558. // vertices, normals, uvs
  13559. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  13560. const vertex = shapeVertices[ i ];
  13561. vertices.push( vertex.x, vertex.y, 0 );
  13562. normals.push( 0, 0, 1 );
  13563. uvs.push( vertex.x, vertex.y ); // world uvs
  13564. }
  13565. // indices
  13566. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  13567. const face = faces[ i ];
  13568. const a = face[ 0 ] + indexOffset;
  13569. const b = face[ 1 ] + indexOffset;
  13570. const c = face[ 2 ] + indexOffset;
  13571. indices.push( a, b, c );
  13572. groupCount += 3;
  13573. }
  13574. }
  13575. }
  13576. copy( source ) {
  13577. super.copy( source );
  13578. this.parameters = Object.assign( {}, source.parameters );
  13579. return this;
  13580. }
  13581. toJSON() {
  13582. const data = super.toJSON();
  13583. const shapes = this.parameters.shapes;
  13584. return toJSON( shapes, data );
  13585. }
  13586. static fromJSON( data, shapes ) {
  13587. const geometryShapes = [];
  13588. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13589. const shape = shapes[ data.shapes[ j ] ];
  13590. geometryShapes.push( shape );
  13591. }
  13592. return new ShapeGeometry( geometryShapes, data.curveSegments );
  13593. }
  13594. }
  13595. function toJSON( shapes, data ) {
  13596. data.shapes = [];
  13597. if ( Array.isArray( shapes ) ) {
  13598. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13599. const shape = shapes[ i ];
  13600. data.shapes.push( shape.uuid );
  13601. }
  13602. } else {
  13603. data.shapes.push( shapes.uuid );
  13604. }
  13605. return data;
  13606. }
  13607. class SphereGeometry extends BufferGeometry {
  13608. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  13609. super();
  13610. this.type = 'SphereGeometry';
  13611. this.parameters = {
  13612. radius: radius,
  13613. widthSegments: widthSegments,
  13614. heightSegments: heightSegments,
  13615. phiStart: phiStart,
  13616. phiLength: phiLength,
  13617. thetaStart: thetaStart,
  13618. thetaLength: thetaLength
  13619. };
  13620. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  13621. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  13622. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  13623. let index = 0;
  13624. const grid = [];
  13625. const vertex = new Vector3();
  13626. const normal = new Vector3();
  13627. // buffers
  13628. const indices = [];
  13629. const vertices = [];
  13630. const normals = [];
  13631. const uvs = [];
  13632. // generate vertices, normals and uvs
  13633. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  13634. const verticesRow = [];
  13635. const v = iy / heightSegments;
  13636. // special case for the poles
  13637. let uOffset = 0;
  13638. if ( iy === 0 && thetaStart === 0 ) {
  13639. uOffset = 0.5 / widthSegments;
  13640. } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
  13641. uOffset = - 0.5 / widthSegments;
  13642. }
  13643. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  13644. const u = ix / widthSegments;
  13645. // vertex
  13646. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13647. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  13648. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13649. vertices.push( vertex.x, vertex.y, vertex.z );
  13650. // normal
  13651. normal.copy( vertex ).normalize();
  13652. normals.push( normal.x, normal.y, normal.z );
  13653. // uv
  13654. uvs.push( u + uOffset, 1 - v );
  13655. verticesRow.push( index ++ );
  13656. }
  13657. grid.push( verticesRow );
  13658. }
  13659. // indices
  13660. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  13661. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  13662. const a = grid[ iy ][ ix + 1 ];
  13663. const b = grid[ iy ][ ix ];
  13664. const c = grid[ iy + 1 ][ ix ];
  13665. const d = grid[ iy + 1 ][ ix + 1 ];
  13666. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  13667. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  13668. }
  13669. }
  13670. // build geometry
  13671. this.setIndex( indices );
  13672. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13673. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13674. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13675. }
  13676. copy( source ) {
  13677. super.copy( source );
  13678. this.parameters = Object.assign( {}, source.parameters );
  13679. return this;
  13680. }
  13681. static fromJSON( data ) {
  13682. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  13683. }
  13684. }
  13685. class TetrahedronGeometry extends PolyhedronGeometry {
  13686. constructor( radius = 1, detail = 0 ) {
  13687. const vertices = [
  13688. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  13689. ];
  13690. const indices = [
  13691. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  13692. ];
  13693. super( vertices, indices, radius, detail );
  13694. this.type = 'TetrahedronGeometry';
  13695. this.parameters = {
  13696. radius: radius,
  13697. detail: detail
  13698. };
  13699. }
  13700. static fromJSON( data ) {
  13701. return new TetrahedronGeometry( data.radius, data.detail );
  13702. }
  13703. }
  13704. class TorusGeometry extends BufferGeometry {
  13705. constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
  13706. super();
  13707. this.type = 'TorusGeometry';
  13708. this.parameters = {
  13709. radius: radius,
  13710. tube: tube,
  13711. radialSegments: radialSegments,
  13712. tubularSegments: tubularSegments,
  13713. arc: arc
  13714. };
  13715. radialSegments = Math.floor( radialSegments );
  13716. tubularSegments = Math.floor( tubularSegments );
  13717. // buffers
  13718. const indices = [];
  13719. const vertices = [];
  13720. const normals = [];
  13721. const uvs = [];
  13722. // helper variables
  13723. const center = new Vector3();
  13724. const vertex = new Vector3();
  13725. const normal = new Vector3();
  13726. // generate vertices, normals and uvs
  13727. for ( let j = 0; j <= radialSegments; j ++ ) {
  13728. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13729. const u = i / tubularSegments * arc;
  13730. const v = j / radialSegments * Math.PI * 2;
  13731. // vertex
  13732. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  13733. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  13734. vertex.z = tube * Math.sin( v );
  13735. vertices.push( vertex.x, vertex.y, vertex.z );
  13736. // normal
  13737. center.x = radius * Math.cos( u );
  13738. center.y = radius * Math.sin( u );
  13739. normal.subVectors( vertex, center ).normalize();
  13740. normals.push( normal.x, normal.y, normal.z );
  13741. // uv
  13742. uvs.push( i / tubularSegments );
  13743. uvs.push( j / radialSegments );
  13744. }
  13745. }
  13746. // generate indices
  13747. for ( let j = 1; j <= radialSegments; j ++ ) {
  13748. for ( let i = 1; i <= tubularSegments; i ++ ) {
  13749. // indices
  13750. const a = ( tubularSegments + 1 ) * j + i - 1;
  13751. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  13752. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  13753. const d = ( tubularSegments + 1 ) * j + i;
  13754. // faces
  13755. indices.push( a, b, d );
  13756. indices.push( b, c, d );
  13757. }
  13758. }
  13759. // build geometry
  13760. this.setIndex( indices );
  13761. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13762. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13763. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13764. }
  13765. copy( source ) {
  13766. super.copy( source );
  13767. this.parameters = Object.assign( {}, source.parameters );
  13768. return this;
  13769. }
  13770. static fromJSON( data ) {
  13771. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  13772. }
  13773. }
  13774. class TorusKnotGeometry extends BufferGeometry {
  13775. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  13776. super();
  13777. this.type = 'TorusKnotGeometry';
  13778. this.parameters = {
  13779. radius: radius,
  13780. tube: tube,
  13781. tubularSegments: tubularSegments,
  13782. radialSegments: radialSegments,
  13783. p: p,
  13784. q: q
  13785. };
  13786. tubularSegments = Math.floor( tubularSegments );
  13787. radialSegments = Math.floor( radialSegments );
  13788. // buffers
  13789. const indices = [];
  13790. const vertices = [];
  13791. const normals = [];
  13792. const uvs = [];
  13793. // helper variables
  13794. const vertex = new Vector3();
  13795. const normal = new Vector3();
  13796. const P1 = new Vector3();
  13797. const P2 = new Vector3();
  13798. const B = new Vector3();
  13799. const T = new Vector3();
  13800. const N = new Vector3();
  13801. // generate vertices, normals and uvs
  13802. for ( let i = 0; i <= tubularSegments; ++ i ) {
  13803. // the radian "u" is used to calculate the position on the torus curve of the current tubular segment
  13804. const u = i / tubularSegments * p * Math.PI * 2;
  13805. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  13806. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  13807. calculatePositionOnCurve( u, p, q, radius, P1 );
  13808. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  13809. // calculate orthonormal basis
  13810. T.subVectors( P2, P1 );
  13811. N.addVectors( P2, P1 );
  13812. B.crossVectors( T, N );
  13813. N.crossVectors( B, T );
  13814. // normalize B, N. T can be ignored, we don't use it
  13815. B.normalize();
  13816. N.normalize();
  13817. for ( let j = 0; j <= radialSegments; ++ j ) {
  13818. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  13819. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  13820. const v = j / radialSegments * Math.PI * 2;
  13821. const cx = - tube * Math.cos( v );
  13822. const cy = tube * Math.sin( v );
  13823. // now calculate the final vertex position.
  13824. // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve
  13825. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  13826. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  13827. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  13828. vertices.push( vertex.x, vertex.y, vertex.z );
  13829. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  13830. normal.subVectors( vertex, P1 ).normalize();
  13831. normals.push( normal.x, normal.y, normal.z );
  13832. // uv
  13833. uvs.push( i / tubularSegments );
  13834. uvs.push( j / radialSegments );
  13835. }
  13836. }
  13837. // generate indices
  13838. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13839. for ( let i = 1; i <= radialSegments; i ++ ) {
  13840. // indices
  13841. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13842. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13843. const c = ( radialSegments + 1 ) * j + i;
  13844. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13845. // faces
  13846. indices.push( a, b, d );
  13847. indices.push( b, c, d );
  13848. }
  13849. }
  13850. // build geometry
  13851. this.setIndex( indices );
  13852. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13853. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13854. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13855. // this function calculates the current position on the torus curve
  13856. function calculatePositionOnCurve( u, p, q, radius, position ) {
  13857. const cu = Math.cos( u );
  13858. const su = Math.sin( u );
  13859. const quOverP = q / p * u;
  13860. const cs = Math.cos( quOverP );
  13861. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  13862. position.y = radius * ( 2 + cs ) * su * 0.5;
  13863. position.z = radius * Math.sin( quOverP ) * 0.5;
  13864. }
  13865. }
  13866. copy( source ) {
  13867. super.copy( source );
  13868. this.parameters = Object.assign( {}, source.parameters );
  13869. return this;
  13870. }
  13871. static fromJSON( data ) {
  13872. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  13873. }
  13874. }
  13875. class TubeGeometry extends BufferGeometry {
  13876. 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 ) {
  13877. super();
  13878. this.type = 'TubeGeometry';
  13879. this.parameters = {
  13880. path: path,
  13881. tubularSegments: tubularSegments,
  13882. radius: radius,
  13883. radialSegments: radialSegments,
  13884. closed: closed
  13885. };
  13886. const frames = path.computeFrenetFrames( tubularSegments, closed );
  13887. // expose internals
  13888. this.tangents = frames.tangents;
  13889. this.normals = frames.normals;
  13890. this.binormals = frames.binormals;
  13891. // helper variables
  13892. const vertex = new Vector3();
  13893. const normal = new Vector3();
  13894. const uv = new Vector2();
  13895. let P = new Vector3();
  13896. // buffer
  13897. const vertices = [];
  13898. const normals = [];
  13899. const uvs = [];
  13900. const indices = [];
  13901. // create buffer data
  13902. generateBufferData();
  13903. // build geometry
  13904. this.setIndex( indices );
  13905. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13906. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13907. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13908. // functions
  13909. function generateBufferData() {
  13910. for ( let i = 0; i < tubularSegments; i ++ ) {
  13911. generateSegment( i );
  13912. }
  13913. // if the geometry is not closed, generate the last row of vertices and normals
  13914. // at the regular position on the given path
  13915. //
  13916. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  13917. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  13918. // uvs are generated in a separate function.
  13919. // this makes it easy compute correct values for closed geometries
  13920. generateUVs();
  13921. // finally create faces
  13922. generateIndices();
  13923. }
  13924. function generateSegment( i ) {
  13925. // we use getPointAt to sample evenly distributed points from the given path
  13926. P = path.getPointAt( i / tubularSegments, P );
  13927. // retrieve corresponding normal and binormal
  13928. const N = frames.normals[ i ];
  13929. const B = frames.binormals[ i ];
  13930. // generate normals and vertices for the current segment
  13931. for ( let j = 0; j <= radialSegments; j ++ ) {
  13932. const v = j / radialSegments * Math.PI * 2;
  13933. const sin = Math.sin( v );
  13934. const cos = - Math.cos( v );
  13935. // normal
  13936. normal.x = ( cos * N.x + sin * B.x );
  13937. normal.y = ( cos * N.y + sin * B.y );
  13938. normal.z = ( cos * N.z + sin * B.z );
  13939. normal.normalize();
  13940. normals.push( normal.x, normal.y, normal.z );
  13941. // vertex
  13942. vertex.x = P.x + radius * normal.x;
  13943. vertex.y = P.y + radius * normal.y;
  13944. vertex.z = P.z + radius * normal.z;
  13945. vertices.push( vertex.x, vertex.y, vertex.z );
  13946. }
  13947. }
  13948. function generateIndices() {
  13949. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13950. for ( let i = 1; i <= radialSegments; i ++ ) {
  13951. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13952. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13953. const c = ( radialSegments + 1 ) * j + i;
  13954. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13955. // faces
  13956. indices.push( a, b, d );
  13957. indices.push( b, c, d );
  13958. }
  13959. }
  13960. }
  13961. function generateUVs() {
  13962. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13963. for ( let j = 0; j <= radialSegments; j ++ ) {
  13964. uv.x = i / tubularSegments;
  13965. uv.y = j / radialSegments;
  13966. uvs.push( uv.x, uv.y );
  13967. }
  13968. }
  13969. }
  13970. }
  13971. copy( source ) {
  13972. super.copy( source );
  13973. this.parameters = Object.assign( {}, source.parameters );
  13974. return this;
  13975. }
  13976. toJSON() {
  13977. const data = super.toJSON();
  13978. data.path = this.parameters.path.toJSON();
  13979. return data;
  13980. }
  13981. static fromJSON( data ) {
  13982. // This only works for built-in curves (e.g. CatmullRomCurve3).
  13983. // User defined curves or instances of CurvePath will not be deserialized.
  13984. return new TubeGeometry(
  13985. new Curves[ data.path.type ]().fromJSON( data.path ),
  13986. data.tubularSegments,
  13987. data.radius,
  13988. data.radialSegments,
  13989. data.closed
  13990. );
  13991. }
  13992. }
  13993. class WireframeGeometry extends BufferGeometry {
  13994. constructor( geometry = null ) {
  13995. super();
  13996. this.type = 'WireframeGeometry';
  13997. this.parameters = {
  13998. geometry: geometry
  13999. };
  14000. if ( geometry !== null ) {
  14001. // buffer
  14002. const vertices = [];
  14003. const edges = new Set();
  14004. // helper variables
  14005. const start = new Vector3();
  14006. const end = new Vector3();
  14007. if ( geometry.index !== null ) {
  14008. // indexed BufferGeometry
  14009. const position = geometry.attributes.position;
  14010. const indices = geometry.index;
  14011. let groups = geometry.groups;
  14012. if ( groups.length === 0 ) {
  14013. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14014. }
  14015. // create a data structure that contains all edges without duplicates
  14016. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  14017. const group = groups[ o ];
  14018. const groupStart = group.start;
  14019. const groupCount = group.count;
  14020. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  14021. for ( let j = 0; j < 3; j ++ ) {
  14022. const index1 = indices.getX( i + j );
  14023. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  14024. start.fromBufferAttribute( position, index1 );
  14025. end.fromBufferAttribute( position, index2 );
  14026. if ( isUniqueEdge( start, end, edges ) === true ) {
  14027. vertices.push( start.x, start.y, start.z );
  14028. vertices.push( end.x, end.y, end.z );
  14029. }
  14030. }
  14031. }
  14032. }
  14033. } else {
  14034. // non-indexed BufferGeometry
  14035. const position = geometry.attributes.position;
  14036. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14037. for ( let j = 0; j < 3; j ++ ) {
  14038. // three edges per triangle, an edge is represented as (index1, index2)
  14039. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14040. const index1 = 3 * i + j;
  14041. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  14042. start.fromBufferAttribute( position, index1 );
  14043. end.fromBufferAttribute( position, index2 );
  14044. if ( isUniqueEdge( start, end, edges ) === true ) {
  14045. vertices.push( start.x, start.y, start.z );
  14046. vertices.push( end.x, end.y, end.z );
  14047. }
  14048. }
  14049. }
  14050. }
  14051. // build geometry
  14052. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14053. }
  14054. }
  14055. copy( source ) {
  14056. super.copy( source );
  14057. this.parameters = Object.assign( {}, source.parameters );
  14058. return this;
  14059. }
  14060. }
  14061. function isUniqueEdge( start, end, edges ) {
  14062. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  14063. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  14064. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  14065. return false;
  14066. } else {
  14067. edges.add( hash1 );
  14068. edges.add( hash2 );
  14069. return true;
  14070. }
  14071. }
  14072. var Geometries = /*#__PURE__*/Object.freeze({
  14073. __proto__: null,
  14074. BoxGeometry: BoxGeometry,
  14075. CapsuleGeometry: CapsuleGeometry,
  14076. CircleGeometry: CircleGeometry,
  14077. ConeGeometry: ConeGeometry,
  14078. CylinderGeometry: CylinderGeometry,
  14079. DodecahedronGeometry: DodecahedronGeometry,
  14080. EdgesGeometry: EdgesGeometry,
  14081. ExtrudeGeometry: ExtrudeGeometry,
  14082. IcosahedronGeometry: IcosahedronGeometry,
  14083. LatheGeometry: LatheGeometry,
  14084. OctahedronGeometry: OctahedronGeometry,
  14085. PlaneGeometry: PlaneGeometry,
  14086. PolyhedronGeometry: PolyhedronGeometry,
  14087. RingGeometry: RingGeometry,
  14088. ShapeGeometry: ShapeGeometry,
  14089. SphereGeometry: SphereGeometry,
  14090. TetrahedronGeometry: TetrahedronGeometry,
  14091. TorusGeometry: TorusGeometry,
  14092. TorusKnotGeometry: TorusKnotGeometry,
  14093. TubeGeometry: TubeGeometry,
  14094. WireframeGeometry: WireframeGeometry
  14095. });
  14096. class ShadowMaterial extends Material {
  14097. constructor( parameters ) {
  14098. super();
  14099. this.isShadowMaterial = true;
  14100. this.type = 'ShadowMaterial';
  14101. this.color = new Color( 0x000000 );
  14102. this.transparent = true;
  14103. this.fog = true;
  14104. this.setValues( parameters );
  14105. }
  14106. copy( source ) {
  14107. super.copy( source );
  14108. this.color.copy( source.color );
  14109. this.fog = source.fog;
  14110. return this;
  14111. }
  14112. }
  14113. class RawShaderMaterial extends ShaderMaterial {
  14114. constructor( parameters ) {
  14115. super( parameters );
  14116. this.isRawShaderMaterial = true;
  14117. this.type = 'RawShaderMaterial';
  14118. }
  14119. }
  14120. class MeshStandardMaterial extends Material {
  14121. constructor( parameters ) {
  14122. super();
  14123. this.isMeshStandardMaterial = true;
  14124. this.type = 'MeshStandardMaterial';
  14125. this.defines = { 'STANDARD': '' };
  14126. this.color = new Color( 0xffffff ); // diffuse
  14127. this.roughness = 1.0;
  14128. this.metalness = 0.0;
  14129. this.map = null;
  14130. this.lightMap = null;
  14131. this.lightMapIntensity = 1.0;
  14132. this.aoMap = null;
  14133. this.aoMapIntensity = 1.0;
  14134. this.emissive = new Color( 0x000000 );
  14135. this.emissiveIntensity = 1.0;
  14136. this.emissiveMap = null;
  14137. this.bumpMap = null;
  14138. this.bumpScale = 1;
  14139. this.normalMap = null;
  14140. this.normalMapType = TangentSpaceNormalMap;
  14141. this.normalScale = new Vector2( 1, 1 );
  14142. this.displacementMap = null;
  14143. this.displacementScale = 1;
  14144. this.displacementBias = 0;
  14145. this.roughnessMap = null;
  14146. this.metalnessMap = null;
  14147. this.alphaMap = null;
  14148. this.envMap = null;
  14149. this.envMapRotation = new Euler();
  14150. this.envMapIntensity = 1.0;
  14151. this.wireframe = false;
  14152. this.wireframeLinewidth = 1;
  14153. this.wireframeLinecap = 'round';
  14154. this.wireframeLinejoin = 'round';
  14155. this.flatShading = false;
  14156. this.fog = true;
  14157. this.setValues( parameters );
  14158. }
  14159. copy( source ) {
  14160. super.copy( source );
  14161. this.defines = { 'STANDARD': '' };
  14162. this.color.copy( source.color );
  14163. this.roughness = source.roughness;
  14164. this.metalness = source.metalness;
  14165. this.map = source.map;
  14166. this.lightMap = source.lightMap;
  14167. this.lightMapIntensity = source.lightMapIntensity;
  14168. this.aoMap = source.aoMap;
  14169. this.aoMapIntensity = source.aoMapIntensity;
  14170. this.emissive.copy( source.emissive );
  14171. this.emissiveMap = source.emissiveMap;
  14172. this.emissiveIntensity = source.emissiveIntensity;
  14173. this.bumpMap = source.bumpMap;
  14174. this.bumpScale = source.bumpScale;
  14175. this.normalMap = source.normalMap;
  14176. this.normalMapType = source.normalMapType;
  14177. this.normalScale.copy( source.normalScale );
  14178. this.displacementMap = source.displacementMap;
  14179. this.displacementScale = source.displacementScale;
  14180. this.displacementBias = source.displacementBias;
  14181. this.roughnessMap = source.roughnessMap;
  14182. this.metalnessMap = source.metalnessMap;
  14183. this.alphaMap = source.alphaMap;
  14184. this.envMap = source.envMap;
  14185. this.envMapRotation.copy( source.envMapRotation );
  14186. this.envMapIntensity = source.envMapIntensity;
  14187. this.wireframe = source.wireframe;
  14188. this.wireframeLinewidth = source.wireframeLinewidth;
  14189. this.wireframeLinecap = source.wireframeLinecap;
  14190. this.wireframeLinejoin = source.wireframeLinejoin;
  14191. this.flatShading = source.flatShading;
  14192. this.fog = source.fog;
  14193. return this;
  14194. }
  14195. }
  14196. class MeshPhysicalMaterial extends MeshStandardMaterial {
  14197. constructor( parameters ) {
  14198. super();
  14199. this.isMeshPhysicalMaterial = true;
  14200. this.defines = {
  14201. 'STANDARD': '',
  14202. 'PHYSICAL': ''
  14203. };
  14204. this.type = 'MeshPhysicalMaterial';
  14205. this.anisotropyRotation = 0;
  14206. this.anisotropyMap = null;
  14207. this.clearcoatMap = null;
  14208. this.clearcoatRoughness = 0.0;
  14209. this.clearcoatRoughnessMap = null;
  14210. this.clearcoatNormalScale = new Vector2( 1, 1 );
  14211. this.clearcoatNormalMap = null;
  14212. this.ior = 1.5;
  14213. Object.defineProperty( this, 'reflectivity', {
  14214. get: function () {
  14215. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  14216. },
  14217. set: function ( reflectivity ) {
  14218. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  14219. }
  14220. } );
  14221. this.iridescenceMap = null;
  14222. this.iridescenceIOR = 1.3;
  14223. this.iridescenceThicknessRange = [ 100, 400 ];
  14224. this.iridescenceThicknessMap = null;
  14225. this.sheenColor = new Color( 0x000000 );
  14226. this.sheenColorMap = null;
  14227. this.sheenRoughness = 1.0;
  14228. this.sheenRoughnessMap = null;
  14229. this.transmissionMap = null;
  14230. this.thickness = 0;
  14231. this.thicknessMap = null;
  14232. this.attenuationDistance = Infinity;
  14233. this.attenuationColor = new Color( 1, 1, 1 );
  14234. this.specularIntensity = 1.0;
  14235. this.specularIntensityMap = null;
  14236. this.specularColor = new Color( 1, 1, 1 );
  14237. this.specularColorMap = null;
  14238. this._anisotropy = 0;
  14239. this._clearcoat = 0;
  14240. this._dispersion = 0;
  14241. this._iridescence = 0;
  14242. this._sheen = 0.0;
  14243. this._transmission = 0;
  14244. this.setValues( parameters );
  14245. }
  14246. get anisotropy() {
  14247. return this._anisotropy;
  14248. }
  14249. set anisotropy( value ) {
  14250. if ( this._anisotropy > 0 !== value > 0 ) {
  14251. this.version ++;
  14252. }
  14253. this._anisotropy = value;
  14254. }
  14255. get clearcoat() {
  14256. return this._clearcoat;
  14257. }
  14258. set clearcoat( value ) {
  14259. if ( this._clearcoat > 0 !== value > 0 ) {
  14260. this.version ++;
  14261. }
  14262. this._clearcoat = value;
  14263. }
  14264. get iridescence() {
  14265. return this._iridescence;
  14266. }
  14267. set iridescence( value ) {
  14268. if ( this._iridescence > 0 !== value > 0 ) {
  14269. this.version ++;
  14270. }
  14271. this._iridescence = value;
  14272. }
  14273. get dispersion() {
  14274. return this._dispersion;
  14275. }
  14276. set dispersion( value ) {
  14277. if ( this._dispersion > 0 !== value > 0 ) {
  14278. this.version ++;
  14279. }
  14280. this._dispersion = value;
  14281. }
  14282. get sheen() {
  14283. return this._sheen;
  14284. }
  14285. set sheen( value ) {
  14286. if ( this._sheen > 0 !== value > 0 ) {
  14287. this.version ++;
  14288. }
  14289. this._sheen = value;
  14290. }
  14291. get transmission() {
  14292. return this._transmission;
  14293. }
  14294. set transmission( value ) {
  14295. if ( this._transmission > 0 !== value > 0 ) {
  14296. this.version ++;
  14297. }
  14298. this._transmission = value;
  14299. }
  14300. copy( source ) {
  14301. super.copy( source );
  14302. this.defines = {
  14303. 'STANDARD': '',
  14304. 'PHYSICAL': ''
  14305. };
  14306. this.anisotropy = source.anisotropy;
  14307. this.anisotropyRotation = source.anisotropyRotation;
  14308. this.anisotropyMap = source.anisotropyMap;
  14309. this.clearcoat = source.clearcoat;
  14310. this.clearcoatMap = source.clearcoatMap;
  14311. this.clearcoatRoughness = source.clearcoatRoughness;
  14312. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  14313. this.clearcoatNormalMap = source.clearcoatNormalMap;
  14314. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  14315. this.dispersion = source.dispersion;
  14316. this.ior = source.ior;
  14317. this.iridescence = source.iridescence;
  14318. this.iridescenceMap = source.iridescenceMap;
  14319. this.iridescenceIOR = source.iridescenceIOR;
  14320. this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ];
  14321. this.iridescenceThicknessMap = source.iridescenceThicknessMap;
  14322. this.sheen = source.sheen;
  14323. this.sheenColor.copy( source.sheenColor );
  14324. this.sheenColorMap = source.sheenColorMap;
  14325. this.sheenRoughness = source.sheenRoughness;
  14326. this.sheenRoughnessMap = source.sheenRoughnessMap;
  14327. this.transmission = source.transmission;
  14328. this.transmissionMap = source.transmissionMap;
  14329. this.thickness = source.thickness;
  14330. this.thicknessMap = source.thicknessMap;
  14331. this.attenuationDistance = source.attenuationDistance;
  14332. this.attenuationColor.copy( source.attenuationColor );
  14333. this.specularIntensity = source.specularIntensity;
  14334. this.specularIntensityMap = source.specularIntensityMap;
  14335. this.specularColor.copy( source.specularColor );
  14336. this.specularColorMap = source.specularColorMap;
  14337. return this;
  14338. }
  14339. }
  14340. class MeshPhongMaterial extends Material {
  14341. constructor( parameters ) {
  14342. super();
  14343. this.isMeshPhongMaterial = true;
  14344. this.type = 'MeshPhongMaterial';
  14345. this.color = new Color( 0xffffff ); // diffuse
  14346. this.specular = new Color( 0x111111 );
  14347. this.shininess = 30;
  14348. this.map = null;
  14349. this.lightMap = null;
  14350. this.lightMapIntensity = 1.0;
  14351. this.aoMap = null;
  14352. this.aoMapIntensity = 1.0;
  14353. this.emissive = new Color( 0x000000 );
  14354. this.emissiveIntensity = 1.0;
  14355. this.emissiveMap = null;
  14356. this.bumpMap = null;
  14357. this.bumpScale = 1;
  14358. this.normalMap = null;
  14359. this.normalMapType = TangentSpaceNormalMap;
  14360. this.normalScale = new Vector2( 1, 1 );
  14361. this.displacementMap = null;
  14362. this.displacementScale = 1;
  14363. this.displacementBias = 0;
  14364. this.specularMap = null;
  14365. this.alphaMap = null;
  14366. this.envMap = null;
  14367. this.envMapRotation = new Euler();
  14368. this.combine = MultiplyOperation;
  14369. this.reflectivity = 1;
  14370. this.refractionRatio = 0.98;
  14371. this.wireframe = false;
  14372. this.wireframeLinewidth = 1;
  14373. this.wireframeLinecap = 'round';
  14374. this.wireframeLinejoin = 'round';
  14375. this.flatShading = false;
  14376. this.fog = true;
  14377. this.setValues( parameters );
  14378. }
  14379. copy( source ) {
  14380. super.copy( source );
  14381. this.color.copy( source.color );
  14382. this.specular.copy( source.specular );
  14383. this.shininess = source.shininess;
  14384. this.map = source.map;
  14385. this.lightMap = source.lightMap;
  14386. this.lightMapIntensity = source.lightMapIntensity;
  14387. this.aoMap = source.aoMap;
  14388. this.aoMapIntensity = source.aoMapIntensity;
  14389. this.emissive.copy( source.emissive );
  14390. this.emissiveMap = source.emissiveMap;
  14391. this.emissiveIntensity = source.emissiveIntensity;
  14392. this.bumpMap = source.bumpMap;
  14393. this.bumpScale = source.bumpScale;
  14394. this.normalMap = source.normalMap;
  14395. this.normalMapType = source.normalMapType;
  14396. this.normalScale.copy( source.normalScale );
  14397. this.displacementMap = source.displacementMap;
  14398. this.displacementScale = source.displacementScale;
  14399. this.displacementBias = source.displacementBias;
  14400. this.specularMap = source.specularMap;
  14401. this.alphaMap = source.alphaMap;
  14402. this.envMap = source.envMap;
  14403. this.envMapRotation.copy( source.envMapRotation );
  14404. this.combine = source.combine;
  14405. this.reflectivity = source.reflectivity;
  14406. this.refractionRatio = source.refractionRatio;
  14407. this.wireframe = source.wireframe;
  14408. this.wireframeLinewidth = source.wireframeLinewidth;
  14409. this.wireframeLinecap = source.wireframeLinecap;
  14410. this.wireframeLinejoin = source.wireframeLinejoin;
  14411. this.flatShading = source.flatShading;
  14412. this.fog = source.fog;
  14413. return this;
  14414. }
  14415. }
  14416. class MeshToonMaterial extends Material {
  14417. constructor( parameters ) {
  14418. super();
  14419. this.isMeshToonMaterial = true;
  14420. this.defines = { 'TOON': '' };
  14421. this.type = 'MeshToonMaterial';
  14422. this.color = new Color( 0xffffff );
  14423. this.map = null;
  14424. this.gradientMap = null;
  14425. this.lightMap = null;
  14426. this.lightMapIntensity = 1.0;
  14427. this.aoMap = null;
  14428. this.aoMapIntensity = 1.0;
  14429. this.emissive = new Color( 0x000000 );
  14430. this.emissiveIntensity = 1.0;
  14431. this.emissiveMap = null;
  14432. this.bumpMap = null;
  14433. this.bumpScale = 1;
  14434. this.normalMap = null;
  14435. this.normalMapType = TangentSpaceNormalMap;
  14436. this.normalScale = new Vector2( 1, 1 );
  14437. this.displacementMap = null;
  14438. this.displacementScale = 1;
  14439. this.displacementBias = 0;
  14440. this.alphaMap = null;
  14441. this.wireframe = false;
  14442. this.wireframeLinewidth = 1;
  14443. this.wireframeLinecap = 'round';
  14444. this.wireframeLinejoin = 'round';
  14445. this.fog = true;
  14446. this.setValues( parameters );
  14447. }
  14448. copy( source ) {
  14449. super.copy( source );
  14450. this.color.copy( source.color );
  14451. this.map = source.map;
  14452. this.gradientMap = source.gradientMap;
  14453. this.lightMap = source.lightMap;
  14454. this.lightMapIntensity = source.lightMapIntensity;
  14455. this.aoMap = source.aoMap;
  14456. this.aoMapIntensity = source.aoMapIntensity;
  14457. this.emissive.copy( source.emissive );
  14458. this.emissiveMap = source.emissiveMap;
  14459. this.emissiveIntensity = source.emissiveIntensity;
  14460. this.bumpMap = source.bumpMap;
  14461. this.bumpScale = source.bumpScale;
  14462. this.normalMap = source.normalMap;
  14463. this.normalMapType = source.normalMapType;
  14464. this.normalScale.copy( source.normalScale );
  14465. this.displacementMap = source.displacementMap;
  14466. this.displacementScale = source.displacementScale;
  14467. this.displacementBias = source.displacementBias;
  14468. this.alphaMap = source.alphaMap;
  14469. this.wireframe = source.wireframe;
  14470. this.wireframeLinewidth = source.wireframeLinewidth;
  14471. this.wireframeLinecap = source.wireframeLinecap;
  14472. this.wireframeLinejoin = source.wireframeLinejoin;
  14473. this.fog = source.fog;
  14474. return this;
  14475. }
  14476. }
  14477. class MeshNormalMaterial extends Material {
  14478. constructor( parameters ) {
  14479. super();
  14480. this.isMeshNormalMaterial = true;
  14481. this.type = 'MeshNormalMaterial';
  14482. this.bumpMap = null;
  14483. this.bumpScale = 1;
  14484. this.normalMap = null;
  14485. this.normalMapType = TangentSpaceNormalMap;
  14486. this.normalScale = new Vector2( 1, 1 );
  14487. this.displacementMap = null;
  14488. this.displacementScale = 1;
  14489. this.displacementBias = 0;
  14490. this.wireframe = false;
  14491. this.wireframeLinewidth = 1;
  14492. this.flatShading = false;
  14493. this.setValues( parameters );
  14494. }
  14495. copy( source ) {
  14496. super.copy( source );
  14497. this.bumpMap = source.bumpMap;
  14498. this.bumpScale = source.bumpScale;
  14499. this.normalMap = source.normalMap;
  14500. this.normalMapType = source.normalMapType;
  14501. this.normalScale.copy( source.normalScale );
  14502. this.displacementMap = source.displacementMap;
  14503. this.displacementScale = source.displacementScale;
  14504. this.displacementBias = source.displacementBias;
  14505. this.wireframe = source.wireframe;
  14506. this.wireframeLinewidth = source.wireframeLinewidth;
  14507. this.flatShading = source.flatShading;
  14508. return this;
  14509. }
  14510. }
  14511. class MeshLambertMaterial extends Material {
  14512. constructor( parameters ) {
  14513. super();
  14514. this.isMeshLambertMaterial = true;
  14515. this.type = 'MeshLambertMaterial';
  14516. this.color = new Color( 0xffffff ); // diffuse
  14517. this.map = null;
  14518. this.lightMap = null;
  14519. this.lightMapIntensity = 1.0;
  14520. this.aoMap = null;
  14521. this.aoMapIntensity = 1.0;
  14522. this.emissive = new Color( 0x000000 );
  14523. this.emissiveIntensity = 1.0;
  14524. this.emissiveMap = null;
  14525. this.bumpMap = null;
  14526. this.bumpScale = 1;
  14527. this.normalMap = null;
  14528. this.normalMapType = TangentSpaceNormalMap;
  14529. this.normalScale = new Vector2( 1, 1 );
  14530. this.displacementMap = null;
  14531. this.displacementScale = 1;
  14532. this.displacementBias = 0;
  14533. this.specularMap = null;
  14534. this.alphaMap = null;
  14535. this.envMap = null;
  14536. this.envMapRotation = new Euler();
  14537. this.combine = MultiplyOperation;
  14538. this.reflectivity = 1;
  14539. this.refractionRatio = 0.98;
  14540. this.wireframe = false;
  14541. this.wireframeLinewidth = 1;
  14542. this.wireframeLinecap = 'round';
  14543. this.wireframeLinejoin = 'round';
  14544. this.flatShading = false;
  14545. this.fog = true;
  14546. this.setValues( parameters );
  14547. }
  14548. copy( source ) {
  14549. super.copy( source );
  14550. this.color.copy( source.color );
  14551. this.map = source.map;
  14552. this.lightMap = source.lightMap;
  14553. this.lightMapIntensity = source.lightMapIntensity;
  14554. this.aoMap = source.aoMap;
  14555. this.aoMapIntensity = source.aoMapIntensity;
  14556. this.emissive.copy( source.emissive );
  14557. this.emissiveMap = source.emissiveMap;
  14558. this.emissiveIntensity = source.emissiveIntensity;
  14559. this.bumpMap = source.bumpMap;
  14560. this.bumpScale = source.bumpScale;
  14561. this.normalMap = source.normalMap;
  14562. this.normalMapType = source.normalMapType;
  14563. this.normalScale.copy( source.normalScale );
  14564. this.displacementMap = source.displacementMap;
  14565. this.displacementScale = source.displacementScale;
  14566. this.displacementBias = source.displacementBias;
  14567. this.specularMap = source.specularMap;
  14568. this.alphaMap = source.alphaMap;
  14569. this.envMap = source.envMap;
  14570. this.envMapRotation.copy( source.envMapRotation );
  14571. this.combine = source.combine;
  14572. this.reflectivity = source.reflectivity;
  14573. this.refractionRatio = source.refractionRatio;
  14574. this.wireframe = source.wireframe;
  14575. this.wireframeLinewidth = source.wireframeLinewidth;
  14576. this.wireframeLinecap = source.wireframeLinecap;
  14577. this.wireframeLinejoin = source.wireframeLinejoin;
  14578. this.flatShading = source.flatShading;
  14579. this.fog = source.fog;
  14580. return this;
  14581. }
  14582. }
  14583. class MeshDepthMaterial extends Material {
  14584. constructor( parameters ) {
  14585. super();
  14586. this.isMeshDepthMaterial = true;
  14587. this.type = 'MeshDepthMaterial';
  14588. this.depthPacking = BasicDepthPacking;
  14589. this.map = null;
  14590. this.alphaMap = null;
  14591. this.displacementMap = null;
  14592. this.displacementScale = 1;
  14593. this.displacementBias = 0;
  14594. this.wireframe = false;
  14595. this.wireframeLinewidth = 1;
  14596. this.setValues( parameters );
  14597. }
  14598. copy( source ) {
  14599. super.copy( source );
  14600. this.depthPacking = source.depthPacking;
  14601. this.map = source.map;
  14602. this.alphaMap = source.alphaMap;
  14603. this.displacementMap = source.displacementMap;
  14604. this.displacementScale = source.displacementScale;
  14605. this.displacementBias = source.displacementBias;
  14606. this.wireframe = source.wireframe;
  14607. this.wireframeLinewidth = source.wireframeLinewidth;
  14608. return this;
  14609. }
  14610. }
  14611. class MeshDistanceMaterial extends Material {
  14612. constructor( parameters ) {
  14613. super();
  14614. this.isMeshDistanceMaterial = true;
  14615. this.type = 'MeshDistanceMaterial';
  14616. this.map = null;
  14617. this.alphaMap = null;
  14618. this.displacementMap = null;
  14619. this.displacementScale = 1;
  14620. this.displacementBias = 0;
  14621. this.setValues( parameters );
  14622. }
  14623. copy( source ) {
  14624. super.copy( source );
  14625. this.map = source.map;
  14626. this.alphaMap = source.alphaMap;
  14627. this.displacementMap = source.displacementMap;
  14628. this.displacementScale = source.displacementScale;
  14629. this.displacementBias = source.displacementBias;
  14630. return this;
  14631. }
  14632. }
  14633. class MeshMatcapMaterial extends Material {
  14634. constructor( parameters ) {
  14635. super();
  14636. this.isMeshMatcapMaterial = true;
  14637. this.defines = { 'MATCAP': '' };
  14638. this.type = 'MeshMatcapMaterial';
  14639. this.color = new Color( 0xffffff ); // diffuse
  14640. this.matcap = null;
  14641. this.map = null;
  14642. this.bumpMap = null;
  14643. this.bumpScale = 1;
  14644. this.normalMap = null;
  14645. this.normalMapType = TangentSpaceNormalMap;
  14646. this.normalScale = new Vector2( 1, 1 );
  14647. this.displacementMap = null;
  14648. this.displacementScale = 1;
  14649. this.displacementBias = 0;
  14650. this.alphaMap = null;
  14651. this.flatShading = false;
  14652. this.fog = true;
  14653. this.setValues( parameters );
  14654. }
  14655. copy( source ) {
  14656. super.copy( source );
  14657. this.defines = { 'MATCAP': '' };
  14658. this.color.copy( source.color );
  14659. this.matcap = source.matcap;
  14660. this.map = source.map;
  14661. this.bumpMap = source.bumpMap;
  14662. this.bumpScale = source.bumpScale;
  14663. this.normalMap = source.normalMap;
  14664. this.normalMapType = source.normalMapType;
  14665. this.normalScale.copy( source.normalScale );
  14666. this.displacementMap = source.displacementMap;
  14667. this.displacementScale = source.displacementScale;
  14668. this.displacementBias = source.displacementBias;
  14669. this.alphaMap = source.alphaMap;
  14670. this.flatShading = source.flatShading;
  14671. this.fog = source.fog;
  14672. return this;
  14673. }
  14674. }
  14675. class LineDashedMaterial extends LineBasicMaterial {
  14676. constructor( parameters ) {
  14677. super();
  14678. this.isLineDashedMaterial = true;
  14679. this.type = 'LineDashedMaterial';
  14680. this.scale = 1;
  14681. this.dashSize = 3;
  14682. this.gapSize = 1;
  14683. this.setValues( parameters );
  14684. }
  14685. copy( source ) {
  14686. super.copy( source );
  14687. this.scale = source.scale;
  14688. this.dashSize = source.dashSize;
  14689. this.gapSize = source.gapSize;
  14690. return this;
  14691. }
  14692. }
  14693. // converts an array to a specific type
  14694. function convertArray( array, type, forceClone ) {
  14695. if ( ! array || // let 'undefined' and 'null' pass
  14696. ! forceClone && array.constructor === type ) return array;
  14697. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  14698. return new type( array ); // create typed array
  14699. }
  14700. return Array.prototype.slice.call( array ); // create Array
  14701. }
  14702. function isTypedArray( object ) {
  14703. return ArrayBuffer.isView( object ) &&
  14704. ! ( object instanceof DataView );
  14705. }
  14706. // returns an array by which times and values can be sorted
  14707. function getKeyframeOrder( times ) {
  14708. function compareTime( i, j ) {
  14709. return times[ i ] - times[ j ];
  14710. }
  14711. const n = times.length;
  14712. const result = new Array( n );
  14713. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  14714. result.sort( compareTime );
  14715. return result;
  14716. }
  14717. // uses the array previously returned by 'getKeyframeOrder' to sort data
  14718. function sortedArray( values, stride, order ) {
  14719. const nValues = values.length;
  14720. const result = new values.constructor( nValues );
  14721. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  14722. const srcOffset = order[ i ] * stride;
  14723. for ( let j = 0; j !== stride; ++ j ) {
  14724. result[ dstOffset ++ ] = values[ srcOffset + j ];
  14725. }
  14726. }
  14727. return result;
  14728. }
  14729. // function for parsing AOS keyframe formats
  14730. function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
  14731. let i = 1, key = jsonKeys[ 0 ];
  14732. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  14733. key = jsonKeys[ i ++ ];
  14734. }
  14735. if ( key === undefined ) return; // no data
  14736. let value = key[ valuePropertyName ];
  14737. if ( value === undefined ) return; // no data
  14738. if ( Array.isArray( value ) ) {
  14739. do {
  14740. value = key[ valuePropertyName ];
  14741. if ( value !== undefined ) {
  14742. times.push( key.time );
  14743. values.push.apply( values, value ); // push all elements
  14744. }
  14745. key = jsonKeys[ i ++ ];
  14746. } while ( key !== undefined );
  14747. } else if ( value.toArray !== undefined ) {
  14748. // ...assume THREE.Math-ish
  14749. do {
  14750. value = key[ valuePropertyName ];
  14751. if ( value !== undefined ) {
  14752. times.push( key.time );
  14753. value.toArray( values, values.length );
  14754. }
  14755. key = jsonKeys[ i ++ ];
  14756. } while ( key !== undefined );
  14757. } else {
  14758. // otherwise push as-is
  14759. do {
  14760. value = key[ valuePropertyName ];
  14761. if ( value !== undefined ) {
  14762. times.push( key.time );
  14763. values.push( value );
  14764. }
  14765. key = jsonKeys[ i ++ ];
  14766. } while ( key !== undefined );
  14767. }
  14768. }
  14769. function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  14770. const clip = sourceClip.clone();
  14771. clip.name = name;
  14772. const tracks = [];
  14773. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14774. const track = clip.tracks[ i ];
  14775. const valueSize = track.getValueSize();
  14776. const times = [];
  14777. const values = [];
  14778. for ( let j = 0; j < track.times.length; ++ j ) {
  14779. const frame = track.times[ j ] * fps;
  14780. if ( frame < startFrame || frame >= endFrame ) continue;
  14781. times.push( track.times[ j ] );
  14782. for ( let k = 0; k < valueSize; ++ k ) {
  14783. values.push( track.values[ j * valueSize + k ] );
  14784. }
  14785. }
  14786. if ( times.length === 0 ) continue;
  14787. track.times = convertArray( times, track.times.constructor );
  14788. track.values = convertArray( values, track.values.constructor );
  14789. tracks.push( track );
  14790. }
  14791. clip.tracks = tracks;
  14792. // find minimum .times value across all tracks in the trimmed clip
  14793. let minStartTime = Infinity;
  14794. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14795. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  14796. minStartTime = clip.tracks[ i ].times[ 0 ];
  14797. }
  14798. }
  14799. // shift all tracks such that clip begins at t=0
  14800. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14801. clip.tracks[ i ].shift( - 1 * minStartTime );
  14802. }
  14803. clip.resetDuration();
  14804. return clip;
  14805. }
  14806. function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  14807. if ( fps <= 0 ) fps = 30;
  14808. const numTracks = referenceClip.tracks.length;
  14809. const referenceTime = referenceFrame / fps;
  14810. // Make each track's values relative to the values at the reference frame
  14811. for ( let i = 0; i < numTracks; ++ i ) {
  14812. const referenceTrack = referenceClip.tracks[ i ];
  14813. const referenceTrackType = referenceTrack.ValueTypeName;
  14814. // Skip this track if it's non-numeric
  14815. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  14816. // Find the track in the target clip whose name and type matches the reference track
  14817. const targetTrack = targetClip.tracks.find( function ( track ) {
  14818. return track.name === referenceTrack.name
  14819. && track.ValueTypeName === referenceTrackType;
  14820. } );
  14821. if ( targetTrack === undefined ) continue;
  14822. let referenceOffset = 0;
  14823. const referenceValueSize = referenceTrack.getValueSize();
  14824. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14825. referenceOffset = referenceValueSize / 3;
  14826. }
  14827. let targetOffset = 0;
  14828. const targetValueSize = targetTrack.getValueSize();
  14829. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14830. targetOffset = targetValueSize / 3;
  14831. }
  14832. const lastIndex = referenceTrack.times.length - 1;
  14833. let referenceValue;
  14834. // Find the value to subtract out of the track
  14835. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  14836. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  14837. const startIndex = referenceOffset;
  14838. const endIndex = referenceValueSize - referenceOffset;
  14839. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14840. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  14841. // Reference frame is after the last keyframe, so just use the last keyframe
  14842. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  14843. const endIndex = startIndex + referenceValueSize - referenceOffset;
  14844. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14845. } else {
  14846. // Interpolate to the reference value
  14847. const interpolant = referenceTrack.createInterpolant();
  14848. const startIndex = referenceOffset;
  14849. const endIndex = referenceValueSize - referenceOffset;
  14850. interpolant.evaluate( referenceTime );
  14851. referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
  14852. }
  14853. // Conjugate the quaternion
  14854. if ( referenceTrackType === 'quaternion' ) {
  14855. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  14856. referenceQuat.toArray( referenceValue );
  14857. }
  14858. // Subtract the reference value from all of the track values
  14859. const numTimes = targetTrack.times.length;
  14860. for ( let j = 0; j < numTimes; ++ j ) {
  14861. const valueStart = j * targetValueSize + targetOffset;
  14862. if ( referenceTrackType === 'quaternion' ) {
  14863. // Multiply the conjugate for quaternion track types
  14864. Quaternion.multiplyQuaternionsFlat(
  14865. targetTrack.values,
  14866. valueStart,
  14867. referenceValue,
  14868. 0,
  14869. targetTrack.values,
  14870. valueStart
  14871. );
  14872. } else {
  14873. const valueEnd = targetValueSize - targetOffset * 2;
  14874. // Subtract each value for all other numeric track types
  14875. for ( let k = 0; k < valueEnd; ++ k ) {
  14876. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  14877. }
  14878. }
  14879. }
  14880. }
  14881. targetClip.blendMode = AdditiveAnimationBlendMode;
  14882. return targetClip;
  14883. }
  14884. const AnimationUtils = {
  14885. convertArray: convertArray,
  14886. isTypedArray: isTypedArray,
  14887. getKeyframeOrder: getKeyframeOrder,
  14888. sortedArray: sortedArray,
  14889. flattenJSON: flattenJSON,
  14890. subclip: subclip,
  14891. makeClipAdditive: makeClipAdditive
  14892. };
  14893. /**
  14894. * Abstract base class of interpolants over parametric samples.
  14895. *
  14896. * The parameter domain is one dimensional, typically the time or a path
  14897. * along a curve defined by the data.
  14898. *
  14899. * The sample values can have any dimensionality and derived classes may
  14900. * apply special interpretations to the data.
  14901. *
  14902. * This class provides the interval seek in a Template Method, deferring
  14903. * the actual interpolation to derived classes.
  14904. *
  14905. * Time complexity is O(1) for linear access crossing at most two points
  14906. * and O(log N) for random access, where N is the number of positions.
  14907. *
  14908. * References:
  14909. *
  14910. * http://www.oodesign.com/template-method-pattern.html
  14911. *
  14912. */
  14913. class Interpolant {
  14914. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  14915. this.parameterPositions = parameterPositions;
  14916. this._cachedIndex = 0;
  14917. this.resultBuffer = resultBuffer !== undefined ?
  14918. resultBuffer : new sampleValues.constructor( sampleSize );
  14919. this.sampleValues = sampleValues;
  14920. this.valueSize = sampleSize;
  14921. this.settings = null;
  14922. this.DefaultSettings_ = {};
  14923. }
  14924. evaluate( t ) {
  14925. const pp = this.parameterPositions;
  14926. let i1 = this._cachedIndex,
  14927. t1 = pp[ i1 ],
  14928. t0 = pp[ i1 - 1 ];
  14929. validate_interval: {
  14930. seek: {
  14931. let right;
  14932. linear_scan: {
  14933. //- See http://jsperf.com/comparison-to-undefined/3
  14934. //- slower code:
  14935. //-
  14936. //- if ( t >= t1 || t1 === undefined ) {
  14937. forward_scan: if ( ! ( t < t1 ) ) {
  14938. for ( let giveUpAt = i1 + 2; ; ) {
  14939. if ( t1 === undefined ) {
  14940. if ( t < t0 ) break forward_scan;
  14941. // after end
  14942. i1 = pp.length;
  14943. this._cachedIndex = i1;
  14944. return this.copySampleValue_( i1 - 1 );
  14945. }
  14946. if ( i1 === giveUpAt ) break; // this loop
  14947. t0 = t1;
  14948. t1 = pp[ ++ i1 ];
  14949. if ( t < t1 ) {
  14950. // we have arrived at the sought interval
  14951. break seek;
  14952. }
  14953. }
  14954. // prepare binary search on the right side of the index
  14955. right = pp.length;
  14956. break linear_scan;
  14957. }
  14958. //- slower code:
  14959. //- if ( t < t0 || t0 === undefined ) {
  14960. if ( ! ( t >= t0 ) ) {
  14961. // looping?
  14962. const t1global = pp[ 1 ];
  14963. if ( t < t1global ) {
  14964. i1 = 2; // + 1, using the scan for the details
  14965. t0 = t1global;
  14966. }
  14967. // linear reverse scan
  14968. for ( let giveUpAt = i1 - 2; ; ) {
  14969. if ( t0 === undefined ) {
  14970. // before start
  14971. this._cachedIndex = 0;
  14972. return this.copySampleValue_( 0 );
  14973. }
  14974. if ( i1 === giveUpAt ) break; // this loop
  14975. t1 = t0;
  14976. t0 = pp[ -- i1 - 1 ];
  14977. if ( t >= t0 ) {
  14978. // we have arrived at the sought interval
  14979. break seek;
  14980. }
  14981. }
  14982. // prepare binary search on the left side of the index
  14983. right = i1;
  14984. i1 = 0;
  14985. break linear_scan;
  14986. }
  14987. // the interval is valid
  14988. break validate_interval;
  14989. } // linear scan
  14990. // binary search
  14991. while ( i1 < right ) {
  14992. const mid = ( i1 + right ) >>> 1;
  14993. if ( t < pp[ mid ] ) {
  14994. right = mid;
  14995. } else {
  14996. i1 = mid + 1;
  14997. }
  14998. }
  14999. t1 = pp[ i1 ];
  15000. t0 = pp[ i1 - 1 ];
  15001. // check boundary cases, again
  15002. if ( t0 === undefined ) {
  15003. this._cachedIndex = 0;
  15004. return this.copySampleValue_( 0 );
  15005. }
  15006. if ( t1 === undefined ) {
  15007. i1 = pp.length;
  15008. this._cachedIndex = i1;
  15009. return this.copySampleValue_( i1 - 1 );
  15010. }
  15011. } // seek
  15012. this._cachedIndex = i1;
  15013. this.intervalChanged_( i1, t0, t1 );
  15014. } // validate_interval
  15015. return this.interpolate_( i1, t0, t, t1 );
  15016. }
  15017. getSettings_() {
  15018. return this.settings || this.DefaultSettings_;
  15019. }
  15020. copySampleValue_( index ) {
  15021. // copies a sample value to the result buffer
  15022. const result = this.resultBuffer,
  15023. values = this.sampleValues,
  15024. stride = this.valueSize,
  15025. offset = index * stride;
  15026. for ( let i = 0; i !== stride; ++ i ) {
  15027. result[ i ] = values[ offset + i ];
  15028. }
  15029. return result;
  15030. }
  15031. // Template methods for derived classes:
  15032. interpolate_( /* i1, t0, t, t1 */ ) {
  15033. throw new Error( 'call to abstract method' );
  15034. // implementations shall return this.resultBuffer
  15035. }
  15036. intervalChanged_( /* i1, t0, t1 */ ) {
  15037. // empty
  15038. }
  15039. }
  15040. /**
  15041. * Fast and simple cubic spline interpolant.
  15042. *
  15043. * It was derived from a Hermitian construction setting the first derivative
  15044. * at each sample position to the linear slope between neighboring positions
  15045. * over their parameter interval.
  15046. */
  15047. class CubicInterpolant extends Interpolant {
  15048. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15049. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15050. this._weightPrev = - 0;
  15051. this._offsetPrev = - 0;
  15052. this._weightNext = - 0;
  15053. this._offsetNext = - 0;
  15054. this.DefaultSettings_ = {
  15055. endingStart: ZeroCurvatureEnding,
  15056. endingEnd: ZeroCurvatureEnding
  15057. };
  15058. }
  15059. intervalChanged_( i1, t0, t1 ) {
  15060. const pp = this.parameterPositions;
  15061. let iPrev = i1 - 2,
  15062. iNext = i1 + 1,
  15063. tPrev = pp[ iPrev ],
  15064. tNext = pp[ iNext ];
  15065. if ( tPrev === undefined ) {
  15066. switch ( this.getSettings_().endingStart ) {
  15067. case ZeroSlopeEnding:
  15068. // f'(t0) = 0
  15069. iPrev = i1;
  15070. tPrev = 2 * t0 - t1;
  15071. break;
  15072. case WrapAroundEnding:
  15073. // use the other end of the curve
  15074. iPrev = pp.length - 2;
  15075. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  15076. break;
  15077. default: // ZeroCurvatureEnding
  15078. // f''(t0) = 0 a.k.a. Natural Spline
  15079. iPrev = i1;
  15080. tPrev = t1;
  15081. }
  15082. }
  15083. if ( tNext === undefined ) {
  15084. switch ( this.getSettings_().endingEnd ) {
  15085. case ZeroSlopeEnding:
  15086. // f'(tN) = 0
  15087. iNext = i1;
  15088. tNext = 2 * t1 - t0;
  15089. break;
  15090. case WrapAroundEnding:
  15091. // use the other end of the curve
  15092. iNext = 1;
  15093. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  15094. break;
  15095. default: // ZeroCurvatureEnding
  15096. // f''(tN) = 0, a.k.a. Natural Spline
  15097. iNext = i1 - 1;
  15098. tNext = t0;
  15099. }
  15100. }
  15101. const halfDt = ( t1 - t0 ) * 0.5,
  15102. stride = this.valueSize;
  15103. this._weightPrev = halfDt / ( t0 - tPrev );
  15104. this._weightNext = halfDt / ( tNext - t1 );
  15105. this._offsetPrev = iPrev * stride;
  15106. this._offsetNext = iNext * stride;
  15107. }
  15108. interpolate_( i1, t0, t, t1 ) {
  15109. const result = this.resultBuffer,
  15110. values = this.sampleValues,
  15111. stride = this.valueSize,
  15112. o1 = i1 * stride, o0 = o1 - stride,
  15113. oP = this._offsetPrev, oN = this._offsetNext,
  15114. wP = this._weightPrev, wN = this._weightNext,
  15115. p = ( t - t0 ) / ( t1 - t0 ),
  15116. pp = p * p,
  15117. ppp = pp * p;
  15118. // evaluate polynomials
  15119. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  15120. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  15121. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  15122. const sN = wN * ppp - wN * pp;
  15123. // combine data linearly
  15124. for ( let i = 0; i !== stride; ++ i ) {
  15125. result[ i ] =
  15126. sP * values[ oP + i ] +
  15127. s0 * values[ o0 + i ] +
  15128. s1 * values[ o1 + i ] +
  15129. sN * values[ oN + i ];
  15130. }
  15131. return result;
  15132. }
  15133. }
  15134. class LinearInterpolant extends Interpolant {
  15135. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15136. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15137. }
  15138. interpolate_( i1, t0, t, t1 ) {
  15139. const result = this.resultBuffer,
  15140. values = this.sampleValues,
  15141. stride = this.valueSize,
  15142. offset1 = i1 * stride,
  15143. offset0 = offset1 - stride,
  15144. weight1 = ( t - t0 ) / ( t1 - t0 ),
  15145. weight0 = 1 - weight1;
  15146. for ( let i = 0; i !== stride; ++ i ) {
  15147. result[ i ] =
  15148. values[ offset0 + i ] * weight0 +
  15149. values[ offset1 + i ] * weight1;
  15150. }
  15151. return result;
  15152. }
  15153. }
  15154. /**
  15155. *
  15156. * Interpolant that evaluates to the sample value at the position preceding
  15157. * the parameter.
  15158. */
  15159. class DiscreteInterpolant extends Interpolant {
  15160. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15161. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15162. }
  15163. interpolate_( i1 /*, t0, t, t1 */ ) {
  15164. return this.copySampleValue_( i1 - 1 );
  15165. }
  15166. }
  15167. class KeyframeTrack {
  15168. constructor( name, times, values, interpolation ) {
  15169. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  15170. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  15171. this.name = name;
  15172. this.times = convertArray( times, this.TimeBufferType );
  15173. this.values = convertArray( values, this.ValueBufferType );
  15174. this.setInterpolation( interpolation || this.DefaultInterpolation );
  15175. }
  15176. // Serialization (in static context, because of constructor invocation
  15177. // and automatic invocation of .toJSON):
  15178. static toJSON( track ) {
  15179. const trackType = track.constructor;
  15180. let json;
  15181. // derived classes can define a static toJSON method
  15182. if ( trackType.toJSON !== this.toJSON ) {
  15183. json = trackType.toJSON( track );
  15184. } else {
  15185. // by default, we assume the data can be serialized as-is
  15186. json = {
  15187. 'name': track.name,
  15188. 'times': convertArray( track.times, Array ),
  15189. 'values': convertArray( track.values, Array )
  15190. };
  15191. const interpolation = track.getInterpolation();
  15192. if ( interpolation !== track.DefaultInterpolation ) {
  15193. json.interpolation = interpolation;
  15194. }
  15195. }
  15196. json.type = track.ValueTypeName; // mandatory
  15197. return json;
  15198. }
  15199. InterpolantFactoryMethodDiscrete( result ) {
  15200. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  15201. }
  15202. InterpolantFactoryMethodLinear( result ) {
  15203. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15204. }
  15205. InterpolantFactoryMethodSmooth( result ) {
  15206. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  15207. }
  15208. setInterpolation( interpolation ) {
  15209. let factoryMethod;
  15210. switch ( interpolation ) {
  15211. case InterpolateDiscrete:
  15212. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  15213. break;
  15214. case InterpolateLinear:
  15215. factoryMethod = this.InterpolantFactoryMethodLinear;
  15216. break;
  15217. case InterpolateSmooth:
  15218. factoryMethod = this.InterpolantFactoryMethodSmooth;
  15219. break;
  15220. }
  15221. if ( factoryMethod === undefined ) {
  15222. const message = 'unsupported interpolation for ' +
  15223. this.ValueTypeName + ' keyframe track named ' + this.name;
  15224. if ( this.createInterpolant === undefined ) {
  15225. // fall back to default, unless the default itself is messed up
  15226. if ( interpolation !== this.DefaultInterpolation ) {
  15227. this.setInterpolation( this.DefaultInterpolation );
  15228. } else {
  15229. throw new Error( message ); // fatal, in this case
  15230. }
  15231. }
  15232. console.warn( 'THREE.KeyframeTrack:', message );
  15233. return this;
  15234. }
  15235. this.createInterpolant = factoryMethod;
  15236. return this;
  15237. }
  15238. getInterpolation() {
  15239. switch ( this.createInterpolant ) {
  15240. case this.InterpolantFactoryMethodDiscrete:
  15241. return InterpolateDiscrete;
  15242. case this.InterpolantFactoryMethodLinear:
  15243. return InterpolateLinear;
  15244. case this.InterpolantFactoryMethodSmooth:
  15245. return InterpolateSmooth;
  15246. }
  15247. }
  15248. getValueSize() {
  15249. return this.values.length / this.times.length;
  15250. }
  15251. // move all keyframes either forwards or backwards in time
  15252. shift( timeOffset ) {
  15253. if ( timeOffset !== 0.0 ) {
  15254. const times = this.times;
  15255. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15256. times[ i ] += timeOffset;
  15257. }
  15258. }
  15259. return this;
  15260. }
  15261. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  15262. scale( timeScale ) {
  15263. if ( timeScale !== 1.0 ) {
  15264. const times = this.times;
  15265. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15266. times[ i ] *= timeScale;
  15267. }
  15268. }
  15269. return this;
  15270. }
  15271. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  15272. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  15273. trim( startTime, endTime ) {
  15274. const times = this.times,
  15275. nKeys = times.length;
  15276. let from = 0,
  15277. to = nKeys - 1;
  15278. while ( from !== nKeys && times[ from ] < startTime ) {
  15279. ++ from;
  15280. }
  15281. while ( to !== - 1 && times[ to ] > endTime ) {
  15282. -- to;
  15283. }
  15284. ++ to; // inclusive -> exclusive bound
  15285. if ( from !== 0 || to !== nKeys ) {
  15286. // empty tracks are forbidden, so keep at least one keyframe
  15287. if ( from >= to ) {
  15288. to = Math.max( to, 1 );
  15289. from = to - 1;
  15290. }
  15291. const stride = this.getValueSize();
  15292. this.times = times.slice( from, to );
  15293. this.values = this.values.slice( from * stride, to * stride );
  15294. }
  15295. return this;
  15296. }
  15297. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  15298. validate() {
  15299. let valid = true;
  15300. const valueSize = this.getValueSize();
  15301. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  15302. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  15303. valid = false;
  15304. }
  15305. const times = this.times,
  15306. values = this.values,
  15307. nKeys = times.length;
  15308. if ( nKeys === 0 ) {
  15309. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  15310. valid = false;
  15311. }
  15312. let prevTime = null;
  15313. for ( let i = 0; i !== nKeys; i ++ ) {
  15314. const currTime = times[ i ];
  15315. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  15316. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  15317. valid = false;
  15318. break;
  15319. }
  15320. if ( prevTime !== null && prevTime > currTime ) {
  15321. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  15322. valid = false;
  15323. break;
  15324. }
  15325. prevTime = currTime;
  15326. }
  15327. if ( values !== undefined ) {
  15328. if ( isTypedArray( values ) ) {
  15329. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  15330. const value = values[ i ];
  15331. if ( isNaN( value ) ) {
  15332. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  15333. valid = false;
  15334. break;
  15335. }
  15336. }
  15337. }
  15338. }
  15339. return valid;
  15340. }
  15341. // removes equivalent sequential keys as common in morph target sequences
  15342. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  15343. optimize() {
  15344. // times or values may be shared with other tracks, so overwriting is unsafe
  15345. const times = this.times.slice(),
  15346. values = this.values.slice(),
  15347. stride = this.getValueSize(),
  15348. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  15349. lastIndex = times.length - 1;
  15350. let writeIndex = 1;
  15351. for ( let i = 1; i < lastIndex; ++ i ) {
  15352. let keep = false;
  15353. const time = times[ i ];
  15354. const timeNext = times[ i + 1 ];
  15355. // remove adjacent keyframes scheduled at the same time
  15356. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  15357. if ( ! smoothInterpolation ) {
  15358. // remove unnecessary keyframes same as their neighbors
  15359. const offset = i * stride,
  15360. offsetP = offset - stride,
  15361. offsetN = offset + stride;
  15362. for ( let j = 0; j !== stride; ++ j ) {
  15363. const value = values[ offset + j ];
  15364. if ( value !== values[ offsetP + j ] ||
  15365. value !== values[ offsetN + j ] ) {
  15366. keep = true;
  15367. break;
  15368. }
  15369. }
  15370. } else {
  15371. keep = true;
  15372. }
  15373. }
  15374. // in-place compaction
  15375. if ( keep ) {
  15376. if ( i !== writeIndex ) {
  15377. times[ writeIndex ] = times[ i ];
  15378. const readOffset = i * stride,
  15379. writeOffset = writeIndex * stride;
  15380. for ( let j = 0; j !== stride; ++ j ) {
  15381. values[ writeOffset + j ] = values[ readOffset + j ];
  15382. }
  15383. }
  15384. ++ writeIndex;
  15385. }
  15386. }
  15387. // flush last keyframe (compaction looks ahead)
  15388. if ( lastIndex > 0 ) {
  15389. times[ writeIndex ] = times[ lastIndex ];
  15390. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  15391. values[ writeOffset + j ] = values[ readOffset + j ];
  15392. }
  15393. ++ writeIndex;
  15394. }
  15395. if ( writeIndex !== times.length ) {
  15396. this.times = times.slice( 0, writeIndex );
  15397. this.values = values.slice( 0, writeIndex * stride );
  15398. } else {
  15399. this.times = times;
  15400. this.values = values;
  15401. }
  15402. return this;
  15403. }
  15404. clone() {
  15405. const times = this.times.slice();
  15406. const values = this.values.slice();
  15407. const TypedKeyframeTrack = this.constructor;
  15408. const track = new TypedKeyframeTrack( this.name, times, values );
  15409. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  15410. track.createInterpolant = this.createInterpolant;
  15411. return track;
  15412. }
  15413. }
  15414. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  15415. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  15416. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  15417. /**
  15418. * A Track of Boolean keyframe values.
  15419. */
  15420. class BooleanKeyframeTrack extends KeyframeTrack {
  15421. // No interpolation parameter because only InterpolateDiscrete is valid.
  15422. constructor( name, times, values ) {
  15423. super( name, times, values );
  15424. }
  15425. }
  15426. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  15427. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  15428. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15429. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15430. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15431. /**
  15432. * A Track of keyframe values that represent color.
  15433. */
  15434. class ColorKeyframeTrack extends KeyframeTrack {}
  15435. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  15436. /**
  15437. * A Track of numeric keyframe values.
  15438. */
  15439. class NumberKeyframeTrack extends KeyframeTrack {}
  15440. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  15441. /**
  15442. * Spherical linear unit quaternion interpolant.
  15443. */
  15444. class QuaternionLinearInterpolant extends Interpolant {
  15445. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15446. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15447. }
  15448. interpolate_( i1, t0, t, t1 ) {
  15449. const result = this.resultBuffer,
  15450. values = this.sampleValues,
  15451. stride = this.valueSize,
  15452. alpha = ( t - t0 ) / ( t1 - t0 );
  15453. let offset = i1 * stride;
  15454. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  15455. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  15456. }
  15457. return result;
  15458. }
  15459. }
  15460. /**
  15461. * A Track of quaternion keyframe values.
  15462. */
  15463. class QuaternionKeyframeTrack extends KeyframeTrack {
  15464. InterpolantFactoryMethodLinear( result ) {
  15465. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15466. }
  15467. }
  15468. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  15469. // ValueBufferType is inherited
  15470. // DefaultInterpolation is inherited;
  15471. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15472. /**
  15473. * A Track that interpolates Strings
  15474. */
  15475. class StringKeyframeTrack extends KeyframeTrack {
  15476. // No interpolation parameter because only InterpolateDiscrete is valid.
  15477. constructor( name, times, values ) {
  15478. super( name, times, values );
  15479. }
  15480. }
  15481. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  15482. StringKeyframeTrack.prototype.ValueBufferType = Array;
  15483. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15484. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15485. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15486. /**
  15487. * A Track of vectored keyframe values.
  15488. */
  15489. class VectorKeyframeTrack extends KeyframeTrack {}
  15490. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  15491. class AnimationClip {
  15492. constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) {
  15493. this.name = name;
  15494. this.tracks = tracks;
  15495. this.duration = duration;
  15496. this.blendMode = blendMode;
  15497. this.uuid = generateUUID();
  15498. // this means it should figure out its duration by scanning the tracks
  15499. if ( this.duration < 0 ) {
  15500. this.resetDuration();
  15501. }
  15502. }
  15503. static parse( json ) {
  15504. const tracks = [],
  15505. jsonTracks = json.tracks,
  15506. frameTime = 1.0 / ( json.fps || 1.0 );
  15507. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  15508. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  15509. }
  15510. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  15511. clip.uuid = json.uuid;
  15512. return clip;
  15513. }
  15514. static toJSON( clip ) {
  15515. const tracks = [],
  15516. clipTracks = clip.tracks;
  15517. const json = {
  15518. 'name': clip.name,
  15519. 'duration': clip.duration,
  15520. 'tracks': tracks,
  15521. 'uuid': clip.uuid,
  15522. 'blendMode': clip.blendMode
  15523. };
  15524. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  15525. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  15526. }
  15527. return json;
  15528. }
  15529. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  15530. const numMorphTargets = morphTargetSequence.length;
  15531. const tracks = [];
  15532. for ( let i = 0; i < numMorphTargets; i ++ ) {
  15533. let times = [];
  15534. let values = [];
  15535. times.push(
  15536. ( i + numMorphTargets - 1 ) % numMorphTargets,
  15537. i,
  15538. ( i + 1 ) % numMorphTargets );
  15539. values.push( 0, 1, 0 );
  15540. const order = getKeyframeOrder( times );
  15541. times = sortedArray( times, 1, order );
  15542. values = sortedArray( values, 1, order );
  15543. // if there is a key at the first frame, duplicate it as the
  15544. // last frame as well for perfect loop.
  15545. if ( ! noLoop && times[ 0 ] === 0 ) {
  15546. times.push( numMorphTargets );
  15547. values.push( values[ 0 ] );
  15548. }
  15549. tracks.push(
  15550. new NumberKeyframeTrack(
  15551. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  15552. times, values
  15553. ).scale( 1.0 / fps ) );
  15554. }
  15555. return new this( name, - 1, tracks );
  15556. }
  15557. static findByName( objectOrClipArray, name ) {
  15558. let clipArray = objectOrClipArray;
  15559. if ( ! Array.isArray( objectOrClipArray ) ) {
  15560. const o = objectOrClipArray;
  15561. clipArray = o.geometry && o.geometry.animations || o.animations;
  15562. }
  15563. for ( let i = 0; i < clipArray.length; i ++ ) {
  15564. if ( clipArray[ i ].name === name ) {
  15565. return clipArray[ i ];
  15566. }
  15567. }
  15568. return null;
  15569. }
  15570. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  15571. const animationToMorphTargets = {};
  15572. // tested with https://regex101.com/ on trick sequences
  15573. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  15574. const pattern = /^([\w-]*?)([\d]+)$/;
  15575. // sort morph target names into animation groups based
  15576. // patterns like Walk_001, Walk_002, Run_001, Run_002
  15577. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  15578. const morphTarget = morphTargets[ i ];
  15579. const parts = morphTarget.name.match( pattern );
  15580. if ( parts && parts.length > 1 ) {
  15581. const name = parts[ 1 ];
  15582. let animationMorphTargets = animationToMorphTargets[ name ];
  15583. if ( ! animationMorphTargets ) {
  15584. animationToMorphTargets[ name ] = animationMorphTargets = [];
  15585. }
  15586. animationMorphTargets.push( morphTarget );
  15587. }
  15588. }
  15589. const clips = [];
  15590. for ( const name in animationToMorphTargets ) {
  15591. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  15592. }
  15593. return clips;
  15594. }
  15595. // parse the animation.hierarchy format
  15596. static parseAnimation( animation, bones ) {
  15597. if ( ! animation ) {
  15598. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  15599. return null;
  15600. }
  15601. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  15602. // only return track if there are actually keys.
  15603. if ( animationKeys.length !== 0 ) {
  15604. const times = [];
  15605. const values = [];
  15606. flattenJSON( animationKeys, times, values, propertyName );
  15607. // empty keys are filtered out, so check again
  15608. if ( times.length !== 0 ) {
  15609. destTracks.push( new trackType( trackName, times, values ) );
  15610. }
  15611. }
  15612. };
  15613. const tracks = [];
  15614. const clipName = animation.name || 'default';
  15615. const fps = animation.fps || 30;
  15616. const blendMode = animation.blendMode;
  15617. // automatic length determination in AnimationClip.
  15618. let duration = animation.length || - 1;
  15619. const hierarchyTracks = animation.hierarchy || [];
  15620. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  15621. const animationKeys = hierarchyTracks[ h ].keys;
  15622. // skip empty tracks
  15623. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  15624. // process morph targets
  15625. if ( animationKeys[ 0 ].morphTargets ) {
  15626. // figure out all morph targets used in this track
  15627. const morphTargetNames = {};
  15628. let k;
  15629. for ( k = 0; k < animationKeys.length; k ++ ) {
  15630. if ( animationKeys[ k ].morphTargets ) {
  15631. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  15632. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  15633. }
  15634. }
  15635. }
  15636. // create a track for each morph target with all zero
  15637. // morphTargetInfluences except for the keys in which
  15638. // the morphTarget is named.
  15639. for ( const morphTargetName in morphTargetNames ) {
  15640. const times = [];
  15641. const values = [];
  15642. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  15643. const animationKey = animationKeys[ k ];
  15644. times.push( animationKey.time );
  15645. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  15646. }
  15647. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  15648. }
  15649. duration = morphTargetNames.length * fps;
  15650. } else {
  15651. // ...assume skeletal animation
  15652. const boneName = '.bones[' + bones[ h ].name + ']';
  15653. addNonemptyTrack(
  15654. VectorKeyframeTrack, boneName + '.position',
  15655. animationKeys, 'pos', tracks );
  15656. addNonemptyTrack(
  15657. QuaternionKeyframeTrack, boneName + '.quaternion',
  15658. animationKeys, 'rot', tracks );
  15659. addNonemptyTrack(
  15660. VectorKeyframeTrack, boneName + '.scale',
  15661. animationKeys, 'scl', tracks );
  15662. }
  15663. }
  15664. if ( tracks.length === 0 ) {
  15665. return null;
  15666. }
  15667. const clip = new this( clipName, duration, tracks, blendMode );
  15668. return clip;
  15669. }
  15670. resetDuration() {
  15671. const tracks = this.tracks;
  15672. let duration = 0;
  15673. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  15674. const track = this.tracks[ i ];
  15675. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  15676. }
  15677. this.duration = duration;
  15678. return this;
  15679. }
  15680. trim() {
  15681. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15682. this.tracks[ i ].trim( 0, this.duration );
  15683. }
  15684. return this;
  15685. }
  15686. validate() {
  15687. let valid = true;
  15688. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15689. valid = valid && this.tracks[ i ].validate();
  15690. }
  15691. return valid;
  15692. }
  15693. optimize() {
  15694. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15695. this.tracks[ i ].optimize();
  15696. }
  15697. return this;
  15698. }
  15699. clone() {
  15700. const tracks = [];
  15701. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15702. tracks.push( this.tracks[ i ].clone() );
  15703. }
  15704. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  15705. }
  15706. toJSON() {
  15707. return this.constructor.toJSON( this );
  15708. }
  15709. }
  15710. function getTrackTypeForValueTypeName( typeName ) {
  15711. switch ( typeName.toLowerCase() ) {
  15712. case 'scalar':
  15713. case 'double':
  15714. case 'float':
  15715. case 'number':
  15716. case 'integer':
  15717. return NumberKeyframeTrack;
  15718. case 'vector':
  15719. case 'vector2':
  15720. case 'vector3':
  15721. case 'vector4':
  15722. return VectorKeyframeTrack;
  15723. case 'color':
  15724. return ColorKeyframeTrack;
  15725. case 'quaternion':
  15726. return QuaternionKeyframeTrack;
  15727. case 'bool':
  15728. case 'boolean':
  15729. return BooleanKeyframeTrack;
  15730. case 'string':
  15731. return StringKeyframeTrack;
  15732. }
  15733. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  15734. }
  15735. function parseKeyframeTrack( json ) {
  15736. if ( json.type === undefined ) {
  15737. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  15738. }
  15739. const trackType = getTrackTypeForValueTypeName( json.type );
  15740. if ( json.times === undefined ) {
  15741. const times = [], values = [];
  15742. flattenJSON( json.keys, times, values, 'value' );
  15743. json.times = times;
  15744. json.values = values;
  15745. }
  15746. // derived classes can define a static parse method
  15747. if ( trackType.parse !== undefined ) {
  15748. return trackType.parse( json );
  15749. } else {
  15750. // by default, we assume a constructor compatible with the base
  15751. return new trackType( json.name, json.times, json.values, json.interpolation );
  15752. }
  15753. }
  15754. const Cache = {
  15755. enabled: false,
  15756. files: {},
  15757. add: function ( key, file ) {
  15758. if ( this.enabled === false ) return;
  15759. // console.log( 'THREE.Cache', 'Adding key:', key );
  15760. this.files[ key ] = file;
  15761. },
  15762. get: function ( key ) {
  15763. if ( this.enabled === false ) return;
  15764. // console.log( 'THREE.Cache', 'Checking key:', key );
  15765. return this.files[ key ];
  15766. },
  15767. remove: function ( key ) {
  15768. delete this.files[ key ];
  15769. },
  15770. clear: function () {
  15771. this.files = {};
  15772. }
  15773. };
  15774. class LoadingManager {
  15775. constructor( onLoad, onProgress, onError ) {
  15776. const scope = this;
  15777. let isLoading = false;
  15778. let itemsLoaded = 0;
  15779. let itemsTotal = 0;
  15780. let urlModifier = undefined;
  15781. const handlers = [];
  15782. // Refer to #5689 for the reason why we don't set .onStart
  15783. // in the constructor
  15784. this.onStart = undefined;
  15785. this.onLoad = onLoad;
  15786. this.onProgress = onProgress;
  15787. this.onError = onError;
  15788. this.itemStart = function ( url ) {
  15789. itemsTotal ++;
  15790. if ( isLoading === false ) {
  15791. if ( scope.onStart !== undefined ) {
  15792. scope.onStart( url, itemsLoaded, itemsTotal );
  15793. }
  15794. }
  15795. isLoading = true;
  15796. };
  15797. this.itemEnd = function ( url ) {
  15798. itemsLoaded ++;
  15799. if ( scope.onProgress !== undefined ) {
  15800. scope.onProgress( url, itemsLoaded, itemsTotal );
  15801. }
  15802. if ( itemsLoaded === itemsTotal ) {
  15803. isLoading = false;
  15804. if ( scope.onLoad !== undefined ) {
  15805. scope.onLoad();
  15806. }
  15807. }
  15808. };
  15809. this.itemError = function ( url ) {
  15810. if ( scope.onError !== undefined ) {
  15811. scope.onError( url );
  15812. }
  15813. };
  15814. this.resolveURL = function ( url ) {
  15815. if ( urlModifier ) {
  15816. return urlModifier( url );
  15817. }
  15818. return url;
  15819. };
  15820. this.setURLModifier = function ( transform ) {
  15821. urlModifier = transform;
  15822. return this;
  15823. };
  15824. this.addHandler = function ( regex, loader ) {
  15825. handlers.push( regex, loader );
  15826. return this;
  15827. };
  15828. this.removeHandler = function ( regex ) {
  15829. const index = handlers.indexOf( regex );
  15830. if ( index !== - 1 ) {
  15831. handlers.splice( index, 2 );
  15832. }
  15833. return this;
  15834. };
  15835. this.getHandler = function ( file ) {
  15836. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  15837. const regex = handlers[ i ];
  15838. const loader = handlers[ i + 1 ];
  15839. if ( regex.global ) regex.lastIndex = 0; // see #17920
  15840. if ( regex.test( file ) ) {
  15841. return loader;
  15842. }
  15843. }
  15844. return null;
  15845. };
  15846. }
  15847. }
  15848. const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager();
  15849. class Loader {
  15850. constructor( manager ) {
  15851. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  15852. this.crossOrigin = 'anonymous';
  15853. this.withCredentials = false;
  15854. this.path = '';
  15855. this.resourcePath = '';
  15856. this.requestHeader = {};
  15857. }
  15858. load( /* url, onLoad, onProgress, onError */ ) {}
  15859. loadAsync( url, onProgress ) {
  15860. const scope = this;
  15861. return new Promise( function ( resolve, reject ) {
  15862. scope.load( url, resolve, onProgress, reject );
  15863. } );
  15864. }
  15865. parse( /* data */ ) {}
  15866. setCrossOrigin( crossOrigin ) {
  15867. this.crossOrigin = crossOrigin;
  15868. return this;
  15869. }
  15870. setWithCredentials( value ) {
  15871. this.withCredentials = value;
  15872. return this;
  15873. }
  15874. setPath( path ) {
  15875. this.path = path;
  15876. return this;
  15877. }
  15878. setResourcePath( resourcePath ) {
  15879. this.resourcePath = resourcePath;
  15880. return this;
  15881. }
  15882. setRequestHeader( requestHeader ) {
  15883. this.requestHeader = requestHeader;
  15884. return this;
  15885. }
  15886. }
  15887. Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT';
  15888. const loading = {};
  15889. class HttpError extends Error {
  15890. constructor( message, response ) {
  15891. super( message );
  15892. this.response = response;
  15893. }
  15894. }
  15895. class FileLoader extends Loader {
  15896. constructor( manager ) {
  15897. super( manager );
  15898. }
  15899. load( url, onLoad, onProgress, onError ) {
  15900. if ( url === undefined ) url = '';
  15901. if ( this.path !== undefined ) url = this.path + url;
  15902. url = this.manager.resolveURL( url );
  15903. const cached = Cache.get( url );
  15904. if ( cached !== undefined ) {
  15905. this.manager.itemStart( url );
  15906. setTimeout( () => {
  15907. if ( onLoad ) onLoad( cached );
  15908. this.manager.itemEnd( url );
  15909. }, 0 );
  15910. return cached;
  15911. }
  15912. // Check if request is duplicate
  15913. if ( loading[ url ] !== undefined ) {
  15914. loading[ url ].push( {
  15915. onLoad: onLoad,
  15916. onProgress: onProgress,
  15917. onError: onError
  15918. } );
  15919. return;
  15920. }
  15921. // Initialise array for duplicate requests
  15922. loading[ url ] = [];
  15923. loading[ url ].push( {
  15924. onLoad: onLoad,
  15925. onProgress: onProgress,
  15926. onError: onError,
  15927. } );
  15928. // create request
  15929. const req = new Request( url, {
  15930. headers: new Headers( this.requestHeader ),
  15931. credentials: this.withCredentials ? 'include' : 'same-origin',
  15932. // An abort controller could be added within a future PR
  15933. } );
  15934. // record states ( avoid data race )
  15935. const mimeType = this.mimeType;
  15936. const responseType = this.responseType;
  15937. // start the fetch
  15938. fetch( req )
  15939. .then( response => {
  15940. if ( response.status === 200 || response.status === 0 ) {
  15941. // Some browsers return HTTP Status 0 when using non-http protocol
  15942. // e.g. 'file://' or 'data://'. Handle as success.
  15943. if ( response.status === 0 ) {
  15944. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  15945. }
  15946. // Workaround: Checking if response.body === undefined for Alipay browser #23548
  15947. if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) {
  15948. return response;
  15949. }
  15950. const callbacks = loading[ url ];
  15951. const reader = response.body.getReader();
  15952. // Nginx needs X-File-Size check
  15953. // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
  15954. const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' );
  15955. const total = contentLength ? parseInt( contentLength ) : 0;
  15956. const lengthComputable = total !== 0;
  15957. let loaded = 0;
  15958. // periodically read data into the new stream tracking while download progress
  15959. const stream = new ReadableStream( {
  15960. start( controller ) {
  15961. readData();
  15962. function readData() {
  15963. reader.read().then( ( { done, value } ) => {
  15964. if ( done ) {
  15965. controller.close();
  15966. } else {
  15967. loaded += value.byteLength;
  15968. const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
  15969. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15970. const callback = callbacks[ i ];
  15971. if ( callback.onProgress ) callback.onProgress( event );
  15972. }
  15973. controller.enqueue( value );
  15974. readData();
  15975. }
  15976. }, ( e ) => {
  15977. controller.error( e );
  15978. } );
  15979. }
  15980. }
  15981. } );
  15982. return new Response( stream );
  15983. } else {
  15984. throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response );
  15985. }
  15986. } )
  15987. .then( response => {
  15988. switch ( responseType ) {
  15989. case 'arraybuffer':
  15990. return response.arrayBuffer();
  15991. case 'blob':
  15992. return response.blob();
  15993. case 'document':
  15994. return response.text()
  15995. .then( text => {
  15996. const parser = new DOMParser();
  15997. return parser.parseFromString( text, mimeType );
  15998. } );
  15999. case 'json':
  16000. return response.json();
  16001. default:
  16002. if ( mimeType === undefined ) {
  16003. return response.text();
  16004. } else {
  16005. // sniff encoding
  16006. const re = /charset="?([^;"\s]*)"?/i;
  16007. const exec = re.exec( mimeType );
  16008. const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined;
  16009. const decoder = new TextDecoder( label );
  16010. return response.arrayBuffer().then( ab => decoder.decode( ab ) );
  16011. }
  16012. }
  16013. } )
  16014. .then( data => {
  16015. // Add to cache only on HTTP success, so that we do not cache
  16016. // error response bodies as proper responses to requests.
  16017. Cache.add( url, data );
  16018. const callbacks = loading[ url ];
  16019. delete loading[ url ];
  16020. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16021. const callback = callbacks[ i ];
  16022. if ( callback.onLoad ) callback.onLoad( data );
  16023. }
  16024. } )
  16025. .catch( err => {
  16026. // Abort errors and other errors are handled the same
  16027. const callbacks = loading[ url ];
  16028. if ( callbacks === undefined ) {
  16029. // When onLoad was called and url was deleted in `loading`
  16030. this.manager.itemError( url );
  16031. throw err;
  16032. }
  16033. delete loading[ url ];
  16034. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16035. const callback = callbacks[ i ];
  16036. if ( callback.onError ) callback.onError( err );
  16037. }
  16038. this.manager.itemError( url );
  16039. } )
  16040. .finally( () => {
  16041. this.manager.itemEnd( url );
  16042. } );
  16043. this.manager.itemStart( url );
  16044. }
  16045. setResponseType( value ) {
  16046. this.responseType = value;
  16047. return this;
  16048. }
  16049. setMimeType( value ) {
  16050. this.mimeType = value;
  16051. return this;
  16052. }
  16053. }
  16054. class AnimationLoader extends Loader {
  16055. constructor( manager ) {
  16056. super( manager );
  16057. }
  16058. load( url, onLoad, onProgress, onError ) {
  16059. const scope = this;
  16060. const loader = new FileLoader( this.manager );
  16061. loader.setPath( this.path );
  16062. loader.setRequestHeader( this.requestHeader );
  16063. loader.setWithCredentials( this.withCredentials );
  16064. loader.load( url, function ( text ) {
  16065. try {
  16066. onLoad( scope.parse( JSON.parse( text ) ) );
  16067. } catch ( e ) {
  16068. if ( onError ) {
  16069. onError( e );
  16070. } else {
  16071. console.error( e );
  16072. }
  16073. scope.manager.itemError( url );
  16074. }
  16075. }, onProgress, onError );
  16076. }
  16077. parse( json ) {
  16078. const animations = [];
  16079. for ( let i = 0; i < json.length; i ++ ) {
  16080. const clip = AnimationClip.parse( json[ i ] );
  16081. animations.push( clip );
  16082. }
  16083. return animations;
  16084. }
  16085. }
  16086. /**
  16087. * Abstract Base class to block based textures loader (dds, pvr, ...)
  16088. *
  16089. * Sub classes have to implement the parse() method which will be used in load().
  16090. */
  16091. class CompressedTextureLoader extends Loader {
  16092. constructor( manager ) {
  16093. super( manager );
  16094. }
  16095. load( url, onLoad, onProgress, onError ) {
  16096. const scope = this;
  16097. const images = [];
  16098. const texture = new CompressedTexture();
  16099. const loader = new FileLoader( this.manager );
  16100. loader.setPath( this.path );
  16101. loader.setResponseType( 'arraybuffer' );
  16102. loader.setRequestHeader( this.requestHeader );
  16103. loader.setWithCredentials( scope.withCredentials );
  16104. let loaded = 0;
  16105. function loadTexture( i ) {
  16106. loader.load( url[ i ], function ( buffer ) {
  16107. const texDatas = scope.parse( buffer, true );
  16108. images[ i ] = {
  16109. width: texDatas.width,
  16110. height: texDatas.height,
  16111. format: texDatas.format,
  16112. mipmaps: texDatas.mipmaps
  16113. };
  16114. loaded += 1;
  16115. if ( loaded === 6 ) {
  16116. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  16117. texture.image = images;
  16118. texture.format = texDatas.format;
  16119. texture.needsUpdate = true;
  16120. if ( onLoad ) onLoad( texture );
  16121. }
  16122. }, onProgress, onError );
  16123. }
  16124. if ( Array.isArray( url ) ) {
  16125. for ( let i = 0, il = url.length; i < il; ++ i ) {
  16126. loadTexture( i );
  16127. }
  16128. } else {
  16129. // compressed cubemap texture stored in a single DDS file
  16130. loader.load( url, function ( buffer ) {
  16131. const texDatas = scope.parse( buffer, true );
  16132. if ( texDatas.isCubemap ) {
  16133. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  16134. for ( let f = 0; f < faces; f ++ ) {
  16135. images[ f ] = { mipmaps: [] };
  16136. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  16137. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  16138. images[ f ].format = texDatas.format;
  16139. images[ f ].width = texDatas.width;
  16140. images[ f ].height = texDatas.height;
  16141. }
  16142. }
  16143. texture.image = images;
  16144. } else {
  16145. texture.image.width = texDatas.width;
  16146. texture.image.height = texDatas.height;
  16147. texture.mipmaps = texDatas.mipmaps;
  16148. }
  16149. if ( texDatas.mipmapCount === 1 ) {
  16150. texture.minFilter = LinearFilter;
  16151. }
  16152. texture.format = texDatas.format;
  16153. texture.needsUpdate = true;
  16154. if ( onLoad ) onLoad( texture );
  16155. }, onProgress, onError );
  16156. }
  16157. return texture;
  16158. }
  16159. }
  16160. class ImageLoader extends Loader {
  16161. constructor( manager ) {
  16162. super( manager );
  16163. }
  16164. load( url, onLoad, onProgress, onError ) {
  16165. if ( this.path !== undefined ) url = this.path + url;
  16166. url = this.manager.resolveURL( url );
  16167. const scope = this;
  16168. const cached = Cache.get( url );
  16169. if ( cached !== undefined ) {
  16170. scope.manager.itemStart( url );
  16171. setTimeout( function () {
  16172. if ( onLoad ) onLoad( cached );
  16173. scope.manager.itemEnd( url );
  16174. }, 0 );
  16175. return cached;
  16176. }
  16177. const image = createElementNS( 'img' );
  16178. function onImageLoad() {
  16179. removeEventListeners();
  16180. Cache.add( url, this );
  16181. if ( onLoad ) onLoad( this );
  16182. scope.manager.itemEnd( url );
  16183. }
  16184. function onImageError( event ) {
  16185. removeEventListeners();
  16186. if ( onError ) onError( event );
  16187. scope.manager.itemError( url );
  16188. scope.manager.itemEnd( url );
  16189. }
  16190. function removeEventListeners() {
  16191. image.removeEventListener( 'load', onImageLoad, false );
  16192. image.removeEventListener( 'error', onImageError, false );
  16193. }
  16194. image.addEventListener( 'load', onImageLoad, false );
  16195. image.addEventListener( 'error', onImageError, false );
  16196. if ( url.slice( 0, 5 ) !== 'data:' ) {
  16197. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  16198. }
  16199. scope.manager.itemStart( url );
  16200. image.src = url;
  16201. return image;
  16202. }
  16203. }
  16204. class CubeTextureLoader extends Loader {
  16205. constructor( manager ) {
  16206. super( manager );
  16207. }
  16208. load( urls, onLoad, onProgress, onError ) {
  16209. const texture = new CubeTexture();
  16210. texture.colorSpace = SRGBColorSpace;
  16211. const loader = new ImageLoader( this.manager );
  16212. loader.setCrossOrigin( this.crossOrigin );
  16213. loader.setPath( this.path );
  16214. let loaded = 0;
  16215. function loadTexture( i ) {
  16216. loader.load( urls[ i ], function ( image ) {
  16217. texture.images[ i ] = image;
  16218. loaded ++;
  16219. if ( loaded === 6 ) {
  16220. texture.needsUpdate = true;
  16221. if ( onLoad ) onLoad( texture );
  16222. }
  16223. }, undefined, onError );
  16224. }
  16225. for ( let i = 0; i < urls.length; ++ i ) {
  16226. loadTexture( i );
  16227. }
  16228. return texture;
  16229. }
  16230. }
  16231. /**
  16232. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  16233. *
  16234. * Sub classes have to implement the parse() method which will be used in load().
  16235. */
  16236. class DataTextureLoader extends Loader {
  16237. constructor( manager ) {
  16238. super( manager );
  16239. }
  16240. load( url, onLoad, onProgress, onError ) {
  16241. const scope = this;
  16242. const texture = new DataTexture();
  16243. const loader = new FileLoader( this.manager );
  16244. loader.setResponseType( 'arraybuffer' );
  16245. loader.setRequestHeader( this.requestHeader );
  16246. loader.setPath( this.path );
  16247. loader.setWithCredentials( scope.withCredentials );
  16248. loader.load( url, function ( buffer ) {
  16249. let texData;
  16250. try {
  16251. texData = scope.parse( buffer );
  16252. } catch ( error ) {
  16253. if ( onError !== undefined ) {
  16254. onError( error );
  16255. } else {
  16256. console.error( error );
  16257. return;
  16258. }
  16259. }
  16260. if ( texData.image !== undefined ) {
  16261. texture.image = texData.image;
  16262. } else if ( texData.data !== undefined ) {
  16263. texture.image.width = texData.width;
  16264. texture.image.height = texData.height;
  16265. texture.image.data = texData.data;
  16266. }
  16267. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  16268. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  16269. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  16270. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  16271. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  16272. if ( texData.colorSpace !== undefined ) {
  16273. texture.colorSpace = texData.colorSpace;
  16274. }
  16275. if ( texData.flipY !== undefined ) {
  16276. texture.flipY = texData.flipY;
  16277. }
  16278. if ( texData.format !== undefined ) {
  16279. texture.format = texData.format;
  16280. }
  16281. if ( texData.type !== undefined ) {
  16282. texture.type = texData.type;
  16283. }
  16284. if ( texData.mipmaps !== undefined ) {
  16285. texture.mipmaps = texData.mipmaps;
  16286. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  16287. }
  16288. if ( texData.mipmapCount === 1 ) {
  16289. texture.minFilter = LinearFilter;
  16290. }
  16291. if ( texData.generateMipmaps !== undefined ) {
  16292. texture.generateMipmaps = texData.generateMipmaps;
  16293. }
  16294. texture.needsUpdate = true;
  16295. if ( onLoad ) onLoad( texture, texData );
  16296. }, onProgress, onError );
  16297. return texture;
  16298. }
  16299. }
  16300. class TextureLoader extends Loader {
  16301. constructor( manager ) {
  16302. super( manager );
  16303. }
  16304. load( url, onLoad, onProgress, onError ) {
  16305. const texture = new Texture();
  16306. const loader = new ImageLoader( this.manager );
  16307. loader.setCrossOrigin( this.crossOrigin );
  16308. loader.setPath( this.path );
  16309. loader.load( url, function ( image ) {
  16310. texture.image = image;
  16311. texture.needsUpdate = true;
  16312. if ( onLoad !== undefined ) {
  16313. onLoad( texture );
  16314. }
  16315. }, onProgress, onError );
  16316. return texture;
  16317. }
  16318. }
  16319. class Light extends Object3D {
  16320. constructor( color, intensity = 1 ) {
  16321. super();
  16322. this.isLight = true;
  16323. this.type = 'Light';
  16324. this.color = new Color( color );
  16325. this.intensity = intensity;
  16326. }
  16327. dispose() {
  16328. // Empty here in base class; some subclasses override.
  16329. }
  16330. copy( source, recursive ) {
  16331. super.copy( source, recursive );
  16332. this.color.copy( source.color );
  16333. this.intensity = source.intensity;
  16334. return this;
  16335. }
  16336. toJSON( meta ) {
  16337. const data = super.toJSON( meta );
  16338. data.object.color = this.color.getHex();
  16339. data.object.intensity = this.intensity;
  16340. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  16341. if ( this.distance !== undefined ) data.object.distance = this.distance;
  16342. if ( this.angle !== undefined ) data.object.angle = this.angle;
  16343. if ( this.decay !== undefined ) data.object.decay = this.decay;
  16344. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  16345. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  16346. if ( this.target !== undefined ) data.object.target = this.target.uuid;
  16347. return data;
  16348. }
  16349. }
  16350. class HemisphereLight extends Light {
  16351. constructor( skyColor, groundColor, intensity ) {
  16352. super( skyColor, intensity );
  16353. this.isHemisphereLight = true;
  16354. this.type = 'HemisphereLight';
  16355. this.position.copy( Object3D.DEFAULT_UP );
  16356. this.updateMatrix();
  16357. this.groundColor = new Color( groundColor );
  16358. }
  16359. copy( source, recursive ) {
  16360. super.copy( source, recursive );
  16361. this.groundColor.copy( source.groundColor );
  16362. return this;
  16363. }
  16364. }
  16365. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  16366. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  16367. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  16368. class LightShadow {
  16369. constructor( camera ) {
  16370. this.camera = camera;
  16371. this.intensity = 1;
  16372. this.bias = 0;
  16373. this.normalBias = 0;
  16374. this.radius = 1;
  16375. this.blurSamples = 8;
  16376. this.mapSize = new Vector2( 512, 512 );
  16377. this.map = null;
  16378. this.mapPass = null;
  16379. this.matrix = new Matrix4();
  16380. this.autoUpdate = true;
  16381. this.needsUpdate = false;
  16382. this._frustum = new Frustum();
  16383. this._frameExtents = new Vector2( 1, 1 );
  16384. this._viewportCount = 1;
  16385. this._viewports = [
  16386. new Vector4( 0, 0, 1, 1 )
  16387. ];
  16388. }
  16389. getViewportCount() {
  16390. return this._viewportCount;
  16391. }
  16392. getFrustum() {
  16393. return this._frustum;
  16394. }
  16395. updateMatrices( light ) {
  16396. const shadowCamera = this.camera;
  16397. const shadowMatrix = this.matrix;
  16398. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  16399. shadowCamera.position.copy( _lightPositionWorld$1 );
  16400. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  16401. shadowCamera.lookAt( _lookTarget$1 );
  16402. shadowCamera.updateMatrixWorld();
  16403. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  16404. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  16405. shadowMatrix.set(
  16406. 0.5, 0.0, 0.0, 0.5,
  16407. 0.0, 0.5, 0.0, 0.5,
  16408. 0.0, 0.0, 0.5, 0.5,
  16409. 0.0, 0.0, 0.0, 1.0
  16410. );
  16411. shadowMatrix.multiply( _projScreenMatrix$1 );
  16412. }
  16413. getViewport( viewportIndex ) {
  16414. return this._viewports[ viewportIndex ];
  16415. }
  16416. getFrameExtents() {
  16417. return this._frameExtents;
  16418. }
  16419. dispose() {
  16420. if ( this.map ) {
  16421. this.map.dispose();
  16422. }
  16423. if ( this.mapPass ) {
  16424. this.mapPass.dispose();
  16425. }
  16426. }
  16427. copy( source ) {
  16428. this.camera = source.camera.clone();
  16429. this.intensity = source.intensity;
  16430. this.bias = source.bias;
  16431. this.radius = source.radius;
  16432. this.mapSize.copy( source.mapSize );
  16433. return this;
  16434. }
  16435. clone() {
  16436. return new this.constructor().copy( this );
  16437. }
  16438. toJSON() {
  16439. const object = {};
  16440. if ( this.intensity !== 1 ) object.intensity = this.intensity;
  16441. if ( this.bias !== 0 ) object.bias = this.bias;
  16442. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  16443. if ( this.radius !== 1 ) object.radius = this.radius;
  16444. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  16445. object.camera = this.camera.toJSON( false ).object;
  16446. delete object.camera.matrix;
  16447. return object;
  16448. }
  16449. }
  16450. class SpotLightShadow extends LightShadow {
  16451. constructor() {
  16452. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  16453. this.isSpotLightShadow = true;
  16454. this.focus = 1;
  16455. }
  16456. updateMatrices( light ) {
  16457. const camera = this.camera;
  16458. const fov = RAD2DEG * 2 * light.angle * this.focus;
  16459. const aspect = this.mapSize.width / this.mapSize.height;
  16460. const far = light.distance || camera.far;
  16461. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  16462. camera.fov = fov;
  16463. camera.aspect = aspect;
  16464. camera.far = far;
  16465. camera.updateProjectionMatrix();
  16466. }
  16467. super.updateMatrices( light );
  16468. }
  16469. copy( source ) {
  16470. super.copy( source );
  16471. this.focus = source.focus;
  16472. return this;
  16473. }
  16474. }
  16475. class SpotLight extends Light {
  16476. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
  16477. super( color, intensity );
  16478. this.isSpotLight = true;
  16479. this.type = 'SpotLight';
  16480. this.position.copy( Object3D.DEFAULT_UP );
  16481. this.updateMatrix();
  16482. this.target = new Object3D();
  16483. this.distance = distance;
  16484. this.angle = angle;
  16485. this.penumbra = penumbra;
  16486. this.decay = decay;
  16487. this.map = null;
  16488. this.shadow = new SpotLightShadow();
  16489. }
  16490. get power() {
  16491. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16492. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  16493. return this.intensity * Math.PI;
  16494. }
  16495. set power( power ) {
  16496. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16497. this.intensity = power / Math.PI;
  16498. }
  16499. dispose() {
  16500. this.shadow.dispose();
  16501. }
  16502. copy( source, recursive ) {
  16503. super.copy( source, recursive );
  16504. this.distance = source.distance;
  16505. this.angle = source.angle;
  16506. this.penumbra = source.penumbra;
  16507. this.decay = source.decay;
  16508. this.target = source.target.clone();
  16509. this.shadow = source.shadow.clone();
  16510. return this;
  16511. }
  16512. }
  16513. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  16514. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  16515. const _lookTarget = /*@__PURE__*/ new Vector3();
  16516. class PointLightShadow extends LightShadow {
  16517. constructor() {
  16518. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  16519. this.isPointLightShadow = true;
  16520. this._frameExtents = new Vector2( 4, 2 );
  16521. this._viewportCount = 6;
  16522. this._viewports = [
  16523. // These viewports map a cube-map onto a 2D texture with the
  16524. // following orientation:
  16525. //
  16526. // xzXZ
  16527. // y Y
  16528. //
  16529. // X - Positive x direction
  16530. // x - Negative x direction
  16531. // Y - Positive y direction
  16532. // y - Negative y direction
  16533. // Z - Positive z direction
  16534. // z - Negative z direction
  16535. // positive X
  16536. new Vector4( 2, 1, 1, 1 ),
  16537. // negative X
  16538. new Vector4( 0, 1, 1, 1 ),
  16539. // positive Z
  16540. new Vector4( 3, 1, 1, 1 ),
  16541. // negative Z
  16542. new Vector4( 1, 1, 1, 1 ),
  16543. // positive Y
  16544. new Vector4( 3, 0, 1, 1 ),
  16545. // negative Y
  16546. new Vector4( 1, 0, 1, 1 )
  16547. ];
  16548. this._cubeDirections = [
  16549. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  16550. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  16551. ];
  16552. this._cubeUps = [
  16553. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  16554. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  16555. ];
  16556. }
  16557. updateMatrices( light, viewportIndex = 0 ) {
  16558. const camera = this.camera;
  16559. const shadowMatrix = this.matrix;
  16560. const far = light.distance || camera.far;
  16561. if ( far !== camera.far ) {
  16562. camera.far = far;
  16563. camera.updateProjectionMatrix();
  16564. }
  16565. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  16566. camera.position.copy( _lightPositionWorld );
  16567. _lookTarget.copy( camera.position );
  16568. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  16569. camera.up.copy( this._cubeUps[ viewportIndex ] );
  16570. camera.lookAt( _lookTarget );
  16571. camera.updateMatrixWorld();
  16572. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  16573. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  16574. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  16575. }
  16576. }
  16577. class PointLight extends Light {
  16578. constructor( color, intensity, distance = 0, decay = 2 ) {
  16579. super( color, intensity );
  16580. this.isPointLight = true;
  16581. this.type = 'PointLight';
  16582. this.distance = distance;
  16583. this.decay = decay;
  16584. this.shadow = new PointLightShadow();
  16585. }
  16586. get power() {
  16587. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16588. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  16589. return this.intensity * 4 * Math.PI;
  16590. }
  16591. set power( power ) {
  16592. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16593. this.intensity = power / ( 4 * Math.PI );
  16594. }
  16595. dispose() {
  16596. this.shadow.dispose();
  16597. }
  16598. copy( source, recursive ) {
  16599. super.copy( source, recursive );
  16600. this.distance = source.distance;
  16601. this.decay = source.decay;
  16602. this.shadow = source.shadow.clone();
  16603. return this;
  16604. }
  16605. }
  16606. class OrthographicCamera extends Camera {
  16607. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  16608. super();
  16609. this.isOrthographicCamera = true;
  16610. this.type = 'OrthographicCamera';
  16611. this.zoom = 1;
  16612. this.view = null;
  16613. this.left = left;
  16614. this.right = right;
  16615. this.top = top;
  16616. this.bottom = bottom;
  16617. this.near = near;
  16618. this.far = far;
  16619. this.updateProjectionMatrix();
  16620. }
  16621. copy( source, recursive ) {
  16622. super.copy( source, recursive );
  16623. this.left = source.left;
  16624. this.right = source.right;
  16625. this.top = source.top;
  16626. this.bottom = source.bottom;
  16627. this.near = source.near;
  16628. this.far = source.far;
  16629. this.zoom = source.zoom;
  16630. this.view = source.view === null ? null : Object.assign( {}, source.view );
  16631. return this;
  16632. }
  16633. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  16634. if ( this.view === null ) {
  16635. this.view = {
  16636. enabled: true,
  16637. fullWidth: 1,
  16638. fullHeight: 1,
  16639. offsetX: 0,
  16640. offsetY: 0,
  16641. width: 1,
  16642. height: 1
  16643. };
  16644. }
  16645. this.view.enabled = true;
  16646. this.view.fullWidth = fullWidth;
  16647. this.view.fullHeight = fullHeight;
  16648. this.view.offsetX = x;
  16649. this.view.offsetY = y;
  16650. this.view.width = width;
  16651. this.view.height = height;
  16652. this.updateProjectionMatrix();
  16653. }
  16654. clearViewOffset() {
  16655. if ( this.view !== null ) {
  16656. this.view.enabled = false;
  16657. }
  16658. this.updateProjectionMatrix();
  16659. }
  16660. updateProjectionMatrix() {
  16661. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  16662. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  16663. const cx = ( this.right + this.left ) / 2;
  16664. const cy = ( this.top + this.bottom ) / 2;
  16665. let left = cx - dx;
  16666. let right = cx + dx;
  16667. let top = cy + dy;
  16668. let bottom = cy - dy;
  16669. if ( this.view !== null && this.view.enabled ) {
  16670. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  16671. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  16672. left += scaleW * this.view.offsetX;
  16673. right = left + scaleW * this.view.width;
  16674. top -= scaleH * this.view.offsetY;
  16675. bottom = top - scaleH * this.view.height;
  16676. }
  16677. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
  16678. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  16679. }
  16680. toJSON( meta ) {
  16681. const data = super.toJSON( meta );
  16682. data.object.zoom = this.zoom;
  16683. data.object.left = this.left;
  16684. data.object.right = this.right;
  16685. data.object.top = this.top;
  16686. data.object.bottom = this.bottom;
  16687. data.object.near = this.near;
  16688. data.object.far = this.far;
  16689. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  16690. return data;
  16691. }
  16692. }
  16693. class DirectionalLightShadow extends LightShadow {
  16694. constructor() {
  16695. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  16696. this.isDirectionalLightShadow = true;
  16697. }
  16698. }
  16699. class DirectionalLight extends Light {
  16700. constructor( color, intensity ) {
  16701. super( color, intensity );
  16702. this.isDirectionalLight = true;
  16703. this.type = 'DirectionalLight';
  16704. this.position.copy( Object3D.DEFAULT_UP );
  16705. this.updateMatrix();
  16706. this.target = new Object3D();
  16707. this.shadow = new DirectionalLightShadow();
  16708. }
  16709. dispose() {
  16710. this.shadow.dispose();
  16711. }
  16712. copy( source ) {
  16713. super.copy( source );
  16714. this.target = source.target.clone();
  16715. this.shadow = source.shadow.clone();
  16716. return this;
  16717. }
  16718. }
  16719. class AmbientLight extends Light {
  16720. constructor( color, intensity ) {
  16721. super( color, intensity );
  16722. this.isAmbientLight = true;
  16723. this.type = 'AmbientLight';
  16724. }
  16725. }
  16726. class RectAreaLight extends Light {
  16727. constructor( color, intensity, width = 10, height = 10 ) {
  16728. super( color, intensity );
  16729. this.isRectAreaLight = true;
  16730. this.type = 'RectAreaLight';
  16731. this.width = width;
  16732. this.height = height;
  16733. }
  16734. get power() {
  16735. // compute the light's luminous power (in lumens) from its intensity (in nits)
  16736. return this.intensity * this.width * this.height * Math.PI;
  16737. }
  16738. set power( power ) {
  16739. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  16740. this.intensity = power / ( this.width * this.height * Math.PI );
  16741. }
  16742. copy( source ) {
  16743. super.copy( source );
  16744. this.width = source.width;
  16745. this.height = source.height;
  16746. return this;
  16747. }
  16748. toJSON( meta ) {
  16749. const data = super.toJSON( meta );
  16750. data.object.width = this.width;
  16751. data.object.height = this.height;
  16752. return data;
  16753. }
  16754. }
  16755. /**
  16756. * Primary reference:
  16757. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16758. *
  16759. * Secondary reference:
  16760. * https://www.ppsloan.org/publications/StupidSH36.pdf
  16761. */
  16762. // 3-band SH defined by 9 coefficients
  16763. class SphericalHarmonics3 {
  16764. constructor() {
  16765. this.isSphericalHarmonics3 = true;
  16766. this.coefficients = [];
  16767. for ( let i = 0; i < 9; i ++ ) {
  16768. this.coefficients.push( new Vector3() );
  16769. }
  16770. }
  16771. set( coefficients ) {
  16772. for ( let i = 0; i < 9; i ++ ) {
  16773. this.coefficients[ i ].copy( coefficients[ i ] );
  16774. }
  16775. return this;
  16776. }
  16777. zero() {
  16778. for ( let i = 0; i < 9; i ++ ) {
  16779. this.coefficients[ i ].set( 0, 0, 0 );
  16780. }
  16781. return this;
  16782. }
  16783. // get the radiance in the direction of the normal
  16784. // target is a Vector3
  16785. getAt( normal, target ) {
  16786. // normal is assumed to be unit length
  16787. const x = normal.x, y = normal.y, z = normal.z;
  16788. const coeff = this.coefficients;
  16789. // band 0
  16790. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  16791. // band 1
  16792. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  16793. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  16794. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  16795. // band 2
  16796. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  16797. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  16798. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  16799. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  16800. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  16801. return target;
  16802. }
  16803. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  16804. // target is a Vector3
  16805. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16806. getIrradianceAt( normal, target ) {
  16807. // normal is assumed to be unit length
  16808. const x = normal.x, y = normal.y, z = normal.z;
  16809. const coeff = this.coefficients;
  16810. // band 0
  16811. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  16812. // band 1
  16813. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  16814. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  16815. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  16816. // band 2
  16817. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  16818. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  16819. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  16820. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  16821. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  16822. return target;
  16823. }
  16824. add( sh ) {
  16825. for ( let i = 0; i < 9; i ++ ) {
  16826. this.coefficients[ i ].add( sh.coefficients[ i ] );
  16827. }
  16828. return this;
  16829. }
  16830. addScaledSH( sh, s ) {
  16831. for ( let i = 0; i < 9; i ++ ) {
  16832. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  16833. }
  16834. return this;
  16835. }
  16836. scale( s ) {
  16837. for ( let i = 0; i < 9; i ++ ) {
  16838. this.coefficients[ i ].multiplyScalar( s );
  16839. }
  16840. return this;
  16841. }
  16842. lerp( sh, alpha ) {
  16843. for ( let i = 0; i < 9; i ++ ) {
  16844. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  16845. }
  16846. return this;
  16847. }
  16848. equals( sh ) {
  16849. for ( let i = 0; i < 9; i ++ ) {
  16850. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  16851. return false;
  16852. }
  16853. }
  16854. return true;
  16855. }
  16856. copy( sh ) {
  16857. return this.set( sh.coefficients );
  16858. }
  16859. clone() {
  16860. return new this.constructor().copy( this );
  16861. }
  16862. fromArray( array, offset = 0 ) {
  16863. const coefficients = this.coefficients;
  16864. for ( let i = 0; i < 9; i ++ ) {
  16865. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  16866. }
  16867. return this;
  16868. }
  16869. toArray( array = [], offset = 0 ) {
  16870. const coefficients = this.coefficients;
  16871. for ( let i = 0; i < 9; i ++ ) {
  16872. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  16873. }
  16874. return array;
  16875. }
  16876. // evaluate the basis functions
  16877. // shBasis is an Array[ 9 ]
  16878. static getBasisAt( normal, shBasis ) {
  16879. // normal is assumed to be unit length
  16880. const x = normal.x, y = normal.y, z = normal.z;
  16881. // band 0
  16882. shBasis[ 0 ] = 0.282095;
  16883. // band 1
  16884. shBasis[ 1 ] = 0.488603 * y;
  16885. shBasis[ 2 ] = 0.488603 * z;
  16886. shBasis[ 3 ] = 0.488603 * x;
  16887. // band 2
  16888. shBasis[ 4 ] = 1.092548 * x * y;
  16889. shBasis[ 5 ] = 1.092548 * y * z;
  16890. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  16891. shBasis[ 7 ] = 1.092548 * x * z;
  16892. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  16893. }
  16894. }
  16895. class LightProbe extends Light {
  16896. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  16897. super( undefined, intensity );
  16898. this.isLightProbe = true;
  16899. this.sh = sh;
  16900. }
  16901. copy( source ) {
  16902. super.copy( source );
  16903. this.sh.copy( source.sh );
  16904. return this;
  16905. }
  16906. fromJSON( json ) {
  16907. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  16908. this.sh.fromArray( json.sh );
  16909. return this;
  16910. }
  16911. toJSON( meta ) {
  16912. const data = super.toJSON( meta );
  16913. data.object.sh = this.sh.toArray();
  16914. return data;
  16915. }
  16916. }
  16917. class MaterialLoader extends Loader {
  16918. constructor( manager ) {
  16919. super( manager );
  16920. this.textures = {};
  16921. }
  16922. load( url, onLoad, onProgress, onError ) {
  16923. const scope = this;
  16924. const loader = new FileLoader( scope.manager );
  16925. loader.setPath( scope.path );
  16926. loader.setRequestHeader( scope.requestHeader );
  16927. loader.setWithCredentials( scope.withCredentials );
  16928. loader.load( url, function ( text ) {
  16929. try {
  16930. onLoad( scope.parse( JSON.parse( text ) ) );
  16931. } catch ( e ) {
  16932. if ( onError ) {
  16933. onError( e );
  16934. } else {
  16935. console.error( e );
  16936. }
  16937. scope.manager.itemError( url );
  16938. }
  16939. }, onProgress, onError );
  16940. }
  16941. parse( json ) {
  16942. const textures = this.textures;
  16943. function getTexture( name ) {
  16944. if ( textures[ name ] === undefined ) {
  16945. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  16946. }
  16947. return textures[ name ];
  16948. }
  16949. const material = this.createMaterialFromType( json.type );
  16950. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  16951. if ( json.name !== undefined ) material.name = json.name;
  16952. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  16953. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  16954. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  16955. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  16956. if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor );
  16957. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  16958. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  16959. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  16960. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  16961. if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor );
  16962. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  16963. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  16964. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  16965. if ( json.dispersion !== undefined ) material.dispersion = json.dispersion;
  16966. if ( json.iridescence !== undefined ) material.iridescence = json.iridescence;
  16967. if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR;
  16968. if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
  16969. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  16970. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  16971. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  16972. if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor );
  16973. if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy;
  16974. if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation;
  16975. if ( json.fog !== undefined ) material.fog = json.fog;
  16976. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  16977. if ( json.blending !== undefined ) material.blending = json.blending;
  16978. if ( json.combine !== undefined ) material.combine = json.combine;
  16979. if ( json.side !== undefined ) material.side = json.side;
  16980. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  16981. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  16982. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  16983. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  16984. if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
  16985. if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
  16986. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  16987. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  16988. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  16989. if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
  16990. if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
  16991. if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
  16992. if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
  16993. if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
  16994. if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
  16995. if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
  16996. if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
  16997. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  16998. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  16999. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  17000. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  17001. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  17002. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  17003. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  17004. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  17005. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  17006. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  17007. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  17008. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  17009. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  17010. if ( json.linewidth !== undefined ) material.linewidth = json.linewidth;
  17011. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  17012. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  17013. if ( json.scale !== undefined ) material.scale = json.scale;
  17014. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  17015. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  17016. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  17017. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  17018. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  17019. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  17020. if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
  17021. if ( json.visible !== undefined ) material.visible = json.visible;
  17022. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  17023. if ( json.userData !== undefined ) material.userData = json.userData;
  17024. if ( json.vertexColors !== undefined ) {
  17025. if ( typeof json.vertexColors === 'number' ) {
  17026. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  17027. } else {
  17028. material.vertexColors = json.vertexColors;
  17029. }
  17030. }
  17031. // Shader Material
  17032. if ( json.uniforms !== undefined ) {
  17033. for ( const name in json.uniforms ) {
  17034. const uniform = json.uniforms[ name ];
  17035. material.uniforms[ name ] = {};
  17036. switch ( uniform.type ) {
  17037. case 't':
  17038. material.uniforms[ name ].value = getTexture( uniform.value );
  17039. break;
  17040. case 'c':
  17041. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  17042. break;
  17043. case 'v2':
  17044. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  17045. break;
  17046. case 'v3':
  17047. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  17048. break;
  17049. case 'v4':
  17050. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  17051. break;
  17052. case 'm3':
  17053. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  17054. break;
  17055. case 'm4':
  17056. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  17057. break;
  17058. default:
  17059. material.uniforms[ name ].value = uniform.value;
  17060. }
  17061. }
  17062. }
  17063. if ( json.defines !== undefined ) material.defines = json.defines;
  17064. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  17065. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  17066. if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion;
  17067. if ( json.extensions !== undefined ) {
  17068. for ( const key in json.extensions ) {
  17069. material.extensions[ key ] = json.extensions[ key ];
  17070. }
  17071. }
  17072. if ( json.lights !== undefined ) material.lights = json.lights;
  17073. if ( json.clipping !== undefined ) material.clipping = json.clipping;
  17074. // for PointsMaterial
  17075. if ( json.size !== undefined ) material.size = json.size;
  17076. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  17077. // maps
  17078. if ( json.map !== undefined ) material.map = getTexture( json.map );
  17079. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  17080. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  17081. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  17082. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  17083. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  17084. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  17085. if ( json.normalScale !== undefined ) {
  17086. let normalScale = json.normalScale;
  17087. if ( Array.isArray( normalScale ) === false ) {
  17088. // Blender exporter used to export a scalar. See #7459
  17089. normalScale = [ normalScale, normalScale ];
  17090. }
  17091. material.normalScale = new Vector2().fromArray( normalScale );
  17092. }
  17093. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  17094. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  17095. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  17096. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  17097. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  17098. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  17099. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  17100. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  17101. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  17102. if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
  17103. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  17104. if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
  17105. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  17106. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  17107. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  17108. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  17109. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  17110. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  17111. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  17112. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  17113. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  17114. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  17115. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  17116. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  17117. if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap );
  17118. if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap );
  17119. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  17120. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  17121. if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap );
  17122. if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap );
  17123. if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap );
  17124. return material;
  17125. }
  17126. setTextures( value ) {
  17127. this.textures = value;
  17128. return this;
  17129. }
  17130. createMaterialFromType( type ) {
  17131. return MaterialLoader.createMaterialFromType( type );
  17132. }
  17133. static createMaterialFromType( type ) {
  17134. const materialLib = {
  17135. ShadowMaterial,
  17136. SpriteMaterial,
  17137. RawShaderMaterial,
  17138. ShaderMaterial,
  17139. PointsMaterial,
  17140. MeshPhysicalMaterial,
  17141. MeshStandardMaterial,
  17142. MeshPhongMaterial,
  17143. MeshToonMaterial,
  17144. MeshNormalMaterial,
  17145. MeshLambertMaterial,
  17146. MeshDepthMaterial,
  17147. MeshDistanceMaterial,
  17148. MeshBasicMaterial,
  17149. MeshMatcapMaterial,
  17150. LineDashedMaterial,
  17151. LineBasicMaterial,
  17152. Material
  17153. };
  17154. return new materialLib[ type ]();
  17155. }
  17156. }
  17157. class LoaderUtils {
  17158. static decodeText( array ) { // @deprecated, r165
  17159. console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
  17160. if ( typeof TextDecoder !== 'undefined' ) {
  17161. return new TextDecoder().decode( array );
  17162. }
  17163. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  17164. // throws a "maximum call stack size exceeded" error for large arrays.
  17165. let s = '';
  17166. for ( let i = 0, il = array.length; i < il; i ++ ) {
  17167. // Implicitly assumes little-endian.
  17168. s += String.fromCharCode( array[ i ] );
  17169. }
  17170. try {
  17171. // merges multi-byte utf-8 characters.
  17172. return decodeURIComponent( escape( s ) );
  17173. } catch ( e ) { // see #16358
  17174. return s;
  17175. }
  17176. }
  17177. static extractUrlBase( url ) {
  17178. const index = url.lastIndexOf( '/' );
  17179. if ( index === - 1 ) return './';
  17180. return url.slice( 0, index + 1 );
  17181. }
  17182. static resolveURL( url, path ) {
  17183. // Invalid URL
  17184. if ( typeof url !== 'string' || url === '' ) return '';
  17185. // Host Relative URL
  17186. if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
  17187. path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
  17188. }
  17189. // Absolute URL http://,https://,//
  17190. if ( /^(https?:)?\/\//i.test( url ) ) return url;
  17191. // Data URI
  17192. if ( /^data:.*,.*$/i.test( url ) ) return url;
  17193. // Blob URL
  17194. if ( /^blob:.*$/i.test( url ) ) return url;
  17195. // Relative URL
  17196. return path + url;
  17197. }
  17198. }
  17199. class InstancedBufferGeometry extends BufferGeometry {
  17200. constructor() {
  17201. super();
  17202. this.isInstancedBufferGeometry = true;
  17203. this.type = 'InstancedBufferGeometry';
  17204. this.instanceCount = Infinity;
  17205. }
  17206. copy( source ) {
  17207. super.copy( source );
  17208. this.instanceCount = source.instanceCount;
  17209. return this;
  17210. }
  17211. toJSON() {
  17212. const data = super.toJSON();
  17213. data.instanceCount = this.instanceCount;
  17214. data.isInstancedBufferGeometry = true;
  17215. return data;
  17216. }
  17217. }
  17218. class BufferGeometryLoader extends Loader {
  17219. constructor( manager ) {
  17220. super( manager );
  17221. }
  17222. load( url, onLoad, onProgress, onError ) {
  17223. const scope = this;
  17224. const loader = new FileLoader( scope.manager );
  17225. loader.setPath( scope.path );
  17226. loader.setRequestHeader( scope.requestHeader );
  17227. loader.setWithCredentials( scope.withCredentials );
  17228. loader.load( url, function ( text ) {
  17229. try {
  17230. onLoad( scope.parse( JSON.parse( text ) ) );
  17231. } catch ( e ) {
  17232. if ( onError ) {
  17233. onError( e );
  17234. } else {
  17235. console.error( e );
  17236. }
  17237. scope.manager.itemError( url );
  17238. }
  17239. }, onProgress, onError );
  17240. }
  17241. parse( json ) {
  17242. const interleavedBufferMap = {};
  17243. const arrayBufferMap = {};
  17244. function getInterleavedBuffer( json, uuid ) {
  17245. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  17246. const interleavedBuffers = json.interleavedBuffers;
  17247. const interleavedBuffer = interleavedBuffers[ uuid ];
  17248. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  17249. const array = getTypedArray( interleavedBuffer.type, buffer );
  17250. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  17251. ib.uuid = interleavedBuffer.uuid;
  17252. interleavedBufferMap[ uuid ] = ib;
  17253. return ib;
  17254. }
  17255. function getArrayBuffer( json, uuid ) {
  17256. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  17257. const arrayBuffers = json.arrayBuffers;
  17258. const arrayBuffer = arrayBuffers[ uuid ];
  17259. const ab = new Uint32Array( arrayBuffer ).buffer;
  17260. arrayBufferMap[ uuid ] = ab;
  17261. return ab;
  17262. }
  17263. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  17264. const index = json.data.index;
  17265. if ( index !== undefined ) {
  17266. const typedArray = getTypedArray( index.type, index.array );
  17267. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  17268. }
  17269. const attributes = json.data.attributes;
  17270. for ( const key in attributes ) {
  17271. const attribute = attributes[ key ];
  17272. let bufferAttribute;
  17273. if ( attribute.isInterleavedBufferAttribute ) {
  17274. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17275. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17276. } else {
  17277. const typedArray = getTypedArray( attribute.type, attribute.array );
  17278. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  17279. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  17280. }
  17281. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17282. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  17283. geometry.setAttribute( key, bufferAttribute );
  17284. }
  17285. const morphAttributes = json.data.morphAttributes;
  17286. if ( morphAttributes ) {
  17287. for ( const key in morphAttributes ) {
  17288. const attributeArray = morphAttributes[ key ];
  17289. const array = [];
  17290. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  17291. const attribute = attributeArray[ i ];
  17292. let bufferAttribute;
  17293. if ( attribute.isInterleavedBufferAttribute ) {
  17294. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17295. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17296. } else {
  17297. const typedArray = getTypedArray( attribute.type, attribute.array );
  17298. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  17299. }
  17300. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17301. array.push( bufferAttribute );
  17302. }
  17303. geometry.morphAttributes[ key ] = array;
  17304. }
  17305. }
  17306. const morphTargetsRelative = json.data.morphTargetsRelative;
  17307. if ( morphTargetsRelative ) {
  17308. geometry.morphTargetsRelative = true;
  17309. }
  17310. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  17311. if ( groups !== undefined ) {
  17312. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  17313. const group = groups[ i ];
  17314. geometry.addGroup( group.start, group.count, group.materialIndex );
  17315. }
  17316. }
  17317. const boundingSphere = json.data.boundingSphere;
  17318. if ( boundingSphere !== undefined ) {
  17319. const center = new Vector3();
  17320. if ( boundingSphere.center !== undefined ) {
  17321. center.fromArray( boundingSphere.center );
  17322. }
  17323. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  17324. }
  17325. if ( json.name ) geometry.name = json.name;
  17326. if ( json.userData ) geometry.userData = json.userData;
  17327. return geometry;
  17328. }
  17329. }
  17330. class ObjectLoader extends Loader {
  17331. constructor( manager ) {
  17332. super( manager );
  17333. }
  17334. load( url, onLoad, onProgress, onError ) {
  17335. const scope = this;
  17336. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17337. this.resourcePath = this.resourcePath || path;
  17338. const loader = new FileLoader( this.manager );
  17339. loader.setPath( this.path );
  17340. loader.setRequestHeader( this.requestHeader );
  17341. loader.setWithCredentials( this.withCredentials );
  17342. loader.load( url, function ( text ) {
  17343. let json = null;
  17344. try {
  17345. json = JSON.parse( text );
  17346. } catch ( error ) {
  17347. if ( onError !== undefined ) onError( error );
  17348. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  17349. return;
  17350. }
  17351. const metadata = json.metadata;
  17352. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17353. if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) );
  17354. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17355. return;
  17356. }
  17357. scope.parse( json, onLoad );
  17358. }, onProgress, onError );
  17359. }
  17360. async loadAsync( url, onProgress ) {
  17361. const scope = this;
  17362. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17363. this.resourcePath = this.resourcePath || path;
  17364. const loader = new FileLoader( this.manager );
  17365. loader.setPath( this.path );
  17366. loader.setRequestHeader( this.requestHeader );
  17367. loader.setWithCredentials( this.withCredentials );
  17368. const text = await loader.loadAsync( url, onProgress );
  17369. const json = JSON.parse( text );
  17370. const metadata = json.metadata;
  17371. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17372. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17373. }
  17374. return await scope.parseAsync( json );
  17375. }
  17376. parse( json, onLoad ) {
  17377. const animations = this.parseAnimations( json.animations );
  17378. const shapes = this.parseShapes( json.shapes );
  17379. const geometries = this.parseGeometries( json.geometries, shapes );
  17380. const images = this.parseImages( json.images, function () {
  17381. if ( onLoad !== undefined ) onLoad( object );
  17382. } );
  17383. const textures = this.parseTextures( json.textures, images );
  17384. const materials = this.parseMaterials( json.materials, textures );
  17385. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17386. const skeletons = this.parseSkeletons( json.skeletons, object );
  17387. this.bindSkeletons( object, skeletons );
  17388. this.bindLightTargets( object );
  17389. //
  17390. if ( onLoad !== undefined ) {
  17391. let hasImages = false;
  17392. for ( const uuid in images ) {
  17393. if ( images[ uuid ].data instanceof HTMLImageElement ) {
  17394. hasImages = true;
  17395. break;
  17396. }
  17397. }
  17398. if ( hasImages === false ) onLoad( object );
  17399. }
  17400. return object;
  17401. }
  17402. async parseAsync( json ) {
  17403. const animations = this.parseAnimations( json.animations );
  17404. const shapes = this.parseShapes( json.shapes );
  17405. const geometries = this.parseGeometries( json.geometries, shapes );
  17406. const images = await this.parseImagesAsync( json.images );
  17407. const textures = this.parseTextures( json.textures, images );
  17408. const materials = this.parseMaterials( json.materials, textures );
  17409. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17410. const skeletons = this.parseSkeletons( json.skeletons, object );
  17411. this.bindSkeletons( object, skeletons );
  17412. this.bindLightTargets( object );
  17413. return object;
  17414. }
  17415. parseShapes( json ) {
  17416. const shapes = {};
  17417. if ( json !== undefined ) {
  17418. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17419. const shape = new Shape().fromJSON( json[ i ] );
  17420. shapes[ shape.uuid ] = shape;
  17421. }
  17422. }
  17423. return shapes;
  17424. }
  17425. parseSkeletons( json, object ) {
  17426. const skeletons = {};
  17427. const bones = {};
  17428. // generate bone lookup table
  17429. object.traverse( function ( child ) {
  17430. if ( child.isBone ) bones[ child.uuid ] = child;
  17431. } );
  17432. // create skeletons
  17433. if ( json !== undefined ) {
  17434. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17435. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  17436. skeletons[ skeleton.uuid ] = skeleton;
  17437. }
  17438. }
  17439. return skeletons;
  17440. }
  17441. parseGeometries( json, shapes ) {
  17442. const geometries = {};
  17443. if ( json !== undefined ) {
  17444. const bufferGeometryLoader = new BufferGeometryLoader();
  17445. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17446. let geometry;
  17447. const data = json[ i ];
  17448. switch ( data.type ) {
  17449. case 'BufferGeometry':
  17450. case 'InstancedBufferGeometry':
  17451. geometry = bufferGeometryLoader.parse( data );
  17452. break;
  17453. default:
  17454. if ( data.type in Geometries ) {
  17455. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  17456. } else {
  17457. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  17458. }
  17459. }
  17460. geometry.uuid = data.uuid;
  17461. if ( data.name !== undefined ) geometry.name = data.name;
  17462. if ( data.userData !== undefined ) geometry.userData = data.userData;
  17463. geometries[ data.uuid ] = geometry;
  17464. }
  17465. }
  17466. return geometries;
  17467. }
  17468. parseMaterials( json, textures ) {
  17469. const cache = {}; // MultiMaterial
  17470. const materials = {};
  17471. if ( json !== undefined ) {
  17472. const loader = new MaterialLoader();
  17473. loader.setTextures( textures );
  17474. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17475. const data = json[ i ];
  17476. if ( cache[ data.uuid ] === undefined ) {
  17477. cache[ data.uuid ] = loader.parse( data );
  17478. }
  17479. materials[ data.uuid ] = cache[ data.uuid ];
  17480. }
  17481. }
  17482. return materials;
  17483. }
  17484. parseAnimations( json ) {
  17485. const animations = {};
  17486. if ( json !== undefined ) {
  17487. for ( let i = 0; i < json.length; i ++ ) {
  17488. const data = json[ i ];
  17489. const clip = AnimationClip.parse( data );
  17490. animations[ clip.uuid ] = clip;
  17491. }
  17492. }
  17493. return animations;
  17494. }
  17495. parseImages( json, onLoad ) {
  17496. const scope = this;
  17497. const images = {};
  17498. let loader;
  17499. function loadImage( url ) {
  17500. scope.manager.itemStart( url );
  17501. return loader.load( url, function () {
  17502. scope.manager.itemEnd( url );
  17503. }, undefined, function () {
  17504. scope.manager.itemError( url );
  17505. scope.manager.itemEnd( url );
  17506. } );
  17507. }
  17508. function deserializeImage( image ) {
  17509. if ( typeof image === 'string' ) {
  17510. const url = image;
  17511. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17512. return loadImage( path );
  17513. } else {
  17514. if ( image.data ) {
  17515. return {
  17516. data: getTypedArray( image.type, image.data ),
  17517. width: image.width,
  17518. height: image.height
  17519. };
  17520. } else {
  17521. return null;
  17522. }
  17523. }
  17524. }
  17525. if ( json !== undefined && json.length > 0 ) {
  17526. const manager = new LoadingManager( onLoad );
  17527. loader = new ImageLoader( manager );
  17528. loader.setCrossOrigin( this.crossOrigin );
  17529. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17530. const image = json[ i ];
  17531. const url = image.url;
  17532. if ( Array.isArray( url ) ) {
  17533. // load array of images e.g CubeTexture
  17534. const imageArray = [];
  17535. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17536. const currentUrl = url[ j ];
  17537. const deserializedImage = deserializeImage( currentUrl );
  17538. if ( deserializedImage !== null ) {
  17539. if ( deserializedImage instanceof HTMLImageElement ) {
  17540. imageArray.push( deserializedImage );
  17541. } else {
  17542. // special case: handle array of data textures for cube textures
  17543. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17544. }
  17545. }
  17546. }
  17547. images[ image.uuid ] = new Source( imageArray );
  17548. } else {
  17549. // load single image
  17550. const deserializedImage = deserializeImage( image.url );
  17551. images[ image.uuid ] = new Source( deserializedImage );
  17552. }
  17553. }
  17554. }
  17555. return images;
  17556. }
  17557. async parseImagesAsync( json ) {
  17558. const scope = this;
  17559. const images = {};
  17560. let loader;
  17561. async function deserializeImage( image ) {
  17562. if ( typeof image === 'string' ) {
  17563. const url = image;
  17564. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17565. return await loader.loadAsync( path );
  17566. } else {
  17567. if ( image.data ) {
  17568. return {
  17569. data: getTypedArray( image.type, image.data ),
  17570. width: image.width,
  17571. height: image.height
  17572. };
  17573. } else {
  17574. return null;
  17575. }
  17576. }
  17577. }
  17578. if ( json !== undefined && json.length > 0 ) {
  17579. loader = new ImageLoader( this.manager );
  17580. loader.setCrossOrigin( this.crossOrigin );
  17581. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17582. const image = json[ i ];
  17583. const url = image.url;
  17584. if ( Array.isArray( url ) ) {
  17585. // load array of images e.g CubeTexture
  17586. const imageArray = [];
  17587. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17588. const currentUrl = url[ j ];
  17589. const deserializedImage = await deserializeImage( currentUrl );
  17590. if ( deserializedImage !== null ) {
  17591. if ( deserializedImage instanceof HTMLImageElement ) {
  17592. imageArray.push( deserializedImage );
  17593. } else {
  17594. // special case: handle array of data textures for cube textures
  17595. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17596. }
  17597. }
  17598. }
  17599. images[ image.uuid ] = new Source( imageArray );
  17600. } else {
  17601. // load single image
  17602. const deserializedImage = await deserializeImage( image.url );
  17603. images[ image.uuid ] = new Source( deserializedImage );
  17604. }
  17605. }
  17606. }
  17607. return images;
  17608. }
  17609. parseTextures( json, images ) {
  17610. function parseConstant( value, type ) {
  17611. if ( typeof value === 'number' ) return value;
  17612. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  17613. return type[ value ];
  17614. }
  17615. const textures = {};
  17616. if ( json !== undefined ) {
  17617. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17618. const data = json[ i ];
  17619. if ( data.image === undefined ) {
  17620. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  17621. }
  17622. if ( images[ data.image ] === undefined ) {
  17623. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  17624. }
  17625. const source = images[ data.image ];
  17626. const image = source.data;
  17627. let texture;
  17628. if ( Array.isArray( image ) ) {
  17629. texture = new CubeTexture();
  17630. if ( image.length === 6 ) texture.needsUpdate = true;
  17631. } else {
  17632. if ( image && image.data ) {
  17633. texture = new DataTexture();
  17634. } else {
  17635. texture = new Texture();
  17636. }
  17637. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  17638. }
  17639. texture.source = source;
  17640. texture.uuid = data.uuid;
  17641. if ( data.name !== undefined ) texture.name = data.name;
  17642. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  17643. if ( data.channel !== undefined ) texture.channel = data.channel;
  17644. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  17645. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  17646. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  17647. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  17648. if ( data.wrap !== undefined ) {
  17649. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  17650. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  17651. }
  17652. if ( data.format !== undefined ) texture.format = data.format;
  17653. if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
  17654. if ( data.type !== undefined ) texture.type = data.type;
  17655. if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
  17656. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  17657. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  17658. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  17659. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  17660. if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps;
  17661. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  17662. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  17663. if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
  17664. if ( data.userData !== undefined ) texture.userData = data.userData;
  17665. textures[ data.uuid ] = texture;
  17666. }
  17667. }
  17668. return textures;
  17669. }
  17670. parseObject( data, geometries, materials, textures, animations ) {
  17671. let object;
  17672. function getGeometry( name ) {
  17673. if ( geometries[ name ] === undefined ) {
  17674. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  17675. }
  17676. return geometries[ name ];
  17677. }
  17678. function getMaterial( name ) {
  17679. if ( name === undefined ) return undefined;
  17680. if ( Array.isArray( name ) ) {
  17681. const array = [];
  17682. for ( let i = 0, l = name.length; i < l; i ++ ) {
  17683. const uuid = name[ i ];
  17684. if ( materials[ uuid ] === undefined ) {
  17685. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  17686. }
  17687. array.push( materials[ uuid ] );
  17688. }
  17689. return array;
  17690. }
  17691. if ( materials[ name ] === undefined ) {
  17692. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  17693. }
  17694. return materials[ name ];
  17695. }
  17696. function getTexture( uuid ) {
  17697. if ( textures[ uuid ] === undefined ) {
  17698. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  17699. }
  17700. return textures[ uuid ];
  17701. }
  17702. let geometry, material;
  17703. switch ( data.type ) {
  17704. case 'Scene':
  17705. object = new Scene();
  17706. if ( data.background !== undefined ) {
  17707. if ( Number.isInteger( data.background ) ) {
  17708. object.background = new Color( data.background );
  17709. } else {
  17710. object.background = getTexture( data.background );
  17711. }
  17712. }
  17713. if ( data.environment !== undefined ) {
  17714. object.environment = getTexture( data.environment );
  17715. }
  17716. if ( data.fog !== undefined ) {
  17717. if ( data.fog.type === 'Fog' ) {
  17718. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  17719. } else if ( data.fog.type === 'FogExp2' ) {
  17720. object.fog = new FogExp2( data.fog.color, data.fog.density );
  17721. }
  17722. if ( data.fog.name !== '' ) {
  17723. object.fog.name = data.fog.name;
  17724. }
  17725. }
  17726. if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
  17727. if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
  17728. if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
  17729. if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
  17730. if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
  17731. break;
  17732. case 'PerspectiveCamera':
  17733. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  17734. if ( data.focus !== undefined ) object.focus = data.focus;
  17735. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17736. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  17737. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  17738. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17739. break;
  17740. case 'OrthographicCamera':
  17741. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  17742. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17743. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17744. break;
  17745. case 'AmbientLight':
  17746. object = new AmbientLight( data.color, data.intensity );
  17747. break;
  17748. case 'DirectionalLight':
  17749. object = new DirectionalLight( data.color, data.intensity );
  17750. object.target = data.target || '';
  17751. break;
  17752. case 'PointLight':
  17753. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  17754. break;
  17755. case 'RectAreaLight':
  17756. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  17757. break;
  17758. case 'SpotLight':
  17759. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  17760. object.target = data.target || '';
  17761. break;
  17762. case 'HemisphereLight':
  17763. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  17764. break;
  17765. case 'LightProbe':
  17766. object = new LightProbe().fromJSON( data );
  17767. break;
  17768. case 'SkinnedMesh':
  17769. geometry = getGeometry( data.geometry );
  17770. material = getMaterial( data.material );
  17771. object = new SkinnedMesh( geometry, material );
  17772. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  17773. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  17774. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  17775. break;
  17776. case 'Mesh':
  17777. geometry = getGeometry( data.geometry );
  17778. material = getMaterial( data.material );
  17779. object = new Mesh( geometry, material );
  17780. break;
  17781. case 'InstancedMesh':
  17782. geometry = getGeometry( data.geometry );
  17783. material = getMaterial( data.material );
  17784. const count = data.count;
  17785. const instanceMatrix = data.instanceMatrix;
  17786. const instanceColor = data.instanceColor;
  17787. object = new InstancedMesh( geometry, material, count );
  17788. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  17789. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  17790. break;
  17791. case 'BatchedMesh':
  17792. geometry = getGeometry( data.geometry );
  17793. material = getMaterial( data.material );
  17794. object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material );
  17795. object.geometry = geometry;
  17796. object.perObjectFrustumCulled = data.perObjectFrustumCulled;
  17797. object.sortObjects = data.sortObjects;
  17798. object._drawRanges = data.drawRanges;
  17799. object._reservedRanges = data.reservedRanges;
  17800. object._visibility = data.visibility;
  17801. object._active = data.active;
  17802. object._bounds = data.bounds.map( bound => {
  17803. const box = new Box3();
  17804. box.min.fromArray( bound.boxMin );
  17805. box.max.fromArray( bound.boxMax );
  17806. const sphere = new Sphere();
  17807. sphere.radius = bound.sphereRadius;
  17808. sphere.center.fromArray( bound.sphereCenter );
  17809. return {
  17810. boxInitialized: bound.boxInitialized,
  17811. box: box,
  17812. sphereInitialized: bound.sphereInitialized,
  17813. sphere: sphere
  17814. };
  17815. } );
  17816. object._maxInstanceCount = data.maxInstanceCount;
  17817. object._maxVertexCount = data.maxVertexCount;
  17818. object._maxIndexCount = data.maxIndexCount;
  17819. object._geometryInitialized = data.geometryInitialized;
  17820. object._geometryCount = data.geometryCount;
  17821. object._matricesTexture = getTexture( data.matricesTexture.uuid );
  17822. if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
  17823. break;
  17824. case 'LOD':
  17825. object = new LOD();
  17826. break;
  17827. case 'Line':
  17828. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  17829. break;
  17830. case 'LineLoop':
  17831. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  17832. break;
  17833. case 'LineSegments':
  17834. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  17835. break;
  17836. case 'PointCloud':
  17837. case 'Points':
  17838. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  17839. break;
  17840. case 'Sprite':
  17841. object = new Sprite( getMaterial( data.material ) );
  17842. break;
  17843. case 'Group':
  17844. object = new Group();
  17845. break;
  17846. case 'Bone':
  17847. object = new Bone();
  17848. break;
  17849. default:
  17850. object = new Object3D();
  17851. }
  17852. object.uuid = data.uuid;
  17853. if ( data.name !== undefined ) object.name = data.name;
  17854. if ( data.matrix !== undefined ) {
  17855. object.matrix.fromArray( data.matrix );
  17856. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  17857. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  17858. } else {
  17859. if ( data.position !== undefined ) object.position.fromArray( data.position );
  17860. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  17861. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  17862. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  17863. }
  17864. if ( data.up !== undefined ) object.up.fromArray( data.up );
  17865. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  17866. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  17867. if ( data.shadow ) {
  17868. if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
  17869. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  17870. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  17871. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  17872. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  17873. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  17874. }
  17875. if ( data.visible !== undefined ) object.visible = data.visible;
  17876. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  17877. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  17878. if ( data.userData !== undefined ) object.userData = data.userData;
  17879. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  17880. if ( data.children !== undefined ) {
  17881. const children = data.children;
  17882. for ( let i = 0; i < children.length; i ++ ) {
  17883. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  17884. }
  17885. }
  17886. if ( data.animations !== undefined ) {
  17887. const objectAnimations = data.animations;
  17888. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  17889. const uuid = objectAnimations[ i ];
  17890. object.animations.push( animations[ uuid ] );
  17891. }
  17892. }
  17893. if ( data.type === 'LOD' ) {
  17894. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  17895. const levels = data.levels;
  17896. for ( let l = 0; l < levels.length; l ++ ) {
  17897. const level = levels[ l ];
  17898. const child = object.getObjectByProperty( 'uuid', level.object );
  17899. if ( child !== undefined ) {
  17900. object.addLevel( child, level.distance, level.hysteresis );
  17901. }
  17902. }
  17903. }
  17904. return object;
  17905. }
  17906. bindSkeletons( object, skeletons ) {
  17907. if ( Object.keys( skeletons ).length === 0 ) return;
  17908. object.traverse( function ( child ) {
  17909. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  17910. const skeleton = skeletons[ child.skeleton ];
  17911. if ( skeleton === undefined ) {
  17912. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  17913. } else {
  17914. child.bind( skeleton, child.bindMatrix );
  17915. }
  17916. }
  17917. } );
  17918. }
  17919. bindLightTargets( object ) {
  17920. object.traverse( function ( child ) {
  17921. if ( child.isDirectionalLight || child.isSpotLight ) {
  17922. const uuid = child.target;
  17923. const target = object.getObjectByProperty( 'uuid', uuid );
  17924. if ( target !== undefined ) {
  17925. child.target = target;
  17926. } else {
  17927. child.target = new Object3D();
  17928. }
  17929. }
  17930. } );
  17931. }
  17932. }
  17933. const TEXTURE_MAPPING = {
  17934. UVMapping: UVMapping,
  17935. CubeReflectionMapping: CubeReflectionMapping,
  17936. CubeRefractionMapping: CubeRefractionMapping,
  17937. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  17938. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  17939. CubeUVReflectionMapping: CubeUVReflectionMapping
  17940. };
  17941. const TEXTURE_WRAPPING = {
  17942. RepeatWrapping: RepeatWrapping,
  17943. ClampToEdgeWrapping: ClampToEdgeWrapping,
  17944. MirroredRepeatWrapping: MirroredRepeatWrapping
  17945. };
  17946. const TEXTURE_FILTER = {
  17947. NearestFilter: NearestFilter,
  17948. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  17949. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  17950. LinearFilter: LinearFilter,
  17951. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  17952. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  17953. };
  17954. class ImageBitmapLoader extends Loader {
  17955. constructor( manager ) {
  17956. super( manager );
  17957. this.isImageBitmapLoader = true;
  17958. if ( typeof createImageBitmap === 'undefined' ) {
  17959. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  17960. }
  17961. if ( typeof fetch === 'undefined' ) {
  17962. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  17963. }
  17964. this.options = { premultiplyAlpha: 'none' };
  17965. }
  17966. setOptions( options ) {
  17967. this.options = options;
  17968. return this;
  17969. }
  17970. load( url, onLoad, onProgress, onError ) {
  17971. if ( url === undefined ) url = '';
  17972. if ( this.path !== undefined ) url = this.path + url;
  17973. url = this.manager.resolveURL( url );
  17974. const scope = this;
  17975. const cached = Cache.get( url );
  17976. if ( cached !== undefined ) {
  17977. scope.manager.itemStart( url );
  17978. // If cached is a promise, wait for it to resolve
  17979. if ( cached.then ) {
  17980. cached.then( imageBitmap => {
  17981. if ( onLoad ) onLoad( imageBitmap );
  17982. scope.manager.itemEnd( url );
  17983. } ).catch( e => {
  17984. if ( onError ) onError( e );
  17985. } );
  17986. return;
  17987. }
  17988. // If cached is not a promise (i.e., it's already an imageBitmap)
  17989. setTimeout( function () {
  17990. if ( onLoad ) onLoad( cached );
  17991. scope.manager.itemEnd( url );
  17992. }, 0 );
  17993. return cached;
  17994. }
  17995. const fetchOptions = {};
  17996. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  17997. fetchOptions.headers = this.requestHeader;
  17998. const promise = fetch( url, fetchOptions ).then( function ( res ) {
  17999. return res.blob();
  18000. } ).then( function ( blob ) {
  18001. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  18002. } ).then( function ( imageBitmap ) {
  18003. Cache.add( url, imageBitmap );
  18004. if ( onLoad ) onLoad( imageBitmap );
  18005. scope.manager.itemEnd( url );
  18006. return imageBitmap;
  18007. } ).catch( function ( e ) {
  18008. if ( onError ) onError( e );
  18009. Cache.remove( url );
  18010. scope.manager.itemError( url );
  18011. scope.manager.itemEnd( url );
  18012. } );
  18013. Cache.add( url, promise );
  18014. scope.manager.itemStart( url );
  18015. }
  18016. }
  18017. let _context;
  18018. class AudioContext {
  18019. static getContext() {
  18020. if ( _context === undefined ) {
  18021. _context = new ( window.AudioContext || window.webkitAudioContext )();
  18022. }
  18023. return _context;
  18024. }
  18025. static setContext( value ) {
  18026. _context = value;
  18027. }
  18028. }
  18029. class AudioLoader extends Loader {
  18030. constructor( manager ) {
  18031. super( manager );
  18032. }
  18033. load( url, onLoad, onProgress, onError ) {
  18034. const scope = this;
  18035. const loader = new FileLoader( this.manager );
  18036. loader.setResponseType( 'arraybuffer' );
  18037. loader.setPath( this.path );
  18038. loader.setRequestHeader( this.requestHeader );
  18039. loader.setWithCredentials( this.withCredentials );
  18040. loader.load( url, function ( buffer ) {
  18041. try {
  18042. // Create a copy of the buffer. The `decodeAudioData` method
  18043. // detaches the buffer when complete, preventing reuse.
  18044. const bufferCopy = buffer.slice( 0 );
  18045. const context = AudioContext.getContext();
  18046. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  18047. onLoad( audioBuffer );
  18048. } ).catch( handleError );
  18049. } catch ( e ) {
  18050. handleError( e );
  18051. }
  18052. }, onProgress, onError );
  18053. function handleError( e ) {
  18054. if ( onError ) {
  18055. onError( e );
  18056. } else {
  18057. console.error( e );
  18058. }
  18059. scope.manager.itemError( url );
  18060. }
  18061. }
  18062. }
  18063. const _eyeRight = /*@__PURE__*/ new Matrix4();
  18064. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  18065. const _projectionMatrix = /*@__PURE__*/ new Matrix4();
  18066. class StereoCamera {
  18067. constructor() {
  18068. this.type = 'StereoCamera';
  18069. this.aspect = 1;
  18070. this.eyeSep = 0.064;
  18071. this.cameraL = new PerspectiveCamera();
  18072. this.cameraL.layers.enable( 1 );
  18073. this.cameraL.matrixAutoUpdate = false;
  18074. this.cameraR = new PerspectiveCamera();
  18075. this.cameraR.layers.enable( 2 );
  18076. this.cameraR.matrixAutoUpdate = false;
  18077. this._cache = {
  18078. focus: null,
  18079. fov: null,
  18080. aspect: null,
  18081. near: null,
  18082. far: null,
  18083. zoom: null,
  18084. eyeSep: null
  18085. };
  18086. }
  18087. update( camera ) {
  18088. const cache = this._cache;
  18089. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  18090. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  18091. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  18092. if ( needsUpdate ) {
  18093. cache.focus = camera.focus;
  18094. cache.fov = camera.fov;
  18095. cache.aspect = camera.aspect * this.aspect;
  18096. cache.near = camera.near;
  18097. cache.far = camera.far;
  18098. cache.zoom = camera.zoom;
  18099. cache.eyeSep = this.eyeSep;
  18100. // Off-axis stereoscopic effect based on
  18101. // http://paulbourke.net/stereographics/stereorender/
  18102. _projectionMatrix.copy( camera.projectionMatrix );
  18103. const eyeSepHalf = cache.eyeSep / 2;
  18104. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  18105. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  18106. let xmin, xmax;
  18107. // translate xOffset
  18108. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  18109. _eyeRight.elements[ 12 ] = eyeSepHalf;
  18110. // for left eye
  18111. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  18112. xmax = ymax * cache.aspect + eyeSepOnProjection;
  18113. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18114. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18115. this.cameraL.projectionMatrix.copy( _projectionMatrix );
  18116. // for right eye
  18117. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  18118. xmax = ymax * cache.aspect - eyeSepOnProjection;
  18119. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18120. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18121. this.cameraR.projectionMatrix.copy( _projectionMatrix );
  18122. }
  18123. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  18124. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  18125. }
  18126. }
  18127. class ArrayCamera extends PerspectiveCamera {
  18128. constructor( array = [] ) {
  18129. super();
  18130. this.isArrayCamera = true;
  18131. this.cameras = array;
  18132. }
  18133. }
  18134. class Clock {
  18135. constructor( autoStart = true ) {
  18136. this.autoStart = autoStart;
  18137. this.startTime = 0;
  18138. this.oldTime = 0;
  18139. this.elapsedTime = 0;
  18140. this.running = false;
  18141. }
  18142. start() {
  18143. this.startTime = now();
  18144. this.oldTime = this.startTime;
  18145. this.elapsedTime = 0;
  18146. this.running = true;
  18147. }
  18148. stop() {
  18149. this.getElapsedTime();
  18150. this.running = false;
  18151. this.autoStart = false;
  18152. }
  18153. getElapsedTime() {
  18154. this.getDelta();
  18155. return this.elapsedTime;
  18156. }
  18157. getDelta() {
  18158. let diff = 0;
  18159. if ( this.autoStart && ! this.running ) {
  18160. this.start();
  18161. return 0;
  18162. }
  18163. if ( this.running ) {
  18164. const newTime = now();
  18165. diff = ( newTime - this.oldTime ) / 1000;
  18166. this.oldTime = newTime;
  18167. this.elapsedTime += diff;
  18168. }
  18169. return diff;
  18170. }
  18171. }
  18172. function now() {
  18173. return performance.now();
  18174. }
  18175. const _position$1 = /*@__PURE__*/ new Vector3();
  18176. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  18177. const _scale$1 = /*@__PURE__*/ new Vector3();
  18178. const _orientation$1 = /*@__PURE__*/ new Vector3();
  18179. class AudioListener extends Object3D {
  18180. constructor() {
  18181. super();
  18182. this.type = 'AudioListener';
  18183. this.context = AudioContext.getContext();
  18184. this.gain = this.context.createGain();
  18185. this.gain.connect( this.context.destination );
  18186. this.filter = null;
  18187. this.timeDelta = 0;
  18188. // private
  18189. this._clock = new Clock();
  18190. }
  18191. getInput() {
  18192. return this.gain;
  18193. }
  18194. removeFilter() {
  18195. if ( this.filter !== null ) {
  18196. this.gain.disconnect( this.filter );
  18197. this.filter.disconnect( this.context.destination );
  18198. this.gain.connect( this.context.destination );
  18199. this.filter = null;
  18200. }
  18201. return this;
  18202. }
  18203. getFilter() {
  18204. return this.filter;
  18205. }
  18206. setFilter( value ) {
  18207. if ( this.filter !== null ) {
  18208. this.gain.disconnect( this.filter );
  18209. this.filter.disconnect( this.context.destination );
  18210. } else {
  18211. this.gain.disconnect( this.context.destination );
  18212. }
  18213. this.filter = value;
  18214. this.gain.connect( this.filter );
  18215. this.filter.connect( this.context.destination );
  18216. return this;
  18217. }
  18218. getMasterVolume() {
  18219. return this.gain.gain.value;
  18220. }
  18221. setMasterVolume( value ) {
  18222. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18223. return this;
  18224. }
  18225. updateMatrixWorld( force ) {
  18226. super.updateMatrixWorld( force );
  18227. const listener = this.context.listener;
  18228. const up = this.up;
  18229. this.timeDelta = this._clock.getDelta();
  18230. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  18231. _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 );
  18232. if ( listener.positionX ) {
  18233. // code path for Chrome (see #14393)
  18234. const endTime = this.context.currentTime + this.timeDelta;
  18235. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  18236. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  18237. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  18238. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  18239. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  18240. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  18241. listener.upX.linearRampToValueAtTime( up.x, endTime );
  18242. listener.upY.linearRampToValueAtTime( up.y, endTime );
  18243. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  18244. } else {
  18245. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  18246. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  18247. }
  18248. }
  18249. }
  18250. class Audio extends Object3D {
  18251. constructor( listener ) {
  18252. super();
  18253. this.type = 'Audio';
  18254. this.listener = listener;
  18255. this.context = listener.context;
  18256. this.gain = this.context.createGain();
  18257. this.gain.connect( listener.getInput() );
  18258. this.autoplay = false;
  18259. this.buffer = null;
  18260. this.detune = 0;
  18261. this.loop = false;
  18262. this.loopStart = 0;
  18263. this.loopEnd = 0;
  18264. this.offset = 0;
  18265. this.duration = undefined;
  18266. this.playbackRate = 1;
  18267. this.isPlaying = false;
  18268. this.hasPlaybackControl = true;
  18269. this.source = null;
  18270. this.sourceType = 'empty';
  18271. this._startedAt = 0;
  18272. this._progress = 0;
  18273. this._connected = false;
  18274. this.filters = [];
  18275. }
  18276. getOutput() {
  18277. return this.gain;
  18278. }
  18279. setNodeSource( audioNode ) {
  18280. this.hasPlaybackControl = false;
  18281. this.sourceType = 'audioNode';
  18282. this.source = audioNode;
  18283. this.connect();
  18284. return this;
  18285. }
  18286. setMediaElementSource( mediaElement ) {
  18287. this.hasPlaybackControl = false;
  18288. this.sourceType = 'mediaNode';
  18289. this.source = this.context.createMediaElementSource( mediaElement );
  18290. this.connect();
  18291. return this;
  18292. }
  18293. setMediaStreamSource( mediaStream ) {
  18294. this.hasPlaybackControl = false;
  18295. this.sourceType = 'mediaStreamNode';
  18296. this.source = this.context.createMediaStreamSource( mediaStream );
  18297. this.connect();
  18298. return this;
  18299. }
  18300. setBuffer( audioBuffer ) {
  18301. this.buffer = audioBuffer;
  18302. this.sourceType = 'buffer';
  18303. if ( this.autoplay ) this.play();
  18304. return this;
  18305. }
  18306. play( delay = 0 ) {
  18307. if ( this.isPlaying === true ) {
  18308. console.warn( 'THREE.Audio: Audio is already playing.' );
  18309. return;
  18310. }
  18311. if ( this.hasPlaybackControl === false ) {
  18312. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18313. return;
  18314. }
  18315. this._startedAt = this.context.currentTime + delay;
  18316. const source = this.context.createBufferSource();
  18317. source.buffer = this.buffer;
  18318. source.loop = this.loop;
  18319. source.loopStart = this.loopStart;
  18320. source.loopEnd = this.loopEnd;
  18321. source.onended = this.onEnded.bind( this );
  18322. source.start( this._startedAt, this._progress + this.offset, this.duration );
  18323. this.isPlaying = true;
  18324. this.source = source;
  18325. this.setDetune( this.detune );
  18326. this.setPlaybackRate( this.playbackRate );
  18327. return this.connect();
  18328. }
  18329. pause() {
  18330. if ( this.hasPlaybackControl === false ) {
  18331. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18332. return;
  18333. }
  18334. if ( this.isPlaying === true ) {
  18335. // update current progress
  18336. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  18337. if ( this.loop === true ) {
  18338. // ensure _progress does not exceed duration with looped audios
  18339. this._progress = this._progress % ( this.duration || this.buffer.duration );
  18340. }
  18341. this.source.stop();
  18342. this.source.onended = null;
  18343. this.isPlaying = false;
  18344. }
  18345. return this;
  18346. }
  18347. stop( delay = 0 ) {
  18348. if ( this.hasPlaybackControl === false ) {
  18349. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18350. return;
  18351. }
  18352. this._progress = 0;
  18353. if ( this.source !== null ) {
  18354. this.source.stop( this.context.currentTime + delay );
  18355. this.source.onended = null;
  18356. }
  18357. this.isPlaying = false;
  18358. return this;
  18359. }
  18360. connect() {
  18361. if ( this.filters.length > 0 ) {
  18362. this.source.connect( this.filters[ 0 ] );
  18363. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18364. this.filters[ i - 1 ].connect( this.filters[ i ] );
  18365. }
  18366. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  18367. } else {
  18368. this.source.connect( this.getOutput() );
  18369. }
  18370. this._connected = true;
  18371. return this;
  18372. }
  18373. disconnect() {
  18374. if ( this._connected === false ) {
  18375. return;
  18376. }
  18377. if ( this.filters.length > 0 ) {
  18378. this.source.disconnect( this.filters[ 0 ] );
  18379. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18380. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  18381. }
  18382. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  18383. } else {
  18384. this.source.disconnect( this.getOutput() );
  18385. }
  18386. this._connected = false;
  18387. return this;
  18388. }
  18389. getFilters() {
  18390. return this.filters;
  18391. }
  18392. setFilters( value ) {
  18393. if ( ! value ) value = [];
  18394. if ( this._connected === true ) {
  18395. this.disconnect();
  18396. this.filters = value.slice();
  18397. this.connect();
  18398. } else {
  18399. this.filters = value.slice();
  18400. }
  18401. return this;
  18402. }
  18403. setDetune( value ) {
  18404. this.detune = value;
  18405. if ( this.isPlaying === true && this.source.detune !== undefined ) {
  18406. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  18407. }
  18408. return this;
  18409. }
  18410. getDetune() {
  18411. return this.detune;
  18412. }
  18413. getFilter() {
  18414. return this.getFilters()[ 0 ];
  18415. }
  18416. setFilter( filter ) {
  18417. return this.setFilters( filter ? [ filter ] : [] );
  18418. }
  18419. setPlaybackRate( value ) {
  18420. if ( this.hasPlaybackControl === false ) {
  18421. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18422. return;
  18423. }
  18424. this.playbackRate = value;
  18425. if ( this.isPlaying === true ) {
  18426. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  18427. }
  18428. return this;
  18429. }
  18430. getPlaybackRate() {
  18431. return this.playbackRate;
  18432. }
  18433. onEnded() {
  18434. this.isPlaying = false;
  18435. this._progress = 0;
  18436. }
  18437. getLoop() {
  18438. if ( this.hasPlaybackControl === false ) {
  18439. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18440. return false;
  18441. }
  18442. return this.loop;
  18443. }
  18444. setLoop( value ) {
  18445. if ( this.hasPlaybackControl === false ) {
  18446. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18447. return;
  18448. }
  18449. this.loop = value;
  18450. if ( this.isPlaying === true ) {
  18451. this.source.loop = this.loop;
  18452. }
  18453. return this;
  18454. }
  18455. setLoopStart( value ) {
  18456. this.loopStart = value;
  18457. return this;
  18458. }
  18459. setLoopEnd( value ) {
  18460. this.loopEnd = value;
  18461. return this;
  18462. }
  18463. getVolume() {
  18464. return this.gain.gain.value;
  18465. }
  18466. setVolume( value ) {
  18467. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18468. return this;
  18469. }
  18470. copy( source, recursive ) {
  18471. super.copy( source, recursive );
  18472. if ( source.sourceType !== 'buffer' ) {
  18473. console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
  18474. return this;
  18475. }
  18476. this.autoplay = source.autoplay;
  18477. this.buffer = source.buffer;
  18478. this.detune = source.detune;
  18479. this.loop = source.loop;
  18480. this.loopStart = source.loopStart;
  18481. this.loopEnd = source.loopEnd;
  18482. this.offset = source.offset;
  18483. this.duration = source.duration;
  18484. this.playbackRate = source.playbackRate;
  18485. this.hasPlaybackControl = source.hasPlaybackControl;
  18486. this.sourceType = source.sourceType;
  18487. this.filters = source.filters.slice();
  18488. return this;
  18489. }
  18490. clone( recursive ) {
  18491. return new this.constructor( this.listener ).copy( this, recursive );
  18492. }
  18493. }
  18494. const _position = /*@__PURE__*/ new Vector3();
  18495. const _quaternion = /*@__PURE__*/ new Quaternion();
  18496. const _scale = /*@__PURE__*/ new Vector3();
  18497. const _orientation = /*@__PURE__*/ new Vector3();
  18498. class PositionalAudio extends Audio {
  18499. constructor( listener ) {
  18500. super( listener );
  18501. this.panner = this.context.createPanner();
  18502. this.panner.panningModel = 'HRTF';
  18503. this.panner.connect( this.gain );
  18504. }
  18505. connect() {
  18506. super.connect();
  18507. this.panner.connect( this.gain );
  18508. }
  18509. disconnect() {
  18510. super.disconnect();
  18511. this.panner.disconnect( this.gain );
  18512. }
  18513. getOutput() {
  18514. return this.panner;
  18515. }
  18516. getRefDistance() {
  18517. return this.panner.refDistance;
  18518. }
  18519. setRefDistance( value ) {
  18520. this.panner.refDistance = value;
  18521. return this;
  18522. }
  18523. getRolloffFactor() {
  18524. return this.panner.rolloffFactor;
  18525. }
  18526. setRolloffFactor( value ) {
  18527. this.panner.rolloffFactor = value;
  18528. return this;
  18529. }
  18530. getDistanceModel() {
  18531. return this.panner.distanceModel;
  18532. }
  18533. setDistanceModel( value ) {
  18534. this.panner.distanceModel = value;
  18535. return this;
  18536. }
  18537. getMaxDistance() {
  18538. return this.panner.maxDistance;
  18539. }
  18540. setMaxDistance( value ) {
  18541. this.panner.maxDistance = value;
  18542. return this;
  18543. }
  18544. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  18545. this.panner.coneInnerAngle = coneInnerAngle;
  18546. this.panner.coneOuterAngle = coneOuterAngle;
  18547. this.panner.coneOuterGain = coneOuterGain;
  18548. return this;
  18549. }
  18550. updateMatrixWorld( force ) {
  18551. super.updateMatrixWorld( force );
  18552. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  18553. this.matrixWorld.decompose( _position, _quaternion, _scale );
  18554. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  18555. const panner = this.panner;
  18556. if ( panner.positionX ) {
  18557. // code path for Chrome and Firefox (see #14393)
  18558. const endTime = this.context.currentTime + this.listener.timeDelta;
  18559. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  18560. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  18561. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  18562. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  18563. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  18564. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  18565. } else {
  18566. panner.setPosition( _position.x, _position.y, _position.z );
  18567. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  18568. }
  18569. }
  18570. }
  18571. class AudioAnalyser {
  18572. constructor( audio, fftSize = 2048 ) {
  18573. this.analyser = audio.context.createAnalyser();
  18574. this.analyser.fftSize = fftSize;
  18575. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  18576. audio.getOutput().connect( this.analyser );
  18577. }
  18578. getFrequencyData() {
  18579. this.analyser.getByteFrequencyData( this.data );
  18580. return this.data;
  18581. }
  18582. getAverageFrequency() {
  18583. let value = 0;
  18584. const data = this.getFrequencyData();
  18585. for ( let i = 0; i < data.length; i ++ ) {
  18586. value += data[ i ];
  18587. }
  18588. return value / data.length;
  18589. }
  18590. }
  18591. class PropertyMixer {
  18592. constructor( binding, typeName, valueSize ) {
  18593. this.binding = binding;
  18594. this.valueSize = valueSize;
  18595. let mixFunction,
  18596. mixFunctionAdditive,
  18597. setIdentity;
  18598. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  18599. //
  18600. // interpolators can use .buffer as their .result
  18601. // the data then goes to 'incoming'
  18602. //
  18603. // 'accu0' and 'accu1' are used frame-interleaved for
  18604. // the cumulative result and are compared to detect
  18605. // changes
  18606. //
  18607. // 'orig' stores the original state of the property
  18608. //
  18609. // 'add' is used for additive cumulative results
  18610. //
  18611. // 'work' is optional and is only present for quaternion types. It is used
  18612. // to store intermediate quaternion multiplication results
  18613. switch ( typeName ) {
  18614. case 'quaternion':
  18615. mixFunction = this._slerp;
  18616. mixFunctionAdditive = this._slerpAdditive;
  18617. setIdentity = this._setAdditiveIdentityQuaternion;
  18618. this.buffer = new Float64Array( valueSize * 6 );
  18619. this._workIndex = 5;
  18620. break;
  18621. case 'string':
  18622. case 'bool':
  18623. mixFunction = this._select;
  18624. // Use the regular mix function and for additive on these types,
  18625. // additive is not relevant for non-numeric types
  18626. mixFunctionAdditive = this._select;
  18627. setIdentity = this._setAdditiveIdentityOther;
  18628. this.buffer = new Array( valueSize * 5 );
  18629. break;
  18630. default:
  18631. mixFunction = this._lerp;
  18632. mixFunctionAdditive = this._lerpAdditive;
  18633. setIdentity = this._setAdditiveIdentityNumeric;
  18634. this.buffer = new Float64Array( valueSize * 5 );
  18635. }
  18636. this._mixBufferRegion = mixFunction;
  18637. this._mixBufferRegionAdditive = mixFunctionAdditive;
  18638. this._setIdentity = setIdentity;
  18639. this._origIndex = 3;
  18640. this._addIndex = 4;
  18641. this.cumulativeWeight = 0;
  18642. this.cumulativeWeightAdditive = 0;
  18643. this.useCount = 0;
  18644. this.referenceCount = 0;
  18645. }
  18646. // accumulate data in the 'incoming' region into 'accu<i>'
  18647. accumulate( accuIndex, weight ) {
  18648. // note: happily accumulating nothing when weight = 0, the caller knows
  18649. // the weight and shouldn't have made the call in the first place
  18650. const buffer = this.buffer,
  18651. stride = this.valueSize,
  18652. offset = accuIndex * stride + stride;
  18653. let currentWeight = this.cumulativeWeight;
  18654. if ( currentWeight === 0 ) {
  18655. // accuN := incoming * weight
  18656. for ( let i = 0; i !== stride; ++ i ) {
  18657. buffer[ offset + i ] = buffer[ i ];
  18658. }
  18659. currentWeight = weight;
  18660. } else {
  18661. // accuN := accuN + incoming * weight
  18662. currentWeight += weight;
  18663. const mix = weight / currentWeight;
  18664. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  18665. }
  18666. this.cumulativeWeight = currentWeight;
  18667. }
  18668. // accumulate data in the 'incoming' region into 'add'
  18669. accumulateAdditive( weight ) {
  18670. const buffer = this.buffer,
  18671. stride = this.valueSize,
  18672. offset = stride * this._addIndex;
  18673. if ( this.cumulativeWeightAdditive === 0 ) {
  18674. // add = identity
  18675. this._setIdentity();
  18676. }
  18677. // add := add + incoming * weight
  18678. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  18679. this.cumulativeWeightAdditive += weight;
  18680. }
  18681. // apply the state of 'accu<i>' to the binding when accus differ
  18682. apply( accuIndex ) {
  18683. const stride = this.valueSize,
  18684. buffer = this.buffer,
  18685. offset = accuIndex * stride + stride,
  18686. weight = this.cumulativeWeight,
  18687. weightAdditive = this.cumulativeWeightAdditive,
  18688. binding = this.binding;
  18689. this.cumulativeWeight = 0;
  18690. this.cumulativeWeightAdditive = 0;
  18691. if ( weight < 1 ) {
  18692. // accuN := accuN + original * ( 1 - cumulativeWeight )
  18693. const originalValueOffset = stride * this._origIndex;
  18694. this._mixBufferRegion(
  18695. buffer, offset, originalValueOffset, 1 - weight, stride );
  18696. }
  18697. if ( weightAdditive > 0 ) {
  18698. // accuN := accuN + additive accuN
  18699. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  18700. }
  18701. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  18702. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  18703. // value has changed -> update scene graph
  18704. binding.setValue( buffer, offset );
  18705. break;
  18706. }
  18707. }
  18708. }
  18709. // remember the state of the bound property and copy it to both accus
  18710. saveOriginalState() {
  18711. const binding = this.binding;
  18712. const buffer = this.buffer,
  18713. stride = this.valueSize,
  18714. originalValueOffset = stride * this._origIndex;
  18715. binding.getValue( buffer, originalValueOffset );
  18716. // accu[0..1] := orig -- initially detect changes against the original
  18717. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  18718. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  18719. }
  18720. // Add to identity for additive
  18721. this._setIdentity();
  18722. this.cumulativeWeight = 0;
  18723. this.cumulativeWeightAdditive = 0;
  18724. }
  18725. // apply the state previously taken via 'saveOriginalState' to the binding
  18726. restoreOriginalState() {
  18727. const originalValueOffset = this.valueSize * 3;
  18728. this.binding.setValue( this.buffer, originalValueOffset );
  18729. }
  18730. _setAdditiveIdentityNumeric() {
  18731. const startIndex = this._addIndex * this.valueSize;
  18732. const endIndex = startIndex + this.valueSize;
  18733. for ( let i = startIndex; i < endIndex; i ++ ) {
  18734. this.buffer[ i ] = 0;
  18735. }
  18736. }
  18737. _setAdditiveIdentityQuaternion() {
  18738. this._setAdditiveIdentityNumeric();
  18739. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  18740. }
  18741. _setAdditiveIdentityOther() {
  18742. const startIndex = this._origIndex * this.valueSize;
  18743. const targetIndex = this._addIndex * this.valueSize;
  18744. for ( let i = 0; i < this.valueSize; i ++ ) {
  18745. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  18746. }
  18747. }
  18748. // mix functions
  18749. _select( buffer, dstOffset, srcOffset, t, stride ) {
  18750. if ( t >= 0.5 ) {
  18751. for ( let i = 0; i !== stride; ++ i ) {
  18752. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  18753. }
  18754. }
  18755. }
  18756. _slerp( buffer, dstOffset, srcOffset, t ) {
  18757. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  18758. }
  18759. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18760. const workOffset = this._workIndex * stride;
  18761. // Store result in intermediate buffer offset
  18762. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  18763. // Slerp to the intermediate result
  18764. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  18765. }
  18766. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  18767. const s = 1 - t;
  18768. for ( let i = 0; i !== stride; ++ i ) {
  18769. const j = dstOffset + i;
  18770. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  18771. }
  18772. }
  18773. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18774. for ( let i = 0; i !== stride; ++ i ) {
  18775. const j = dstOffset + i;
  18776. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  18777. }
  18778. }
  18779. }
  18780. // Characters [].:/ are reserved for track binding syntax.
  18781. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  18782. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  18783. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  18784. // only latin characters, and the unicode \p{L} is not yet supported. So
  18785. // instead, we exclude reserved characters and match everything else.
  18786. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  18787. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  18788. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  18789. // be matched to parse the rest of the track name.
  18790. const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  18791. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  18792. const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  18793. // Object on target node, and accessor. May not contain reserved
  18794. // characters. Accessor may contain any character except closing bracket.
  18795. const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  18796. // Property and accessor. May not contain reserved characters. Accessor may
  18797. // contain any non-bracket characters.
  18798. const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  18799. const _trackRe = new RegExp( ''
  18800. + '^'
  18801. + _directoryRe
  18802. + _nodeRe
  18803. + _objectRe
  18804. + _propertyRe
  18805. + '$'
  18806. );
  18807. const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
  18808. class Composite {
  18809. constructor( targetGroup, path, optionalParsedPath ) {
  18810. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  18811. this._targetGroup = targetGroup;
  18812. this._bindings = targetGroup.subscribe_( path, parsedPath );
  18813. }
  18814. getValue( array, offset ) {
  18815. this.bind(); // bind all binding
  18816. const firstValidIndex = this._targetGroup.nCachedObjects_,
  18817. binding = this._bindings[ firstValidIndex ];
  18818. // and only call .getValue on the first
  18819. if ( binding !== undefined ) binding.getValue( array, offset );
  18820. }
  18821. setValue( array, offset ) {
  18822. const bindings = this._bindings;
  18823. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18824. bindings[ i ].setValue( array, offset );
  18825. }
  18826. }
  18827. bind() {
  18828. const bindings = this._bindings;
  18829. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18830. bindings[ i ].bind();
  18831. }
  18832. }
  18833. unbind() {
  18834. const bindings = this._bindings;
  18835. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18836. bindings[ i ].unbind();
  18837. }
  18838. }
  18839. }
  18840. // Note: This class uses a State pattern on a per-method basis:
  18841. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  18842. // prototype version of these methods with one that represents
  18843. // the bound state. When the property is not found, the methods
  18844. // become no-ops.
  18845. class PropertyBinding {
  18846. constructor( rootNode, path, parsedPath ) {
  18847. this.path = path;
  18848. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  18849. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
  18850. this.rootNode = rootNode;
  18851. // initial state of these methods that calls 'bind'
  18852. this.getValue = this._getValue_unbound;
  18853. this.setValue = this._setValue_unbound;
  18854. }
  18855. static create( root, path, parsedPath ) {
  18856. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  18857. return new PropertyBinding( root, path, parsedPath );
  18858. } else {
  18859. return new PropertyBinding.Composite( root, path, parsedPath );
  18860. }
  18861. }
  18862. /**
  18863. * Replaces spaces with underscores and removes unsupported characters from
  18864. * node names, to ensure compatibility with parseTrackName().
  18865. *
  18866. * @param {string} name Node name to be sanitized.
  18867. * @return {string}
  18868. */
  18869. static sanitizeNodeName( name ) {
  18870. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  18871. }
  18872. static parseTrackName( trackName ) {
  18873. const matches = _trackRe.exec( trackName );
  18874. if ( matches === null ) {
  18875. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  18876. }
  18877. const results = {
  18878. // directoryName: matches[ 1 ], // (tschw) currently unused
  18879. nodeName: matches[ 2 ],
  18880. objectName: matches[ 3 ],
  18881. objectIndex: matches[ 4 ],
  18882. propertyName: matches[ 5 ], // required
  18883. propertyIndex: matches[ 6 ]
  18884. };
  18885. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  18886. if ( lastDot !== undefined && lastDot !== - 1 ) {
  18887. const objectName = results.nodeName.substring( lastDot + 1 );
  18888. // Object names must be checked against an allowlist. Otherwise, there
  18889. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  18890. // 'bar' could be the objectName, or part of a nodeName (which can
  18891. // include '.' characters).
  18892. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  18893. results.nodeName = results.nodeName.substring( 0, lastDot );
  18894. results.objectName = objectName;
  18895. }
  18896. }
  18897. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  18898. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  18899. }
  18900. return results;
  18901. }
  18902. static findNode( root, nodeName ) {
  18903. if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  18904. return root;
  18905. }
  18906. // search into skeleton bones.
  18907. if ( root.skeleton ) {
  18908. const bone = root.skeleton.getBoneByName( nodeName );
  18909. if ( bone !== undefined ) {
  18910. return bone;
  18911. }
  18912. }
  18913. // search into node subtree.
  18914. if ( root.children ) {
  18915. const searchNodeSubtree = function ( children ) {
  18916. for ( let i = 0; i < children.length; i ++ ) {
  18917. const childNode = children[ i ];
  18918. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  18919. return childNode;
  18920. }
  18921. const result = searchNodeSubtree( childNode.children );
  18922. if ( result ) return result;
  18923. }
  18924. return null;
  18925. };
  18926. const subTreeNode = searchNodeSubtree( root.children );
  18927. if ( subTreeNode ) {
  18928. return subTreeNode;
  18929. }
  18930. }
  18931. return null;
  18932. }
  18933. // these are used to "bind" a nonexistent property
  18934. _getValue_unavailable() {}
  18935. _setValue_unavailable() {}
  18936. // Getters
  18937. _getValue_direct( buffer, offset ) {
  18938. buffer[ offset ] = this.targetObject[ this.propertyName ];
  18939. }
  18940. _getValue_array( buffer, offset ) {
  18941. const source = this.resolvedProperty;
  18942. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  18943. buffer[ offset ++ ] = source[ i ];
  18944. }
  18945. }
  18946. _getValue_arrayElement( buffer, offset ) {
  18947. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  18948. }
  18949. _getValue_toArray( buffer, offset ) {
  18950. this.resolvedProperty.toArray( buffer, offset );
  18951. }
  18952. // Direct
  18953. _setValue_direct( buffer, offset ) {
  18954. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18955. }
  18956. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  18957. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18958. this.targetObject.needsUpdate = true;
  18959. }
  18960. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18961. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18962. this.targetObject.matrixWorldNeedsUpdate = true;
  18963. }
  18964. // EntireArray
  18965. _setValue_array( buffer, offset ) {
  18966. const dest = this.resolvedProperty;
  18967. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18968. dest[ i ] = buffer[ offset ++ ];
  18969. }
  18970. }
  18971. _setValue_array_setNeedsUpdate( buffer, offset ) {
  18972. const dest = this.resolvedProperty;
  18973. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18974. dest[ i ] = buffer[ offset ++ ];
  18975. }
  18976. this.targetObject.needsUpdate = true;
  18977. }
  18978. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18979. const dest = this.resolvedProperty;
  18980. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18981. dest[ i ] = buffer[ offset ++ ];
  18982. }
  18983. this.targetObject.matrixWorldNeedsUpdate = true;
  18984. }
  18985. // ArrayElement
  18986. _setValue_arrayElement( buffer, offset ) {
  18987. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18988. }
  18989. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  18990. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18991. this.targetObject.needsUpdate = true;
  18992. }
  18993. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18994. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18995. this.targetObject.matrixWorldNeedsUpdate = true;
  18996. }
  18997. // HasToFromArray
  18998. _setValue_fromArray( buffer, offset ) {
  18999. this.resolvedProperty.fromArray( buffer, offset );
  19000. }
  19001. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  19002. this.resolvedProperty.fromArray( buffer, offset );
  19003. this.targetObject.needsUpdate = true;
  19004. }
  19005. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  19006. this.resolvedProperty.fromArray( buffer, offset );
  19007. this.targetObject.matrixWorldNeedsUpdate = true;
  19008. }
  19009. _getValue_unbound( targetArray, offset ) {
  19010. this.bind();
  19011. this.getValue( targetArray, offset );
  19012. }
  19013. _setValue_unbound( sourceArray, offset ) {
  19014. this.bind();
  19015. this.setValue( sourceArray, offset );
  19016. }
  19017. // create getter / setter pair for a property in the scene graph
  19018. bind() {
  19019. let targetObject = this.node;
  19020. const parsedPath = this.parsedPath;
  19021. const objectName = parsedPath.objectName;
  19022. const propertyName = parsedPath.propertyName;
  19023. let propertyIndex = parsedPath.propertyIndex;
  19024. if ( ! targetObject ) {
  19025. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
  19026. this.node = targetObject;
  19027. }
  19028. // set fail state so we can just 'return' on error
  19029. this.getValue = this._getValue_unavailable;
  19030. this.setValue = this._setValue_unavailable;
  19031. // ensure there is a value node
  19032. if ( ! targetObject ) {
  19033. console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
  19034. return;
  19035. }
  19036. if ( objectName ) {
  19037. let objectIndex = parsedPath.objectIndex;
  19038. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  19039. switch ( objectName ) {
  19040. case 'materials':
  19041. if ( ! targetObject.material ) {
  19042. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19043. return;
  19044. }
  19045. if ( ! targetObject.material.materials ) {
  19046. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  19047. return;
  19048. }
  19049. targetObject = targetObject.material.materials;
  19050. break;
  19051. case 'bones':
  19052. if ( ! targetObject.skeleton ) {
  19053. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  19054. return;
  19055. }
  19056. // potential future optimization: skip this if propertyIndex is already an integer
  19057. // and convert the integer string to a true integer.
  19058. targetObject = targetObject.skeleton.bones;
  19059. // support resolving morphTarget names into indices.
  19060. for ( let i = 0; i < targetObject.length; i ++ ) {
  19061. if ( targetObject[ i ].name === objectIndex ) {
  19062. objectIndex = i;
  19063. break;
  19064. }
  19065. }
  19066. break;
  19067. case 'map':
  19068. if ( 'map' in targetObject ) {
  19069. targetObject = targetObject.map;
  19070. break;
  19071. }
  19072. if ( ! targetObject.material ) {
  19073. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19074. return;
  19075. }
  19076. if ( ! targetObject.material.map ) {
  19077. console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
  19078. return;
  19079. }
  19080. targetObject = targetObject.material.map;
  19081. break;
  19082. default:
  19083. if ( targetObject[ objectName ] === undefined ) {
  19084. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  19085. return;
  19086. }
  19087. targetObject = targetObject[ objectName ];
  19088. }
  19089. if ( objectIndex !== undefined ) {
  19090. if ( targetObject[ objectIndex ] === undefined ) {
  19091. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  19092. return;
  19093. }
  19094. targetObject = targetObject[ objectIndex ];
  19095. }
  19096. }
  19097. // resolve property
  19098. const nodeProperty = targetObject[ propertyName ];
  19099. if ( nodeProperty === undefined ) {
  19100. const nodeName = parsedPath.nodeName;
  19101. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  19102. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  19103. return;
  19104. }
  19105. // determine versioning scheme
  19106. let versioning = this.Versioning.None;
  19107. this.targetObject = targetObject;
  19108. if ( targetObject.isMaterial === true ) {
  19109. versioning = this.Versioning.NeedsUpdate;
  19110. } else if ( targetObject.isObject3D === true ) {
  19111. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  19112. }
  19113. // determine how the property gets bound
  19114. let bindingType = this.BindingType.Direct;
  19115. if ( propertyIndex !== undefined ) {
  19116. // access a sub element of the property array (only primitives are supported right now)
  19117. if ( propertyName === 'morphTargetInfluences' ) {
  19118. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  19119. // support resolving morphTarget names into indices.
  19120. if ( ! targetObject.geometry ) {
  19121. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  19122. return;
  19123. }
  19124. if ( ! targetObject.geometry.morphAttributes ) {
  19125. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  19126. return;
  19127. }
  19128. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  19129. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  19130. }
  19131. }
  19132. bindingType = this.BindingType.ArrayElement;
  19133. this.resolvedProperty = nodeProperty;
  19134. this.propertyIndex = propertyIndex;
  19135. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  19136. // must use copy for Object3D.Euler/Quaternion
  19137. bindingType = this.BindingType.HasFromToArray;
  19138. this.resolvedProperty = nodeProperty;
  19139. } else if ( Array.isArray( nodeProperty ) ) {
  19140. bindingType = this.BindingType.EntireArray;
  19141. this.resolvedProperty = nodeProperty;
  19142. } else {
  19143. this.propertyName = propertyName;
  19144. }
  19145. // select getter / setter
  19146. this.getValue = this.GetterByBindingType[ bindingType ];
  19147. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  19148. }
  19149. unbind() {
  19150. this.node = null;
  19151. // back to the prototype version of getValue / setValue
  19152. // note: avoiding to mutate the shape of 'this' via 'delete'
  19153. this.getValue = this._getValue_unbound;
  19154. this.setValue = this._setValue_unbound;
  19155. }
  19156. }
  19157. PropertyBinding.Composite = Composite;
  19158. PropertyBinding.prototype.BindingType = {
  19159. Direct: 0,
  19160. EntireArray: 1,
  19161. ArrayElement: 2,
  19162. HasFromToArray: 3
  19163. };
  19164. PropertyBinding.prototype.Versioning = {
  19165. None: 0,
  19166. NeedsUpdate: 1,
  19167. MatrixWorldNeedsUpdate: 2
  19168. };
  19169. PropertyBinding.prototype.GetterByBindingType = [
  19170. PropertyBinding.prototype._getValue_direct,
  19171. PropertyBinding.prototype._getValue_array,
  19172. PropertyBinding.prototype._getValue_arrayElement,
  19173. PropertyBinding.prototype._getValue_toArray,
  19174. ];
  19175. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  19176. [
  19177. // Direct
  19178. PropertyBinding.prototype._setValue_direct,
  19179. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  19180. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  19181. ], [
  19182. // EntireArray
  19183. PropertyBinding.prototype._setValue_array,
  19184. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  19185. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  19186. ], [
  19187. // ArrayElement
  19188. PropertyBinding.prototype._setValue_arrayElement,
  19189. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  19190. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  19191. ], [
  19192. // HasToFromArray
  19193. PropertyBinding.prototype._setValue_fromArray,
  19194. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  19195. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  19196. ]
  19197. ];
  19198. /**
  19199. *
  19200. * A group of objects that receives a shared animation state.
  19201. *
  19202. * Usage:
  19203. *
  19204. * - Add objects you would otherwise pass as 'root' to the
  19205. * constructor or the .clipAction method of AnimationMixer.
  19206. *
  19207. * - Instead pass this object as 'root'.
  19208. *
  19209. * - You can also add and remove objects later when the mixer
  19210. * is running.
  19211. *
  19212. * Note:
  19213. *
  19214. * Objects of this class appear as one object to the mixer,
  19215. * so cache control of the individual objects must be done
  19216. * on the group.
  19217. *
  19218. * Limitation:
  19219. *
  19220. * - The animated properties must be compatible among the
  19221. * all objects in the group.
  19222. *
  19223. * - A single property can either be controlled through a
  19224. * target group or directly, but not both.
  19225. */
  19226. class AnimationObjectGroup {
  19227. constructor() {
  19228. this.isAnimationObjectGroup = true;
  19229. this.uuid = generateUUID();
  19230. // cached objects followed by the active ones
  19231. this._objects = Array.prototype.slice.call( arguments );
  19232. this.nCachedObjects_ = 0; // threshold
  19233. // note: read by PropertyBinding.Composite
  19234. const indices = {};
  19235. this._indicesByUUID = indices; // for bookkeeping
  19236. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19237. indices[ arguments[ i ].uuid ] = i;
  19238. }
  19239. this._paths = []; // inside: string
  19240. this._parsedPaths = []; // inside: { we don't care, here }
  19241. this._bindings = []; // inside: Array< PropertyBinding >
  19242. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  19243. const scope = this;
  19244. this.stats = {
  19245. objects: {
  19246. get total() {
  19247. return scope._objects.length;
  19248. },
  19249. get inUse() {
  19250. return this.total - scope.nCachedObjects_;
  19251. }
  19252. },
  19253. get bindingsPerObject() {
  19254. return scope._bindings.length;
  19255. }
  19256. };
  19257. }
  19258. add() {
  19259. const objects = this._objects,
  19260. indicesByUUID = this._indicesByUUID,
  19261. paths = this._paths,
  19262. parsedPaths = this._parsedPaths,
  19263. bindings = this._bindings,
  19264. nBindings = bindings.length;
  19265. let knownObject = undefined,
  19266. nObjects = objects.length,
  19267. nCachedObjects = this.nCachedObjects_;
  19268. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19269. const object = arguments[ i ],
  19270. uuid = object.uuid;
  19271. let index = indicesByUUID[ uuid ];
  19272. if ( index === undefined ) {
  19273. // unknown object -> add it to the ACTIVE region
  19274. index = nObjects ++;
  19275. indicesByUUID[ uuid ] = index;
  19276. objects.push( object );
  19277. // accounting is done, now do the same for all bindings
  19278. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19279. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  19280. }
  19281. } else if ( index < nCachedObjects ) {
  19282. knownObject = objects[ index ];
  19283. // move existing object to the ACTIVE region
  19284. const firstActiveIndex = -- nCachedObjects,
  19285. lastCachedObject = objects[ firstActiveIndex ];
  19286. indicesByUUID[ lastCachedObject.uuid ] = index;
  19287. objects[ index ] = lastCachedObject;
  19288. indicesByUUID[ uuid ] = firstActiveIndex;
  19289. objects[ firstActiveIndex ] = object;
  19290. // accounting is done, now do the same for all bindings
  19291. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19292. const bindingsForPath = bindings[ j ],
  19293. lastCached = bindingsForPath[ firstActiveIndex ];
  19294. let binding = bindingsForPath[ index ];
  19295. bindingsForPath[ index ] = lastCached;
  19296. if ( binding === undefined ) {
  19297. // since we do not bother to create new bindings
  19298. // for objects that are cached, the binding may
  19299. // or may not exist
  19300. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  19301. }
  19302. bindingsForPath[ firstActiveIndex ] = binding;
  19303. }
  19304. } else if ( objects[ index ] !== knownObject ) {
  19305. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  19306. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  19307. } // else the object is already where we want it to be
  19308. } // for arguments
  19309. this.nCachedObjects_ = nCachedObjects;
  19310. }
  19311. remove() {
  19312. const objects = this._objects,
  19313. indicesByUUID = this._indicesByUUID,
  19314. bindings = this._bindings,
  19315. nBindings = bindings.length;
  19316. let nCachedObjects = this.nCachedObjects_;
  19317. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19318. const object = arguments[ i ],
  19319. uuid = object.uuid,
  19320. index = indicesByUUID[ uuid ];
  19321. if ( index !== undefined && index >= nCachedObjects ) {
  19322. // move existing object into the CACHED region
  19323. const lastCachedIndex = nCachedObjects ++,
  19324. firstActiveObject = objects[ lastCachedIndex ];
  19325. indicesByUUID[ firstActiveObject.uuid ] = index;
  19326. objects[ index ] = firstActiveObject;
  19327. indicesByUUID[ uuid ] = lastCachedIndex;
  19328. objects[ lastCachedIndex ] = object;
  19329. // accounting is done, now do the same for all bindings
  19330. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19331. const bindingsForPath = bindings[ j ],
  19332. firstActive = bindingsForPath[ lastCachedIndex ],
  19333. binding = bindingsForPath[ index ];
  19334. bindingsForPath[ index ] = firstActive;
  19335. bindingsForPath[ lastCachedIndex ] = binding;
  19336. }
  19337. }
  19338. } // for arguments
  19339. this.nCachedObjects_ = nCachedObjects;
  19340. }
  19341. // remove & forget
  19342. uncache() {
  19343. const objects = this._objects,
  19344. indicesByUUID = this._indicesByUUID,
  19345. bindings = this._bindings,
  19346. nBindings = bindings.length;
  19347. let nCachedObjects = this.nCachedObjects_,
  19348. nObjects = objects.length;
  19349. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19350. const object = arguments[ i ],
  19351. uuid = object.uuid,
  19352. index = indicesByUUID[ uuid ];
  19353. if ( index !== undefined ) {
  19354. delete indicesByUUID[ uuid ];
  19355. if ( index < nCachedObjects ) {
  19356. // object is cached, shrink the CACHED region
  19357. const firstActiveIndex = -- nCachedObjects,
  19358. lastCachedObject = objects[ firstActiveIndex ],
  19359. lastIndex = -- nObjects,
  19360. lastObject = objects[ lastIndex ];
  19361. // last cached object takes this object's place
  19362. indicesByUUID[ lastCachedObject.uuid ] = index;
  19363. objects[ index ] = lastCachedObject;
  19364. // last object goes to the activated slot and pop
  19365. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  19366. objects[ firstActiveIndex ] = lastObject;
  19367. objects.pop();
  19368. // accounting is done, now do the same for all bindings
  19369. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19370. const bindingsForPath = bindings[ j ],
  19371. lastCached = bindingsForPath[ firstActiveIndex ],
  19372. last = bindingsForPath[ lastIndex ];
  19373. bindingsForPath[ index ] = lastCached;
  19374. bindingsForPath[ firstActiveIndex ] = last;
  19375. bindingsForPath.pop();
  19376. }
  19377. } else {
  19378. // object is active, just swap with the last and pop
  19379. const lastIndex = -- nObjects,
  19380. lastObject = objects[ lastIndex ];
  19381. if ( lastIndex > 0 ) {
  19382. indicesByUUID[ lastObject.uuid ] = index;
  19383. }
  19384. objects[ index ] = lastObject;
  19385. objects.pop();
  19386. // accounting is done, now do the same for all bindings
  19387. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19388. const bindingsForPath = bindings[ j ];
  19389. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  19390. bindingsForPath.pop();
  19391. }
  19392. } // cached or active
  19393. } // if object is known
  19394. } // for arguments
  19395. this.nCachedObjects_ = nCachedObjects;
  19396. }
  19397. // Internal interface used by befriended PropertyBinding.Composite:
  19398. subscribe_( path, parsedPath ) {
  19399. // returns an array of bindings for the given path that is changed
  19400. // according to the contained objects in the group
  19401. const indicesByPath = this._bindingsIndicesByPath;
  19402. let index = indicesByPath[ path ];
  19403. const bindings = this._bindings;
  19404. if ( index !== undefined ) return bindings[ index ];
  19405. const paths = this._paths,
  19406. parsedPaths = this._parsedPaths,
  19407. objects = this._objects,
  19408. nObjects = objects.length,
  19409. nCachedObjects = this.nCachedObjects_,
  19410. bindingsForPath = new Array( nObjects );
  19411. index = bindings.length;
  19412. indicesByPath[ path ] = index;
  19413. paths.push( path );
  19414. parsedPaths.push( parsedPath );
  19415. bindings.push( bindingsForPath );
  19416. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  19417. const object = objects[ i ];
  19418. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  19419. }
  19420. return bindingsForPath;
  19421. }
  19422. unsubscribe_( path ) {
  19423. // tells the group to forget about a property path and no longer
  19424. // update the array previously obtained with 'subscribe_'
  19425. const indicesByPath = this._bindingsIndicesByPath,
  19426. index = indicesByPath[ path ];
  19427. if ( index !== undefined ) {
  19428. const paths = this._paths,
  19429. parsedPaths = this._parsedPaths,
  19430. bindings = this._bindings,
  19431. lastBindingsIndex = bindings.length - 1,
  19432. lastBindings = bindings[ lastBindingsIndex ],
  19433. lastBindingsPath = path[ lastBindingsIndex ];
  19434. indicesByPath[ lastBindingsPath ] = index;
  19435. bindings[ index ] = lastBindings;
  19436. bindings.pop();
  19437. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  19438. parsedPaths.pop();
  19439. paths[ index ] = paths[ lastBindingsIndex ];
  19440. paths.pop();
  19441. }
  19442. }
  19443. }
  19444. class AnimationAction {
  19445. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  19446. this._mixer = mixer;
  19447. this._clip = clip;
  19448. this._localRoot = localRoot;
  19449. this.blendMode = blendMode;
  19450. const tracks = clip.tracks,
  19451. nTracks = tracks.length,
  19452. interpolants = new Array( nTracks );
  19453. const interpolantSettings = {
  19454. endingStart: ZeroCurvatureEnding,
  19455. endingEnd: ZeroCurvatureEnding
  19456. };
  19457. for ( let i = 0; i !== nTracks; ++ i ) {
  19458. const interpolant = tracks[ i ].createInterpolant( null );
  19459. interpolants[ i ] = interpolant;
  19460. interpolant.settings = interpolantSettings;
  19461. }
  19462. this._interpolantSettings = interpolantSettings;
  19463. this._interpolants = interpolants; // bound by the mixer
  19464. // inside: PropertyMixer (managed by the mixer)
  19465. this._propertyBindings = new Array( nTracks );
  19466. this._cacheIndex = null; // for the memory manager
  19467. this._byClipCacheIndex = null; // for the memory manager
  19468. this._timeScaleInterpolant = null;
  19469. this._weightInterpolant = null;
  19470. this.loop = LoopRepeat;
  19471. this._loopCount = - 1;
  19472. // global mixer time when the action is to be started
  19473. // it's set back to 'null' upon start of the action
  19474. this._startTime = null;
  19475. // scaled local time of the action
  19476. // gets clamped or wrapped to 0..clip.duration according to loop
  19477. this.time = 0;
  19478. this.timeScale = 1;
  19479. this._effectiveTimeScale = 1;
  19480. this.weight = 1;
  19481. this._effectiveWeight = 1;
  19482. this.repetitions = Infinity; // no. of repetitions when looping
  19483. this.paused = false; // true -> zero effective time scale
  19484. this.enabled = true; // false -> zero effective weight
  19485. this.clampWhenFinished = false;// keep feeding the last frame?
  19486. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  19487. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  19488. }
  19489. // State & Scheduling
  19490. play() {
  19491. this._mixer._activateAction( this );
  19492. return this;
  19493. }
  19494. stop() {
  19495. this._mixer._deactivateAction( this );
  19496. return this.reset();
  19497. }
  19498. reset() {
  19499. this.paused = false;
  19500. this.enabled = true;
  19501. this.time = 0; // restart clip
  19502. this._loopCount = - 1;// forget previous loops
  19503. this._startTime = null;// forget scheduling
  19504. return this.stopFading().stopWarping();
  19505. }
  19506. isRunning() {
  19507. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  19508. this._startTime === null && this._mixer._isActiveAction( this );
  19509. }
  19510. // return true when play has been called
  19511. isScheduled() {
  19512. return this._mixer._isActiveAction( this );
  19513. }
  19514. startAt( time ) {
  19515. this._startTime = time;
  19516. return this;
  19517. }
  19518. setLoop( mode, repetitions ) {
  19519. this.loop = mode;
  19520. this.repetitions = repetitions;
  19521. return this;
  19522. }
  19523. // Weight
  19524. // set the weight stopping any scheduled fading
  19525. // although .enabled = false yields an effective weight of zero, this
  19526. // method does *not* change .enabled, because it would be confusing
  19527. setEffectiveWeight( weight ) {
  19528. this.weight = weight;
  19529. // note: same logic as when updated at runtime
  19530. this._effectiveWeight = this.enabled ? weight : 0;
  19531. return this.stopFading();
  19532. }
  19533. // return the weight considering fading and .enabled
  19534. getEffectiveWeight() {
  19535. return this._effectiveWeight;
  19536. }
  19537. fadeIn( duration ) {
  19538. return this._scheduleFading( duration, 0, 1 );
  19539. }
  19540. fadeOut( duration ) {
  19541. return this._scheduleFading( duration, 1, 0 );
  19542. }
  19543. crossFadeFrom( fadeOutAction, duration, warp ) {
  19544. fadeOutAction.fadeOut( duration );
  19545. this.fadeIn( duration );
  19546. if ( warp ) {
  19547. const fadeInDuration = this._clip.duration,
  19548. fadeOutDuration = fadeOutAction._clip.duration,
  19549. startEndRatio = fadeOutDuration / fadeInDuration,
  19550. endStartRatio = fadeInDuration / fadeOutDuration;
  19551. fadeOutAction.warp( 1.0, startEndRatio, duration );
  19552. this.warp( endStartRatio, 1.0, duration );
  19553. }
  19554. return this;
  19555. }
  19556. crossFadeTo( fadeInAction, duration, warp ) {
  19557. return fadeInAction.crossFadeFrom( this, duration, warp );
  19558. }
  19559. stopFading() {
  19560. const weightInterpolant = this._weightInterpolant;
  19561. if ( weightInterpolant !== null ) {
  19562. this._weightInterpolant = null;
  19563. this._mixer._takeBackControlInterpolant( weightInterpolant );
  19564. }
  19565. return this;
  19566. }
  19567. // Time Scale Control
  19568. // set the time scale stopping any scheduled warping
  19569. // although .paused = true yields an effective time scale of zero, this
  19570. // method does *not* change .paused, because it would be confusing
  19571. setEffectiveTimeScale( timeScale ) {
  19572. this.timeScale = timeScale;
  19573. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  19574. return this.stopWarping();
  19575. }
  19576. // return the time scale considering warping and .paused
  19577. getEffectiveTimeScale() {
  19578. return this._effectiveTimeScale;
  19579. }
  19580. setDuration( duration ) {
  19581. this.timeScale = this._clip.duration / duration;
  19582. return this.stopWarping();
  19583. }
  19584. syncWith( action ) {
  19585. this.time = action.time;
  19586. this.timeScale = action.timeScale;
  19587. return this.stopWarping();
  19588. }
  19589. halt( duration ) {
  19590. return this.warp( this._effectiveTimeScale, 0, duration );
  19591. }
  19592. warp( startTimeScale, endTimeScale, duration ) {
  19593. const mixer = this._mixer,
  19594. now = mixer.time,
  19595. timeScale = this.timeScale;
  19596. let interpolant = this._timeScaleInterpolant;
  19597. if ( interpolant === null ) {
  19598. interpolant = mixer._lendControlInterpolant();
  19599. this._timeScaleInterpolant = interpolant;
  19600. }
  19601. const times = interpolant.parameterPositions,
  19602. values = interpolant.sampleValues;
  19603. times[ 0 ] = now;
  19604. times[ 1 ] = now + duration;
  19605. values[ 0 ] = startTimeScale / timeScale;
  19606. values[ 1 ] = endTimeScale / timeScale;
  19607. return this;
  19608. }
  19609. stopWarping() {
  19610. const timeScaleInterpolant = this._timeScaleInterpolant;
  19611. if ( timeScaleInterpolant !== null ) {
  19612. this._timeScaleInterpolant = null;
  19613. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  19614. }
  19615. return this;
  19616. }
  19617. // Object Accessors
  19618. getMixer() {
  19619. return this._mixer;
  19620. }
  19621. getClip() {
  19622. return this._clip;
  19623. }
  19624. getRoot() {
  19625. return this._localRoot || this._mixer._root;
  19626. }
  19627. // Interna
  19628. _update( time, deltaTime, timeDirection, accuIndex ) {
  19629. // called by the mixer
  19630. if ( ! this.enabled ) {
  19631. // call ._updateWeight() to update ._effectiveWeight
  19632. this._updateWeight( time );
  19633. return;
  19634. }
  19635. const startTime = this._startTime;
  19636. if ( startTime !== null ) {
  19637. // check for scheduled start of action
  19638. const timeRunning = ( time - startTime ) * timeDirection;
  19639. if ( timeRunning < 0 || timeDirection === 0 ) {
  19640. deltaTime = 0;
  19641. } else {
  19642. this._startTime = null; // unschedule
  19643. deltaTime = timeDirection * timeRunning;
  19644. }
  19645. }
  19646. // apply time scale and advance time
  19647. deltaTime *= this._updateTimeScale( time );
  19648. const clipTime = this._updateTime( deltaTime );
  19649. // note: _updateTime may disable the action resulting in
  19650. // an effective weight of 0
  19651. const weight = this._updateWeight( time );
  19652. if ( weight > 0 ) {
  19653. const interpolants = this._interpolants;
  19654. const propertyMixers = this._propertyBindings;
  19655. switch ( this.blendMode ) {
  19656. case AdditiveAnimationBlendMode:
  19657. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19658. interpolants[ j ].evaluate( clipTime );
  19659. propertyMixers[ j ].accumulateAdditive( weight );
  19660. }
  19661. break;
  19662. case NormalAnimationBlendMode:
  19663. default:
  19664. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19665. interpolants[ j ].evaluate( clipTime );
  19666. propertyMixers[ j ].accumulate( accuIndex, weight );
  19667. }
  19668. }
  19669. }
  19670. }
  19671. _updateWeight( time ) {
  19672. let weight = 0;
  19673. if ( this.enabled ) {
  19674. weight = this.weight;
  19675. const interpolant = this._weightInterpolant;
  19676. if ( interpolant !== null ) {
  19677. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19678. weight *= interpolantValue;
  19679. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19680. this.stopFading();
  19681. if ( interpolantValue === 0 ) {
  19682. // faded out, disable
  19683. this.enabled = false;
  19684. }
  19685. }
  19686. }
  19687. }
  19688. this._effectiveWeight = weight;
  19689. return weight;
  19690. }
  19691. _updateTimeScale( time ) {
  19692. let timeScale = 0;
  19693. if ( ! this.paused ) {
  19694. timeScale = this.timeScale;
  19695. const interpolant = this._timeScaleInterpolant;
  19696. if ( interpolant !== null ) {
  19697. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19698. timeScale *= interpolantValue;
  19699. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19700. this.stopWarping();
  19701. if ( timeScale === 0 ) {
  19702. // motion has halted, pause
  19703. this.paused = true;
  19704. } else {
  19705. // warp done - apply final time scale
  19706. this.timeScale = timeScale;
  19707. }
  19708. }
  19709. }
  19710. }
  19711. this._effectiveTimeScale = timeScale;
  19712. return timeScale;
  19713. }
  19714. _updateTime( deltaTime ) {
  19715. const duration = this._clip.duration;
  19716. const loop = this.loop;
  19717. let time = this.time + deltaTime;
  19718. let loopCount = this._loopCount;
  19719. const pingPong = ( loop === LoopPingPong );
  19720. if ( deltaTime === 0 ) {
  19721. if ( loopCount === - 1 ) return time;
  19722. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  19723. }
  19724. if ( loop === LoopOnce ) {
  19725. if ( loopCount === - 1 ) {
  19726. // just started
  19727. this._loopCount = 0;
  19728. this._setEndings( true, true, false );
  19729. }
  19730. handle_stop: {
  19731. if ( time >= duration ) {
  19732. time = duration;
  19733. } else if ( time < 0 ) {
  19734. time = 0;
  19735. } else {
  19736. this.time = time;
  19737. break handle_stop;
  19738. }
  19739. if ( this.clampWhenFinished ) this.paused = true;
  19740. else this.enabled = false;
  19741. this.time = time;
  19742. this._mixer.dispatchEvent( {
  19743. type: 'finished', action: this,
  19744. direction: deltaTime < 0 ? - 1 : 1
  19745. } );
  19746. }
  19747. } else { // repetitive Repeat or PingPong
  19748. if ( loopCount === - 1 ) {
  19749. // just started
  19750. if ( deltaTime >= 0 ) {
  19751. loopCount = 0;
  19752. this._setEndings( true, this.repetitions === 0, pingPong );
  19753. } else {
  19754. // when looping in reverse direction, the initial
  19755. // transition through zero counts as a repetition,
  19756. // so leave loopCount at -1
  19757. this._setEndings( this.repetitions === 0, true, pingPong );
  19758. }
  19759. }
  19760. if ( time >= duration || time < 0 ) {
  19761. // wrap around
  19762. const loopDelta = Math.floor( time / duration ); // signed
  19763. time -= duration * loopDelta;
  19764. loopCount += Math.abs( loopDelta );
  19765. const pending = this.repetitions - loopCount;
  19766. if ( pending <= 0 ) {
  19767. // have to stop (switch state, clamp time, fire event)
  19768. if ( this.clampWhenFinished ) this.paused = true;
  19769. else this.enabled = false;
  19770. time = deltaTime > 0 ? duration : 0;
  19771. this.time = time;
  19772. this._mixer.dispatchEvent( {
  19773. type: 'finished', action: this,
  19774. direction: deltaTime > 0 ? 1 : - 1
  19775. } );
  19776. } else {
  19777. // keep running
  19778. if ( pending === 1 ) {
  19779. // entering the last round
  19780. const atStart = deltaTime < 0;
  19781. this._setEndings( atStart, ! atStart, pingPong );
  19782. } else {
  19783. this._setEndings( false, false, pingPong );
  19784. }
  19785. this._loopCount = loopCount;
  19786. this.time = time;
  19787. this._mixer.dispatchEvent( {
  19788. type: 'loop', action: this, loopDelta: loopDelta
  19789. } );
  19790. }
  19791. } else {
  19792. this.time = time;
  19793. }
  19794. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  19795. // invert time for the "pong round"
  19796. return duration - time;
  19797. }
  19798. }
  19799. return time;
  19800. }
  19801. _setEndings( atStart, atEnd, pingPong ) {
  19802. const settings = this._interpolantSettings;
  19803. if ( pingPong ) {
  19804. settings.endingStart = ZeroSlopeEnding;
  19805. settings.endingEnd = ZeroSlopeEnding;
  19806. } else {
  19807. // assuming for LoopOnce atStart == atEnd == true
  19808. if ( atStart ) {
  19809. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19810. } else {
  19811. settings.endingStart = WrapAroundEnding;
  19812. }
  19813. if ( atEnd ) {
  19814. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19815. } else {
  19816. settings.endingEnd = WrapAroundEnding;
  19817. }
  19818. }
  19819. }
  19820. _scheduleFading( duration, weightNow, weightThen ) {
  19821. const mixer = this._mixer, now = mixer.time;
  19822. let interpolant = this._weightInterpolant;
  19823. if ( interpolant === null ) {
  19824. interpolant = mixer._lendControlInterpolant();
  19825. this._weightInterpolant = interpolant;
  19826. }
  19827. const times = interpolant.parameterPositions,
  19828. values = interpolant.sampleValues;
  19829. times[ 0 ] = now;
  19830. values[ 0 ] = weightNow;
  19831. times[ 1 ] = now + duration;
  19832. values[ 1 ] = weightThen;
  19833. return this;
  19834. }
  19835. }
  19836. const _controlInterpolantsResultBuffer = new Float32Array( 1 );
  19837. class AnimationMixer extends EventDispatcher {
  19838. constructor( root ) {
  19839. super();
  19840. this._root = root;
  19841. this._initMemoryManager();
  19842. this._accuIndex = 0;
  19843. this.time = 0;
  19844. this.timeScale = 1.0;
  19845. }
  19846. _bindAction( action, prototypeAction ) {
  19847. const root = action._localRoot || this._root,
  19848. tracks = action._clip.tracks,
  19849. nTracks = tracks.length,
  19850. bindings = action._propertyBindings,
  19851. interpolants = action._interpolants,
  19852. rootUuid = root.uuid,
  19853. bindingsByRoot = this._bindingsByRootAndName;
  19854. let bindingsByName = bindingsByRoot[ rootUuid ];
  19855. if ( bindingsByName === undefined ) {
  19856. bindingsByName = {};
  19857. bindingsByRoot[ rootUuid ] = bindingsByName;
  19858. }
  19859. for ( let i = 0; i !== nTracks; ++ i ) {
  19860. const track = tracks[ i ],
  19861. trackName = track.name;
  19862. let binding = bindingsByName[ trackName ];
  19863. if ( binding !== undefined ) {
  19864. ++ binding.referenceCount;
  19865. bindings[ i ] = binding;
  19866. } else {
  19867. binding = bindings[ i ];
  19868. if ( binding !== undefined ) {
  19869. // existing binding, make sure the cache knows
  19870. if ( binding._cacheIndex === null ) {
  19871. ++ binding.referenceCount;
  19872. this._addInactiveBinding( binding, rootUuid, trackName );
  19873. }
  19874. continue;
  19875. }
  19876. const path = prototypeAction && prototypeAction.
  19877. _propertyBindings[ i ].binding.parsedPath;
  19878. binding = new PropertyMixer(
  19879. PropertyBinding.create( root, trackName, path ),
  19880. track.ValueTypeName, track.getValueSize() );
  19881. ++ binding.referenceCount;
  19882. this._addInactiveBinding( binding, rootUuid, trackName );
  19883. bindings[ i ] = binding;
  19884. }
  19885. interpolants[ i ].resultBuffer = binding.buffer;
  19886. }
  19887. }
  19888. _activateAction( action ) {
  19889. if ( ! this._isActiveAction( action ) ) {
  19890. if ( action._cacheIndex === null ) {
  19891. // this action has been forgotten by the cache, but the user
  19892. // appears to be still using it -> rebind
  19893. const rootUuid = ( action._localRoot || this._root ).uuid,
  19894. clipUuid = action._clip.uuid,
  19895. actionsForClip = this._actionsByClip[ clipUuid ];
  19896. this._bindAction( action,
  19897. actionsForClip && actionsForClip.knownActions[ 0 ] );
  19898. this._addInactiveAction( action, clipUuid, rootUuid );
  19899. }
  19900. const bindings = action._propertyBindings;
  19901. // increment reference counts / sort out state
  19902. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19903. const binding = bindings[ i ];
  19904. if ( binding.useCount ++ === 0 ) {
  19905. this._lendBinding( binding );
  19906. binding.saveOriginalState();
  19907. }
  19908. }
  19909. this._lendAction( action );
  19910. }
  19911. }
  19912. _deactivateAction( action ) {
  19913. if ( this._isActiveAction( action ) ) {
  19914. const bindings = action._propertyBindings;
  19915. // decrement reference counts / sort out state
  19916. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19917. const binding = bindings[ i ];
  19918. if ( -- binding.useCount === 0 ) {
  19919. binding.restoreOriginalState();
  19920. this._takeBackBinding( binding );
  19921. }
  19922. }
  19923. this._takeBackAction( action );
  19924. }
  19925. }
  19926. // Memory manager
  19927. _initMemoryManager() {
  19928. this._actions = []; // 'nActiveActions' followed by inactive ones
  19929. this._nActiveActions = 0;
  19930. this._actionsByClip = {};
  19931. // inside:
  19932. // {
  19933. // knownActions: Array< AnimationAction > - used as prototypes
  19934. // actionByRoot: AnimationAction - lookup
  19935. // }
  19936. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  19937. this._nActiveBindings = 0;
  19938. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  19939. this._controlInterpolants = []; // same game as above
  19940. this._nActiveControlInterpolants = 0;
  19941. const scope = this;
  19942. this.stats = {
  19943. actions: {
  19944. get total() {
  19945. return scope._actions.length;
  19946. },
  19947. get inUse() {
  19948. return scope._nActiveActions;
  19949. }
  19950. },
  19951. bindings: {
  19952. get total() {
  19953. return scope._bindings.length;
  19954. },
  19955. get inUse() {
  19956. return scope._nActiveBindings;
  19957. }
  19958. },
  19959. controlInterpolants: {
  19960. get total() {
  19961. return scope._controlInterpolants.length;
  19962. },
  19963. get inUse() {
  19964. return scope._nActiveControlInterpolants;
  19965. }
  19966. }
  19967. };
  19968. }
  19969. // Memory management for AnimationAction objects
  19970. _isActiveAction( action ) {
  19971. const index = action._cacheIndex;
  19972. return index !== null && index < this._nActiveActions;
  19973. }
  19974. _addInactiveAction( action, clipUuid, rootUuid ) {
  19975. const actions = this._actions,
  19976. actionsByClip = this._actionsByClip;
  19977. let actionsForClip = actionsByClip[ clipUuid ];
  19978. if ( actionsForClip === undefined ) {
  19979. actionsForClip = {
  19980. knownActions: [ action ],
  19981. actionByRoot: {}
  19982. };
  19983. action._byClipCacheIndex = 0;
  19984. actionsByClip[ clipUuid ] = actionsForClip;
  19985. } else {
  19986. const knownActions = actionsForClip.knownActions;
  19987. action._byClipCacheIndex = knownActions.length;
  19988. knownActions.push( action );
  19989. }
  19990. action._cacheIndex = actions.length;
  19991. actions.push( action );
  19992. actionsForClip.actionByRoot[ rootUuid ] = action;
  19993. }
  19994. _removeInactiveAction( action ) {
  19995. const actions = this._actions,
  19996. lastInactiveAction = actions[ actions.length - 1 ],
  19997. cacheIndex = action._cacheIndex;
  19998. lastInactiveAction._cacheIndex = cacheIndex;
  19999. actions[ cacheIndex ] = lastInactiveAction;
  20000. actions.pop();
  20001. action._cacheIndex = null;
  20002. const clipUuid = action._clip.uuid,
  20003. actionsByClip = this._actionsByClip,
  20004. actionsForClip = actionsByClip[ clipUuid ],
  20005. knownActionsForClip = actionsForClip.knownActions,
  20006. lastKnownAction =
  20007. knownActionsForClip[ knownActionsForClip.length - 1 ],
  20008. byClipCacheIndex = action._byClipCacheIndex;
  20009. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  20010. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  20011. knownActionsForClip.pop();
  20012. action._byClipCacheIndex = null;
  20013. const actionByRoot = actionsForClip.actionByRoot,
  20014. rootUuid = ( action._localRoot || this._root ).uuid;
  20015. delete actionByRoot[ rootUuid ];
  20016. if ( knownActionsForClip.length === 0 ) {
  20017. delete actionsByClip[ clipUuid ];
  20018. }
  20019. this._removeInactiveBindingsForAction( action );
  20020. }
  20021. _removeInactiveBindingsForAction( action ) {
  20022. const bindings = action._propertyBindings;
  20023. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  20024. const binding = bindings[ i ];
  20025. if ( -- binding.referenceCount === 0 ) {
  20026. this._removeInactiveBinding( binding );
  20027. }
  20028. }
  20029. }
  20030. _lendAction( action ) {
  20031. // [ active actions | inactive actions ]
  20032. // [ active actions >| inactive actions ]
  20033. // s a
  20034. // <-swap->
  20035. // a s
  20036. const actions = this._actions,
  20037. prevIndex = action._cacheIndex,
  20038. lastActiveIndex = this._nActiveActions ++,
  20039. firstInactiveAction = actions[ lastActiveIndex ];
  20040. action._cacheIndex = lastActiveIndex;
  20041. actions[ lastActiveIndex ] = action;
  20042. firstInactiveAction._cacheIndex = prevIndex;
  20043. actions[ prevIndex ] = firstInactiveAction;
  20044. }
  20045. _takeBackAction( action ) {
  20046. // [ active actions | inactive actions ]
  20047. // [ active actions |< inactive actions ]
  20048. // a s
  20049. // <-swap->
  20050. // s a
  20051. const actions = this._actions,
  20052. prevIndex = action._cacheIndex,
  20053. firstInactiveIndex = -- this._nActiveActions,
  20054. lastActiveAction = actions[ firstInactiveIndex ];
  20055. action._cacheIndex = firstInactiveIndex;
  20056. actions[ firstInactiveIndex ] = action;
  20057. lastActiveAction._cacheIndex = prevIndex;
  20058. actions[ prevIndex ] = lastActiveAction;
  20059. }
  20060. // Memory management for PropertyMixer objects
  20061. _addInactiveBinding( binding, rootUuid, trackName ) {
  20062. const bindingsByRoot = this._bindingsByRootAndName,
  20063. bindings = this._bindings;
  20064. let bindingByName = bindingsByRoot[ rootUuid ];
  20065. if ( bindingByName === undefined ) {
  20066. bindingByName = {};
  20067. bindingsByRoot[ rootUuid ] = bindingByName;
  20068. }
  20069. bindingByName[ trackName ] = binding;
  20070. binding._cacheIndex = bindings.length;
  20071. bindings.push( binding );
  20072. }
  20073. _removeInactiveBinding( binding ) {
  20074. const bindings = this._bindings,
  20075. propBinding = binding.binding,
  20076. rootUuid = propBinding.rootNode.uuid,
  20077. trackName = propBinding.path,
  20078. bindingsByRoot = this._bindingsByRootAndName,
  20079. bindingByName = bindingsByRoot[ rootUuid ],
  20080. lastInactiveBinding = bindings[ bindings.length - 1 ],
  20081. cacheIndex = binding._cacheIndex;
  20082. lastInactiveBinding._cacheIndex = cacheIndex;
  20083. bindings[ cacheIndex ] = lastInactiveBinding;
  20084. bindings.pop();
  20085. delete bindingByName[ trackName ];
  20086. if ( Object.keys( bindingByName ).length === 0 ) {
  20087. delete bindingsByRoot[ rootUuid ];
  20088. }
  20089. }
  20090. _lendBinding( binding ) {
  20091. const bindings = this._bindings,
  20092. prevIndex = binding._cacheIndex,
  20093. lastActiveIndex = this._nActiveBindings ++,
  20094. firstInactiveBinding = bindings[ lastActiveIndex ];
  20095. binding._cacheIndex = lastActiveIndex;
  20096. bindings[ lastActiveIndex ] = binding;
  20097. firstInactiveBinding._cacheIndex = prevIndex;
  20098. bindings[ prevIndex ] = firstInactiveBinding;
  20099. }
  20100. _takeBackBinding( binding ) {
  20101. const bindings = this._bindings,
  20102. prevIndex = binding._cacheIndex,
  20103. firstInactiveIndex = -- this._nActiveBindings,
  20104. lastActiveBinding = bindings[ firstInactiveIndex ];
  20105. binding._cacheIndex = firstInactiveIndex;
  20106. bindings[ firstInactiveIndex ] = binding;
  20107. lastActiveBinding._cacheIndex = prevIndex;
  20108. bindings[ prevIndex ] = lastActiveBinding;
  20109. }
  20110. // Memory management of Interpolants for weight and time scale
  20111. _lendControlInterpolant() {
  20112. const interpolants = this._controlInterpolants,
  20113. lastActiveIndex = this._nActiveControlInterpolants ++;
  20114. let interpolant = interpolants[ lastActiveIndex ];
  20115. if ( interpolant === undefined ) {
  20116. interpolant = new LinearInterpolant(
  20117. new Float32Array( 2 ), new Float32Array( 2 ),
  20118. 1, _controlInterpolantsResultBuffer );
  20119. interpolant.__cacheIndex = lastActiveIndex;
  20120. interpolants[ lastActiveIndex ] = interpolant;
  20121. }
  20122. return interpolant;
  20123. }
  20124. _takeBackControlInterpolant( interpolant ) {
  20125. const interpolants = this._controlInterpolants,
  20126. prevIndex = interpolant.__cacheIndex,
  20127. firstInactiveIndex = -- this._nActiveControlInterpolants,
  20128. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  20129. interpolant.__cacheIndex = firstInactiveIndex;
  20130. interpolants[ firstInactiveIndex ] = interpolant;
  20131. lastActiveInterpolant.__cacheIndex = prevIndex;
  20132. interpolants[ prevIndex ] = lastActiveInterpolant;
  20133. }
  20134. // return an action for a clip optionally using a custom root target
  20135. // object (this method allocates a lot of dynamic memory in case a
  20136. // previously unknown clip/root combination is specified)
  20137. clipAction( clip, optionalRoot, blendMode ) {
  20138. const root = optionalRoot || this._root,
  20139. rootUuid = root.uuid;
  20140. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  20141. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  20142. const actionsForClip = this._actionsByClip[ clipUuid ];
  20143. let prototypeAction = null;
  20144. if ( blendMode === undefined ) {
  20145. if ( clipObject !== null ) {
  20146. blendMode = clipObject.blendMode;
  20147. } else {
  20148. blendMode = NormalAnimationBlendMode;
  20149. }
  20150. }
  20151. if ( actionsForClip !== undefined ) {
  20152. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  20153. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  20154. return existingAction;
  20155. }
  20156. // we know the clip, so we don't have to parse all
  20157. // the bindings again but can just copy
  20158. prototypeAction = actionsForClip.knownActions[ 0 ];
  20159. // also, take the clip from the prototype action
  20160. if ( clipObject === null )
  20161. clipObject = prototypeAction._clip;
  20162. }
  20163. // clip must be known when specified via string
  20164. if ( clipObject === null ) return null;
  20165. // allocate all resources required to run it
  20166. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  20167. this._bindAction( newAction, prototypeAction );
  20168. // and make the action known to the memory manager
  20169. this._addInactiveAction( newAction, clipUuid, rootUuid );
  20170. return newAction;
  20171. }
  20172. // get an existing action
  20173. existingAction( clip, optionalRoot ) {
  20174. const root = optionalRoot || this._root,
  20175. rootUuid = root.uuid,
  20176. clipObject = typeof clip === 'string' ?
  20177. AnimationClip.findByName( root, clip ) : clip,
  20178. clipUuid = clipObject ? clipObject.uuid : clip,
  20179. actionsForClip = this._actionsByClip[ clipUuid ];
  20180. if ( actionsForClip !== undefined ) {
  20181. return actionsForClip.actionByRoot[ rootUuid ] || null;
  20182. }
  20183. return null;
  20184. }
  20185. // deactivates all previously scheduled actions
  20186. stopAllAction() {
  20187. const actions = this._actions,
  20188. nActions = this._nActiveActions;
  20189. for ( let i = nActions - 1; i >= 0; -- i ) {
  20190. actions[ i ].stop();
  20191. }
  20192. return this;
  20193. }
  20194. // advance the time and update apply the animation
  20195. update( deltaTime ) {
  20196. deltaTime *= this.timeScale;
  20197. const actions = this._actions,
  20198. nActions = this._nActiveActions,
  20199. time = this.time += deltaTime,
  20200. timeDirection = Math.sign( deltaTime ),
  20201. accuIndex = this._accuIndex ^= 1;
  20202. // run active actions
  20203. for ( let i = 0; i !== nActions; ++ i ) {
  20204. const action = actions[ i ];
  20205. action._update( time, deltaTime, timeDirection, accuIndex );
  20206. }
  20207. // update scene graph
  20208. const bindings = this._bindings,
  20209. nBindings = this._nActiveBindings;
  20210. for ( let i = 0; i !== nBindings; ++ i ) {
  20211. bindings[ i ].apply( accuIndex );
  20212. }
  20213. return this;
  20214. }
  20215. // Allows you to seek to a specific time in an animation.
  20216. setTime( timeInSeconds ) {
  20217. this.time = 0; // Zero out time attribute for AnimationMixer object;
  20218. for ( let i = 0; i < this._actions.length; i ++ ) {
  20219. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  20220. }
  20221. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  20222. }
  20223. // return this mixer's root target object
  20224. getRoot() {
  20225. return this._root;
  20226. }
  20227. // free all resources specific to a particular clip
  20228. uncacheClip( clip ) {
  20229. const actions = this._actions,
  20230. clipUuid = clip.uuid,
  20231. actionsByClip = this._actionsByClip,
  20232. actionsForClip = actionsByClip[ clipUuid ];
  20233. if ( actionsForClip !== undefined ) {
  20234. // note: just calling _removeInactiveAction would mess up the
  20235. // iteration state and also require updating the state we can
  20236. // just throw away
  20237. const actionsToRemove = actionsForClip.knownActions;
  20238. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  20239. const action = actionsToRemove[ i ];
  20240. this._deactivateAction( action );
  20241. const cacheIndex = action._cacheIndex,
  20242. lastInactiveAction = actions[ actions.length - 1 ];
  20243. action._cacheIndex = null;
  20244. action._byClipCacheIndex = null;
  20245. lastInactiveAction._cacheIndex = cacheIndex;
  20246. actions[ cacheIndex ] = lastInactiveAction;
  20247. actions.pop();
  20248. this._removeInactiveBindingsForAction( action );
  20249. }
  20250. delete actionsByClip[ clipUuid ];
  20251. }
  20252. }
  20253. // free all resources specific to a particular root target object
  20254. uncacheRoot( root ) {
  20255. const rootUuid = root.uuid,
  20256. actionsByClip = this._actionsByClip;
  20257. for ( const clipUuid in actionsByClip ) {
  20258. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  20259. action = actionByRoot[ rootUuid ];
  20260. if ( action !== undefined ) {
  20261. this._deactivateAction( action );
  20262. this._removeInactiveAction( action );
  20263. }
  20264. }
  20265. const bindingsByRoot = this._bindingsByRootAndName,
  20266. bindingByName = bindingsByRoot[ rootUuid ];
  20267. if ( bindingByName !== undefined ) {
  20268. for ( const trackName in bindingByName ) {
  20269. const binding = bindingByName[ trackName ];
  20270. binding.restoreOriginalState();
  20271. this._removeInactiveBinding( binding );
  20272. }
  20273. }
  20274. }
  20275. // remove a targeted clip from the cache
  20276. uncacheAction( clip, optionalRoot ) {
  20277. const action = this.existingAction( clip, optionalRoot );
  20278. if ( action !== null ) {
  20279. this._deactivateAction( action );
  20280. this._removeInactiveAction( action );
  20281. }
  20282. }
  20283. }
  20284. class RenderTarget3D extends RenderTarget {
  20285. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  20286. super( width, height, options );
  20287. this.isRenderTarget3D = true;
  20288. this.depth = depth;
  20289. this.texture = new Data3DTexture( null, width, height, depth );
  20290. this.texture.isRenderTargetTexture = true;
  20291. }
  20292. }
  20293. class RenderTargetArray extends RenderTarget {
  20294. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  20295. super( width, height, options );
  20296. this.isRenderTargetArray = true;
  20297. this.depth = depth;
  20298. this.texture = new DataArrayTexture( null, width, height, depth );
  20299. this.texture.isRenderTargetTexture = true;
  20300. }
  20301. }
  20302. class Uniform {
  20303. constructor( value ) {
  20304. this.value = value;
  20305. }
  20306. clone() {
  20307. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  20308. }
  20309. }
  20310. let _id = 0;
  20311. class UniformsGroup extends EventDispatcher {
  20312. constructor() {
  20313. super();
  20314. this.isUniformsGroup = true;
  20315. Object.defineProperty( this, 'id', { value: _id ++ } );
  20316. this.name = '';
  20317. this.usage = StaticDrawUsage;
  20318. this.uniforms = [];
  20319. }
  20320. add( uniform ) {
  20321. this.uniforms.push( uniform );
  20322. return this;
  20323. }
  20324. remove( uniform ) {
  20325. const index = this.uniforms.indexOf( uniform );
  20326. if ( index !== - 1 ) this.uniforms.splice( index, 1 );
  20327. return this;
  20328. }
  20329. setName( name ) {
  20330. this.name = name;
  20331. return this;
  20332. }
  20333. setUsage( value ) {
  20334. this.usage = value;
  20335. return this;
  20336. }
  20337. dispose() {
  20338. this.dispatchEvent( { type: 'dispose' } );
  20339. return this;
  20340. }
  20341. copy( source ) {
  20342. this.name = source.name;
  20343. this.usage = source.usage;
  20344. const uniformsSource = source.uniforms;
  20345. this.uniforms.length = 0;
  20346. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  20347. const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
  20348. for ( let j = 0; j < uniforms.length; j ++ ) {
  20349. this.uniforms.push( uniforms[ j ].clone() );
  20350. }
  20351. }
  20352. return this;
  20353. }
  20354. clone() {
  20355. return new this.constructor().copy( this );
  20356. }
  20357. }
  20358. class InstancedInterleavedBuffer extends InterleavedBuffer {
  20359. constructor( array, stride, meshPerAttribute = 1 ) {
  20360. super( array, stride );
  20361. this.isInstancedInterleavedBuffer = true;
  20362. this.meshPerAttribute = meshPerAttribute;
  20363. }
  20364. copy( source ) {
  20365. super.copy( source );
  20366. this.meshPerAttribute = source.meshPerAttribute;
  20367. return this;
  20368. }
  20369. clone( data ) {
  20370. const ib = super.clone( data );
  20371. ib.meshPerAttribute = this.meshPerAttribute;
  20372. return ib;
  20373. }
  20374. toJSON( data ) {
  20375. const json = super.toJSON( data );
  20376. json.isInstancedInterleavedBuffer = true;
  20377. json.meshPerAttribute = this.meshPerAttribute;
  20378. return json;
  20379. }
  20380. }
  20381. class GLBufferAttribute {
  20382. constructor( buffer, type, itemSize, elementSize, count ) {
  20383. this.isGLBufferAttribute = true;
  20384. this.name = '';
  20385. this.buffer = buffer;
  20386. this.type = type;
  20387. this.itemSize = itemSize;
  20388. this.elementSize = elementSize;
  20389. this.count = count;
  20390. this.version = 0;
  20391. }
  20392. set needsUpdate( value ) {
  20393. if ( value === true ) this.version ++;
  20394. }
  20395. setBuffer( buffer ) {
  20396. this.buffer = buffer;
  20397. return this;
  20398. }
  20399. setType( type, elementSize ) {
  20400. this.type = type;
  20401. this.elementSize = elementSize;
  20402. return this;
  20403. }
  20404. setItemSize( itemSize ) {
  20405. this.itemSize = itemSize;
  20406. return this;
  20407. }
  20408. setCount( count ) {
  20409. this.count = count;
  20410. return this;
  20411. }
  20412. }
  20413. const _matrix = /*@__PURE__*/ new Matrix4();
  20414. class Raycaster {
  20415. constructor( origin, direction, near = 0, far = Infinity ) {
  20416. this.ray = new Ray( origin, direction );
  20417. // direction is assumed to be normalized (for accurate distance calculations)
  20418. this.near = near;
  20419. this.far = far;
  20420. this.camera = null;
  20421. this.layers = new Layers();
  20422. this.params = {
  20423. Mesh: {},
  20424. Line: { threshold: 1 },
  20425. LOD: {},
  20426. Points: { threshold: 1 },
  20427. Sprite: {}
  20428. };
  20429. }
  20430. set( origin, direction ) {
  20431. // direction is assumed to be normalized (for accurate distance calculations)
  20432. this.ray.set( origin, direction );
  20433. }
  20434. setFromCamera( coords, camera ) {
  20435. if ( camera.isPerspectiveCamera ) {
  20436. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  20437. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  20438. this.camera = camera;
  20439. } else if ( camera.isOrthographicCamera ) {
  20440. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  20441. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  20442. this.camera = camera;
  20443. } else {
  20444. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  20445. }
  20446. }
  20447. setFromXRController( controller ) {
  20448. _matrix.identity().extractRotation( controller.matrixWorld );
  20449. this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
  20450. this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
  20451. return this;
  20452. }
  20453. intersectObject( object, recursive = true, intersects = [] ) {
  20454. intersect( object, this, intersects, recursive );
  20455. intersects.sort( ascSort );
  20456. return intersects;
  20457. }
  20458. intersectObjects( objects, recursive = true, intersects = [] ) {
  20459. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  20460. intersect( objects[ i ], this, intersects, recursive );
  20461. }
  20462. intersects.sort( ascSort );
  20463. return intersects;
  20464. }
  20465. }
  20466. function ascSort( a, b ) {
  20467. return a.distance - b.distance;
  20468. }
  20469. function intersect( object, raycaster, intersects, recursive ) {
  20470. let propagate = true;
  20471. if ( object.layers.test( raycaster.layers ) ) {
  20472. const result = object.raycast( raycaster, intersects );
  20473. if ( result === false ) propagate = false;
  20474. }
  20475. if ( propagate === true && recursive === true ) {
  20476. const children = object.children;
  20477. for ( let i = 0, l = children.length; i < l; i ++ ) {
  20478. intersect( children[ i ], raycaster, intersects, true );
  20479. }
  20480. }
  20481. }
  20482. /**
  20483. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  20484. *
  20485. * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up.
  20486. * theta (the azimuthal angle) is measured from the positive z-axis.
  20487. */
  20488. class Spherical {
  20489. constructor( radius = 1, phi = 0, theta = 0 ) {
  20490. this.radius = radius;
  20491. this.phi = phi; // polar angle
  20492. this.theta = theta; // azimuthal angle
  20493. return this;
  20494. }
  20495. set( radius, phi, theta ) {
  20496. this.radius = radius;
  20497. this.phi = phi;
  20498. this.theta = theta;
  20499. return this;
  20500. }
  20501. copy( other ) {
  20502. this.radius = other.radius;
  20503. this.phi = other.phi;
  20504. this.theta = other.theta;
  20505. return this;
  20506. }
  20507. // restrict phi to be between EPS and PI-EPS
  20508. makeSafe() {
  20509. const EPS = 0.000001;
  20510. this.phi = clamp( this.phi, EPS, Math.PI - EPS );
  20511. return this;
  20512. }
  20513. setFromVector3( v ) {
  20514. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20515. }
  20516. setFromCartesianCoords( x, y, z ) {
  20517. this.radius = Math.sqrt( x * x + y * y + z * z );
  20518. if ( this.radius === 0 ) {
  20519. this.theta = 0;
  20520. this.phi = 0;
  20521. } else {
  20522. this.theta = Math.atan2( x, z );
  20523. this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );
  20524. }
  20525. return this;
  20526. }
  20527. clone() {
  20528. return new this.constructor().copy( this );
  20529. }
  20530. }
  20531. /**
  20532. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  20533. */
  20534. class Cylindrical {
  20535. constructor( radius = 1, theta = 0, y = 0 ) {
  20536. this.radius = radius; // distance from the origin to a point in the x-z plane
  20537. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  20538. this.y = y; // height above the x-z plane
  20539. return this;
  20540. }
  20541. set( radius, theta, y ) {
  20542. this.radius = radius;
  20543. this.theta = theta;
  20544. this.y = y;
  20545. return this;
  20546. }
  20547. copy( other ) {
  20548. this.radius = other.radius;
  20549. this.theta = other.theta;
  20550. this.y = other.y;
  20551. return this;
  20552. }
  20553. setFromVector3( v ) {
  20554. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20555. }
  20556. setFromCartesianCoords( x, y, z ) {
  20557. this.radius = Math.sqrt( x * x + z * z );
  20558. this.theta = Math.atan2( x, z );
  20559. this.y = y;
  20560. return this;
  20561. }
  20562. clone() {
  20563. return new this.constructor().copy( this );
  20564. }
  20565. }
  20566. class Matrix2 {
  20567. constructor( n11, n12, n21, n22 ) {
  20568. Matrix2.prototype.isMatrix2 = true;
  20569. this.elements = [
  20570. 1, 0,
  20571. 0, 1,
  20572. ];
  20573. if ( n11 !== undefined ) {
  20574. this.set( n11, n12, n21, n22 );
  20575. }
  20576. }
  20577. identity() {
  20578. this.set(
  20579. 1, 0,
  20580. 0, 1,
  20581. );
  20582. return this;
  20583. }
  20584. fromArray( array, offset = 0 ) {
  20585. for ( let i = 0; i < 4; i ++ ) {
  20586. this.elements[ i ] = array[ i + offset ];
  20587. }
  20588. return this;
  20589. }
  20590. set( n11, n12, n21, n22 ) {
  20591. const te = this.elements;
  20592. te[ 0 ] = n11; te[ 2 ] = n12;
  20593. te[ 1 ] = n21; te[ 3 ] = n22;
  20594. return this;
  20595. }
  20596. }
  20597. const _vector$4 = /*@__PURE__*/ new Vector2();
  20598. class Box2 {
  20599. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  20600. this.isBox2 = true;
  20601. this.min = min;
  20602. this.max = max;
  20603. }
  20604. set( min, max ) {
  20605. this.min.copy( min );
  20606. this.max.copy( max );
  20607. return this;
  20608. }
  20609. setFromPoints( points ) {
  20610. this.makeEmpty();
  20611. for ( let i = 0, il = points.length; i < il; i ++ ) {
  20612. this.expandByPoint( points[ i ] );
  20613. }
  20614. return this;
  20615. }
  20616. setFromCenterAndSize( center, size ) {
  20617. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  20618. this.min.copy( center ).sub( halfSize );
  20619. this.max.copy( center ).add( halfSize );
  20620. return this;
  20621. }
  20622. clone() {
  20623. return new this.constructor().copy( this );
  20624. }
  20625. copy( box ) {
  20626. this.min.copy( box.min );
  20627. this.max.copy( box.max );
  20628. return this;
  20629. }
  20630. makeEmpty() {
  20631. this.min.x = this.min.y = + Infinity;
  20632. this.max.x = this.max.y = - Infinity;
  20633. return this;
  20634. }
  20635. isEmpty() {
  20636. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  20637. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  20638. }
  20639. getCenter( target ) {
  20640. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  20641. }
  20642. getSize( target ) {
  20643. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  20644. }
  20645. expandByPoint( point ) {
  20646. this.min.min( point );
  20647. this.max.max( point );
  20648. return this;
  20649. }
  20650. expandByVector( vector ) {
  20651. this.min.sub( vector );
  20652. this.max.add( vector );
  20653. return this;
  20654. }
  20655. expandByScalar( scalar ) {
  20656. this.min.addScalar( - scalar );
  20657. this.max.addScalar( scalar );
  20658. return this;
  20659. }
  20660. containsPoint( point ) {
  20661. return point.x >= this.min.x && point.x <= this.max.x &&
  20662. point.y >= this.min.y && point.y <= this.max.y;
  20663. }
  20664. containsBox( box ) {
  20665. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  20666. this.min.y <= box.min.y && box.max.y <= this.max.y;
  20667. }
  20668. getParameter( point, target ) {
  20669. // This can potentially have a divide by zero if the box
  20670. // has a size dimension of 0.
  20671. return target.set(
  20672. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  20673. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  20674. );
  20675. }
  20676. intersectsBox( box ) {
  20677. // using 4 splitting planes to rule out intersections
  20678. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  20679. box.max.y >= this.min.y && box.min.y <= this.max.y;
  20680. }
  20681. clampPoint( point, target ) {
  20682. return target.copy( point ).clamp( this.min, this.max );
  20683. }
  20684. distanceToPoint( point ) {
  20685. return this.clampPoint( point, _vector$4 ).distanceTo( point );
  20686. }
  20687. intersect( box ) {
  20688. this.min.max( box.min );
  20689. this.max.min( box.max );
  20690. if ( this.isEmpty() ) this.makeEmpty();
  20691. return this;
  20692. }
  20693. union( box ) {
  20694. this.min.min( box.min );
  20695. this.max.max( box.max );
  20696. return this;
  20697. }
  20698. translate( offset ) {
  20699. this.min.add( offset );
  20700. this.max.add( offset );
  20701. return this;
  20702. }
  20703. equals( box ) {
  20704. return box.min.equals( this.min ) && box.max.equals( this.max );
  20705. }
  20706. }
  20707. const _startP = /*@__PURE__*/ new Vector3();
  20708. const _startEnd = /*@__PURE__*/ new Vector3();
  20709. class Line3 {
  20710. constructor( start = new Vector3(), end = new Vector3() ) {
  20711. this.start = start;
  20712. this.end = end;
  20713. }
  20714. set( start, end ) {
  20715. this.start.copy( start );
  20716. this.end.copy( end );
  20717. return this;
  20718. }
  20719. copy( line ) {
  20720. this.start.copy( line.start );
  20721. this.end.copy( line.end );
  20722. return this;
  20723. }
  20724. getCenter( target ) {
  20725. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  20726. }
  20727. delta( target ) {
  20728. return target.subVectors( this.end, this.start );
  20729. }
  20730. distanceSq() {
  20731. return this.start.distanceToSquared( this.end );
  20732. }
  20733. distance() {
  20734. return this.start.distanceTo( this.end );
  20735. }
  20736. at( t, target ) {
  20737. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20738. }
  20739. closestPointToPointParameter( point, clampToLine ) {
  20740. _startP.subVectors( point, this.start );
  20741. _startEnd.subVectors( this.end, this.start );
  20742. const startEnd2 = _startEnd.dot( _startEnd );
  20743. const startEnd_startP = _startEnd.dot( _startP );
  20744. let t = startEnd_startP / startEnd2;
  20745. if ( clampToLine ) {
  20746. t = clamp( t, 0, 1 );
  20747. }
  20748. return t;
  20749. }
  20750. closestPointToPoint( point, clampToLine, target ) {
  20751. const t = this.closestPointToPointParameter( point, clampToLine );
  20752. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20753. }
  20754. applyMatrix4( matrix ) {
  20755. this.start.applyMatrix4( matrix );
  20756. this.end.applyMatrix4( matrix );
  20757. return this;
  20758. }
  20759. equals( line ) {
  20760. return line.start.equals( this.start ) && line.end.equals( this.end );
  20761. }
  20762. clone() {
  20763. return new this.constructor().copy( this );
  20764. }
  20765. }
  20766. const _vector$3 = /*@__PURE__*/ new Vector3();
  20767. class SpotLightHelper extends Object3D {
  20768. constructor( light, color ) {
  20769. super();
  20770. this.light = light;
  20771. this.matrixAutoUpdate = false;
  20772. this.color = color;
  20773. this.type = 'SpotLightHelper';
  20774. const geometry = new BufferGeometry();
  20775. const positions = [
  20776. 0, 0, 0, 0, 0, 1,
  20777. 0, 0, 0, 1, 0, 1,
  20778. 0, 0, 0, - 1, 0, 1,
  20779. 0, 0, 0, 0, 1, 1,
  20780. 0, 0, 0, 0, - 1, 1
  20781. ];
  20782. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  20783. const p1 = ( i / l ) * Math.PI * 2;
  20784. const p2 = ( j / l ) * Math.PI * 2;
  20785. positions.push(
  20786. Math.cos( p1 ), Math.sin( p1 ), 1,
  20787. Math.cos( p2 ), Math.sin( p2 ), 1
  20788. );
  20789. }
  20790. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  20791. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  20792. this.cone = new LineSegments( geometry, material );
  20793. this.add( this.cone );
  20794. this.update();
  20795. }
  20796. dispose() {
  20797. this.cone.geometry.dispose();
  20798. this.cone.material.dispose();
  20799. }
  20800. update() {
  20801. this.light.updateWorldMatrix( true, false );
  20802. this.light.target.updateWorldMatrix( true, false );
  20803. // update the local matrix based on the parent and light target transforms
  20804. if ( this.parent ) {
  20805. this.parent.updateWorldMatrix( true );
  20806. this.matrix
  20807. .copy( this.parent.matrixWorld )
  20808. .invert()
  20809. .multiply( this.light.matrixWorld );
  20810. } else {
  20811. this.matrix.copy( this.light.matrixWorld );
  20812. }
  20813. this.matrixWorld.copy( this.light.matrixWorld );
  20814. const coneLength = this.light.distance ? this.light.distance : 1000;
  20815. const coneWidth = coneLength * Math.tan( this.light.angle );
  20816. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20817. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  20818. this.cone.lookAt( _vector$3 );
  20819. if ( this.color !== undefined ) {
  20820. this.cone.material.color.set( this.color );
  20821. } else {
  20822. this.cone.material.color.copy( this.light.color );
  20823. }
  20824. }
  20825. }
  20826. const _vector$2 = /*@__PURE__*/ new Vector3();
  20827. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  20828. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  20829. class SkeletonHelper extends LineSegments {
  20830. constructor( object ) {
  20831. const bones = getBoneList( object );
  20832. const geometry = new BufferGeometry();
  20833. const vertices = [];
  20834. const colors = [];
  20835. const color1 = new Color( 0, 0, 1 );
  20836. const color2 = new Color( 0, 1, 0 );
  20837. for ( let i = 0; i < bones.length; i ++ ) {
  20838. const bone = bones[ i ];
  20839. if ( bone.parent && bone.parent.isBone ) {
  20840. vertices.push( 0, 0, 0 );
  20841. vertices.push( 0, 0, 0 );
  20842. colors.push( color1.r, color1.g, color1.b );
  20843. colors.push( color2.r, color2.g, color2.b );
  20844. }
  20845. }
  20846. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20847. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20848. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  20849. super( geometry, material );
  20850. this.isSkeletonHelper = true;
  20851. this.type = 'SkeletonHelper';
  20852. this.root = object;
  20853. this.bones = bones;
  20854. this.matrix = object.matrixWorld;
  20855. this.matrixAutoUpdate = false;
  20856. }
  20857. updateMatrixWorld( force ) {
  20858. const bones = this.bones;
  20859. const geometry = this.geometry;
  20860. const position = geometry.getAttribute( 'position' );
  20861. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  20862. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  20863. const bone = bones[ i ];
  20864. if ( bone.parent && bone.parent.isBone ) {
  20865. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  20866. _vector$2.setFromMatrixPosition( _boneMatrix );
  20867. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  20868. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  20869. _vector$2.setFromMatrixPosition( _boneMatrix );
  20870. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  20871. j += 2;
  20872. }
  20873. }
  20874. geometry.getAttribute( 'position' ).needsUpdate = true;
  20875. super.updateMatrixWorld( force );
  20876. }
  20877. dispose() {
  20878. this.geometry.dispose();
  20879. this.material.dispose();
  20880. }
  20881. }
  20882. function getBoneList( object ) {
  20883. const boneList = [];
  20884. if ( object.isBone === true ) {
  20885. boneList.push( object );
  20886. }
  20887. for ( let i = 0; i < object.children.length; i ++ ) {
  20888. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  20889. }
  20890. return boneList;
  20891. }
  20892. class PointLightHelper extends Mesh {
  20893. constructor( light, sphereSize, color ) {
  20894. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  20895. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20896. super( geometry, material );
  20897. this.light = light;
  20898. this.color = color;
  20899. this.type = 'PointLightHelper';
  20900. this.matrix = this.light.matrixWorld;
  20901. this.matrixAutoUpdate = false;
  20902. this.update();
  20903. /*
  20904. // TODO: delete this comment?
  20905. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20906. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20907. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20908. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20909. const d = light.distance;
  20910. if ( d === 0.0 ) {
  20911. this.lightDistance.visible = false;
  20912. } else {
  20913. this.lightDistance.scale.set( d, d, d );
  20914. }
  20915. this.add( this.lightDistance );
  20916. */
  20917. }
  20918. dispose() {
  20919. this.geometry.dispose();
  20920. this.material.dispose();
  20921. }
  20922. update() {
  20923. this.light.updateWorldMatrix( true, false );
  20924. if ( this.color !== undefined ) {
  20925. this.material.color.set( this.color );
  20926. } else {
  20927. this.material.color.copy( this.light.color );
  20928. }
  20929. /*
  20930. const d = this.light.distance;
  20931. if ( d === 0.0 ) {
  20932. this.lightDistance.visible = false;
  20933. } else {
  20934. this.lightDistance.visible = true;
  20935. this.lightDistance.scale.set( d, d, d );
  20936. }
  20937. */
  20938. }
  20939. }
  20940. const _vector$1 = /*@__PURE__*/ new Vector3();
  20941. const _color1 = /*@__PURE__*/ new Color();
  20942. const _color2 = /*@__PURE__*/ new Color();
  20943. class HemisphereLightHelper extends Object3D {
  20944. constructor( light, size, color ) {
  20945. super();
  20946. this.light = light;
  20947. this.matrix = light.matrixWorld;
  20948. this.matrixAutoUpdate = false;
  20949. this.color = color;
  20950. this.type = 'HemisphereLightHelper';
  20951. const geometry = new OctahedronGeometry( size );
  20952. geometry.rotateY( Math.PI * 0.5 );
  20953. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20954. if ( this.color === undefined ) this.material.vertexColors = true;
  20955. const position = geometry.getAttribute( 'position' );
  20956. const colors = new Float32Array( position.count * 3 );
  20957. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  20958. this.add( new Mesh( geometry, this.material ) );
  20959. this.update();
  20960. }
  20961. dispose() {
  20962. this.children[ 0 ].geometry.dispose();
  20963. this.children[ 0 ].material.dispose();
  20964. }
  20965. update() {
  20966. const mesh = this.children[ 0 ];
  20967. if ( this.color !== undefined ) {
  20968. this.material.color.set( this.color );
  20969. } else {
  20970. const colors = mesh.geometry.getAttribute( 'color' );
  20971. _color1.copy( this.light.color );
  20972. _color2.copy( this.light.groundColor );
  20973. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  20974. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  20975. colors.setXYZ( i, color.r, color.g, color.b );
  20976. }
  20977. colors.needsUpdate = true;
  20978. }
  20979. this.light.updateWorldMatrix( true, false );
  20980. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20981. }
  20982. }
  20983. class GridHelper extends LineSegments {
  20984. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  20985. color1 = new Color( color1 );
  20986. color2 = new Color( color2 );
  20987. const center = divisions / 2;
  20988. const step = size / divisions;
  20989. const halfSize = size / 2;
  20990. const vertices = [], colors = [];
  20991. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  20992. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  20993. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  20994. const color = i === center ? color1 : color2;
  20995. color.toArray( colors, j ); j += 3;
  20996. color.toArray( colors, j ); j += 3;
  20997. color.toArray( colors, j ); j += 3;
  20998. color.toArray( colors, j ); j += 3;
  20999. }
  21000. const geometry = new BufferGeometry();
  21001. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21002. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21003. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21004. super( geometry, material );
  21005. this.type = 'GridHelper';
  21006. }
  21007. dispose() {
  21008. this.geometry.dispose();
  21009. this.material.dispose();
  21010. }
  21011. }
  21012. class PolarGridHelper extends LineSegments {
  21013. constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  21014. color1 = new Color( color1 );
  21015. color2 = new Color( color2 );
  21016. const vertices = [];
  21017. const colors = [];
  21018. // create the sectors
  21019. if ( sectors > 1 ) {
  21020. for ( let i = 0; i < sectors; i ++ ) {
  21021. const v = ( i / sectors ) * ( Math.PI * 2 );
  21022. const x = Math.sin( v ) * radius;
  21023. const z = Math.cos( v ) * radius;
  21024. vertices.push( 0, 0, 0 );
  21025. vertices.push( x, 0, z );
  21026. const color = ( i & 1 ) ? color1 : color2;
  21027. colors.push( color.r, color.g, color.b );
  21028. colors.push( color.r, color.g, color.b );
  21029. }
  21030. }
  21031. // create the rings
  21032. for ( let i = 0; i < rings; i ++ ) {
  21033. const color = ( i & 1 ) ? color1 : color2;
  21034. const r = radius - ( radius / rings * i );
  21035. for ( let j = 0; j < divisions; j ++ ) {
  21036. // first vertex
  21037. let v = ( j / divisions ) * ( Math.PI * 2 );
  21038. let x = Math.sin( v ) * r;
  21039. let z = Math.cos( v ) * r;
  21040. vertices.push( x, 0, z );
  21041. colors.push( color.r, color.g, color.b );
  21042. // second vertex
  21043. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  21044. x = Math.sin( v ) * r;
  21045. z = Math.cos( v ) * r;
  21046. vertices.push( x, 0, z );
  21047. colors.push( color.r, color.g, color.b );
  21048. }
  21049. }
  21050. const geometry = new BufferGeometry();
  21051. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21052. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21053. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21054. super( geometry, material );
  21055. this.type = 'PolarGridHelper';
  21056. }
  21057. dispose() {
  21058. this.geometry.dispose();
  21059. this.material.dispose();
  21060. }
  21061. }
  21062. const _v1 = /*@__PURE__*/ new Vector3();
  21063. const _v2 = /*@__PURE__*/ new Vector3();
  21064. const _v3 = /*@__PURE__*/ new Vector3();
  21065. class DirectionalLightHelper extends Object3D {
  21066. constructor( light, size, color ) {
  21067. super();
  21068. this.light = light;
  21069. this.matrix = light.matrixWorld;
  21070. this.matrixAutoUpdate = false;
  21071. this.color = color;
  21072. this.type = 'DirectionalLightHelper';
  21073. if ( size === undefined ) size = 1;
  21074. let geometry = new BufferGeometry();
  21075. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  21076. - size, size, 0,
  21077. size, size, 0,
  21078. size, - size, 0,
  21079. - size, - size, 0,
  21080. - size, size, 0
  21081. ], 3 ) );
  21082. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  21083. this.lightPlane = new Line( geometry, material );
  21084. this.add( this.lightPlane );
  21085. geometry = new BufferGeometry();
  21086. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  21087. this.targetLine = new Line( geometry, material );
  21088. this.add( this.targetLine );
  21089. this.update();
  21090. }
  21091. dispose() {
  21092. this.lightPlane.geometry.dispose();
  21093. this.lightPlane.material.dispose();
  21094. this.targetLine.geometry.dispose();
  21095. this.targetLine.material.dispose();
  21096. }
  21097. update() {
  21098. this.light.updateWorldMatrix( true, false );
  21099. this.light.target.updateWorldMatrix( true, false );
  21100. _v1.setFromMatrixPosition( this.light.matrixWorld );
  21101. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21102. _v3.subVectors( _v2, _v1 );
  21103. this.lightPlane.lookAt( _v2 );
  21104. if ( this.color !== undefined ) {
  21105. this.lightPlane.material.color.set( this.color );
  21106. this.targetLine.material.color.set( this.color );
  21107. } else {
  21108. this.lightPlane.material.color.copy( this.light.color );
  21109. this.targetLine.material.color.copy( this.light.color );
  21110. }
  21111. this.targetLine.lookAt( _v2 );
  21112. this.targetLine.scale.z = _v3.length();
  21113. }
  21114. }
  21115. const _vector = /*@__PURE__*/ new Vector3();
  21116. const _camera = /*@__PURE__*/ new Camera();
  21117. /**
  21118. * - shows frustum, line of sight and up of the camera
  21119. * - suitable for fast updates
  21120. * - based on frustum visualization in lightgl.js shadowmap example
  21121. * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html
  21122. */
  21123. class CameraHelper extends LineSegments {
  21124. constructor( camera ) {
  21125. const geometry = new BufferGeometry();
  21126. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  21127. const vertices = [];
  21128. const colors = [];
  21129. const pointMap = {};
  21130. // near
  21131. addLine( 'n1', 'n2' );
  21132. addLine( 'n2', 'n4' );
  21133. addLine( 'n4', 'n3' );
  21134. addLine( 'n3', 'n1' );
  21135. // far
  21136. addLine( 'f1', 'f2' );
  21137. addLine( 'f2', 'f4' );
  21138. addLine( 'f4', 'f3' );
  21139. addLine( 'f3', 'f1' );
  21140. // sides
  21141. addLine( 'n1', 'f1' );
  21142. addLine( 'n2', 'f2' );
  21143. addLine( 'n3', 'f3' );
  21144. addLine( 'n4', 'f4' );
  21145. // cone
  21146. addLine( 'p', 'n1' );
  21147. addLine( 'p', 'n2' );
  21148. addLine( 'p', 'n3' );
  21149. addLine( 'p', 'n4' );
  21150. // up
  21151. addLine( 'u1', 'u2' );
  21152. addLine( 'u2', 'u3' );
  21153. addLine( 'u3', 'u1' );
  21154. // target
  21155. addLine( 'c', 't' );
  21156. addLine( 'p', 'c' );
  21157. // cross
  21158. addLine( 'cn1', 'cn2' );
  21159. addLine( 'cn3', 'cn4' );
  21160. addLine( 'cf1', 'cf2' );
  21161. addLine( 'cf3', 'cf4' );
  21162. function addLine( a, b ) {
  21163. addPoint( a );
  21164. addPoint( b );
  21165. }
  21166. function addPoint( id ) {
  21167. vertices.push( 0, 0, 0 );
  21168. colors.push( 0, 0, 0 );
  21169. if ( pointMap[ id ] === undefined ) {
  21170. pointMap[ id ] = [];
  21171. }
  21172. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  21173. }
  21174. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21175. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21176. super( geometry, material );
  21177. this.type = 'CameraHelper';
  21178. this.camera = camera;
  21179. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  21180. this.matrix = camera.matrixWorld;
  21181. this.matrixAutoUpdate = false;
  21182. this.pointMap = pointMap;
  21183. this.update();
  21184. // colors
  21185. const colorFrustum = new Color( 0xffaa00 );
  21186. const colorCone = new Color( 0xff0000 );
  21187. const colorUp = new Color( 0x00aaff );
  21188. const colorTarget = new Color( 0xffffff );
  21189. const colorCross = new Color( 0x333333 );
  21190. this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross );
  21191. }
  21192. setColors( frustum, cone, up, target, cross ) {
  21193. const geometry = this.geometry;
  21194. const colorAttribute = geometry.getAttribute( 'color' );
  21195. // near
  21196. colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2
  21197. colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4
  21198. colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3
  21199. colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1
  21200. // far
  21201. colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2
  21202. colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4
  21203. colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3
  21204. colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1
  21205. // sides
  21206. colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1
  21207. colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2
  21208. colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3
  21209. colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4
  21210. // cone
  21211. colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1
  21212. colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2
  21213. colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3
  21214. colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4
  21215. // up
  21216. colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2
  21217. colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3
  21218. colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1
  21219. // target
  21220. colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t
  21221. colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c
  21222. // cross
  21223. colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2
  21224. colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4
  21225. colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2
  21226. colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4
  21227. colorAttribute.needsUpdate = true;
  21228. }
  21229. update() {
  21230. const geometry = this.geometry;
  21231. const pointMap = this.pointMap;
  21232. const w = 1, h = 1;
  21233. // we need just camera projection matrix inverse
  21234. // world matrix must be identity
  21235. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  21236. // Adjust z values based on coordinate system
  21237. const nearZ = this.camera.coordinateSystem === WebGLCoordinateSystem ? - 1 : 0;
  21238. // center / target
  21239. setPoint( 'c', pointMap, geometry, _camera, 0, 0, nearZ );
  21240. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  21241. // near
  21242. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, nearZ );
  21243. setPoint( 'n2', pointMap, geometry, _camera, w, - h, nearZ );
  21244. setPoint( 'n3', pointMap, geometry, _camera, - w, h, nearZ );
  21245. setPoint( 'n4', pointMap, geometry, _camera, w, h, nearZ );
  21246. // far
  21247. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  21248. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  21249. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  21250. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  21251. // up
  21252. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, nearZ );
  21253. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, nearZ );
  21254. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, nearZ );
  21255. // cross
  21256. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  21257. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  21258. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  21259. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  21260. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, nearZ );
  21261. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, nearZ );
  21262. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, nearZ );
  21263. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, nearZ );
  21264. geometry.getAttribute( 'position' ).needsUpdate = true;
  21265. }
  21266. dispose() {
  21267. this.geometry.dispose();
  21268. this.material.dispose();
  21269. }
  21270. }
  21271. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  21272. _vector.set( x, y, z ).unproject( camera );
  21273. const points = pointMap[ point ];
  21274. if ( points !== undefined ) {
  21275. const position = geometry.getAttribute( 'position' );
  21276. for ( let i = 0, l = points.length; i < l; i ++ ) {
  21277. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  21278. }
  21279. }
  21280. }
  21281. const _box = /*@__PURE__*/ new Box3();
  21282. class BoxHelper extends LineSegments {
  21283. constructor( object, color = 0xffff00 ) {
  21284. 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 ] );
  21285. const positions = new Float32Array( 8 * 3 );
  21286. const geometry = new BufferGeometry();
  21287. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21288. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  21289. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21290. this.object = object;
  21291. this.type = 'BoxHelper';
  21292. this.matrixAutoUpdate = false;
  21293. this.update();
  21294. }
  21295. update( object ) {
  21296. if ( object !== undefined ) {
  21297. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  21298. }
  21299. if ( this.object !== undefined ) {
  21300. _box.setFromObject( this.object );
  21301. }
  21302. if ( _box.isEmpty() ) return;
  21303. const min = _box.min;
  21304. const max = _box.max;
  21305. /*
  21306. 5____4
  21307. 1/___0/|
  21308. | 6__|_7
  21309. 2/___3/
  21310. 0: max.x, max.y, max.z
  21311. 1: min.x, max.y, max.z
  21312. 2: min.x, min.y, max.z
  21313. 3: max.x, min.y, max.z
  21314. 4: max.x, max.y, min.z
  21315. 5: min.x, max.y, min.z
  21316. 6: min.x, min.y, min.z
  21317. 7: max.x, min.y, min.z
  21318. */
  21319. const position = this.geometry.attributes.position;
  21320. const array = position.array;
  21321. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21322. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21323. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21324. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21325. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21326. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21327. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21328. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21329. position.needsUpdate = true;
  21330. this.geometry.computeBoundingSphere();
  21331. }
  21332. setFromObject( object ) {
  21333. this.object = object;
  21334. this.update();
  21335. return this;
  21336. }
  21337. copy( source, recursive ) {
  21338. super.copy( source, recursive );
  21339. this.object = source.object;
  21340. return this;
  21341. }
  21342. dispose() {
  21343. this.geometry.dispose();
  21344. this.material.dispose();
  21345. }
  21346. }
  21347. class Box3Helper extends LineSegments {
  21348. constructor( box, color = 0xffff00 ) {
  21349. 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 ] );
  21350. 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 ];
  21351. const geometry = new BufferGeometry();
  21352. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21353. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21354. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21355. this.box = box;
  21356. this.type = 'Box3Helper';
  21357. this.geometry.computeBoundingSphere();
  21358. }
  21359. updateMatrixWorld( force ) {
  21360. const box = this.box;
  21361. if ( box.isEmpty() ) return;
  21362. box.getCenter( this.position );
  21363. box.getSize( this.scale );
  21364. this.scale.multiplyScalar( 0.5 );
  21365. super.updateMatrixWorld( force );
  21366. }
  21367. dispose() {
  21368. this.geometry.dispose();
  21369. this.material.dispose();
  21370. }
  21371. }
  21372. class PlaneHelper extends Line {
  21373. constructor( plane, size = 1, hex = 0xffff00 ) {
  21374. const color = hex;
  21375. 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 ];
  21376. const geometry = new BufferGeometry();
  21377. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21378. geometry.computeBoundingSphere();
  21379. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21380. this.type = 'PlaneHelper';
  21381. this.plane = plane;
  21382. this.size = size;
  21383. const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  21384. const geometry2 = new BufferGeometry();
  21385. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  21386. geometry2.computeBoundingSphere();
  21387. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  21388. }
  21389. updateMatrixWorld( force ) {
  21390. this.position.set( 0, 0, 0 );
  21391. this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 );
  21392. this.lookAt( this.plane.normal );
  21393. this.translateZ( - this.plane.constant );
  21394. super.updateMatrixWorld( force );
  21395. }
  21396. dispose() {
  21397. this.geometry.dispose();
  21398. this.material.dispose();
  21399. this.children[ 0 ].geometry.dispose();
  21400. this.children[ 0 ].material.dispose();
  21401. }
  21402. }
  21403. const _axis = /*@__PURE__*/ new Vector3();
  21404. let _lineGeometry, _coneGeometry;
  21405. class ArrowHelper extends Object3D {
  21406. // dir is assumed to be normalized
  21407. 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 ) {
  21408. super();
  21409. this.type = 'ArrowHelper';
  21410. if ( _lineGeometry === undefined ) {
  21411. _lineGeometry = new BufferGeometry();
  21412. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  21413. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21414. _coneGeometry.translate( 0, - 0.5, 0 );
  21415. }
  21416. this.position.copy( origin );
  21417. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21418. this.line.matrixAutoUpdate = false;
  21419. this.add( this.line );
  21420. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  21421. this.cone.matrixAutoUpdate = false;
  21422. this.add( this.cone );
  21423. this.setDirection( dir );
  21424. this.setLength( length, headLength, headWidth );
  21425. }
  21426. setDirection( dir ) {
  21427. // dir is assumed to be normalized
  21428. if ( dir.y > 0.99999 ) {
  21429. this.quaternion.set( 0, 0, 0, 1 );
  21430. } else if ( dir.y < - 0.99999 ) {
  21431. this.quaternion.set( 1, 0, 0, 0 );
  21432. } else {
  21433. _axis.set( dir.z, 0, - dir.x ).normalize();
  21434. const radians = Math.acos( dir.y );
  21435. this.quaternion.setFromAxisAngle( _axis, radians );
  21436. }
  21437. }
  21438. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21439. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  21440. this.line.updateMatrix();
  21441. this.cone.scale.set( headWidth, headLength, headWidth );
  21442. this.cone.position.y = length;
  21443. this.cone.updateMatrix();
  21444. }
  21445. setColor( color ) {
  21446. this.line.material.color.set( color );
  21447. this.cone.material.color.set( color );
  21448. }
  21449. copy( source ) {
  21450. super.copy( source, false );
  21451. this.line.copy( source.line );
  21452. this.cone.copy( source.cone );
  21453. return this;
  21454. }
  21455. dispose() {
  21456. this.line.geometry.dispose();
  21457. this.line.material.dispose();
  21458. this.cone.geometry.dispose();
  21459. this.cone.material.dispose();
  21460. }
  21461. }
  21462. class AxesHelper extends LineSegments {
  21463. constructor( size = 1 ) {
  21464. const vertices = [
  21465. 0, 0, 0, size, 0, 0,
  21466. 0, 0, 0, 0, size, 0,
  21467. 0, 0, 0, 0, 0, size
  21468. ];
  21469. const colors = [
  21470. 1, 0, 0, 1, 0.6, 0,
  21471. 0, 1, 0, 0.6, 1, 0,
  21472. 0, 0, 1, 0, 0.6, 1
  21473. ];
  21474. const geometry = new BufferGeometry();
  21475. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21476. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21477. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21478. super( geometry, material );
  21479. this.type = 'AxesHelper';
  21480. }
  21481. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  21482. const color = new Color();
  21483. const array = this.geometry.attributes.color.array;
  21484. color.set( xAxisColor );
  21485. color.toArray( array, 0 );
  21486. color.toArray( array, 3 );
  21487. color.set( yAxisColor );
  21488. color.toArray( array, 6 );
  21489. color.toArray( array, 9 );
  21490. color.set( zAxisColor );
  21491. color.toArray( array, 12 );
  21492. color.toArray( array, 15 );
  21493. this.geometry.attributes.color.needsUpdate = true;
  21494. return this;
  21495. }
  21496. dispose() {
  21497. this.geometry.dispose();
  21498. this.material.dispose();
  21499. }
  21500. }
  21501. class ShapePath {
  21502. constructor() {
  21503. this.type = 'ShapePath';
  21504. this.color = new Color();
  21505. this.subPaths = [];
  21506. this.currentPath = null;
  21507. }
  21508. moveTo( x, y ) {
  21509. this.currentPath = new Path();
  21510. this.subPaths.push( this.currentPath );
  21511. this.currentPath.moveTo( x, y );
  21512. return this;
  21513. }
  21514. lineTo( x, y ) {
  21515. this.currentPath.lineTo( x, y );
  21516. return this;
  21517. }
  21518. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21519. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21520. return this;
  21521. }
  21522. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21523. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21524. return this;
  21525. }
  21526. splineThru( pts ) {
  21527. this.currentPath.splineThru( pts );
  21528. return this;
  21529. }
  21530. toShapes( isCCW ) {
  21531. function toShapesNoHoles( inSubpaths ) {
  21532. const shapes = [];
  21533. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21534. const tmpPath = inSubpaths[ i ];
  21535. const tmpShape = new Shape();
  21536. tmpShape.curves = tmpPath.curves;
  21537. shapes.push( tmpShape );
  21538. }
  21539. return shapes;
  21540. }
  21541. function isPointInsidePolygon( inPt, inPolygon ) {
  21542. const polyLen = inPolygon.length;
  21543. // inPt on polygon contour => immediate success or
  21544. // toggling of inside/outside at every single! intersection point of an edge
  21545. // with the horizontal line through inPt, left of inPt
  21546. // not counting lowerY endpoints of edges and whole edges on that line
  21547. let inside = false;
  21548. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21549. let edgeLowPt = inPolygon[ p ];
  21550. let edgeHighPt = inPolygon[ q ];
  21551. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  21552. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  21553. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21554. // not parallel
  21555. if ( edgeDy < 0 ) {
  21556. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21557. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21558. }
  21559. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21560. if ( inPt.y === edgeLowPt.y ) {
  21561. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21562. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21563. } else {
  21564. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21565. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21566. if ( perpEdge < 0 ) continue;
  21567. inside = ! inside; // true intersection left of inPt
  21568. }
  21569. } else {
  21570. // parallel or collinear
  21571. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21572. // edge lies on the same horizontal line as inPt
  21573. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21574. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21575. // continue;
  21576. }
  21577. }
  21578. return inside;
  21579. }
  21580. const isClockWise = ShapeUtils.isClockWise;
  21581. const subPaths = this.subPaths;
  21582. if ( subPaths.length === 0 ) return [];
  21583. let solid, tmpPath, tmpShape;
  21584. const shapes = [];
  21585. if ( subPaths.length === 1 ) {
  21586. tmpPath = subPaths[ 0 ];
  21587. tmpShape = new Shape();
  21588. tmpShape.curves = tmpPath.curves;
  21589. shapes.push( tmpShape );
  21590. return shapes;
  21591. }
  21592. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21593. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21594. // console.log("Holes first", holesFirst);
  21595. const betterShapeHoles = [];
  21596. const newShapes = [];
  21597. let newShapeHoles = [];
  21598. let mainIdx = 0;
  21599. let tmpPoints;
  21600. newShapes[ mainIdx ] = undefined;
  21601. newShapeHoles[ mainIdx ] = [];
  21602. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  21603. tmpPath = subPaths[ i ];
  21604. tmpPoints = tmpPath.getPoints();
  21605. solid = isClockWise( tmpPoints );
  21606. solid = isCCW ? ! solid : solid;
  21607. if ( solid ) {
  21608. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21609. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21610. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21611. if ( holesFirst ) mainIdx ++;
  21612. newShapeHoles[ mainIdx ] = [];
  21613. //console.log('cw', i);
  21614. } else {
  21615. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21616. //console.log('ccw', i);
  21617. }
  21618. }
  21619. // only Holes? -> probably all Shapes with wrong orientation
  21620. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21621. if ( newShapes.length > 1 ) {
  21622. let ambiguous = false;
  21623. let toChange = 0;
  21624. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21625. betterShapeHoles[ sIdx ] = [];
  21626. }
  21627. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21628. const sho = newShapeHoles[ sIdx ];
  21629. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21630. const ho = sho[ hIdx ];
  21631. let hole_unassigned = true;
  21632. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21633. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21634. if ( sIdx !== s2Idx ) toChange ++;
  21635. if ( hole_unassigned ) {
  21636. hole_unassigned = false;
  21637. betterShapeHoles[ s2Idx ].push( ho );
  21638. } else {
  21639. ambiguous = true;
  21640. }
  21641. }
  21642. }
  21643. if ( hole_unassigned ) {
  21644. betterShapeHoles[ sIdx ].push( ho );
  21645. }
  21646. }
  21647. }
  21648. if ( toChange > 0 && ambiguous === false ) {
  21649. newShapeHoles = betterShapeHoles;
  21650. }
  21651. }
  21652. let tmpHoles;
  21653. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  21654. tmpShape = newShapes[ i ].s;
  21655. shapes.push( tmpShape );
  21656. tmpHoles = newShapeHoles[ i ];
  21657. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21658. tmpShape.holes.push( tmpHoles[ j ].h );
  21659. }
  21660. }
  21661. //console.log("shape", shapes);
  21662. return shapes;
  21663. }
  21664. }
  21665. class Controls extends EventDispatcher {
  21666. constructor( object, domElement = null ) {
  21667. super();
  21668. this.object = object;
  21669. this.domElement = domElement;
  21670. this.enabled = true;
  21671. this.state = - 1;
  21672. this.keys = {};
  21673. this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
  21674. this.touches = { ONE: null, TWO: null };
  21675. }
  21676. connect() {}
  21677. disconnect() {}
  21678. dispose() {}
  21679. update( /* delta */ ) {}
  21680. }
  21681. function contain( texture, aspect ) {
  21682. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21683. if ( imageAspect > aspect ) {
  21684. texture.repeat.x = 1;
  21685. texture.repeat.y = imageAspect / aspect;
  21686. texture.offset.x = 0;
  21687. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21688. } else {
  21689. texture.repeat.x = aspect / imageAspect;
  21690. texture.repeat.y = 1;
  21691. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21692. texture.offset.y = 0;
  21693. }
  21694. return texture;
  21695. }
  21696. function cover( texture, aspect ) {
  21697. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21698. if ( imageAspect > aspect ) {
  21699. texture.repeat.x = aspect / imageAspect;
  21700. texture.repeat.y = 1;
  21701. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21702. texture.offset.y = 0;
  21703. } else {
  21704. texture.repeat.x = 1;
  21705. texture.repeat.y = imageAspect / aspect;
  21706. texture.offset.x = 0;
  21707. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21708. }
  21709. return texture;
  21710. }
  21711. function fill( texture ) {
  21712. texture.repeat.x = 1;
  21713. texture.repeat.y = 1;
  21714. texture.offset.x = 0;
  21715. texture.offset.y = 0;
  21716. return texture;
  21717. }
  21718. /**
  21719. * Given the width, height, format, and type of a texture. Determines how many
  21720. * bytes must be used to represent the texture.
  21721. *
  21722. * @param {Number} width
  21723. * @param {Number} height
  21724. * @param {Number} format
  21725. * @param {Number} type
  21726. * @return {Number} The number of bytes required to represent the texture.
  21727. */
  21728. function getByteLength( width, height, format, type ) {
  21729. const typeByteLength = getTextureTypeByteLength( type );
  21730. switch ( format ) {
  21731. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
  21732. case AlphaFormat:
  21733. return width * height;
  21734. case LuminanceFormat:
  21735. return width * height;
  21736. case LuminanceAlphaFormat:
  21737. return width * height * 2;
  21738. case RedFormat:
  21739. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21740. case RedIntegerFormat:
  21741. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21742. case RGFormat:
  21743. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21744. case RGIntegerFormat:
  21745. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21746. case RGBFormat:
  21747. return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21748. case RGBAFormat:
  21749. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21750. case RGBAIntegerFormat:
  21751. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21752. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
  21753. case RGB_S3TC_DXT1_Format:
  21754. case RGBA_S3TC_DXT1_Format:
  21755. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21756. case RGBA_S3TC_DXT3_Format:
  21757. case RGBA_S3TC_DXT5_Format:
  21758. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21759. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
  21760. case RGB_PVRTC_2BPPV1_Format:
  21761. case RGBA_PVRTC_2BPPV1_Format:
  21762. return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
  21763. case RGB_PVRTC_4BPPV1_Format:
  21764. case RGBA_PVRTC_4BPPV1_Format:
  21765. return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
  21766. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
  21767. case RGB_ETC1_Format:
  21768. case RGB_ETC2_Format:
  21769. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21770. case RGBA_ETC2_EAC_Format:
  21771. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21772. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
  21773. case RGBA_ASTC_4x4_Format:
  21774. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21775. case RGBA_ASTC_5x4_Format:
  21776. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21777. case RGBA_ASTC_5x5_Format:
  21778. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21779. case RGBA_ASTC_6x5_Format:
  21780. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21781. case RGBA_ASTC_6x6_Format:
  21782. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21783. case RGBA_ASTC_8x5_Format:
  21784. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21785. case RGBA_ASTC_8x6_Format:
  21786. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21787. case RGBA_ASTC_8x8_Format:
  21788. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21789. case RGBA_ASTC_10x5_Format:
  21790. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21791. case RGBA_ASTC_10x6_Format:
  21792. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21793. case RGBA_ASTC_10x8_Format:
  21794. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21795. case RGBA_ASTC_10x10_Format:
  21796. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21797. case RGBA_ASTC_12x10_Format:
  21798. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21799. case RGBA_ASTC_12x12_Format:
  21800. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
  21801. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
  21802. case RGBA_BPTC_Format:
  21803. case RGB_BPTC_SIGNED_Format:
  21804. case RGB_BPTC_UNSIGNED_Format:
  21805. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21806. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
  21807. case RED_RGTC1_Format:
  21808. case SIGNED_RED_RGTC1_Format:
  21809. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
  21810. case RED_GREEN_RGTC2_Format:
  21811. case SIGNED_RED_GREEN_RGTC2_Format:
  21812. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21813. }
  21814. throw new Error(
  21815. `Unable to determine texture byte length for ${format} format.`,
  21816. );
  21817. }
  21818. function getTextureTypeByteLength( type ) {
  21819. switch ( type ) {
  21820. case UnsignedByteType:
  21821. case ByteType:
  21822. return { byteLength: 1, components: 1 };
  21823. case UnsignedShortType:
  21824. case ShortType:
  21825. case HalfFloatType:
  21826. return { byteLength: 2, components: 1 };
  21827. case UnsignedShort4444Type:
  21828. case UnsignedShort5551Type:
  21829. return { byteLength: 2, components: 4 };
  21830. case UnsignedIntType:
  21831. case IntType:
  21832. case FloatType:
  21833. return { byteLength: 4, components: 1 };
  21834. case UnsignedInt5999Type:
  21835. return { byteLength: 4, components: 3 };
  21836. }
  21837. throw new Error( `Unknown texture type ${type}.` );
  21838. }
  21839. const TextureUtils = {
  21840. contain,
  21841. cover,
  21842. fill,
  21843. getByteLength
  21844. };
  21845. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  21846. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  21847. revision: REVISION,
  21848. } } ) );
  21849. }
  21850. if ( typeof window !== 'undefined' ) {
  21851. if ( window.__THREE__ ) {
  21852. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  21853. } else {
  21854. window.__THREE__ = REVISION;
  21855. }
  21856. }
  21857. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BackSide, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, Color, ColorKeyframeTrack, ColorManagement, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, ConstantAlphaFactor, ConstantColorFactor, Controls, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FramebufferTexture, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, NormalAnimationBlendMode, NormalBlending, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, Path, PerspectiveCamera, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RAD2DEG, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RedFormat, RedIntegerFormat, ReinhardToneMapping, RenderTarget, RenderTarget3D, RenderTargetArray, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingGeometry, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, ShaderMaterial, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronGeometry, Texture, TextureLoader, TextureUtils, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, VideoFrameTexture, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, arrayNeedsUint32, cloneUniforms, createCanvasElement, createElementNS, getByteLength, getUnlitUniformColorSpace, mergeUniforms, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce };
粤ICP备19079148号