three.core.js 735 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987
  1. /**
  2. * @license
  3. * Copyright 2010-2024 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '171';
  7. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  8. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  9. const CullFaceNone = 0;
  10. const CullFaceBack = 1;
  11. const CullFaceFront = 2;
  12. const CullFaceFrontBack = 3;
  13. const BasicShadowMap = 0;
  14. const PCFShadowMap = 1;
  15. const PCFSoftShadowMap = 2;
  16. const VSMShadowMap = 3;
  17. const FrontSide = 0;
  18. const BackSide = 1;
  19. const DoubleSide = 2;
  20. const NoBlending = 0;
  21. const NormalBlending = 1;
  22. const AdditiveBlending = 2;
  23. const SubtractiveBlending = 3;
  24. const MultiplyBlending = 4;
  25. const CustomBlending = 5;
  26. const AddEquation = 100;
  27. const SubtractEquation = 101;
  28. const ReverseSubtractEquation = 102;
  29. const MinEquation = 103;
  30. const MaxEquation = 104;
  31. const ZeroFactor = 200;
  32. const OneFactor = 201;
  33. const SrcColorFactor = 202;
  34. const OneMinusSrcColorFactor = 203;
  35. const SrcAlphaFactor = 204;
  36. const OneMinusSrcAlphaFactor = 205;
  37. const DstAlphaFactor = 206;
  38. const OneMinusDstAlphaFactor = 207;
  39. const DstColorFactor = 208;
  40. const OneMinusDstColorFactor = 209;
  41. const SrcAlphaSaturateFactor = 210;
  42. const ConstantColorFactor = 211;
  43. const OneMinusConstantColorFactor = 212;
  44. const ConstantAlphaFactor = 213;
  45. const OneMinusConstantAlphaFactor = 214;
  46. const NeverDepth = 0;
  47. const AlwaysDepth = 1;
  48. const LessDepth = 2;
  49. const LessEqualDepth = 3;
  50. const EqualDepth = 4;
  51. const GreaterEqualDepth = 5;
  52. const GreaterDepth = 6;
  53. const NotEqualDepth = 7;
  54. const MultiplyOperation = 0;
  55. const MixOperation = 1;
  56. const AddOperation = 2;
  57. const NoToneMapping = 0;
  58. const LinearToneMapping = 1;
  59. const ReinhardToneMapping = 2;
  60. const CineonToneMapping = 3;
  61. const ACESFilmicToneMapping = 4;
  62. const CustomToneMapping = 5;
  63. const AgXToneMapping = 6;
  64. const NeutralToneMapping = 7;
  65. const AttachedBindMode = 'attached';
  66. const DetachedBindMode = 'detached';
  67. const UVMapping = 300;
  68. const CubeReflectionMapping = 301;
  69. const CubeRefractionMapping = 302;
  70. const EquirectangularReflectionMapping = 303;
  71. const EquirectangularRefractionMapping = 304;
  72. const CubeUVReflectionMapping = 306;
  73. const RepeatWrapping = 1000;
  74. const ClampToEdgeWrapping = 1001;
  75. const MirroredRepeatWrapping = 1002;
  76. const NearestFilter = 1003;
  77. const NearestMipmapNearestFilter = 1004;
  78. const NearestMipMapNearestFilter = 1004;
  79. const NearestMipmapLinearFilter = 1005;
  80. const NearestMipMapLinearFilter = 1005;
  81. const LinearFilter = 1006;
  82. const LinearMipmapNearestFilter = 1007;
  83. const LinearMipMapNearestFilter = 1007;
  84. const LinearMipmapLinearFilter = 1008;
  85. const LinearMipMapLinearFilter = 1008;
  86. const UnsignedByteType = 1009;
  87. const ByteType = 1010;
  88. const ShortType = 1011;
  89. const UnsignedShortType = 1012;
  90. const IntType = 1013;
  91. const UnsignedIntType = 1014;
  92. const FloatType = 1015;
  93. const HalfFloatType = 1016;
  94. const UnsignedShort4444Type = 1017;
  95. const UnsignedShort5551Type = 1018;
  96. const UnsignedInt248Type = 1020;
  97. const UnsignedInt5999Type = 35902;
  98. const AlphaFormat = 1021;
  99. const RGBFormat = 1022;
  100. const RGBAFormat = 1023;
  101. const LuminanceFormat = 1024;
  102. const LuminanceAlphaFormat = 1025;
  103. const DepthFormat = 1026;
  104. const DepthStencilFormat = 1027;
  105. const RedFormat = 1028;
  106. const RedIntegerFormat = 1029;
  107. const RGFormat = 1030;
  108. const RGIntegerFormat = 1031;
  109. const RGBIntegerFormat = 1032;
  110. const RGBAIntegerFormat = 1033;
  111. const RGB_S3TC_DXT1_Format = 33776;
  112. const RGBA_S3TC_DXT1_Format = 33777;
  113. const RGBA_S3TC_DXT3_Format = 33778;
  114. const RGBA_S3TC_DXT5_Format = 33779;
  115. const RGB_PVRTC_4BPPV1_Format = 35840;
  116. const RGB_PVRTC_2BPPV1_Format = 35841;
  117. const RGBA_PVRTC_4BPPV1_Format = 35842;
  118. const RGBA_PVRTC_2BPPV1_Format = 35843;
  119. const RGB_ETC1_Format = 36196;
  120. const RGB_ETC2_Format = 37492;
  121. const RGBA_ETC2_EAC_Format = 37496;
  122. const RGBA_ASTC_4x4_Format = 37808;
  123. const RGBA_ASTC_5x4_Format = 37809;
  124. const RGBA_ASTC_5x5_Format = 37810;
  125. const RGBA_ASTC_6x5_Format = 37811;
  126. const RGBA_ASTC_6x6_Format = 37812;
  127. const RGBA_ASTC_8x5_Format = 37813;
  128. const RGBA_ASTC_8x6_Format = 37814;
  129. const RGBA_ASTC_8x8_Format = 37815;
  130. const RGBA_ASTC_10x5_Format = 37816;
  131. const RGBA_ASTC_10x6_Format = 37817;
  132. const RGBA_ASTC_10x8_Format = 37818;
  133. const RGBA_ASTC_10x10_Format = 37819;
  134. const RGBA_ASTC_12x10_Format = 37820;
  135. const RGBA_ASTC_12x12_Format = 37821;
  136. const RGBA_BPTC_Format = 36492;
  137. const RGB_BPTC_SIGNED_Format = 36494;
  138. const RGB_BPTC_UNSIGNED_Format = 36495;
  139. const RED_RGTC1_Format = 36283;
  140. const SIGNED_RED_RGTC1_Format = 36284;
  141. const RED_GREEN_RGTC2_Format = 36285;
  142. const SIGNED_RED_GREEN_RGTC2_Format = 36286;
  143. const LoopOnce = 2200;
  144. const LoopRepeat = 2201;
  145. const LoopPingPong = 2202;
  146. const InterpolateDiscrete = 2300;
  147. const InterpolateLinear = 2301;
  148. const InterpolateSmooth = 2302;
  149. const ZeroCurvatureEnding = 2400;
  150. const ZeroSlopeEnding = 2401;
  151. const WrapAroundEnding = 2402;
  152. const NormalAnimationBlendMode = 2500;
  153. const AdditiveAnimationBlendMode = 2501;
  154. const TrianglesDrawMode = 0;
  155. const TriangleStripDrawMode = 1;
  156. const TriangleFanDrawMode = 2;
  157. const BasicDepthPacking = 3200;
  158. const RGBADepthPacking = 3201;
  159. const RGBDepthPacking = 3202;
  160. const RGDepthPacking = 3203;
  161. const TangentSpaceNormalMap = 0;
  162. const ObjectSpaceNormalMap = 1;
  163. // Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available.
  164. const NoColorSpace = '';
  165. const SRGBColorSpace = 'srgb';
  166. const LinearSRGBColorSpace = 'srgb-linear';
  167. const LinearTransfer = 'linear';
  168. const SRGBTransfer = 'srgb';
  169. const ZeroStencilOp = 0;
  170. const KeepStencilOp = 7680;
  171. const ReplaceStencilOp = 7681;
  172. const IncrementStencilOp = 7682;
  173. const DecrementStencilOp = 7683;
  174. const IncrementWrapStencilOp = 34055;
  175. const DecrementWrapStencilOp = 34056;
  176. const InvertStencilOp = 5386;
  177. const NeverStencilFunc = 512;
  178. const LessStencilFunc = 513;
  179. const EqualStencilFunc = 514;
  180. const LessEqualStencilFunc = 515;
  181. const GreaterStencilFunc = 516;
  182. const NotEqualStencilFunc = 517;
  183. const GreaterEqualStencilFunc = 518;
  184. const AlwaysStencilFunc = 519;
  185. const NeverCompare = 512;
  186. const LessCompare = 513;
  187. const EqualCompare = 514;
  188. const LessEqualCompare = 515;
  189. const GreaterCompare = 516;
  190. const NotEqualCompare = 517;
  191. const GreaterEqualCompare = 518;
  192. const AlwaysCompare = 519;
  193. const StaticDrawUsage = 35044;
  194. const DynamicDrawUsage = 35048;
  195. const StreamDrawUsage = 35040;
  196. const StaticReadUsage = 35045;
  197. const DynamicReadUsage = 35049;
  198. const StreamReadUsage = 35041;
  199. const StaticCopyUsage = 35046;
  200. const DynamicCopyUsage = 35050;
  201. const StreamCopyUsage = 35042;
  202. const GLSL1 = '100';
  203. const GLSL3 = '300 es';
  204. const WebGLCoordinateSystem = 2000;
  205. const WebGPUCoordinateSystem = 2001;
  206. /**
  207. * https://github.com/mrdoob/eventdispatcher.js/
  208. */
  209. class EventDispatcher {
  210. addEventListener( type, listener ) {
  211. if ( this._listeners === undefined ) this._listeners = {};
  212. const listeners = this._listeners;
  213. if ( listeners[ type ] === undefined ) {
  214. listeners[ type ] = [];
  215. }
  216. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  217. listeners[ type ].push( listener );
  218. }
  219. }
  220. hasEventListener( type, listener ) {
  221. if ( this._listeners === undefined ) return false;
  222. const listeners = this._listeners;
  223. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  224. }
  225. removeEventListener( type, listener ) {
  226. if ( this._listeners === undefined ) return;
  227. const listeners = this._listeners;
  228. const listenerArray = listeners[ type ];
  229. if ( listenerArray !== undefined ) {
  230. const index = listenerArray.indexOf( listener );
  231. if ( index !== - 1 ) {
  232. listenerArray.splice( index, 1 );
  233. }
  234. }
  235. }
  236. dispatchEvent( event ) {
  237. if ( this._listeners === undefined ) return;
  238. const listeners = this._listeners;
  239. const listenerArray = listeners[ event.type ];
  240. if ( listenerArray !== undefined ) {
  241. event.target = this;
  242. // Make a copy, in case listeners are removed while iterating.
  243. const array = listenerArray.slice( 0 );
  244. for ( let i = 0, l = array.length; i < l; i ++ ) {
  245. array[ i ].call( this, event );
  246. }
  247. event.target = null;
  248. }
  249. }
  250. }
  251. const _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ];
  252. let _seed = 1234567;
  253. const DEG2RAD = Math.PI / 180;
  254. const RAD2DEG = 180 / Math.PI;
  255. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  256. function generateUUID() {
  257. const d0 = Math.random() * 0xffffffff | 0;
  258. const d1 = Math.random() * 0xffffffff | 0;
  259. const d2 = Math.random() * 0xffffffff | 0;
  260. const d3 = Math.random() * 0xffffffff | 0;
  261. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  262. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  263. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  264. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  265. // .toLowerCase() here flattens concatenated strings to save heap memory space.
  266. return uuid.toLowerCase();
  267. }
  268. function clamp( value, min, max ) {
  269. return Math.max( min, Math.min( max, value ) );
  270. }
  271. // compute euclidean modulo of m % n
  272. // https://en.wikipedia.org/wiki/Modulo_operation
  273. function euclideanModulo( n, m ) {
  274. return ( ( n % m ) + m ) % m;
  275. }
  276. // Linear mapping from range <a1, a2> to range <b1, b2>
  277. function mapLinear( x, a1, a2, b1, b2 ) {
  278. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  279. }
  280. // https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/
  281. function inverseLerp( x, y, value ) {
  282. if ( x !== y ) {
  283. return ( value - x ) / ( y - x );
  284. } else {
  285. return 0;
  286. }
  287. }
  288. // https://en.wikipedia.org/wiki/Linear_interpolation
  289. function lerp( x, y, t ) {
  290. return ( 1 - t ) * x + t * y;
  291. }
  292. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  293. function damp( x, y, lambda, dt ) {
  294. return lerp( x, y, 1 - Math.exp( - lambda * dt ) );
  295. }
  296. // https://www.desmos.com/calculator/vcsjnyz7x4
  297. function pingpong( x, length = 1 ) {
  298. return length - Math.abs( euclideanModulo( x, length * 2 ) - length );
  299. }
  300. // http://en.wikipedia.org/wiki/Smoothstep
  301. function smoothstep( x, min, max ) {
  302. if ( x <= min ) return 0;
  303. if ( x >= max ) return 1;
  304. x = ( x - min ) / ( max - min );
  305. return x * x * ( 3 - 2 * x );
  306. }
  307. function smootherstep( x, min, max ) {
  308. if ( x <= min ) return 0;
  309. if ( x >= max ) return 1;
  310. x = ( x - min ) / ( max - min );
  311. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  312. }
  313. // Random integer from <low, high> interval
  314. function randInt( low, high ) {
  315. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  316. }
  317. // Random float from <low, high> interval
  318. function randFloat( low, high ) {
  319. return low + Math.random() * ( high - low );
  320. }
  321. // Random float from <-range/2, range/2> interval
  322. function randFloatSpread( range ) {
  323. return range * ( 0.5 - Math.random() );
  324. }
  325. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  326. function seededRandom( s ) {
  327. if ( s !== undefined ) _seed = s;
  328. // Mulberry32 generator
  329. let t = _seed += 0x6D2B79F5;
  330. t = Math.imul( t ^ t >>> 15, t | 1 );
  331. t ^= t + Math.imul( t ^ t >>> 7, t | 61 );
  332. return ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296;
  333. }
  334. function degToRad( degrees ) {
  335. return degrees * DEG2RAD;
  336. }
  337. function radToDeg( radians ) {
  338. return radians * RAD2DEG;
  339. }
  340. function isPowerOfTwo( value ) {
  341. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  342. }
  343. function ceilPowerOfTwo( value ) {
  344. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  345. }
  346. function floorPowerOfTwo( value ) {
  347. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  348. }
  349. function setQuaternionFromProperEuler( q, a, b, c, order ) {
  350. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  351. // rotations are applied to the axes in the order specified by 'order'
  352. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  353. // angles are in radians
  354. const cos = Math.cos;
  355. const sin = Math.sin;
  356. const c2 = cos( b / 2 );
  357. const s2 = sin( b / 2 );
  358. const c13 = cos( ( a + c ) / 2 );
  359. const s13 = sin( ( a + c ) / 2 );
  360. const c1_3 = cos( ( a - c ) / 2 );
  361. const s1_3 = sin( ( a - c ) / 2 );
  362. const c3_1 = cos( ( c - a ) / 2 );
  363. const s3_1 = sin( ( c - a ) / 2 );
  364. switch ( order ) {
  365. case 'XYX':
  366. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  367. break;
  368. case 'YZY':
  369. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  370. break;
  371. case 'ZXZ':
  372. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  373. break;
  374. case 'XZX':
  375. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  376. break;
  377. case 'YXY':
  378. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  379. break;
  380. case 'ZYZ':
  381. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  382. break;
  383. default:
  384. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  385. }
  386. }
  387. function denormalize( value, array ) {
  388. switch ( array.constructor ) {
  389. case Float32Array:
  390. return value;
  391. case Uint32Array:
  392. return value / 4294967295.0;
  393. case Uint16Array:
  394. return value / 65535.0;
  395. case Uint8Array:
  396. return value / 255.0;
  397. case Int32Array:
  398. return Math.max( value / 2147483647.0, - 1.0 );
  399. case Int16Array:
  400. return Math.max( value / 32767.0, - 1.0 );
  401. case Int8Array:
  402. return Math.max( value / 127.0, - 1.0 );
  403. default:
  404. throw new Error( 'Invalid component type.' );
  405. }
  406. }
  407. function normalize( value, array ) {
  408. switch ( array.constructor ) {
  409. case Float32Array:
  410. return value;
  411. case Uint32Array:
  412. return Math.round( value * 4294967295.0 );
  413. case Uint16Array:
  414. return Math.round( value * 65535.0 );
  415. case Uint8Array:
  416. return Math.round( value * 255.0 );
  417. case Int32Array:
  418. return Math.round( value * 2147483647.0 );
  419. case Int16Array:
  420. return Math.round( value * 32767.0 );
  421. case Int8Array:
  422. return Math.round( value * 127.0 );
  423. default:
  424. throw new Error( 'Invalid component type.' );
  425. }
  426. }
  427. const MathUtils = {
  428. DEG2RAD: DEG2RAD,
  429. RAD2DEG: RAD2DEG,
  430. generateUUID: generateUUID,
  431. clamp: clamp,
  432. euclideanModulo: euclideanModulo,
  433. mapLinear: mapLinear,
  434. inverseLerp: inverseLerp,
  435. lerp: lerp,
  436. damp: damp,
  437. pingpong: pingpong,
  438. smoothstep: smoothstep,
  439. smootherstep: smootherstep,
  440. randInt: randInt,
  441. randFloat: randFloat,
  442. randFloatSpread: randFloatSpread,
  443. seededRandom: seededRandom,
  444. degToRad: degToRad,
  445. radToDeg: radToDeg,
  446. isPowerOfTwo: isPowerOfTwo,
  447. ceilPowerOfTwo: ceilPowerOfTwo,
  448. floorPowerOfTwo: floorPowerOfTwo,
  449. setQuaternionFromProperEuler: setQuaternionFromProperEuler,
  450. normalize: normalize,
  451. denormalize: denormalize
  452. };
  453. class Vector2 {
  454. constructor( x = 0, y = 0 ) {
  455. Vector2.prototype.isVector2 = true;
  456. this.x = x;
  457. this.y = y;
  458. }
  459. get width() {
  460. return this.x;
  461. }
  462. set width( value ) {
  463. this.x = value;
  464. }
  465. get height() {
  466. return this.y;
  467. }
  468. set height( value ) {
  469. this.y = value;
  470. }
  471. set( x, y ) {
  472. this.x = x;
  473. this.y = y;
  474. return this;
  475. }
  476. setScalar( scalar ) {
  477. this.x = scalar;
  478. this.y = scalar;
  479. return this;
  480. }
  481. setX( x ) {
  482. this.x = x;
  483. return this;
  484. }
  485. setY( y ) {
  486. this.y = y;
  487. return this;
  488. }
  489. setComponent( index, value ) {
  490. switch ( index ) {
  491. case 0: this.x = value; break;
  492. case 1: this.y = value; break;
  493. default: throw new Error( 'index is out of range: ' + index );
  494. }
  495. return this;
  496. }
  497. getComponent( index ) {
  498. switch ( index ) {
  499. case 0: return this.x;
  500. case 1: return this.y;
  501. default: throw new Error( 'index is out of range: ' + index );
  502. }
  503. }
  504. clone() {
  505. return new this.constructor( this.x, this.y );
  506. }
  507. copy( v ) {
  508. this.x = v.x;
  509. this.y = v.y;
  510. return this;
  511. }
  512. add( v ) {
  513. this.x += v.x;
  514. this.y += v.y;
  515. return this;
  516. }
  517. addScalar( s ) {
  518. this.x += s;
  519. this.y += s;
  520. return this;
  521. }
  522. addVectors( a, b ) {
  523. this.x = a.x + b.x;
  524. this.y = a.y + b.y;
  525. return this;
  526. }
  527. addScaledVector( v, s ) {
  528. this.x += v.x * s;
  529. this.y += v.y * s;
  530. return this;
  531. }
  532. sub( v ) {
  533. this.x -= v.x;
  534. this.y -= v.y;
  535. return this;
  536. }
  537. subScalar( s ) {
  538. this.x -= s;
  539. this.y -= s;
  540. return this;
  541. }
  542. subVectors( a, b ) {
  543. this.x = a.x - b.x;
  544. this.y = a.y - b.y;
  545. return this;
  546. }
  547. multiply( v ) {
  548. this.x *= v.x;
  549. this.y *= v.y;
  550. return this;
  551. }
  552. multiplyScalar( scalar ) {
  553. this.x *= scalar;
  554. this.y *= scalar;
  555. return this;
  556. }
  557. divide( v ) {
  558. this.x /= v.x;
  559. this.y /= v.y;
  560. return this;
  561. }
  562. divideScalar( scalar ) {
  563. return this.multiplyScalar( 1 / scalar );
  564. }
  565. applyMatrix3( m ) {
  566. const x = this.x, y = this.y;
  567. const e = m.elements;
  568. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  569. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  570. return this;
  571. }
  572. min( v ) {
  573. this.x = Math.min( this.x, v.x );
  574. this.y = Math.min( this.y, v.y );
  575. return this;
  576. }
  577. max( v ) {
  578. this.x = Math.max( this.x, v.x );
  579. this.y = Math.max( this.y, v.y );
  580. return this;
  581. }
  582. clamp( min, max ) {
  583. // assumes min < max, componentwise
  584. this.x = clamp( this.x, min.x, max.x );
  585. this.y = clamp( this.y, min.y, max.y );
  586. return this;
  587. }
  588. clampScalar( minVal, maxVal ) {
  589. this.x = clamp( this.x, minVal, maxVal );
  590. this.y = clamp( this.y, minVal, maxVal );
  591. return this;
  592. }
  593. clampLength( min, max ) {
  594. const length = this.length();
  595. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  596. }
  597. floor() {
  598. this.x = Math.floor( this.x );
  599. this.y = Math.floor( this.y );
  600. return this;
  601. }
  602. ceil() {
  603. this.x = Math.ceil( this.x );
  604. this.y = Math.ceil( this.y );
  605. return this;
  606. }
  607. round() {
  608. this.x = Math.round( this.x );
  609. this.y = Math.round( this.y );
  610. return this;
  611. }
  612. roundToZero() {
  613. this.x = Math.trunc( this.x );
  614. this.y = Math.trunc( this.y );
  615. return this;
  616. }
  617. negate() {
  618. this.x = - this.x;
  619. this.y = - this.y;
  620. return this;
  621. }
  622. dot( v ) {
  623. return this.x * v.x + this.y * v.y;
  624. }
  625. cross( v ) {
  626. return this.x * v.y - this.y * v.x;
  627. }
  628. lengthSq() {
  629. return this.x * this.x + this.y * this.y;
  630. }
  631. length() {
  632. return Math.sqrt( this.x * this.x + this.y * this.y );
  633. }
  634. manhattanLength() {
  635. return Math.abs( this.x ) + Math.abs( this.y );
  636. }
  637. normalize() {
  638. return this.divideScalar( this.length() || 1 );
  639. }
  640. angle() {
  641. // computes the angle in radians with respect to the positive x-axis
  642. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  643. return angle;
  644. }
  645. angleTo( v ) {
  646. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  647. if ( denominator === 0 ) return Math.PI / 2;
  648. const theta = this.dot( v ) / denominator;
  649. // clamp, to handle numerical problems
  650. return Math.acos( clamp( theta, - 1, 1 ) );
  651. }
  652. distanceTo( v ) {
  653. return Math.sqrt( this.distanceToSquared( v ) );
  654. }
  655. distanceToSquared( v ) {
  656. const dx = this.x - v.x, dy = this.y - v.y;
  657. return dx * dx + dy * dy;
  658. }
  659. manhattanDistanceTo( v ) {
  660. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  661. }
  662. setLength( length ) {
  663. return this.normalize().multiplyScalar( length );
  664. }
  665. lerp( v, alpha ) {
  666. this.x += ( v.x - this.x ) * alpha;
  667. this.y += ( v.y - this.y ) * alpha;
  668. return this;
  669. }
  670. lerpVectors( v1, v2, alpha ) {
  671. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  672. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  673. return this;
  674. }
  675. equals( v ) {
  676. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  677. }
  678. fromArray( array, offset = 0 ) {
  679. this.x = array[ offset ];
  680. this.y = array[ offset + 1 ];
  681. return this;
  682. }
  683. toArray( array = [], offset = 0 ) {
  684. array[ offset ] = this.x;
  685. array[ offset + 1 ] = this.y;
  686. return array;
  687. }
  688. fromBufferAttribute( attribute, index ) {
  689. this.x = attribute.getX( index );
  690. this.y = attribute.getY( index );
  691. return this;
  692. }
  693. rotateAround( center, angle ) {
  694. const c = Math.cos( angle ), s = Math.sin( angle );
  695. const x = this.x - center.x;
  696. const y = this.y - center.y;
  697. this.x = x * c - y * s + center.x;
  698. this.y = x * s + y * c + center.y;
  699. return this;
  700. }
  701. random() {
  702. this.x = Math.random();
  703. this.y = Math.random();
  704. return this;
  705. }
  706. *[ Symbol.iterator ]() {
  707. yield this.x;
  708. yield this.y;
  709. }
  710. }
  711. class Matrix3 {
  712. constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  713. Matrix3.prototype.isMatrix3 = true;
  714. this.elements = [
  715. 1, 0, 0,
  716. 0, 1, 0,
  717. 0, 0, 1
  718. ];
  719. if ( n11 !== undefined ) {
  720. this.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 );
  721. }
  722. }
  723. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  724. const te = this.elements;
  725. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  726. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  727. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  728. return this;
  729. }
  730. identity() {
  731. this.set(
  732. 1, 0, 0,
  733. 0, 1, 0,
  734. 0, 0, 1
  735. );
  736. return this;
  737. }
  738. copy( m ) {
  739. const te = this.elements;
  740. const me = m.elements;
  741. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  742. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  743. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  744. return this;
  745. }
  746. extractBasis( xAxis, yAxis, zAxis ) {
  747. xAxis.setFromMatrix3Column( this, 0 );
  748. yAxis.setFromMatrix3Column( this, 1 );
  749. zAxis.setFromMatrix3Column( this, 2 );
  750. return this;
  751. }
  752. setFromMatrix4( m ) {
  753. const me = m.elements;
  754. this.set(
  755. me[ 0 ], me[ 4 ], me[ 8 ],
  756. me[ 1 ], me[ 5 ], me[ 9 ],
  757. me[ 2 ], me[ 6 ], me[ 10 ]
  758. );
  759. return this;
  760. }
  761. multiply( m ) {
  762. return this.multiplyMatrices( this, m );
  763. }
  764. premultiply( m ) {
  765. return this.multiplyMatrices( m, this );
  766. }
  767. multiplyMatrices( a, b ) {
  768. const ae = a.elements;
  769. const be = b.elements;
  770. const te = this.elements;
  771. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  772. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  773. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  774. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  775. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  776. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  777. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  778. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  779. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  780. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  781. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  782. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  783. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  784. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  785. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  786. return this;
  787. }
  788. multiplyScalar( s ) {
  789. const te = this.elements;
  790. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  791. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  792. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  793. return this;
  794. }
  795. determinant() {
  796. const te = this.elements;
  797. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  798. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  799. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  800. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  801. }
  802. invert() {
  803. const te = this.elements,
  804. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  805. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  806. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  807. t11 = n33 * n22 - n32 * n23,
  808. t12 = n32 * n13 - n33 * n12,
  809. t13 = n23 * n12 - n22 * n13,
  810. det = n11 * t11 + n21 * t12 + n31 * t13;
  811. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  812. const detInv = 1 / det;
  813. te[ 0 ] = t11 * detInv;
  814. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  815. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  816. te[ 3 ] = t12 * detInv;
  817. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  818. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  819. te[ 6 ] = t13 * detInv;
  820. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  821. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  822. return this;
  823. }
  824. transpose() {
  825. let tmp;
  826. const m = this.elements;
  827. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  828. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  829. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  830. return this;
  831. }
  832. getNormalMatrix( matrix4 ) {
  833. return this.setFromMatrix4( matrix4 ).invert().transpose();
  834. }
  835. transposeIntoArray( r ) {
  836. const m = this.elements;
  837. r[ 0 ] = m[ 0 ];
  838. r[ 1 ] = m[ 3 ];
  839. r[ 2 ] = m[ 6 ];
  840. r[ 3 ] = m[ 1 ];
  841. r[ 4 ] = m[ 4 ];
  842. r[ 5 ] = m[ 7 ];
  843. r[ 6 ] = m[ 2 ];
  844. r[ 7 ] = m[ 5 ];
  845. r[ 8 ] = m[ 8 ];
  846. return this;
  847. }
  848. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  849. const c = Math.cos( rotation );
  850. const s = Math.sin( rotation );
  851. this.set(
  852. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  853. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  854. 0, 0, 1
  855. );
  856. return this;
  857. }
  858. //
  859. scale( sx, sy ) {
  860. this.premultiply( _m3.makeScale( sx, sy ) );
  861. return this;
  862. }
  863. rotate( theta ) {
  864. this.premultiply( _m3.makeRotation( - theta ) );
  865. return this;
  866. }
  867. translate( tx, ty ) {
  868. this.premultiply( _m3.makeTranslation( tx, ty ) );
  869. return this;
  870. }
  871. // for 2D Transforms
  872. makeTranslation( x, y ) {
  873. if ( x.isVector2 ) {
  874. this.set(
  875. 1, 0, x.x,
  876. 0, 1, x.y,
  877. 0, 0, 1
  878. );
  879. } else {
  880. this.set(
  881. 1, 0, x,
  882. 0, 1, y,
  883. 0, 0, 1
  884. );
  885. }
  886. return this;
  887. }
  888. makeRotation( theta ) {
  889. // counterclockwise
  890. const c = Math.cos( theta );
  891. const s = Math.sin( theta );
  892. this.set(
  893. c, - s, 0,
  894. s, c, 0,
  895. 0, 0, 1
  896. );
  897. return this;
  898. }
  899. makeScale( x, y ) {
  900. this.set(
  901. x, 0, 0,
  902. 0, y, 0,
  903. 0, 0, 1
  904. );
  905. return this;
  906. }
  907. //
  908. equals( matrix ) {
  909. const te = this.elements;
  910. const me = matrix.elements;
  911. for ( let i = 0; i < 9; i ++ ) {
  912. if ( te[ i ] !== me[ i ] ) return false;
  913. }
  914. return true;
  915. }
  916. fromArray( array, offset = 0 ) {
  917. for ( let i = 0; i < 9; i ++ ) {
  918. this.elements[ i ] = array[ i + offset ];
  919. }
  920. return this;
  921. }
  922. toArray( array = [], offset = 0 ) {
  923. const te = this.elements;
  924. array[ offset ] = te[ 0 ];
  925. array[ offset + 1 ] = te[ 1 ];
  926. array[ offset + 2 ] = te[ 2 ];
  927. array[ offset + 3 ] = te[ 3 ];
  928. array[ offset + 4 ] = te[ 4 ];
  929. array[ offset + 5 ] = te[ 5 ];
  930. array[ offset + 6 ] = te[ 6 ];
  931. array[ offset + 7 ] = te[ 7 ];
  932. array[ offset + 8 ] = te[ 8 ];
  933. return array;
  934. }
  935. clone() {
  936. return new this.constructor().fromArray( this.elements );
  937. }
  938. }
  939. const _m3 = /*@__PURE__*/ new Matrix3();
  940. function arrayNeedsUint32( array ) {
  941. // assumes larger values usually on last
  942. for ( let i = array.length - 1; i >= 0; -- i ) {
  943. if ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565
  944. }
  945. return false;
  946. }
  947. const TYPED_ARRAYS = {
  948. Int8Array: Int8Array,
  949. Uint8Array: Uint8Array,
  950. Uint8ClampedArray: Uint8ClampedArray,
  951. Int16Array: Int16Array,
  952. Uint16Array: Uint16Array,
  953. Int32Array: Int32Array,
  954. Uint32Array: Uint32Array,
  955. Float32Array: Float32Array,
  956. Float64Array: Float64Array
  957. };
  958. function getTypedArray( type, buffer ) {
  959. return new TYPED_ARRAYS[ type ]( buffer );
  960. }
  961. function createElementNS( name ) {
  962. return document.createElementNS( 'http://www.w3.org/1999/xhtml', name );
  963. }
  964. function createCanvasElement() {
  965. const canvas = createElementNS( 'canvas' );
  966. canvas.style.display = 'block';
  967. return canvas;
  968. }
  969. const _cache = {};
  970. function warnOnce( message ) {
  971. if ( message in _cache ) return;
  972. _cache[ message ] = true;
  973. console.warn( message );
  974. }
  975. function probeAsync( gl, sync, interval ) {
  976. return new Promise( function ( resolve, reject ) {
  977. function probe() {
  978. switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {
  979. case gl.WAIT_FAILED:
  980. reject();
  981. break;
  982. case gl.TIMEOUT_EXPIRED:
  983. setTimeout( probe, interval );
  984. break;
  985. default:
  986. resolve();
  987. }
  988. }
  989. setTimeout( probe, interval );
  990. } );
  991. }
  992. function toNormalizedProjectionMatrix( projectionMatrix ) {
  993. const m = projectionMatrix.elements;
  994. // Convert [-1, 1] to [0, 1] projection matrix
  995. m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ];
  996. m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ];
  997. m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ];
  998. m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ];
  999. }
  1000. function toReversedProjectionMatrix( projectionMatrix ) {
  1001. const m = projectionMatrix.elements;
  1002. const isPerspectiveMatrix = m[ 11 ] === - 1;
  1003. // Reverse [0, 1] projection matrix
  1004. if ( isPerspectiveMatrix ) {
  1005. m[ 10 ] = - m[ 10 ] - 1;
  1006. m[ 14 ] = - m[ 14 ];
  1007. } else {
  1008. m[ 10 ] = - m[ 10 ];
  1009. m[ 14 ] = - m[ 14 ] + 1;
  1010. }
  1011. }
  1012. const LINEAR_REC709_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  1013. 0.4123908, 0.3575843, 0.1804808,
  1014. 0.2126390, 0.7151687, 0.0721923,
  1015. 0.0193308, 0.1191948, 0.9505322
  1016. );
  1017. const XYZ_TO_LINEAR_REC709 = /*@__PURE__*/ new Matrix3().set(
  1018. 3.2409699, - 1.5373832, - 0.4986108,
  1019. - 0.9692436, 1.8759675, 0.0415551,
  1020. 0.0556301, - 0.2039770, 1.0569715
  1021. );
  1022. function createColorManagement() {
  1023. const ColorManagement = {
  1024. enabled: true,
  1025. workingColorSpace: LinearSRGBColorSpace,
  1026. /**
  1027. * Implementations of supported color spaces.
  1028. *
  1029. * Required:
  1030. * - primaries: chromaticity coordinates [ rx ry gx gy bx by ]
  1031. * - whitePoint: reference white [ x y ]
  1032. * - transfer: transfer function (pre-defined)
  1033. * - toXYZ: Matrix3 RGB to XYZ transform
  1034. * - fromXYZ: Matrix3 XYZ to RGB transform
  1035. * - luminanceCoefficients: RGB luminance coefficients
  1036. *
  1037. * Optional:
  1038. * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
  1039. * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
  1040. *
  1041. * Reference:
  1042. * - https://www.russellcottrell.com/photo/matrixCalculator.htm
  1043. */
  1044. spaces: {},
  1045. convert: function ( color, sourceColorSpace, targetColorSpace ) {
  1046. if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {
  1047. return color;
  1048. }
  1049. if ( this.spaces[ sourceColorSpace ].transfer === SRGBTransfer ) {
  1050. color.r = SRGBToLinear( color.r );
  1051. color.g = SRGBToLinear( color.g );
  1052. color.b = SRGBToLinear( color.b );
  1053. }
  1054. if ( this.spaces[ sourceColorSpace ].primaries !== this.spaces[ targetColorSpace ].primaries ) {
  1055. color.applyMatrix3( this.spaces[ sourceColorSpace ].toXYZ );
  1056. color.applyMatrix3( this.spaces[ targetColorSpace ].fromXYZ );
  1057. }
  1058. if ( this.spaces[ targetColorSpace ].transfer === SRGBTransfer ) {
  1059. color.r = LinearToSRGB( color.r );
  1060. color.g = LinearToSRGB( color.g );
  1061. color.b = LinearToSRGB( color.b );
  1062. }
  1063. return color;
  1064. },
  1065. fromWorkingColorSpace: function ( color, targetColorSpace ) {
  1066. return this.convert( color, this.workingColorSpace, targetColorSpace );
  1067. },
  1068. toWorkingColorSpace: function ( color, sourceColorSpace ) {
  1069. return this.convert( color, sourceColorSpace, this.workingColorSpace );
  1070. },
  1071. getPrimaries: function ( colorSpace ) {
  1072. return this.spaces[ colorSpace ].primaries;
  1073. },
  1074. getTransfer: function ( colorSpace ) {
  1075. if ( colorSpace === NoColorSpace ) return LinearTransfer;
  1076. return this.spaces[ colorSpace ].transfer;
  1077. },
  1078. getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {
  1079. return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
  1080. },
  1081. define: function ( colorSpaces ) {
  1082. Object.assign( this.spaces, colorSpaces );
  1083. },
  1084. // Internal APIs
  1085. _getMatrix: function ( targetMatrix, sourceColorSpace, targetColorSpace ) {
  1086. return targetMatrix
  1087. .copy( this.spaces[ sourceColorSpace ].toXYZ )
  1088. .multiply( this.spaces[ targetColorSpace ].fromXYZ );
  1089. },
  1090. _getDrawingBufferColorSpace: function ( colorSpace ) {
  1091. return this.spaces[ colorSpace ].outputColorSpaceConfig.drawingBufferColorSpace;
  1092. },
  1093. _getUnpackColorSpace: function ( colorSpace = this.workingColorSpace ) {
  1094. return this.spaces[ colorSpace ].workingColorSpaceConfig.unpackColorSpace;
  1095. }
  1096. };
  1097. /******************************************************************************
  1098. * sRGB definitions
  1099. */
  1100. const REC709_PRIMARIES = [ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 ];
  1101. const REC709_LUMINANCE_COEFFICIENTS = [ 0.2126, 0.7152, 0.0722 ];
  1102. const D65 = [ 0.3127, 0.3290 ];
  1103. ColorManagement.define( {
  1104. [ LinearSRGBColorSpace ]: {
  1105. primaries: REC709_PRIMARIES,
  1106. whitePoint: D65,
  1107. transfer: LinearTransfer,
  1108. toXYZ: LINEAR_REC709_TO_XYZ,
  1109. fromXYZ: XYZ_TO_LINEAR_REC709,
  1110. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1111. workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
  1112. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1113. },
  1114. [ SRGBColorSpace ]: {
  1115. primaries: REC709_PRIMARIES,
  1116. whitePoint: D65,
  1117. transfer: SRGBTransfer,
  1118. toXYZ: LINEAR_REC709_TO_XYZ,
  1119. fromXYZ: XYZ_TO_LINEAR_REC709,
  1120. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1121. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1122. },
  1123. } );
  1124. return ColorManagement;
  1125. }
  1126. const ColorManagement = /*@__PURE__*/ createColorManagement();
  1127. function SRGBToLinear( c ) {
  1128. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  1129. }
  1130. function LinearToSRGB( c ) {
  1131. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  1132. }
  1133. let _canvas;
  1134. class ImageUtils {
  1135. static getDataURL( image ) {
  1136. if ( /^data:/i.test( image.src ) ) {
  1137. return image.src;
  1138. }
  1139. if ( typeof HTMLCanvasElement === 'undefined' ) {
  1140. return image.src;
  1141. }
  1142. let canvas;
  1143. if ( image instanceof HTMLCanvasElement ) {
  1144. canvas = image;
  1145. } else {
  1146. if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );
  1147. _canvas.width = image.width;
  1148. _canvas.height = image.height;
  1149. const context = _canvas.getContext( '2d' );
  1150. if ( image instanceof ImageData ) {
  1151. context.putImageData( image, 0, 0 );
  1152. } else {
  1153. context.drawImage( image, 0, 0, image.width, image.height );
  1154. }
  1155. canvas = _canvas;
  1156. }
  1157. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1158. console.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image );
  1159. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1160. } else {
  1161. return canvas.toDataURL( 'image/png' );
  1162. }
  1163. }
  1164. static sRGBToLinear( image ) {
  1165. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1166. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1167. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1168. const canvas = createElementNS( 'canvas' );
  1169. canvas.width = image.width;
  1170. canvas.height = image.height;
  1171. const context = canvas.getContext( '2d' );
  1172. context.drawImage( image, 0, 0, image.width, image.height );
  1173. const imageData = context.getImageData( 0, 0, image.width, image.height );
  1174. const data = imageData.data;
  1175. for ( let i = 0; i < data.length; i ++ ) {
  1176. data[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255;
  1177. }
  1178. context.putImageData( imageData, 0, 0 );
  1179. return canvas;
  1180. } else if ( image.data ) {
  1181. const data = image.data.slice( 0 );
  1182. for ( let i = 0; i < data.length; i ++ ) {
  1183. if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {
  1184. data[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 );
  1185. } else {
  1186. // assuming float
  1187. data[ i ] = SRGBToLinear( data[ i ] );
  1188. }
  1189. }
  1190. return {
  1191. data: data,
  1192. width: image.width,
  1193. height: image.height
  1194. };
  1195. } else {
  1196. console.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' );
  1197. return image;
  1198. }
  1199. }
  1200. }
  1201. let _sourceId = 0;
  1202. class Source {
  1203. constructor( data = null ) {
  1204. this.isSource = true;
  1205. Object.defineProperty( this, 'id', { value: _sourceId ++ } );
  1206. this.uuid = generateUUID();
  1207. this.data = data;
  1208. this.dataReady = true;
  1209. this.version = 0;
  1210. }
  1211. set needsUpdate( value ) {
  1212. if ( value === true ) this.version ++;
  1213. }
  1214. toJSON( meta ) {
  1215. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1216. if ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) {
  1217. return meta.images[ this.uuid ];
  1218. }
  1219. const output = {
  1220. uuid: this.uuid,
  1221. url: ''
  1222. };
  1223. const data = this.data;
  1224. if ( data !== null ) {
  1225. let url;
  1226. if ( Array.isArray( data ) ) {
  1227. // cube texture
  1228. url = [];
  1229. for ( let i = 0, l = data.length; i < l; i ++ ) {
  1230. if ( data[ i ].isDataTexture ) {
  1231. url.push( serializeImage( data[ i ].image ) );
  1232. } else {
  1233. url.push( serializeImage( data[ i ] ) );
  1234. }
  1235. }
  1236. } else {
  1237. // texture
  1238. url = serializeImage( data );
  1239. }
  1240. output.url = url;
  1241. }
  1242. if ( ! isRootObject ) {
  1243. meta.images[ this.uuid ] = output;
  1244. }
  1245. return output;
  1246. }
  1247. }
  1248. function serializeImage( image ) {
  1249. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1250. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1251. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1252. // default images
  1253. return ImageUtils.getDataURL( image );
  1254. } else {
  1255. if ( image.data ) {
  1256. // images of DataTexture
  1257. return {
  1258. data: Array.from( image.data ),
  1259. width: image.width,
  1260. height: image.height,
  1261. type: image.data.constructor.name
  1262. };
  1263. } else {
  1264. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1265. return {};
  1266. }
  1267. }
  1268. }
  1269. let _textureId = 0;
  1270. class Texture extends EventDispatcher {
  1271. constructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace ) {
  1272. super();
  1273. this.isTexture = true;
  1274. Object.defineProperty( this, 'id', { value: _textureId ++ } );
  1275. this.uuid = generateUUID();
  1276. this.name = '';
  1277. this.source = new Source( image );
  1278. this.mipmaps = [];
  1279. this.mapping = mapping;
  1280. this.channel = 0;
  1281. this.wrapS = wrapS;
  1282. this.wrapT = wrapT;
  1283. this.magFilter = magFilter;
  1284. this.minFilter = minFilter;
  1285. this.anisotropy = anisotropy;
  1286. this.format = format;
  1287. this.internalFormat = null;
  1288. this.type = type;
  1289. this.offset = new Vector2( 0, 0 );
  1290. this.repeat = new Vector2( 1, 1 );
  1291. this.center = new Vector2( 0, 0 );
  1292. this.rotation = 0;
  1293. this.matrixAutoUpdate = true;
  1294. this.matrix = new Matrix3();
  1295. this.generateMipmaps = true;
  1296. this.premultiplyAlpha = false;
  1297. this.flipY = true;
  1298. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1299. this.colorSpace = colorSpace;
  1300. this.userData = {};
  1301. this.version = 0;
  1302. this.onUpdate = null;
  1303. this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
  1304. this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
  1305. }
  1306. get image() {
  1307. return this.source.data;
  1308. }
  1309. set image( value = null ) {
  1310. this.source.data = value;
  1311. }
  1312. updateMatrix() {
  1313. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1314. }
  1315. clone() {
  1316. return new this.constructor().copy( this );
  1317. }
  1318. copy( source ) {
  1319. this.name = source.name;
  1320. this.source = source.source;
  1321. this.mipmaps = source.mipmaps.slice( 0 );
  1322. this.mapping = source.mapping;
  1323. this.channel = source.channel;
  1324. this.wrapS = source.wrapS;
  1325. this.wrapT = source.wrapT;
  1326. this.magFilter = source.magFilter;
  1327. this.minFilter = source.minFilter;
  1328. this.anisotropy = source.anisotropy;
  1329. this.format = source.format;
  1330. this.internalFormat = source.internalFormat;
  1331. this.type = source.type;
  1332. this.offset.copy( source.offset );
  1333. this.repeat.copy( source.repeat );
  1334. this.center.copy( source.center );
  1335. this.rotation = source.rotation;
  1336. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1337. this.matrix.copy( source.matrix );
  1338. this.generateMipmaps = source.generateMipmaps;
  1339. this.premultiplyAlpha = source.premultiplyAlpha;
  1340. this.flipY = source.flipY;
  1341. this.unpackAlignment = source.unpackAlignment;
  1342. this.colorSpace = source.colorSpace;
  1343. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  1344. this.needsUpdate = true;
  1345. return this;
  1346. }
  1347. toJSON( meta ) {
  1348. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1349. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1350. return meta.textures[ this.uuid ];
  1351. }
  1352. const output = {
  1353. metadata: {
  1354. version: 4.6,
  1355. type: 'Texture',
  1356. generator: 'Texture.toJSON'
  1357. },
  1358. uuid: this.uuid,
  1359. name: this.name,
  1360. image: this.source.toJSON( meta ).uuid,
  1361. mapping: this.mapping,
  1362. channel: this.channel,
  1363. repeat: [ this.repeat.x, this.repeat.y ],
  1364. offset: [ this.offset.x, this.offset.y ],
  1365. center: [ this.center.x, this.center.y ],
  1366. rotation: this.rotation,
  1367. wrap: [ this.wrapS, this.wrapT ],
  1368. format: this.format,
  1369. internalFormat: this.internalFormat,
  1370. type: this.type,
  1371. colorSpace: this.colorSpace,
  1372. minFilter: this.minFilter,
  1373. magFilter: this.magFilter,
  1374. anisotropy: this.anisotropy,
  1375. flipY: this.flipY,
  1376. generateMipmaps: this.generateMipmaps,
  1377. premultiplyAlpha: this.premultiplyAlpha,
  1378. unpackAlignment: this.unpackAlignment
  1379. };
  1380. if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;
  1381. if ( ! isRootObject ) {
  1382. meta.textures[ this.uuid ] = output;
  1383. }
  1384. return output;
  1385. }
  1386. dispose() {
  1387. this.dispatchEvent( { type: 'dispose' } );
  1388. }
  1389. transformUv( uv ) {
  1390. if ( this.mapping !== UVMapping ) return uv;
  1391. uv.applyMatrix3( this.matrix );
  1392. if ( uv.x < 0 || uv.x > 1 ) {
  1393. switch ( this.wrapS ) {
  1394. case RepeatWrapping:
  1395. uv.x = uv.x - Math.floor( uv.x );
  1396. break;
  1397. case ClampToEdgeWrapping:
  1398. uv.x = uv.x < 0 ? 0 : 1;
  1399. break;
  1400. case MirroredRepeatWrapping:
  1401. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1402. uv.x = Math.ceil( uv.x ) - uv.x;
  1403. } else {
  1404. uv.x = uv.x - Math.floor( uv.x );
  1405. }
  1406. break;
  1407. }
  1408. }
  1409. if ( uv.y < 0 || uv.y > 1 ) {
  1410. switch ( this.wrapT ) {
  1411. case RepeatWrapping:
  1412. uv.y = uv.y - Math.floor( uv.y );
  1413. break;
  1414. case ClampToEdgeWrapping:
  1415. uv.y = uv.y < 0 ? 0 : 1;
  1416. break;
  1417. case MirroredRepeatWrapping:
  1418. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1419. uv.y = Math.ceil( uv.y ) - uv.y;
  1420. } else {
  1421. uv.y = uv.y - Math.floor( uv.y );
  1422. }
  1423. break;
  1424. }
  1425. }
  1426. if ( this.flipY ) {
  1427. uv.y = 1 - uv.y;
  1428. }
  1429. return uv;
  1430. }
  1431. set needsUpdate( value ) {
  1432. if ( value === true ) {
  1433. this.version ++;
  1434. this.source.needsUpdate = true;
  1435. }
  1436. }
  1437. set needsPMREMUpdate( value ) {
  1438. if ( value === true ) {
  1439. this.pmremVersion ++;
  1440. }
  1441. }
  1442. }
  1443. Texture.DEFAULT_IMAGE = null;
  1444. Texture.DEFAULT_MAPPING = UVMapping;
  1445. Texture.DEFAULT_ANISOTROPY = 1;
  1446. class Vector4 {
  1447. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1448. Vector4.prototype.isVector4 = true;
  1449. this.x = x;
  1450. this.y = y;
  1451. this.z = z;
  1452. this.w = w;
  1453. }
  1454. get width() {
  1455. return this.z;
  1456. }
  1457. set width( value ) {
  1458. this.z = value;
  1459. }
  1460. get height() {
  1461. return this.w;
  1462. }
  1463. set height( value ) {
  1464. this.w = value;
  1465. }
  1466. set( x, y, z, w ) {
  1467. this.x = x;
  1468. this.y = y;
  1469. this.z = z;
  1470. this.w = w;
  1471. return this;
  1472. }
  1473. setScalar( scalar ) {
  1474. this.x = scalar;
  1475. this.y = scalar;
  1476. this.z = scalar;
  1477. this.w = scalar;
  1478. return this;
  1479. }
  1480. setX( x ) {
  1481. this.x = x;
  1482. return this;
  1483. }
  1484. setY( y ) {
  1485. this.y = y;
  1486. return this;
  1487. }
  1488. setZ( z ) {
  1489. this.z = z;
  1490. return this;
  1491. }
  1492. setW( w ) {
  1493. this.w = w;
  1494. return this;
  1495. }
  1496. setComponent( index, value ) {
  1497. switch ( index ) {
  1498. case 0: this.x = value; break;
  1499. case 1: this.y = value; break;
  1500. case 2: this.z = value; break;
  1501. case 3: this.w = value; break;
  1502. default: throw new Error( 'index is out of range: ' + index );
  1503. }
  1504. return this;
  1505. }
  1506. getComponent( index ) {
  1507. switch ( index ) {
  1508. case 0: return this.x;
  1509. case 1: return this.y;
  1510. case 2: return this.z;
  1511. case 3: return this.w;
  1512. default: throw new Error( 'index is out of range: ' + index );
  1513. }
  1514. }
  1515. clone() {
  1516. return new this.constructor( this.x, this.y, this.z, this.w );
  1517. }
  1518. copy( v ) {
  1519. this.x = v.x;
  1520. this.y = v.y;
  1521. this.z = v.z;
  1522. this.w = ( v.w !== undefined ) ? v.w : 1;
  1523. return this;
  1524. }
  1525. add( v ) {
  1526. this.x += v.x;
  1527. this.y += v.y;
  1528. this.z += v.z;
  1529. this.w += v.w;
  1530. return this;
  1531. }
  1532. addScalar( s ) {
  1533. this.x += s;
  1534. this.y += s;
  1535. this.z += s;
  1536. this.w += s;
  1537. return this;
  1538. }
  1539. addVectors( a, b ) {
  1540. this.x = a.x + b.x;
  1541. this.y = a.y + b.y;
  1542. this.z = a.z + b.z;
  1543. this.w = a.w + b.w;
  1544. return this;
  1545. }
  1546. addScaledVector( v, s ) {
  1547. this.x += v.x * s;
  1548. this.y += v.y * s;
  1549. this.z += v.z * s;
  1550. this.w += v.w * s;
  1551. return this;
  1552. }
  1553. sub( v ) {
  1554. this.x -= v.x;
  1555. this.y -= v.y;
  1556. this.z -= v.z;
  1557. this.w -= v.w;
  1558. return this;
  1559. }
  1560. subScalar( s ) {
  1561. this.x -= s;
  1562. this.y -= s;
  1563. this.z -= s;
  1564. this.w -= s;
  1565. return this;
  1566. }
  1567. subVectors( a, b ) {
  1568. this.x = a.x - b.x;
  1569. this.y = a.y - b.y;
  1570. this.z = a.z - b.z;
  1571. this.w = a.w - b.w;
  1572. return this;
  1573. }
  1574. multiply( v ) {
  1575. this.x *= v.x;
  1576. this.y *= v.y;
  1577. this.z *= v.z;
  1578. this.w *= v.w;
  1579. return this;
  1580. }
  1581. multiplyScalar( scalar ) {
  1582. this.x *= scalar;
  1583. this.y *= scalar;
  1584. this.z *= scalar;
  1585. this.w *= scalar;
  1586. return this;
  1587. }
  1588. applyMatrix4( m ) {
  1589. const x = this.x, y = this.y, z = this.z, w = this.w;
  1590. const e = m.elements;
  1591. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1592. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1593. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1594. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1595. return this;
  1596. }
  1597. divide( v ) {
  1598. this.x /= v.x;
  1599. this.y /= v.y;
  1600. this.z /= v.z;
  1601. this.w /= v.w;
  1602. return this;
  1603. }
  1604. divideScalar( scalar ) {
  1605. return this.multiplyScalar( 1 / scalar );
  1606. }
  1607. setAxisAngleFromQuaternion( q ) {
  1608. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1609. // q is assumed to be normalized
  1610. this.w = 2 * Math.acos( q.w );
  1611. const s = Math.sqrt( 1 - q.w * q.w );
  1612. if ( s < 0.0001 ) {
  1613. this.x = 1;
  1614. this.y = 0;
  1615. this.z = 0;
  1616. } else {
  1617. this.x = q.x / s;
  1618. this.y = q.y / s;
  1619. this.z = q.z / s;
  1620. }
  1621. return this;
  1622. }
  1623. setAxisAngleFromRotationMatrix( m ) {
  1624. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1625. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1626. let angle, x, y, z; // variables for result
  1627. const epsilon = 0.01, // margin to allow for rounding errors
  1628. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1629. te = m.elements,
  1630. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1631. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1632. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1633. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1634. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1635. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1636. // singularity found
  1637. // first check for identity matrix which must have +1 for all terms
  1638. // in leading diagonal and zero in other terms
  1639. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1640. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1641. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1642. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1643. // this singularity is identity matrix so angle = 0
  1644. this.set( 1, 0, 0, 0 );
  1645. return this; // zero angle, arbitrary axis
  1646. }
  1647. // otherwise this singularity is angle = 180
  1648. angle = Math.PI;
  1649. const xx = ( m11 + 1 ) / 2;
  1650. const yy = ( m22 + 1 ) / 2;
  1651. const zz = ( m33 + 1 ) / 2;
  1652. const xy = ( m12 + m21 ) / 4;
  1653. const xz = ( m13 + m31 ) / 4;
  1654. const yz = ( m23 + m32 ) / 4;
  1655. if ( ( xx > yy ) && ( xx > zz ) ) {
  1656. // m11 is the largest diagonal term
  1657. if ( xx < epsilon ) {
  1658. x = 0;
  1659. y = 0.707106781;
  1660. z = 0.707106781;
  1661. } else {
  1662. x = Math.sqrt( xx );
  1663. y = xy / x;
  1664. z = xz / x;
  1665. }
  1666. } else if ( yy > zz ) {
  1667. // m22 is the largest diagonal term
  1668. if ( yy < epsilon ) {
  1669. x = 0.707106781;
  1670. y = 0;
  1671. z = 0.707106781;
  1672. } else {
  1673. y = Math.sqrt( yy );
  1674. x = xy / y;
  1675. z = yz / y;
  1676. }
  1677. } else {
  1678. // m33 is the largest diagonal term so base result on this
  1679. if ( zz < epsilon ) {
  1680. x = 0.707106781;
  1681. y = 0.707106781;
  1682. z = 0;
  1683. } else {
  1684. z = Math.sqrt( zz );
  1685. x = xz / z;
  1686. y = yz / z;
  1687. }
  1688. }
  1689. this.set( x, y, z, angle );
  1690. return this; // return 180 deg rotation
  1691. }
  1692. // as we have reached here there are no singularities so we can handle normally
  1693. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1694. ( m13 - m31 ) * ( m13 - m31 ) +
  1695. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1696. if ( Math.abs( s ) < 0.001 ) s = 1;
  1697. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1698. // caught by singularity test above, but I've left it in just in case
  1699. this.x = ( m32 - m23 ) / s;
  1700. this.y = ( m13 - m31 ) / s;
  1701. this.z = ( m21 - m12 ) / s;
  1702. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1703. return this;
  1704. }
  1705. setFromMatrixPosition( m ) {
  1706. const e = m.elements;
  1707. this.x = e[ 12 ];
  1708. this.y = e[ 13 ];
  1709. this.z = e[ 14 ];
  1710. this.w = e[ 15 ];
  1711. return this;
  1712. }
  1713. min( v ) {
  1714. this.x = Math.min( this.x, v.x );
  1715. this.y = Math.min( this.y, v.y );
  1716. this.z = Math.min( this.z, v.z );
  1717. this.w = Math.min( this.w, v.w );
  1718. return this;
  1719. }
  1720. max( v ) {
  1721. this.x = Math.max( this.x, v.x );
  1722. this.y = Math.max( this.y, v.y );
  1723. this.z = Math.max( this.z, v.z );
  1724. this.w = Math.max( this.w, v.w );
  1725. return this;
  1726. }
  1727. clamp( min, max ) {
  1728. // assumes min < max, componentwise
  1729. this.x = clamp( this.x, min.x, max.x );
  1730. this.y = clamp( this.y, min.y, max.y );
  1731. this.z = clamp( this.z, min.z, max.z );
  1732. this.w = clamp( this.w, min.w, max.w );
  1733. return this;
  1734. }
  1735. clampScalar( minVal, maxVal ) {
  1736. this.x = clamp( this.x, minVal, maxVal );
  1737. this.y = clamp( this.y, minVal, maxVal );
  1738. this.z = clamp( this.z, minVal, maxVal );
  1739. this.w = clamp( this.w, minVal, maxVal );
  1740. return this;
  1741. }
  1742. clampLength( min, max ) {
  1743. const length = this.length();
  1744. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  1745. }
  1746. floor() {
  1747. this.x = Math.floor( this.x );
  1748. this.y = Math.floor( this.y );
  1749. this.z = Math.floor( this.z );
  1750. this.w = Math.floor( this.w );
  1751. return this;
  1752. }
  1753. ceil() {
  1754. this.x = Math.ceil( this.x );
  1755. this.y = Math.ceil( this.y );
  1756. this.z = Math.ceil( this.z );
  1757. this.w = Math.ceil( this.w );
  1758. return this;
  1759. }
  1760. round() {
  1761. this.x = Math.round( this.x );
  1762. this.y = Math.round( this.y );
  1763. this.z = Math.round( this.z );
  1764. this.w = Math.round( this.w );
  1765. return this;
  1766. }
  1767. roundToZero() {
  1768. this.x = Math.trunc( this.x );
  1769. this.y = Math.trunc( this.y );
  1770. this.z = Math.trunc( this.z );
  1771. this.w = Math.trunc( this.w );
  1772. return this;
  1773. }
  1774. negate() {
  1775. this.x = - this.x;
  1776. this.y = - this.y;
  1777. this.z = - this.z;
  1778. this.w = - this.w;
  1779. return this;
  1780. }
  1781. dot( v ) {
  1782. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1783. }
  1784. lengthSq() {
  1785. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1786. }
  1787. length() {
  1788. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1789. }
  1790. manhattanLength() {
  1791. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1792. }
  1793. normalize() {
  1794. return this.divideScalar( this.length() || 1 );
  1795. }
  1796. setLength( length ) {
  1797. return this.normalize().multiplyScalar( length );
  1798. }
  1799. lerp( v, alpha ) {
  1800. this.x += ( v.x - this.x ) * alpha;
  1801. this.y += ( v.y - this.y ) * alpha;
  1802. this.z += ( v.z - this.z ) * alpha;
  1803. this.w += ( v.w - this.w ) * alpha;
  1804. return this;
  1805. }
  1806. lerpVectors( v1, v2, alpha ) {
  1807. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1808. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1809. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1810. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1811. return this;
  1812. }
  1813. equals( v ) {
  1814. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1815. }
  1816. fromArray( array, offset = 0 ) {
  1817. this.x = array[ offset ];
  1818. this.y = array[ offset + 1 ];
  1819. this.z = array[ offset + 2 ];
  1820. this.w = array[ offset + 3 ];
  1821. return this;
  1822. }
  1823. toArray( array = [], offset = 0 ) {
  1824. array[ offset ] = this.x;
  1825. array[ offset + 1 ] = this.y;
  1826. array[ offset + 2 ] = this.z;
  1827. array[ offset + 3 ] = this.w;
  1828. return array;
  1829. }
  1830. fromBufferAttribute( attribute, index ) {
  1831. this.x = attribute.getX( index );
  1832. this.y = attribute.getY( index );
  1833. this.z = attribute.getZ( index );
  1834. this.w = attribute.getW( index );
  1835. return this;
  1836. }
  1837. random() {
  1838. this.x = Math.random();
  1839. this.y = Math.random();
  1840. this.z = Math.random();
  1841. this.w = Math.random();
  1842. return this;
  1843. }
  1844. *[ Symbol.iterator ]() {
  1845. yield this.x;
  1846. yield this.y;
  1847. yield this.z;
  1848. yield this.w;
  1849. }
  1850. }
  1851. /*
  1852. In options, we can specify:
  1853. * Texture parameters for an auto-generated target texture
  1854. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1855. */
  1856. class RenderTarget extends EventDispatcher {
  1857. constructor( width = 1, height = 1, options = {} ) {
  1858. super();
  1859. this.isRenderTarget = true;
  1860. this.width = width;
  1861. this.height = height;
  1862. this.depth = 1;
  1863. this.scissor = new Vector4( 0, 0, width, height );
  1864. this.scissorTest = false;
  1865. this.viewport = new Vector4( 0, 0, width, height );
  1866. const image = { width: width, height: height, depth: 1 };
  1867. options = Object.assign( {
  1868. generateMipmaps: false,
  1869. internalFormat: null,
  1870. minFilter: LinearFilter,
  1871. depthBuffer: true,
  1872. stencilBuffer: false,
  1873. resolveDepthBuffer: true,
  1874. resolveStencilBuffer: true,
  1875. depthTexture: null,
  1876. samples: 0,
  1877. count: 1
  1878. }, options );
  1879. const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  1880. texture.flipY = false;
  1881. texture.generateMipmaps = options.generateMipmaps;
  1882. texture.internalFormat = options.internalFormat;
  1883. this.textures = [];
  1884. const count = options.count;
  1885. for ( let i = 0; i < count; i ++ ) {
  1886. this.textures[ i ] = texture.clone();
  1887. this.textures[ i ].isRenderTargetTexture = true;
  1888. }
  1889. this.depthBuffer = options.depthBuffer;
  1890. this.stencilBuffer = options.stencilBuffer;
  1891. this.resolveDepthBuffer = options.resolveDepthBuffer;
  1892. this.resolveStencilBuffer = options.resolveStencilBuffer;
  1893. this.depthTexture = options.depthTexture;
  1894. this.samples = options.samples;
  1895. }
  1896. get texture() {
  1897. return this.textures[ 0 ];
  1898. }
  1899. set texture( value ) {
  1900. this.textures[ 0 ] = value;
  1901. }
  1902. setSize( width, height, depth = 1 ) {
  1903. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1904. this.width = width;
  1905. this.height = height;
  1906. this.depth = depth;
  1907. for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
  1908. this.textures[ i ].image.width = width;
  1909. this.textures[ i ].image.height = height;
  1910. this.textures[ i ].image.depth = depth;
  1911. }
  1912. this.dispose();
  1913. }
  1914. this.viewport.set( 0, 0, width, height );
  1915. this.scissor.set( 0, 0, width, height );
  1916. }
  1917. clone() {
  1918. return new this.constructor().copy( this );
  1919. }
  1920. copy( source ) {
  1921. this.width = source.width;
  1922. this.height = source.height;
  1923. this.depth = source.depth;
  1924. this.scissor.copy( source.scissor );
  1925. this.scissorTest = source.scissorTest;
  1926. this.viewport.copy( source.viewport );
  1927. this.textures.length = 0;
  1928. for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
  1929. this.textures[ i ] = source.textures[ i ].clone();
  1930. this.textures[ i ].isRenderTargetTexture = true;
  1931. }
  1932. // ensure image object is not shared, see #20328
  1933. const image = Object.assign( {}, source.texture.image );
  1934. this.texture.source = new Source( image );
  1935. this.depthBuffer = source.depthBuffer;
  1936. this.stencilBuffer = source.stencilBuffer;
  1937. this.resolveDepthBuffer = source.resolveDepthBuffer;
  1938. this.resolveStencilBuffer = source.resolveStencilBuffer;
  1939. if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
  1940. this.samples = source.samples;
  1941. return this;
  1942. }
  1943. dispose() {
  1944. this.dispatchEvent( { type: 'dispose' } );
  1945. }
  1946. }
  1947. class WebGLRenderTarget extends RenderTarget {
  1948. constructor( width = 1, height = 1, options = {} ) {
  1949. super( width, height, options );
  1950. this.isWebGLRenderTarget = true;
  1951. }
  1952. }
  1953. class DataArrayTexture extends Texture {
  1954. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1955. super( null );
  1956. this.isDataArrayTexture = true;
  1957. this.image = { data, width, height, depth };
  1958. this.magFilter = NearestFilter;
  1959. this.minFilter = NearestFilter;
  1960. this.wrapR = ClampToEdgeWrapping;
  1961. this.generateMipmaps = false;
  1962. this.flipY = false;
  1963. this.unpackAlignment = 1;
  1964. this.layerUpdates = new Set();
  1965. }
  1966. addLayerUpdate( layerIndex ) {
  1967. this.layerUpdates.add( layerIndex );
  1968. }
  1969. clearLayerUpdates() {
  1970. this.layerUpdates.clear();
  1971. }
  1972. }
  1973. class WebGLArrayRenderTarget extends WebGLRenderTarget {
  1974. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  1975. super( width, height, options );
  1976. this.isWebGLArrayRenderTarget = true;
  1977. this.depth = depth;
  1978. this.texture = new DataArrayTexture( null, width, height, depth );
  1979. this.texture.isRenderTargetTexture = true;
  1980. }
  1981. }
  1982. class Data3DTexture extends Texture {
  1983. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1984. // We're going to add .setXXX() methods for setting properties later.
  1985. // Users can still set in DataTexture3D directly.
  1986. //
  1987. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  1988. // texture.anisotropy = 16;
  1989. //
  1990. // See #14839
  1991. super( null );
  1992. this.isData3DTexture = true;
  1993. this.image = { data, width, height, depth };
  1994. this.magFilter = NearestFilter;
  1995. this.minFilter = NearestFilter;
  1996. this.wrapR = ClampToEdgeWrapping;
  1997. this.generateMipmaps = false;
  1998. this.flipY = false;
  1999. this.unpackAlignment = 1;
  2000. }
  2001. }
  2002. class WebGL3DRenderTarget extends WebGLRenderTarget {
  2003. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  2004. super( width, height, options );
  2005. this.isWebGL3DRenderTarget = true;
  2006. this.depth = depth;
  2007. this.texture = new Data3DTexture( null, width, height, depth );
  2008. this.texture.isRenderTargetTexture = true;
  2009. }
  2010. }
  2011. class Quaternion {
  2012. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  2013. this.isQuaternion = true;
  2014. this._x = x;
  2015. this._y = y;
  2016. this._z = z;
  2017. this._w = w;
  2018. }
  2019. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  2020. // fuzz-free, array-based Quaternion SLERP operation
  2021. let x0 = src0[ srcOffset0 + 0 ],
  2022. y0 = src0[ srcOffset0 + 1 ],
  2023. z0 = src0[ srcOffset0 + 2 ],
  2024. w0 = src0[ srcOffset0 + 3 ];
  2025. const x1 = src1[ srcOffset1 + 0 ],
  2026. y1 = src1[ srcOffset1 + 1 ],
  2027. z1 = src1[ srcOffset1 + 2 ],
  2028. w1 = src1[ srcOffset1 + 3 ];
  2029. if ( t === 0 ) {
  2030. dst[ dstOffset + 0 ] = x0;
  2031. dst[ dstOffset + 1 ] = y0;
  2032. dst[ dstOffset + 2 ] = z0;
  2033. dst[ dstOffset + 3 ] = w0;
  2034. return;
  2035. }
  2036. if ( t === 1 ) {
  2037. dst[ dstOffset + 0 ] = x1;
  2038. dst[ dstOffset + 1 ] = y1;
  2039. dst[ dstOffset + 2 ] = z1;
  2040. dst[ dstOffset + 3 ] = w1;
  2041. return;
  2042. }
  2043. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  2044. let s = 1 - t;
  2045. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2046. dir = ( cos >= 0 ? 1 : - 1 ),
  2047. sqrSin = 1 - cos * cos;
  2048. // Skip the Slerp for tiny steps to avoid numeric problems:
  2049. if ( sqrSin > Number.EPSILON ) {
  2050. const sin = Math.sqrt( sqrSin ),
  2051. len = Math.atan2( sin, cos * dir );
  2052. s = Math.sin( s * len ) / sin;
  2053. t = Math.sin( t * len ) / sin;
  2054. }
  2055. const tDir = t * dir;
  2056. x0 = x0 * s + x1 * tDir;
  2057. y0 = y0 * s + y1 * tDir;
  2058. z0 = z0 * s + z1 * tDir;
  2059. w0 = w0 * s + w1 * tDir;
  2060. // Normalize in case we just did a lerp:
  2061. if ( s === 1 - t ) {
  2062. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  2063. x0 *= f;
  2064. y0 *= f;
  2065. z0 *= f;
  2066. w0 *= f;
  2067. }
  2068. }
  2069. dst[ dstOffset ] = x0;
  2070. dst[ dstOffset + 1 ] = y0;
  2071. dst[ dstOffset + 2 ] = z0;
  2072. dst[ dstOffset + 3 ] = w0;
  2073. }
  2074. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  2075. const x0 = src0[ srcOffset0 ];
  2076. const y0 = src0[ srcOffset0 + 1 ];
  2077. const z0 = src0[ srcOffset0 + 2 ];
  2078. const w0 = src0[ srcOffset0 + 3 ];
  2079. const x1 = src1[ srcOffset1 ];
  2080. const y1 = src1[ srcOffset1 + 1 ];
  2081. const z1 = src1[ srcOffset1 + 2 ];
  2082. const w1 = src1[ srcOffset1 + 3 ];
  2083. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2084. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2085. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2086. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2087. return dst;
  2088. }
  2089. get x() {
  2090. return this._x;
  2091. }
  2092. set x( value ) {
  2093. this._x = value;
  2094. this._onChangeCallback();
  2095. }
  2096. get y() {
  2097. return this._y;
  2098. }
  2099. set y( value ) {
  2100. this._y = value;
  2101. this._onChangeCallback();
  2102. }
  2103. get z() {
  2104. return this._z;
  2105. }
  2106. set z( value ) {
  2107. this._z = value;
  2108. this._onChangeCallback();
  2109. }
  2110. get w() {
  2111. return this._w;
  2112. }
  2113. set w( value ) {
  2114. this._w = value;
  2115. this._onChangeCallback();
  2116. }
  2117. set( x, y, z, w ) {
  2118. this._x = x;
  2119. this._y = y;
  2120. this._z = z;
  2121. this._w = w;
  2122. this._onChangeCallback();
  2123. return this;
  2124. }
  2125. clone() {
  2126. return new this.constructor( this._x, this._y, this._z, this._w );
  2127. }
  2128. copy( quaternion ) {
  2129. this._x = quaternion.x;
  2130. this._y = quaternion.y;
  2131. this._z = quaternion.z;
  2132. this._w = quaternion.w;
  2133. this._onChangeCallback();
  2134. return this;
  2135. }
  2136. setFromEuler( euler, update = true ) {
  2137. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  2138. // http://www.mathworks.com/matlabcentral/fileexchange/
  2139. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2140. // content/SpinCalc.m
  2141. const cos = Math.cos;
  2142. const sin = Math.sin;
  2143. const c1 = cos( x / 2 );
  2144. const c2 = cos( y / 2 );
  2145. const c3 = cos( z / 2 );
  2146. const s1 = sin( x / 2 );
  2147. const s2 = sin( y / 2 );
  2148. const s3 = sin( z / 2 );
  2149. switch ( order ) {
  2150. case 'XYZ':
  2151. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2152. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2153. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2154. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2155. break;
  2156. case 'YXZ':
  2157. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2158. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2159. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2160. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2161. break;
  2162. case 'ZXY':
  2163. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2164. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2165. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2166. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2167. break;
  2168. case 'ZYX':
  2169. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2170. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2171. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2172. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2173. break;
  2174. case 'YZX':
  2175. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2176. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2177. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2178. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2179. break;
  2180. case 'XZY':
  2181. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2182. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2183. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2184. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2185. break;
  2186. default:
  2187. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  2188. }
  2189. if ( update === true ) this._onChangeCallback();
  2190. return this;
  2191. }
  2192. setFromAxisAngle( axis, angle ) {
  2193. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2194. // assumes axis is normalized
  2195. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  2196. this._x = axis.x * s;
  2197. this._y = axis.y * s;
  2198. this._z = axis.z * s;
  2199. this._w = Math.cos( halfAngle );
  2200. this._onChangeCallback();
  2201. return this;
  2202. }
  2203. setFromRotationMatrix( m ) {
  2204. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2205. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2206. const te = m.elements,
  2207. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2208. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2209. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  2210. trace = m11 + m22 + m33;
  2211. if ( trace > 0 ) {
  2212. const s = 0.5 / Math.sqrt( trace + 1.0 );
  2213. this._w = 0.25 / s;
  2214. this._x = ( m32 - m23 ) * s;
  2215. this._y = ( m13 - m31 ) * s;
  2216. this._z = ( m21 - m12 ) * s;
  2217. } else if ( m11 > m22 && m11 > m33 ) {
  2218. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  2219. this._w = ( m32 - m23 ) / s;
  2220. this._x = 0.25 * s;
  2221. this._y = ( m12 + m21 ) / s;
  2222. this._z = ( m13 + m31 ) / s;
  2223. } else if ( m22 > m33 ) {
  2224. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  2225. this._w = ( m13 - m31 ) / s;
  2226. this._x = ( m12 + m21 ) / s;
  2227. this._y = 0.25 * s;
  2228. this._z = ( m23 + m32 ) / s;
  2229. } else {
  2230. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  2231. this._w = ( m21 - m12 ) / s;
  2232. this._x = ( m13 + m31 ) / s;
  2233. this._y = ( m23 + m32 ) / s;
  2234. this._z = 0.25 * s;
  2235. }
  2236. this._onChangeCallback();
  2237. return this;
  2238. }
  2239. setFromUnitVectors( vFrom, vTo ) {
  2240. // assumes direction vectors vFrom and vTo are normalized
  2241. let r = vFrom.dot( vTo ) + 1;
  2242. if ( r < Number.EPSILON ) {
  2243. // vFrom and vTo point in opposite directions
  2244. r = 0;
  2245. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  2246. this._x = - vFrom.y;
  2247. this._y = vFrom.x;
  2248. this._z = 0;
  2249. this._w = r;
  2250. } else {
  2251. this._x = 0;
  2252. this._y = - vFrom.z;
  2253. this._z = vFrom.y;
  2254. this._w = r;
  2255. }
  2256. } else {
  2257. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2258. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2259. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2260. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2261. this._w = r;
  2262. }
  2263. return this.normalize();
  2264. }
  2265. angleTo( q ) {
  2266. return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );
  2267. }
  2268. rotateTowards( q, step ) {
  2269. const angle = this.angleTo( q );
  2270. if ( angle === 0 ) return this;
  2271. const t = Math.min( 1, step / angle );
  2272. this.slerp( q, t );
  2273. return this;
  2274. }
  2275. identity() {
  2276. return this.set( 0, 0, 0, 1 );
  2277. }
  2278. invert() {
  2279. // quaternion is assumed to have unit length
  2280. return this.conjugate();
  2281. }
  2282. conjugate() {
  2283. this._x *= - 1;
  2284. this._y *= - 1;
  2285. this._z *= - 1;
  2286. this._onChangeCallback();
  2287. return this;
  2288. }
  2289. dot( v ) {
  2290. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2291. }
  2292. lengthSq() {
  2293. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2294. }
  2295. length() {
  2296. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  2297. }
  2298. normalize() {
  2299. let l = this.length();
  2300. if ( l === 0 ) {
  2301. this._x = 0;
  2302. this._y = 0;
  2303. this._z = 0;
  2304. this._w = 1;
  2305. } else {
  2306. l = 1 / l;
  2307. this._x = this._x * l;
  2308. this._y = this._y * l;
  2309. this._z = this._z * l;
  2310. this._w = this._w * l;
  2311. }
  2312. this._onChangeCallback();
  2313. return this;
  2314. }
  2315. multiply( q ) {
  2316. return this.multiplyQuaternions( this, q );
  2317. }
  2318. premultiply( q ) {
  2319. return this.multiplyQuaternions( q, this );
  2320. }
  2321. multiplyQuaternions( a, b ) {
  2322. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2323. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  2324. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  2325. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2326. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2327. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2328. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2329. this._onChangeCallback();
  2330. return this;
  2331. }
  2332. slerp( qb, t ) {
  2333. if ( t === 0 ) return this;
  2334. if ( t === 1 ) return this.copy( qb );
  2335. const x = this._x, y = this._y, z = this._z, w = this._w;
  2336. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2337. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2338. if ( cosHalfTheta < 0 ) {
  2339. this._w = - qb._w;
  2340. this._x = - qb._x;
  2341. this._y = - qb._y;
  2342. this._z = - qb._z;
  2343. cosHalfTheta = - cosHalfTheta;
  2344. } else {
  2345. this.copy( qb );
  2346. }
  2347. if ( cosHalfTheta >= 1.0 ) {
  2348. this._w = w;
  2349. this._x = x;
  2350. this._y = y;
  2351. this._z = z;
  2352. return this;
  2353. }
  2354. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2355. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  2356. const s = 1 - t;
  2357. this._w = s * w + t * this._w;
  2358. this._x = s * x + t * this._x;
  2359. this._y = s * y + t * this._y;
  2360. this._z = s * z + t * this._z;
  2361. this.normalize(); // normalize calls _onChangeCallback()
  2362. return this;
  2363. }
  2364. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  2365. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  2366. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2367. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2368. this._w = ( w * ratioA + this._w * ratioB );
  2369. this._x = ( x * ratioA + this._x * ratioB );
  2370. this._y = ( y * ratioA + this._y * ratioB );
  2371. this._z = ( z * ratioA + this._z * ratioB );
  2372. this._onChangeCallback();
  2373. return this;
  2374. }
  2375. slerpQuaternions( qa, qb, t ) {
  2376. return this.copy( qa ).slerp( qb, t );
  2377. }
  2378. random() {
  2379. // sets this quaternion to a uniform random unit quaternnion
  2380. // Ken Shoemake
  2381. // Uniform random rotations
  2382. // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
  2383. const theta1 = 2 * Math.PI * Math.random();
  2384. const theta2 = 2 * Math.PI * Math.random();
  2385. const x0 = Math.random();
  2386. const r1 = Math.sqrt( 1 - x0 );
  2387. const r2 = Math.sqrt( x0 );
  2388. return this.set(
  2389. r1 * Math.sin( theta1 ),
  2390. r1 * Math.cos( theta1 ),
  2391. r2 * Math.sin( theta2 ),
  2392. r2 * Math.cos( theta2 ),
  2393. );
  2394. }
  2395. equals( quaternion ) {
  2396. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  2397. }
  2398. fromArray( array, offset = 0 ) {
  2399. this._x = array[ offset ];
  2400. this._y = array[ offset + 1 ];
  2401. this._z = array[ offset + 2 ];
  2402. this._w = array[ offset + 3 ];
  2403. this._onChangeCallback();
  2404. return this;
  2405. }
  2406. toArray( array = [], offset = 0 ) {
  2407. array[ offset ] = this._x;
  2408. array[ offset + 1 ] = this._y;
  2409. array[ offset + 2 ] = this._z;
  2410. array[ offset + 3 ] = this._w;
  2411. return array;
  2412. }
  2413. fromBufferAttribute( attribute, index ) {
  2414. this._x = attribute.getX( index );
  2415. this._y = attribute.getY( index );
  2416. this._z = attribute.getZ( index );
  2417. this._w = attribute.getW( index );
  2418. this._onChangeCallback();
  2419. return this;
  2420. }
  2421. toJSON() {
  2422. return this.toArray();
  2423. }
  2424. _onChange( callback ) {
  2425. this._onChangeCallback = callback;
  2426. return this;
  2427. }
  2428. _onChangeCallback() {}
  2429. *[ Symbol.iterator ]() {
  2430. yield this._x;
  2431. yield this._y;
  2432. yield this._z;
  2433. yield this._w;
  2434. }
  2435. }
  2436. class Vector3 {
  2437. constructor( x = 0, y = 0, z = 0 ) {
  2438. Vector3.prototype.isVector3 = true;
  2439. this.x = x;
  2440. this.y = y;
  2441. this.z = z;
  2442. }
  2443. set( x, y, z ) {
  2444. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  2445. this.x = x;
  2446. this.y = y;
  2447. this.z = z;
  2448. return this;
  2449. }
  2450. setScalar( scalar ) {
  2451. this.x = scalar;
  2452. this.y = scalar;
  2453. this.z = scalar;
  2454. return this;
  2455. }
  2456. setX( x ) {
  2457. this.x = x;
  2458. return this;
  2459. }
  2460. setY( y ) {
  2461. this.y = y;
  2462. return this;
  2463. }
  2464. setZ( z ) {
  2465. this.z = z;
  2466. return this;
  2467. }
  2468. setComponent( index, value ) {
  2469. switch ( index ) {
  2470. case 0: this.x = value; break;
  2471. case 1: this.y = value; break;
  2472. case 2: this.z = value; break;
  2473. default: throw new Error( 'index is out of range: ' + index );
  2474. }
  2475. return this;
  2476. }
  2477. getComponent( index ) {
  2478. switch ( index ) {
  2479. case 0: return this.x;
  2480. case 1: return this.y;
  2481. case 2: return this.z;
  2482. default: throw new Error( 'index is out of range: ' + index );
  2483. }
  2484. }
  2485. clone() {
  2486. return new this.constructor( this.x, this.y, this.z );
  2487. }
  2488. copy( v ) {
  2489. this.x = v.x;
  2490. this.y = v.y;
  2491. this.z = v.z;
  2492. return this;
  2493. }
  2494. add( v ) {
  2495. this.x += v.x;
  2496. this.y += v.y;
  2497. this.z += v.z;
  2498. return this;
  2499. }
  2500. addScalar( s ) {
  2501. this.x += s;
  2502. this.y += s;
  2503. this.z += s;
  2504. return this;
  2505. }
  2506. addVectors( a, b ) {
  2507. this.x = a.x + b.x;
  2508. this.y = a.y + b.y;
  2509. this.z = a.z + b.z;
  2510. return this;
  2511. }
  2512. addScaledVector( v, s ) {
  2513. this.x += v.x * s;
  2514. this.y += v.y * s;
  2515. this.z += v.z * s;
  2516. return this;
  2517. }
  2518. sub( v ) {
  2519. this.x -= v.x;
  2520. this.y -= v.y;
  2521. this.z -= v.z;
  2522. return this;
  2523. }
  2524. subScalar( s ) {
  2525. this.x -= s;
  2526. this.y -= s;
  2527. this.z -= s;
  2528. return this;
  2529. }
  2530. subVectors( a, b ) {
  2531. this.x = a.x - b.x;
  2532. this.y = a.y - b.y;
  2533. this.z = a.z - b.z;
  2534. return this;
  2535. }
  2536. multiply( v ) {
  2537. this.x *= v.x;
  2538. this.y *= v.y;
  2539. this.z *= v.z;
  2540. return this;
  2541. }
  2542. multiplyScalar( scalar ) {
  2543. this.x *= scalar;
  2544. this.y *= scalar;
  2545. this.z *= scalar;
  2546. return this;
  2547. }
  2548. multiplyVectors( a, b ) {
  2549. this.x = a.x * b.x;
  2550. this.y = a.y * b.y;
  2551. this.z = a.z * b.z;
  2552. return this;
  2553. }
  2554. applyEuler( euler ) {
  2555. return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );
  2556. }
  2557. applyAxisAngle( axis, angle ) {
  2558. return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );
  2559. }
  2560. applyMatrix3( m ) {
  2561. const x = this.x, y = this.y, z = this.z;
  2562. const e = m.elements;
  2563. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2564. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2565. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2566. return this;
  2567. }
  2568. applyNormalMatrix( m ) {
  2569. return this.applyMatrix3( m ).normalize();
  2570. }
  2571. applyMatrix4( m ) {
  2572. const x = this.x, y = this.y, z = this.z;
  2573. const e = m.elements;
  2574. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2575. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2576. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2577. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2578. return this;
  2579. }
  2580. applyQuaternion( q ) {
  2581. // quaternion q is assumed to have unit length
  2582. const vx = this.x, vy = this.y, vz = this.z;
  2583. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2584. // t = 2 * cross( q.xyz, v );
  2585. const tx = 2 * ( qy * vz - qz * vy );
  2586. const ty = 2 * ( qz * vx - qx * vz );
  2587. const tz = 2 * ( qx * vy - qy * vx );
  2588. // v + q.w * t + cross( q.xyz, t );
  2589. this.x = vx + qw * tx + qy * tz - qz * ty;
  2590. this.y = vy + qw * ty + qz * tx - qx * tz;
  2591. this.z = vz + qw * tz + qx * ty - qy * tx;
  2592. return this;
  2593. }
  2594. project( camera ) {
  2595. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2596. }
  2597. unproject( camera ) {
  2598. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2599. }
  2600. transformDirection( m ) {
  2601. // input: THREE.Matrix4 affine matrix
  2602. // vector interpreted as a direction
  2603. const x = this.x, y = this.y, z = this.z;
  2604. const e = m.elements;
  2605. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2606. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2607. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2608. return this.normalize();
  2609. }
  2610. divide( v ) {
  2611. this.x /= v.x;
  2612. this.y /= v.y;
  2613. this.z /= v.z;
  2614. return this;
  2615. }
  2616. divideScalar( scalar ) {
  2617. return this.multiplyScalar( 1 / scalar );
  2618. }
  2619. min( v ) {
  2620. this.x = Math.min( this.x, v.x );
  2621. this.y = Math.min( this.y, v.y );
  2622. this.z = Math.min( this.z, v.z );
  2623. return this;
  2624. }
  2625. max( v ) {
  2626. this.x = Math.max( this.x, v.x );
  2627. this.y = Math.max( this.y, v.y );
  2628. this.z = Math.max( this.z, v.z );
  2629. return this;
  2630. }
  2631. clamp( min, max ) {
  2632. // assumes min < max, componentwise
  2633. this.x = clamp( this.x, min.x, max.x );
  2634. this.y = clamp( this.y, min.y, max.y );
  2635. this.z = clamp( this.z, min.z, max.z );
  2636. return this;
  2637. }
  2638. clampScalar( minVal, maxVal ) {
  2639. this.x = clamp( this.x, minVal, maxVal );
  2640. this.y = clamp( this.y, minVal, maxVal );
  2641. this.z = clamp( this.z, minVal, maxVal );
  2642. return this;
  2643. }
  2644. clampLength( min, max ) {
  2645. const length = this.length();
  2646. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  2647. }
  2648. floor() {
  2649. this.x = Math.floor( this.x );
  2650. this.y = Math.floor( this.y );
  2651. this.z = Math.floor( this.z );
  2652. return this;
  2653. }
  2654. ceil() {
  2655. this.x = Math.ceil( this.x );
  2656. this.y = Math.ceil( this.y );
  2657. this.z = Math.ceil( this.z );
  2658. return this;
  2659. }
  2660. round() {
  2661. this.x = Math.round( this.x );
  2662. this.y = Math.round( this.y );
  2663. this.z = Math.round( this.z );
  2664. return this;
  2665. }
  2666. roundToZero() {
  2667. this.x = Math.trunc( this.x );
  2668. this.y = Math.trunc( this.y );
  2669. this.z = Math.trunc( this.z );
  2670. return this;
  2671. }
  2672. negate() {
  2673. this.x = - this.x;
  2674. this.y = - this.y;
  2675. this.z = - this.z;
  2676. return this;
  2677. }
  2678. dot( v ) {
  2679. return this.x * v.x + this.y * v.y + this.z * v.z;
  2680. }
  2681. // TODO lengthSquared?
  2682. lengthSq() {
  2683. return this.x * this.x + this.y * this.y + this.z * this.z;
  2684. }
  2685. length() {
  2686. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2687. }
  2688. manhattanLength() {
  2689. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2690. }
  2691. normalize() {
  2692. return this.divideScalar( this.length() || 1 );
  2693. }
  2694. setLength( length ) {
  2695. return this.normalize().multiplyScalar( length );
  2696. }
  2697. lerp( v, alpha ) {
  2698. this.x += ( v.x - this.x ) * alpha;
  2699. this.y += ( v.y - this.y ) * alpha;
  2700. this.z += ( v.z - this.z ) * alpha;
  2701. return this;
  2702. }
  2703. lerpVectors( v1, v2, alpha ) {
  2704. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2705. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2706. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2707. return this;
  2708. }
  2709. cross( v ) {
  2710. return this.crossVectors( this, v );
  2711. }
  2712. crossVectors( a, b ) {
  2713. const ax = a.x, ay = a.y, az = a.z;
  2714. const bx = b.x, by = b.y, bz = b.z;
  2715. this.x = ay * bz - az * by;
  2716. this.y = az * bx - ax * bz;
  2717. this.z = ax * by - ay * bx;
  2718. return this;
  2719. }
  2720. projectOnVector( v ) {
  2721. const denominator = v.lengthSq();
  2722. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2723. const scalar = v.dot( this ) / denominator;
  2724. return this.copy( v ).multiplyScalar( scalar );
  2725. }
  2726. projectOnPlane( planeNormal ) {
  2727. _vector$c.copy( this ).projectOnVector( planeNormal );
  2728. return this.sub( _vector$c );
  2729. }
  2730. reflect( normal ) {
  2731. // reflect incident vector off plane orthogonal to normal
  2732. // normal is assumed to have unit length
  2733. return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2734. }
  2735. angleTo( v ) {
  2736. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2737. if ( denominator === 0 ) return Math.PI / 2;
  2738. const theta = this.dot( v ) / denominator;
  2739. // clamp, to handle numerical problems
  2740. return Math.acos( clamp( theta, - 1, 1 ) );
  2741. }
  2742. distanceTo( v ) {
  2743. return Math.sqrt( this.distanceToSquared( v ) );
  2744. }
  2745. distanceToSquared( v ) {
  2746. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2747. return dx * dx + dy * dy + dz * dz;
  2748. }
  2749. manhattanDistanceTo( v ) {
  2750. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2751. }
  2752. setFromSpherical( s ) {
  2753. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2754. }
  2755. setFromSphericalCoords( radius, phi, theta ) {
  2756. const sinPhiRadius = Math.sin( phi ) * radius;
  2757. this.x = sinPhiRadius * Math.sin( theta );
  2758. this.y = Math.cos( phi ) * radius;
  2759. this.z = sinPhiRadius * Math.cos( theta );
  2760. return this;
  2761. }
  2762. setFromCylindrical( c ) {
  2763. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2764. }
  2765. setFromCylindricalCoords( radius, theta, y ) {
  2766. this.x = radius * Math.sin( theta );
  2767. this.y = y;
  2768. this.z = radius * Math.cos( theta );
  2769. return this;
  2770. }
  2771. setFromMatrixPosition( m ) {
  2772. const e = m.elements;
  2773. this.x = e[ 12 ];
  2774. this.y = e[ 13 ];
  2775. this.z = e[ 14 ];
  2776. return this;
  2777. }
  2778. setFromMatrixScale( m ) {
  2779. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2780. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2781. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2782. this.x = sx;
  2783. this.y = sy;
  2784. this.z = sz;
  2785. return this;
  2786. }
  2787. setFromMatrixColumn( m, index ) {
  2788. return this.fromArray( m.elements, index * 4 );
  2789. }
  2790. setFromMatrix3Column( m, index ) {
  2791. return this.fromArray( m.elements, index * 3 );
  2792. }
  2793. setFromEuler( e ) {
  2794. this.x = e._x;
  2795. this.y = e._y;
  2796. this.z = e._z;
  2797. return this;
  2798. }
  2799. setFromColor( c ) {
  2800. this.x = c.r;
  2801. this.y = c.g;
  2802. this.z = c.b;
  2803. return this;
  2804. }
  2805. equals( v ) {
  2806. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2807. }
  2808. fromArray( array, offset = 0 ) {
  2809. this.x = array[ offset ];
  2810. this.y = array[ offset + 1 ];
  2811. this.z = array[ offset + 2 ];
  2812. return this;
  2813. }
  2814. toArray( array = [], offset = 0 ) {
  2815. array[ offset ] = this.x;
  2816. array[ offset + 1 ] = this.y;
  2817. array[ offset + 2 ] = this.z;
  2818. return array;
  2819. }
  2820. fromBufferAttribute( attribute, index ) {
  2821. this.x = attribute.getX( index );
  2822. this.y = attribute.getY( index );
  2823. this.z = attribute.getZ( index );
  2824. return this;
  2825. }
  2826. random() {
  2827. this.x = Math.random();
  2828. this.y = Math.random();
  2829. this.z = Math.random();
  2830. return this;
  2831. }
  2832. randomDirection() {
  2833. // https://mathworld.wolfram.com/SpherePointPicking.html
  2834. const theta = Math.random() * Math.PI * 2;
  2835. const u = Math.random() * 2 - 1;
  2836. const c = Math.sqrt( 1 - u * u );
  2837. this.x = c * Math.cos( theta );
  2838. this.y = u;
  2839. this.z = c * Math.sin( theta );
  2840. return this;
  2841. }
  2842. *[ Symbol.iterator ]() {
  2843. yield this.x;
  2844. yield this.y;
  2845. yield this.z;
  2846. }
  2847. }
  2848. const _vector$c = /*@__PURE__*/ new Vector3();
  2849. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  2850. class Box3 {
  2851. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2852. this.isBox3 = true;
  2853. this.min = min;
  2854. this.max = max;
  2855. }
  2856. set( min, max ) {
  2857. this.min.copy( min );
  2858. this.max.copy( max );
  2859. return this;
  2860. }
  2861. setFromArray( array ) {
  2862. this.makeEmpty();
  2863. for ( let i = 0, il = array.length; i < il; i += 3 ) {
  2864. this.expandByPoint( _vector$b.fromArray( array, i ) );
  2865. }
  2866. return this;
  2867. }
  2868. setFromBufferAttribute( attribute ) {
  2869. this.makeEmpty();
  2870. for ( let i = 0, il = attribute.count; i < il; i ++ ) {
  2871. this.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) );
  2872. }
  2873. return this;
  2874. }
  2875. setFromPoints( points ) {
  2876. this.makeEmpty();
  2877. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2878. this.expandByPoint( points[ i ] );
  2879. }
  2880. return this;
  2881. }
  2882. setFromCenterAndSize( center, size ) {
  2883. const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );
  2884. this.min.copy( center ).sub( halfSize );
  2885. this.max.copy( center ).add( halfSize );
  2886. return this;
  2887. }
  2888. setFromObject( object, precise = false ) {
  2889. this.makeEmpty();
  2890. return this.expandByObject( object, precise );
  2891. }
  2892. clone() {
  2893. return new this.constructor().copy( this );
  2894. }
  2895. copy( box ) {
  2896. this.min.copy( box.min );
  2897. this.max.copy( box.max );
  2898. return this;
  2899. }
  2900. makeEmpty() {
  2901. this.min.x = this.min.y = this.min.z = + Infinity;
  2902. this.max.x = this.max.y = this.max.z = - Infinity;
  2903. return this;
  2904. }
  2905. isEmpty() {
  2906. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2907. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2908. }
  2909. getCenter( target ) {
  2910. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2911. }
  2912. getSize( target ) {
  2913. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2914. }
  2915. expandByPoint( point ) {
  2916. this.min.min( point );
  2917. this.max.max( point );
  2918. return this;
  2919. }
  2920. expandByVector( vector ) {
  2921. this.min.sub( vector );
  2922. this.max.add( vector );
  2923. return this;
  2924. }
  2925. expandByScalar( scalar ) {
  2926. this.min.addScalar( - scalar );
  2927. this.max.addScalar( scalar );
  2928. return this;
  2929. }
  2930. expandByObject( object, precise = false ) {
  2931. // Computes the world-axis-aligned bounding box of an object (including its children),
  2932. // accounting for both the object's, and children's, world transforms
  2933. object.updateWorldMatrix( false, false );
  2934. const geometry = object.geometry;
  2935. if ( geometry !== undefined ) {
  2936. const positionAttribute = geometry.getAttribute( 'position' );
  2937. // precise AABB computation based on vertex data requires at least a position attribute.
  2938. // instancing isn't supported so far and uses the normal (conservative) code path.
  2939. if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
  2940. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  2941. if ( object.isMesh === true ) {
  2942. object.getVertexPosition( i, _vector$b );
  2943. } else {
  2944. _vector$b.fromBufferAttribute( positionAttribute, i );
  2945. }
  2946. _vector$b.applyMatrix4( object.matrixWorld );
  2947. this.expandByPoint( _vector$b );
  2948. }
  2949. } else {
  2950. if ( object.boundingBox !== undefined ) {
  2951. // object-level bounding box
  2952. if ( object.boundingBox === null ) {
  2953. object.computeBoundingBox();
  2954. }
  2955. _box$4.copy( object.boundingBox );
  2956. } else {
  2957. // geometry-level bounding box
  2958. if ( geometry.boundingBox === null ) {
  2959. geometry.computeBoundingBox();
  2960. }
  2961. _box$4.copy( geometry.boundingBox );
  2962. }
  2963. _box$4.applyMatrix4( object.matrixWorld );
  2964. this.union( _box$4 );
  2965. }
  2966. }
  2967. const children = object.children;
  2968. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2969. this.expandByObject( children[ i ], precise );
  2970. }
  2971. return this;
  2972. }
  2973. containsPoint( point ) {
  2974. return point.x >= this.min.x && point.x <= this.max.x &&
  2975. point.y >= this.min.y && point.y <= this.max.y &&
  2976. point.z >= this.min.z && point.z <= this.max.z;
  2977. }
  2978. containsBox( box ) {
  2979. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2980. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2981. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2982. }
  2983. getParameter( point, target ) {
  2984. // This can potentially have a divide by zero if the box
  2985. // has a size dimension of 0.
  2986. return target.set(
  2987. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2988. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2989. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2990. );
  2991. }
  2992. intersectsBox( box ) {
  2993. // using 6 splitting planes to rule out intersections.
  2994. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  2995. box.max.y >= this.min.y && box.min.y <= this.max.y &&
  2996. box.max.z >= this.min.z && box.min.z <= this.max.z;
  2997. }
  2998. intersectsSphere( sphere ) {
  2999. // Find the point on the AABB closest to the sphere center.
  3000. this.clampPoint( sphere.center, _vector$b );
  3001. // If that point is inside the sphere, the AABB and sphere intersect.
  3002. return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3003. }
  3004. intersectsPlane( plane ) {
  3005. // We compute the minimum and maximum dot product values. If those values
  3006. // are on the same side (back or front) of the plane, then there is no intersection.
  3007. let min, max;
  3008. if ( plane.normal.x > 0 ) {
  3009. min = plane.normal.x * this.min.x;
  3010. max = plane.normal.x * this.max.x;
  3011. } else {
  3012. min = plane.normal.x * this.max.x;
  3013. max = plane.normal.x * this.min.x;
  3014. }
  3015. if ( plane.normal.y > 0 ) {
  3016. min += plane.normal.y * this.min.y;
  3017. max += plane.normal.y * this.max.y;
  3018. } else {
  3019. min += plane.normal.y * this.max.y;
  3020. max += plane.normal.y * this.min.y;
  3021. }
  3022. if ( plane.normal.z > 0 ) {
  3023. min += plane.normal.z * this.min.z;
  3024. max += plane.normal.z * this.max.z;
  3025. } else {
  3026. min += plane.normal.z * this.max.z;
  3027. max += plane.normal.z * this.min.z;
  3028. }
  3029. return ( min <= - plane.constant && max >= - plane.constant );
  3030. }
  3031. intersectsTriangle( triangle ) {
  3032. if ( this.isEmpty() ) {
  3033. return false;
  3034. }
  3035. // compute box center and extents
  3036. this.getCenter( _center );
  3037. _extents.subVectors( this.max, _center );
  3038. // translate triangle to aabb origin
  3039. _v0$2.subVectors( triangle.a, _center );
  3040. _v1$7.subVectors( triangle.b, _center );
  3041. _v2$4.subVectors( triangle.c, _center );
  3042. // compute edge vectors for triangle
  3043. _f0.subVectors( _v1$7, _v0$2 );
  3044. _f1.subVectors( _v2$4, _v1$7 );
  3045. _f2.subVectors( _v0$2, _v2$4 );
  3046. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3047. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3048. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3049. let axes = [
  3050. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3051. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3052. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3053. ];
  3054. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3055. return false;
  3056. }
  3057. // test 3 face normals from the aabb
  3058. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3059. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3060. return false;
  3061. }
  3062. // finally testing the face normal of the triangle
  3063. // use already existing triangle edge vectors here
  3064. _triangleNormal.crossVectors( _f0, _f1 );
  3065. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3066. return satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents );
  3067. }
  3068. clampPoint( point, target ) {
  3069. return target.copy( point ).clamp( this.min, this.max );
  3070. }
  3071. distanceToPoint( point ) {
  3072. return this.clampPoint( point, _vector$b ).distanceTo( point );
  3073. }
  3074. getBoundingSphere( target ) {
  3075. if ( this.isEmpty() ) {
  3076. target.makeEmpty();
  3077. } else {
  3078. this.getCenter( target.center );
  3079. target.radius = this.getSize( _vector$b ).length() * 0.5;
  3080. }
  3081. return target;
  3082. }
  3083. intersect( box ) {
  3084. this.min.max( box.min );
  3085. this.max.min( box.max );
  3086. // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  3087. if ( this.isEmpty() ) this.makeEmpty();
  3088. return this;
  3089. }
  3090. union( box ) {
  3091. this.min.min( box.min );
  3092. this.max.max( box.max );
  3093. return this;
  3094. }
  3095. applyMatrix4( matrix ) {
  3096. // transform of empty box is an empty box.
  3097. if ( this.isEmpty() ) return this;
  3098. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3099. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3100. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3101. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3102. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3103. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3104. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3105. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3106. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3107. this.setFromPoints( _points );
  3108. return this;
  3109. }
  3110. translate( offset ) {
  3111. this.min.add( offset );
  3112. this.max.add( offset );
  3113. return this;
  3114. }
  3115. equals( box ) {
  3116. return box.min.equals( this.min ) && box.max.equals( this.max );
  3117. }
  3118. }
  3119. const _points = [
  3120. /*@__PURE__*/ new Vector3(),
  3121. /*@__PURE__*/ new Vector3(),
  3122. /*@__PURE__*/ new Vector3(),
  3123. /*@__PURE__*/ new Vector3(),
  3124. /*@__PURE__*/ new Vector3(),
  3125. /*@__PURE__*/ new Vector3(),
  3126. /*@__PURE__*/ new Vector3(),
  3127. /*@__PURE__*/ new Vector3()
  3128. ];
  3129. const _vector$b = /*@__PURE__*/ new Vector3();
  3130. const _box$4 = /*@__PURE__*/ new Box3();
  3131. // triangle centered vertices
  3132. const _v0$2 = /*@__PURE__*/ new Vector3();
  3133. const _v1$7 = /*@__PURE__*/ new Vector3();
  3134. const _v2$4 = /*@__PURE__*/ new Vector3();
  3135. // triangle edge vectors
  3136. const _f0 = /*@__PURE__*/ new Vector3();
  3137. const _f1 = /*@__PURE__*/ new Vector3();
  3138. const _f2 = /*@__PURE__*/ new Vector3();
  3139. const _center = /*@__PURE__*/ new Vector3();
  3140. const _extents = /*@__PURE__*/ new Vector3();
  3141. const _triangleNormal = /*@__PURE__*/ new Vector3();
  3142. const _testAxis = /*@__PURE__*/ new Vector3();
  3143. function satForAxes( axes, v0, v1, v2, extents ) {
  3144. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3145. _testAxis.fromArray( axes, i );
  3146. // project the aabb onto the separating axis
  3147. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  3148. // project all 3 vertices of the triangle onto the separating axis
  3149. const p0 = v0.dot( _testAxis );
  3150. const p1 = v1.dot( _testAxis );
  3151. const p2 = v2.dot( _testAxis );
  3152. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3153. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3154. // points of the projected triangle are outside the projected half-length of the aabb
  3155. // the axis is separating and we can exit
  3156. return false;
  3157. }
  3158. }
  3159. return true;
  3160. }
  3161. const _box$3 = /*@__PURE__*/ new Box3();
  3162. const _v1$6 = /*@__PURE__*/ new Vector3();
  3163. const _v2$3 = /*@__PURE__*/ new Vector3();
  3164. class Sphere {
  3165. constructor( center = new Vector3(), radius = - 1 ) {
  3166. this.isSphere = true;
  3167. this.center = center;
  3168. this.radius = radius;
  3169. }
  3170. set( center, radius ) {
  3171. this.center.copy( center );
  3172. this.radius = radius;
  3173. return this;
  3174. }
  3175. setFromPoints( points, optionalCenter ) {
  3176. const center = this.center;
  3177. if ( optionalCenter !== undefined ) {
  3178. center.copy( optionalCenter );
  3179. } else {
  3180. _box$3.setFromPoints( points ).getCenter( center );
  3181. }
  3182. let maxRadiusSq = 0;
  3183. for ( let i = 0, il = points.length; i < il; i ++ ) {
  3184. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3185. }
  3186. this.radius = Math.sqrt( maxRadiusSq );
  3187. return this;
  3188. }
  3189. copy( sphere ) {
  3190. this.center.copy( sphere.center );
  3191. this.radius = sphere.radius;
  3192. return this;
  3193. }
  3194. isEmpty() {
  3195. return ( this.radius < 0 );
  3196. }
  3197. makeEmpty() {
  3198. this.center.set( 0, 0, 0 );
  3199. this.radius = - 1;
  3200. return this;
  3201. }
  3202. containsPoint( point ) {
  3203. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3204. }
  3205. distanceToPoint( point ) {
  3206. return ( point.distanceTo( this.center ) - this.radius );
  3207. }
  3208. intersectsSphere( sphere ) {
  3209. const radiusSum = this.radius + sphere.radius;
  3210. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3211. }
  3212. intersectsBox( box ) {
  3213. return box.intersectsSphere( this );
  3214. }
  3215. intersectsPlane( plane ) {
  3216. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3217. }
  3218. clampPoint( point, target ) {
  3219. const deltaLengthSq = this.center.distanceToSquared( point );
  3220. target.copy( point );
  3221. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3222. target.sub( this.center ).normalize();
  3223. target.multiplyScalar( this.radius ).add( this.center );
  3224. }
  3225. return target;
  3226. }
  3227. getBoundingBox( target ) {
  3228. if ( this.isEmpty() ) {
  3229. // Empty sphere produces empty bounding box
  3230. target.makeEmpty();
  3231. return target;
  3232. }
  3233. target.set( this.center, this.center );
  3234. target.expandByScalar( this.radius );
  3235. return target;
  3236. }
  3237. applyMatrix4( matrix ) {
  3238. this.center.applyMatrix4( matrix );
  3239. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3240. return this;
  3241. }
  3242. translate( offset ) {
  3243. this.center.add( offset );
  3244. return this;
  3245. }
  3246. expandByPoint( point ) {
  3247. if ( this.isEmpty() ) {
  3248. this.center.copy( point );
  3249. this.radius = 0;
  3250. return this;
  3251. }
  3252. _v1$6.subVectors( point, this.center );
  3253. const lengthSq = _v1$6.lengthSq();
  3254. if ( lengthSq > ( this.radius * this.radius ) ) {
  3255. // calculate the minimal sphere
  3256. const length = Math.sqrt( lengthSq );
  3257. const delta = ( length - this.radius ) * 0.5;
  3258. this.center.addScaledVector( _v1$6, delta / length );
  3259. this.radius += delta;
  3260. }
  3261. return this;
  3262. }
  3263. union( sphere ) {
  3264. if ( sphere.isEmpty() ) {
  3265. return this;
  3266. }
  3267. if ( this.isEmpty() ) {
  3268. this.copy( sphere );
  3269. return this;
  3270. }
  3271. if ( this.center.equals( sphere.center ) === true ) {
  3272. this.radius = Math.max( this.radius, sphere.radius );
  3273. } else {
  3274. _v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius );
  3275. this.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) );
  3276. this.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) );
  3277. }
  3278. return this;
  3279. }
  3280. equals( sphere ) {
  3281. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3282. }
  3283. clone() {
  3284. return new this.constructor().copy( this );
  3285. }
  3286. }
  3287. const _vector$a = /*@__PURE__*/ new Vector3();
  3288. const _segCenter = /*@__PURE__*/ new Vector3();
  3289. const _segDir = /*@__PURE__*/ new Vector3();
  3290. const _diff = /*@__PURE__*/ new Vector3();
  3291. const _edge1 = /*@__PURE__*/ new Vector3();
  3292. const _edge2 = /*@__PURE__*/ new Vector3();
  3293. const _normal$1 = /*@__PURE__*/ new Vector3();
  3294. class Ray {
  3295. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
  3296. this.origin = origin;
  3297. this.direction = direction;
  3298. }
  3299. set( origin, direction ) {
  3300. this.origin.copy( origin );
  3301. this.direction.copy( direction );
  3302. return this;
  3303. }
  3304. copy( ray ) {
  3305. this.origin.copy( ray.origin );
  3306. this.direction.copy( ray.direction );
  3307. return this;
  3308. }
  3309. at( t, target ) {
  3310. return target.copy( this.origin ).addScaledVector( this.direction, t );
  3311. }
  3312. lookAt( v ) {
  3313. this.direction.copy( v ).sub( this.origin ).normalize();
  3314. return this;
  3315. }
  3316. recast( t ) {
  3317. this.origin.copy( this.at( t, _vector$a ) );
  3318. return this;
  3319. }
  3320. closestPointToPoint( point, target ) {
  3321. target.subVectors( point, this.origin );
  3322. const directionDistance = target.dot( this.direction );
  3323. if ( directionDistance < 0 ) {
  3324. return target.copy( this.origin );
  3325. }
  3326. return target.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3327. }
  3328. distanceToPoint( point ) {
  3329. return Math.sqrt( this.distanceSqToPoint( point ) );
  3330. }
  3331. distanceSqToPoint( point ) {
  3332. const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );
  3333. // point behind the ray
  3334. if ( directionDistance < 0 ) {
  3335. return this.origin.distanceToSquared( point );
  3336. }
  3337. _vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3338. return _vector$a.distanceToSquared( point );
  3339. }
  3340. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3341. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3342. // It returns the min distance between the ray and the segment
  3343. // defined by v0 and v1
  3344. // It can also set two optional targets :
  3345. // - The closest point on the ray
  3346. // - The closest point on the segment
  3347. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3348. _segDir.copy( v1 ).sub( v0 ).normalize();
  3349. _diff.copy( this.origin ).sub( _segCenter );
  3350. const segExtent = v0.distanceTo( v1 ) * 0.5;
  3351. const a01 = - this.direction.dot( _segDir );
  3352. const b0 = _diff.dot( this.direction );
  3353. const b1 = - _diff.dot( _segDir );
  3354. const c = _diff.lengthSq();
  3355. const det = Math.abs( 1 - a01 * a01 );
  3356. let s0, s1, sqrDist, extDet;
  3357. if ( det > 0 ) {
  3358. // The ray and segment are not parallel.
  3359. s0 = a01 * b1 - b0;
  3360. s1 = a01 * b0 - b1;
  3361. extDet = segExtent * det;
  3362. if ( s0 >= 0 ) {
  3363. if ( s1 >= - extDet ) {
  3364. if ( s1 <= extDet ) {
  3365. // region 0
  3366. // Minimum at interior points of ray and segment.
  3367. const invDet = 1 / det;
  3368. s0 *= invDet;
  3369. s1 *= invDet;
  3370. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3371. } else {
  3372. // region 1
  3373. s1 = segExtent;
  3374. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3375. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3376. }
  3377. } else {
  3378. // region 5
  3379. s1 = - segExtent;
  3380. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3381. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3382. }
  3383. } else {
  3384. if ( s1 <= - extDet ) {
  3385. // region 4
  3386. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3387. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3388. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3389. } else if ( s1 <= extDet ) {
  3390. // region 3
  3391. s0 = 0;
  3392. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3393. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3394. } else {
  3395. // region 2
  3396. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3397. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3398. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3399. }
  3400. }
  3401. } else {
  3402. // Ray and segment are parallel.
  3403. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3404. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3405. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3406. }
  3407. if ( optionalPointOnRay ) {
  3408. optionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 );
  3409. }
  3410. if ( optionalPointOnSegment ) {
  3411. optionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 );
  3412. }
  3413. return sqrDist;
  3414. }
  3415. intersectSphere( sphere, target ) {
  3416. _vector$a.subVectors( sphere.center, this.origin );
  3417. const tca = _vector$a.dot( this.direction );
  3418. const d2 = _vector$a.dot( _vector$a ) - tca * tca;
  3419. const radius2 = sphere.radius * sphere.radius;
  3420. if ( d2 > radius2 ) return null;
  3421. const thc = Math.sqrt( radius2 - d2 );
  3422. // t0 = first intersect point - entrance on front of sphere
  3423. const t0 = tca - thc;
  3424. // t1 = second intersect point - exit point on back of sphere
  3425. const t1 = tca + thc;
  3426. // test to see if t1 is behind the ray - if so, return null
  3427. if ( t1 < 0 ) return null;
  3428. // test to see if t0 is behind the ray:
  3429. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3430. // in order to always return an intersect point that is in front of the ray.
  3431. if ( t0 < 0 ) return this.at( t1, target );
  3432. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3433. return this.at( t0, target );
  3434. }
  3435. intersectsSphere( sphere ) {
  3436. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  3437. }
  3438. distanceToPlane( plane ) {
  3439. const denominator = plane.normal.dot( this.direction );
  3440. if ( denominator === 0 ) {
  3441. // line is coplanar, return origin
  3442. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3443. return 0;
  3444. }
  3445. // Null is preferable to undefined since undefined means.... it is undefined
  3446. return null;
  3447. }
  3448. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3449. // Return if the ray never intersects the plane
  3450. return t >= 0 ? t : null;
  3451. }
  3452. intersectPlane( plane, target ) {
  3453. const t = this.distanceToPlane( plane );
  3454. if ( t === null ) {
  3455. return null;
  3456. }
  3457. return this.at( t, target );
  3458. }
  3459. intersectsPlane( plane ) {
  3460. // check if the ray lies on the plane first
  3461. const distToPoint = plane.distanceToPoint( this.origin );
  3462. if ( distToPoint === 0 ) {
  3463. return true;
  3464. }
  3465. const denominator = plane.normal.dot( this.direction );
  3466. if ( denominator * distToPoint < 0 ) {
  3467. return true;
  3468. }
  3469. // ray origin is behind the plane (and is pointing behind it)
  3470. return false;
  3471. }
  3472. intersectBox( box, target ) {
  3473. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  3474. const invdirx = 1 / this.direction.x,
  3475. invdiry = 1 / this.direction.y,
  3476. invdirz = 1 / this.direction.z;
  3477. const origin = this.origin;
  3478. if ( invdirx >= 0 ) {
  3479. tmin = ( box.min.x - origin.x ) * invdirx;
  3480. tmax = ( box.max.x - origin.x ) * invdirx;
  3481. } else {
  3482. tmin = ( box.max.x - origin.x ) * invdirx;
  3483. tmax = ( box.min.x - origin.x ) * invdirx;
  3484. }
  3485. if ( invdiry >= 0 ) {
  3486. tymin = ( box.min.y - origin.y ) * invdiry;
  3487. tymax = ( box.max.y - origin.y ) * invdiry;
  3488. } else {
  3489. tymin = ( box.max.y - origin.y ) * invdiry;
  3490. tymax = ( box.min.y - origin.y ) * invdiry;
  3491. }
  3492. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3493. if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;
  3494. if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;
  3495. if ( invdirz >= 0 ) {
  3496. tzmin = ( box.min.z - origin.z ) * invdirz;
  3497. tzmax = ( box.max.z - origin.z ) * invdirz;
  3498. } else {
  3499. tzmin = ( box.max.z - origin.z ) * invdirz;
  3500. tzmax = ( box.min.z - origin.z ) * invdirz;
  3501. }
  3502. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3503. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3504. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3505. //return point closest to the ray (positive side)
  3506. if ( tmax < 0 ) return null;
  3507. return this.at( tmin >= 0 ? tmin : tmax, target );
  3508. }
  3509. intersectsBox( box ) {
  3510. return this.intersectBox( box, _vector$a ) !== null;
  3511. }
  3512. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3513. // Compute the offset origin, edges, and normal.
  3514. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3515. _edge1.subVectors( b, a );
  3516. _edge2.subVectors( c, a );
  3517. _normal$1.crossVectors( _edge1, _edge2 );
  3518. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3519. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3520. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3521. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3522. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3523. let DdN = this.direction.dot( _normal$1 );
  3524. let sign;
  3525. if ( DdN > 0 ) {
  3526. if ( backfaceCulling ) return null;
  3527. sign = 1;
  3528. } else if ( DdN < 0 ) {
  3529. sign = - 1;
  3530. DdN = - DdN;
  3531. } else {
  3532. return null;
  3533. }
  3534. _diff.subVectors( this.origin, a );
  3535. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3536. // b1 < 0, no intersection
  3537. if ( DdQxE2 < 0 ) {
  3538. return null;
  3539. }
  3540. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3541. // b2 < 0, no intersection
  3542. if ( DdE1xQ < 0 ) {
  3543. return null;
  3544. }
  3545. // b1+b2 > 1, no intersection
  3546. if ( DdQxE2 + DdE1xQ > DdN ) {
  3547. return null;
  3548. }
  3549. // Line intersects triangle, check if ray does.
  3550. const QdN = - sign * _diff.dot( _normal$1 );
  3551. // t < 0, no intersection
  3552. if ( QdN < 0 ) {
  3553. return null;
  3554. }
  3555. // Ray intersects triangle.
  3556. return this.at( QdN / DdN, target );
  3557. }
  3558. applyMatrix4( matrix4 ) {
  3559. this.origin.applyMatrix4( matrix4 );
  3560. this.direction.transformDirection( matrix4 );
  3561. return this;
  3562. }
  3563. equals( ray ) {
  3564. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3565. }
  3566. clone() {
  3567. return new this.constructor().copy( this );
  3568. }
  3569. }
  3570. class Matrix4 {
  3571. constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3572. Matrix4.prototype.isMatrix4 = true;
  3573. this.elements = [
  3574. 1, 0, 0, 0,
  3575. 0, 1, 0, 0,
  3576. 0, 0, 1, 0,
  3577. 0, 0, 0, 1
  3578. ];
  3579. if ( n11 !== undefined ) {
  3580. this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );
  3581. }
  3582. }
  3583. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3584. const te = this.elements;
  3585. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3586. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3587. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3588. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3589. return this;
  3590. }
  3591. identity() {
  3592. this.set(
  3593. 1, 0, 0, 0,
  3594. 0, 1, 0, 0,
  3595. 0, 0, 1, 0,
  3596. 0, 0, 0, 1
  3597. );
  3598. return this;
  3599. }
  3600. clone() {
  3601. return new Matrix4().fromArray( this.elements );
  3602. }
  3603. copy( m ) {
  3604. const te = this.elements;
  3605. const me = m.elements;
  3606. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3607. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3608. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3609. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3610. return this;
  3611. }
  3612. copyPosition( m ) {
  3613. const te = this.elements, me = m.elements;
  3614. te[ 12 ] = me[ 12 ];
  3615. te[ 13 ] = me[ 13 ];
  3616. te[ 14 ] = me[ 14 ];
  3617. return this;
  3618. }
  3619. setFromMatrix3( m ) {
  3620. const me = m.elements;
  3621. this.set(
  3622. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3623. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3624. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3625. 0, 0, 0, 1
  3626. );
  3627. return this;
  3628. }
  3629. extractBasis( xAxis, yAxis, zAxis ) {
  3630. xAxis.setFromMatrixColumn( this, 0 );
  3631. yAxis.setFromMatrixColumn( this, 1 );
  3632. zAxis.setFromMatrixColumn( this, 2 );
  3633. return this;
  3634. }
  3635. makeBasis( xAxis, yAxis, zAxis ) {
  3636. this.set(
  3637. xAxis.x, yAxis.x, zAxis.x, 0,
  3638. xAxis.y, yAxis.y, zAxis.y, 0,
  3639. xAxis.z, yAxis.z, zAxis.z, 0,
  3640. 0, 0, 0, 1
  3641. );
  3642. return this;
  3643. }
  3644. extractRotation( m ) {
  3645. // this method does not support reflection matrices
  3646. const te = this.elements;
  3647. const me = m.elements;
  3648. const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();
  3649. const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();
  3650. const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();
  3651. te[ 0 ] = me[ 0 ] * scaleX;
  3652. te[ 1 ] = me[ 1 ] * scaleX;
  3653. te[ 2 ] = me[ 2 ] * scaleX;
  3654. te[ 3 ] = 0;
  3655. te[ 4 ] = me[ 4 ] * scaleY;
  3656. te[ 5 ] = me[ 5 ] * scaleY;
  3657. te[ 6 ] = me[ 6 ] * scaleY;
  3658. te[ 7 ] = 0;
  3659. te[ 8 ] = me[ 8 ] * scaleZ;
  3660. te[ 9 ] = me[ 9 ] * scaleZ;
  3661. te[ 10 ] = me[ 10 ] * scaleZ;
  3662. te[ 11 ] = 0;
  3663. te[ 12 ] = 0;
  3664. te[ 13 ] = 0;
  3665. te[ 14 ] = 0;
  3666. te[ 15 ] = 1;
  3667. return this;
  3668. }
  3669. makeRotationFromEuler( euler ) {
  3670. const te = this.elements;
  3671. const x = euler.x, y = euler.y, z = euler.z;
  3672. const a = Math.cos( x ), b = Math.sin( x );
  3673. const c = Math.cos( y ), d = Math.sin( y );
  3674. const e = Math.cos( z ), f = Math.sin( z );
  3675. if ( euler.order === 'XYZ' ) {
  3676. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3677. te[ 0 ] = c * e;
  3678. te[ 4 ] = - c * f;
  3679. te[ 8 ] = d;
  3680. te[ 1 ] = af + be * d;
  3681. te[ 5 ] = ae - bf * d;
  3682. te[ 9 ] = - b * c;
  3683. te[ 2 ] = bf - ae * d;
  3684. te[ 6 ] = be + af * d;
  3685. te[ 10 ] = a * c;
  3686. } else if ( euler.order === 'YXZ' ) {
  3687. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3688. te[ 0 ] = ce + df * b;
  3689. te[ 4 ] = de * b - cf;
  3690. te[ 8 ] = a * d;
  3691. te[ 1 ] = a * f;
  3692. te[ 5 ] = a * e;
  3693. te[ 9 ] = - b;
  3694. te[ 2 ] = cf * b - de;
  3695. te[ 6 ] = df + ce * b;
  3696. te[ 10 ] = a * c;
  3697. } else if ( euler.order === 'ZXY' ) {
  3698. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3699. te[ 0 ] = ce - df * b;
  3700. te[ 4 ] = - a * f;
  3701. te[ 8 ] = de + cf * b;
  3702. te[ 1 ] = cf + de * b;
  3703. te[ 5 ] = a * e;
  3704. te[ 9 ] = df - ce * b;
  3705. te[ 2 ] = - a * d;
  3706. te[ 6 ] = b;
  3707. te[ 10 ] = a * c;
  3708. } else if ( euler.order === 'ZYX' ) {
  3709. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3710. te[ 0 ] = c * e;
  3711. te[ 4 ] = be * d - af;
  3712. te[ 8 ] = ae * d + bf;
  3713. te[ 1 ] = c * f;
  3714. te[ 5 ] = bf * d + ae;
  3715. te[ 9 ] = af * d - be;
  3716. te[ 2 ] = - d;
  3717. te[ 6 ] = b * c;
  3718. te[ 10 ] = a * c;
  3719. } else if ( euler.order === 'YZX' ) {
  3720. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3721. te[ 0 ] = c * e;
  3722. te[ 4 ] = bd - ac * f;
  3723. te[ 8 ] = bc * f + ad;
  3724. te[ 1 ] = f;
  3725. te[ 5 ] = a * e;
  3726. te[ 9 ] = - b * e;
  3727. te[ 2 ] = - d * e;
  3728. te[ 6 ] = ad * f + bc;
  3729. te[ 10 ] = ac - bd * f;
  3730. } else if ( euler.order === 'XZY' ) {
  3731. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3732. te[ 0 ] = c * e;
  3733. te[ 4 ] = - f;
  3734. te[ 8 ] = d * e;
  3735. te[ 1 ] = ac * f + bd;
  3736. te[ 5 ] = a * e;
  3737. te[ 9 ] = ad * f - bc;
  3738. te[ 2 ] = bc * f - ad;
  3739. te[ 6 ] = b * e;
  3740. te[ 10 ] = bd * f + ac;
  3741. }
  3742. // bottom row
  3743. te[ 3 ] = 0;
  3744. te[ 7 ] = 0;
  3745. te[ 11 ] = 0;
  3746. // last column
  3747. te[ 12 ] = 0;
  3748. te[ 13 ] = 0;
  3749. te[ 14 ] = 0;
  3750. te[ 15 ] = 1;
  3751. return this;
  3752. }
  3753. makeRotationFromQuaternion( q ) {
  3754. return this.compose( _zero, q, _one );
  3755. }
  3756. lookAt( eye, target, up ) {
  3757. const te = this.elements;
  3758. _z.subVectors( eye, target );
  3759. if ( _z.lengthSq() === 0 ) {
  3760. // eye and target are in the same position
  3761. _z.z = 1;
  3762. }
  3763. _z.normalize();
  3764. _x.crossVectors( up, _z );
  3765. if ( _x.lengthSq() === 0 ) {
  3766. // up and z are parallel
  3767. if ( Math.abs( up.z ) === 1 ) {
  3768. _z.x += 0.0001;
  3769. } else {
  3770. _z.z += 0.0001;
  3771. }
  3772. _z.normalize();
  3773. _x.crossVectors( up, _z );
  3774. }
  3775. _x.normalize();
  3776. _y.crossVectors( _z, _x );
  3777. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3778. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3779. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3780. return this;
  3781. }
  3782. multiply( m ) {
  3783. return this.multiplyMatrices( this, m );
  3784. }
  3785. premultiply( m ) {
  3786. return this.multiplyMatrices( m, this );
  3787. }
  3788. multiplyMatrices( a, b ) {
  3789. const ae = a.elements;
  3790. const be = b.elements;
  3791. const te = this.elements;
  3792. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3793. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3794. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3795. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3796. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3797. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3798. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3799. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3800. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3801. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3802. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3803. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3804. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3805. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3806. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3807. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3808. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3809. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3810. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3811. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3812. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3813. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3814. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3815. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3816. return this;
  3817. }
  3818. multiplyScalar( s ) {
  3819. const te = this.elements;
  3820. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3821. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3822. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3823. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3824. return this;
  3825. }
  3826. determinant() {
  3827. const te = this.elements;
  3828. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3829. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3830. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3831. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3832. //TODO: make this more efficient
  3833. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3834. return (
  3835. n41 * (
  3836. + n14 * n23 * n32
  3837. - n13 * n24 * n32
  3838. - n14 * n22 * n33
  3839. + n12 * n24 * n33
  3840. + n13 * n22 * n34
  3841. - n12 * n23 * n34
  3842. ) +
  3843. n42 * (
  3844. + n11 * n23 * n34
  3845. - n11 * n24 * n33
  3846. + n14 * n21 * n33
  3847. - n13 * n21 * n34
  3848. + n13 * n24 * n31
  3849. - n14 * n23 * n31
  3850. ) +
  3851. n43 * (
  3852. + n11 * n24 * n32
  3853. - n11 * n22 * n34
  3854. - n14 * n21 * n32
  3855. + n12 * n21 * n34
  3856. + n14 * n22 * n31
  3857. - n12 * n24 * n31
  3858. ) +
  3859. n44 * (
  3860. - n13 * n22 * n31
  3861. - n11 * n23 * n32
  3862. + n11 * n22 * n33
  3863. + n13 * n21 * n32
  3864. - n12 * n21 * n33
  3865. + n12 * n23 * n31
  3866. )
  3867. );
  3868. }
  3869. transpose() {
  3870. const te = this.elements;
  3871. let tmp;
  3872. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3873. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3874. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3875. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3876. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3877. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3878. return this;
  3879. }
  3880. setPosition( x, y, z ) {
  3881. const te = this.elements;
  3882. if ( x.isVector3 ) {
  3883. te[ 12 ] = x.x;
  3884. te[ 13 ] = x.y;
  3885. te[ 14 ] = x.z;
  3886. } else {
  3887. te[ 12 ] = x;
  3888. te[ 13 ] = y;
  3889. te[ 14 ] = z;
  3890. }
  3891. return this;
  3892. }
  3893. invert() {
  3894. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3895. const te = this.elements,
  3896. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3897. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3898. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3899. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3900. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3901. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3902. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3903. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3904. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3905. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3906. const detInv = 1 / det;
  3907. te[ 0 ] = t11 * detInv;
  3908. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3909. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3910. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3911. te[ 4 ] = t12 * detInv;
  3912. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3913. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3914. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3915. te[ 8 ] = t13 * detInv;
  3916. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3917. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3918. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3919. te[ 12 ] = t14 * detInv;
  3920. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3921. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3922. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3923. return this;
  3924. }
  3925. scale( v ) {
  3926. const te = this.elements;
  3927. const x = v.x, y = v.y, z = v.z;
  3928. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3929. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3930. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3931. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3932. return this;
  3933. }
  3934. getMaxScaleOnAxis() {
  3935. const te = this.elements;
  3936. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3937. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3938. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3939. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3940. }
  3941. makeTranslation( x, y, z ) {
  3942. if ( x.isVector3 ) {
  3943. this.set(
  3944. 1, 0, 0, x.x,
  3945. 0, 1, 0, x.y,
  3946. 0, 0, 1, x.z,
  3947. 0, 0, 0, 1
  3948. );
  3949. } else {
  3950. this.set(
  3951. 1, 0, 0, x,
  3952. 0, 1, 0, y,
  3953. 0, 0, 1, z,
  3954. 0, 0, 0, 1
  3955. );
  3956. }
  3957. return this;
  3958. }
  3959. makeRotationX( theta ) {
  3960. const c = Math.cos( theta ), s = Math.sin( theta );
  3961. this.set(
  3962. 1, 0, 0, 0,
  3963. 0, c, - s, 0,
  3964. 0, s, c, 0,
  3965. 0, 0, 0, 1
  3966. );
  3967. return this;
  3968. }
  3969. makeRotationY( theta ) {
  3970. const c = Math.cos( theta ), s = Math.sin( theta );
  3971. this.set(
  3972. c, 0, s, 0,
  3973. 0, 1, 0, 0,
  3974. - s, 0, c, 0,
  3975. 0, 0, 0, 1
  3976. );
  3977. return this;
  3978. }
  3979. makeRotationZ( theta ) {
  3980. const c = Math.cos( theta ), s = Math.sin( theta );
  3981. this.set(
  3982. c, - s, 0, 0,
  3983. s, c, 0, 0,
  3984. 0, 0, 1, 0,
  3985. 0, 0, 0, 1
  3986. );
  3987. return this;
  3988. }
  3989. makeRotationAxis( axis, angle ) {
  3990. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3991. const c = Math.cos( angle );
  3992. const s = Math.sin( angle );
  3993. const t = 1 - c;
  3994. const x = axis.x, y = axis.y, z = axis.z;
  3995. const tx = t * x, ty = t * y;
  3996. this.set(
  3997. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3998. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3999. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  4000. 0, 0, 0, 1
  4001. );
  4002. return this;
  4003. }
  4004. makeScale( x, y, z ) {
  4005. this.set(
  4006. x, 0, 0, 0,
  4007. 0, y, 0, 0,
  4008. 0, 0, z, 0,
  4009. 0, 0, 0, 1
  4010. );
  4011. return this;
  4012. }
  4013. makeShear( xy, xz, yx, yz, zx, zy ) {
  4014. this.set(
  4015. 1, yx, zx, 0,
  4016. xy, 1, zy, 0,
  4017. xz, yz, 1, 0,
  4018. 0, 0, 0, 1
  4019. );
  4020. return this;
  4021. }
  4022. compose( position, quaternion, scale ) {
  4023. const te = this.elements;
  4024. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  4025. const x2 = x + x, y2 = y + y, z2 = z + z;
  4026. const xx = x * x2, xy = x * y2, xz = x * z2;
  4027. const yy = y * y2, yz = y * z2, zz = z * z2;
  4028. const wx = w * x2, wy = w * y2, wz = w * z2;
  4029. const sx = scale.x, sy = scale.y, sz = scale.z;
  4030. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  4031. te[ 1 ] = ( xy + wz ) * sx;
  4032. te[ 2 ] = ( xz - wy ) * sx;
  4033. te[ 3 ] = 0;
  4034. te[ 4 ] = ( xy - wz ) * sy;
  4035. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  4036. te[ 6 ] = ( yz + wx ) * sy;
  4037. te[ 7 ] = 0;
  4038. te[ 8 ] = ( xz + wy ) * sz;
  4039. te[ 9 ] = ( yz - wx ) * sz;
  4040. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  4041. te[ 11 ] = 0;
  4042. te[ 12 ] = position.x;
  4043. te[ 13 ] = position.y;
  4044. te[ 14 ] = position.z;
  4045. te[ 15 ] = 1;
  4046. return this;
  4047. }
  4048. decompose( position, quaternion, scale ) {
  4049. const te = this.elements;
  4050. let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  4051. const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  4052. const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  4053. // if determine is negative, we need to invert one scale
  4054. const det = this.determinant();
  4055. if ( det < 0 ) sx = - sx;
  4056. position.x = te[ 12 ];
  4057. position.y = te[ 13 ];
  4058. position.z = te[ 14 ];
  4059. // scale the rotation part
  4060. _m1$2.copy( this );
  4061. const invSX = 1 / sx;
  4062. const invSY = 1 / sy;
  4063. const invSZ = 1 / sz;
  4064. _m1$2.elements[ 0 ] *= invSX;
  4065. _m1$2.elements[ 1 ] *= invSX;
  4066. _m1$2.elements[ 2 ] *= invSX;
  4067. _m1$2.elements[ 4 ] *= invSY;
  4068. _m1$2.elements[ 5 ] *= invSY;
  4069. _m1$2.elements[ 6 ] *= invSY;
  4070. _m1$2.elements[ 8 ] *= invSZ;
  4071. _m1$2.elements[ 9 ] *= invSZ;
  4072. _m1$2.elements[ 10 ] *= invSZ;
  4073. quaternion.setFromRotationMatrix( _m1$2 );
  4074. scale.x = sx;
  4075. scale.y = sy;
  4076. scale.z = sz;
  4077. return this;
  4078. }
  4079. makePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4080. const te = this.elements;
  4081. const x = 2 * near / ( right - left );
  4082. const y = 2 * near / ( top - bottom );
  4083. const a = ( right + left ) / ( right - left );
  4084. const b = ( top + bottom ) / ( top - bottom );
  4085. let c, d;
  4086. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4087. c = - ( far + near ) / ( far - near );
  4088. d = ( - 2 * far * near ) / ( far - near );
  4089. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4090. c = - far / ( far - near );
  4091. d = ( - far * near ) / ( far - near );
  4092. } else {
  4093. throw new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem );
  4094. }
  4095. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  4096. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  4097. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  4098. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  4099. return this;
  4100. }
  4101. makeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4102. const te = this.elements;
  4103. const w = 1.0 / ( right - left );
  4104. const h = 1.0 / ( top - bottom );
  4105. const p = 1.0 / ( far - near );
  4106. const x = ( right + left ) * w;
  4107. const y = ( top + bottom ) * h;
  4108. let z, zInv;
  4109. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4110. z = ( far + near ) * p;
  4111. zInv = - 2 * p;
  4112. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4113. z = near * p;
  4114. zInv = - 1 * p;
  4115. } else {
  4116. throw new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem );
  4117. }
  4118. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  4119. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  4120. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = zInv; te[ 14 ] = - z;
  4121. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  4122. return this;
  4123. }
  4124. equals( matrix ) {
  4125. const te = this.elements;
  4126. const me = matrix.elements;
  4127. for ( let i = 0; i < 16; i ++ ) {
  4128. if ( te[ i ] !== me[ i ] ) return false;
  4129. }
  4130. return true;
  4131. }
  4132. fromArray( array, offset = 0 ) {
  4133. for ( let i = 0; i < 16; i ++ ) {
  4134. this.elements[ i ] = array[ i + offset ];
  4135. }
  4136. return this;
  4137. }
  4138. toArray( array = [], offset = 0 ) {
  4139. const te = this.elements;
  4140. array[ offset ] = te[ 0 ];
  4141. array[ offset + 1 ] = te[ 1 ];
  4142. array[ offset + 2 ] = te[ 2 ];
  4143. array[ offset + 3 ] = te[ 3 ];
  4144. array[ offset + 4 ] = te[ 4 ];
  4145. array[ offset + 5 ] = te[ 5 ];
  4146. array[ offset + 6 ] = te[ 6 ];
  4147. array[ offset + 7 ] = te[ 7 ];
  4148. array[ offset + 8 ] = te[ 8 ];
  4149. array[ offset + 9 ] = te[ 9 ];
  4150. array[ offset + 10 ] = te[ 10 ];
  4151. array[ offset + 11 ] = te[ 11 ];
  4152. array[ offset + 12 ] = te[ 12 ];
  4153. array[ offset + 13 ] = te[ 13 ];
  4154. array[ offset + 14 ] = te[ 14 ];
  4155. array[ offset + 15 ] = te[ 15 ];
  4156. return array;
  4157. }
  4158. }
  4159. const _v1$5 = /*@__PURE__*/ new Vector3();
  4160. const _m1$2 = /*@__PURE__*/ new Matrix4();
  4161. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  4162. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  4163. const _x = /*@__PURE__*/ new Vector3();
  4164. const _y = /*@__PURE__*/ new Vector3();
  4165. const _z = /*@__PURE__*/ new Vector3();
  4166. const _matrix$2 = /*@__PURE__*/ new Matrix4();
  4167. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  4168. class Euler {
  4169. constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {
  4170. this.isEuler = true;
  4171. this._x = x;
  4172. this._y = y;
  4173. this._z = z;
  4174. this._order = order;
  4175. }
  4176. get x() {
  4177. return this._x;
  4178. }
  4179. set x( value ) {
  4180. this._x = value;
  4181. this._onChangeCallback();
  4182. }
  4183. get y() {
  4184. return this._y;
  4185. }
  4186. set y( value ) {
  4187. this._y = value;
  4188. this._onChangeCallback();
  4189. }
  4190. get z() {
  4191. return this._z;
  4192. }
  4193. set z( value ) {
  4194. this._z = value;
  4195. this._onChangeCallback();
  4196. }
  4197. get order() {
  4198. return this._order;
  4199. }
  4200. set order( value ) {
  4201. this._order = value;
  4202. this._onChangeCallback();
  4203. }
  4204. set( x, y, z, order = this._order ) {
  4205. this._x = x;
  4206. this._y = y;
  4207. this._z = z;
  4208. this._order = order;
  4209. this._onChangeCallback();
  4210. return this;
  4211. }
  4212. clone() {
  4213. return new this.constructor( this._x, this._y, this._z, this._order );
  4214. }
  4215. copy( euler ) {
  4216. this._x = euler._x;
  4217. this._y = euler._y;
  4218. this._z = euler._z;
  4219. this._order = euler._order;
  4220. this._onChangeCallback();
  4221. return this;
  4222. }
  4223. setFromRotationMatrix( m, order = this._order, update = true ) {
  4224. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4225. const te = m.elements;
  4226. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4227. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4228. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4229. switch ( order ) {
  4230. case 'XYZ':
  4231. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4232. if ( Math.abs( m13 ) < 0.9999999 ) {
  4233. this._x = Math.atan2( - m23, m33 );
  4234. this._z = Math.atan2( - m12, m11 );
  4235. } else {
  4236. this._x = Math.atan2( m32, m22 );
  4237. this._z = 0;
  4238. }
  4239. break;
  4240. case 'YXZ':
  4241. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4242. if ( Math.abs( m23 ) < 0.9999999 ) {
  4243. this._y = Math.atan2( m13, m33 );
  4244. this._z = Math.atan2( m21, m22 );
  4245. } else {
  4246. this._y = Math.atan2( - m31, m11 );
  4247. this._z = 0;
  4248. }
  4249. break;
  4250. case 'ZXY':
  4251. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4252. if ( Math.abs( m32 ) < 0.9999999 ) {
  4253. this._y = Math.atan2( - m31, m33 );
  4254. this._z = Math.atan2( - m12, m22 );
  4255. } else {
  4256. this._y = 0;
  4257. this._z = Math.atan2( m21, m11 );
  4258. }
  4259. break;
  4260. case 'ZYX':
  4261. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4262. if ( Math.abs( m31 ) < 0.9999999 ) {
  4263. this._x = Math.atan2( m32, m33 );
  4264. this._z = Math.atan2( m21, m11 );
  4265. } else {
  4266. this._x = 0;
  4267. this._z = Math.atan2( - m12, m22 );
  4268. }
  4269. break;
  4270. case 'YZX':
  4271. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4272. if ( Math.abs( m21 ) < 0.9999999 ) {
  4273. this._x = Math.atan2( - m23, m22 );
  4274. this._y = Math.atan2( - m31, m11 );
  4275. } else {
  4276. this._x = 0;
  4277. this._y = Math.atan2( m13, m33 );
  4278. }
  4279. break;
  4280. case 'XZY':
  4281. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4282. if ( Math.abs( m12 ) < 0.9999999 ) {
  4283. this._x = Math.atan2( m32, m22 );
  4284. this._y = Math.atan2( m13, m11 );
  4285. } else {
  4286. this._x = Math.atan2( - m23, m33 );
  4287. this._y = 0;
  4288. }
  4289. break;
  4290. default:
  4291. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  4292. }
  4293. this._order = order;
  4294. if ( update === true ) this._onChangeCallback();
  4295. return this;
  4296. }
  4297. setFromQuaternion( q, order, update ) {
  4298. _matrix$2.makeRotationFromQuaternion( q );
  4299. return this.setFromRotationMatrix( _matrix$2, order, update );
  4300. }
  4301. setFromVector3( v, order = this._order ) {
  4302. return this.set( v.x, v.y, v.z, order );
  4303. }
  4304. reorder( newOrder ) {
  4305. // WARNING: this discards revolution information -bhouston
  4306. _quaternion$3.setFromEuler( this );
  4307. return this.setFromQuaternion( _quaternion$3, newOrder );
  4308. }
  4309. equals( euler ) {
  4310. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4311. }
  4312. fromArray( array ) {
  4313. this._x = array[ 0 ];
  4314. this._y = array[ 1 ];
  4315. this._z = array[ 2 ];
  4316. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4317. this._onChangeCallback();
  4318. return this;
  4319. }
  4320. toArray( array = [], offset = 0 ) {
  4321. array[ offset ] = this._x;
  4322. array[ offset + 1 ] = this._y;
  4323. array[ offset + 2 ] = this._z;
  4324. array[ offset + 3 ] = this._order;
  4325. return array;
  4326. }
  4327. _onChange( callback ) {
  4328. this._onChangeCallback = callback;
  4329. return this;
  4330. }
  4331. _onChangeCallback() {}
  4332. *[ Symbol.iterator ]() {
  4333. yield this._x;
  4334. yield this._y;
  4335. yield this._z;
  4336. yield this._order;
  4337. }
  4338. }
  4339. Euler.DEFAULT_ORDER = 'XYZ';
  4340. class Layers {
  4341. constructor() {
  4342. this.mask = 1 | 0;
  4343. }
  4344. set( channel ) {
  4345. this.mask = ( 1 << channel | 0 ) >>> 0;
  4346. }
  4347. enable( channel ) {
  4348. this.mask |= 1 << channel | 0;
  4349. }
  4350. enableAll() {
  4351. this.mask = 0xffffffff | 0;
  4352. }
  4353. toggle( channel ) {
  4354. this.mask ^= 1 << channel | 0;
  4355. }
  4356. disable( channel ) {
  4357. this.mask &= ~ ( 1 << channel | 0 );
  4358. }
  4359. disableAll() {
  4360. this.mask = 0;
  4361. }
  4362. test( layers ) {
  4363. return ( this.mask & layers.mask ) !== 0;
  4364. }
  4365. isEnabled( channel ) {
  4366. return ( this.mask & ( 1 << channel | 0 ) ) !== 0;
  4367. }
  4368. }
  4369. let _object3DId = 0;
  4370. const _v1$4 = /*@__PURE__*/ new Vector3();
  4371. const _q1 = /*@__PURE__*/ new Quaternion();
  4372. const _m1$1 = /*@__PURE__*/ new Matrix4();
  4373. const _target = /*@__PURE__*/ new Vector3();
  4374. const _position$3 = /*@__PURE__*/ new Vector3();
  4375. const _scale$2 = /*@__PURE__*/ new Vector3();
  4376. const _quaternion$2 = /*@__PURE__*/ new Quaternion();
  4377. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  4378. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4379. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  4380. const _addedEvent = { type: 'added' };
  4381. const _removedEvent = { type: 'removed' };
  4382. const _childaddedEvent = { type: 'childadded', child: null };
  4383. const _childremovedEvent = { type: 'childremoved', child: null };
  4384. class Object3D extends EventDispatcher {
  4385. constructor() {
  4386. super();
  4387. this.isObject3D = true;
  4388. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  4389. this.uuid = generateUUID();
  4390. this.name = '';
  4391. this.type = 'Object3D';
  4392. this.parent = null;
  4393. this.children = [];
  4394. this.up = Object3D.DEFAULT_UP.clone();
  4395. const position = new Vector3();
  4396. const rotation = new Euler();
  4397. const quaternion = new Quaternion();
  4398. const scale = new Vector3( 1, 1, 1 );
  4399. function onRotationChange() {
  4400. quaternion.setFromEuler( rotation, false );
  4401. }
  4402. function onQuaternionChange() {
  4403. rotation.setFromQuaternion( quaternion, undefined, false );
  4404. }
  4405. rotation._onChange( onRotationChange );
  4406. quaternion._onChange( onQuaternionChange );
  4407. Object.defineProperties( this, {
  4408. position: {
  4409. configurable: true,
  4410. enumerable: true,
  4411. value: position
  4412. },
  4413. rotation: {
  4414. configurable: true,
  4415. enumerable: true,
  4416. value: rotation
  4417. },
  4418. quaternion: {
  4419. configurable: true,
  4420. enumerable: true,
  4421. value: quaternion
  4422. },
  4423. scale: {
  4424. configurable: true,
  4425. enumerable: true,
  4426. value: scale
  4427. },
  4428. modelViewMatrix: {
  4429. value: new Matrix4()
  4430. },
  4431. normalMatrix: {
  4432. value: new Matrix3()
  4433. }
  4434. } );
  4435. this.matrix = new Matrix4();
  4436. this.matrixWorld = new Matrix4();
  4437. this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
  4438. this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
  4439. this.matrixWorldNeedsUpdate = false;
  4440. this.layers = new Layers();
  4441. this.visible = true;
  4442. this.castShadow = false;
  4443. this.receiveShadow = false;
  4444. this.frustumCulled = true;
  4445. this.renderOrder = 0;
  4446. this.animations = [];
  4447. this.userData = {};
  4448. }
  4449. onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4450. onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4451. onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4452. onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4453. applyMatrix4( matrix ) {
  4454. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4455. this.matrix.premultiply( matrix );
  4456. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4457. }
  4458. applyQuaternion( q ) {
  4459. this.quaternion.premultiply( q );
  4460. return this;
  4461. }
  4462. setRotationFromAxisAngle( axis, angle ) {
  4463. // assumes axis is normalized
  4464. this.quaternion.setFromAxisAngle( axis, angle );
  4465. }
  4466. setRotationFromEuler( euler ) {
  4467. this.quaternion.setFromEuler( euler, true );
  4468. }
  4469. setRotationFromMatrix( m ) {
  4470. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4471. this.quaternion.setFromRotationMatrix( m );
  4472. }
  4473. setRotationFromQuaternion( q ) {
  4474. // assumes q is normalized
  4475. this.quaternion.copy( q );
  4476. }
  4477. rotateOnAxis( axis, angle ) {
  4478. // rotate object on axis in object space
  4479. // axis is assumed to be normalized
  4480. _q1.setFromAxisAngle( axis, angle );
  4481. this.quaternion.multiply( _q1 );
  4482. return this;
  4483. }
  4484. rotateOnWorldAxis( axis, angle ) {
  4485. // rotate object on axis in world space
  4486. // axis is assumed to be normalized
  4487. // method assumes no rotated parent
  4488. _q1.setFromAxisAngle( axis, angle );
  4489. this.quaternion.premultiply( _q1 );
  4490. return this;
  4491. }
  4492. rotateX( angle ) {
  4493. return this.rotateOnAxis( _xAxis, angle );
  4494. }
  4495. rotateY( angle ) {
  4496. return this.rotateOnAxis( _yAxis, angle );
  4497. }
  4498. rotateZ( angle ) {
  4499. return this.rotateOnAxis( _zAxis, angle );
  4500. }
  4501. translateOnAxis( axis, distance ) {
  4502. // translate object by distance along axis in object space
  4503. // axis is assumed to be normalized
  4504. _v1$4.copy( axis ).applyQuaternion( this.quaternion );
  4505. this.position.add( _v1$4.multiplyScalar( distance ) );
  4506. return this;
  4507. }
  4508. translateX( distance ) {
  4509. return this.translateOnAxis( _xAxis, distance );
  4510. }
  4511. translateY( distance ) {
  4512. return this.translateOnAxis( _yAxis, distance );
  4513. }
  4514. translateZ( distance ) {
  4515. return this.translateOnAxis( _zAxis, distance );
  4516. }
  4517. localToWorld( vector ) {
  4518. this.updateWorldMatrix( true, false );
  4519. return vector.applyMatrix4( this.matrixWorld );
  4520. }
  4521. worldToLocal( vector ) {
  4522. this.updateWorldMatrix( true, false );
  4523. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4524. }
  4525. lookAt( x, y, z ) {
  4526. // This method does not support objects having non-uniformly-scaled parent(s)
  4527. if ( x.isVector3 ) {
  4528. _target.copy( x );
  4529. } else {
  4530. _target.set( x, y, z );
  4531. }
  4532. const parent = this.parent;
  4533. this.updateWorldMatrix( true, false );
  4534. _position$3.setFromMatrixPosition( this.matrixWorld );
  4535. if ( this.isCamera || this.isLight ) {
  4536. _m1$1.lookAt( _position$3, _target, this.up );
  4537. } else {
  4538. _m1$1.lookAt( _target, _position$3, this.up );
  4539. }
  4540. this.quaternion.setFromRotationMatrix( _m1$1 );
  4541. if ( parent ) {
  4542. _m1$1.extractRotation( parent.matrixWorld );
  4543. _q1.setFromRotationMatrix( _m1$1 );
  4544. this.quaternion.premultiply( _q1.invert() );
  4545. }
  4546. }
  4547. add( object ) {
  4548. if ( arguments.length > 1 ) {
  4549. for ( let i = 0; i < arguments.length; i ++ ) {
  4550. this.add( arguments[ i ] );
  4551. }
  4552. return this;
  4553. }
  4554. if ( object === this ) {
  4555. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4556. return this;
  4557. }
  4558. if ( object && object.isObject3D ) {
  4559. object.removeFromParent();
  4560. object.parent = this;
  4561. this.children.push( object );
  4562. object.dispatchEvent( _addedEvent );
  4563. _childaddedEvent.child = object;
  4564. this.dispatchEvent( _childaddedEvent );
  4565. _childaddedEvent.child = null;
  4566. } else {
  4567. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4568. }
  4569. return this;
  4570. }
  4571. remove( object ) {
  4572. if ( arguments.length > 1 ) {
  4573. for ( let i = 0; i < arguments.length; i ++ ) {
  4574. this.remove( arguments[ i ] );
  4575. }
  4576. return this;
  4577. }
  4578. const index = this.children.indexOf( object );
  4579. if ( index !== - 1 ) {
  4580. object.parent = null;
  4581. this.children.splice( index, 1 );
  4582. object.dispatchEvent( _removedEvent );
  4583. _childremovedEvent.child = object;
  4584. this.dispatchEvent( _childremovedEvent );
  4585. _childremovedEvent.child = null;
  4586. }
  4587. return this;
  4588. }
  4589. removeFromParent() {
  4590. const parent = this.parent;
  4591. if ( parent !== null ) {
  4592. parent.remove( this );
  4593. }
  4594. return this;
  4595. }
  4596. clear() {
  4597. return this.remove( ... this.children );
  4598. }
  4599. attach( object ) {
  4600. // adds object as a child of this, while maintaining the object's world transform
  4601. // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
  4602. this.updateWorldMatrix( true, false );
  4603. _m1$1.copy( this.matrixWorld ).invert();
  4604. if ( object.parent !== null ) {
  4605. object.parent.updateWorldMatrix( true, false );
  4606. _m1$1.multiply( object.parent.matrixWorld );
  4607. }
  4608. object.applyMatrix4( _m1$1 );
  4609. object.removeFromParent();
  4610. object.parent = this;
  4611. this.children.push( object );
  4612. object.updateWorldMatrix( false, true );
  4613. object.dispatchEvent( _addedEvent );
  4614. _childaddedEvent.child = object;
  4615. this.dispatchEvent( _childaddedEvent );
  4616. _childaddedEvent.child = null;
  4617. return this;
  4618. }
  4619. getObjectById( id ) {
  4620. return this.getObjectByProperty( 'id', id );
  4621. }
  4622. getObjectByName( name ) {
  4623. return this.getObjectByProperty( 'name', name );
  4624. }
  4625. getObjectByProperty( name, value ) {
  4626. if ( this[ name ] === value ) return this;
  4627. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4628. const child = this.children[ i ];
  4629. const object = child.getObjectByProperty( name, value );
  4630. if ( object !== undefined ) {
  4631. return object;
  4632. }
  4633. }
  4634. return undefined;
  4635. }
  4636. getObjectsByProperty( name, value, result = [] ) {
  4637. if ( this[ name ] === value ) result.push( this );
  4638. const children = this.children;
  4639. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4640. children[ i ].getObjectsByProperty( name, value, result );
  4641. }
  4642. return result;
  4643. }
  4644. getWorldPosition( target ) {
  4645. this.updateWorldMatrix( true, false );
  4646. return target.setFromMatrixPosition( this.matrixWorld );
  4647. }
  4648. getWorldQuaternion( target ) {
  4649. this.updateWorldMatrix( true, false );
  4650. this.matrixWorld.decompose( _position$3, target, _scale$2 );
  4651. return target;
  4652. }
  4653. getWorldScale( target ) {
  4654. this.updateWorldMatrix( true, false );
  4655. this.matrixWorld.decompose( _position$3, _quaternion$2, target );
  4656. return target;
  4657. }
  4658. getWorldDirection( target ) {
  4659. this.updateWorldMatrix( true, false );
  4660. const e = this.matrixWorld.elements;
  4661. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4662. }
  4663. raycast( /* raycaster, intersects */ ) {}
  4664. traverse( callback ) {
  4665. callback( this );
  4666. const children = this.children;
  4667. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4668. children[ i ].traverse( callback );
  4669. }
  4670. }
  4671. traverseVisible( callback ) {
  4672. if ( this.visible === false ) return;
  4673. callback( this );
  4674. const children = this.children;
  4675. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4676. children[ i ].traverseVisible( callback );
  4677. }
  4678. }
  4679. traverseAncestors( callback ) {
  4680. const parent = this.parent;
  4681. if ( parent !== null ) {
  4682. callback( parent );
  4683. parent.traverseAncestors( callback );
  4684. }
  4685. }
  4686. updateMatrix() {
  4687. this.matrix.compose( this.position, this.quaternion, this.scale );
  4688. this.matrixWorldNeedsUpdate = true;
  4689. }
  4690. updateMatrixWorld( force ) {
  4691. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4692. if ( this.matrixWorldNeedsUpdate || force ) {
  4693. if ( this.matrixWorldAutoUpdate === true ) {
  4694. if ( this.parent === null ) {
  4695. this.matrixWorld.copy( this.matrix );
  4696. } else {
  4697. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4698. }
  4699. }
  4700. this.matrixWorldNeedsUpdate = false;
  4701. force = true;
  4702. }
  4703. // make sure descendants are updated if required
  4704. const children = this.children;
  4705. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4706. const child = children[ i ];
  4707. child.updateMatrixWorld( force );
  4708. }
  4709. }
  4710. updateWorldMatrix( updateParents, updateChildren ) {
  4711. const parent = this.parent;
  4712. if ( updateParents === true && parent !== null ) {
  4713. parent.updateWorldMatrix( true, false );
  4714. }
  4715. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4716. if ( this.matrixWorldAutoUpdate === true ) {
  4717. if ( this.parent === null ) {
  4718. this.matrixWorld.copy( this.matrix );
  4719. } else {
  4720. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4721. }
  4722. }
  4723. // make sure descendants are updated
  4724. if ( updateChildren === true ) {
  4725. const children = this.children;
  4726. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4727. const child = children[ i ];
  4728. child.updateWorldMatrix( false, true );
  4729. }
  4730. }
  4731. }
  4732. toJSON( meta ) {
  4733. // meta is a string when called from JSON.stringify
  4734. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4735. const output = {};
  4736. // meta is a hash used to collect geometries, materials.
  4737. // not providing it implies that this is the root object
  4738. // being serialized.
  4739. if ( isRootObject ) {
  4740. // initialize meta obj
  4741. meta = {
  4742. geometries: {},
  4743. materials: {},
  4744. textures: {},
  4745. images: {},
  4746. shapes: {},
  4747. skeletons: {},
  4748. animations: {},
  4749. nodes: {}
  4750. };
  4751. output.metadata = {
  4752. version: 4.6,
  4753. type: 'Object',
  4754. generator: 'Object3D.toJSON'
  4755. };
  4756. }
  4757. // standard Object3D serialization
  4758. const object = {};
  4759. object.uuid = this.uuid;
  4760. object.type = this.type;
  4761. if ( this.name !== '' ) object.name = this.name;
  4762. if ( this.castShadow === true ) object.castShadow = true;
  4763. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4764. if ( this.visible === false ) object.visible = false;
  4765. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4766. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4767. if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;
  4768. object.layers = this.layers.mask;
  4769. object.matrix = this.matrix.toArray();
  4770. object.up = this.up.toArray();
  4771. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4772. // object specific properties
  4773. if ( this.isInstancedMesh ) {
  4774. object.type = 'InstancedMesh';
  4775. object.count = this.count;
  4776. object.instanceMatrix = this.instanceMatrix.toJSON();
  4777. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  4778. }
  4779. if ( this.isBatchedMesh ) {
  4780. object.type = 'BatchedMesh';
  4781. object.perObjectFrustumCulled = this.perObjectFrustumCulled;
  4782. object.sortObjects = this.sortObjects;
  4783. object.drawRanges = this._drawRanges;
  4784. object.reservedRanges = this._reservedRanges;
  4785. object.visibility = this._visibility;
  4786. object.active = this._active;
  4787. object.bounds = this._bounds.map( bound => ( {
  4788. boxInitialized: bound.boxInitialized,
  4789. boxMin: bound.box.min.toArray(),
  4790. boxMax: bound.box.max.toArray(),
  4791. sphereInitialized: bound.sphereInitialized,
  4792. sphereRadius: bound.sphere.radius,
  4793. sphereCenter: bound.sphere.center.toArray()
  4794. } ) );
  4795. object.maxInstanceCount = this._maxInstanceCount;
  4796. object.maxVertexCount = this._maxVertexCount;
  4797. object.maxIndexCount = this._maxIndexCount;
  4798. object.geometryInitialized = this._geometryInitialized;
  4799. object.geometryCount = this._geometryCount;
  4800. object.matricesTexture = this._matricesTexture.toJSON( meta );
  4801. if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
  4802. if ( this.boundingSphere !== null ) {
  4803. object.boundingSphere = {
  4804. center: object.boundingSphere.center.toArray(),
  4805. radius: object.boundingSphere.radius
  4806. };
  4807. }
  4808. if ( this.boundingBox !== null ) {
  4809. object.boundingBox = {
  4810. min: object.boundingBox.min.toArray(),
  4811. max: object.boundingBox.max.toArray()
  4812. };
  4813. }
  4814. }
  4815. //
  4816. function serialize( library, element ) {
  4817. if ( library[ element.uuid ] === undefined ) {
  4818. library[ element.uuid ] = element.toJSON( meta );
  4819. }
  4820. return element.uuid;
  4821. }
  4822. if ( this.isScene ) {
  4823. if ( this.background ) {
  4824. if ( this.background.isColor ) {
  4825. object.background = this.background.toJSON();
  4826. } else if ( this.background.isTexture ) {
  4827. object.background = this.background.toJSON( meta ).uuid;
  4828. }
  4829. }
  4830. if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {
  4831. object.environment = this.environment.toJSON( meta ).uuid;
  4832. }
  4833. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  4834. object.geometry = serialize( meta.geometries, this.geometry );
  4835. const parameters = this.geometry.parameters;
  4836. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4837. const shapes = parameters.shapes;
  4838. if ( Array.isArray( shapes ) ) {
  4839. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4840. const shape = shapes[ i ];
  4841. serialize( meta.shapes, shape );
  4842. }
  4843. } else {
  4844. serialize( meta.shapes, shapes );
  4845. }
  4846. }
  4847. }
  4848. if ( this.isSkinnedMesh ) {
  4849. object.bindMode = this.bindMode;
  4850. object.bindMatrix = this.bindMatrix.toArray();
  4851. if ( this.skeleton !== undefined ) {
  4852. serialize( meta.skeletons, this.skeleton );
  4853. object.skeleton = this.skeleton.uuid;
  4854. }
  4855. }
  4856. if ( this.material !== undefined ) {
  4857. if ( Array.isArray( this.material ) ) {
  4858. const uuids = [];
  4859. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4860. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4861. }
  4862. object.material = uuids;
  4863. } else {
  4864. object.material = serialize( meta.materials, this.material );
  4865. }
  4866. }
  4867. //
  4868. if ( this.children.length > 0 ) {
  4869. object.children = [];
  4870. for ( let i = 0; i < this.children.length; i ++ ) {
  4871. object.children.push( this.children[ i ].toJSON( meta ).object );
  4872. }
  4873. }
  4874. //
  4875. if ( this.animations.length > 0 ) {
  4876. object.animations = [];
  4877. for ( let i = 0; i < this.animations.length; i ++ ) {
  4878. const animation = this.animations[ i ];
  4879. object.animations.push( serialize( meta.animations, animation ) );
  4880. }
  4881. }
  4882. if ( isRootObject ) {
  4883. const geometries = extractFromCache( meta.geometries );
  4884. const materials = extractFromCache( meta.materials );
  4885. const textures = extractFromCache( meta.textures );
  4886. const images = extractFromCache( meta.images );
  4887. const shapes = extractFromCache( meta.shapes );
  4888. const skeletons = extractFromCache( meta.skeletons );
  4889. const animations = extractFromCache( meta.animations );
  4890. const nodes = extractFromCache( meta.nodes );
  4891. if ( geometries.length > 0 ) output.geometries = geometries;
  4892. if ( materials.length > 0 ) output.materials = materials;
  4893. if ( textures.length > 0 ) output.textures = textures;
  4894. if ( images.length > 0 ) output.images = images;
  4895. if ( shapes.length > 0 ) output.shapes = shapes;
  4896. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4897. if ( animations.length > 0 ) output.animations = animations;
  4898. if ( nodes.length > 0 ) output.nodes = nodes;
  4899. }
  4900. output.object = object;
  4901. return output;
  4902. // extract data from the cache hash
  4903. // remove metadata on each item
  4904. // and return as array
  4905. function extractFromCache( cache ) {
  4906. const values = [];
  4907. for ( const key in cache ) {
  4908. const data = cache[ key ];
  4909. delete data.metadata;
  4910. values.push( data );
  4911. }
  4912. return values;
  4913. }
  4914. }
  4915. clone( recursive ) {
  4916. return new this.constructor().copy( this, recursive );
  4917. }
  4918. copy( source, recursive = true ) {
  4919. this.name = source.name;
  4920. this.up.copy( source.up );
  4921. this.position.copy( source.position );
  4922. this.rotation.order = source.rotation.order;
  4923. this.quaternion.copy( source.quaternion );
  4924. this.scale.copy( source.scale );
  4925. this.matrix.copy( source.matrix );
  4926. this.matrixWorld.copy( source.matrixWorld );
  4927. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4928. this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
  4929. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4930. this.layers.mask = source.layers.mask;
  4931. this.visible = source.visible;
  4932. this.castShadow = source.castShadow;
  4933. this.receiveShadow = source.receiveShadow;
  4934. this.frustumCulled = source.frustumCulled;
  4935. this.renderOrder = source.renderOrder;
  4936. this.animations = source.animations.slice();
  4937. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4938. if ( recursive === true ) {
  4939. for ( let i = 0; i < source.children.length; i ++ ) {
  4940. const child = source.children[ i ];
  4941. this.add( child.clone() );
  4942. }
  4943. }
  4944. return this;
  4945. }
  4946. }
  4947. Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4948. Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
  4949. Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
  4950. const _v0$1 = /*@__PURE__*/ new Vector3();
  4951. const _v1$3 = /*@__PURE__*/ new Vector3();
  4952. const _v2$2 = /*@__PURE__*/ new Vector3();
  4953. const _v3$2 = /*@__PURE__*/ new Vector3();
  4954. const _vab = /*@__PURE__*/ new Vector3();
  4955. const _vac = /*@__PURE__*/ new Vector3();
  4956. const _vbc = /*@__PURE__*/ new Vector3();
  4957. const _vap = /*@__PURE__*/ new Vector3();
  4958. const _vbp = /*@__PURE__*/ new Vector3();
  4959. const _vcp = /*@__PURE__*/ new Vector3();
  4960. const _v40 = /*@__PURE__*/ new Vector4();
  4961. const _v41 = /*@__PURE__*/ new Vector4();
  4962. const _v42 = /*@__PURE__*/ new Vector4();
  4963. class Triangle {
  4964. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4965. this.a = a;
  4966. this.b = b;
  4967. this.c = c;
  4968. }
  4969. static getNormal( a, b, c, target ) {
  4970. target.subVectors( c, b );
  4971. _v0$1.subVectors( a, b );
  4972. target.cross( _v0$1 );
  4973. const targetLengthSq = target.lengthSq();
  4974. if ( targetLengthSq > 0 ) {
  4975. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4976. }
  4977. return target.set( 0, 0, 0 );
  4978. }
  4979. // static/instance method to calculate barycentric coordinates
  4980. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4981. static getBarycoord( point, a, b, c, target ) {
  4982. _v0$1.subVectors( c, a );
  4983. _v1$3.subVectors( b, a );
  4984. _v2$2.subVectors( point, a );
  4985. const dot00 = _v0$1.dot( _v0$1 );
  4986. const dot01 = _v0$1.dot( _v1$3 );
  4987. const dot02 = _v0$1.dot( _v2$2 );
  4988. const dot11 = _v1$3.dot( _v1$3 );
  4989. const dot12 = _v1$3.dot( _v2$2 );
  4990. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4991. // collinear or singular triangle
  4992. if ( denom === 0 ) {
  4993. target.set( 0, 0, 0 );
  4994. return null;
  4995. }
  4996. const invDenom = 1 / denom;
  4997. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4998. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4999. // barycentric coordinates must always sum to 1
  5000. return target.set( 1 - u - v, v, u );
  5001. }
  5002. static containsPoint( point, a, b, c ) {
  5003. // if the triangle is degenerate then we can't contain a point
  5004. if ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) {
  5005. return false;
  5006. }
  5007. return ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 );
  5008. }
  5009. static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {
  5010. if ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) {
  5011. target.x = 0;
  5012. target.y = 0;
  5013. if ( 'z' in target ) target.z = 0;
  5014. if ( 'w' in target ) target.w = 0;
  5015. return null;
  5016. }
  5017. target.setScalar( 0 );
  5018. target.addScaledVector( v1, _v3$2.x );
  5019. target.addScaledVector( v2, _v3$2.y );
  5020. target.addScaledVector( v3, _v3$2.z );
  5021. return target;
  5022. }
  5023. static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) {
  5024. _v40.setScalar( 0 );
  5025. _v41.setScalar( 0 );
  5026. _v42.setScalar( 0 );
  5027. _v40.fromBufferAttribute( attr, i1 );
  5028. _v41.fromBufferAttribute( attr, i2 );
  5029. _v42.fromBufferAttribute( attr, i3 );
  5030. target.setScalar( 0 );
  5031. target.addScaledVector( _v40, barycoord.x );
  5032. target.addScaledVector( _v41, barycoord.y );
  5033. target.addScaledVector( _v42, barycoord.z );
  5034. return target;
  5035. }
  5036. static isFrontFacing( a, b, c, direction ) {
  5037. _v0$1.subVectors( c, b );
  5038. _v1$3.subVectors( a, b );
  5039. // strictly front facing
  5040. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  5041. }
  5042. set( a, b, c ) {
  5043. this.a.copy( a );
  5044. this.b.copy( b );
  5045. this.c.copy( c );
  5046. return this;
  5047. }
  5048. setFromPointsAndIndices( points, i0, i1, i2 ) {
  5049. this.a.copy( points[ i0 ] );
  5050. this.b.copy( points[ i1 ] );
  5051. this.c.copy( points[ i2 ] );
  5052. return this;
  5053. }
  5054. setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
  5055. this.a.fromBufferAttribute( attribute, i0 );
  5056. this.b.fromBufferAttribute( attribute, i1 );
  5057. this.c.fromBufferAttribute( attribute, i2 );
  5058. return this;
  5059. }
  5060. clone() {
  5061. return new this.constructor().copy( this );
  5062. }
  5063. copy( triangle ) {
  5064. this.a.copy( triangle.a );
  5065. this.b.copy( triangle.b );
  5066. this.c.copy( triangle.c );
  5067. return this;
  5068. }
  5069. getArea() {
  5070. _v0$1.subVectors( this.c, this.b );
  5071. _v1$3.subVectors( this.a, this.b );
  5072. return _v0$1.cross( _v1$3 ).length() * 0.5;
  5073. }
  5074. getMidpoint( target ) {
  5075. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  5076. }
  5077. getNormal( target ) {
  5078. return Triangle.getNormal( this.a, this.b, this.c, target );
  5079. }
  5080. getPlane( target ) {
  5081. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  5082. }
  5083. getBarycoord( point, target ) {
  5084. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  5085. }
  5086. getInterpolation( point, v1, v2, v3, target ) {
  5087. return Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target );
  5088. }
  5089. containsPoint( point ) {
  5090. return Triangle.containsPoint( point, this.a, this.b, this.c );
  5091. }
  5092. isFrontFacing( direction ) {
  5093. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  5094. }
  5095. intersectsBox( box ) {
  5096. return box.intersectsTriangle( this );
  5097. }
  5098. closestPointToPoint( p, target ) {
  5099. const a = this.a, b = this.b, c = this.c;
  5100. let v, w;
  5101. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5102. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5103. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5104. // basically, we're distinguishing which of the voronoi regions of the triangle
  5105. // the point lies in with the minimum amount of redundant computation.
  5106. _vab.subVectors( b, a );
  5107. _vac.subVectors( c, a );
  5108. _vap.subVectors( p, a );
  5109. const d1 = _vab.dot( _vap );
  5110. const d2 = _vac.dot( _vap );
  5111. if ( d1 <= 0 && d2 <= 0 ) {
  5112. // vertex region of A; barycentric coords (1, 0, 0)
  5113. return target.copy( a );
  5114. }
  5115. _vbp.subVectors( p, b );
  5116. const d3 = _vab.dot( _vbp );
  5117. const d4 = _vac.dot( _vbp );
  5118. if ( d3 >= 0 && d4 <= d3 ) {
  5119. // vertex region of B; barycentric coords (0, 1, 0)
  5120. return target.copy( b );
  5121. }
  5122. const vc = d1 * d4 - d3 * d2;
  5123. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  5124. v = d1 / ( d1 - d3 );
  5125. // edge region of AB; barycentric coords (1-v, v, 0)
  5126. return target.copy( a ).addScaledVector( _vab, v );
  5127. }
  5128. _vcp.subVectors( p, c );
  5129. const d5 = _vab.dot( _vcp );
  5130. const d6 = _vac.dot( _vcp );
  5131. if ( d6 >= 0 && d5 <= d6 ) {
  5132. // vertex region of C; barycentric coords (0, 0, 1)
  5133. return target.copy( c );
  5134. }
  5135. const vb = d5 * d2 - d1 * d6;
  5136. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  5137. w = d2 / ( d2 - d6 );
  5138. // edge region of AC; barycentric coords (1-w, 0, w)
  5139. return target.copy( a ).addScaledVector( _vac, w );
  5140. }
  5141. const va = d3 * d6 - d5 * d4;
  5142. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  5143. _vbc.subVectors( c, b );
  5144. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  5145. // edge region of BC; barycentric coords (0, 1-w, w)
  5146. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  5147. }
  5148. // face region
  5149. const denom = 1 / ( va + vb + vc );
  5150. // u = va * denom
  5151. v = vb * denom;
  5152. w = vc * denom;
  5153. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  5154. }
  5155. equals( triangle ) {
  5156. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  5157. }
  5158. }
  5159. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5160. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5161. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5162. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5163. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5164. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5165. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5166. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5167. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5168. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5169. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5170. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5171. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5172. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5173. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5174. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5175. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5176. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5177. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5178. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5179. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5180. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5181. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5182. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5183. const _hslA = { h: 0, s: 0, l: 0 };
  5184. const _hslB = { h: 0, s: 0, l: 0 };
  5185. function hue2rgb( p, q, t ) {
  5186. if ( t < 0 ) t += 1;
  5187. if ( t > 1 ) t -= 1;
  5188. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5189. if ( t < 1 / 2 ) return q;
  5190. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5191. return p;
  5192. }
  5193. class Color {
  5194. constructor( r, g, b ) {
  5195. this.isColor = true;
  5196. this.r = 1;
  5197. this.g = 1;
  5198. this.b = 1;
  5199. return this.set( r, g, b );
  5200. }
  5201. set( r, g, b ) {
  5202. if ( g === undefined && b === undefined ) {
  5203. // r is THREE.Color, hex or string
  5204. const value = r;
  5205. if ( value && value.isColor ) {
  5206. this.copy( value );
  5207. } else if ( typeof value === 'number' ) {
  5208. this.setHex( value );
  5209. } else if ( typeof value === 'string' ) {
  5210. this.setStyle( value );
  5211. }
  5212. } else {
  5213. this.setRGB( r, g, b );
  5214. }
  5215. return this;
  5216. }
  5217. setScalar( scalar ) {
  5218. this.r = scalar;
  5219. this.g = scalar;
  5220. this.b = scalar;
  5221. return this;
  5222. }
  5223. setHex( hex, colorSpace = SRGBColorSpace ) {
  5224. hex = Math.floor( hex );
  5225. this.r = ( hex >> 16 & 255 ) / 255;
  5226. this.g = ( hex >> 8 & 255 ) / 255;
  5227. this.b = ( hex & 255 ) / 255;
  5228. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5229. return this;
  5230. }
  5231. setRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) {
  5232. this.r = r;
  5233. this.g = g;
  5234. this.b = b;
  5235. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5236. return this;
  5237. }
  5238. setHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) {
  5239. // h,s,l ranges are in 0.0 - 1.0
  5240. h = euclideanModulo( h, 1 );
  5241. s = clamp( s, 0, 1 );
  5242. l = clamp( l, 0, 1 );
  5243. if ( s === 0 ) {
  5244. this.r = this.g = this.b = l;
  5245. } else {
  5246. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5247. const q = ( 2 * l ) - p;
  5248. this.r = hue2rgb( q, p, h + 1 / 3 );
  5249. this.g = hue2rgb( q, p, h );
  5250. this.b = hue2rgb( q, p, h - 1 / 3 );
  5251. }
  5252. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5253. return this;
  5254. }
  5255. setStyle( style, colorSpace = SRGBColorSpace ) {
  5256. function handleAlpha( string ) {
  5257. if ( string === undefined ) return;
  5258. if ( parseFloat( string ) < 1 ) {
  5259. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5260. }
  5261. }
  5262. let m;
  5263. if ( m = /^(\w+)\(([^\)]*)\)/.exec( style ) ) {
  5264. // rgb / hsl
  5265. let color;
  5266. const name = m[ 1 ];
  5267. const components = m[ 2 ];
  5268. switch ( name ) {
  5269. case 'rgb':
  5270. case 'rgba':
  5271. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5272. // rgb(255,0,0) rgba(255,0,0,0.5)
  5273. handleAlpha( color[ 4 ] );
  5274. return this.setRGB(
  5275. Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255,
  5276. Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255,
  5277. Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255,
  5278. colorSpace
  5279. );
  5280. }
  5281. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5282. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5283. handleAlpha( color[ 4 ] );
  5284. return this.setRGB(
  5285. Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100,
  5286. Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100,
  5287. Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100,
  5288. colorSpace
  5289. );
  5290. }
  5291. break;
  5292. case 'hsl':
  5293. case 'hsla':
  5294. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5295. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5296. handleAlpha( color[ 4 ] );
  5297. return this.setHSL(
  5298. parseFloat( color[ 1 ] ) / 360,
  5299. parseFloat( color[ 2 ] ) / 100,
  5300. parseFloat( color[ 3 ] ) / 100,
  5301. colorSpace
  5302. );
  5303. }
  5304. break;
  5305. default:
  5306. console.warn( 'THREE.Color: Unknown color model ' + style );
  5307. }
  5308. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5309. // hex color
  5310. const hex = m[ 1 ];
  5311. const size = hex.length;
  5312. if ( size === 3 ) {
  5313. // #ff0
  5314. return this.setRGB(
  5315. parseInt( hex.charAt( 0 ), 16 ) / 15,
  5316. parseInt( hex.charAt( 1 ), 16 ) / 15,
  5317. parseInt( hex.charAt( 2 ), 16 ) / 15,
  5318. colorSpace
  5319. );
  5320. } else if ( size === 6 ) {
  5321. // #ff0000
  5322. return this.setHex( parseInt( hex, 16 ), colorSpace );
  5323. } else {
  5324. console.warn( 'THREE.Color: Invalid hex color ' + style );
  5325. }
  5326. } else if ( style && style.length > 0 ) {
  5327. return this.setColorName( style, colorSpace );
  5328. }
  5329. return this;
  5330. }
  5331. setColorName( style, colorSpace = SRGBColorSpace ) {
  5332. // color keywords
  5333. const hex = _colorKeywords[ style.toLowerCase() ];
  5334. if ( hex !== undefined ) {
  5335. // red
  5336. this.setHex( hex, colorSpace );
  5337. } else {
  5338. // unknown color
  5339. console.warn( 'THREE.Color: Unknown color ' + style );
  5340. }
  5341. return this;
  5342. }
  5343. clone() {
  5344. return new this.constructor( this.r, this.g, this.b );
  5345. }
  5346. copy( color ) {
  5347. this.r = color.r;
  5348. this.g = color.g;
  5349. this.b = color.b;
  5350. return this;
  5351. }
  5352. copySRGBToLinear( color ) {
  5353. this.r = SRGBToLinear( color.r );
  5354. this.g = SRGBToLinear( color.g );
  5355. this.b = SRGBToLinear( color.b );
  5356. return this;
  5357. }
  5358. copyLinearToSRGB( color ) {
  5359. this.r = LinearToSRGB( color.r );
  5360. this.g = LinearToSRGB( color.g );
  5361. this.b = LinearToSRGB( color.b );
  5362. return this;
  5363. }
  5364. convertSRGBToLinear() {
  5365. this.copySRGBToLinear( this );
  5366. return this;
  5367. }
  5368. convertLinearToSRGB() {
  5369. this.copyLinearToSRGB( this );
  5370. return this;
  5371. }
  5372. getHex( colorSpace = SRGBColorSpace ) {
  5373. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5374. return Math.round( clamp( _color.r * 255, 0, 255 ) ) * 65536 + Math.round( clamp( _color.g * 255, 0, 255 ) ) * 256 + Math.round( clamp( _color.b * 255, 0, 255 ) );
  5375. }
  5376. getHexString( colorSpace = SRGBColorSpace ) {
  5377. return ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( - 6 );
  5378. }
  5379. getHSL( target, colorSpace = ColorManagement.workingColorSpace ) {
  5380. // h,s,l ranges are in 0.0 - 1.0
  5381. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5382. const r = _color.r, g = _color.g, b = _color.b;
  5383. const max = Math.max( r, g, b );
  5384. const min = Math.min( r, g, b );
  5385. let hue, saturation;
  5386. const lightness = ( min + max ) / 2.0;
  5387. if ( min === max ) {
  5388. hue = 0;
  5389. saturation = 0;
  5390. } else {
  5391. const delta = max - min;
  5392. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5393. switch ( max ) {
  5394. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5395. case g: hue = ( b - r ) / delta + 2; break;
  5396. case b: hue = ( r - g ) / delta + 4; break;
  5397. }
  5398. hue /= 6;
  5399. }
  5400. target.h = hue;
  5401. target.s = saturation;
  5402. target.l = lightness;
  5403. return target;
  5404. }
  5405. getRGB( target, colorSpace = ColorManagement.workingColorSpace ) {
  5406. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5407. target.r = _color.r;
  5408. target.g = _color.g;
  5409. target.b = _color.b;
  5410. return target;
  5411. }
  5412. getStyle( colorSpace = SRGBColorSpace ) {
  5413. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5414. const r = _color.r, g = _color.g, b = _color.b;
  5415. if ( colorSpace !== SRGBColorSpace ) {
  5416. // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
  5417. return `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`;
  5418. }
  5419. return `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`;
  5420. }
  5421. offsetHSL( h, s, l ) {
  5422. this.getHSL( _hslA );
  5423. return this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l );
  5424. }
  5425. add( color ) {
  5426. this.r += color.r;
  5427. this.g += color.g;
  5428. this.b += color.b;
  5429. return this;
  5430. }
  5431. addColors( color1, color2 ) {
  5432. this.r = color1.r + color2.r;
  5433. this.g = color1.g + color2.g;
  5434. this.b = color1.b + color2.b;
  5435. return this;
  5436. }
  5437. addScalar( s ) {
  5438. this.r += s;
  5439. this.g += s;
  5440. this.b += s;
  5441. return this;
  5442. }
  5443. sub( color ) {
  5444. this.r = Math.max( 0, this.r - color.r );
  5445. this.g = Math.max( 0, this.g - color.g );
  5446. this.b = Math.max( 0, this.b - color.b );
  5447. return this;
  5448. }
  5449. multiply( color ) {
  5450. this.r *= color.r;
  5451. this.g *= color.g;
  5452. this.b *= color.b;
  5453. return this;
  5454. }
  5455. multiplyScalar( s ) {
  5456. this.r *= s;
  5457. this.g *= s;
  5458. this.b *= s;
  5459. return this;
  5460. }
  5461. lerp( color, alpha ) {
  5462. this.r += ( color.r - this.r ) * alpha;
  5463. this.g += ( color.g - this.g ) * alpha;
  5464. this.b += ( color.b - this.b ) * alpha;
  5465. return this;
  5466. }
  5467. lerpColors( color1, color2, alpha ) {
  5468. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5469. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5470. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5471. return this;
  5472. }
  5473. lerpHSL( color, alpha ) {
  5474. this.getHSL( _hslA );
  5475. color.getHSL( _hslB );
  5476. const h = lerp( _hslA.h, _hslB.h, alpha );
  5477. const s = lerp( _hslA.s, _hslB.s, alpha );
  5478. const l = lerp( _hslA.l, _hslB.l, alpha );
  5479. this.setHSL( h, s, l );
  5480. return this;
  5481. }
  5482. setFromVector3( v ) {
  5483. this.r = v.x;
  5484. this.g = v.y;
  5485. this.b = v.z;
  5486. return this;
  5487. }
  5488. applyMatrix3( m ) {
  5489. const r = this.r, g = this.g, b = this.b;
  5490. const e = m.elements;
  5491. this.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b;
  5492. this.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b;
  5493. this.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b;
  5494. return this;
  5495. }
  5496. equals( c ) {
  5497. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5498. }
  5499. fromArray( array, offset = 0 ) {
  5500. this.r = array[ offset ];
  5501. this.g = array[ offset + 1 ];
  5502. this.b = array[ offset + 2 ];
  5503. return this;
  5504. }
  5505. toArray( array = [], offset = 0 ) {
  5506. array[ offset ] = this.r;
  5507. array[ offset + 1 ] = this.g;
  5508. array[ offset + 2 ] = this.b;
  5509. return array;
  5510. }
  5511. fromBufferAttribute( attribute, index ) {
  5512. this.r = attribute.getX( index );
  5513. this.g = attribute.getY( index );
  5514. this.b = attribute.getZ( index );
  5515. return this;
  5516. }
  5517. toJSON() {
  5518. return this.getHex();
  5519. }
  5520. *[ Symbol.iterator ]() {
  5521. yield this.r;
  5522. yield this.g;
  5523. yield this.b;
  5524. }
  5525. }
  5526. const _color = /*@__PURE__*/ new Color();
  5527. Color.NAMES = _colorKeywords;
  5528. let _materialId = 0;
  5529. class Material extends EventDispatcher {
  5530. constructor() {
  5531. super();
  5532. this.isMaterial = true;
  5533. Object.defineProperty( this, 'id', { value: _materialId ++ } );
  5534. this.uuid = generateUUID();
  5535. this.name = '';
  5536. this.type = 'Material';
  5537. this.blending = NormalBlending;
  5538. this.side = FrontSide;
  5539. this.vertexColors = false;
  5540. this.opacity = 1;
  5541. this.transparent = false;
  5542. this.alphaHash = false;
  5543. this.blendSrc = SrcAlphaFactor;
  5544. this.blendDst = OneMinusSrcAlphaFactor;
  5545. this.blendEquation = AddEquation;
  5546. this.blendSrcAlpha = null;
  5547. this.blendDstAlpha = null;
  5548. this.blendEquationAlpha = null;
  5549. this.blendColor = new Color( 0, 0, 0 );
  5550. this.blendAlpha = 0;
  5551. this.depthFunc = LessEqualDepth;
  5552. this.depthTest = true;
  5553. this.depthWrite = true;
  5554. this.stencilWriteMask = 0xff;
  5555. this.stencilFunc = AlwaysStencilFunc;
  5556. this.stencilRef = 0;
  5557. this.stencilFuncMask = 0xff;
  5558. this.stencilFail = KeepStencilOp;
  5559. this.stencilZFail = KeepStencilOp;
  5560. this.stencilZPass = KeepStencilOp;
  5561. this.stencilWrite = false;
  5562. this.clippingPlanes = null;
  5563. this.clipIntersection = false;
  5564. this.clipShadows = false;
  5565. this.shadowSide = null;
  5566. this.colorWrite = true;
  5567. this.precision = null; // override the renderer's default precision for this material
  5568. this.polygonOffset = false;
  5569. this.polygonOffsetFactor = 0;
  5570. this.polygonOffsetUnits = 0;
  5571. this.dithering = false;
  5572. this.alphaToCoverage = false;
  5573. this.premultipliedAlpha = false;
  5574. this.forceSinglePass = false;
  5575. this.visible = true;
  5576. this.toneMapped = true;
  5577. this.userData = {};
  5578. this.version = 0;
  5579. this._alphaTest = 0;
  5580. }
  5581. get alphaTest() {
  5582. return this._alphaTest;
  5583. }
  5584. set alphaTest( value ) {
  5585. if ( this._alphaTest > 0 !== value > 0 ) {
  5586. this.version ++;
  5587. }
  5588. this._alphaTest = value;
  5589. }
  5590. // onBeforeRender and onBeforeCompile only supported in WebGLRenderer
  5591. onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}
  5592. onBeforeCompile( /* shaderobject, renderer */ ) {}
  5593. customProgramCacheKey() {
  5594. return this.onBeforeCompile.toString();
  5595. }
  5596. setValues( values ) {
  5597. if ( values === undefined ) return;
  5598. for ( const key in values ) {
  5599. const newValue = values[ key ];
  5600. if ( newValue === undefined ) {
  5601. console.warn( `THREE.Material: parameter '${ key }' has value of undefined.` );
  5602. continue;
  5603. }
  5604. const currentValue = this[ key ];
  5605. if ( currentValue === undefined ) {
  5606. console.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` );
  5607. continue;
  5608. }
  5609. if ( currentValue && currentValue.isColor ) {
  5610. currentValue.set( newValue );
  5611. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5612. currentValue.copy( newValue );
  5613. } else {
  5614. this[ key ] = newValue;
  5615. }
  5616. }
  5617. }
  5618. toJSON( meta ) {
  5619. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  5620. if ( isRootObject ) {
  5621. meta = {
  5622. textures: {},
  5623. images: {}
  5624. };
  5625. }
  5626. const data = {
  5627. metadata: {
  5628. version: 4.6,
  5629. type: 'Material',
  5630. generator: 'Material.toJSON'
  5631. }
  5632. };
  5633. // standard Material serialization
  5634. data.uuid = this.uuid;
  5635. data.type = this.type;
  5636. if ( this.name !== '' ) data.name = this.name;
  5637. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5638. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5639. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5640. if ( this.sheen !== undefined ) data.sheen = this.sheen;
  5641. if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
  5642. if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
  5643. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5644. if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5645. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5646. if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
  5647. if ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex();
  5648. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5649. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5650. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5651. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5652. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5653. }
  5654. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5655. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5656. }
  5657. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5658. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5659. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5660. }
  5661. if ( this.dispersion !== undefined ) data.dispersion = this.dispersion;
  5662. if ( this.iridescence !== undefined ) data.iridescence = this.iridescence;
  5663. if ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR;
  5664. if ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange;
  5665. if ( this.iridescenceMap && this.iridescenceMap.isTexture ) {
  5666. data.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid;
  5667. }
  5668. if ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) {
  5669. data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid;
  5670. }
  5671. if ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy;
  5672. if ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation;
  5673. if ( this.anisotropyMap && this.anisotropyMap.isTexture ) {
  5674. data.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid;
  5675. }
  5676. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5677. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5678. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5679. if ( this.lightMap && this.lightMap.isTexture ) {
  5680. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5681. data.lightMapIntensity = this.lightMapIntensity;
  5682. }
  5683. if ( this.aoMap && this.aoMap.isTexture ) {
  5684. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5685. data.aoMapIntensity = this.aoMapIntensity;
  5686. }
  5687. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5688. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5689. data.bumpScale = this.bumpScale;
  5690. }
  5691. if ( this.normalMap && this.normalMap.isTexture ) {
  5692. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5693. data.normalMapType = this.normalMapType;
  5694. data.normalScale = this.normalScale.toArray();
  5695. }
  5696. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5697. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5698. data.displacementScale = this.displacementScale;
  5699. data.displacementBias = this.displacementBias;
  5700. }
  5701. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5702. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5703. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5704. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5705. if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;
  5706. if ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid;
  5707. if ( this.envMap && this.envMap.isTexture ) {
  5708. data.envMap = this.envMap.toJSON( meta ).uuid;
  5709. if ( this.combine !== undefined ) data.combine = this.combine;
  5710. }
  5711. if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();
  5712. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5713. if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
  5714. if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
  5715. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5716. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5717. }
  5718. if ( this.transmission !== undefined ) data.transmission = this.transmission;
  5719. if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
  5720. if ( this.thickness !== undefined ) data.thickness = this.thickness;
  5721. if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
  5722. if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;
  5723. if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();
  5724. if ( this.size !== undefined ) data.size = this.size;
  5725. if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
  5726. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5727. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5728. if ( this.side !== FrontSide ) data.side = this.side;
  5729. if ( this.vertexColors === true ) data.vertexColors = true;
  5730. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5731. if ( this.transparent === true ) data.transparent = true;
  5732. if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
  5733. if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
  5734. if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
  5735. if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
  5736. if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
  5737. if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
  5738. if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
  5739. if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;
  5740. if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
  5741. if ( this.depthTest === false ) data.depthTest = this.depthTest;
  5742. if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
  5743. if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;
  5744. if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
  5745. if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
  5746. if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
  5747. if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
  5748. if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
  5749. if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
  5750. if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
  5751. if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;
  5752. // rotation (SpriteMaterial)
  5753. if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
  5754. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5755. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5756. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5757. if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5758. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5759. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5760. if ( this.scale !== undefined ) data.scale = this.scale;
  5761. if ( this.dithering === true ) data.dithering = true;
  5762. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5763. if ( this.alphaHash === true ) data.alphaHash = true;
  5764. if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
  5765. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
  5766. if ( this.forceSinglePass === true ) data.forceSinglePass = true;
  5767. if ( this.wireframe === true ) data.wireframe = true;
  5768. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5769. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5770. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5771. if ( this.flatShading === true ) data.flatShading = true;
  5772. if ( this.visible === false ) data.visible = false;
  5773. if ( this.toneMapped === false ) data.toneMapped = false;
  5774. if ( this.fog === false ) data.fog = false;
  5775. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  5776. // TODO: Copied from Object3D.toJSON
  5777. function extractFromCache( cache ) {
  5778. const values = [];
  5779. for ( const key in cache ) {
  5780. const data = cache[ key ];
  5781. delete data.metadata;
  5782. values.push( data );
  5783. }
  5784. return values;
  5785. }
  5786. if ( isRootObject ) {
  5787. const textures = extractFromCache( meta.textures );
  5788. const images = extractFromCache( meta.images );
  5789. if ( textures.length > 0 ) data.textures = textures;
  5790. if ( images.length > 0 ) data.images = images;
  5791. }
  5792. return data;
  5793. }
  5794. clone() {
  5795. return new this.constructor().copy( this );
  5796. }
  5797. copy( source ) {
  5798. this.name = source.name;
  5799. this.blending = source.blending;
  5800. this.side = source.side;
  5801. this.vertexColors = source.vertexColors;
  5802. this.opacity = source.opacity;
  5803. this.transparent = source.transparent;
  5804. this.blendSrc = source.blendSrc;
  5805. this.blendDst = source.blendDst;
  5806. this.blendEquation = source.blendEquation;
  5807. this.blendSrcAlpha = source.blendSrcAlpha;
  5808. this.blendDstAlpha = source.blendDstAlpha;
  5809. this.blendEquationAlpha = source.blendEquationAlpha;
  5810. this.blendColor.copy( source.blendColor );
  5811. this.blendAlpha = source.blendAlpha;
  5812. this.depthFunc = source.depthFunc;
  5813. this.depthTest = source.depthTest;
  5814. this.depthWrite = source.depthWrite;
  5815. this.stencilWriteMask = source.stencilWriteMask;
  5816. this.stencilFunc = source.stencilFunc;
  5817. this.stencilRef = source.stencilRef;
  5818. this.stencilFuncMask = source.stencilFuncMask;
  5819. this.stencilFail = source.stencilFail;
  5820. this.stencilZFail = source.stencilZFail;
  5821. this.stencilZPass = source.stencilZPass;
  5822. this.stencilWrite = source.stencilWrite;
  5823. const srcPlanes = source.clippingPlanes;
  5824. let dstPlanes = null;
  5825. if ( srcPlanes !== null ) {
  5826. const n = srcPlanes.length;
  5827. dstPlanes = new Array( n );
  5828. for ( let i = 0; i !== n; ++ i ) {
  5829. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5830. }
  5831. }
  5832. this.clippingPlanes = dstPlanes;
  5833. this.clipIntersection = source.clipIntersection;
  5834. this.clipShadows = source.clipShadows;
  5835. this.shadowSide = source.shadowSide;
  5836. this.colorWrite = source.colorWrite;
  5837. this.precision = source.precision;
  5838. this.polygonOffset = source.polygonOffset;
  5839. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5840. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5841. this.dithering = source.dithering;
  5842. this.alphaTest = source.alphaTest;
  5843. this.alphaHash = source.alphaHash;
  5844. this.alphaToCoverage = source.alphaToCoverage;
  5845. this.premultipliedAlpha = source.premultipliedAlpha;
  5846. this.forceSinglePass = source.forceSinglePass;
  5847. this.visible = source.visible;
  5848. this.toneMapped = source.toneMapped;
  5849. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5850. return this;
  5851. }
  5852. dispose() {
  5853. this.dispatchEvent( { type: 'dispose' } );
  5854. }
  5855. set needsUpdate( value ) {
  5856. if ( value === true ) this.version ++;
  5857. }
  5858. onBuild( /* shaderobject, renderer */ ) {
  5859. console.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166
  5860. }
  5861. }
  5862. class MeshBasicMaterial extends Material {
  5863. constructor( parameters ) {
  5864. super();
  5865. this.isMeshBasicMaterial = true;
  5866. this.type = 'MeshBasicMaterial';
  5867. this.color = new Color( 0xffffff ); // emissive
  5868. this.map = null;
  5869. this.lightMap = null;
  5870. this.lightMapIntensity = 1.0;
  5871. this.aoMap = null;
  5872. this.aoMapIntensity = 1.0;
  5873. this.specularMap = null;
  5874. this.alphaMap = null;
  5875. this.envMap = null;
  5876. this.envMapRotation = new Euler();
  5877. this.combine = MultiplyOperation;
  5878. this.reflectivity = 1;
  5879. this.refractionRatio = 0.98;
  5880. this.wireframe = false;
  5881. this.wireframeLinewidth = 1;
  5882. this.wireframeLinecap = 'round';
  5883. this.wireframeLinejoin = 'round';
  5884. this.fog = true;
  5885. this.setValues( parameters );
  5886. }
  5887. copy( source ) {
  5888. super.copy( source );
  5889. this.color.copy( source.color );
  5890. this.map = source.map;
  5891. this.lightMap = source.lightMap;
  5892. this.lightMapIntensity = source.lightMapIntensity;
  5893. this.aoMap = source.aoMap;
  5894. this.aoMapIntensity = source.aoMapIntensity;
  5895. this.specularMap = source.specularMap;
  5896. this.alphaMap = source.alphaMap;
  5897. this.envMap = source.envMap;
  5898. this.envMapRotation.copy( source.envMapRotation );
  5899. this.combine = source.combine;
  5900. this.reflectivity = source.reflectivity;
  5901. this.refractionRatio = source.refractionRatio;
  5902. this.wireframe = source.wireframe;
  5903. this.wireframeLinewidth = source.wireframeLinewidth;
  5904. this.wireframeLinecap = source.wireframeLinecap;
  5905. this.wireframeLinejoin = source.wireframeLinejoin;
  5906. this.fog = source.fog;
  5907. return this;
  5908. }
  5909. }
  5910. // Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
  5911. const _tables = /*@__PURE__*/ _generateTables();
  5912. function _generateTables() {
  5913. // float32 to float16 helpers
  5914. const buffer = new ArrayBuffer( 4 );
  5915. const floatView = new Float32Array( buffer );
  5916. const uint32View = new Uint32Array( buffer );
  5917. const baseTable = new Uint32Array( 512 );
  5918. const shiftTable = new Uint32Array( 512 );
  5919. for ( let i = 0; i < 256; ++ i ) {
  5920. const e = i - 127;
  5921. // very small number (0, -0)
  5922. if ( e < - 27 ) {
  5923. baseTable[ i ] = 0x0000;
  5924. baseTable[ i | 0x100 ] = 0x8000;
  5925. shiftTable[ i ] = 24;
  5926. shiftTable[ i | 0x100 ] = 24;
  5927. // small number (denorm)
  5928. } else if ( e < - 14 ) {
  5929. baseTable[ i ] = 0x0400 >> ( - e - 14 );
  5930. baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;
  5931. shiftTable[ i ] = - e - 1;
  5932. shiftTable[ i | 0x100 ] = - e - 1;
  5933. // normal number
  5934. } else if ( e <= 15 ) {
  5935. baseTable[ i ] = ( e + 15 ) << 10;
  5936. baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;
  5937. shiftTable[ i ] = 13;
  5938. shiftTable[ i | 0x100 ] = 13;
  5939. // large number (Infinity, -Infinity)
  5940. } else if ( e < 128 ) {
  5941. baseTable[ i ] = 0x7c00;
  5942. baseTable[ i | 0x100 ] = 0xfc00;
  5943. shiftTable[ i ] = 24;
  5944. shiftTable[ i | 0x100 ] = 24;
  5945. // stay (NaN, Infinity, -Infinity)
  5946. } else {
  5947. baseTable[ i ] = 0x7c00;
  5948. baseTable[ i | 0x100 ] = 0xfc00;
  5949. shiftTable[ i ] = 13;
  5950. shiftTable[ i | 0x100 ] = 13;
  5951. }
  5952. }
  5953. // float16 to float32 helpers
  5954. const mantissaTable = new Uint32Array( 2048 );
  5955. const exponentTable = new Uint32Array( 64 );
  5956. const offsetTable = new Uint32Array( 64 );
  5957. for ( let i = 1; i < 1024; ++ i ) {
  5958. let m = i << 13; // zero pad mantissa bits
  5959. let e = 0; // zero exponent
  5960. // normalized
  5961. while ( ( m & 0x00800000 ) === 0 ) {
  5962. m <<= 1;
  5963. e -= 0x00800000; // decrement exponent
  5964. }
  5965. m &= ~ 0x00800000; // clear leading 1 bit
  5966. e += 0x38800000; // adjust bias
  5967. mantissaTable[ i ] = m | e;
  5968. }
  5969. for ( let i = 1024; i < 2048; ++ i ) {
  5970. mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );
  5971. }
  5972. for ( let i = 1; i < 31; ++ i ) {
  5973. exponentTable[ i ] = i << 23;
  5974. }
  5975. exponentTable[ 31 ] = 0x47800000;
  5976. exponentTable[ 32 ] = 0x80000000;
  5977. for ( let i = 33; i < 63; ++ i ) {
  5978. exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );
  5979. }
  5980. exponentTable[ 63 ] = 0xc7800000;
  5981. for ( let i = 1; i < 64; ++ i ) {
  5982. if ( i !== 32 ) {
  5983. offsetTable[ i ] = 1024;
  5984. }
  5985. }
  5986. return {
  5987. floatView: floatView,
  5988. uint32View: uint32View,
  5989. baseTable: baseTable,
  5990. shiftTable: shiftTable,
  5991. mantissaTable: mantissaTable,
  5992. exponentTable: exponentTable,
  5993. offsetTable: offsetTable
  5994. };
  5995. }
  5996. // float32 to float16
  5997. function toHalfFloat( val ) {
  5998. if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
  5999. val = clamp( val, - 65504, 65504 );
  6000. _tables.floatView[ 0 ] = val;
  6001. const f = _tables.uint32View[ 0 ];
  6002. const e = ( f >> 23 ) & 0x1ff;
  6003. return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
  6004. }
  6005. // float16 to float32
  6006. function fromHalfFloat( val ) {
  6007. const m = val >> 10;
  6008. _tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];
  6009. return _tables.floatView[ 0 ];
  6010. }
  6011. const DataUtils = {
  6012. toHalfFloat: toHalfFloat,
  6013. fromHalfFloat: fromHalfFloat,
  6014. };
  6015. const _vector$9 = /*@__PURE__*/ new Vector3();
  6016. const _vector2$1 = /*@__PURE__*/ new Vector2();
  6017. class BufferAttribute {
  6018. constructor( array, itemSize, normalized = false ) {
  6019. if ( Array.isArray( array ) ) {
  6020. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6021. }
  6022. this.isBufferAttribute = true;
  6023. this.name = '';
  6024. this.array = array;
  6025. this.itemSize = itemSize;
  6026. this.count = array !== undefined ? array.length / itemSize : 0;
  6027. this.normalized = normalized;
  6028. this.usage = StaticDrawUsage;
  6029. this.updateRanges = [];
  6030. this.gpuType = FloatType;
  6031. this.version = 0;
  6032. }
  6033. onUploadCallback() {}
  6034. set needsUpdate( value ) {
  6035. if ( value === true ) this.version ++;
  6036. }
  6037. setUsage( value ) {
  6038. this.usage = value;
  6039. return this;
  6040. }
  6041. addUpdateRange( start, count ) {
  6042. this.updateRanges.push( { start, count } );
  6043. }
  6044. clearUpdateRanges() {
  6045. this.updateRanges.length = 0;
  6046. }
  6047. copy( source ) {
  6048. this.name = source.name;
  6049. this.array = new source.array.constructor( source.array );
  6050. this.itemSize = source.itemSize;
  6051. this.count = source.count;
  6052. this.normalized = source.normalized;
  6053. this.usage = source.usage;
  6054. this.gpuType = source.gpuType;
  6055. return this;
  6056. }
  6057. copyAt( index1, attribute, index2 ) {
  6058. index1 *= this.itemSize;
  6059. index2 *= attribute.itemSize;
  6060. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  6061. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6062. }
  6063. return this;
  6064. }
  6065. copyArray( array ) {
  6066. this.array.set( array );
  6067. return this;
  6068. }
  6069. applyMatrix3( m ) {
  6070. if ( this.itemSize === 2 ) {
  6071. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6072. _vector2$1.fromBufferAttribute( this, i );
  6073. _vector2$1.applyMatrix3( m );
  6074. this.setXY( i, _vector2$1.x, _vector2$1.y );
  6075. }
  6076. } else if ( this.itemSize === 3 ) {
  6077. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6078. _vector$9.fromBufferAttribute( this, i );
  6079. _vector$9.applyMatrix3( m );
  6080. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6081. }
  6082. }
  6083. return this;
  6084. }
  6085. applyMatrix4( m ) {
  6086. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6087. _vector$9.fromBufferAttribute( this, i );
  6088. _vector$9.applyMatrix4( m );
  6089. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6090. }
  6091. return this;
  6092. }
  6093. applyNormalMatrix( m ) {
  6094. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6095. _vector$9.fromBufferAttribute( this, i );
  6096. _vector$9.applyNormalMatrix( m );
  6097. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6098. }
  6099. return this;
  6100. }
  6101. transformDirection( m ) {
  6102. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6103. _vector$9.fromBufferAttribute( this, i );
  6104. _vector$9.transformDirection( m );
  6105. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6106. }
  6107. return this;
  6108. }
  6109. set( value, offset = 0 ) {
  6110. // Matching BufferAttribute constructor, do not normalize the array.
  6111. this.array.set( value, offset );
  6112. return this;
  6113. }
  6114. getComponent( index, component ) {
  6115. let value = this.array[ index * this.itemSize + component ];
  6116. if ( this.normalized ) value = denormalize( value, this.array );
  6117. return value;
  6118. }
  6119. setComponent( index, component, value ) {
  6120. if ( this.normalized ) value = normalize( value, this.array );
  6121. this.array[ index * this.itemSize + component ] = value;
  6122. return this;
  6123. }
  6124. getX( index ) {
  6125. let x = this.array[ index * this.itemSize ];
  6126. if ( this.normalized ) x = denormalize( x, this.array );
  6127. return x;
  6128. }
  6129. setX( index, x ) {
  6130. if ( this.normalized ) x = normalize( x, this.array );
  6131. this.array[ index * this.itemSize ] = x;
  6132. return this;
  6133. }
  6134. getY( index ) {
  6135. let y = this.array[ index * this.itemSize + 1 ];
  6136. if ( this.normalized ) y = denormalize( y, this.array );
  6137. return y;
  6138. }
  6139. setY( index, y ) {
  6140. if ( this.normalized ) y = normalize( y, this.array );
  6141. this.array[ index * this.itemSize + 1 ] = y;
  6142. return this;
  6143. }
  6144. getZ( index ) {
  6145. let z = this.array[ index * this.itemSize + 2 ];
  6146. if ( this.normalized ) z = denormalize( z, this.array );
  6147. return z;
  6148. }
  6149. setZ( index, z ) {
  6150. if ( this.normalized ) z = normalize( z, this.array );
  6151. this.array[ index * this.itemSize + 2 ] = z;
  6152. return this;
  6153. }
  6154. getW( index ) {
  6155. let w = this.array[ index * this.itemSize + 3 ];
  6156. if ( this.normalized ) w = denormalize( w, this.array );
  6157. return w;
  6158. }
  6159. setW( index, w ) {
  6160. if ( this.normalized ) w = normalize( w, this.array );
  6161. this.array[ index * this.itemSize + 3 ] = w;
  6162. return this;
  6163. }
  6164. setXY( index, x, y ) {
  6165. index *= this.itemSize;
  6166. if ( this.normalized ) {
  6167. x = normalize( x, this.array );
  6168. y = normalize( y, this.array );
  6169. }
  6170. this.array[ index + 0 ] = x;
  6171. this.array[ index + 1 ] = y;
  6172. return this;
  6173. }
  6174. setXYZ( index, x, y, z ) {
  6175. index *= this.itemSize;
  6176. if ( this.normalized ) {
  6177. x = normalize( x, this.array );
  6178. y = normalize( y, this.array );
  6179. z = normalize( z, this.array );
  6180. }
  6181. this.array[ index + 0 ] = x;
  6182. this.array[ index + 1 ] = y;
  6183. this.array[ index + 2 ] = z;
  6184. return this;
  6185. }
  6186. setXYZW( index, x, y, z, w ) {
  6187. index *= this.itemSize;
  6188. if ( this.normalized ) {
  6189. x = normalize( x, this.array );
  6190. y = normalize( y, this.array );
  6191. z = normalize( z, this.array );
  6192. w = normalize( w, this.array );
  6193. }
  6194. this.array[ index + 0 ] = x;
  6195. this.array[ index + 1 ] = y;
  6196. this.array[ index + 2 ] = z;
  6197. this.array[ index + 3 ] = w;
  6198. return this;
  6199. }
  6200. onUpload( callback ) {
  6201. this.onUploadCallback = callback;
  6202. return this;
  6203. }
  6204. clone() {
  6205. return new this.constructor( this.array, this.itemSize ).copy( this );
  6206. }
  6207. toJSON() {
  6208. const data = {
  6209. itemSize: this.itemSize,
  6210. type: this.array.constructor.name,
  6211. array: Array.from( this.array ),
  6212. normalized: this.normalized
  6213. };
  6214. if ( this.name !== '' ) data.name = this.name;
  6215. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  6216. return data;
  6217. }
  6218. }
  6219. //
  6220. class Int8BufferAttribute extends BufferAttribute {
  6221. constructor( array, itemSize, normalized ) {
  6222. super( new Int8Array( array ), itemSize, normalized );
  6223. }
  6224. }
  6225. class Uint8BufferAttribute extends BufferAttribute {
  6226. constructor( array, itemSize, normalized ) {
  6227. super( new Uint8Array( array ), itemSize, normalized );
  6228. }
  6229. }
  6230. class Uint8ClampedBufferAttribute extends BufferAttribute {
  6231. constructor( array, itemSize, normalized ) {
  6232. super( new Uint8ClampedArray( array ), itemSize, normalized );
  6233. }
  6234. }
  6235. class Int16BufferAttribute extends BufferAttribute {
  6236. constructor( array, itemSize, normalized ) {
  6237. super( new Int16Array( array ), itemSize, normalized );
  6238. }
  6239. }
  6240. class Uint16BufferAttribute extends BufferAttribute {
  6241. constructor( array, itemSize, normalized ) {
  6242. super( new Uint16Array( array ), itemSize, normalized );
  6243. }
  6244. }
  6245. class Int32BufferAttribute extends BufferAttribute {
  6246. constructor( array, itemSize, normalized ) {
  6247. super( new Int32Array( array ), itemSize, normalized );
  6248. }
  6249. }
  6250. class Uint32BufferAttribute extends BufferAttribute {
  6251. constructor( array, itemSize, normalized ) {
  6252. super( new Uint32Array( array ), itemSize, normalized );
  6253. }
  6254. }
  6255. class Float16BufferAttribute extends BufferAttribute {
  6256. constructor( array, itemSize, normalized ) {
  6257. super( new Uint16Array( array ), itemSize, normalized );
  6258. this.isFloat16BufferAttribute = true;
  6259. }
  6260. getX( index ) {
  6261. let x = fromHalfFloat( this.array[ index * this.itemSize ] );
  6262. if ( this.normalized ) x = denormalize( x, this.array );
  6263. return x;
  6264. }
  6265. setX( index, x ) {
  6266. if ( this.normalized ) x = normalize( x, this.array );
  6267. this.array[ index * this.itemSize ] = toHalfFloat( x );
  6268. return this;
  6269. }
  6270. getY( index ) {
  6271. let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
  6272. if ( this.normalized ) y = denormalize( y, this.array );
  6273. return y;
  6274. }
  6275. setY( index, y ) {
  6276. if ( this.normalized ) y = normalize( y, this.array );
  6277. this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
  6278. return this;
  6279. }
  6280. getZ( index ) {
  6281. let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
  6282. if ( this.normalized ) z = denormalize( z, this.array );
  6283. return z;
  6284. }
  6285. setZ( index, z ) {
  6286. if ( this.normalized ) z = normalize( z, this.array );
  6287. this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
  6288. return this;
  6289. }
  6290. getW( index ) {
  6291. let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
  6292. if ( this.normalized ) w = denormalize( w, this.array );
  6293. return w;
  6294. }
  6295. setW( index, w ) {
  6296. if ( this.normalized ) w = normalize( w, this.array );
  6297. this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
  6298. return this;
  6299. }
  6300. setXY( index, x, y ) {
  6301. index *= this.itemSize;
  6302. if ( this.normalized ) {
  6303. x = normalize( x, this.array );
  6304. y = normalize( y, this.array );
  6305. }
  6306. this.array[ index + 0 ] = toHalfFloat( x );
  6307. this.array[ index + 1 ] = toHalfFloat( y );
  6308. return this;
  6309. }
  6310. setXYZ( index, x, y, z ) {
  6311. index *= this.itemSize;
  6312. if ( this.normalized ) {
  6313. x = normalize( x, this.array );
  6314. y = normalize( y, this.array );
  6315. z = normalize( z, this.array );
  6316. }
  6317. this.array[ index + 0 ] = toHalfFloat( x );
  6318. this.array[ index + 1 ] = toHalfFloat( y );
  6319. this.array[ index + 2 ] = toHalfFloat( z );
  6320. return this;
  6321. }
  6322. setXYZW( index, x, y, z, w ) {
  6323. index *= this.itemSize;
  6324. if ( this.normalized ) {
  6325. x = normalize( x, this.array );
  6326. y = normalize( y, this.array );
  6327. z = normalize( z, this.array );
  6328. w = normalize( w, this.array );
  6329. }
  6330. this.array[ index + 0 ] = toHalfFloat( x );
  6331. this.array[ index + 1 ] = toHalfFloat( y );
  6332. this.array[ index + 2 ] = toHalfFloat( z );
  6333. this.array[ index + 3 ] = toHalfFloat( w );
  6334. return this;
  6335. }
  6336. }
  6337. class Float32BufferAttribute extends BufferAttribute {
  6338. constructor( array, itemSize, normalized ) {
  6339. super( new Float32Array( array ), itemSize, normalized );
  6340. }
  6341. }
  6342. let _id$1 = 0;
  6343. const _m1 = /*@__PURE__*/ new Matrix4();
  6344. const _obj = /*@__PURE__*/ new Object3D();
  6345. const _offset = /*@__PURE__*/ new Vector3();
  6346. const _box$2 = /*@__PURE__*/ new Box3();
  6347. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  6348. const _vector$8 = /*@__PURE__*/ new Vector3();
  6349. class BufferGeometry extends EventDispatcher {
  6350. constructor() {
  6351. super();
  6352. this.isBufferGeometry = true;
  6353. Object.defineProperty( this, 'id', { value: _id$1 ++ } );
  6354. this.uuid = generateUUID();
  6355. this.name = '';
  6356. this.type = 'BufferGeometry';
  6357. this.index = null;
  6358. this.indirect = null;
  6359. this.attributes = {};
  6360. this.morphAttributes = {};
  6361. this.morphTargetsRelative = false;
  6362. this.groups = [];
  6363. this.boundingBox = null;
  6364. this.boundingSphere = null;
  6365. this.drawRange = { start: 0, count: Infinity };
  6366. this.userData = {};
  6367. }
  6368. getIndex() {
  6369. return this.index;
  6370. }
  6371. setIndex( index ) {
  6372. if ( Array.isArray( index ) ) {
  6373. this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6374. } else {
  6375. this.index = index;
  6376. }
  6377. return this;
  6378. }
  6379. setIndirect( indirect ) {
  6380. this.indirect = indirect;
  6381. return this;
  6382. }
  6383. getIndirect() {
  6384. return this.indirect;
  6385. }
  6386. getAttribute( name ) {
  6387. return this.attributes[ name ];
  6388. }
  6389. setAttribute( name, attribute ) {
  6390. this.attributes[ name ] = attribute;
  6391. return this;
  6392. }
  6393. deleteAttribute( name ) {
  6394. delete this.attributes[ name ];
  6395. return this;
  6396. }
  6397. hasAttribute( name ) {
  6398. return this.attributes[ name ] !== undefined;
  6399. }
  6400. addGroup( start, count, materialIndex = 0 ) {
  6401. this.groups.push( {
  6402. start: start,
  6403. count: count,
  6404. materialIndex: materialIndex
  6405. } );
  6406. }
  6407. clearGroups() {
  6408. this.groups = [];
  6409. }
  6410. setDrawRange( start, count ) {
  6411. this.drawRange.start = start;
  6412. this.drawRange.count = count;
  6413. }
  6414. applyMatrix4( matrix ) {
  6415. const position = this.attributes.position;
  6416. if ( position !== undefined ) {
  6417. position.applyMatrix4( matrix );
  6418. position.needsUpdate = true;
  6419. }
  6420. const normal = this.attributes.normal;
  6421. if ( normal !== undefined ) {
  6422. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6423. normal.applyNormalMatrix( normalMatrix );
  6424. normal.needsUpdate = true;
  6425. }
  6426. const tangent = this.attributes.tangent;
  6427. if ( tangent !== undefined ) {
  6428. tangent.transformDirection( matrix );
  6429. tangent.needsUpdate = true;
  6430. }
  6431. if ( this.boundingBox !== null ) {
  6432. this.computeBoundingBox();
  6433. }
  6434. if ( this.boundingSphere !== null ) {
  6435. this.computeBoundingSphere();
  6436. }
  6437. return this;
  6438. }
  6439. applyQuaternion( q ) {
  6440. _m1.makeRotationFromQuaternion( q );
  6441. this.applyMatrix4( _m1 );
  6442. return this;
  6443. }
  6444. rotateX( angle ) {
  6445. // rotate geometry around world x-axis
  6446. _m1.makeRotationX( angle );
  6447. this.applyMatrix4( _m1 );
  6448. return this;
  6449. }
  6450. rotateY( angle ) {
  6451. // rotate geometry around world y-axis
  6452. _m1.makeRotationY( angle );
  6453. this.applyMatrix4( _m1 );
  6454. return this;
  6455. }
  6456. rotateZ( angle ) {
  6457. // rotate geometry around world z-axis
  6458. _m1.makeRotationZ( angle );
  6459. this.applyMatrix4( _m1 );
  6460. return this;
  6461. }
  6462. translate( x, y, z ) {
  6463. // translate geometry
  6464. _m1.makeTranslation( x, y, z );
  6465. this.applyMatrix4( _m1 );
  6466. return this;
  6467. }
  6468. scale( x, y, z ) {
  6469. // scale geometry
  6470. _m1.makeScale( x, y, z );
  6471. this.applyMatrix4( _m1 );
  6472. return this;
  6473. }
  6474. lookAt( vector ) {
  6475. _obj.lookAt( vector );
  6476. _obj.updateMatrix();
  6477. this.applyMatrix4( _obj.matrix );
  6478. return this;
  6479. }
  6480. center() {
  6481. this.computeBoundingBox();
  6482. this.boundingBox.getCenter( _offset ).negate();
  6483. this.translate( _offset.x, _offset.y, _offset.z );
  6484. return this;
  6485. }
  6486. setFromPoints( points ) {
  6487. const positionAttribute = this.getAttribute( 'position' );
  6488. if ( positionAttribute === undefined ) {
  6489. const position = [];
  6490. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6491. const point = points[ i ];
  6492. position.push( point.x, point.y, point.z || 0 );
  6493. }
  6494. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6495. } else {
  6496. const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size
  6497. for ( let i = 0; i < l; i ++ ) {
  6498. const point = points[ i ];
  6499. positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
  6500. }
  6501. if ( points.length > positionAttribute.count ) {
  6502. console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
  6503. }
  6504. positionAttribute.needsUpdate = true;
  6505. }
  6506. return this;
  6507. }
  6508. computeBoundingBox() {
  6509. if ( this.boundingBox === null ) {
  6510. this.boundingBox = new Box3();
  6511. }
  6512. const position = this.attributes.position;
  6513. const morphAttributesPosition = this.morphAttributes.position;
  6514. if ( position && position.isGLBufferAttribute ) {
  6515. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
  6516. this.boundingBox.set(
  6517. new Vector3( - Infinity, - Infinity, - Infinity ),
  6518. new Vector3( + Infinity, + Infinity, + Infinity )
  6519. );
  6520. return;
  6521. }
  6522. if ( position !== undefined ) {
  6523. this.boundingBox.setFromBufferAttribute( position );
  6524. // process morph attributes if present
  6525. if ( morphAttributesPosition ) {
  6526. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6527. const morphAttribute = morphAttributesPosition[ i ];
  6528. _box$2.setFromBufferAttribute( morphAttribute );
  6529. if ( this.morphTargetsRelative ) {
  6530. _vector$8.addVectors( this.boundingBox.min, _box$2.min );
  6531. this.boundingBox.expandByPoint( _vector$8 );
  6532. _vector$8.addVectors( this.boundingBox.max, _box$2.max );
  6533. this.boundingBox.expandByPoint( _vector$8 );
  6534. } else {
  6535. this.boundingBox.expandByPoint( _box$2.min );
  6536. this.boundingBox.expandByPoint( _box$2.max );
  6537. }
  6538. }
  6539. }
  6540. } else {
  6541. this.boundingBox.makeEmpty();
  6542. }
  6543. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6544. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6545. }
  6546. }
  6547. computeBoundingSphere() {
  6548. if ( this.boundingSphere === null ) {
  6549. this.boundingSphere = new Sphere();
  6550. }
  6551. const position = this.attributes.position;
  6552. const morphAttributesPosition = this.morphAttributes.position;
  6553. if ( position && position.isGLBufferAttribute ) {
  6554. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
  6555. this.boundingSphere.set( new Vector3(), Infinity );
  6556. return;
  6557. }
  6558. if ( position ) {
  6559. // first, find the center of the bounding sphere
  6560. const center = this.boundingSphere.center;
  6561. _box$2.setFromBufferAttribute( position );
  6562. // process morph attributes if present
  6563. if ( morphAttributesPosition ) {
  6564. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6565. const morphAttribute = morphAttributesPosition[ i ];
  6566. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6567. if ( this.morphTargetsRelative ) {
  6568. _vector$8.addVectors( _box$2.min, _boxMorphTargets.min );
  6569. _box$2.expandByPoint( _vector$8 );
  6570. _vector$8.addVectors( _box$2.max, _boxMorphTargets.max );
  6571. _box$2.expandByPoint( _vector$8 );
  6572. } else {
  6573. _box$2.expandByPoint( _boxMorphTargets.min );
  6574. _box$2.expandByPoint( _boxMorphTargets.max );
  6575. }
  6576. }
  6577. }
  6578. _box$2.getCenter( center );
  6579. // second, try to find a boundingSphere with a radius smaller than the
  6580. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6581. let maxRadiusSq = 0;
  6582. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6583. _vector$8.fromBufferAttribute( position, i );
  6584. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6585. }
  6586. // process morph attributes if present
  6587. if ( morphAttributesPosition ) {
  6588. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6589. const morphAttribute = morphAttributesPosition[ i ];
  6590. const morphTargetsRelative = this.morphTargetsRelative;
  6591. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6592. _vector$8.fromBufferAttribute( morphAttribute, j );
  6593. if ( morphTargetsRelative ) {
  6594. _offset.fromBufferAttribute( position, j );
  6595. _vector$8.add( _offset );
  6596. }
  6597. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6598. }
  6599. }
  6600. }
  6601. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6602. if ( isNaN( this.boundingSphere.radius ) ) {
  6603. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6604. }
  6605. }
  6606. }
  6607. computeTangents() {
  6608. const index = this.index;
  6609. const attributes = this.attributes;
  6610. // based on http://www.terathon.com/code/tangent.html
  6611. // (per vertex tangents)
  6612. if ( index === null ||
  6613. attributes.position === undefined ||
  6614. attributes.normal === undefined ||
  6615. attributes.uv === undefined ) {
  6616. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  6617. return;
  6618. }
  6619. const positionAttribute = attributes.position;
  6620. const normalAttribute = attributes.normal;
  6621. const uvAttribute = attributes.uv;
  6622. if ( this.hasAttribute( 'tangent' ) === false ) {
  6623. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
  6624. }
  6625. const tangentAttribute = this.getAttribute( 'tangent' );
  6626. const tan1 = [], tan2 = [];
  6627. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  6628. tan1[ i ] = new Vector3();
  6629. tan2[ i ] = new Vector3();
  6630. }
  6631. const vA = new Vector3(),
  6632. vB = new Vector3(),
  6633. vC = new Vector3(),
  6634. uvA = new Vector2(),
  6635. uvB = new Vector2(),
  6636. uvC = new Vector2(),
  6637. sdir = new Vector3(),
  6638. tdir = new Vector3();
  6639. function handleTriangle( a, b, c ) {
  6640. vA.fromBufferAttribute( positionAttribute, a );
  6641. vB.fromBufferAttribute( positionAttribute, b );
  6642. vC.fromBufferAttribute( positionAttribute, c );
  6643. uvA.fromBufferAttribute( uvAttribute, a );
  6644. uvB.fromBufferAttribute( uvAttribute, b );
  6645. uvC.fromBufferAttribute( uvAttribute, c );
  6646. vB.sub( vA );
  6647. vC.sub( vA );
  6648. uvB.sub( uvA );
  6649. uvC.sub( uvA );
  6650. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6651. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6652. if ( ! isFinite( r ) ) return;
  6653. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6654. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6655. tan1[ a ].add( sdir );
  6656. tan1[ b ].add( sdir );
  6657. tan1[ c ].add( sdir );
  6658. tan2[ a ].add( tdir );
  6659. tan2[ b ].add( tdir );
  6660. tan2[ c ].add( tdir );
  6661. }
  6662. let groups = this.groups;
  6663. if ( groups.length === 0 ) {
  6664. groups = [ {
  6665. start: 0,
  6666. count: index.count
  6667. } ];
  6668. }
  6669. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6670. const group = groups[ i ];
  6671. const start = group.start;
  6672. const count = group.count;
  6673. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6674. handleTriangle(
  6675. index.getX( j + 0 ),
  6676. index.getX( j + 1 ),
  6677. index.getX( j + 2 )
  6678. );
  6679. }
  6680. }
  6681. const tmp = new Vector3(), tmp2 = new Vector3();
  6682. const n = new Vector3(), n2 = new Vector3();
  6683. function handleVertex( v ) {
  6684. n.fromBufferAttribute( normalAttribute, v );
  6685. n2.copy( n );
  6686. const t = tan1[ v ];
  6687. // Gram-Schmidt orthogonalize
  6688. tmp.copy( t );
  6689. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6690. // Calculate handedness
  6691. tmp2.crossVectors( n2, t );
  6692. const test = tmp2.dot( tan2[ v ] );
  6693. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6694. tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
  6695. }
  6696. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6697. const group = groups[ i ];
  6698. const start = group.start;
  6699. const count = group.count;
  6700. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6701. handleVertex( index.getX( j + 0 ) );
  6702. handleVertex( index.getX( j + 1 ) );
  6703. handleVertex( index.getX( j + 2 ) );
  6704. }
  6705. }
  6706. }
  6707. computeVertexNormals() {
  6708. const index = this.index;
  6709. const positionAttribute = this.getAttribute( 'position' );
  6710. if ( positionAttribute !== undefined ) {
  6711. let normalAttribute = this.getAttribute( 'normal' );
  6712. if ( normalAttribute === undefined ) {
  6713. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6714. this.setAttribute( 'normal', normalAttribute );
  6715. } else {
  6716. // reset existing normals to zero
  6717. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6718. normalAttribute.setXYZ( i, 0, 0, 0 );
  6719. }
  6720. }
  6721. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6722. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6723. const cb = new Vector3(), ab = new Vector3();
  6724. // indexed elements
  6725. if ( index ) {
  6726. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6727. const vA = index.getX( i + 0 );
  6728. const vB = index.getX( i + 1 );
  6729. const vC = index.getX( i + 2 );
  6730. pA.fromBufferAttribute( positionAttribute, vA );
  6731. pB.fromBufferAttribute( positionAttribute, vB );
  6732. pC.fromBufferAttribute( positionAttribute, vC );
  6733. cb.subVectors( pC, pB );
  6734. ab.subVectors( pA, pB );
  6735. cb.cross( ab );
  6736. nA.fromBufferAttribute( normalAttribute, vA );
  6737. nB.fromBufferAttribute( normalAttribute, vB );
  6738. nC.fromBufferAttribute( normalAttribute, vC );
  6739. nA.add( cb );
  6740. nB.add( cb );
  6741. nC.add( cb );
  6742. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6743. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6744. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6745. }
  6746. } else {
  6747. // non-indexed elements (unconnected triangle soup)
  6748. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6749. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6750. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6751. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6752. cb.subVectors( pC, pB );
  6753. ab.subVectors( pA, pB );
  6754. cb.cross( ab );
  6755. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6756. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6757. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6758. }
  6759. }
  6760. this.normalizeNormals();
  6761. normalAttribute.needsUpdate = true;
  6762. }
  6763. }
  6764. normalizeNormals() {
  6765. const normals = this.attributes.normal;
  6766. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6767. _vector$8.fromBufferAttribute( normals, i );
  6768. _vector$8.normalize();
  6769. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6770. }
  6771. }
  6772. toNonIndexed() {
  6773. function convertBufferAttribute( attribute, indices ) {
  6774. const array = attribute.array;
  6775. const itemSize = attribute.itemSize;
  6776. const normalized = attribute.normalized;
  6777. const array2 = new array.constructor( indices.length * itemSize );
  6778. let index = 0, index2 = 0;
  6779. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6780. if ( attribute.isInterleavedBufferAttribute ) {
  6781. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6782. } else {
  6783. index = indices[ i ] * itemSize;
  6784. }
  6785. for ( let j = 0; j < itemSize; j ++ ) {
  6786. array2[ index2 ++ ] = array[ index ++ ];
  6787. }
  6788. }
  6789. return new BufferAttribute( array2, itemSize, normalized );
  6790. }
  6791. //
  6792. if ( this.index === null ) {
  6793. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6794. return this;
  6795. }
  6796. const geometry2 = new BufferGeometry();
  6797. const indices = this.index.array;
  6798. const attributes = this.attributes;
  6799. // attributes
  6800. for ( const name in attributes ) {
  6801. const attribute = attributes[ name ];
  6802. const newAttribute = convertBufferAttribute( attribute, indices );
  6803. geometry2.setAttribute( name, newAttribute );
  6804. }
  6805. // morph attributes
  6806. const morphAttributes = this.morphAttributes;
  6807. for ( const name in morphAttributes ) {
  6808. const morphArray = [];
  6809. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6810. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6811. const attribute = morphAttribute[ i ];
  6812. const newAttribute = convertBufferAttribute( attribute, indices );
  6813. morphArray.push( newAttribute );
  6814. }
  6815. geometry2.morphAttributes[ name ] = morphArray;
  6816. }
  6817. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6818. // groups
  6819. const groups = this.groups;
  6820. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6821. const group = groups[ i ];
  6822. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6823. }
  6824. return geometry2;
  6825. }
  6826. toJSON() {
  6827. const data = {
  6828. metadata: {
  6829. version: 4.6,
  6830. type: 'BufferGeometry',
  6831. generator: 'BufferGeometry.toJSON'
  6832. }
  6833. };
  6834. // standard BufferGeometry serialization
  6835. data.uuid = this.uuid;
  6836. data.type = this.type;
  6837. if ( this.name !== '' ) data.name = this.name;
  6838. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6839. if ( this.parameters !== undefined ) {
  6840. const parameters = this.parameters;
  6841. for ( const key in parameters ) {
  6842. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6843. }
  6844. return data;
  6845. }
  6846. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6847. data.data = { attributes: {} };
  6848. const index = this.index;
  6849. if ( index !== null ) {
  6850. data.data.index = {
  6851. type: index.array.constructor.name,
  6852. array: Array.prototype.slice.call( index.array )
  6853. };
  6854. }
  6855. const attributes = this.attributes;
  6856. for ( const key in attributes ) {
  6857. const attribute = attributes[ key ];
  6858. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6859. }
  6860. const morphAttributes = {};
  6861. let hasMorphAttributes = false;
  6862. for ( const key in this.morphAttributes ) {
  6863. const attributeArray = this.morphAttributes[ key ];
  6864. const array = [];
  6865. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6866. const attribute = attributeArray[ i ];
  6867. array.push( attribute.toJSON( data.data ) );
  6868. }
  6869. if ( array.length > 0 ) {
  6870. morphAttributes[ key ] = array;
  6871. hasMorphAttributes = true;
  6872. }
  6873. }
  6874. if ( hasMorphAttributes ) {
  6875. data.data.morphAttributes = morphAttributes;
  6876. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6877. }
  6878. const groups = this.groups;
  6879. if ( groups.length > 0 ) {
  6880. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6881. }
  6882. const boundingSphere = this.boundingSphere;
  6883. if ( boundingSphere !== null ) {
  6884. data.data.boundingSphere = {
  6885. center: boundingSphere.center.toArray(),
  6886. radius: boundingSphere.radius
  6887. };
  6888. }
  6889. return data;
  6890. }
  6891. clone() {
  6892. return new this.constructor().copy( this );
  6893. }
  6894. copy( source ) {
  6895. // reset
  6896. this.index = null;
  6897. this.attributes = {};
  6898. this.morphAttributes = {};
  6899. this.groups = [];
  6900. this.boundingBox = null;
  6901. this.boundingSphere = null;
  6902. // used for storing cloned, shared data
  6903. const data = {};
  6904. // name
  6905. this.name = source.name;
  6906. // index
  6907. const index = source.index;
  6908. if ( index !== null ) {
  6909. this.setIndex( index.clone( data ) );
  6910. }
  6911. // attributes
  6912. const attributes = source.attributes;
  6913. for ( const name in attributes ) {
  6914. const attribute = attributes[ name ];
  6915. this.setAttribute( name, attribute.clone( data ) );
  6916. }
  6917. // morph attributes
  6918. const morphAttributes = source.morphAttributes;
  6919. for ( const name in morphAttributes ) {
  6920. const array = [];
  6921. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6922. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6923. array.push( morphAttribute[ i ].clone( data ) );
  6924. }
  6925. this.morphAttributes[ name ] = array;
  6926. }
  6927. this.morphTargetsRelative = source.morphTargetsRelative;
  6928. // groups
  6929. const groups = source.groups;
  6930. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6931. const group = groups[ i ];
  6932. this.addGroup( group.start, group.count, group.materialIndex );
  6933. }
  6934. // bounding box
  6935. const boundingBox = source.boundingBox;
  6936. if ( boundingBox !== null ) {
  6937. this.boundingBox = boundingBox.clone();
  6938. }
  6939. // bounding sphere
  6940. const boundingSphere = source.boundingSphere;
  6941. if ( boundingSphere !== null ) {
  6942. this.boundingSphere = boundingSphere.clone();
  6943. }
  6944. // draw range
  6945. this.drawRange.start = source.drawRange.start;
  6946. this.drawRange.count = source.drawRange.count;
  6947. // user data
  6948. this.userData = source.userData;
  6949. return this;
  6950. }
  6951. dispose() {
  6952. this.dispatchEvent( { type: 'dispose' } );
  6953. }
  6954. }
  6955. const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();
  6956. const _ray$3 = /*@__PURE__*/ new Ray();
  6957. const _sphere$6 = /*@__PURE__*/ new Sphere();
  6958. const _sphereHitAt = /*@__PURE__*/ new Vector3();
  6959. const _vA$1 = /*@__PURE__*/ new Vector3();
  6960. const _vB$1 = /*@__PURE__*/ new Vector3();
  6961. const _vC$1 = /*@__PURE__*/ new Vector3();
  6962. const _tempA = /*@__PURE__*/ new Vector3();
  6963. const _morphA = /*@__PURE__*/ new Vector3();
  6964. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6965. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6966. class Mesh extends Object3D {
  6967. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6968. super();
  6969. this.isMesh = true;
  6970. this.type = 'Mesh';
  6971. this.geometry = geometry;
  6972. this.material = material;
  6973. this.updateMorphTargets();
  6974. }
  6975. copy( source, recursive ) {
  6976. super.copy( source, recursive );
  6977. if ( source.morphTargetInfluences !== undefined ) {
  6978. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6979. }
  6980. if ( source.morphTargetDictionary !== undefined ) {
  6981. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6982. }
  6983. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  6984. this.geometry = source.geometry;
  6985. return this;
  6986. }
  6987. updateMorphTargets() {
  6988. const geometry = this.geometry;
  6989. const morphAttributes = geometry.morphAttributes;
  6990. const keys = Object.keys( morphAttributes );
  6991. if ( keys.length > 0 ) {
  6992. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6993. if ( morphAttribute !== undefined ) {
  6994. this.morphTargetInfluences = [];
  6995. this.morphTargetDictionary = {};
  6996. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6997. const name = morphAttribute[ m ].name || String( m );
  6998. this.morphTargetInfluences.push( 0 );
  6999. this.morphTargetDictionary[ name ] = m;
  7000. }
  7001. }
  7002. }
  7003. }
  7004. getVertexPosition( index, target ) {
  7005. const geometry = this.geometry;
  7006. const position = geometry.attributes.position;
  7007. const morphPosition = geometry.morphAttributes.position;
  7008. const morphTargetsRelative = geometry.morphTargetsRelative;
  7009. target.fromBufferAttribute( position, index );
  7010. const morphInfluences = this.morphTargetInfluences;
  7011. if ( morphPosition && morphInfluences ) {
  7012. _morphA.set( 0, 0, 0 );
  7013. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  7014. const influence = morphInfluences[ i ];
  7015. const morphAttribute = morphPosition[ i ];
  7016. if ( influence === 0 ) continue;
  7017. _tempA.fromBufferAttribute( morphAttribute, index );
  7018. if ( morphTargetsRelative ) {
  7019. _morphA.addScaledVector( _tempA, influence );
  7020. } else {
  7021. _morphA.addScaledVector( _tempA.sub( target ), influence );
  7022. }
  7023. }
  7024. target.add( _morphA );
  7025. }
  7026. return target;
  7027. }
  7028. raycast( raycaster, intersects ) {
  7029. const geometry = this.geometry;
  7030. const material = this.material;
  7031. const matrixWorld = this.matrixWorld;
  7032. if ( material === undefined ) return;
  7033. // test with bounding sphere in world space
  7034. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7035. _sphere$6.copy( geometry.boundingSphere );
  7036. _sphere$6.applyMatrix4( matrixWorld );
  7037. // check distance from ray origin to bounding sphere
  7038. _ray$3.copy( raycaster.ray ).recast( raycaster.near );
  7039. if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {
  7040. if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;
  7041. if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;
  7042. }
  7043. // convert ray to local space of mesh
  7044. _inverseMatrix$3.copy( matrixWorld ).invert();
  7045. _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );
  7046. // test with bounding box in local space
  7047. if ( geometry.boundingBox !== null ) {
  7048. if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;
  7049. }
  7050. // test for intersections with geometry
  7051. this._computeIntersections( raycaster, intersects, _ray$3 );
  7052. }
  7053. _computeIntersections( raycaster, intersects, rayLocalSpace ) {
  7054. let intersection;
  7055. const geometry = this.geometry;
  7056. const material = this.material;
  7057. const index = geometry.index;
  7058. const position = geometry.attributes.position;
  7059. const uv = geometry.attributes.uv;
  7060. const uv1 = geometry.attributes.uv1;
  7061. const normal = geometry.attributes.normal;
  7062. const groups = geometry.groups;
  7063. const drawRange = geometry.drawRange;
  7064. if ( index !== null ) {
  7065. // indexed buffer geometry
  7066. if ( Array.isArray( material ) ) {
  7067. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7068. const group = groups[ i ];
  7069. const groupMaterial = material[ group.materialIndex ];
  7070. const start = Math.max( group.start, drawRange.start );
  7071. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7072. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7073. const a = index.getX( j );
  7074. const b = index.getX( j + 1 );
  7075. const c = index.getX( j + 2 );
  7076. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7077. if ( intersection ) {
  7078. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  7079. intersection.face.materialIndex = group.materialIndex;
  7080. intersects.push( intersection );
  7081. }
  7082. }
  7083. }
  7084. } else {
  7085. const start = Math.max( 0, drawRange.start );
  7086. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  7087. for ( let i = start, il = end; i < il; i += 3 ) {
  7088. const a = index.getX( i );
  7089. const b = index.getX( i + 1 );
  7090. const c = index.getX( i + 2 );
  7091. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7092. if ( intersection ) {
  7093. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  7094. intersects.push( intersection );
  7095. }
  7096. }
  7097. }
  7098. } else if ( position !== undefined ) {
  7099. // non-indexed buffer geometry
  7100. if ( Array.isArray( material ) ) {
  7101. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7102. const group = groups[ i ];
  7103. const groupMaterial = material[ group.materialIndex ];
  7104. const start = Math.max( group.start, drawRange.start );
  7105. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7106. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7107. const a = j;
  7108. const b = j + 1;
  7109. const c = j + 2;
  7110. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7111. if ( intersection ) {
  7112. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  7113. intersection.face.materialIndex = group.materialIndex;
  7114. intersects.push( intersection );
  7115. }
  7116. }
  7117. }
  7118. } else {
  7119. const start = Math.max( 0, drawRange.start );
  7120. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  7121. for ( let i = start, il = end; i < il; i += 3 ) {
  7122. const a = i;
  7123. const b = i + 1;
  7124. const c = i + 2;
  7125. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7126. if ( intersection ) {
  7127. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  7128. intersects.push( intersection );
  7129. }
  7130. }
  7131. }
  7132. }
  7133. }
  7134. }
  7135. function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {
  7136. let intersect;
  7137. if ( material.side === BackSide ) {
  7138. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  7139. } else {
  7140. intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );
  7141. }
  7142. if ( intersect === null ) return null;
  7143. _intersectionPointWorld.copy( point );
  7144. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  7145. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  7146. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  7147. return {
  7148. distance: distance,
  7149. point: _intersectionPointWorld.clone(),
  7150. object: object
  7151. };
  7152. }
  7153. function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {
  7154. object.getVertexPosition( a, _vA$1 );
  7155. object.getVertexPosition( b, _vB$1 );
  7156. object.getVertexPosition( c, _vC$1 );
  7157. const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  7158. if ( intersection ) {
  7159. const barycoord = new Vector3();
  7160. Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
  7161. if ( uv ) {
  7162. intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
  7163. }
  7164. if ( uv1 ) {
  7165. intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
  7166. }
  7167. if ( normal ) {
  7168. intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
  7169. if ( intersection.normal.dot( ray.direction ) > 0 ) {
  7170. intersection.normal.multiplyScalar( - 1 );
  7171. }
  7172. }
  7173. const face = {
  7174. a: a,
  7175. b: b,
  7176. c: c,
  7177. normal: new Vector3(),
  7178. materialIndex: 0
  7179. };
  7180. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  7181. intersection.face = face;
  7182. intersection.barycoord = barycoord;
  7183. }
  7184. return intersection;
  7185. }
  7186. class BoxGeometry extends BufferGeometry {
  7187. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  7188. super();
  7189. this.type = 'BoxGeometry';
  7190. this.parameters = {
  7191. width: width,
  7192. height: height,
  7193. depth: depth,
  7194. widthSegments: widthSegments,
  7195. heightSegments: heightSegments,
  7196. depthSegments: depthSegments
  7197. };
  7198. const scope = this;
  7199. // segments
  7200. widthSegments = Math.floor( widthSegments );
  7201. heightSegments = Math.floor( heightSegments );
  7202. depthSegments = Math.floor( depthSegments );
  7203. // buffers
  7204. const indices = [];
  7205. const vertices = [];
  7206. const normals = [];
  7207. const uvs = [];
  7208. // helper variables
  7209. let numberOfVertices = 0;
  7210. let groupStart = 0;
  7211. // build each side of the box geometry
  7212. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7213. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7214. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7215. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7216. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7217. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7218. // build geometry
  7219. this.setIndex( indices );
  7220. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7221. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7222. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7223. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7224. const segmentWidth = width / gridX;
  7225. const segmentHeight = height / gridY;
  7226. const widthHalf = width / 2;
  7227. const heightHalf = height / 2;
  7228. const depthHalf = depth / 2;
  7229. const gridX1 = gridX + 1;
  7230. const gridY1 = gridY + 1;
  7231. let vertexCounter = 0;
  7232. let groupCount = 0;
  7233. const vector = new Vector3();
  7234. // generate vertices, normals and uvs
  7235. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7236. const y = iy * segmentHeight - heightHalf;
  7237. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7238. const x = ix * segmentWidth - widthHalf;
  7239. // set values to correct vector component
  7240. vector[ u ] = x * udir;
  7241. vector[ v ] = y * vdir;
  7242. vector[ w ] = depthHalf;
  7243. // now apply vector to vertex buffer
  7244. vertices.push( vector.x, vector.y, vector.z );
  7245. // set values to correct vector component
  7246. vector[ u ] = 0;
  7247. vector[ v ] = 0;
  7248. vector[ w ] = depth > 0 ? 1 : - 1;
  7249. // now apply vector to normal buffer
  7250. normals.push( vector.x, vector.y, vector.z );
  7251. // uvs
  7252. uvs.push( ix / gridX );
  7253. uvs.push( 1 - ( iy / gridY ) );
  7254. // counters
  7255. vertexCounter += 1;
  7256. }
  7257. }
  7258. // indices
  7259. // 1. you need three indices to draw a single face
  7260. // 2. a single segment consists of two faces
  7261. // 3. so we need to generate six (2*3) indices per segment
  7262. for ( let iy = 0; iy < gridY; iy ++ ) {
  7263. for ( let ix = 0; ix < gridX; ix ++ ) {
  7264. const a = numberOfVertices + ix + gridX1 * iy;
  7265. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7266. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7267. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7268. // faces
  7269. indices.push( a, b, d );
  7270. indices.push( b, c, d );
  7271. // increase counter
  7272. groupCount += 6;
  7273. }
  7274. }
  7275. // add a group to the geometry. this will ensure multi material support
  7276. scope.addGroup( groupStart, groupCount, materialIndex );
  7277. // calculate new start value for groups
  7278. groupStart += groupCount;
  7279. // update total number of vertices
  7280. numberOfVertices += vertexCounter;
  7281. }
  7282. }
  7283. copy( source ) {
  7284. super.copy( source );
  7285. this.parameters = Object.assign( {}, source.parameters );
  7286. return this;
  7287. }
  7288. static fromJSON( data ) {
  7289. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  7290. }
  7291. }
  7292. /**
  7293. * Uniform Utilities
  7294. */
  7295. function cloneUniforms( src ) {
  7296. const dst = {};
  7297. for ( const u in src ) {
  7298. dst[ u ] = {};
  7299. for ( const p in src[ u ] ) {
  7300. const property = src[ u ][ p ];
  7301. if ( property && ( property.isColor ||
  7302. property.isMatrix3 || property.isMatrix4 ||
  7303. property.isVector2 || property.isVector3 || property.isVector4 ||
  7304. property.isTexture || property.isQuaternion ) ) {
  7305. if ( property.isRenderTargetTexture ) {
  7306. console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );
  7307. dst[ u ][ p ] = null;
  7308. } else {
  7309. dst[ u ][ p ] = property.clone();
  7310. }
  7311. } else if ( Array.isArray( property ) ) {
  7312. dst[ u ][ p ] = property.slice();
  7313. } else {
  7314. dst[ u ][ p ] = property;
  7315. }
  7316. }
  7317. }
  7318. return dst;
  7319. }
  7320. function mergeUniforms( uniforms ) {
  7321. const merged = {};
  7322. for ( let u = 0; u < uniforms.length; u ++ ) {
  7323. const tmp = cloneUniforms( uniforms[ u ] );
  7324. for ( const p in tmp ) {
  7325. merged[ p ] = tmp[ p ];
  7326. }
  7327. }
  7328. return merged;
  7329. }
  7330. function cloneUniformsGroups( src ) {
  7331. const dst = [];
  7332. for ( let u = 0; u < src.length; u ++ ) {
  7333. dst.push( src[ u ].clone() );
  7334. }
  7335. return dst;
  7336. }
  7337. function getUnlitUniformColorSpace( renderer ) {
  7338. const currentRenderTarget = renderer.getRenderTarget();
  7339. if ( currentRenderTarget === null ) {
  7340. // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
  7341. return renderer.outputColorSpace;
  7342. }
  7343. // https://github.com/mrdoob/three.js/issues/27868
  7344. if ( currentRenderTarget.isXRRenderTarget === true ) {
  7345. return currentRenderTarget.texture.colorSpace;
  7346. }
  7347. return ColorManagement.workingColorSpace;
  7348. }
  7349. // Legacy
  7350. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7351. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7352. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7353. class ShaderMaterial extends Material {
  7354. constructor( parameters ) {
  7355. super();
  7356. this.isShaderMaterial = true;
  7357. this.type = 'ShaderMaterial';
  7358. this.defines = {};
  7359. this.uniforms = {};
  7360. this.uniformsGroups = [];
  7361. this.vertexShader = default_vertex;
  7362. this.fragmentShader = default_fragment;
  7363. this.linewidth = 1;
  7364. this.wireframe = false;
  7365. this.wireframeLinewidth = 1;
  7366. this.fog = false; // set to use scene fog
  7367. this.lights = false; // set to use scene lights
  7368. this.clipping = false; // set to use user-defined clipping planes
  7369. this.forceSinglePass = true;
  7370. this.extensions = {
  7371. clipCullDistance: false, // set to use vertex shader clipping
  7372. multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID
  7373. };
  7374. // When rendered geometry doesn't include these attributes but the material does,
  7375. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7376. this.defaultAttributeValues = {
  7377. 'color': [ 1, 1, 1 ],
  7378. 'uv': [ 0, 0 ],
  7379. 'uv1': [ 0, 0 ]
  7380. };
  7381. this.index0AttributeName = undefined;
  7382. this.uniformsNeedUpdate = false;
  7383. this.glslVersion = null;
  7384. if ( parameters !== undefined ) {
  7385. this.setValues( parameters );
  7386. }
  7387. }
  7388. copy( source ) {
  7389. super.copy( source );
  7390. this.fragmentShader = source.fragmentShader;
  7391. this.vertexShader = source.vertexShader;
  7392. this.uniforms = cloneUniforms( source.uniforms );
  7393. this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );
  7394. this.defines = Object.assign( {}, source.defines );
  7395. this.wireframe = source.wireframe;
  7396. this.wireframeLinewidth = source.wireframeLinewidth;
  7397. this.fog = source.fog;
  7398. this.lights = source.lights;
  7399. this.clipping = source.clipping;
  7400. this.extensions = Object.assign( {}, source.extensions );
  7401. this.glslVersion = source.glslVersion;
  7402. return this;
  7403. }
  7404. toJSON( meta ) {
  7405. const data = super.toJSON( meta );
  7406. data.glslVersion = this.glslVersion;
  7407. data.uniforms = {};
  7408. for ( const name in this.uniforms ) {
  7409. const uniform = this.uniforms[ name ];
  7410. const value = uniform.value;
  7411. if ( value && value.isTexture ) {
  7412. data.uniforms[ name ] = {
  7413. type: 't',
  7414. value: value.toJSON( meta ).uuid
  7415. };
  7416. } else if ( value && value.isColor ) {
  7417. data.uniforms[ name ] = {
  7418. type: 'c',
  7419. value: value.getHex()
  7420. };
  7421. } else if ( value && value.isVector2 ) {
  7422. data.uniforms[ name ] = {
  7423. type: 'v2',
  7424. value: value.toArray()
  7425. };
  7426. } else if ( value && value.isVector3 ) {
  7427. data.uniforms[ name ] = {
  7428. type: 'v3',
  7429. value: value.toArray()
  7430. };
  7431. } else if ( value && value.isVector4 ) {
  7432. data.uniforms[ name ] = {
  7433. type: 'v4',
  7434. value: value.toArray()
  7435. };
  7436. } else if ( value && value.isMatrix3 ) {
  7437. data.uniforms[ name ] = {
  7438. type: 'm3',
  7439. value: value.toArray()
  7440. };
  7441. } else if ( value && value.isMatrix4 ) {
  7442. data.uniforms[ name ] = {
  7443. type: 'm4',
  7444. value: value.toArray()
  7445. };
  7446. } else {
  7447. data.uniforms[ name ] = {
  7448. value: value
  7449. };
  7450. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7451. }
  7452. }
  7453. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7454. data.vertexShader = this.vertexShader;
  7455. data.fragmentShader = this.fragmentShader;
  7456. data.lights = this.lights;
  7457. data.clipping = this.clipping;
  7458. const extensions = {};
  7459. for ( const key in this.extensions ) {
  7460. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7461. }
  7462. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7463. return data;
  7464. }
  7465. }
  7466. class Camera extends Object3D {
  7467. constructor() {
  7468. super();
  7469. this.isCamera = true;
  7470. this.type = 'Camera';
  7471. this.matrixWorldInverse = new Matrix4();
  7472. this.projectionMatrix = new Matrix4();
  7473. this.projectionMatrixInverse = new Matrix4();
  7474. this.coordinateSystem = WebGLCoordinateSystem;
  7475. }
  7476. copy( source, recursive ) {
  7477. super.copy( source, recursive );
  7478. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7479. this.projectionMatrix.copy( source.projectionMatrix );
  7480. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7481. this.coordinateSystem = source.coordinateSystem;
  7482. return this;
  7483. }
  7484. getWorldDirection( target ) {
  7485. return super.getWorldDirection( target ).negate();
  7486. }
  7487. updateMatrixWorld( force ) {
  7488. super.updateMatrixWorld( force );
  7489. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7490. }
  7491. updateWorldMatrix( updateParents, updateChildren ) {
  7492. super.updateWorldMatrix( updateParents, updateChildren );
  7493. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7494. }
  7495. clone() {
  7496. return new this.constructor().copy( this );
  7497. }
  7498. }
  7499. const _v3$1 = /*@__PURE__*/ new Vector3();
  7500. const _minTarget = /*@__PURE__*/ new Vector2();
  7501. const _maxTarget = /*@__PURE__*/ new Vector2();
  7502. class PerspectiveCamera extends Camera {
  7503. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7504. super();
  7505. this.isPerspectiveCamera = true;
  7506. this.type = 'PerspectiveCamera';
  7507. this.fov = fov;
  7508. this.zoom = 1;
  7509. this.near = near;
  7510. this.far = far;
  7511. this.focus = 10;
  7512. this.aspect = aspect;
  7513. this.view = null;
  7514. this.filmGauge = 35; // width of the film (default in millimeters)
  7515. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7516. this.updateProjectionMatrix();
  7517. }
  7518. copy( source, recursive ) {
  7519. super.copy( source, recursive );
  7520. this.fov = source.fov;
  7521. this.zoom = source.zoom;
  7522. this.near = source.near;
  7523. this.far = source.far;
  7524. this.focus = source.focus;
  7525. this.aspect = source.aspect;
  7526. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7527. this.filmGauge = source.filmGauge;
  7528. this.filmOffset = source.filmOffset;
  7529. return this;
  7530. }
  7531. /**
  7532. * Sets the FOV by focal length in respect to the current .filmGauge.
  7533. *
  7534. * The default film gauge is 35, so that the focal length can be specified for
  7535. * a 35mm (full frame) camera.
  7536. *
  7537. * Values for focal length and film gauge must have the same unit.
  7538. */
  7539. setFocalLength( focalLength ) {
  7540. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7541. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7542. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  7543. this.updateProjectionMatrix();
  7544. }
  7545. /**
  7546. * Calculates the focal length from the current .fov and .filmGauge.
  7547. */
  7548. getFocalLength() {
  7549. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  7550. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7551. }
  7552. getEffectiveFOV() {
  7553. return RAD2DEG * 2 * Math.atan(
  7554. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7555. }
  7556. getFilmWidth() {
  7557. // film not completely covered in portrait format (aspect < 1)
  7558. return this.filmGauge * Math.min( this.aspect, 1 );
  7559. }
  7560. getFilmHeight() {
  7561. // film not completely covered in landscape format (aspect > 1)
  7562. return this.filmGauge / Math.max( this.aspect, 1 );
  7563. }
  7564. /**
  7565. * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  7566. * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  7567. */
  7568. getViewBounds( distance, minTarget, maxTarget ) {
  7569. _v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7570. minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7571. _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7572. maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7573. }
  7574. /**
  7575. * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  7576. * Copies the result into the target Vector2, where x is width and y is height.
  7577. */
  7578. getViewSize( distance, target ) {
  7579. this.getViewBounds( distance, _minTarget, _maxTarget );
  7580. return target.subVectors( _maxTarget, _minTarget );
  7581. }
  7582. /**
  7583. * Sets an offset in a larger frustum. This is useful for multi-window or
  7584. * multi-monitor/multi-machine setups.
  7585. *
  7586. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7587. * the monitors are in grid like this
  7588. *
  7589. * +---+---+---+
  7590. * | A | B | C |
  7591. * +---+---+---+
  7592. * | D | E | F |
  7593. * +---+---+---+
  7594. *
  7595. * then for each monitor you would call it like this
  7596. *
  7597. * const w = 1920;
  7598. * const h = 1080;
  7599. * const fullWidth = w * 3;
  7600. * const fullHeight = h * 2;
  7601. *
  7602. * --A--
  7603. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7604. * --B--
  7605. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7606. * --C--
  7607. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7608. * --D--
  7609. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7610. * --E--
  7611. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7612. * --F--
  7613. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7614. *
  7615. * Note there is no reason monitors have to be the same size or in a grid.
  7616. */
  7617. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  7618. this.aspect = fullWidth / fullHeight;
  7619. if ( this.view === null ) {
  7620. this.view = {
  7621. enabled: true,
  7622. fullWidth: 1,
  7623. fullHeight: 1,
  7624. offsetX: 0,
  7625. offsetY: 0,
  7626. width: 1,
  7627. height: 1
  7628. };
  7629. }
  7630. this.view.enabled = true;
  7631. this.view.fullWidth = fullWidth;
  7632. this.view.fullHeight = fullHeight;
  7633. this.view.offsetX = x;
  7634. this.view.offsetY = y;
  7635. this.view.width = width;
  7636. this.view.height = height;
  7637. this.updateProjectionMatrix();
  7638. }
  7639. clearViewOffset() {
  7640. if ( this.view !== null ) {
  7641. this.view.enabled = false;
  7642. }
  7643. this.updateProjectionMatrix();
  7644. }
  7645. updateProjectionMatrix() {
  7646. const near = this.near;
  7647. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7648. let height = 2 * top;
  7649. let width = this.aspect * height;
  7650. let left = - 0.5 * width;
  7651. const view = this.view;
  7652. if ( this.view !== null && this.view.enabled ) {
  7653. const fullWidth = view.fullWidth,
  7654. fullHeight = view.fullHeight;
  7655. left += view.offsetX * width / fullWidth;
  7656. top -= view.offsetY * height / fullHeight;
  7657. width *= view.width / fullWidth;
  7658. height *= view.height / fullHeight;
  7659. }
  7660. const skew = this.filmOffset;
  7661. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7662. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
  7663. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7664. }
  7665. toJSON( meta ) {
  7666. const data = super.toJSON( meta );
  7667. data.object.fov = this.fov;
  7668. data.object.zoom = this.zoom;
  7669. data.object.near = this.near;
  7670. data.object.far = this.far;
  7671. data.object.focus = this.focus;
  7672. data.object.aspect = this.aspect;
  7673. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7674. data.object.filmGauge = this.filmGauge;
  7675. data.object.filmOffset = this.filmOffset;
  7676. return data;
  7677. }
  7678. }
  7679. const fov = - 90; // negative fov is not an error
  7680. const aspect = 1;
  7681. class CubeCamera extends Object3D {
  7682. constructor( near, far, renderTarget ) {
  7683. super();
  7684. this.type = 'CubeCamera';
  7685. this.renderTarget = renderTarget;
  7686. this.coordinateSystem = null;
  7687. this.activeMipmapLevel = 0;
  7688. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7689. cameraPX.layers = this.layers;
  7690. this.add( cameraPX );
  7691. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7692. cameraNX.layers = this.layers;
  7693. this.add( cameraNX );
  7694. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7695. cameraPY.layers = this.layers;
  7696. this.add( cameraPY );
  7697. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7698. cameraNY.layers = this.layers;
  7699. this.add( cameraNY );
  7700. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7701. cameraPZ.layers = this.layers;
  7702. this.add( cameraPZ );
  7703. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7704. cameraNZ.layers = this.layers;
  7705. this.add( cameraNZ );
  7706. }
  7707. updateCoordinateSystem() {
  7708. const coordinateSystem = this.coordinateSystem;
  7709. const cameras = this.children.concat();
  7710. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
  7711. for ( const camera of cameras ) this.remove( camera );
  7712. if ( coordinateSystem === WebGLCoordinateSystem ) {
  7713. cameraPX.up.set( 0, 1, 0 );
  7714. cameraPX.lookAt( 1, 0, 0 );
  7715. cameraNX.up.set( 0, 1, 0 );
  7716. cameraNX.lookAt( - 1, 0, 0 );
  7717. cameraPY.up.set( 0, 0, - 1 );
  7718. cameraPY.lookAt( 0, 1, 0 );
  7719. cameraNY.up.set( 0, 0, 1 );
  7720. cameraNY.lookAt( 0, - 1, 0 );
  7721. cameraPZ.up.set( 0, 1, 0 );
  7722. cameraPZ.lookAt( 0, 0, 1 );
  7723. cameraNZ.up.set( 0, 1, 0 );
  7724. cameraNZ.lookAt( 0, 0, - 1 );
  7725. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  7726. cameraPX.up.set( 0, - 1, 0 );
  7727. cameraPX.lookAt( - 1, 0, 0 );
  7728. cameraNX.up.set( 0, - 1, 0 );
  7729. cameraNX.lookAt( 1, 0, 0 );
  7730. cameraPY.up.set( 0, 0, 1 );
  7731. cameraPY.lookAt( 0, 1, 0 );
  7732. cameraNY.up.set( 0, 0, - 1 );
  7733. cameraNY.lookAt( 0, - 1, 0 );
  7734. cameraPZ.up.set( 0, - 1, 0 );
  7735. cameraPZ.lookAt( 0, 0, 1 );
  7736. cameraNZ.up.set( 0, - 1, 0 );
  7737. cameraNZ.lookAt( 0, 0, - 1 );
  7738. } else {
  7739. throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
  7740. }
  7741. for ( const camera of cameras ) {
  7742. this.add( camera );
  7743. camera.updateMatrixWorld();
  7744. }
  7745. }
  7746. update( renderer, scene ) {
  7747. if ( this.parent === null ) this.updateMatrixWorld();
  7748. const { renderTarget, activeMipmapLevel } = this;
  7749. if ( this.coordinateSystem !== renderer.coordinateSystem ) {
  7750. this.coordinateSystem = renderer.coordinateSystem;
  7751. this.updateCoordinateSystem();
  7752. }
  7753. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7754. const currentRenderTarget = renderer.getRenderTarget();
  7755. const currentActiveCubeFace = renderer.getActiveCubeFace();
  7756. const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
  7757. const currentXrEnabled = renderer.xr.enabled;
  7758. renderer.xr.enabled = false;
  7759. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7760. renderTarget.texture.generateMipmaps = false;
  7761. renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
  7762. renderer.render( scene, cameraPX );
  7763. renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
  7764. renderer.render( scene, cameraNX );
  7765. renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
  7766. renderer.render( scene, cameraPY );
  7767. renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
  7768. renderer.render( scene, cameraNY );
  7769. renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
  7770. renderer.render( scene, cameraPZ );
  7771. // mipmaps are generated during the last call of render()
  7772. // at this point, all sides of the cube render target are defined
  7773. renderTarget.texture.generateMipmaps = generateMipmaps;
  7774. renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
  7775. renderer.render( scene, cameraNZ );
  7776. renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
  7777. renderer.xr.enabled = currentXrEnabled;
  7778. renderTarget.texture.needsPMREMUpdate = true;
  7779. }
  7780. }
  7781. class CubeTexture extends Texture {
  7782. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {
  7783. images = images !== undefined ? images : [];
  7784. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7785. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  7786. this.isCubeTexture = true;
  7787. this.flipY = false;
  7788. }
  7789. get images() {
  7790. return this.image;
  7791. }
  7792. set images( value ) {
  7793. this.image = value;
  7794. }
  7795. }
  7796. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7797. constructor( size = 1, options = {} ) {
  7798. super( size, size, options );
  7799. this.isWebGLCubeRenderTarget = true;
  7800. const image = { width: size, height: size, depth: 1 };
  7801. const images = [ image, image, image, image, image, image ];
  7802. this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  7803. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7804. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7805. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7806. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7807. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7808. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7809. this.texture.isRenderTargetTexture = true;
  7810. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7811. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7812. }
  7813. fromEquirectangularTexture( renderer, texture ) {
  7814. this.texture.type = texture.type;
  7815. this.texture.colorSpace = texture.colorSpace;
  7816. this.texture.generateMipmaps = texture.generateMipmaps;
  7817. this.texture.minFilter = texture.minFilter;
  7818. this.texture.magFilter = texture.magFilter;
  7819. const shader = {
  7820. uniforms: {
  7821. tEquirect: { value: null },
  7822. },
  7823. vertexShader: /* glsl */`
  7824. varying vec3 vWorldDirection;
  7825. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7826. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7827. }
  7828. void main() {
  7829. vWorldDirection = transformDirection( position, modelMatrix );
  7830. #include <begin_vertex>
  7831. #include <project_vertex>
  7832. }
  7833. `,
  7834. fragmentShader: /* glsl */`
  7835. uniform sampler2D tEquirect;
  7836. varying vec3 vWorldDirection;
  7837. #include <common>
  7838. void main() {
  7839. vec3 direction = normalize( vWorldDirection );
  7840. vec2 sampleUV = equirectUv( direction );
  7841. gl_FragColor = texture2D( tEquirect, sampleUV );
  7842. }
  7843. `
  7844. };
  7845. const geometry = new BoxGeometry( 5, 5, 5 );
  7846. const material = new ShaderMaterial( {
  7847. name: 'CubemapFromEquirect',
  7848. uniforms: cloneUniforms( shader.uniforms ),
  7849. vertexShader: shader.vertexShader,
  7850. fragmentShader: shader.fragmentShader,
  7851. side: BackSide,
  7852. blending: NoBlending
  7853. } );
  7854. material.uniforms.tEquirect.value = texture;
  7855. const mesh = new Mesh( geometry, material );
  7856. const currentMinFilter = texture.minFilter;
  7857. // Avoid blurred poles
  7858. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7859. const camera = new CubeCamera( 1, 10, this );
  7860. camera.update( renderer, mesh );
  7861. texture.minFilter = currentMinFilter;
  7862. mesh.geometry.dispose();
  7863. mesh.material.dispose();
  7864. return this;
  7865. }
  7866. clear( renderer, color, depth, stencil ) {
  7867. const currentRenderTarget = renderer.getRenderTarget();
  7868. for ( let i = 0; i < 6; i ++ ) {
  7869. renderer.setRenderTarget( this, i );
  7870. renderer.clear( color, depth, stencil );
  7871. }
  7872. renderer.setRenderTarget( currentRenderTarget );
  7873. }
  7874. }
  7875. class FogExp2 {
  7876. constructor( color, density = 0.00025 ) {
  7877. this.isFogExp2 = true;
  7878. this.name = '';
  7879. this.color = new Color( color );
  7880. this.density = density;
  7881. }
  7882. clone() {
  7883. return new FogExp2( this.color, this.density );
  7884. }
  7885. toJSON( /* meta */ ) {
  7886. return {
  7887. type: 'FogExp2',
  7888. name: this.name,
  7889. color: this.color.getHex(),
  7890. density: this.density
  7891. };
  7892. }
  7893. }
  7894. class Fog {
  7895. constructor( color, near = 1, far = 1000 ) {
  7896. this.isFog = true;
  7897. this.name = '';
  7898. this.color = new Color( color );
  7899. this.near = near;
  7900. this.far = far;
  7901. }
  7902. clone() {
  7903. return new Fog( this.color, this.near, this.far );
  7904. }
  7905. toJSON( /* meta */ ) {
  7906. return {
  7907. type: 'Fog',
  7908. name: this.name,
  7909. color: this.color.getHex(),
  7910. near: this.near,
  7911. far: this.far
  7912. };
  7913. }
  7914. }
  7915. class Scene extends Object3D {
  7916. constructor() {
  7917. super();
  7918. this.isScene = true;
  7919. this.type = 'Scene';
  7920. this.background = null;
  7921. this.environment = null;
  7922. this.fog = null;
  7923. this.backgroundBlurriness = 0;
  7924. this.backgroundIntensity = 1;
  7925. this.backgroundRotation = new Euler();
  7926. this.environmentIntensity = 1;
  7927. this.environmentRotation = new Euler();
  7928. this.overrideMaterial = null;
  7929. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  7930. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
  7931. }
  7932. }
  7933. copy( source, recursive ) {
  7934. super.copy( source, recursive );
  7935. if ( source.background !== null ) this.background = source.background.clone();
  7936. if ( source.environment !== null ) this.environment = source.environment.clone();
  7937. if ( source.fog !== null ) this.fog = source.fog.clone();
  7938. this.backgroundBlurriness = source.backgroundBlurriness;
  7939. this.backgroundIntensity = source.backgroundIntensity;
  7940. this.backgroundRotation.copy( source.backgroundRotation );
  7941. this.environmentIntensity = source.environmentIntensity;
  7942. this.environmentRotation.copy( source.environmentRotation );
  7943. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  7944. this.matrixAutoUpdate = source.matrixAutoUpdate;
  7945. return this;
  7946. }
  7947. toJSON( meta ) {
  7948. const data = super.toJSON( meta );
  7949. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  7950. if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
  7951. if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
  7952. data.object.backgroundRotation = this.backgroundRotation.toArray();
  7953. if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
  7954. data.object.environmentRotation = this.environmentRotation.toArray();
  7955. return data;
  7956. }
  7957. }
  7958. class InterleavedBuffer {
  7959. constructor( array, stride ) {
  7960. this.isInterleavedBuffer = true;
  7961. this.array = array;
  7962. this.stride = stride;
  7963. this.count = array !== undefined ? array.length / stride : 0;
  7964. this.usage = StaticDrawUsage;
  7965. this.updateRanges = [];
  7966. this.version = 0;
  7967. this.uuid = generateUUID();
  7968. }
  7969. onUploadCallback() {}
  7970. set needsUpdate( value ) {
  7971. if ( value === true ) this.version ++;
  7972. }
  7973. setUsage( value ) {
  7974. this.usage = value;
  7975. return this;
  7976. }
  7977. addUpdateRange( start, count ) {
  7978. this.updateRanges.push( { start, count } );
  7979. }
  7980. clearUpdateRanges() {
  7981. this.updateRanges.length = 0;
  7982. }
  7983. copy( source ) {
  7984. this.array = new source.array.constructor( source.array );
  7985. this.count = source.count;
  7986. this.stride = source.stride;
  7987. this.usage = source.usage;
  7988. return this;
  7989. }
  7990. copyAt( index1, attribute, index2 ) {
  7991. index1 *= this.stride;
  7992. index2 *= attribute.stride;
  7993. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  7994. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7995. }
  7996. return this;
  7997. }
  7998. set( value, offset = 0 ) {
  7999. this.array.set( value, offset );
  8000. return this;
  8001. }
  8002. clone( data ) {
  8003. if ( data.arrayBuffers === undefined ) {
  8004. data.arrayBuffers = {};
  8005. }
  8006. if ( this.array.buffer._uuid === undefined ) {
  8007. this.array.buffer._uuid = generateUUID();
  8008. }
  8009. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8010. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  8011. }
  8012. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  8013. const ib = new this.constructor( array, this.stride );
  8014. ib.setUsage( this.usage );
  8015. return ib;
  8016. }
  8017. onUpload( callback ) {
  8018. this.onUploadCallback = callback;
  8019. return this;
  8020. }
  8021. toJSON( data ) {
  8022. if ( data.arrayBuffers === undefined ) {
  8023. data.arrayBuffers = {};
  8024. }
  8025. // generate UUID for array buffer if necessary
  8026. if ( this.array.buffer._uuid === undefined ) {
  8027. this.array.buffer._uuid = generateUUID();
  8028. }
  8029. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8030. data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
  8031. }
  8032. //
  8033. return {
  8034. uuid: this.uuid,
  8035. buffer: this.array.buffer._uuid,
  8036. type: this.array.constructor.name,
  8037. stride: this.stride
  8038. };
  8039. }
  8040. }
  8041. const _vector$7 = /*@__PURE__*/ new Vector3();
  8042. class InterleavedBufferAttribute {
  8043. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  8044. this.isInterleavedBufferAttribute = true;
  8045. this.name = '';
  8046. this.data = interleavedBuffer;
  8047. this.itemSize = itemSize;
  8048. this.offset = offset;
  8049. this.normalized = normalized;
  8050. }
  8051. get count() {
  8052. return this.data.count;
  8053. }
  8054. get array() {
  8055. return this.data.array;
  8056. }
  8057. set needsUpdate( value ) {
  8058. this.data.needsUpdate = value;
  8059. }
  8060. applyMatrix4( m ) {
  8061. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  8062. _vector$7.fromBufferAttribute( this, i );
  8063. _vector$7.applyMatrix4( m );
  8064. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8065. }
  8066. return this;
  8067. }
  8068. applyNormalMatrix( m ) {
  8069. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8070. _vector$7.fromBufferAttribute( this, i );
  8071. _vector$7.applyNormalMatrix( m );
  8072. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8073. }
  8074. return this;
  8075. }
  8076. transformDirection( m ) {
  8077. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8078. _vector$7.fromBufferAttribute( this, i );
  8079. _vector$7.transformDirection( m );
  8080. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8081. }
  8082. return this;
  8083. }
  8084. getComponent( index, component ) {
  8085. let value = this.array[ index * this.data.stride + this.offset + component ];
  8086. if ( this.normalized ) value = denormalize( value, this.array );
  8087. return value;
  8088. }
  8089. setComponent( index, component, value ) {
  8090. if ( this.normalized ) value = normalize( value, this.array );
  8091. this.data.array[ index * this.data.stride + this.offset + component ] = value;
  8092. return this;
  8093. }
  8094. setX( index, x ) {
  8095. if ( this.normalized ) x = normalize( x, this.array );
  8096. this.data.array[ index * this.data.stride + this.offset ] = x;
  8097. return this;
  8098. }
  8099. setY( index, y ) {
  8100. if ( this.normalized ) y = normalize( y, this.array );
  8101. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  8102. return this;
  8103. }
  8104. setZ( index, z ) {
  8105. if ( this.normalized ) z = normalize( z, this.array );
  8106. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  8107. return this;
  8108. }
  8109. setW( index, w ) {
  8110. if ( this.normalized ) w = normalize( w, this.array );
  8111. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  8112. return this;
  8113. }
  8114. getX( index ) {
  8115. let x = this.data.array[ index * this.data.stride + this.offset ];
  8116. if ( this.normalized ) x = denormalize( x, this.array );
  8117. return x;
  8118. }
  8119. getY( index ) {
  8120. let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
  8121. if ( this.normalized ) y = denormalize( y, this.array );
  8122. return y;
  8123. }
  8124. getZ( index ) {
  8125. let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
  8126. if ( this.normalized ) z = denormalize( z, this.array );
  8127. return z;
  8128. }
  8129. getW( index ) {
  8130. let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
  8131. if ( this.normalized ) w = denormalize( w, this.array );
  8132. return w;
  8133. }
  8134. setXY( index, x, y ) {
  8135. index = index * this.data.stride + this.offset;
  8136. if ( this.normalized ) {
  8137. x = normalize( x, this.array );
  8138. y = normalize( y, this.array );
  8139. }
  8140. this.data.array[ index + 0 ] = x;
  8141. this.data.array[ index + 1 ] = y;
  8142. return this;
  8143. }
  8144. setXYZ( index, x, y, z ) {
  8145. index = index * this.data.stride + this.offset;
  8146. if ( this.normalized ) {
  8147. x = normalize( x, this.array );
  8148. y = normalize( y, this.array );
  8149. z = normalize( z, this.array );
  8150. }
  8151. this.data.array[ index + 0 ] = x;
  8152. this.data.array[ index + 1 ] = y;
  8153. this.data.array[ index + 2 ] = z;
  8154. return this;
  8155. }
  8156. setXYZW( index, x, y, z, w ) {
  8157. index = index * this.data.stride + this.offset;
  8158. if ( this.normalized ) {
  8159. x = normalize( x, this.array );
  8160. y = normalize( y, this.array );
  8161. z = normalize( z, this.array );
  8162. w = normalize( w, this.array );
  8163. }
  8164. this.data.array[ index + 0 ] = x;
  8165. this.data.array[ index + 1 ] = y;
  8166. this.data.array[ index + 2 ] = z;
  8167. this.data.array[ index + 3 ] = w;
  8168. return this;
  8169. }
  8170. clone( data ) {
  8171. if ( data === undefined ) {
  8172. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
  8173. const array = [];
  8174. for ( let i = 0; i < this.count; i ++ ) {
  8175. const index = i * this.data.stride + this.offset;
  8176. for ( let j = 0; j < this.itemSize; j ++ ) {
  8177. array.push( this.data.array[ index + j ] );
  8178. }
  8179. }
  8180. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  8181. } else {
  8182. if ( data.interleavedBuffers === undefined ) {
  8183. data.interleavedBuffers = {};
  8184. }
  8185. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8186. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  8187. }
  8188. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  8189. }
  8190. }
  8191. toJSON( data ) {
  8192. if ( data === undefined ) {
  8193. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
  8194. const array = [];
  8195. for ( let i = 0; i < this.count; i ++ ) {
  8196. const index = i * this.data.stride + this.offset;
  8197. for ( let j = 0; j < this.itemSize; j ++ ) {
  8198. array.push( this.data.array[ index + j ] );
  8199. }
  8200. }
  8201. // de-interleave data and save it as an ordinary buffer attribute for now
  8202. return {
  8203. itemSize: this.itemSize,
  8204. type: this.array.constructor.name,
  8205. array: array,
  8206. normalized: this.normalized
  8207. };
  8208. } else {
  8209. // save as true interleaved attribute
  8210. if ( data.interleavedBuffers === undefined ) {
  8211. data.interleavedBuffers = {};
  8212. }
  8213. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8214. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  8215. }
  8216. return {
  8217. isInterleavedBufferAttribute: true,
  8218. itemSize: this.itemSize,
  8219. data: this.data.uuid,
  8220. offset: this.offset,
  8221. normalized: this.normalized
  8222. };
  8223. }
  8224. }
  8225. }
  8226. class SpriteMaterial extends Material {
  8227. constructor( parameters ) {
  8228. super();
  8229. this.isSpriteMaterial = true;
  8230. this.type = 'SpriteMaterial';
  8231. this.color = new Color( 0xffffff );
  8232. this.map = null;
  8233. this.alphaMap = null;
  8234. this.rotation = 0;
  8235. this.sizeAttenuation = true;
  8236. this.transparent = true;
  8237. this.fog = true;
  8238. this.setValues( parameters );
  8239. }
  8240. copy( source ) {
  8241. super.copy( source );
  8242. this.color.copy( source.color );
  8243. this.map = source.map;
  8244. this.alphaMap = source.alphaMap;
  8245. this.rotation = source.rotation;
  8246. this.sizeAttenuation = source.sizeAttenuation;
  8247. this.fog = source.fog;
  8248. return this;
  8249. }
  8250. }
  8251. let _geometry;
  8252. const _intersectPoint = /*@__PURE__*/ new Vector3();
  8253. const _worldScale = /*@__PURE__*/ new Vector3();
  8254. const _mvPosition = /*@__PURE__*/ new Vector3();
  8255. const _alignedPosition = /*@__PURE__*/ new Vector2();
  8256. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  8257. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  8258. const _vA = /*@__PURE__*/ new Vector3();
  8259. const _vB = /*@__PURE__*/ new Vector3();
  8260. const _vC = /*@__PURE__*/ new Vector3();
  8261. const _uvA = /*@__PURE__*/ new Vector2();
  8262. const _uvB = /*@__PURE__*/ new Vector2();
  8263. const _uvC = /*@__PURE__*/ new Vector2();
  8264. class Sprite extends Object3D {
  8265. constructor( material = new SpriteMaterial() ) {
  8266. super();
  8267. this.isSprite = true;
  8268. this.type = 'Sprite';
  8269. if ( _geometry === undefined ) {
  8270. _geometry = new BufferGeometry();
  8271. const float32Array = new Float32Array( [
  8272. - 0.5, - 0.5, 0, 0, 0,
  8273. 0.5, - 0.5, 0, 1, 0,
  8274. 0.5, 0.5, 0, 1, 1,
  8275. - 0.5, 0.5, 0, 0, 1
  8276. ] );
  8277. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  8278. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  8279. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  8280. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  8281. }
  8282. this.geometry = _geometry;
  8283. this.material = material;
  8284. this.center = new Vector2( 0.5, 0.5 );
  8285. }
  8286. raycast( raycaster, intersects ) {
  8287. if ( raycaster.camera === null ) {
  8288. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  8289. }
  8290. _worldScale.setFromMatrixScale( this.matrixWorld );
  8291. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  8292. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  8293. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  8294. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  8295. _worldScale.multiplyScalar( - _mvPosition.z );
  8296. }
  8297. const rotation = this.material.rotation;
  8298. let sin, cos;
  8299. if ( rotation !== 0 ) {
  8300. cos = Math.cos( rotation );
  8301. sin = Math.sin( rotation );
  8302. }
  8303. const center = this.center;
  8304. transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8305. transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8306. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8307. _uvA.set( 0, 0 );
  8308. _uvB.set( 1, 0 );
  8309. _uvC.set( 1, 1 );
  8310. // check first triangle
  8311. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  8312. if ( intersect === null ) {
  8313. // check second triangle
  8314. transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8315. _uvB.set( 0, 1 );
  8316. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  8317. if ( intersect === null ) {
  8318. return;
  8319. }
  8320. }
  8321. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  8322. if ( distance < raycaster.near || distance > raycaster.far ) return;
  8323. intersects.push( {
  8324. distance: distance,
  8325. point: _intersectPoint.clone(),
  8326. uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  8327. face: null,
  8328. object: this
  8329. } );
  8330. }
  8331. copy( source, recursive ) {
  8332. super.copy( source, recursive );
  8333. if ( source.center !== undefined ) this.center.copy( source.center );
  8334. this.material = source.material;
  8335. return this;
  8336. }
  8337. }
  8338. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  8339. // compute position in camera space
  8340. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  8341. // to check if rotation is not zero
  8342. if ( sin !== undefined ) {
  8343. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  8344. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  8345. } else {
  8346. _rotatedPosition.copy( _alignedPosition );
  8347. }
  8348. vertexPosition.copy( mvPosition );
  8349. vertexPosition.x += _rotatedPosition.x;
  8350. vertexPosition.y += _rotatedPosition.y;
  8351. // transform to world space
  8352. vertexPosition.applyMatrix4( _viewWorldMatrix );
  8353. }
  8354. const _v1$2 = /*@__PURE__*/ new Vector3();
  8355. const _v2$1 = /*@__PURE__*/ new Vector3();
  8356. class LOD extends Object3D {
  8357. constructor() {
  8358. super();
  8359. this._currentLevel = 0;
  8360. this.type = 'LOD';
  8361. Object.defineProperties( this, {
  8362. levels: {
  8363. enumerable: true,
  8364. value: []
  8365. },
  8366. isLOD: {
  8367. value: true,
  8368. }
  8369. } );
  8370. this.autoUpdate = true;
  8371. }
  8372. copy( source ) {
  8373. super.copy( source, false );
  8374. const levels = source.levels;
  8375. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8376. const level = levels[ i ];
  8377. this.addLevel( level.object.clone(), level.distance, level.hysteresis );
  8378. }
  8379. this.autoUpdate = source.autoUpdate;
  8380. return this;
  8381. }
  8382. addLevel( object, distance = 0, hysteresis = 0 ) {
  8383. distance = Math.abs( distance );
  8384. const levels = this.levels;
  8385. let l;
  8386. for ( l = 0; l < levels.length; l ++ ) {
  8387. if ( distance < levels[ l ].distance ) {
  8388. break;
  8389. }
  8390. }
  8391. levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } );
  8392. this.add( object );
  8393. return this;
  8394. }
  8395. removeLevel( distance ) {
  8396. const levels = this.levels;
  8397. for ( let i = 0; i < levels.length; i ++ ) {
  8398. if ( levels[ i ].distance === distance ) {
  8399. const removedElements = levels.splice( i, 1 );
  8400. this.remove( removedElements[ 0 ].object );
  8401. return true;
  8402. }
  8403. }
  8404. return false;
  8405. }
  8406. getCurrentLevel() {
  8407. return this._currentLevel;
  8408. }
  8409. getObjectForDistance( distance ) {
  8410. const levels = this.levels;
  8411. if ( levels.length > 0 ) {
  8412. let i, l;
  8413. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8414. let levelDistance = levels[ i ].distance;
  8415. if ( levels[ i ].object.visible ) {
  8416. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8417. }
  8418. if ( distance < levelDistance ) {
  8419. break;
  8420. }
  8421. }
  8422. return levels[ i - 1 ].object;
  8423. }
  8424. return null;
  8425. }
  8426. raycast( raycaster, intersects ) {
  8427. const levels = this.levels;
  8428. if ( levels.length > 0 ) {
  8429. _v1$2.setFromMatrixPosition( this.matrixWorld );
  8430. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  8431. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  8432. }
  8433. }
  8434. update( camera ) {
  8435. const levels = this.levels;
  8436. if ( levels.length > 1 ) {
  8437. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  8438. _v2$1.setFromMatrixPosition( this.matrixWorld );
  8439. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  8440. levels[ 0 ].object.visible = true;
  8441. let i, l;
  8442. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8443. let levelDistance = levels[ i ].distance;
  8444. if ( levels[ i ].object.visible ) {
  8445. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8446. }
  8447. if ( distance >= levelDistance ) {
  8448. levels[ i - 1 ].object.visible = false;
  8449. levels[ i ].object.visible = true;
  8450. } else {
  8451. break;
  8452. }
  8453. }
  8454. this._currentLevel = i - 1;
  8455. for ( ; i < l; i ++ ) {
  8456. levels[ i ].object.visible = false;
  8457. }
  8458. }
  8459. }
  8460. toJSON( meta ) {
  8461. const data = super.toJSON( meta );
  8462. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  8463. data.object.levels = [];
  8464. const levels = this.levels;
  8465. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8466. const level = levels[ i ];
  8467. data.object.levels.push( {
  8468. object: level.object.uuid,
  8469. distance: level.distance,
  8470. hysteresis: level.hysteresis
  8471. } );
  8472. }
  8473. return data;
  8474. }
  8475. }
  8476. const _basePosition = /*@__PURE__*/ new Vector3();
  8477. const _skinIndex = /*@__PURE__*/ new Vector4();
  8478. const _skinWeight = /*@__PURE__*/ new Vector4();
  8479. const _vector3 = /*@__PURE__*/ new Vector3();
  8480. const _matrix4 = /*@__PURE__*/ new Matrix4();
  8481. const _vertex = /*@__PURE__*/ new Vector3();
  8482. const _sphere$5 = /*@__PURE__*/ new Sphere();
  8483. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  8484. const _ray$2 = /*@__PURE__*/ new Ray();
  8485. class SkinnedMesh extends Mesh {
  8486. constructor( geometry, material ) {
  8487. super( geometry, material );
  8488. this.isSkinnedMesh = true;
  8489. this.type = 'SkinnedMesh';
  8490. this.bindMode = AttachedBindMode;
  8491. this.bindMatrix = new Matrix4();
  8492. this.bindMatrixInverse = new Matrix4();
  8493. this.boundingBox = null;
  8494. this.boundingSphere = null;
  8495. }
  8496. computeBoundingBox() {
  8497. const geometry = this.geometry;
  8498. if ( this.boundingBox === null ) {
  8499. this.boundingBox = new Box3();
  8500. }
  8501. this.boundingBox.makeEmpty();
  8502. const positionAttribute = geometry.getAttribute( 'position' );
  8503. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8504. this.getVertexPosition( i, _vertex );
  8505. this.boundingBox.expandByPoint( _vertex );
  8506. }
  8507. }
  8508. computeBoundingSphere() {
  8509. const geometry = this.geometry;
  8510. if ( this.boundingSphere === null ) {
  8511. this.boundingSphere = new Sphere();
  8512. }
  8513. this.boundingSphere.makeEmpty();
  8514. const positionAttribute = geometry.getAttribute( 'position' );
  8515. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8516. this.getVertexPosition( i, _vertex );
  8517. this.boundingSphere.expandByPoint( _vertex );
  8518. }
  8519. }
  8520. copy( source, recursive ) {
  8521. super.copy( source, recursive );
  8522. this.bindMode = source.bindMode;
  8523. this.bindMatrix.copy( source.bindMatrix );
  8524. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  8525. this.skeleton = source.skeleton;
  8526. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8527. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8528. return this;
  8529. }
  8530. raycast( raycaster, intersects ) {
  8531. const material = this.material;
  8532. const matrixWorld = this.matrixWorld;
  8533. if ( material === undefined ) return;
  8534. // test with bounding sphere in world space
  8535. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8536. _sphere$5.copy( this.boundingSphere );
  8537. _sphere$5.applyMatrix4( matrixWorld );
  8538. if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return;
  8539. // convert ray to local space of skinned mesh
  8540. _inverseMatrix$2.copy( matrixWorld ).invert();
  8541. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  8542. // test with bounding box in local space
  8543. if ( this.boundingBox !== null ) {
  8544. if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return;
  8545. }
  8546. // test for intersections with geometry
  8547. this._computeIntersections( raycaster, intersects, _ray$2 );
  8548. }
  8549. getVertexPosition( index, target ) {
  8550. super.getVertexPosition( index, target );
  8551. this.applyBoneTransform( index, target );
  8552. return target;
  8553. }
  8554. bind( skeleton, bindMatrix ) {
  8555. this.skeleton = skeleton;
  8556. if ( bindMatrix === undefined ) {
  8557. this.updateMatrixWorld( true );
  8558. this.skeleton.calculateInverses();
  8559. bindMatrix = this.matrixWorld;
  8560. }
  8561. this.bindMatrix.copy( bindMatrix );
  8562. this.bindMatrixInverse.copy( bindMatrix ).invert();
  8563. }
  8564. pose() {
  8565. this.skeleton.pose();
  8566. }
  8567. normalizeSkinWeights() {
  8568. const vector = new Vector4();
  8569. const skinWeight = this.geometry.attributes.skinWeight;
  8570. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  8571. vector.fromBufferAttribute( skinWeight, i );
  8572. const scale = 1.0 / vector.manhattanLength();
  8573. if ( scale !== Infinity ) {
  8574. vector.multiplyScalar( scale );
  8575. } else {
  8576. vector.set( 1, 0, 0, 0 ); // do something reasonable
  8577. }
  8578. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  8579. }
  8580. }
  8581. updateMatrixWorld( force ) {
  8582. super.updateMatrixWorld( force );
  8583. if ( this.bindMode === AttachedBindMode ) {
  8584. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  8585. } else if ( this.bindMode === DetachedBindMode ) {
  8586. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  8587. } else {
  8588. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  8589. }
  8590. }
  8591. applyBoneTransform( index, vector ) {
  8592. const skeleton = this.skeleton;
  8593. const geometry = this.geometry;
  8594. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  8595. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  8596. _basePosition.copy( vector ).applyMatrix4( this.bindMatrix );
  8597. vector.set( 0, 0, 0 );
  8598. for ( let i = 0; i < 4; i ++ ) {
  8599. const weight = _skinWeight.getComponent( i );
  8600. if ( weight !== 0 ) {
  8601. const boneIndex = _skinIndex.getComponent( i );
  8602. _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  8603. vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight );
  8604. }
  8605. }
  8606. return vector.applyMatrix4( this.bindMatrixInverse );
  8607. }
  8608. }
  8609. class Bone extends Object3D {
  8610. constructor() {
  8611. super();
  8612. this.isBone = true;
  8613. this.type = 'Bone';
  8614. }
  8615. }
  8616. class DataTexture extends Texture {
  8617. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  8618. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  8619. this.isDataTexture = true;
  8620. this.image = { data: data, width: width, height: height };
  8621. this.generateMipmaps = false;
  8622. this.flipY = false;
  8623. this.unpackAlignment = 1;
  8624. }
  8625. }
  8626. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  8627. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  8628. class Skeleton {
  8629. constructor( bones = [], boneInverses = [] ) {
  8630. this.uuid = generateUUID();
  8631. this.bones = bones.slice( 0 );
  8632. this.boneInverses = boneInverses;
  8633. this.boneMatrices = null;
  8634. this.boneTexture = null;
  8635. this.init();
  8636. }
  8637. init() {
  8638. const bones = this.bones;
  8639. const boneInverses = this.boneInverses;
  8640. this.boneMatrices = new Float32Array( bones.length * 16 );
  8641. // calculate inverse bone matrices if necessary
  8642. if ( boneInverses.length === 0 ) {
  8643. this.calculateInverses();
  8644. } else {
  8645. // handle special case
  8646. if ( bones.length !== boneInverses.length ) {
  8647. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  8648. this.boneInverses = [];
  8649. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8650. this.boneInverses.push( new Matrix4() );
  8651. }
  8652. }
  8653. }
  8654. }
  8655. calculateInverses() {
  8656. this.boneInverses.length = 0;
  8657. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8658. const inverse = new Matrix4();
  8659. if ( this.bones[ i ] ) {
  8660. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  8661. }
  8662. this.boneInverses.push( inverse );
  8663. }
  8664. }
  8665. pose() {
  8666. // recover the bind-time world matrices
  8667. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8668. const bone = this.bones[ i ];
  8669. if ( bone ) {
  8670. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  8671. }
  8672. }
  8673. // compute the local matrices, positions, rotations and scales
  8674. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8675. const bone = this.bones[ i ];
  8676. if ( bone ) {
  8677. if ( bone.parent && bone.parent.isBone ) {
  8678. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  8679. bone.matrix.multiply( bone.matrixWorld );
  8680. } else {
  8681. bone.matrix.copy( bone.matrixWorld );
  8682. }
  8683. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  8684. }
  8685. }
  8686. }
  8687. update() {
  8688. const bones = this.bones;
  8689. const boneInverses = this.boneInverses;
  8690. const boneMatrices = this.boneMatrices;
  8691. const boneTexture = this.boneTexture;
  8692. // flatten bone matrices to array
  8693. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  8694. // compute the offset between the current and the original transform
  8695. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  8696. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  8697. _offsetMatrix.toArray( boneMatrices, i * 16 );
  8698. }
  8699. if ( boneTexture !== null ) {
  8700. boneTexture.needsUpdate = true;
  8701. }
  8702. }
  8703. clone() {
  8704. return new Skeleton( this.bones, this.boneInverses );
  8705. }
  8706. computeBoneTexture() {
  8707. // layout (1 matrix = 4 pixels)
  8708. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  8709. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  8710. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  8711. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  8712. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  8713. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  8714. size = Math.ceil( size / 4 ) * 4;
  8715. size = Math.max( size, 4 );
  8716. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  8717. boneMatrices.set( this.boneMatrices ); // copy current values
  8718. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  8719. boneTexture.needsUpdate = true;
  8720. this.boneMatrices = boneMatrices;
  8721. this.boneTexture = boneTexture;
  8722. return this;
  8723. }
  8724. getBoneByName( name ) {
  8725. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8726. const bone = this.bones[ i ];
  8727. if ( bone.name === name ) {
  8728. return bone;
  8729. }
  8730. }
  8731. return undefined;
  8732. }
  8733. dispose( ) {
  8734. if ( this.boneTexture !== null ) {
  8735. this.boneTexture.dispose();
  8736. this.boneTexture = null;
  8737. }
  8738. }
  8739. fromJSON( json, bones ) {
  8740. this.uuid = json.uuid;
  8741. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  8742. const uuid = json.bones[ i ];
  8743. let bone = bones[ uuid ];
  8744. if ( bone === undefined ) {
  8745. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  8746. bone = new Bone();
  8747. }
  8748. this.bones.push( bone );
  8749. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  8750. }
  8751. this.init();
  8752. return this;
  8753. }
  8754. toJSON() {
  8755. const data = {
  8756. metadata: {
  8757. version: 4.6,
  8758. type: 'Skeleton',
  8759. generator: 'Skeleton.toJSON'
  8760. },
  8761. bones: [],
  8762. boneInverses: []
  8763. };
  8764. data.uuid = this.uuid;
  8765. const bones = this.bones;
  8766. const boneInverses = this.boneInverses;
  8767. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  8768. const bone = bones[ i ];
  8769. data.bones.push( bone.uuid );
  8770. const boneInverse = boneInverses[ i ];
  8771. data.boneInverses.push( boneInverse.toArray() );
  8772. }
  8773. return data;
  8774. }
  8775. }
  8776. class InstancedBufferAttribute extends BufferAttribute {
  8777. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  8778. super( array, itemSize, normalized );
  8779. this.isInstancedBufferAttribute = true;
  8780. this.meshPerAttribute = meshPerAttribute;
  8781. }
  8782. copy( source ) {
  8783. super.copy( source );
  8784. this.meshPerAttribute = source.meshPerAttribute;
  8785. return this;
  8786. }
  8787. toJSON() {
  8788. const data = super.toJSON();
  8789. data.meshPerAttribute = this.meshPerAttribute;
  8790. data.isInstancedBufferAttribute = true;
  8791. return data;
  8792. }
  8793. }
  8794. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  8795. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  8796. const _instanceIntersects = [];
  8797. const _box3 = /*@__PURE__*/ new Box3();
  8798. const _identity = /*@__PURE__*/ new Matrix4();
  8799. const _mesh$1 = /*@__PURE__*/ new Mesh();
  8800. const _sphere$4 = /*@__PURE__*/ new Sphere();
  8801. class InstancedMesh extends Mesh {
  8802. constructor( geometry, material, count ) {
  8803. super( geometry, material );
  8804. this.isInstancedMesh = true;
  8805. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  8806. this.instanceColor = null;
  8807. this.morphTexture = null;
  8808. this.count = count;
  8809. this.boundingBox = null;
  8810. this.boundingSphere = null;
  8811. for ( let i = 0; i < count; i ++ ) {
  8812. this.setMatrixAt( i, _identity );
  8813. }
  8814. }
  8815. computeBoundingBox() {
  8816. const geometry = this.geometry;
  8817. const count = this.count;
  8818. if ( this.boundingBox === null ) {
  8819. this.boundingBox = new Box3();
  8820. }
  8821. if ( geometry.boundingBox === null ) {
  8822. geometry.computeBoundingBox();
  8823. }
  8824. this.boundingBox.makeEmpty();
  8825. for ( let i = 0; i < count; i ++ ) {
  8826. this.getMatrixAt( i, _instanceLocalMatrix );
  8827. _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
  8828. this.boundingBox.union( _box3 );
  8829. }
  8830. }
  8831. computeBoundingSphere() {
  8832. const geometry = this.geometry;
  8833. const count = this.count;
  8834. if ( this.boundingSphere === null ) {
  8835. this.boundingSphere = new Sphere();
  8836. }
  8837. if ( geometry.boundingSphere === null ) {
  8838. geometry.computeBoundingSphere();
  8839. }
  8840. this.boundingSphere.makeEmpty();
  8841. for ( let i = 0; i < count; i ++ ) {
  8842. this.getMatrixAt( i, _instanceLocalMatrix );
  8843. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
  8844. this.boundingSphere.union( _sphere$4 );
  8845. }
  8846. }
  8847. copy( source, recursive ) {
  8848. super.copy( source, recursive );
  8849. this.instanceMatrix.copy( source.instanceMatrix );
  8850. if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
  8851. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  8852. this.count = source.count;
  8853. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8854. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8855. return this;
  8856. }
  8857. getColorAt( index, color ) {
  8858. color.fromArray( this.instanceColor.array, index * 3 );
  8859. }
  8860. getMatrixAt( index, matrix ) {
  8861. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  8862. }
  8863. getMorphAt( index, object ) {
  8864. const objectInfluences = object.morphTargetInfluences;
  8865. const array = this.morphTexture.source.data.data;
  8866. const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
  8867. const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
  8868. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8869. objectInfluences[ i ] = array[ dataIndex + i ];
  8870. }
  8871. }
  8872. raycast( raycaster, intersects ) {
  8873. const matrixWorld = this.matrixWorld;
  8874. const raycastTimes = this.count;
  8875. _mesh$1.geometry = this.geometry;
  8876. _mesh$1.material = this.material;
  8877. if ( _mesh$1.material === undefined ) return;
  8878. // test with bounding sphere first
  8879. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8880. _sphere$4.copy( this.boundingSphere );
  8881. _sphere$4.applyMatrix4( matrixWorld );
  8882. if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return;
  8883. // now test each instance
  8884. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  8885. // calculate the world matrix for each instance
  8886. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  8887. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  8888. // the mesh represents this single instance
  8889. _mesh$1.matrixWorld = _instanceWorldMatrix;
  8890. _mesh$1.raycast( raycaster, _instanceIntersects );
  8891. // process the result of raycast
  8892. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  8893. const intersect = _instanceIntersects[ i ];
  8894. intersect.instanceId = instanceId;
  8895. intersect.object = this;
  8896. intersects.push( intersect );
  8897. }
  8898. _instanceIntersects.length = 0;
  8899. }
  8900. }
  8901. setColorAt( index, color ) {
  8902. if ( this.instanceColor === null ) {
  8903. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 );
  8904. }
  8905. color.toArray( this.instanceColor.array, index * 3 );
  8906. }
  8907. setMatrixAt( index, matrix ) {
  8908. matrix.toArray( this.instanceMatrix.array, index * 16 );
  8909. }
  8910. setMorphAt( index, object ) {
  8911. const objectInfluences = object.morphTargetInfluences;
  8912. const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
  8913. if ( this.morphTexture === null ) {
  8914. this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
  8915. }
  8916. const array = this.morphTexture.source.data.data;
  8917. let morphInfluencesSum = 0;
  8918. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8919. morphInfluencesSum += objectInfluences[ i ];
  8920. }
  8921. const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  8922. const dataIndex = len * index;
  8923. array[ dataIndex ] = morphBaseInfluence;
  8924. array.set( objectInfluences, dataIndex + 1 );
  8925. }
  8926. updateMorphTargets() {
  8927. }
  8928. dispose() {
  8929. this.dispatchEvent( { type: 'dispose' } );
  8930. if ( this.morphTexture !== null ) {
  8931. this.morphTexture.dispose();
  8932. this.morphTexture = null;
  8933. }
  8934. return this;
  8935. }
  8936. }
  8937. const _vector1 = /*@__PURE__*/ new Vector3();
  8938. const _vector2 = /*@__PURE__*/ new Vector3();
  8939. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  8940. class Plane {
  8941. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  8942. this.isPlane = true;
  8943. // normal is assumed to be normalized
  8944. this.normal = normal;
  8945. this.constant = constant;
  8946. }
  8947. set( normal, constant ) {
  8948. this.normal.copy( normal );
  8949. this.constant = constant;
  8950. return this;
  8951. }
  8952. setComponents( x, y, z, w ) {
  8953. this.normal.set( x, y, z );
  8954. this.constant = w;
  8955. return this;
  8956. }
  8957. setFromNormalAndCoplanarPoint( normal, point ) {
  8958. this.normal.copy( normal );
  8959. this.constant = - point.dot( this.normal );
  8960. return this;
  8961. }
  8962. setFromCoplanarPoints( a, b, c ) {
  8963. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8964. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8965. this.setFromNormalAndCoplanarPoint( normal, a );
  8966. return this;
  8967. }
  8968. copy( plane ) {
  8969. this.normal.copy( plane.normal );
  8970. this.constant = plane.constant;
  8971. return this;
  8972. }
  8973. normalize() {
  8974. // Note: will lead to a divide by zero if the plane is invalid.
  8975. const inverseNormalLength = 1.0 / this.normal.length();
  8976. this.normal.multiplyScalar( inverseNormalLength );
  8977. this.constant *= inverseNormalLength;
  8978. return this;
  8979. }
  8980. negate() {
  8981. this.constant *= - 1;
  8982. this.normal.negate();
  8983. return this;
  8984. }
  8985. distanceToPoint( point ) {
  8986. return this.normal.dot( point ) + this.constant;
  8987. }
  8988. distanceToSphere( sphere ) {
  8989. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8990. }
  8991. projectPoint( point, target ) {
  8992. return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );
  8993. }
  8994. intersectLine( line, target ) {
  8995. const direction = line.delta( _vector1 );
  8996. const denominator = this.normal.dot( direction );
  8997. if ( denominator === 0 ) {
  8998. // line is coplanar, return origin
  8999. if ( this.distanceToPoint( line.start ) === 0 ) {
  9000. return target.copy( line.start );
  9001. }
  9002. // Unsure if this is the correct method to handle this case.
  9003. return null;
  9004. }
  9005. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9006. if ( t < 0 || t > 1 ) {
  9007. return null;
  9008. }
  9009. return target.copy( line.start ).addScaledVector( direction, t );
  9010. }
  9011. intersectsLine( line ) {
  9012. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9013. const startSign = this.distanceToPoint( line.start );
  9014. const endSign = this.distanceToPoint( line.end );
  9015. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9016. }
  9017. intersectsBox( box ) {
  9018. return box.intersectsPlane( this );
  9019. }
  9020. intersectsSphere( sphere ) {
  9021. return sphere.intersectsPlane( this );
  9022. }
  9023. coplanarPoint( target ) {
  9024. return target.copy( this.normal ).multiplyScalar( - this.constant );
  9025. }
  9026. applyMatrix4( matrix, optionalNormalMatrix ) {
  9027. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  9028. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  9029. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9030. this.constant = - referencePoint.dot( normal );
  9031. return this;
  9032. }
  9033. translate( offset ) {
  9034. this.constant -= offset.dot( this.normal );
  9035. return this;
  9036. }
  9037. equals( plane ) {
  9038. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9039. }
  9040. clone() {
  9041. return new this.constructor().copy( this );
  9042. }
  9043. }
  9044. const _sphere$3 = /*@__PURE__*/ new Sphere();
  9045. const _vector$6 = /*@__PURE__*/ new Vector3();
  9046. class Frustum {
  9047. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  9048. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  9049. }
  9050. set( p0, p1, p2, p3, p4, p5 ) {
  9051. const planes = this.planes;
  9052. planes[ 0 ].copy( p0 );
  9053. planes[ 1 ].copy( p1 );
  9054. planes[ 2 ].copy( p2 );
  9055. planes[ 3 ].copy( p3 );
  9056. planes[ 4 ].copy( p4 );
  9057. planes[ 5 ].copy( p5 );
  9058. return this;
  9059. }
  9060. copy( frustum ) {
  9061. const planes = this.planes;
  9062. for ( let i = 0; i < 6; i ++ ) {
  9063. planes[ i ].copy( frustum.planes[ i ] );
  9064. }
  9065. return this;
  9066. }
  9067. setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
  9068. const planes = this.planes;
  9069. const me = m.elements;
  9070. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  9071. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  9072. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  9073. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  9074. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  9075. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  9076. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  9077. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  9078. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  9079. if ( coordinateSystem === WebGLCoordinateSystem ) {
  9080. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  9081. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  9082. planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
  9083. } else {
  9084. throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
  9085. }
  9086. return this;
  9087. }
  9088. intersectsObject( object ) {
  9089. if ( object.boundingSphere !== undefined ) {
  9090. if ( object.boundingSphere === null ) object.computeBoundingSphere();
  9091. _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );
  9092. } else {
  9093. const geometry = object.geometry;
  9094. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9095. _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  9096. }
  9097. return this.intersectsSphere( _sphere$3 );
  9098. }
  9099. intersectsSprite( sprite ) {
  9100. _sphere$3.center.set( 0, 0, 0 );
  9101. _sphere$3.radius = 0.7071067811865476;
  9102. _sphere$3.applyMatrix4( sprite.matrixWorld );
  9103. return this.intersectsSphere( _sphere$3 );
  9104. }
  9105. intersectsSphere( sphere ) {
  9106. const planes = this.planes;
  9107. const center = sphere.center;
  9108. const negRadius = - sphere.radius;
  9109. for ( let i = 0; i < 6; i ++ ) {
  9110. const distance = planes[ i ].distanceToPoint( center );
  9111. if ( distance < negRadius ) {
  9112. return false;
  9113. }
  9114. }
  9115. return true;
  9116. }
  9117. intersectsBox( box ) {
  9118. const planes = this.planes;
  9119. for ( let i = 0; i < 6; i ++ ) {
  9120. const plane = planes[ i ];
  9121. // corner at max distance
  9122. _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  9123. _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  9124. _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  9125. if ( plane.distanceToPoint( _vector$6 ) < 0 ) {
  9126. return false;
  9127. }
  9128. }
  9129. return true;
  9130. }
  9131. containsPoint( point ) {
  9132. const planes = this.planes;
  9133. for ( let i = 0; i < 6; i ++ ) {
  9134. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  9135. return false;
  9136. }
  9137. }
  9138. return true;
  9139. }
  9140. clone() {
  9141. return new this.constructor().copy( this );
  9142. }
  9143. }
  9144. function ascIdSort( a, b ) {
  9145. return a - b;
  9146. }
  9147. function sortOpaque( a, b ) {
  9148. return a.z - b.z;
  9149. }
  9150. function sortTransparent( a, b ) {
  9151. return b.z - a.z;
  9152. }
  9153. class MultiDrawRenderList {
  9154. constructor() {
  9155. this.index = 0;
  9156. this.pool = [];
  9157. this.list = [];
  9158. }
  9159. push( start, count, z, index ) {
  9160. const pool = this.pool;
  9161. const list = this.list;
  9162. if ( this.index >= pool.length ) {
  9163. pool.push( {
  9164. start: - 1,
  9165. count: - 1,
  9166. z: - 1,
  9167. index: - 1,
  9168. } );
  9169. }
  9170. const item = pool[ this.index ];
  9171. list.push( item );
  9172. this.index ++;
  9173. item.start = start;
  9174. item.count = count;
  9175. item.z = z;
  9176. item.index = index;
  9177. }
  9178. reset() {
  9179. this.list.length = 0;
  9180. this.index = 0;
  9181. }
  9182. }
  9183. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  9184. const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
  9185. const _frustum = /*@__PURE__*/ new Frustum();
  9186. const _box$1 = /*@__PURE__*/ new Box3();
  9187. const _sphere$2 = /*@__PURE__*/ new Sphere();
  9188. const _vector$5 = /*@__PURE__*/ new Vector3();
  9189. const _forward = /*@__PURE__*/ new Vector3();
  9190. const _temp = /*@__PURE__*/ new Vector3();
  9191. const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
  9192. const _mesh = /*@__PURE__*/ new Mesh();
  9193. const _batchIntersects = [];
  9194. // copies data from attribute "src" into "target" starting at "targetOffset"
  9195. function copyAttributeData( src, target, targetOffset = 0 ) {
  9196. const itemSize = target.itemSize;
  9197. if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
  9198. // use the component getters and setters if the array data cannot
  9199. // be copied directly
  9200. const vertexCount = src.count;
  9201. for ( let i = 0; i < vertexCount; i ++ ) {
  9202. for ( let c = 0; c < itemSize; c ++ ) {
  9203. target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
  9204. }
  9205. }
  9206. } else {
  9207. // faster copy approach using typed array set function
  9208. target.array.set( src.array, targetOffset * itemSize );
  9209. }
  9210. target.needsUpdate = true;
  9211. }
  9212. // safely copies array contents to a potentially smaller array
  9213. function copyArrayContents( src, target ) {
  9214. if ( src.constructor !== target.constructor ) {
  9215. // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
  9216. const len = Math.min( src.length, target.length );
  9217. for ( let i = 0; i < len; i ++ ) {
  9218. target[ i ] = src[ i ];
  9219. }
  9220. } else {
  9221. // if the arrays use the same data layout we can use a fast block copy
  9222. const len = Math.min( src.length, target.length );
  9223. target.set( new src.constructor( src.buffer, 0, len ) );
  9224. }
  9225. }
  9226. class BatchedMesh extends Mesh {
  9227. get maxInstanceCount() {
  9228. return this._maxInstanceCount;
  9229. }
  9230. get instanceCount() {
  9231. return this._instanceInfo.length - this._availableInstanceIds.length;
  9232. }
  9233. get unusedVertexCount() {
  9234. return this._maxVertexCount - this._nextVertexStart;
  9235. }
  9236. get unusedIndexCount() {
  9237. return this._maxIndexCount - this._nextIndexStart;
  9238. }
  9239. constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
  9240. super( new BufferGeometry(), material );
  9241. this.isBatchedMesh = true;
  9242. this.perObjectFrustumCulled = true;
  9243. this.sortObjects = true;
  9244. this.boundingBox = null;
  9245. this.boundingSphere = null;
  9246. this.customSort = null;
  9247. // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
  9248. this._instanceInfo = [];
  9249. this._geometryInfo = [];
  9250. // instance, geometry ids that have been set as inactive, and are available to be overwritten
  9251. this._availableInstanceIds = [];
  9252. this._availableGeometryIds = [];
  9253. // used to track where the next point is that geometry should be inserted
  9254. this._nextIndexStart = 0;
  9255. this._nextVertexStart = 0;
  9256. this._geometryCount = 0;
  9257. // flags
  9258. this._visibilityChanged = true;
  9259. this._geometryInitialized = false;
  9260. // cached user options
  9261. this._maxInstanceCount = maxInstanceCount;
  9262. this._maxVertexCount = maxVertexCount;
  9263. this._maxIndexCount = maxIndexCount;
  9264. // buffers for multi draw
  9265. this._multiDrawCounts = new Int32Array( maxInstanceCount );
  9266. this._multiDrawStarts = new Int32Array( maxInstanceCount );
  9267. this._multiDrawCount = 0;
  9268. this._multiDrawInstances = null;
  9269. // Local matrix per geometry by using data texture
  9270. this._matricesTexture = null;
  9271. this._indirectTexture = null;
  9272. this._colorsTexture = null;
  9273. this._initMatricesTexture();
  9274. this._initIndirectTexture();
  9275. }
  9276. _initMatricesTexture() {
  9277. // layout (1 matrix = 4 pixels)
  9278. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9279. // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
  9280. // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
  9281. // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
  9282. // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
  9283. let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix
  9284. size = Math.ceil( size / 4 ) * 4;
  9285. size = Math.max( size, 4 );
  9286. const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  9287. const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
  9288. this._matricesTexture = matricesTexture;
  9289. }
  9290. _initIndirectTexture() {
  9291. let size = Math.sqrt( this._maxInstanceCount );
  9292. size = Math.ceil( size );
  9293. const indirectArray = new Uint32Array( size * size );
  9294. const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType );
  9295. this._indirectTexture = indirectTexture;
  9296. }
  9297. _initColorsTexture() {
  9298. let size = Math.sqrt( this._maxInstanceCount );
  9299. size = Math.ceil( size );
  9300. // 4 floats per RGBA pixel initialized to white
  9301. const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
  9302. const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
  9303. colorsTexture.colorSpace = ColorManagement.workingColorSpace;
  9304. this._colorsTexture = colorsTexture;
  9305. }
  9306. _initializeGeometry( reference ) {
  9307. const geometry = this.geometry;
  9308. const maxVertexCount = this._maxVertexCount;
  9309. const maxIndexCount = this._maxIndexCount;
  9310. if ( this._geometryInitialized === false ) {
  9311. for ( const attributeName in reference.attributes ) {
  9312. const srcAttribute = reference.getAttribute( attributeName );
  9313. const { array, itemSize, normalized } = srcAttribute;
  9314. const dstArray = new array.constructor( maxVertexCount * itemSize );
  9315. const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized );
  9316. geometry.setAttribute( attributeName, dstAttribute );
  9317. }
  9318. if ( reference.getIndex() !== null ) {
  9319. // Reserve last u16 index for primitive restart.
  9320. const indexArray = maxVertexCount > 65535
  9321. ? new Uint32Array( maxIndexCount )
  9322. : new Uint16Array( maxIndexCount );
  9323. geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
  9324. }
  9325. this._geometryInitialized = true;
  9326. }
  9327. }
  9328. // Make sure the geometry is compatible with the existing combined geometry attributes
  9329. _validateGeometry( geometry ) {
  9330. // check to ensure the geometries are using consistent attributes and indices
  9331. const batchGeometry = this.geometry;
  9332. if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
  9333. throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
  9334. }
  9335. for ( const attributeName in batchGeometry.attributes ) {
  9336. if ( ! geometry.hasAttribute( attributeName ) ) {
  9337. throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
  9338. }
  9339. const srcAttribute = geometry.getAttribute( attributeName );
  9340. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9341. if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
  9342. throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
  9343. }
  9344. }
  9345. }
  9346. validateInstanceId( instanceId ) {
  9347. const instanceInfo = this._instanceInfo;
  9348. if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
  9349. throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
  9350. }
  9351. }
  9352. validateGeometryId( geometryId ) {
  9353. const geometryInfoList = this._geometryInfo;
  9354. if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9355. throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
  9356. }
  9357. }
  9358. setCustomSort( func ) {
  9359. this.customSort = func;
  9360. return this;
  9361. }
  9362. computeBoundingBox() {
  9363. if ( this.boundingBox === null ) {
  9364. this.boundingBox = new Box3();
  9365. }
  9366. const boundingBox = this.boundingBox;
  9367. const instanceInfo = this._instanceInfo;
  9368. boundingBox.makeEmpty();
  9369. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9370. if ( instanceInfo[ i ].active === false ) continue;
  9371. const geometryId = instanceInfo[ i ].geometryIndex;
  9372. this.getMatrixAt( i, _matrix$1 );
  9373. this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
  9374. boundingBox.union( _box$1 );
  9375. }
  9376. }
  9377. computeBoundingSphere() {
  9378. if ( this.boundingSphere === null ) {
  9379. this.boundingSphere = new Sphere();
  9380. }
  9381. const boundingSphere = this.boundingSphere;
  9382. const instanceInfo = this._instanceInfo;
  9383. boundingSphere.makeEmpty();
  9384. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9385. if ( instanceInfo[ i ].active === false ) continue;
  9386. const geometryId = instanceInfo[ i ].geometryIndex;
  9387. this.getMatrixAt( i, _matrix$1 );
  9388. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9389. boundingSphere.union( _sphere$2 );
  9390. }
  9391. }
  9392. addInstance( geometryId ) {
  9393. const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
  9394. // ensure we're not over geometry
  9395. if ( atCapacity && this._availableInstanceIds.length === 0 ) {
  9396. throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
  9397. }
  9398. const instanceInfo = {
  9399. visible: true,
  9400. active: true,
  9401. geometryIndex: geometryId,
  9402. };
  9403. let drawId = null;
  9404. // Prioritize using previously freed instance ids
  9405. if ( this._availableInstanceIds.length > 0 ) {
  9406. this._availableInstanceIds.sort( ascIdSort );
  9407. drawId = this._availableInstanceIds.shift();
  9408. this._instanceInfo[ drawId ] = instanceInfo;
  9409. } else {
  9410. drawId = this._instanceInfo.length;
  9411. this._instanceInfo.push( instanceInfo );
  9412. }
  9413. const matricesTexture = this._matricesTexture;
  9414. _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
  9415. matricesTexture.needsUpdate = true;
  9416. const colorsTexture = this._colorsTexture;
  9417. if ( colorsTexture ) {
  9418. _whiteColor.toArray( colorsTexture.image.data, drawId * 4 );
  9419. colorsTexture.needsUpdate = true;
  9420. }
  9421. this._visibilityChanged = true;
  9422. return drawId;
  9423. }
  9424. addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
  9425. this._initializeGeometry( geometry );
  9426. this._validateGeometry( geometry );
  9427. const geometryInfo = {
  9428. // geometry information
  9429. vertexStart: - 1,
  9430. vertexCount: - 1,
  9431. reservedVertexCount: - 1,
  9432. indexStart: - 1,
  9433. indexCount: - 1,
  9434. reservedIndexCount: - 1,
  9435. // draw range information
  9436. start: - 1,
  9437. count: - 1,
  9438. // state
  9439. boundingBox: null,
  9440. boundingSphere: null,
  9441. active: true,
  9442. };
  9443. const geometryInfoList = this._geometryInfo;
  9444. geometryInfo.vertexStart = this._nextVertexStart;
  9445. geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
  9446. const index = geometry.getIndex();
  9447. const hasIndex = index !== null;
  9448. if ( hasIndex ) {
  9449. geometryInfo.indexStart = this._nextIndexStart;
  9450. geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
  9451. }
  9452. if (
  9453. geometryInfo.indexStart !== - 1 &&
  9454. geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
  9455. geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
  9456. ) {
  9457. throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
  9458. }
  9459. // update id
  9460. let geometryId;
  9461. if ( this._availableGeometryIds.length > 0 ) {
  9462. this._availableGeometryIds.sort( ascIdSort );
  9463. geometryId = this._availableGeometryIds.shift();
  9464. geometryInfoList[ geometryId ] = geometryInfo;
  9465. } else {
  9466. geometryId = this._geometryCount;
  9467. this._geometryCount ++;
  9468. geometryInfoList.push( geometryInfo );
  9469. }
  9470. // update the geometry
  9471. this.setGeometryAt( geometryId, geometry );
  9472. // increment the next geometry position
  9473. this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
  9474. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9475. return geometryId;
  9476. }
  9477. setGeometryAt( geometryId, geometry ) {
  9478. if ( geometryId >= this._geometryCount ) {
  9479. throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
  9480. }
  9481. this._validateGeometry( geometry );
  9482. const batchGeometry = this.geometry;
  9483. const hasIndex = batchGeometry.getIndex() !== null;
  9484. const dstIndex = batchGeometry.getIndex();
  9485. const srcIndex = geometry.getIndex();
  9486. const geometryInfo = this._geometryInfo[ geometryId ];
  9487. if (
  9488. hasIndex &&
  9489. srcIndex.count > geometryInfo.reservedIndexCount ||
  9490. geometry.attributes.position.count > geometryInfo.reservedVertexCount
  9491. ) {
  9492. throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
  9493. }
  9494. // copy geometry buffer data over
  9495. const vertexStart = geometryInfo.vertexStart;
  9496. const reservedVertexCount = geometryInfo.reservedVertexCount;
  9497. geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
  9498. for ( const attributeName in batchGeometry.attributes ) {
  9499. // copy attribute data
  9500. const srcAttribute = geometry.getAttribute( attributeName );
  9501. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9502. copyAttributeData( srcAttribute, dstAttribute, vertexStart );
  9503. // fill the rest in with zeroes
  9504. const itemSize = srcAttribute.itemSize;
  9505. for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
  9506. const index = vertexStart + i;
  9507. for ( let c = 0; c < itemSize; c ++ ) {
  9508. dstAttribute.setComponent( index, c, 0 );
  9509. }
  9510. }
  9511. dstAttribute.needsUpdate = true;
  9512. dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
  9513. }
  9514. // copy index
  9515. if ( hasIndex ) {
  9516. const indexStart = geometryInfo.indexStart;
  9517. const reservedIndexCount = geometryInfo.reservedIndexCount;
  9518. geometryInfo.indexCount = geometry.getIndex().count;
  9519. // copy index data over
  9520. for ( let i = 0; i < srcIndex.count; i ++ ) {
  9521. dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) );
  9522. }
  9523. // fill the rest in with zeroes
  9524. for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
  9525. dstIndex.setX( indexStart + i, vertexStart );
  9526. }
  9527. dstIndex.needsUpdate = true;
  9528. dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
  9529. }
  9530. // update the draw range
  9531. geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9532. geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
  9533. // store the bounding boxes
  9534. geometryInfo.boundingBox = null;
  9535. if ( geometry.boundingBox !== null ) {
  9536. geometryInfo.boundingBox = geometry.boundingBox.clone();
  9537. }
  9538. geometryInfo.boundingSphere = null;
  9539. if ( geometry.boundingSphere !== null ) {
  9540. geometryInfo.boundingSphere = geometry.boundingSphere.clone();
  9541. }
  9542. this._visibilityChanged = true;
  9543. return geometryId;
  9544. }
  9545. deleteGeometry( geometryId ) {
  9546. const geometryInfoList = this._geometryInfo;
  9547. if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9548. return this;
  9549. }
  9550. // delete any instances associated with this geometry
  9551. const instanceInfo = this._instanceInfo;
  9552. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9553. if ( instanceInfo[ i ].geometryIndex === geometryId ) {
  9554. this.deleteInstance( i );
  9555. }
  9556. }
  9557. geometryInfoList[ geometryId ].active = false;
  9558. this._availableGeometryIds.push( geometryId );
  9559. this._visibilityChanged = true;
  9560. return this;
  9561. }
  9562. deleteInstance( instanceId ) {
  9563. this.validateInstanceId( instanceId );
  9564. this._instanceInfo[ instanceId ].active = false;
  9565. this._availableInstanceIds.push( instanceId );
  9566. this._visibilityChanged = true;
  9567. return this;
  9568. }
  9569. optimize() {
  9570. // track the next indices to copy data to
  9571. let nextVertexStart = 0;
  9572. let nextIndexStart = 0;
  9573. // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
  9574. // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
  9575. const geometryInfoList = this._geometryInfo;
  9576. const indices = geometryInfoList
  9577. .map( ( e, i ) => i )
  9578. .sort( ( a, b ) => {
  9579. return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
  9580. } );
  9581. const geometry = this.geometry;
  9582. for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
  9583. // if a geometry range is inactive then don't copy anything
  9584. const index = indices[ i ];
  9585. const geometryInfo = geometryInfoList[ index ];
  9586. if ( geometryInfo.active === false ) {
  9587. continue;
  9588. }
  9589. // if a geometry contains an index buffer then shift it, as well
  9590. if ( geometry.index !== null ) {
  9591. if ( geometryInfo.indexStart !== nextIndexStart ) {
  9592. const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
  9593. const index = geometry.index;
  9594. const array = index.array;
  9595. // shift the index pointers based on how the vertex data will shift
  9596. // adjusting the index must happen first so the original vertex start value is available
  9597. const elementDelta = nextVertexStart - vertexStart;
  9598. for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
  9599. array[ j ] = array[ j ] + elementDelta;
  9600. }
  9601. index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
  9602. index.addUpdateRange( nextIndexStart, reservedIndexCount );
  9603. geometryInfo.indexStart = nextIndexStart;
  9604. }
  9605. nextIndexStart += geometryInfo.reservedIndexCount;
  9606. }
  9607. // if a geometry needs to be moved then copy attribute data to overwrite unused space
  9608. if ( geometryInfo.vertexStart !== nextVertexStart ) {
  9609. const { vertexStart, reservedVertexCount } = geometryInfo;
  9610. const attributes = geometry.attributes;
  9611. for ( const key in attributes ) {
  9612. const attribute = attributes[ key ];
  9613. const { array, itemSize } = attribute;
  9614. array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
  9615. attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
  9616. }
  9617. geometryInfo.vertexStart = nextVertexStart;
  9618. }
  9619. nextVertexStart += geometryInfo.reservedVertexCount;
  9620. geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9621. // step the next geometry points to the shifted position
  9622. this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
  9623. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9624. }
  9625. return this;
  9626. }
  9627. // get bounding box and compute it if it doesn't exist
  9628. getBoundingBoxAt( geometryId, target ) {
  9629. if ( geometryId >= this._geometryCount ) {
  9630. return null;
  9631. }
  9632. // compute bounding box
  9633. const geometry = this.geometry;
  9634. const geometryInfo = this._geometryInfo[ geometryId ];
  9635. if ( geometryInfo.boundingBox === null ) {
  9636. const box = new Box3();
  9637. const index = geometry.index;
  9638. const position = geometry.attributes.position;
  9639. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9640. let iv = i;
  9641. if ( index ) {
  9642. iv = index.getX( iv );
  9643. }
  9644. box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) );
  9645. }
  9646. geometryInfo.boundingBox = box;
  9647. }
  9648. target.copy( geometryInfo.boundingBox );
  9649. return target;
  9650. }
  9651. // get bounding sphere and compute it if it doesn't exist
  9652. getBoundingSphereAt( geometryId, target ) {
  9653. if ( geometryId >= this._geometryCount ) {
  9654. return null;
  9655. }
  9656. // compute bounding sphere
  9657. const geometry = this.geometry;
  9658. const geometryInfo = this._geometryInfo[ geometryId ];
  9659. if ( geometryInfo.boundingSphere === null ) {
  9660. const sphere = new Sphere();
  9661. this.getBoundingBoxAt( geometryId, _box$1 );
  9662. _box$1.getCenter( sphere.center );
  9663. const index = geometry.index;
  9664. const position = geometry.attributes.position;
  9665. let maxRadiusSq = 0;
  9666. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9667. let iv = i;
  9668. if ( index ) {
  9669. iv = index.getX( iv );
  9670. }
  9671. _vector$5.fromBufferAttribute( position, iv );
  9672. maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) );
  9673. }
  9674. sphere.radius = Math.sqrt( maxRadiusSq );
  9675. geometryInfo.boundingSphere = sphere;
  9676. }
  9677. target.copy( geometryInfo.boundingSphere );
  9678. return target;
  9679. }
  9680. setMatrixAt( instanceId, matrix ) {
  9681. this.validateInstanceId( instanceId );
  9682. const matricesTexture = this._matricesTexture;
  9683. const matricesArray = this._matricesTexture.image.data;
  9684. matrix.toArray( matricesArray, instanceId * 16 );
  9685. matricesTexture.needsUpdate = true;
  9686. return this;
  9687. }
  9688. getMatrixAt( instanceId, matrix ) {
  9689. this.validateInstanceId( instanceId );
  9690. return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
  9691. }
  9692. setColorAt( instanceId, color ) {
  9693. this.validateInstanceId( instanceId );
  9694. if ( this._colorsTexture === null ) {
  9695. this._initColorsTexture();
  9696. }
  9697. color.toArray( this._colorsTexture.image.data, instanceId * 4 );
  9698. this._colorsTexture.needsUpdate = true;
  9699. return this;
  9700. }
  9701. getColorAt( instanceId, color ) {
  9702. this.validateInstanceId( instanceId );
  9703. return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
  9704. }
  9705. setVisibleAt( instanceId, value ) {
  9706. this.validateInstanceId( instanceId );
  9707. if ( this._instanceInfo[ instanceId ].visible === value ) {
  9708. return this;
  9709. }
  9710. this._instanceInfo[ instanceId ].visible = value;
  9711. this._visibilityChanged = true;
  9712. return this;
  9713. }
  9714. getVisibleAt( instanceId ) {
  9715. this.validateInstanceId( instanceId );
  9716. return this._instanceInfo[ instanceId ].visible;
  9717. }
  9718. setGeometryIdAt( instanceId, geometryId ) {
  9719. this.validateInstanceId( instanceId );
  9720. this.validateGeometryId( geometryId );
  9721. this._instanceInfo[ instanceId ].geometryIndex = geometryId;
  9722. return this;
  9723. }
  9724. getGeometryIdAt( instanceId ) {
  9725. this.validateInstanceId( instanceId );
  9726. return this._instanceInfo[ instanceId ].geometryIndex;
  9727. }
  9728. getGeometryRangeAt( geometryId, target = {} ) {
  9729. this.validateGeometryId( geometryId );
  9730. const geometryInfo = this._geometryInfo[ geometryId ];
  9731. target.vertexStart = geometryInfo.vertexStart;
  9732. target.vertexCount = geometryInfo.vertexCount;
  9733. target.reservedVertexCount = geometryInfo.reservedVertexCount;
  9734. target.indexStart = geometryInfo.indexStart;
  9735. target.indexCount = geometryInfo.indexCount;
  9736. target.reservedIndexCount = geometryInfo.reservedIndexCount;
  9737. target.start = geometryInfo.start;
  9738. target.count = geometryInfo.count;
  9739. return target;
  9740. }
  9741. setInstanceCount( maxInstanceCount ) {
  9742. // shrink the available instances as much as possible
  9743. const availableInstanceIds = this._availableInstanceIds;
  9744. const instanceInfo = this._instanceInfo;
  9745. availableInstanceIds.sort( ascIdSort );
  9746. while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
  9747. instanceInfo.pop();
  9748. availableInstanceIds.pop();
  9749. }
  9750. // throw an error if it can't be shrunk to the desired size
  9751. if ( maxInstanceCount < instanceInfo.length ) {
  9752. throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
  9753. }
  9754. // copy the multi draw counts
  9755. const multiDrawCounts = new Int32Array( maxInstanceCount );
  9756. const multiDrawStarts = new Int32Array( maxInstanceCount );
  9757. copyArrayContents( this._multiDrawCounts, multiDrawCounts );
  9758. copyArrayContents( this._multiDrawStarts, multiDrawStarts );
  9759. this._multiDrawCounts = multiDrawCounts;
  9760. this._multiDrawStarts = multiDrawStarts;
  9761. this._maxInstanceCount = maxInstanceCount;
  9762. // update texture data for instance sampling
  9763. const indirectTexture = this._indirectTexture;
  9764. const matricesTexture = this._matricesTexture;
  9765. const colorsTexture = this._colorsTexture;
  9766. indirectTexture.dispose();
  9767. this._initIndirectTexture();
  9768. copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
  9769. matricesTexture.dispose();
  9770. this._initMatricesTexture();
  9771. copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
  9772. if ( colorsTexture ) {
  9773. colorsTexture.dispose();
  9774. this._initColorsTexture();
  9775. copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
  9776. }
  9777. }
  9778. setGeometrySize( maxVertexCount, maxIndexCount ) {
  9779. // Check if we can shrink to the requested vertex attribute size
  9780. const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
  9781. const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
  9782. if ( requiredVertexLength > maxVertexCount ) {
  9783. throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9784. }
  9785. // Check if we can shrink to the requested index attribute size
  9786. if ( this.geometry.index ) {
  9787. const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
  9788. if ( requiredIndexLength > maxIndexCount ) {
  9789. throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9790. }
  9791. }
  9792. //
  9793. // dispose of the previous geometry
  9794. const oldGeometry = this.geometry;
  9795. oldGeometry.dispose();
  9796. // recreate the geometry needed based on the previous variant
  9797. this._maxVertexCount = maxVertexCount;
  9798. this._maxIndexCount = maxIndexCount;
  9799. if ( this._geometryInitialized ) {
  9800. this._geometryInitialized = false;
  9801. this.geometry = new BufferGeometry();
  9802. this._initializeGeometry( oldGeometry );
  9803. }
  9804. // copy data from the previous geometry
  9805. const geometry = this.geometry;
  9806. if ( oldGeometry.index ) {
  9807. copyArrayContents( oldGeometry.index.array, geometry.index.array );
  9808. }
  9809. for ( const key in oldGeometry.attributes ) {
  9810. copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
  9811. }
  9812. }
  9813. raycast( raycaster, intersects ) {
  9814. const instanceInfo = this._instanceInfo;
  9815. const geometryInfoList = this._geometryInfo;
  9816. const matrixWorld = this.matrixWorld;
  9817. const batchGeometry = this.geometry;
  9818. // iterate over each geometry
  9819. _mesh.material = this.material;
  9820. _mesh.geometry.index = batchGeometry.index;
  9821. _mesh.geometry.attributes = batchGeometry.attributes;
  9822. if ( _mesh.geometry.boundingBox === null ) {
  9823. _mesh.geometry.boundingBox = new Box3();
  9824. }
  9825. if ( _mesh.geometry.boundingSphere === null ) {
  9826. _mesh.geometry.boundingSphere = new Sphere();
  9827. }
  9828. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9829. if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
  9830. continue;
  9831. }
  9832. const geometryId = instanceInfo[ i ].geometryIndex;
  9833. const geometryInfo = geometryInfoList[ geometryId ];
  9834. _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
  9835. // get the intersects
  9836. this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
  9837. this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
  9838. this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
  9839. _mesh.raycast( raycaster, _batchIntersects );
  9840. // add batch id to the intersects
  9841. for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) {
  9842. const intersect = _batchIntersects[ j ];
  9843. intersect.object = this;
  9844. intersect.batchId = i;
  9845. intersects.push( intersect );
  9846. }
  9847. _batchIntersects.length = 0;
  9848. }
  9849. _mesh.material = null;
  9850. _mesh.geometry.index = null;
  9851. _mesh.geometry.attributes = {};
  9852. _mesh.geometry.setDrawRange( 0, Infinity );
  9853. }
  9854. copy( source ) {
  9855. super.copy( source );
  9856. this.geometry = source.geometry.clone();
  9857. this.perObjectFrustumCulled = source.perObjectFrustumCulled;
  9858. this.sortObjects = source.sortObjects;
  9859. this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
  9860. this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
  9861. this._geometryInfo = source._geometryInfo.map( info => ( {
  9862. ...info,
  9863. boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
  9864. boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
  9865. } ) );
  9866. this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
  9867. this._maxInstanceCount = source._maxInstanceCount;
  9868. this._maxVertexCount = source._maxVertexCount;
  9869. this._maxIndexCount = source._maxIndexCount;
  9870. this._geometryInitialized = source._geometryInitialized;
  9871. this._geometryCount = source._geometryCount;
  9872. this._multiDrawCounts = source._multiDrawCounts.slice();
  9873. this._multiDrawStarts = source._multiDrawStarts.slice();
  9874. this._matricesTexture = source._matricesTexture.clone();
  9875. this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
  9876. if ( this._colorsTexture !== null ) {
  9877. this._colorsTexture = source._colorsTexture.clone();
  9878. this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
  9879. }
  9880. return this;
  9881. }
  9882. dispose() {
  9883. // Assuming the geometry is not shared with other meshes
  9884. this.geometry.dispose();
  9885. this._matricesTexture.dispose();
  9886. this._matricesTexture = null;
  9887. this._indirectTexture.dispose();
  9888. this._indirectTexture = null;
  9889. if ( this._colorsTexture !== null ) {
  9890. this._colorsTexture.dispose();
  9891. this._colorsTexture = null;
  9892. }
  9893. return this;
  9894. }
  9895. onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
  9896. // if visibility has not changed and frustum culling and object sorting is not required
  9897. // then skip iterating over all items
  9898. if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) {
  9899. return;
  9900. }
  9901. // the indexed version of the multi draw function requires specifying the start
  9902. // offset in bytes.
  9903. const index = geometry.getIndex();
  9904. const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
  9905. const instanceInfo = this._instanceInfo;
  9906. const multiDrawStarts = this._multiDrawStarts;
  9907. const multiDrawCounts = this._multiDrawCounts;
  9908. const geometryInfoList = this._geometryInfo;
  9909. const perObjectFrustumCulled = this.perObjectFrustumCulled;
  9910. const indirectTexture = this._indirectTexture;
  9911. const indirectArray = indirectTexture.image.data;
  9912. // prepare the frustum in the local frame
  9913. if ( perObjectFrustumCulled ) {
  9914. _matrix$1
  9915. .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
  9916. .multiply( this.matrixWorld );
  9917. _frustum.setFromProjectionMatrix(
  9918. _matrix$1,
  9919. renderer.coordinateSystem
  9920. );
  9921. }
  9922. let multiDrawCount = 0;
  9923. if ( this.sortObjects ) {
  9924. // get the camera position in the local frame
  9925. _matrix$1.copy( this.matrixWorld ).invert();
  9926. _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
  9927. _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
  9928. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9929. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9930. const geometryId = instanceInfo[ i ].geometryIndex;
  9931. // get the bounds in world space
  9932. this.getMatrixAt( i, _matrix$1 );
  9933. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9934. // determine whether the batched geometry is within the frustum
  9935. let culled = false;
  9936. if ( perObjectFrustumCulled ) {
  9937. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9938. }
  9939. if ( ! culled ) {
  9940. // get the distance from camera used for sorting
  9941. const geometryInfo = geometryInfoList[ geometryId ];
  9942. const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
  9943. _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
  9944. }
  9945. }
  9946. }
  9947. // Sort the draw ranges and prep for rendering
  9948. const list = _renderList.list;
  9949. const customSort = this.customSort;
  9950. if ( customSort === null ) {
  9951. list.sort( material.transparent ? sortTransparent : sortOpaque );
  9952. } else {
  9953. customSort.call( this, list, camera );
  9954. }
  9955. for ( let i = 0, l = list.length; i < l; i ++ ) {
  9956. const item = list[ i ];
  9957. multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
  9958. multiDrawCounts[ multiDrawCount ] = item.count;
  9959. indirectArray[ multiDrawCount ] = item.index;
  9960. multiDrawCount ++;
  9961. }
  9962. _renderList.reset();
  9963. } else {
  9964. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9965. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9966. const geometryId = instanceInfo[ i ].geometryIndex;
  9967. // determine whether the batched geometry is within the frustum
  9968. let culled = false;
  9969. if ( perObjectFrustumCulled ) {
  9970. // get the bounds in world space
  9971. this.getMatrixAt( i, _matrix$1 );
  9972. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9973. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9974. }
  9975. if ( ! culled ) {
  9976. const geometryInfo = geometryInfoList[ geometryId ];
  9977. multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
  9978. multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
  9979. indirectArray[ multiDrawCount ] = i;
  9980. multiDrawCount ++;
  9981. }
  9982. }
  9983. }
  9984. }
  9985. indirectTexture.needsUpdate = true;
  9986. this._multiDrawCount = multiDrawCount;
  9987. this._visibilityChanged = false;
  9988. }
  9989. onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) {
  9990. this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial );
  9991. }
  9992. }
  9993. class LineBasicMaterial extends Material {
  9994. constructor( parameters ) {
  9995. super();
  9996. this.isLineBasicMaterial = true;
  9997. this.type = 'LineBasicMaterial';
  9998. this.color = new Color( 0xffffff );
  9999. this.map = null;
  10000. this.linewidth = 1;
  10001. this.linecap = 'round';
  10002. this.linejoin = 'round';
  10003. this.fog = true;
  10004. this.setValues( parameters );
  10005. }
  10006. copy( source ) {
  10007. super.copy( source );
  10008. this.color.copy( source.color );
  10009. this.map = source.map;
  10010. this.linewidth = source.linewidth;
  10011. this.linecap = source.linecap;
  10012. this.linejoin = source.linejoin;
  10013. this.fog = source.fog;
  10014. return this;
  10015. }
  10016. }
  10017. const _vStart = /*@__PURE__*/ new Vector3();
  10018. const _vEnd = /*@__PURE__*/ new Vector3();
  10019. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  10020. const _ray$1 = /*@__PURE__*/ new Ray();
  10021. const _sphere$1 = /*@__PURE__*/ new Sphere();
  10022. const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
  10023. const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
  10024. class Line extends Object3D {
  10025. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  10026. super();
  10027. this.isLine = true;
  10028. this.type = 'Line';
  10029. this.geometry = geometry;
  10030. this.material = material;
  10031. this.updateMorphTargets();
  10032. }
  10033. copy( source, recursive ) {
  10034. super.copy( source, recursive );
  10035. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10036. this.geometry = source.geometry;
  10037. return this;
  10038. }
  10039. computeLineDistances() {
  10040. const geometry = this.geometry;
  10041. // we assume non-indexed geometry
  10042. if ( geometry.index === null ) {
  10043. const positionAttribute = geometry.attributes.position;
  10044. const lineDistances = [ 0 ];
  10045. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  10046. _vStart.fromBufferAttribute( positionAttribute, i - 1 );
  10047. _vEnd.fromBufferAttribute( positionAttribute, i );
  10048. lineDistances[ i ] = lineDistances[ i - 1 ];
  10049. lineDistances[ i ] += _vStart.distanceTo( _vEnd );
  10050. }
  10051. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10052. } else {
  10053. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10054. }
  10055. return this;
  10056. }
  10057. raycast( raycaster, intersects ) {
  10058. const geometry = this.geometry;
  10059. const matrixWorld = this.matrixWorld;
  10060. const threshold = raycaster.params.Line.threshold;
  10061. const drawRange = geometry.drawRange;
  10062. // Checking boundingSphere distance to ray
  10063. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10064. _sphere$1.copy( geometry.boundingSphere );
  10065. _sphere$1.applyMatrix4( matrixWorld );
  10066. _sphere$1.radius += threshold;
  10067. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  10068. //
  10069. _inverseMatrix$1.copy( matrixWorld ).invert();
  10070. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  10071. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10072. const localThresholdSq = localThreshold * localThreshold;
  10073. const step = this.isLineSegments ? 2 : 1;
  10074. const index = geometry.index;
  10075. const attributes = geometry.attributes;
  10076. const positionAttribute = attributes.position;
  10077. if ( index !== null ) {
  10078. const start = Math.max( 0, drawRange.start );
  10079. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10080. for ( let i = start, l = end - 1; i < l; i += step ) {
  10081. const a = index.getX( i );
  10082. const b = index.getX( i + 1 );
  10083. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10084. if ( intersect ) {
  10085. intersects.push( intersect );
  10086. }
  10087. }
  10088. if ( this.isLineLoop ) {
  10089. const a = index.getX( end - 1 );
  10090. const b = index.getX( start );
  10091. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10092. if ( intersect ) {
  10093. intersects.push( intersect );
  10094. }
  10095. }
  10096. } else {
  10097. const start = Math.max( 0, drawRange.start );
  10098. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10099. for ( let i = start, l = end - 1; i < l; i += step ) {
  10100. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
  10101. if ( intersect ) {
  10102. intersects.push( intersect );
  10103. }
  10104. }
  10105. if ( this.isLineLoop ) {
  10106. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
  10107. if ( intersect ) {
  10108. intersects.push( intersect );
  10109. }
  10110. }
  10111. }
  10112. }
  10113. updateMorphTargets() {
  10114. const geometry = this.geometry;
  10115. const morphAttributes = geometry.morphAttributes;
  10116. const keys = Object.keys( morphAttributes );
  10117. if ( keys.length > 0 ) {
  10118. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10119. if ( morphAttribute !== undefined ) {
  10120. this.morphTargetInfluences = [];
  10121. this.morphTargetDictionary = {};
  10122. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10123. const name = morphAttribute[ m ].name || String( m );
  10124. this.morphTargetInfluences.push( 0 );
  10125. this.morphTargetDictionary[ name ] = m;
  10126. }
  10127. }
  10128. }
  10129. }
  10130. }
  10131. function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
  10132. const positionAttribute = object.geometry.attributes.position;
  10133. _vStart.fromBufferAttribute( positionAttribute, a );
  10134. _vEnd.fromBufferAttribute( positionAttribute, b );
  10135. const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
  10136. if ( distSq > thresholdSq ) return;
  10137. _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
  10138. const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
  10139. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10140. return {
  10141. distance: distance,
  10142. // What do we want? intersection point on the ray or on the segment??
  10143. // point: raycaster.ray.at( distance ),
  10144. point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
  10145. index: a,
  10146. face: null,
  10147. faceIndex: null,
  10148. barycoord: null,
  10149. object: object
  10150. };
  10151. }
  10152. const _start = /*@__PURE__*/ new Vector3();
  10153. const _end = /*@__PURE__*/ new Vector3();
  10154. class LineSegments extends Line {
  10155. constructor( geometry, material ) {
  10156. super( geometry, material );
  10157. this.isLineSegments = true;
  10158. this.type = 'LineSegments';
  10159. }
  10160. computeLineDistances() {
  10161. const geometry = this.geometry;
  10162. // we assume non-indexed geometry
  10163. if ( geometry.index === null ) {
  10164. const positionAttribute = geometry.attributes.position;
  10165. const lineDistances = [];
  10166. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  10167. _start.fromBufferAttribute( positionAttribute, i );
  10168. _end.fromBufferAttribute( positionAttribute, i + 1 );
  10169. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  10170. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  10171. }
  10172. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10173. } else {
  10174. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10175. }
  10176. return this;
  10177. }
  10178. }
  10179. class LineLoop extends Line {
  10180. constructor( geometry, material ) {
  10181. super( geometry, material );
  10182. this.isLineLoop = true;
  10183. this.type = 'LineLoop';
  10184. }
  10185. }
  10186. class PointsMaterial extends Material {
  10187. constructor( parameters ) {
  10188. super();
  10189. this.isPointsMaterial = true;
  10190. this.type = 'PointsMaterial';
  10191. this.color = new Color( 0xffffff );
  10192. this.map = null;
  10193. this.alphaMap = null;
  10194. this.size = 1;
  10195. this.sizeAttenuation = true;
  10196. this.fog = true;
  10197. this.setValues( parameters );
  10198. }
  10199. copy( source ) {
  10200. super.copy( source );
  10201. this.color.copy( source.color );
  10202. this.map = source.map;
  10203. this.alphaMap = source.alphaMap;
  10204. this.size = source.size;
  10205. this.sizeAttenuation = source.sizeAttenuation;
  10206. this.fog = source.fog;
  10207. return this;
  10208. }
  10209. }
  10210. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  10211. const _ray = /*@__PURE__*/ new Ray();
  10212. const _sphere = /*@__PURE__*/ new Sphere();
  10213. const _position$2 = /*@__PURE__*/ new Vector3();
  10214. class Points extends Object3D {
  10215. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  10216. super();
  10217. this.isPoints = true;
  10218. this.type = 'Points';
  10219. this.geometry = geometry;
  10220. this.material = material;
  10221. this.updateMorphTargets();
  10222. }
  10223. copy( source, recursive ) {
  10224. super.copy( source, recursive );
  10225. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10226. this.geometry = source.geometry;
  10227. return this;
  10228. }
  10229. raycast( raycaster, intersects ) {
  10230. const geometry = this.geometry;
  10231. const matrixWorld = this.matrixWorld;
  10232. const threshold = raycaster.params.Points.threshold;
  10233. const drawRange = geometry.drawRange;
  10234. // Checking boundingSphere distance to ray
  10235. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10236. _sphere.copy( geometry.boundingSphere );
  10237. _sphere.applyMatrix4( matrixWorld );
  10238. _sphere.radius += threshold;
  10239. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  10240. //
  10241. _inverseMatrix.copy( matrixWorld ).invert();
  10242. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  10243. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10244. const localThresholdSq = localThreshold * localThreshold;
  10245. const index = geometry.index;
  10246. const attributes = geometry.attributes;
  10247. const positionAttribute = attributes.position;
  10248. if ( index !== null ) {
  10249. const start = Math.max( 0, drawRange.start );
  10250. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10251. for ( let i = start, il = end; i < il; i ++ ) {
  10252. const a = index.getX( i );
  10253. _position$2.fromBufferAttribute( positionAttribute, a );
  10254. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10255. }
  10256. } else {
  10257. const start = Math.max( 0, drawRange.start );
  10258. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10259. for ( let i = start, l = end; i < l; i ++ ) {
  10260. _position$2.fromBufferAttribute( positionAttribute, i );
  10261. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10262. }
  10263. }
  10264. }
  10265. updateMorphTargets() {
  10266. const geometry = this.geometry;
  10267. const morphAttributes = geometry.morphAttributes;
  10268. const keys = Object.keys( morphAttributes );
  10269. if ( keys.length > 0 ) {
  10270. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10271. if ( morphAttribute !== undefined ) {
  10272. this.morphTargetInfluences = [];
  10273. this.morphTargetDictionary = {};
  10274. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10275. const name = morphAttribute[ m ].name || String( m );
  10276. this.morphTargetInfluences.push( 0 );
  10277. this.morphTargetDictionary[ name ] = m;
  10278. }
  10279. }
  10280. }
  10281. }
  10282. }
  10283. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  10284. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  10285. if ( rayPointDistanceSq < localThresholdSq ) {
  10286. const intersectPoint = new Vector3();
  10287. _ray.closestPointToPoint( point, intersectPoint );
  10288. intersectPoint.applyMatrix4( matrixWorld );
  10289. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10290. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10291. intersects.push( {
  10292. distance: distance,
  10293. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10294. point: intersectPoint,
  10295. index: index,
  10296. face: null,
  10297. faceIndex: null,
  10298. barycoord: null,
  10299. object: object
  10300. } );
  10301. }
  10302. }
  10303. class Group extends Object3D {
  10304. constructor() {
  10305. super();
  10306. this.isGroup = true;
  10307. this.type = 'Group';
  10308. }
  10309. }
  10310. class VideoTexture extends Texture {
  10311. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10312. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10313. this.isVideoTexture = true;
  10314. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  10315. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  10316. this.generateMipmaps = false;
  10317. const scope = this;
  10318. function updateVideo() {
  10319. scope.needsUpdate = true;
  10320. video.requestVideoFrameCallback( updateVideo );
  10321. }
  10322. if ( 'requestVideoFrameCallback' in video ) {
  10323. video.requestVideoFrameCallback( updateVideo );
  10324. }
  10325. }
  10326. clone() {
  10327. return new this.constructor( this.image ).copy( this );
  10328. }
  10329. update() {
  10330. const video = this.image;
  10331. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  10332. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  10333. this.needsUpdate = true;
  10334. }
  10335. }
  10336. }
  10337. class FramebufferTexture extends Texture {
  10338. constructor( width, height ) {
  10339. super( { width, height } );
  10340. this.isFramebufferTexture = true;
  10341. this.magFilter = NearestFilter;
  10342. this.minFilter = NearestFilter;
  10343. this.generateMipmaps = false;
  10344. this.needsUpdate = true;
  10345. }
  10346. }
  10347. class CompressedTexture extends Texture {
  10348. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {
  10349. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  10350. this.isCompressedTexture = true;
  10351. this.image = { width: width, height: height };
  10352. this.mipmaps = mipmaps;
  10353. // no flipping for cube textures
  10354. // (also flipping doesn't work for compressed textures )
  10355. this.flipY = false;
  10356. // can't generate mipmaps for compressed textures
  10357. // mips must be embedded in DDS files
  10358. this.generateMipmaps = false;
  10359. }
  10360. }
  10361. class CompressedArrayTexture extends CompressedTexture {
  10362. constructor( mipmaps, width, height, depth, format, type ) {
  10363. super( mipmaps, width, height, format, type );
  10364. this.isCompressedArrayTexture = true;
  10365. this.image.depth = depth;
  10366. this.wrapR = ClampToEdgeWrapping;
  10367. this.layerUpdates = new Set();
  10368. }
  10369. addLayerUpdate( layerIndex ) {
  10370. this.layerUpdates.add( layerIndex );
  10371. }
  10372. clearLayerUpdates() {
  10373. this.layerUpdates.clear();
  10374. }
  10375. }
  10376. class CompressedCubeTexture extends CompressedTexture {
  10377. constructor( images, format, type ) {
  10378. super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
  10379. this.isCompressedCubeTexture = true;
  10380. this.isCubeTexture = true;
  10381. this.image = images;
  10382. }
  10383. }
  10384. class CanvasTexture extends Texture {
  10385. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10386. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10387. this.isCanvasTexture = true;
  10388. this.needsUpdate = true;
  10389. }
  10390. }
  10391. class DepthTexture extends Texture {
  10392. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
  10393. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  10394. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  10395. }
  10396. if ( type === undefined && format === DepthFormat ) type = UnsignedIntType;
  10397. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  10398. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10399. this.isDepthTexture = true;
  10400. this.image = { width: width, height: height };
  10401. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  10402. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  10403. this.flipY = false;
  10404. this.generateMipmaps = false;
  10405. this.compareFunction = null;
  10406. }
  10407. copy( source ) {
  10408. super.copy( source );
  10409. this.compareFunction = source.compareFunction;
  10410. return this;
  10411. }
  10412. toJSON( meta ) {
  10413. const data = super.toJSON( meta );
  10414. if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
  10415. return data;
  10416. }
  10417. }
  10418. /**
  10419. * Extensible curve object.
  10420. *
  10421. * Some common of curve methods:
  10422. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  10423. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  10424. * .getPoints(), .getSpacedPoints()
  10425. * .getLength()
  10426. * .updateArcLengths()
  10427. *
  10428. * This following curves inherit from THREE.Curve:
  10429. *
  10430. * -- 2D curves --
  10431. * THREE.ArcCurve
  10432. * THREE.CubicBezierCurve
  10433. * THREE.EllipseCurve
  10434. * THREE.LineCurve
  10435. * THREE.QuadraticBezierCurve
  10436. * THREE.SplineCurve
  10437. *
  10438. * -- 3D curves --
  10439. * THREE.CatmullRomCurve3
  10440. * THREE.CubicBezierCurve3
  10441. * THREE.LineCurve3
  10442. * THREE.QuadraticBezierCurve3
  10443. *
  10444. * A series of curves can be represented as a THREE.CurvePath.
  10445. *
  10446. **/
  10447. class Curve {
  10448. constructor() {
  10449. this.type = 'Curve';
  10450. this.arcLengthDivisions = 200;
  10451. }
  10452. // Virtual base class method to overwrite and implement in subclasses
  10453. // - t [0 .. 1]
  10454. getPoint( /* t, optionalTarget */ ) {
  10455. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  10456. return null;
  10457. }
  10458. // Get point at relative position in curve according to arc length
  10459. // - u [0 .. 1]
  10460. getPointAt( u, optionalTarget ) {
  10461. const t = this.getUtoTmapping( u );
  10462. return this.getPoint( t, optionalTarget );
  10463. }
  10464. // Get sequence of points using getPoint( t )
  10465. getPoints( divisions = 5 ) {
  10466. const points = [];
  10467. for ( let d = 0; d <= divisions; d ++ ) {
  10468. points.push( this.getPoint( d / divisions ) );
  10469. }
  10470. return points;
  10471. }
  10472. // Get sequence of points using getPointAt( u )
  10473. getSpacedPoints( divisions = 5 ) {
  10474. const points = [];
  10475. for ( let d = 0; d <= divisions; d ++ ) {
  10476. points.push( this.getPointAt( d / divisions ) );
  10477. }
  10478. return points;
  10479. }
  10480. // Get total curve arc length
  10481. getLength() {
  10482. const lengths = this.getLengths();
  10483. return lengths[ lengths.length - 1 ];
  10484. }
  10485. // Get list of cumulative segment lengths
  10486. getLengths( divisions = this.arcLengthDivisions ) {
  10487. if ( this.cacheArcLengths &&
  10488. ( this.cacheArcLengths.length === divisions + 1 ) &&
  10489. ! this.needsUpdate ) {
  10490. return this.cacheArcLengths;
  10491. }
  10492. this.needsUpdate = false;
  10493. const cache = [];
  10494. let current, last = this.getPoint( 0 );
  10495. let sum = 0;
  10496. cache.push( 0 );
  10497. for ( let p = 1; p <= divisions; p ++ ) {
  10498. current = this.getPoint( p / divisions );
  10499. sum += current.distanceTo( last );
  10500. cache.push( sum );
  10501. last = current;
  10502. }
  10503. this.cacheArcLengths = cache;
  10504. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  10505. }
  10506. updateArcLengths() {
  10507. this.needsUpdate = true;
  10508. this.getLengths();
  10509. }
  10510. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  10511. getUtoTmapping( u, distance ) {
  10512. const arcLengths = this.getLengths();
  10513. let i = 0;
  10514. const il = arcLengths.length;
  10515. let targetArcLength; // The targeted u distance value to get
  10516. if ( distance ) {
  10517. targetArcLength = distance;
  10518. } else {
  10519. targetArcLength = u * arcLengths[ il - 1 ];
  10520. }
  10521. // binary search for the index with largest value smaller than target u distance
  10522. let low = 0, high = il - 1, comparison;
  10523. while ( low <= high ) {
  10524. i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
  10525. comparison = arcLengths[ i ] - targetArcLength;
  10526. if ( comparison < 0 ) {
  10527. low = i + 1;
  10528. } else if ( comparison > 0 ) {
  10529. high = i - 1;
  10530. } else {
  10531. high = i;
  10532. break;
  10533. // DONE
  10534. }
  10535. }
  10536. i = high;
  10537. if ( arcLengths[ i ] === targetArcLength ) {
  10538. return i / ( il - 1 );
  10539. }
  10540. // we could get finer grain at lengths, or use simple interpolation between two points
  10541. const lengthBefore = arcLengths[ i ];
  10542. const lengthAfter = arcLengths[ i + 1 ];
  10543. const segmentLength = lengthAfter - lengthBefore;
  10544. // determine where we are between the 'before' and 'after' points
  10545. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  10546. // add that fractional amount to t
  10547. const t = ( i + segmentFraction ) / ( il - 1 );
  10548. return t;
  10549. }
  10550. // Returns a unit vector tangent at t
  10551. // In case any sub curve does not implement its tangent derivation,
  10552. // 2 points a small delta apart will be used to find its gradient
  10553. // which seems to give a reasonable approximation
  10554. getTangent( t, optionalTarget ) {
  10555. const delta = 0.0001;
  10556. let t1 = t - delta;
  10557. let t2 = t + delta;
  10558. // Capping in case of danger
  10559. if ( t1 < 0 ) t1 = 0;
  10560. if ( t2 > 1 ) t2 = 1;
  10561. const pt1 = this.getPoint( t1 );
  10562. const pt2 = this.getPoint( t2 );
  10563. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  10564. tangent.copy( pt2 ).sub( pt1 ).normalize();
  10565. return tangent;
  10566. }
  10567. getTangentAt( u, optionalTarget ) {
  10568. const t = this.getUtoTmapping( u );
  10569. return this.getTangent( t, optionalTarget );
  10570. }
  10571. computeFrenetFrames( segments, closed ) {
  10572. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  10573. const normal = new Vector3();
  10574. const tangents = [];
  10575. const normals = [];
  10576. const binormals = [];
  10577. const vec = new Vector3();
  10578. const mat = new Matrix4();
  10579. // compute the tangent vectors for each segment on the curve
  10580. for ( let i = 0; i <= segments; i ++ ) {
  10581. const u = i / segments;
  10582. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  10583. }
  10584. // select an initial normal vector perpendicular to the first tangent vector,
  10585. // and in the direction of the minimum tangent xyz component
  10586. normals[ 0 ] = new Vector3();
  10587. binormals[ 0 ] = new Vector3();
  10588. let min = Number.MAX_VALUE;
  10589. const tx = Math.abs( tangents[ 0 ].x );
  10590. const ty = Math.abs( tangents[ 0 ].y );
  10591. const tz = Math.abs( tangents[ 0 ].z );
  10592. if ( tx <= min ) {
  10593. min = tx;
  10594. normal.set( 1, 0, 0 );
  10595. }
  10596. if ( ty <= min ) {
  10597. min = ty;
  10598. normal.set( 0, 1, 0 );
  10599. }
  10600. if ( tz <= min ) {
  10601. normal.set( 0, 0, 1 );
  10602. }
  10603. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  10604. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  10605. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  10606. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  10607. for ( let i = 1; i <= segments; i ++ ) {
  10608. normals[ i ] = normals[ i - 1 ].clone();
  10609. binormals[ i ] = binormals[ i - 1 ].clone();
  10610. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  10611. if ( vec.length() > Number.EPSILON ) {
  10612. vec.normalize();
  10613. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  10614. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  10615. }
  10616. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10617. }
  10618. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  10619. if ( closed === true ) {
  10620. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  10621. theta /= segments;
  10622. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  10623. theta = - theta;
  10624. }
  10625. for ( let i = 1; i <= segments; i ++ ) {
  10626. // twist a little...
  10627. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  10628. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10629. }
  10630. }
  10631. return {
  10632. tangents: tangents,
  10633. normals: normals,
  10634. binormals: binormals
  10635. };
  10636. }
  10637. clone() {
  10638. return new this.constructor().copy( this );
  10639. }
  10640. copy( source ) {
  10641. this.arcLengthDivisions = source.arcLengthDivisions;
  10642. return this;
  10643. }
  10644. toJSON() {
  10645. const data = {
  10646. metadata: {
  10647. version: 4.6,
  10648. type: 'Curve',
  10649. generator: 'Curve.toJSON'
  10650. }
  10651. };
  10652. data.arcLengthDivisions = this.arcLengthDivisions;
  10653. data.type = this.type;
  10654. return data;
  10655. }
  10656. fromJSON( json ) {
  10657. this.arcLengthDivisions = json.arcLengthDivisions;
  10658. return this;
  10659. }
  10660. }
  10661. class EllipseCurve extends Curve {
  10662. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  10663. super();
  10664. this.isEllipseCurve = true;
  10665. this.type = 'EllipseCurve';
  10666. this.aX = aX;
  10667. this.aY = aY;
  10668. this.xRadius = xRadius;
  10669. this.yRadius = yRadius;
  10670. this.aStartAngle = aStartAngle;
  10671. this.aEndAngle = aEndAngle;
  10672. this.aClockwise = aClockwise;
  10673. this.aRotation = aRotation;
  10674. }
  10675. getPoint( t, optionalTarget = new Vector2() ) {
  10676. const point = optionalTarget;
  10677. const twoPi = Math.PI * 2;
  10678. let deltaAngle = this.aEndAngle - this.aStartAngle;
  10679. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  10680. // ensures that deltaAngle is 0 .. 2 PI
  10681. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  10682. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  10683. if ( deltaAngle < Number.EPSILON ) {
  10684. if ( samePoints ) {
  10685. deltaAngle = 0;
  10686. } else {
  10687. deltaAngle = twoPi;
  10688. }
  10689. }
  10690. if ( this.aClockwise === true && ! samePoints ) {
  10691. if ( deltaAngle === twoPi ) {
  10692. deltaAngle = - twoPi;
  10693. } else {
  10694. deltaAngle = deltaAngle - twoPi;
  10695. }
  10696. }
  10697. const angle = this.aStartAngle + t * deltaAngle;
  10698. let x = this.aX + this.xRadius * Math.cos( angle );
  10699. let y = this.aY + this.yRadius * Math.sin( angle );
  10700. if ( this.aRotation !== 0 ) {
  10701. const cos = Math.cos( this.aRotation );
  10702. const sin = Math.sin( this.aRotation );
  10703. const tx = x - this.aX;
  10704. const ty = y - this.aY;
  10705. // Rotate the point about the center of the ellipse.
  10706. x = tx * cos - ty * sin + this.aX;
  10707. y = tx * sin + ty * cos + this.aY;
  10708. }
  10709. return point.set( x, y );
  10710. }
  10711. copy( source ) {
  10712. super.copy( source );
  10713. this.aX = source.aX;
  10714. this.aY = source.aY;
  10715. this.xRadius = source.xRadius;
  10716. this.yRadius = source.yRadius;
  10717. this.aStartAngle = source.aStartAngle;
  10718. this.aEndAngle = source.aEndAngle;
  10719. this.aClockwise = source.aClockwise;
  10720. this.aRotation = source.aRotation;
  10721. return this;
  10722. }
  10723. toJSON() {
  10724. const data = super.toJSON();
  10725. data.aX = this.aX;
  10726. data.aY = this.aY;
  10727. data.xRadius = this.xRadius;
  10728. data.yRadius = this.yRadius;
  10729. data.aStartAngle = this.aStartAngle;
  10730. data.aEndAngle = this.aEndAngle;
  10731. data.aClockwise = this.aClockwise;
  10732. data.aRotation = this.aRotation;
  10733. return data;
  10734. }
  10735. fromJSON( json ) {
  10736. super.fromJSON( json );
  10737. this.aX = json.aX;
  10738. this.aY = json.aY;
  10739. this.xRadius = json.xRadius;
  10740. this.yRadius = json.yRadius;
  10741. this.aStartAngle = json.aStartAngle;
  10742. this.aEndAngle = json.aEndAngle;
  10743. this.aClockwise = json.aClockwise;
  10744. this.aRotation = json.aRotation;
  10745. return this;
  10746. }
  10747. }
  10748. class ArcCurve extends EllipseCurve {
  10749. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  10750. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  10751. this.isArcCurve = true;
  10752. this.type = 'ArcCurve';
  10753. }
  10754. }
  10755. /**
  10756. * Centripetal CatmullRom Curve - which is useful for avoiding
  10757. * cusps and self-intersections in non-uniform catmull rom curves.
  10758. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  10759. *
  10760. * curve.type accepts centripetal(default), chordal and catmullrom
  10761. * curve.tension is used for catmullrom which defaults to 0.5
  10762. */
  10763. /*
  10764. Based on an optimized c++ solution in
  10765. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  10766. - http://ideone.com/NoEbVM
  10767. This CubicPoly class could be used for reusing some variables and calculations,
  10768. but for three.js curve use, it could be possible inlined and flatten into a single function call
  10769. which can be placed in CurveUtils.
  10770. */
  10771. function CubicPoly() {
  10772. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  10773. /*
  10774. * Compute coefficients for a cubic polynomial
  10775. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  10776. * such that
  10777. * p(0) = x0, p(1) = x1
  10778. * and
  10779. * p'(0) = t0, p'(1) = t1.
  10780. */
  10781. function init( x0, x1, t0, t1 ) {
  10782. c0 = x0;
  10783. c1 = t0;
  10784. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  10785. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  10786. }
  10787. return {
  10788. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  10789. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  10790. },
  10791. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  10792. // compute tangents when parameterized in [t1,t2]
  10793. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  10794. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  10795. // rescale tangents for parametrization in [0,1]
  10796. t1 *= dt1;
  10797. t2 *= dt1;
  10798. init( x1, x2, t1, t2 );
  10799. },
  10800. calc: function ( t ) {
  10801. const t2 = t * t;
  10802. const t3 = t2 * t;
  10803. return c0 + c1 * t + c2 * t2 + c3 * t3;
  10804. }
  10805. };
  10806. }
  10807. //
  10808. const tmp = /*@__PURE__*/ new Vector3();
  10809. const px = /*@__PURE__*/ new CubicPoly();
  10810. const py = /*@__PURE__*/ new CubicPoly();
  10811. const pz = /*@__PURE__*/ new CubicPoly();
  10812. class CatmullRomCurve3 extends Curve {
  10813. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  10814. super();
  10815. this.isCatmullRomCurve3 = true;
  10816. this.type = 'CatmullRomCurve3';
  10817. this.points = points;
  10818. this.closed = closed;
  10819. this.curveType = curveType;
  10820. this.tension = tension;
  10821. }
  10822. getPoint( t, optionalTarget = new Vector3() ) {
  10823. const point = optionalTarget;
  10824. const points = this.points;
  10825. const l = points.length;
  10826. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  10827. let intPoint = Math.floor( p );
  10828. let weight = p - intPoint;
  10829. if ( this.closed ) {
  10830. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  10831. } else if ( weight === 0 && intPoint === l - 1 ) {
  10832. intPoint = l - 2;
  10833. weight = 1;
  10834. }
  10835. let p0, p3; // 4 points (p1 & p2 defined below)
  10836. if ( this.closed || intPoint > 0 ) {
  10837. p0 = points[ ( intPoint - 1 ) % l ];
  10838. } else {
  10839. // extrapolate first point
  10840. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  10841. p0 = tmp;
  10842. }
  10843. const p1 = points[ intPoint % l ];
  10844. const p2 = points[ ( intPoint + 1 ) % l ];
  10845. if ( this.closed || intPoint + 2 < l ) {
  10846. p3 = points[ ( intPoint + 2 ) % l ];
  10847. } else {
  10848. // extrapolate last point
  10849. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  10850. p3 = tmp;
  10851. }
  10852. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  10853. // init Centripetal / Chordal Catmull-Rom
  10854. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  10855. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  10856. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  10857. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  10858. // safety check for repeated points
  10859. if ( dt1 < 1e-4 ) dt1 = 1.0;
  10860. if ( dt0 < 1e-4 ) dt0 = dt1;
  10861. if ( dt2 < 1e-4 ) dt2 = dt1;
  10862. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  10863. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  10864. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  10865. } else if ( this.curveType === 'catmullrom' ) {
  10866. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  10867. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  10868. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  10869. }
  10870. point.set(
  10871. px.calc( weight ),
  10872. py.calc( weight ),
  10873. pz.calc( weight )
  10874. );
  10875. return point;
  10876. }
  10877. copy( source ) {
  10878. super.copy( source );
  10879. this.points = [];
  10880. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  10881. const point = source.points[ i ];
  10882. this.points.push( point.clone() );
  10883. }
  10884. this.closed = source.closed;
  10885. this.curveType = source.curveType;
  10886. this.tension = source.tension;
  10887. return this;
  10888. }
  10889. toJSON() {
  10890. const data = super.toJSON();
  10891. data.points = [];
  10892. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  10893. const point = this.points[ i ];
  10894. data.points.push( point.toArray() );
  10895. }
  10896. data.closed = this.closed;
  10897. data.curveType = this.curveType;
  10898. data.tension = this.tension;
  10899. return data;
  10900. }
  10901. fromJSON( json ) {
  10902. super.fromJSON( json );
  10903. this.points = [];
  10904. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  10905. const point = json.points[ i ];
  10906. this.points.push( new Vector3().fromArray( point ) );
  10907. }
  10908. this.closed = json.closed;
  10909. this.curveType = json.curveType;
  10910. this.tension = json.tension;
  10911. return this;
  10912. }
  10913. }
  10914. /**
  10915. * Bezier Curves formulas obtained from
  10916. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
  10917. */
  10918. function CatmullRom( t, p0, p1, p2, p3 ) {
  10919. const v0 = ( p2 - p0 ) * 0.5;
  10920. const v1 = ( p3 - p1 ) * 0.5;
  10921. const t2 = t * t;
  10922. const t3 = t * t2;
  10923. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  10924. }
  10925. //
  10926. function QuadraticBezierP0( t, p ) {
  10927. const k = 1 - t;
  10928. return k * k * p;
  10929. }
  10930. function QuadraticBezierP1( t, p ) {
  10931. return 2 * ( 1 - t ) * t * p;
  10932. }
  10933. function QuadraticBezierP2( t, p ) {
  10934. return t * t * p;
  10935. }
  10936. function QuadraticBezier( t, p0, p1, p2 ) {
  10937. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  10938. QuadraticBezierP2( t, p2 );
  10939. }
  10940. //
  10941. function CubicBezierP0( t, p ) {
  10942. const k = 1 - t;
  10943. return k * k * k * p;
  10944. }
  10945. function CubicBezierP1( t, p ) {
  10946. const k = 1 - t;
  10947. return 3 * k * k * t * p;
  10948. }
  10949. function CubicBezierP2( t, p ) {
  10950. return 3 * ( 1 - t ) * t * t * p;
  10951. }
  10952. function CubicBezierP3( t, p ) {
  10953. return t * t * t * p;
  10954. }
  10955. function CubicBezier( t, p0, p1, p2, p3 ) {
  10956. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  10957. CubicBezierP3( t, p3 );
  10958. }
  10959. class CubicBezierCurve extends Curve {
  10960. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  10961. super();
  10962. this.isCubicBezierCurve = true;
  10963. this.type = 'CubicBezierCurve';
  10964. this.v0 = v0;
  10965. this.v1 = v1;
  10966. this.v2 = v2;
  10967. this.v3 = v3;
  10968. }
  10969. getPoint( t, optionalTarget = new Vector2() ) {
  10970. const point = optionalTarget;
  10971. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  10972. point.set(
  10973. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  10974. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  10975. );
  10976. return point;
  10977. }
  10978. copy( source ) {
  10979. super.copy( source );
  10980. this.v0.copy( source.v0 );
  10981. this.v1.copy( source.v1 );
  10982. this.v2.copy( source.v2 );
  10983. this.v3.copy( source.v3 );
  10984. return this;
  10985. }
  10986. toJSON() {
  10987. const data = super.toJSON();
  10988. data.v0 = this.v0.toArray();
  10989. data.v1 = this.v1.toArray();
  10990. data.v2 = this.v2.toArray();
  10991. data.v3 = this.v3.toArray();
  10992. return data;
  10993. }
  10994. fromJSON( json ) {
  10995. super.fromJSON( json );
  10996. this.v0.fromArray( json.v0 );
  10997. this.v1.fromArray( json.v1 );
  10998. this.v2.fromArray( json.v2 );
  10999. this.v3.fromArray( json.v3 );
  11000. return this;
  11001. }
  11002. }
  11003. class CubicBezierCurve3 extends Curve {
  11004. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  11005. super();
  11006. this.isCubicBezierCurve3 = true;
  11007. this.type = 'CubicBezierCurve3';
  11008. this.v0 = v0;
  11009. this.v1 = v1;
  11010. this.v2 = v2;
  11011. this.v3 = v3;
  11012. }
  11013. getPoint( t, optionalTarget = new Vector3() ) {
  11014. const point = optionalTarget;
  11015. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11016. point.set(
  11017. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11018. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  11019. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  11020. );
  11021. return point;
  11022. }
  11023. copy( source ) {
  11024. super.copy( source );
  11025. this.v0.copy( source.v0 );
  11026. this.v1.copy( source.v1 );
  11027. this.v2.copy( source.v2 );
  11028. this.v3.copy( source.v3 );
  11029. return this;
  11030. }
  11031. toJSON() {
  11032. const data = super.toJSON();
  11033. data.v0 = this.v0.toArray();
  11034. data.v1 = this.v1.toArray();
  11035. data.v2 = this.v2.toArray();
  11036. data.v3 = this.v3.toArray();
  11037. return data;
  11038. }
  11039. fromJSON( json ) {
  11040. super.fromJSON( json );
  11041. this.v0.fromArray( json.v0 );
  11042. this.v1.fromArray( json.v1 );
  11043. this.v2.fromArray( json.v2 );
  11044. this.v3.fromArray( json.v3 );
  11045. return this;
  11046. }
  11047. }
  11048. class LineCurve extends Curve {
  11049. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  11050. super();
  11051. this.isLineCurve = true;
  11052. this.type = 'LineCurve';
  11053. this.v1 = v1;
  11054. this.v2 = v2;
  11055. }
  11056. getPoint( t, optionalTarget = new Vector2() ) {
  11057. const point = optionalTarget;
  11058. if ( t === 1 ) {
  11059. point.copy( this.v2 );
  11060. } else {
  11061. point.copy( this.v2 ).sub( this.v1 );
  11062. point.multiplyScalar( t ).add( this.v1 );
  11063. }
  11064. return point;
  11065. }
  11066. // Line curve is linear, so we can overwrite default getPointAt
  11067. getPointAt( u, optionalTarget ) {
  11068. return this.getPoint( u, optionalTarget );
  11069. }
  11070. getTangent( t, optionalTarget = new Vector2() ) {
  11071. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11072. }
  11073. getTangentAt( u, optionalTarget ) {
  11074. return this.getTangent( u, optionalTarget );
  11075. }
  11076. copy( source ) {
  11077. super.copy( source );
  11078. this.v1.copy( source.v1 );
  11079. this.v2.copy( source.v2 );
  11080. return this;
  11081. }
  11082. toJSON() {
  11083. const data = super.toJSON();
  11084. data.v1 = this.v1.toArray();
  11085. data.v2 = this.v2.toArray();
  11086. return data;
  11087. }
  11088. fromJSON( json ) {
  11089. super.fromJSON( json );
  11090. this.v1.fromArray( json.v1 );
  11091. this.v2.fromArray( json.v2 );
  11092. return this;
  11093. }
  11094. }
  11095. class LineCurve3 extends Curve {
  11096. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  11097. super();
  11098. this.isLineCurve3 = true;
  11099. this.type = 'LineCurve3';
  11100. this.v1 = v1;
  11101. this.v2 = v2;
  11102. }
  11103. getPoint( t, optionalTarget = new Vector3() ) {
  11104. const point = optionalTarget;
  11105. if ( t === 1 ) {
  11106. point.copy( this.v2 );
  11107. } else {
  11108. point.copy( this.v2 ).sub( this.v1 );
  11109. point.multiplyScalar( t ).add( this.v1 );
  11110. }
  11111. return point;
  11112. }
  11113. // Line curve is linear, so we can overwrite default getPointAt
  11114. getPointAt( u, optionalTarget ) {
  11115. return this.getPoint( u, optionalTarget );
  11116. }
  11117. getTangent( t, optionalTarget = new Vector3() ) {
  11118. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11119. }
  11120. getTangentAt( u, optionalTarget ) {
  11121. return this.getTangent( u, optionalTarget );
  11122. }
  11123. copy( source ) {
  11124. super.copy( source );
  11125. this.v1.copy( source.v1 );
  11126. this.v2.copy( source.v2 );
  11127. return this;
  11128. }
  11129. toJSON() {
  11130. const data = super.toJSON();
  11131. data.v1 = this.v1.toArray();
  11132. data.v2 = this.v2.toArray();
  11133. return data;
  11134. }
  11135. fromJSON( json ) {
  11136. super.fromJSON( json );
  11137. this.v1.fromArray( json.v1 );
  11138. this.v2.fromArray( json.v2 );
  11139. return this;
  11140. }
  11141. }
  11142. class QuadraticBezierCurve extends Curve {
  11143. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  11144. super();
  11145. this.isQuadraticBezierCurve = true;
  11146. this.type = 'QuadraticBezierCurve';
  11147. this.v0 = v0;
  11148. this.v1 = v1;
  11149. this.v2 = v2;
  11150. }
  11151. getPoint( t, optionalTarget = new Vector2() ) {
  11152. const point = optionalTarget;
  11153. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11154. point.set(
  11155. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11156. QuadraticBezier( t, v0.y, v1.y, v2.y )
  11157. );
  11158. return point;
  11159. }
  11160. copy( source ) {
  11161. super.copy( source );
  11162. this.v0.copy( source.v0 );
  11163. this.v1.copy( source.v1 );
  11164. this.v2.copy( source.v2 );
  11165. return this;
  11166. }
  11167. toJSON() {
  11168. const data = super.toJSON();
  11169. data.v0 = this.v0.toArray();
  11170. data.v1 = this.v1.toArray();
  11171. data.v2 = this.v2.toArray();
  11172. return data;
  11173. }
  11174. fromJSON( json ) {
  11175. super.fromJSON( json );
  11176. this.v0.fromArray( json.v0 );
  11177. this.v1.fromArray( json.v1 );
  11178. this.v2.fromArray( json.v2 );
  11179. return this;
  11180. }
  11181. }
  11182. class QuadraticBezierCurve3 extends Curve {
  11183. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  11184. super();
  11185. this.isQuadraticBezierCurve3 = true;
  11186. this.type = 'QuadraticBezierCurve3';
  11187. this.v0 = v0;
  11188. this.v1 = v1;
  11189. this.v2 = v2;
  11190. }
  11191. getPoint( t, optionalTarget = new Vector3() ) {
  11192. const point = optionalTarget;
  11193. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11194. point.set(
  11195. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11196. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  11197. QuadraticBezier( t, v0.z, v1.z, v2.z )
  11198. );
  11199. return point;
  11200. }
  11201. copy( source ) {
  11202. super.copy( source );
  11203. this.v0.copy( source.v0 );
  11204. this.v1.copy( source.v1 );
  11205. this.v2.copy( source.v2 );
  11206. return this;
  11207. }
  11208. toJSON() {
  11209. const data = super.toJSON();
  11210. data.v0 = this.v0.toArray();
  11211. data.v1 = this.v1.toArray();
  11212. data.v2 = this.v2.toArray();
  11213. return data;
  11214. }
  11215. fromJSON( json ) {
  11216. super.fromJSON( json );
  11217. this.v0.fromArray( json.v0 );
  11218. this.v1.fromArray( json.v1 );
  11219. this.v2.fromArray( json.v2 );
  11220. return this;
  11221. }
  11222. }
  11223. class SplineCurve extends Curve {
  11224. constructor( points = [] ) {
  11225. super();
  11226. this.isSplineCurve = true;
  11227. this.type = 'SplineCurve';
  11228. this.points = points;
  11229. }
  11230. getPoint( t, optionalTarget = new Vector2() ) {
  11231. const point = optionalTarget;
  11232. const points = this.points;
  11233. const p = ( points.length - 1 ) * t;
  11234. const intPoint = Math.floor( p );
  11235. const weight = p - intPoint;
  11236. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  11237. const p1 = points[ intPoint ];
  11238. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  11239. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  11240. point.set(
  11241. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  11242. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  11243. );
  11244. return point;
  11245. }
  11246. copy( source ) {
  11247. super.copy( source );
  11248. this.points = [];
  11249. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11250. const point = source.points[ i ];
  11251. this.points.push( point.clone() );
  11252. }
  11253. return this;
  11254. }
  11255. toJSON() {
  11256. const data = super.toJSON();
  11257. data.points = [];
  11258. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11259. const point = this.points[ i ];
  11260. data.points.push( point.toArray() );
  11261. }
  11262. return data;
  11263. }
  11264. fromJSON( json ) {
  11265. super.fromJSON( json );
  11266. this.points = [];
  11267. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11268. const point = json.points[ i ];
  11269. this.points.push( new Vector2().fromArray( point ) );
  11270. }
  11271. return this;
  11272. }
  11273. }
  11274. var Curves = /*#__PURE__*/Object.freeze({
  11275. __proto__: null,
  11276. ArcCurve: ArcCurve,
  11277. CatmullRomCurve3: CatmullRomCurve3,
  11278. CubicBezierCurve: CubicBezierCurve,
  11279. CubicBezierCurve3: CubicBezierCurve3,
  11280. EllipseCurve: EllipseCurve,
  11281. LineCurve: LineCurve,
  11282. LineCurve3: LineCurve3,
  11283. QuadraticBezierCurve: QuadraticBezierCurve,
  11284. QuadraticBezierCurve3: QuadraticBezierCurve3,
  11285. SplineCurve: SplineCurve
  11286. });
  11287. /**************************************************************
  11288. * Curved Path - a curve path is simply a array of connected
  11289. * curves, but retains the api of a curve
  11290. **************************************************************/
  11291. class CurvePath extends Curve {
  11292. constructor() {
  11293. super();
  11294. this.type = 'CurvePath';
  11295. this.curves = [];
  11296. this.autoClose = false; // Automatically closes the path
  11297. }
  11298. add( curve ) {
  11299. this.curves.push( curve );
  11300. }
  11301. closePath() {
  11302. // Add a line curve if start and end of lines are not connected
  11303. const startPoint = this.curves[ 0 ].getPoint( 0 );
  11304. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  11305. if ( ! startPoint.equals( endPoint ) ) {
  11306. const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
  11307. this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
  11308. }
  11309. return this;
  11310. }
  11311. // To get accurate point with reference to
  11312. // entire path distance at time t,
  11313. // following has to be done:
  11314. // 1. Length of each sub path have to be known
  11315. // 2. Locate and identify type of curve
  11316. // 3. Get t for the curve
  11317. // 4. Return curve.getPointAt(t')
  11318. getPoint( t, optionalTarget ) {
  11319. const d = t * this.getLength();
  11320. const curveLengths = this.getCurveLengths();
  11321. let i = 0;
  11322. // To think about boundaries points.
  11323. while ( i < curveLengths.length ) {
  11324. if ( curveLengths[ i ] >= d ) {
  11325. const diff = curveLengths[ i ] - d;
  11326. const curve = this.curves[ i ];
  11327. const segmentLength = curve.getLength();
  11328. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  11329. return curve.getPointAt( u, optionalTarget );
  11330. }
  11331. i ++;
  11332. }
  11333. return null;
  11334. // loop where sum != 0, sum > d , sum+1 <d
  11335. }
  11336. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11337. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11338. // getPoint() depends on getLength
  11339. getLength() {
  11340. const lens = this.getCurveLengths();
  11341. return lens[ lens.length - 1 ];
  11342. }
  11343. // cacheLengths must be recalculated.
  11344. updateArcLengths() {
  11345. this.needsUpdate = true;
  11346. this.cacheLengths = null;
  11347. this.getCurveLengths();
  11348. }
  11349. // Compute lengths and cache them
  11350. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11351. getCurveLengths() {
  11352. // We use cache values if curves and cache array are same length
  11353. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  11354. return this.cacheLengths;
  11355. }
  11356. // Get length of sub-curve
  11357. // Push sums into cached array
  11358. const lengths = [];
  11359. let sums = 0;
  11360. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11361. sums += this.curves[ i ].getLength();
  11362. lengths.push( sums );
  11363. }
  11364. this.cacheLengths = lengths;
  11365. return lengths;
  11366. }
  11367. getSpacedPoints( divisions = 40 ) {
  11368. const points = [];
  11369. for ( let i = 0; i <= divisions; i ++ ) {
  11370. points.push( this.getPoint( i / divisions ) );
  11371. }
  11372. if ( this.autoClose ) {
  11373. points.push( points[ 0 ] );
  11374. }
  11375. return points;
  11376. }
  11377. getPoints( divisions = 12 ) {
  11378. const points = [];
  11379. let last;
  11380. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  11381. const curve = curves[ i ];
  11382. const resolution = curve.isEllipseCurve ? divisions * 2
  11383. : ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
  11384. : curve.isSplineCurve ? divisions * curve.points.length
  11385. : divisions;
  11386. const pts = curve.getPoints( resolution );
  11387. for ( let j = 0; j < pts.length; j ++ ) {
  11388. const point = pts[ j ];
  11389. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  11390. points.push( point );
  11391. last = point;
  11392. }
  11393. }
  11394. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  11395. points.push( points[ 0 ] );
  11396. }
  11397. return points;
  11398. }
  11399. copy( source ) {
  11400. super.copy( source );
  11401. this.curves = [];
  11402. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  11403. const curve = source.curves[ i ];
  11404. this.curves.push( curve.clone() );
  11405. }
  11406. this.autoClose = source.autoClose;
  11407. return this;
  11408. }
  11409. toJSON() {
  11410. const data = super.toJSON();
  11411. data.autoClose = this.autoClose;
  11412. data.curves = [];
  11413. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11414. const curve = this.curves[ i ];
  11415. data.curves.push( curve.toJSON() );
  11416. }
  11417. return data;
  11418. }
  11419. fromJSON( json ) {
  11420. super.fromJSON( json );
  11421. this.autoClose = json.autoClose;
  11422. this.curves = [];
  11423. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  11424. const curve = json.curves[ i ];
  11425. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  11426. }
  11427. return this;
  11428. }
  11429. }
  11430. class Path extends CurvePath {
  11431. constructor( points ) {
  11432. super();
  11433. this.type = 'Path';
  11434. this.currentPoint = new Vector2();
  11435. if ( points ) {
  11436. this.setFromPoints( points );
  11437. }
  11438. }
  11439. setFromPoints( points ) {
  11440. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  11441. for ( let i = 1, l = points.length; i < l; i ++ ) {
  11442. this.lineTo( points[ i ].x, points[ i ].y );
  11443. }
  11444. return this;
  11445. }
  11446. moveTo( x, y ) {
  11447. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  11448. return this;
  11449. }
  11450. lineTo( x, y ) {
  11451. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  11452. this.curves.push( curve );
  11453. this.currentPoint.set( x, y );
  11454. return this;
  11455. }
  11456. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  11457. const curve = new QuadraticBezierCurve(
  11458. this.currentPoint.clone(),
  11459. new Vector2( aCPx, aCPy ),
  11460. new Vector2( aX, aY )
  11461. );
  11462. this.curves.push( curve );
  11463. this.currentPoint.set( aX, aY );
  11464. return this;
  11465. }
  11466. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  11467. const curve = new CubicBezierCurve(
  11468. this.currentPoint.clone(),
  11469. new Vector2( aCP1x, aCP1y ),
  11470. new Vector2( aCP2x, aCP2y ),
  11471. new Vector2( aX, aY )
  11472. );
  11473. this.curves.push( curve );
  11474. this.currentPoint.set( aX, aY );
  11475. return this;
  11476. }
  11477. splineThru( pts /*Array of Vector*/ ) {
  11478. const npts = [ this.currentPoint.clone() ].concat( pts );
  11479. const curve = new SplineCurve( npts );
  11480. this.curves.push( curve );
  11481. this.currentPoint.copy( pts[ pts.length - 1 ] );
  11482. return this;
  11483. }
  11484. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11485. const x0 = this.currentPoint.x;
  11486. const y0 = this.currentPoint.y;
  11487. this.absarc( aX + x0, aY + y0, aRadius,
  11488. aStartAngle, aEndAngle, aClockwise );
  11489. return this;
  11490. }
  11491. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11492. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  11493. return this;
  11494. }
  11495. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11496. const x0 = this.currentPoint.x;
  11497. const y0 = this.currentPoint.y;
  11498. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11499. return this;
  11500. }
  11501. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11502. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11503. if ( this.curves.length > 0 ) {
  11504. // if a previous curve is present, attempt to join
  11505. const firstPoint = curve.getPoint( 0 );
  11506. if ( ! firstPoint.equals( this.currentPoint ) ) {
  11507. this.lineTo( firstPoint.x, firstPoint.y );
  11508. }
  11509. }
  11510. this.curves.push( curve );
  11511. const lastPoint = curve.getPoint( 1 );
  11512. this.currentPoint.copy( lastPoint );
  11513. return this;
  11514. }
  11515. copy( source ) {
  11516. super.copy( source );
  11517. this.currentPoint.copy( source.currentPoint );
  11518. return this;
  11519. }
  11520. toJSON() {
  11521. const data = super.toJSON();
  11522. data.currentPoint = this.currentPoint.toArray();
  11523. return data;
  11524. }
  11525. fromJSON( json ) {
  11526. super.fromJSON( json );
  11527. this.currentPoint.fromArray( json.currentPoint );
  11528. return this;
  11529. }
  11530. }
  11531. class LatheGeometry extends BufferGeometry {
  11532. constructor( points = [ new Vector2( 0, - 0.5 ), new Vector2( 0.5, 0 ), new Vector2( 0, 0.5 ) ], segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
  11533. super();
  11534. this.type = 'LatheGeometry';
  11535. this.parameters = {
  11536. points: points,
  11537. segments: segments,
  11538. phiStart: phiStart,
  11539. phiLength: phiLength
  11540. };
  11541. segments = Math.floor( segments );
  11542. // clamp phiLength so it's in range of [ 0, 2PI ]
  11543. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  11544. // buffers
  11545. const indices = [];
  11546. const vertices = [];
  11547. const uvs = [];
  11548. const initNormals = [];
  11549. const normals = [];
  11550. // helper variables
  11551. const inverseSegments = 1.0 / segments;
  11552. const vertex = new Vector3();
  11553. const uv = new Vector2();
  11554. const normal = new Vector3();
  11555. const curNormal = new Vector3();
  11556. const prevNormal = new Vector3();
  11557. let dx = 0;
  11558. let dy = 0;
  11559. // pre-compute normals for initial "meridian"
  11560. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11561. switch ( j ) {
  11562. case 0: // special handling for 1st vertex on path
  11563. dx = points[ j + 1 ].x - points[ j ].x;
  11564. dy = points[ j + 1 ].y - points[ j ].y;
  11565. normal.x = dy * 1.0;
  11566. normal.y = - dx;
  11567. normal.z = dy * 0.0;
  11568. prevNormal.copy( normal );
  11569. normal.normalize();
  11570. initNormals.push( normal.x, normal.y, normal.z );
  11571. break;
  11572. case ( points.length - 1 ): // special handling for last Vertex on path
  11573. initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
  11574. break;
  11575. default: // default handling for all vertices in between
  11576. dx = points[ j + 1 ].x - points[ j ].x;
  11577. dy = points[ j + 1 ].y - points[ j ].y;
  11578. normal.x = dy * 1.0;
  11579. normal.y = - dx;
  11580. normal.z = dy * 0.0;
  11581. curNormal.copy( normal );
  11582. normal.x += prevNormal.x;
  11583. normal.y += prevNormal.y;
  11584. normal.z += prevNormal.z;
  11585. normal.normalize();
  11586. initNormals.push( normal.x, normal.y, normal.z );
  11587. prevNormal.copy( curNormal );
  11588. }
  11589. }
  11590. // generate vertices, uvs and normals
  11591. for ( let i = 0; i <= segments; i ++ ) {
  11592. const phi = phiStart + i * inverseSegments * phiLength;
  11593. const sin = Math.sin( phi );
  11594. const cos = Math.cos( phi );
  11595. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11596. // vertex
  11597. vertex.x = points[ j ].x * sin;
  11598. vertex.y = points[ j ].y;
  11599. vertex.z = points[ j ].x * cos;
  11600. vertices.push( vertex.x, vertex.y, vertex.z );
  11601. // uv
  11602. uv.x = i / segments;
  11603. uv.y = j / ( points.length - 1 );
  11604. uvs.push( uv.x, uv.y );
  11605. // normal
  11606. const x = initNormals[ 3 * j + 0 ] * sin;
  11607. const y = initNormals[ 3 * j + 1 ];
  11608. const z = initNormals[ 3 * j + 0 ] * cos;
  11609. normals.push( x, y, z );
  11610. }
  11611. }
  11612. // indices
  11613. for ( let i = 0; i < segments; i ++ ) {
  11614. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  11615. const base = j + i * points.length;
  11616. const a = base;
  11617. const b = base + points.length;
  11618. const c = base + points.length + 1;
  11619. const d = base + 1;
  11620. // faces
  11621. indices.push( a, b, d );
  11622. indices.push( c, d, b );
  11623. }
  11624. }
  11625. // build geometry
  11626. this.setIndex( indices );
  11627. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11628. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11629. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11630. }
  11631. copy( source ) {
  11632. super.copy( source );
  11633. this.parameters = Object.assign( {}, source.parameters );
  11634. return this;
  11635. }
  11636. static fromJSON( data ) {
  11637. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  11638. }
  11639. }
  11640. class CapsuleGeometry extends LatheGeometry {
  11641. constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
  11642. const path = new Path();
  11643. path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
  11644. path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
  11645. super( path.getPoints( capSegments ), radialSegments );
  11646. this.type = 'CapsuleGeometry';
  11647. this.parameters = {
  11648. radius: radius,
  11649. length: length,
  11650. capSegments: capSegments,
  11651. radialSegments: radialSegments,
  11652. };
  11653. }
  11654. static fromJSON( data ) {
  11655. return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
  11656. }
  11657. }
  11658. class CircleGeometry extends BufferGeometry {
  11659. constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11660. super();
  11661. this.type = 'CircleGeometry';
  11662. this.parameters = {
  11663. radius: radius,
  11664. segments: segments,
  11665. thetaStart: thetaStart,
  11666. thetaLength: thetaLength
  11667. };
  11668. segments = Math.max( 3, segments );
  11669. // buffers
  11670. const indices = [];
  11671. const vertices = [];
  11672. const normals = [];
  11673. const uvs = [];
  11674. // helper variables
  11675. const vertex = new Vector3();
  11676. const uv = new Vector2();
  11677. // center point
  11678. vertices.push( 0, 0, 0 );
  11679. normals.push( 0, 0, 1 );
  11680. uvs.push( 0.5, 0.5 );
  11681. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  11682. const segment = thetaStart + s / segments * thetaLength;
  11683. // vertex
  11684. vertex.x = radius * Math.cos( segment );
  11685. vertex.y = radius * Math.sin( segment );
  11686. vertices.push( vertex.x, vertex.y, vertex.z );
  11687. // normal
  11688. normals.push( 0, 0, 1 );
  11689. // uvs
  11690. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  11691. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  11692. uvs.push( uv.x, uv.y );
  11693. }
  11694. // indices
  11695. for ( let i = 1; i <= segments; i ++ ) {
  11696. indices.push( i, i + 1, 0 );
  11697. }
  11698. // build geometry
  11699. this.setIndex( indices );
  11700. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11701. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11702. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11703. }
  11704. copy( source ) {
  11705. super.copy( source );
  11706. this.parameters = Object.assign( {}, source.parameters );
  11707. return this;
  11708. }
  11709. static fromJSON( data ) {
  11710. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  11711. }
  11712. }
  11713. class CylinderGeometry extends BufferGeometry {
  11714. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11715. super();
  11716. this.type = 'CylinderGeometry';
  11717. this.parameters = {
  11718. radiusTop: radiusTop,
  11719. radiusBottom: radiusBottom,
  11720. height: height,
  11721. radialSegments: radialSegments,
  11722. heightSegments: heightSegments,
  11723. openEnded: openEnded,
  11724. thetaStart: thetaStart,
  11725. thetaLength: thetaLength
  11726. };
  11727. const scope = this;
  11728. radialSegments = Math.floor( radialSegments );
  11729. heightSegments = Math.floor( heightSegments );
  11730. // buffers
  11731. const indices = [];
  11732. const vertices = [];
  11733. const normals = [];
  11734. const uvs = [];
  11735. // helper variables
  11736. let index = 0;
  11737. const indexArray = [];
  11738. const halfHeight = height / 2;
  11739. let groupStart = 0;
  11740. // generate geometry
  11741. generateTorso();
  11742. if ( openEnded === false ) {
  11743. if ( radiusTop > 0 ) generateCap( true );
  11744. if ( radiusBottom > 0 ) generateCap( false );
  11745. }
  11746. // build geometry
  11747. this.setIndex( indices );
  11748. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11749. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11750. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11751. function generateTorso() {
  11752. const normal = new Vector3();
  11753. const vertex = new Vector3();
  11754. let groupCount = 0;
  11755. // this will be used to calculate the normal
  11756. const slope = ( radiusBottom - radiusTop ) / height;
  11757. // generate vertices, normals and uvs
  11758. for ( let y = 0; y <= heightSegments; y ++ ) {
  11759. const indexRow = [];
  11760. const v = y / heightSegments;
  11761. // calculate the radius of the current row
  11762. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  11763. for ( let x = 0; x <= radialSegments; x ++ ) {
  11764. const u = x / radialSegments;
  11765. const theta = u * thetaLength + thetaStart;
  11766. const sinTheta = Math.sin( theta );
  11767. const cosTheta = Math.cos( theta );
  11768. // vertex
  11769. vertex.x = radius * sinTheta;
  11770. vertex.y = - v * height + halfHeight;
  11771. vertex.z = radius * cosTheta;
  11772. vertices.push( vertex.x, vertex.y, vertex.z );
  11773. // normal
  11774. normal.set( sinTheta, slope, cosTheta ).normalize();
  11775. normals.push( normal.x, normal.y, normal.z );
  11776. // uv
  11777. uvs.push( u, 1 - v );
  11778. // save index of vertex in respective row
  11779. indexRow.push( index ++ );
  11780. }
  11781. // now save vertices of the row in our index array
  11782. indexArray.push( indexRow );
  11783. }
  11784. // generate indices
  11785. for ( let x = 0; x < radialSegments; x ++ ) {
  11786. for ( let y = 0; y < heightSegments; y ++ ) {
  11787. // we use the index array to access the correct indices
  11788. const a = indexArray[ y ][ x ];
  11789. const b = indexArray[ y + 1 ][ x ];
  11790. const c = indexArray[ y + 1 ][ x + 1 ];
  11791. const d = indexArray[ y ][ x + 1 ];
  11792. // faces
  11793. if ( radiusTop > 0 || y !== 0 ) {
  11794. indices.push( a, b, d );
  11795. groupCount += 3;
  11796. }
  11797. if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
  11798. indices.push( b, c, d );
  11799. groupCount += 3;
  11800. }
  11801. }
  11802. }
  11803. // add a group to the geometry. this will ensure multi material support
  11804. scope.addGroup( groupStart, groupCount, 0 );
  11805. // calculate new start value for groups
  11806. groupStart += groupCount;
  11807. }
  11808. function generateCap( top ) {
  11809. // save the index of the first center vertex
  11810. const centerIndexStart = index;
  11811. const uv = new Vector2();
  11812. const vertex = new Vector3();
  11813. let groupCount = 0;
  11814. const radius = ( top === true ) ? radiusTop : radiusBottom;
  11815. const sign = ( top === true ) ? 1 : - 1;
  11816. // first we generate the center vertex data of the cap.
  11817. // because the geometry needs one set of uvs per face,
  11818. // we must generate a center vertex per face/segment
  11819. for ( let x = 1; x <= radialSegments; x ++ ) {
  11820. // vertex
  11821. vertices.push( 0, halfHeight * sign, 0 );
  11822. // normal
  11823. normals.push( 0, sign, 0 );
  11824. // uv
  11825. uvs.push( 0.5, 0.5 );
  11826. // increase index
  11827. index ++;
  11828. }
  11829. // save the index of the last center vertex
  11830. const centerIndexEnd = index;
  11831. // now we generate the surrounding vertices, normals and uvs
  11832. for ( let x = 0; x <= radialSegments; x ++ ) {
  11833. const u = x / radialSegments;
  11834. const theta = u * thetaLength + thetaStart;
  11835. const cosTheta = Math.cos( theta );
  11836. const sinTheta = Math.sin( theta );
  11837. // vertex
  11838. vertex.x = radius * sinTheta;
  11839. vertex.y = halfHeight * sign;
  11840. vertex.z = radius * cosTheta;
  11841. vertices.push( vertex.x, vertex.y, vertex.z );
  11842. // normal
  11843. normals.push( 0, sign, 0 );
  11844. // uv
  11845. uv.x = ( cosTheta * 0.5 ) + 0.5;
  11846. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  11847. uvs.push( uv.x, uv.y );
  11848. // increase index
  11849. index ++;
  11850. }
  11851. // generate indices
  11852. for ( let x = 0; x < radialSegments; x ++ ) {
  11853. const c = centerIndexStart + x;
  11854. const i = centerIndexEnd + x;
  11855. if ( top === true ) {
  11856. // face top
  11857. indices.push( i, i + 1, c );
  11858. } else {
  11859. // face bottom
  11860. indices.push( i + 1, i, c );
  11861. }
  11862. groupCount += 3;
  11863. }
  11864. // add a group to the geometry. this will ensure multi material support
  11865. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  11866. // calculate new start value for groups
  11867. groupStart += groupCount;
  11868. }
  11869. }
  11870. copy( source ) {
  11871. super.copy( source );
  11872. this.parameters = Object.assign( {}, source.parameters );
  11873. return this;
  11874. }
  11875. static fromJSON( data ) {
  11876. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11877. }
  11878. }
  11879. class ConeGeometry extends CylinderGeometry {
  11880. constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11881. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  11882. this.type = 'ConeGeometry';
  11883. this.parameters = {
  11884. radius: radius,
  11885. height: height,
  11886. radialSegments: radialSegments,
  11887. heightSegments: heightSegments,
  11888. openEnded: openEnded,
  11889. thetaStart: thetaStart,
  11890. thetaLength: thetaLength
  11891. };
  11892. }
  11893. static fromJSON( data ) {
  11894. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11895. }
  11896. }
  11897. class PolyhedronGeometry extends BufferGeometry {
  11898. constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
  11899. super();
  11900. this.type = 'PolyhedronGeometry';
  11901. this.parameters = {
  11902. vertices: vertices,
  11903. indices: indices,
  11904. radius: radius,
  11905. detail: detail
  11906. };
  11907. // default buffer data
  11908. const vertexBuffer = [];
  11909. const uvBuffer = [];
  11910. // the subdivision creates the vertex buffer data
  11911. subdivide( detail );
  11912. // all vertices should lie on a conceptual sphere with a given radius
  11913. applyRadius( radius );
  11914. // finally, create the uv data
  11915. generateUVs();
  11916. // build non-indexed geometry
  11917. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  11918. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  11919. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  11920. if ( detail === 0 ) {
  11921. this.computeVertexNormals(); // flat normals
  11922. } else {
  11923. this.normalizeNormals(); // smooth normals
  11924. }
  11925. // helper functions
  11926. function subdivide( detail ) {
  11927. const a = new Vector3();
  11928. const b = new Vector3();
  11929. const c = new Vector3();
  11930. // iterate over all faces and apply a subdivision with the given detail value
  11931. for ( let i = 0; i < indices.length; i += 3 ) {
  11932. // get the vertices of the face
  11933. getVertexByIndex( indices[ i + 0 ], a );
  11934. getVertexByIndex( indices[ i + 1 ], b );
  11935. getVertexByIndex( indices[ i + 2 ], c );
  11936. // perform subdivision
  11937. subdivideFace( a, b, c, detail );
  11938. }
  11939. }
  11940. function subdivideFace( a, b, c, detail ) {
  11941. const cols = detail + 1;
  11942. // we use this multidimensional array as a data structure for creating the subdivision
  11943. const v = [];
  11944. // construct all of the vertices for this subdivision
  11945. for ( let i = 0; i <= cols; i ++ ) {
  11946. v[ i ] = [];
  11947. const aj = a.clone().lerp( c, i / cols );
  11948. const bj = b.clone().lerp( c, i / cols );
  11949. const rows = cols - i;
  11950. for ( let j = 0; j <= rows; j ++ ) {
  11951. if ( j === 0 && i === cols ) {
  11952. v[ i ][ j ] = aj;
  11953. } else {
  11954. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  11955. }
  11956. }
  11957. }
  11958. // construct all of the faces
  11959. for ( let i = 0; i < cols; i ++ ) {
  11960. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  11961. const k = Math.floor( j / 2 );
  11962. if ( j % 2 === 0 ) {
  11963. pushVertex( v[ i ][ k + 1 ] );
  11964. pushVertex( v[ i + 1 ][ k ] );
  11965. pushVertex( v[ i ][ k ] );
  11966. } else {
  11967. pushVertex( v[ i ][ k + 1 ] );
  11968. pushVertex( v[ i + 1 ][ k + 1 ] );
  11969. pushVertex( v[ i + 1 ][ k ] );
  11970. }
  11971. }
  11972. }
  11973. }
  11974. function applyRadius( radius ) {
  11975. const vertex = new Vector3();
  11976. // iterate over the entire buffer and apply the radius to each vertex
  11977. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  11978. vertex.x = vertexBuffer[ i + 0 ];
  11979. vertex.y = vertexBuffer[ i + 1 ];
  11980. vertex.z = vertexBuffer[ i + 2 ];
  11981. vertex.normalize().multiplyScalar( radius );
  11982. vertexBuffer[ i + 0 ] = vertex.x;
  11983. vertexBuffer[ i + 1 ] = vertex.y;
  11984. vertexBuffer[ i + 2 ] = vertex.z;
  11985. }
  11986. }
  11987. function generateUVs() {
  11988. const vertex = new Vector3();
  11989. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  11990. vertex.x = vertexBuffer[ i + 0 ];
  11991. vertex.y = vertexBuffer[ i + 1 ];
  11992. vertex.z = vertexBuffer[ i + 2 ];
  11993. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  11994. const v = inclination( vertex ) / Math.PI + 0.5;
  11995. uvBuffer.push( u, 1 - v );
  11996. }
  11997. correctUVs();
  11998. correctSeam();
  11999. }
  12000. function correctSeam() {
  12001. // handle case when face straddles the seam, see #3269
  12002. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  12003. // uv data of a single face
  12004. const x0 = uvBuffer[ i + 0 ];
  12005. const x1 = uvBuffer[ i + 2 ];
  12006. const x2 = uvBuffer[ i + 4 ];
  12007. const max = Math.max( x0, x1, x2 );
  12008. const min = Math.min( x0, x1, x2 );
  12009. // 0.9 is somewhat arbitrary
  12010. if ( max > 0.9 && min < 0.1 ) {
  12011. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  12012. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  12013. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  12014. }
  12015. }
  12016. }
  12017. function pushVertex( vertex ) {
  12018. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  12019. }
  12020. function getVertexByIndex( index, vertex ) {
  12021. const stride = index * 3;
  12022. vertex.x = vertices[ stride + 0 ];
  12023. vertex.y = vertices[ stride + 1 ];
  12024. vertex.z = vertices[ stride + 2 ];
  12025. }
  12026. function correctUVs() {
  12027. const a = new Vector3();
  12028. const b = new Vector3();
  12029. const c = new Vector3();
  12030. const centroid = new Vector3();
  12031. const uvA = new Vector2();
  12032. const uvB = new Vector2();
  12033. const uvC = new Vector2();
  12034. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  12035. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  12036. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  12037. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  12038. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  12039. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  12040. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  12041. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  12042. const azi = azimuth( centroid );
  12043. correctUV( uvA, j + 0, a, azi );
  12044. correctUV( uvB, j + 2, b, azi );
  12045. correctUV( uvC, j + 4, c, azi );
  12046. }
  12047. }
  12048. function correctUV( uv, stride, vector, azimuth ) {
  12049. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  12050. uvBuffer[ stride ] = uv.x - 1;
  12051. }
  12052. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  12053. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  12054. }
  12055. }
  12056. // Angle around the Y axis, counter-clockwise when looking from above.
  12057. function azimuth( vector ) {
  12058. return Math.atan2( vector.z, - vector.x );
  12059. }
  12060. // Angle above the XZ plane.
  12061. function inclination( vector ) {
  12062. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  12063. }
  12064. }
  12065. copy( source ) {
  12066. super.copy( source );
  12067. this.parameters = Object.assign( {}, source.parameters );
  12068. return this;
  12069. }
  12070. static fromJSON( data ) {
  12071. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  12072. }
  12073. }
  12074. class DodecahedronGeometry extends PolyhedronGeometry {
  12075. constructor( radius = 1, detail = 0 ) {
  12076. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  12077. const r = 1 / t;
  12078. const vertices = [
  12079. // (±1, ±1, ±1)
  12080. - 1, - 1, - 1, - 1, - 1, 1,
  12081. - 1, 1, - 1, - 1, 1, 1,
  12082. 1, - 1, - 1, 1, - 1, 1,
  12083. 1, 1, - 1, 1, 1, 1,
  12084. // (0, ±1/φ, ±φ)
  12085. 0, - r, - t, 0, - r, t,
  12086. 0, r, - t, 0, r, t,
  12087. // (±1/φ, ±φ, 0)
  12088. - r, - t, 0, - r, t, 0,
  12089. r, - t, 0, r, t, 0,
  12090. // (±φ, 0, ±1/φ)
  12091. - t, 0, - r, t, 0, - r,
  12092. - t, 0, r, t, 0, r
  12093. ];
  12094. const indices = [
  12095. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  12096. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  12097. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  12098. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  12099. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  12100. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  12101. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  12102. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  12103. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  12104. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  12105. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  12106. 1, 12, 14, 1, 14, 5, 1, 5, 9
  12107. ];
  12108. super( vertices, indices, radius, detail );
  12109. this.type = 'DodecahedronGeometry';
  12110. this.parameters = {
  12111. radius: radius,
  12112. detail: detail
  12113. };
  12114. }
  12115. static fromJSON( data ) {
  12116. return new DodecahedronGeometry( data.radius, data.detail );
  12117. }
  12118. }
  12119. const _v0 = /*@__PURE__*/ new Vector3();
  12120. const _v1$1 = /*@__PURE__*/ new Vector3();
  12121. const _normal = /*@__PURE__*/ new Vector3();
  12122. const _triangle = /*@__PURE__*/ new Triangle();
  12123. class EdgesGeometry extends BufferGeometry {
  12124. constructor( geometry = null, thresholdAngle = 1 ) {
  12125. super();
  12126. this.type = 'EdgesGeometry';
  12127. this.parameters = {
  12128. geometry: geometry,
  12129. thresholdAngle: thresholdAngle
  12130. };
  12131. if ( geometry !== null ) {
  12132. const precisionPoints = 4;
  12133. const precision = Math.pow( 10, precisionPoints );
  12134. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  12135. const indexAttr = geometry.getIndex();
  12136. const positionAttr = geometry.getAttribute( 'position' );
  12137. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  12138. const indexArr = [ 0, 0, 0 ];
  12139. const vertKeys = [ 'a', 'b', 'c' ];
  12140. const hashes = new Array( 3 );
  12141. const edgeData = {};
  12142. const vertices = [];
  12143. for ( let i = 0; i < indexCount; i += 3 ) {
  12144. if ( indexAttr ) {
  12145. indexArr[ 0 ] = indexAttr.getX( i );
  12146. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  12147. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  12148. } else {
  12149. indexArr[ 0 ] = i;
  12150. indexArr[ 1 ] = i + 1;
  12151. indexArr[ 2 ] = i + 2;
  12152. }
  12153. const { a, b, c } = _triangle;
  12154. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  12155. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  12156. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  12157. _triangle.getNormal( _normal );
  12158. // create hashes for the edge from the vertices
  12159. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  12160. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  12161. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  12162. // skip degenerate triangles
  12163. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  12164. continue;
  12165. }
  12166. // iterate over every edge
  12167. for ( let j = 0; j < 3; j ++ ) {
  12168. // get the first and next vertex making up the edge
  12169. const jNext = ( j + 1 ) % 3;
  12170. const vecHash0 = hashes[ j ];
  12171. const vecHash1 = hashes[ jNext ];
  12172. const v0 = _triangle[ vertKeys[ j ] ];
  12173. const v1 = _triangle[ vertKeys[ jNext ] ];
  12174. const hash = `${ vecHash0 }_${ vecHash1 }`;
  12175. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  12176. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  12177. // if we found a sibling edge add it into the vertex array if
  12178. // it meets the angle threshold and delete the edge from the map.
  12179. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  12180. vertices.push( v0.x, v0.y, v0.z );
  12181. vertices.push( v1.x, v1.y, v1.z );
  12182. }
  12183. edgeData[ reverseHash ] = null;
  12184. } else if ( ! ( hash in edgeData ) ) {
  12185. // if we've already got an edge here then skip adding a new one
  12186. edgeData[ hash ] = {
  12187. index0: indexArr[ j ],
  12188. index1: indexArr[ jNext ],
  12189. normal: _normal.clone(),
  12190. };
  12191. }
  12192. }
  12193. }
  12194. // iterate over all remaining, unmatched edges and add them to the vertex array
  12195. for ( const key in edgeData ) {
  12196. if ( edgeData[ key ] ) {
  12197. const { index0, index1 } = edgeData[ key ];
  12198. _v0.fromBufferAttribute( positionAttr, index0 );
  12199. _v1$1.fromBufferAttribute( positionAttr, index1 );
  12200. vertices.push( _v0.x, _v0.y, _v0.z );
  12201. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  12202. }
  12203. }
  12204. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  12205. }
  12206. }
  12207. copy( source ) {
  12208. super.copy( source );
  12209. this.parameters = Object.assign( {}, source.parameters );
  12210. return this;
  12211. }
  12212. }
  12213. class Shape extends Path {
  12214. constructor( points ) {
  12215. super( points );
  12216. this.uuid = generateUUID();
  12217. this.type = 'Shape';
  12218. this.holes = [];
  12219. }
  12220. getPointsHoles( divisions ) {
  12221. const holesPts = [];
  12222. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12223. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  12224. }
  12225. return holesPts;
  12226. }
  12227. // get points of shape and holes (keypoints based on segments parameter)
  12228. extractPoints( divisions ) {
  12229. return {
  12230. shape: this.getPoints( divisions ),
  12231. holes: this.getPointsHoles( divisions )
  12232. };
  12233. }
  12234. copy( source ) {
  12235. super.copy( source );
  12236. this.holes = [];
  12237. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  12238. const hole = source.holes[ i ];
  12239. this.holes.push( hole.clone() );
  12240. }
  12241. return this;
  12242. }
  12243. toJSON() {
  12244. const data = super.toJSON();
  12245. data.uuid = this.uuid;
  12246. data.holes = [];
  12247. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12248. const hole = this.holes[ i ];
  12249. data.holes.push( hole.toJSON() );
  12250. }
  12251. return data;
  12252. }
  12253. fromJSON( json ) {
  12254. super.fromJSON( json );
  12255. this.uuid = json.uuid;
  12256. this.holes = [];
  12257. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  12258. const hole = json.holes[ i ];
  12259. this.holes.push( new Path().fromJSON( hole ) );
  12260. }
  12261. return this;
  12262. }
  12263. }
  12264. /**
  12265. * Port from https://github.com/mapbox/earcut (v2.2.4)
  12266. */
  12267. const Earcut = {
  12268. triangulate: function ( data, holeIndices, dim = 2 ) {
  12269. const hasHoles = holeIndices && holeIndices.length;
  12270. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  12271. let outerNode = linkedList( data, 0, outerLen, dim, true );
  12272. const triangles = [];
  12273. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  12274. let minX, minY, maxX, maxY, x, y, invSize;
  12275. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  12276. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  12277. if ( data.length > 80 * dim ) {
  12278. minX = maxX = data[ 0 ];
  12279. minY = maxY = data[ 1 ];
  12280. for ( let i = dim; i < outerLen; i += dim ) {
  12281. x = data[ i ];
  12282. y = data[ i + 1 ];
  12283. if ( x < minX ) minX = x;
  12284. if ( y < minY ) minY = y;
  12285. if ( x > maxX ) maxX = x;
  12286. if ( y > maxY ) maxY = y;
  12287. }
  12288. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  12289. invSize = Math.max( maxX - minX, maxY - minY );
  12290. invSize = invSize !== 0 ? 32767 / invSize : 0;
  12291. }
  12292. earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 );
  12293. return triangles;
  12294. }
  12295. };
  12296. // create a circular doubly linked list from polygon points in the specified winding order
  12297. function linkedList( data, start, end, dim, clockwise ) {
  12298. let i, last;
  12299. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  12300. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12301. } else {
  12302. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12303. }
  12304. if ( last && equals( last, last.next ) ) {
  12305. removeNode( last );
  12306. last = last.next;
  12307. }
  12308. return last;
  12309. }
  12310. // eliminate colinear or duplicate points
  12311. function filterPoints( start, end ) {
  12312. if ( ! start ) return start;
  12313. if ( ! end ) end = start;
  12314. let p = start,
  12315. again;
  12316. do {
  12317. again = false;
  12318. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  12319. removeNode( p );
  12320. p = end = p.prev;
  12321. if ( p === p.next ) break;
  12322. again = true;
  12323. } else {
  12324. p = p.next;
  12325. }
  12326. } while ( again || p !== end );
  12327. return end;
  12328. }
  12329. // main ear slicing loop which triangulates a polygon (given as a linked list)
  12330. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  12331. if ( ! ear ) return;
  12332. // interlink polygon nodes in z-order
  12333. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  12334. let stop = ear,
  12335. prev, next;
  12336. // iterate through ears, slicing them one by one
  12337. while ( ear.prev !== ear.next ) {
  12338. prev = ear.prev;
  12339. next = ear.next;
  12340. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  12341. // cut off the triangle
  12342. triangles.push( prev.i / dim | 0 );
  12343. triangles.push( ear.i / dim | 0 );
  12344. triangles.push( next.i / dim | 0 );
  12345. removeNode( ear );
  12346. // skipping the next vertex leads to less sliver triangles
  12347. ear = next.next;
  12348. stop = next.next;
  12349. continue;
  12350. }
  12351. ear = next;
  12352. // if we looped through the whole remaining polygon and can't find any more ears
  12353. if ( ear === stop ) {
  12354. // try filtering points and slicing again
  12355. if ( ! pass ) {
  12356. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  12357. // if this didn't work, try curing all small self-intersections locally
  12358. } else if ( pass === 1 ) {
  12359. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  12360. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  12361. // as a last resort, try splitting the remaining polygon into two
  12362. } else if ( pass === 2 ) {
  12363. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  12364. }
  12365. break;
  12366. }
  12367. }
  12368. }
  12369. // check whether a polygon node forms a valid ear with adjacent nodes
  12370. function isEar( ear ) {
  12371. const a = ear.prev,
  12372. b = ear,
  12373. c = ear.next;
  12374. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12375. // now make sure we don't have other points inside the potential ear
  12376. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12377. // triangle bbox; min & max are calculated like this for speed
  12378. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12379. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12380. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12381. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12382. let p = c.next;
  12383. while ( p !== a ) {
  12384. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  12385. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) &&
  12386. area( p.prev, p, p.next ) >= 0 ) return false;
  12387. p = p.next;
  12388. }
  12389. return true;
  12390. }
  12391. function isEarHashed( ear, minX, minY, invSize ) {
  12392. const a = ear.prev,
  12393. b = ear,
  12394. c = ear.next;
  12395. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12396. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12397. // triangle bbox; min & max are calculated like this for speed
  12398. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12399. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12400. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12401. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12402. // z-order range for the current triangle bbox;
  12403. const minZ = zOrder( x0, y0, minX, minY, invSize ),
  12404. maxZ = zOrder( x1, y1, minX, minY, invSize );
  12405. let p = ear.prevZ,
  12406. n = ear.nextZ;
  12407. // look for points inside the triangle in both directions
  12408. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  12409. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12410. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12411. p = p.prevZ;
  12412. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12413. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12414. n = n.nextZ;
  12415. }
  12416. // look for remaining points in decreasing z-order
  12417. while ( p && p.z >= minZ ) {
  12418. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12419. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12420. p = p.prevZ;
  12421. }
  12422. // look for remaining points in increasing z-order
  12423. while ( n && n.z <= maxZ ) {
  12424. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12425. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12426. n = n.nextZ;
  12427. }
  12428. return true;
  12429. }
  12430. // go through all polygon nodes and cure small local self-intersections
  12431. function cureLocalIntersections( start, triangles, dim ) {
  12432. let p = start;
  12433. do {
  12434. const a = p.prev,
  12435. b = p.next.next;
  12436. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  12437. triangles.push( a.i / dim | 0 );
  12438. triangles.push( p.i / dim | 0 );
  12439. triangles.push( b.i / dim | 0 );
  12440. // remove two nodes involved
  12441. removeNode( p );
  12442. removeNode( p.next );
  12443. p = start = b;
  12444. }
  12445. p = p.next;
  12446. } while ( p !== start );
  12447. return filterPoints( p );
  12448. }
  12449. // try splitting polygon into two and triangulate them independently
  12450. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  12451. // look for a valid diagonal that divides the polygon into two
  12452. let a = start;
  12453. do {
  12454. let b = a.next.next;
  12455. while ( b !== a.prev ) {
  12456. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  12457. // split the polygon in two by the diagonal
  12458. let c = splitPolygon( a, b );
  12459. // filter colinear points around the cuts
  12460. a = filterPoints( a, a.next );
  12461. c = filterPoints( c, c.next );
  12462. // run earcut on each half
  12463. earcutLinked( a, triangles, dim, minX, minY, invSize, 0 );
  12464. earcutLinked( c, triangles, dim, minX, minY, invSize, 0 );
  12465. return;
  12466. }
  12467. b = b.next;
  12468. }
  12469. a = a.next;
  12470. } while ( a !== start );
  12471. }
  12472. // link every hole into the outer loop, producing a single-ring polygon without holes
  12473. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  12474. const queue = [];
  12475. let i, len, start, end, list;
  12476. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  12477. start = holeIndices[ i ] * dim;
  12478. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  12479. list = linkedList( data, start, end, dim, false );
  12480. if ( list === list.next ) list.steiner = true;
  12481. queue.push( getLeftmost( list ) );
  12482. }
  12483. queue.sort( compareX );
  12484. // process holes from left to right
  12485. for ( i = 0; i < queue.length; i ++ ) {
  12486. outerNode = eliminateHole( queue[ i ], outerNode );
  12487. }
  12488. return outerNode;
  12489. }
  12490. function compareX( a, b ) {
  12491. return a.x - b.x;
  12492. }
  12493. // find a bridge between vertices that connects hole with an outer ring and link it
  12494. function eliminateHole( hole, outerNode ) {
  12495. const bridge = findHoleBridge( hole, outerNode );
  12496. if ( ! bridge ) {
  12497. return outerNode;
  12498. }
  12499. const bridgeReverse = splitPolygon( bridge, hole );
  12500. // filter collinear points around the cuts
  12501. filterPoints( bridgeReverse, bridgeReverse.next );
  12502. return filterPoints( bridge, bridge.next );
  12503. }
  12504. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  12505. function findHoleBridge( hole, outerNode ) {
  12506. let p = outerNode,
  12507. qx = - Infinity,
  12508. m;
  12509. const hx = hole.x, hy = hole.y;
  12510. // find a segment intersected by a ray from the hole's leftmost point to the left;
  12511. // segment's endpoint with lesser x will be potential connection point
  12512. do {
  12513. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  12514. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  12515. if ( x <= hx && x > qx ) {
  12516. qx = x;
  12517. m = p.x < p.next.x ? p : p.next;
  12518. if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint
  12519. }
  12520. }
  12521. p = p.next;
  12522. } while ( p !== outerNode );
  12523. if ( ! m ) return null;
  12524. // look for points inside the triangle of hole point, segment intersection and endpoint;
  12525. // if there are no points found, we have a valid connection;
  12526. // otherwise choose the point of the minimum angle with the ray as connection point
  12527. const stop = m,
  12528. mx = m.x,
  12529. my = m.y;
  12530. let tanMin = Infinity, tan;
  12531. p = m;
  12532. do {
  12533. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  12534. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  12535. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  12536. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  12537. m = p;
  12538. tanMin = tan;
  12539. }
  12540. }
  12541. p = p.next;
  12542. } while ( p !== stop );
  12543. return m;
  12544. }
  12545. // whether sector in vertex m contains sector in vertex p in the same coordinates
  12546. function sectorContainsSector( m, p ) {
  12547. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  12548. }
  12549. // interlink polygon nodes in z-order
  12550. function indexCurve( start, minX, minY, invSize ) {
  12551. let p = start;
  12552. do {
  12553. if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  12554. p.prevZ = p.prev;
  12555. p.nextZ = p.next;
  12556. p = p.next;
  12557. } while ( p !== start );
  12558. p.prevZ.nextZ = null;
  12559. p.prevZ = null;
  12560. sortLinked( p );
  12561. }
  12562. // Simon Tatham's linked list merge sort algorithm
  12563. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  12564. function sortLinked( list ) {
  12565. let i, p, q, e, tail, numMerges, pSize, qSize,
  12566. inSize = 1;
  12567. do {
  12568. p = list;
  12569. list = null;
  12570. tail = null;
  12571. numMerges = 0;
  12572. while ( p ) {
  12573. numMerges ++;
  12574. q = p;
  12575. pSize = 0;
  12576. for ( i = 0; i < inSize; i ++ ) {
  12577. pSize ++;
  12578. q = q.nextZ;
  12579. if ( ! q ) break;
  12580. }
  12581. qSize = inSize;
  12582. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  12583. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  12584. e = p;
  12585. p = p.nextZ;
  12586. pSize --;
  12587. } else {
  12588. e = q;
  12589. q = q.nextZ;
  12590. qSize --;
  12591. }
  12592. if ( tail ) tail.nextZ = e;
  12593. else list = e;
  12594. e.prevZ = tail;
  12595. tail = e;
  12596. }
  12597. p = q;
  12598. }
  12599. tail.nextZ = null;
  12600. inSize *= 2;
  12601. } while ( numMerges > 1 );
  12602. return list;
  12603. }
  12604. // z-order of a point given coords and inverse of the longer side of data bbox
  12605. function zOrder( x, y, minX, minY, invSize ) {
  12606. // coords are transformed into non-negative 15-bit integer range
  12607. x = ( x - minX ) * invSize | 0;
  12608. y = ( y - minY ) * invSize | 0;
  12609. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  12610. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  12611. x = ( x | ( x << 2 ) ) & 0x33333333;
  12612. x = ( x | ( x << 1 ) ) & 0x55555555;
  12613. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  12614. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  12615. y = ( y | ( y << 2 ) ) & 0x33333333;
  12616. y = ( y | ( y << 1 ) ) & 0x55555555;
  12617. return x | ( y << 1 );
  12618. }
  12619. // find the leftmost node of a polygon ring
  12620. function getLeftmost( start ) {
  12621. let p = start,
  12622. leftmost = start;
  12623. do {
  12624. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  12625. p = p.next;
  12626. } while ( p !== start );
  12627. return leftmost;
  12628. }
  12629. // check if a point lies within a convex triangle
  12630. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  12631. return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) &&
  12632. ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) &&
  12633. ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py );
  12634. }
  12635. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  12636. function isValidDiagonal( a, b ) {
  12637. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  12638. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  12639. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  12640. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  12641. }
  12642. // signed area of a triangle
  12643. function area( p, q, r ) {
  12644. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  12645. }
  12646. // check if two points are equal
  12647. function equals( p1, p2 ) {
  12648. return p1.x === p2.x && p1.y === p2.y;
  12649. }
  12650. // check if two segments intersect
  12651. function intersects( p1, q1, p2, q2 ) {
  12652. const o1 = sign( area( p1, q1, p2 ) );
  12653. const o2 = sign( area( p1, q1, q2 ) );
  12654. const o3 = sign( area( p2, q2, p1 ) );
  12655. const o4 = sign( area( p2, q2, q1 ) );
  12656. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  12657. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  12658. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  12659. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  12660. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  12661. return false;
  12662. }
  12663. // for collinear points p, q, r, check if point q lies on segment pr
  12664. function onSegment( p, q, r ) {
  12665. return q.x <= Math.max( p.x, r.x ) && q.x >= Math.min( p.x, r.x ) && q.y <= Math.max( p.y, r.y ) && q.y >= Math.min( p.y, r.y );
  12666. }
  12667. function sign( num ) {
  12668. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  12669. }
  12670. // check if a polygon diagonal intersects any polygon segments
  12671. function intersectsPolygon( a, b ) {
  12672. let p = a;
  12673. do {
  12674. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  12675. intersects( p, p.next, a, b ) ) return true;
  12676. p = p.next;
  12677. } while ( p !== a );
  12678. return false;
  12679. }
  12680. // check if a polygon diagonal is locally inside the polygon
  12681. function locallyInside( a, b ) {
  12682. return area( a.prev, a, a.next ) < 0 ?
  12683. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  12684. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  12685. }
  12686. // check if the middle point of a polygon diagonal is inside the polygon
  12687. function middleInside( a, b ) {
  12688. let p = a,
  12689. inside = false;
  12690. const px = ( a.x + b.x ) / 2,
  12691. py = ( a.y + b.y ) / 2;
  12692. do {
  12693. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  12694. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  12695. inside = ! inside;
  12696. p = p.next;
  12697. } while ( p !== a );
  12698. return inside;
  12699. }
  12700. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  12701. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  12702. function splitPolygon( a, b ) {
  12703. const a2 = new Node( a.i, a.x, a.y ),
  12704. b2 = new Node( b.i, b.x, b.y ),
  12705. an = a.next,
  12706. bp = b.prev;
  12707. a.next = b;
  12708. b.prev = a;
  12709. a2.next = an;
  12710. an.prev = a2;
  12711. b2.next = a2;
  12712. a2.prev = b2;
  12713. bp.next = b2;
  12714. b2.prev = bp;
  12715. return b2;
  12716. }
  12717. // create a node and optionally link it with previous one (in a circular doubly linked list)
  12718. function insertNode( i, x, y, last ) {
  12719. const p = new Node( i, x, y );
  12720. if ( ! last ) {
  12721. p.prev = p;
  12722. p.next = p;
  12723. } else {
  12724. p.next = last.next;
  12725. p.prev = last;
  12726. last.next.prev = p;
  12727. last.next = p;
  12728. }
  12729. return p;
  12730. }
  12731. function removeNode( p ) {
  12732. p.next.prev = p.prev;
  12733. p.prev.next = p.next;
  12734. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  12735. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  12736. }
  12737. function Node( i, x, y ) {
  12738. // vertex index in coordinates array
  12739. this.i = i;
  12740. // vertex coordinates
  12741. this.x = x;
  12742. this.y = y;
  12743. // previous and next vertex nodes in a polygon ring
  12744. this.prev = null;
  12745. this.next = null;
  12746. // z-order curve value
  12747. this.z = 0;
  12748. // previous and next nodes in z-order
  12749. this.prevZ = null;
  12750. this.nextZ = null;
  12751. // indicates whether this is a steiner point
  12752. this.steiner = false;
  12753. }
  12754. function signedArea( data, start, end, dim ) {
  12755. let sum = 0;
  12756. for ( let i = start, j = end - dim; i < end; i += dim ) {
  12757. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  12758. j = i;
  12759. }
  12760. return sum;
  12761. }
  12762. class ShapeUtils {
  12763. // calculate area of the contour polygon
  12764. static area( contour ) {
  12765. const n = contour.length;
  12766. let a = 0.0;
  12767. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  12768. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  12769. }
  12770. return a * 0.5;
  12771. }
  12772. static isClockWise( pts ) {
  12773. return ShapeUtils.area( pts ) < 0;
  12774. }
  12775. static triangulateShape( contour, holes ) {
  12776. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  12777. const holeIndices = []; // array of hole indices
  12778. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  12779. removeDupEndPts( contour );
  12780. addContour( vertices, contour );
  12781. //
  12782. let holeIndex = contour.length;
  12783. holes.forEach( removeDupEndPts );
  12784. for ( let i = 0; i < holes.length; i ++ ) {
  12785. holeIndices.push( holeIndex );
  12786. holeIndex += holes[ i ].length;
  12787. addContour( vertices, holes[ i ] );
  12788. }
  12789. //
  12790. const triangles = Earcut.triangulate( vertices, holeIndices );
  12791. //
  12792. for ( let i = 0; i < triangles.length; i += 3 ) {
  12793. faces.push( triangles.slice( i, i + 3 ) );
  12794. }
  12795. return faces;
  12796. }
  12797. }
  12798. function removeDupEndPts( points ) {
  12799. const l = points.length;
  12800. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  12801. points.pop();
  12802. }
  12803. }
  12804. function addContour( vertices, contour ) {
  12805. for ( let i = 0; i < contour.length; i ++ ) {
  12806. vertices.push( contour[ i ].x );
  12807. vertices.push( contour[ i ].y );
  12808. }
  12809. }
  12810. /**
  12811. * Creates extruded geometry from a path shape.
  12812. *
  12813. * parameters = {
  12814. *
  12815. * curveSegments: <int>, // number of points on the curves
  12816. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  12817. * depth: <float>, // Depth to extrude the shape
  12818. *
  12819. * bevelEnabled: <bool>, // turn on bevel
  12820. * bevelThickness: <float>, // how deep into the original shape bevel goes
  12821. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  12822. * bevelOffset: <float>, // how far from shape outline does bevel start
  12823. * bevelSegments: <int>, // number of bevel layers
  12824. *
  12825. * extrudePath: <THREE.Curve> // curve to extrude shape along
  12826. *
  12827. * UVGenerator: <Object> // object that provides UV generator functions
  12828. *
  12829. * }
  12830. */
  12831. class ExtrudeGeometry extends BufferGeometry {
  12832. constructor( shapes = new Shape( [ new Vector2( 0.5, 0.5 ), new Vector2( - 0.5, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), options = {} ) {
  12833. super();
  12834. this.type = 'ExtrudeGeometry';
  12835. this.parameters = {
  12836. shapes: shapes,
  12837. options: options
  12838. };
  12839. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  12840. const scope = this;
  12841. const verticesArray = [];
  12842. const uvArray = [];
  12843. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  12844. const shape = shapes[ i ];
  12845. addShape( shape );
  12846. }
  12847. // build geometry
  12848. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  12849. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  12850. this.computeVertexNormals();
  12851. // functions
  12852. function addShape( shape ) {
  12853. const placeholder = [];
  12854. // options
  12855. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  12856. const steps = options.steps !== undefined ? options.steps : 1;
  12857. const depth = options.depth !== undefined ? options.depth : 1;
  12858. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  12859. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
  12860. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
  12861. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  12862. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  12863. const extrudePath = options.extrudePath;
  12864. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  12865. //
  12866. let extrudePts, extrudeByPath = false;
  12867. let splineTube, binormal, normal, position2;
  12868. if ( extrudePath ) {
  12869. extrudePts = extrudePath.getSpacedPoints( steps );
  12870. extrudeByPath = true;
  12871. bevelEnabled = false; // bevels not supported for path extrusion
  12872. // SETUP TNB variables
  12873. // TODO1 - have a .isClosed in spline?
  12874. splineTube = extrudePath.computeFrenetFrames( steps, false );
  12875. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  12876. binormal = new Vector3();
  12877. normal = new Vector3();
  12878. position2 = new Vector3();
  12879. }
  12880. // Safeguards if bevels are not enabled
  12881. if ( ! bevelEnabled ) {
  12882. bevelSegments = 0;
  12883. bevelThickness = 0;
  12884. bevelSize = 0;
  12885. bevelOffset = 0;
  12886. }
  12887. // Variables initialization
  12888. const shapePoints = shape.extractPoints( curveSegments );
  12889. let vertices = shapePoints.shape;
  12890. const holes = shapePoints.holes;
  12891. const reverse = ! ShapeUtils.isClockWise( vertices );
  12892. if ( reverse ) {
  12893. vertices = vertices.reverse();
  12894. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  12895. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12896. const ahole = holes[ h ];
  12897. if ( ShapeUtils.isClockWise( ahole ) ) {
  12898. holes[ h ] = ahole.reverse();
  12899. }
  12900. }
  12901. }
  12902. const faces = ShapeUtils.triangulateShape( vertices, holes );
  12903. /* Vertices */
  12904. const contour = vertices; // vertices has all points but contour has only points of circumference
  12905. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12906. const ahole = holes[ h ];
  12907. vertices = vertices.concat( ahole );
  12908. }
  12909. function scalePt2( pt, vec, size ) {
  12910. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  12911. return pt.clone().addScaledVector( vec, size );
  12912. }
  12913. const vlen = vertices.length, flen = faces.length;
  12914. // Find directions for point movement
  12915. function getBevelVec( inPt, inPrev, inNext ) {
  12916. // computes for inPt the corresponding point inPt' on a new contour
  12917. // shifted by 1 unit (length of normalized vector) to the left
  12918. // if we walk along contour clockwise, this new contour is outside the old one
  12919. //
  12920. // inPt' is the intersection of the two lines parallel to the two
  12921. // adjacent edges of inPt at a distance of 1 unit on the left side.
  12922. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  12923. // good reading for geometry algorithms (here: line-line intersection)
  12924. // http://geomalgorithms.com/a05-_intersect-1.html
  12925. const v_prev_x = inPt.x - inPrev.x,
  12926. v_prev_y = inPt.y - inPrev.y;
  12927. const v_next_x = inNext.x - inPt.x,
  12928. v_next_y = inNext.y - inPt.y;
  12929. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  12930. // check for collinear edges
  12931. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12932. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  12933. // not collinear
  12934. // length of vectors for normalizing
  12935. const v_prev_len = Math.sqrt( v_prev_lensq );
  12936. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  12937. // shift adjacent points by unit vectors to the left
  12938. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  12939. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  12940. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  12941. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  12942. // scaling factor for v_prev to intersection point
  12943. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  12944. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  12945. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12946. // vector from inPt to intersection point
  12947. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  12948. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  12949. // Don't normalize!, otherwise sharp corners become ugly
  12950. // but prevent crazy spikes
  12951. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  12952. if ( v_trans_lensq <= 2 ) {
  12953. return new Vector2( v_trans_x, v_trans_y );
  12954. } else {
  12955. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  12956. }
  12957. } else {
  12958. // handle special case of collinear edges
  12959. let direction_eq = false; // assumes: opposite
  12960. if ( v_prev_x > Number.EPSILON ) {
  12961. if ( v_next_x > Number.EPSILON ) {
  12962. direction_eq = true;
  12963. }
  12964. } else {
  12965. if ( v_prev_x < - Number.EPSILON ) {
  12966. if ( v_next_x < - Number.EPSILON ) {
  12967. direction_eq = true;
  12968. }
  12969. } else {
  12970. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  12971. direction_eq = true;
  12972. }
  12973. }
  12974. }
  12975. if ( direction_eq ) {
  12976. // console.log("Warning: lines are a straight sequence");
  12977. v_trans_x = - v_prev_y;
  12978. v_trans_y = v_prev_x;
  12979. shrink_by = Math.sqrt( v_prev_lensq );
  12980. } else {
  12981. // console.log("Warning: lines are a straight spike");
  12982. v_trans_x = v_prev_x;
  12983. v_trans_y = v_prev_y;
  12984. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  12985. }
  12986. }
  12987. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  12988. }
  12989. const contourMovements = [];
  12990. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  12991. if ( j === il ) j = 0;
  12992. if ( k === il ) k = 0;
  12993. // (j)---(i)---(k)
  12994. // console.log('i,j,k', i, j , k)
  12995. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  12996. }
  12997. const holesMovements = [];
  12998. let oneHoleMovements, verticesMovements = contourMovements.concat();
  12999. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13000. const ahole = holes[ h ];
  13001. oneHoleMovements = [];
  13002. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13003. if ( j === il ) j = 0;
  13004. if ( k === il ) k = 0;
  13005. // (j)---(i)---(k)
  13006. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  13007. }
  13008. holesMovements.push( oneHoleMovements );
  13009. verticesMovements = verticesMovements.concat( oneHoleMovements );
  13010. }
  13011. // Loop bevelSegments, 1 for the front, 1 for the back
  13012. for ( let b = 0; b < bevelSegments; b ++ ) {
  13013. //for ( b = bevelSegments; b > 0; b -- ) {
  13014. const t = b / bevelSegments;
  13015. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13016. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13017. // contract shape
  13018. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13019. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13020. v( vert.x, vert.y, - z );
  13021. }
  13022. // expand holes
  13023. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13024. const ahole = holes[ h ];
  13025. oneHoleMovements = holesMovements[ h ];
  13026. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13027. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13028. v( vert.x, vert.y, - z );
  13029. }
  13030. }
  13031. }
  13032. const bs = bevelSize + bevelOffset;
  13033. // Back facing vertices
  13034. for ( let i = 0; i < vlen; i ++ ) {
  13035. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13036. if ( ! extrudeByPath ) {
  13037. v( vert.x, vert.y, 0 );
  13038. } else {
  13039. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  13040. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  13041. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  13042. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  13043. v( position2.x, position2.y, position2.z );
  13044. }
  13045. }
  13046. // Add stepped vertices...
  13047. // Including front facing vertices
  13048. for ( let s = 1; s <= steps; s ++ ) {
  13049. for ( let i = 0; i < vlen; i ++ ) {
  13050. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13051. if ( ! extrudeByPath ) {
  13052. v( vert.x, vert.y, depth / steps * s );
  13053. } else {
  13054. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  13055. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  13056. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  13057. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  13058. v( position2.x, position2.y, position2.z );
  13059. }
  13060. }
  13061. }
  13062. // Add bevel segments planes
  13063. //for ( b = 1; b <= bevelSegments; b ++ ) {
  13064. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  13065. const t = b / bevelSegments;
  13066. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13067. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13068. // contract shape
  13069. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13070. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13071. v( vert.x, vert.y, depth + z );
  13072. }
  13073. // expand holes
  13074. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13075. const ahole = holes[ h ];
  13076. oneHoleMovements = holesMovements[ h ];
  13077. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13078. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13079. if ( ! extrudeByPath ) {
  13080. v( vert.x, vert.y, depth + z );
  13081. } else {
  13082. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  13083. }
  13084. }
  13085. }
  13086. }
  13087. /* Faces */
  13088. // Top and bottom faces
  13089. buildLidFaces();
  13090. // Sides faces
  13091. buildSideFaces();
  13092. ///// Internal functions
  13093. function buildLidFaces() {
  13094. const start = verticesArray.length / 3;
  13095. if ( bevelEnabled ) {
  13096. let layer = 0; // steps + 1
  13097. let offset = vlen * layer;
  13098. // Bottom faces
  13099. for ( let i = 0; i < flen; i ++ ) {
  13100. const face = faces[ i ];
  13101. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  13102. }
  13103. layer = steps + bevelSegments * 2;
  13104. offset = vlen * layer;
  13105. // Top faces
  13106. for ( let i = 0; i < flen; i ++ ) {
  13107. const face = faces[ i ];
  13108. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  13109. }
  13110. } else {
  13111. // Bottom faces
  13112. for ( let i = 0; i < flen; i ++ ) {
  13113. const face = faces[ i ];
  13114. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  13115. }
  13116. // Top faces
  13117. for ( let i = 0; i < flen; i ++ ) {
  13118. const face = faces[ i ];
  13119. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  13120. }
  13121. }
  13122. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  13123. }
  13124. // Create faces for the z-sides of the shape
  13125. function buildSideFaces() {
  13126. const start = verticesArray.length / 3;
  13127. let layeroffset = 0;
  13128. sidewalls( contour, layeroffset );
  13129. layeroffset += contour.length;
  13130. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13131. const ahole = holes[ h ];
  13132. sidewalls( ahole, layeroffset );
  13133. //, true
  13134. layeroffset += ahole.length;
  13135. }
  13136. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  13137. }
  13138. function sidewalls( contour, layeroffset ) {
  13139. let i = contour.length;
  13140. while ( -- i >= 0 ) {
  13141. const j = i;
  13142. let k = i - 1;
  13143. if ( k < 0 ) k = contour.length - 1;
  13144. //console.log('b', i,j, i-1, k,vertices.length);
  13145. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  13146. const slen1 = vlen * s;
  13147. const slen2 = vlen * ( s + 1 );
  13148. const a = layeroffset + j + slen1,
  13149. b = layeroffset + k + slen1,
  13150. c = layeroffset + k + slen2,
  13151. d = layeroffset + j + slen2;
  13152. f4( a, b, c, d );
  13153. }
  13154. }
  13155. }
  13156. function v( x, y, z ) {
  13157. placeholder.push( x );
  13158. placeholder.push( y );
  13159. placeholder.push( z );
  13160. }
  13161. function f3( a, b, c ) {
  13162. addVertex( a );
  13163. addVertex( b );
  13164. addVertex( c );
  13165. const nextIndex = verticesArray.length / 3;
  13166. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13167. addUV( uvs[ 0 ] );
  13168. addUV( uvs[ 1 ] );
  13169. addUV( uvs[ 2 ] );
  13170. }
  13171. function f4( a, b, c, d ) {
  13172. addVertex( a );
  13173. addVertex( b );
  13174. addVertex( d );
  13175. addVertex( b );
  13176. addVertex( c );
  13177. addVertex( d );
  13178. const nextIndex = verticesArray.length / 3;
  13179. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13180. addUV( uvs[ 0 ] );
  13181. addUV( uvs[ 1 ] );
  13182. addUV( uvs[ 3 ] );
  13183. addUV( uvs[ 1 ] );
  13184. addUV( uvs[ 2 ] );
  13185. addUV( uvs[ 3 ] );
  13186. }
  13187. function addVertex( index ) {
  13188. verticesArray.push( placeholder[ index * 3 + 0 ] );
  13189. verticesArray.push( placeholder[ index * 3 + 1 ] );
  13190. verticesArray.push( placeholder[ index * 3 + 2 ] );
  13191. }
  13192. function addUV( vector2 ) {
  13193. uvArray.push( vector2.x );
  13194. uvArray.push( vector2.y );
  13195. }
  13196. }
  13197. }
  13198. copy( source ) {
  13199. super.copy( source );
  13200. this.parameters = Object.assign( {}, source.parameters );
  13201. return this;
  13202. }
  13203. toJSON() {
  13204. const data = super.toJSON();
  13205. const shapes = this.parameters.shapes;
  13206. const options = this.parameters.options;
  13207. return toJSON$1( shapes, options, data );
  13208. }
  13209. static fromJSON( data, shapes ) {
  13210. const geometryShapes = [];
  13211. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13212. const shape = shapes[ data.shapes[ j ] ];
  13213. geometryShapes.push( shape );
  13214. }
  13215. const extrudePath = data.options.extrudePath;
  13216. if ( extrudePath !== undefined ) {
  13217. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  13218. }
  13219. return new ExtrudeGeometry( geometryShapes, data.options );
  13220. }
  13221. }
  13222. const WorldUVGenerator = {
  13223. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  13224. const a_x = vertices[ indexA * 3 ];
  13225. const a_y = vertices[ indexA * 3 + 1 ];
  13226. const b_x = vertices[ indexB * 3 ];
  13227. const b_y = vertices[ indexB * 3 + 1 ];
  13228. const c_x = vertices[ indexC * 3 ];
  13229. const c_y = vertices[ indexC * 3 + 1 ];
  13230. return [
  13231. new Vector2( a_x, a_y ),
  13232. new Vector2( b_x, b_y ),
  13233. new Vector2( c_x, c_y )
  13234. ];
  13235. },
  13236. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  13237. const a_x = vertices[ indexA * 3 ];
  13238. const a_y = vertices[ indexA * 3 + 1 ];
  13239. const a_z = vertices[ indexA * 3 + 2 ];
  13240. const b_x = vertices[ indexB * 3 ];
  13241. const b_y = vertices[ indexB * 3 + 1 ];
  13242. const b_z = vertices[ indexB * 3 + 2 ];
  13243. const c_x = vertices[ indexC * 3 ];
  13244. const c_y = vertices[ indexC * 3 + 1 ];
  13245. const c_z = vertices[ indexC * 3 + 2 ];
  13246. const d_x = vertices[ indexD * 3 ];
  13247. const d_y = vertices[ indexD * 3 + 1 ];
  13248. const d_z = vertices[ indexD * 3 + 2 ];
  13249. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  13250. return [
  13251. new Vector2( a_x, 1 - a_z ),
  13252. new Vector2( b_x, 1 - b_z ),
  13253. new Vector2( c_x, 1 - c_z ),
  13254. new Vector2( d_x, 1 - d_z )
  13255. ];
  13256. } else {
  13257. return [
  13258. new Vector2( a_y, 1 - a_z ),
  13259. new Vector2( b_y, 1 - b_z ),
  13260. new Vector2( c_y, 1 - c_z ),
  13261. new Vector2( d_y, 1 - d_z )
  13262. ];
  13263. }
  13264. }
  13265. };
  13266. function toJSON$1( shapes, options, data ) {
  13267. data.shapes = [];
  13268. if ( Array.isArray( shapes ) ) {
  13269. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13270. const shape = shapes[ i ];
  13271. data.shapes.push( shape.uuid );
  13272. }
  13273. } else {
  13274. data.shapes.push( shapes.uuid );
  13275. }
  13276. data.options = Object.assign( {}, options );
  13277. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  13278. return data;
  13279. }
  13280. class IcosahedronGeometry extends PolyhedronGeometry {
  13281. constructor( radius = 1, detail = 0 ) {
  13282. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  13283. const vertices = [
  13284. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  13285. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  13286. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  13287. ];
  13288. const indices = [
  13289. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  13290. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  13291. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  13292. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  13293. ];
  13294. super( vertices, indices, radius, detail );
  13295. this.type = 'IcosahedronGeometry';
  13296. this.parameters = {
  13297. radius: radius,
  13298. detail: detail
  13299. };
  13300. }
  13301. static fromJSON( data ) {
  13302. return new IcosahedronGeometry( data.radius, data.detail );
  13303. }
  13304. }
  13305. class OctahedronGeometry extends PolyhedronGeometry {
  13306. constructor( radius = 1, detail = 0 ) {
  13307. const vertices = [
  13308. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  13309. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  13310. ];
  13311. const indices = [
  13312. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  13313. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  13314. 1, 3, 4, 1, 4, 2
  13315. ];
  13316. super( vertices, indices, radius, detail );
  13317. this.type = 'OctahedronGeometry';
  13318. this.parameters = {
  13319. radius: radius,
  13320. detail: detail
  13321. };
  13322. }
  13323. static fromJSON( data ) {
  13324. return new OctahedronGeometry( data.radius, data.detail );
  13325. }
  13326. }
  13327. class PlaneGeometry extends BufferGeometry {
  13328. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  13329. super();
  13330. this.type = 'PlaneGeometry';
  13331. this.parameters = {
  13332. width: width,
  13333. height: height,
  13334. widthSegments: widthSegments,
  13335. heightSegments: heightSegments
  13336. };
  13337. const width_half = width / 2;
  13338. const height_half = height / 2;
  13339. const gridX = Math.floor( widthSegments );
  13340. const gridY = Math.floor( heightSegments );
  13341. const gridX1 = gridX + 1;
  13342. const gridY1 = gridY + 1;
  13343. const segment_width = width / gridX;
  13344. const segment_height = height / gridY;
  13345. //
  13346. const indices = [];
  13347. const vertices = [];
  13348. const normals = [];
  13349. const uvs = [];
  13350. for ( let iy = 0; iy < gridY1; iy ++ ) {
  13351. const y = iy * segment_height - height_half;
  13352. for ( let ix = 0; ix < gridX1; ix ++ ) {
  13353. const x = ix * segment_width - width_half;
  13354. vertices.push( x, - y, 0 );
  13355. normals.push( 0, 0, 1 );
  13356. uvs.push( ix / gridX );
  13357. uvs.push( 1 - ( iy / gridY ) );
  13358. }
  13359. }
  13360. for ( let iy = 0; iy < gridY; iy ++ ) {
  13361. for ( let ix = 0; ix < gridX; ix ++ ) {
  13362. const a = ix + gridX1 * iy;
  13363. const b = ix + gridX1 * ( iy + 1 );
  13364. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  13365. const d = ( ix + 1 ) + gridX1 * iy;
  13366. indices.push( a, b, d );
  13367. indices.push( b, c, d );
  13368. }
  13369. }
  13370. this.setIndex( indices );
  13371. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13372. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13373. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13374. }
  13375. copy( source ) {
  13376. super.copy( source );
  13377. this.parameters = Object.assign( {}, source.parameters );
  13378. return this;
  13379. }
  13380. static fromJSON( data ) {
  13381. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  13382. }
  13383. }
  13384. class RingGeometry extends BufferGeometry {
  13385. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  13386. super();
  13387. this.type = 'RingGeometry';
  13388. this.parameters = {
  13389. innerRadius: innerRadius,
  13390. outerRadius: outerRadius,
  13391. thetaSegments: thetaSegments,
  13392. phiSegments: phiSegments,
  13393. thetaStart: thetaStart,
  13394. thetaLength: thetaLength
  13395. };
  13396. thetaSegments = Math.max( 3, thetaSegments );
  13397. phiSegments = Math.max( 1, phiSegments );
  13398. // buffers
  13399. const indices = [];
  13400. const vertices = [];
  13401. const normals = [];
  13402. const uvs = [];
  13403. // some helper variables
  13404. let radius = innerRadius;
  13405. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  13406. const vertex = new Vector3();
  13407. const uv = new Vector2();
  13408. // generate vertices, normals and uvs
  13409. for ( let j = 0; j <= phiSegments; j ++ ) {
  13410. for ( let i = 0; i <= thetaSegments; i ++ ) {
  13411. // values are generate from the inside of the ring to the outside
  13412. const segment = thetaStart + i / thetaSegments * thetaLength;
  13413. // vertex
  13414. vertex.x = radius * Math.cos( segment );
  13415. vertex.y = radius * Math.sin( segment );
  13416. vertices.push( vertex.x, vertex.y, vertex.z );
  13417. // normal
  13418. normals.push( 0, 0, 1 );
  13419. // uv
  13420. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  13421. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  13422. uvs.push( uv.x, uv.y );
  13423. }
  13424. // increase the radius for next row of vertices
  13425. radius += radiusStep;
  13426. }
  13427. // indices
  13428. for ( let j = 0; j < phiSegments; j ++ ) {
  13429. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  13430. for ( let i = 0; i < thetaSegments; i ++ ) {
  13431. const segment = i + thetaSegmentLevel;
  13432. const a = segment;
  13433. const b = segment + thetaSegments + 1;
  13434. const c = segment + thetaSegments + 2;
  13435. const d = segment + 1;
  13436. // faces
  13437. indices.push( a, b, d );
  13438. indices.push( b, c, d );
  13439. }
  13440. }
  13441. // build geometry
  13442. this.setIndex( indices );
  13443. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13444. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13445. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13446. }
  13447. copy( source ) {
  13448. super.copy( source );
  13449. this.parameters = Object.assign( {}, source.parameters );
  13450. return this;
  13451. }
  13452. static fromJSON( data ) {
  13453. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  13454. }
  13455. }
  13456. class ShapeGeometry extends BufferGeometry {
  13457. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
  13458. super();
  13459. this.type = 'ShapeGeometry';
  13460. this.parameters = {
  13461. shapes: shapes,
  13462. curveSegments: curveSegments
  13463. };
  13464. // buffers
  13465. const indices = [];
  13466. const vertices = [];
  13467. const normals = [];
  13468. const uvs = [];
  13469. // helper variables
  13470. let groupStart = 0;
  13471. let groupCount = 0;
  13472. // allow single and array values for "shapes" parameter
  13473. if ( Array.isArray( shapes ) === false ) {
  13474. addShape( shapes );
  13475. } else {
  13476. for ( let i = 0; i < shapes.length; i ++ ) {
  13477. addShape( shapes[ i ] );
  13478. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  13479. groupStart += groupCount;
  13480. groupCount = 0;
  13481. }
  13482. }
  13483. // build geometry
  13484. this.setIndex( indices );
  13485. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13486. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13487. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13488. // helper functions
  13489. function addShape( shape ) {
  13490. const indexOffset = vertices.length / 3;
  13491. const points = shape.extractPoints( curveSegments );
  13492. let shapeVertices = points.shape;
  13493. const shapeHoles = points.holes;
  13494. // check direction of vertices
  13495. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  13496. shapeVertices = shapeVertices.reverse();
  13497. }
  13498. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13499. const shapeHole = shapeHoles[ i ];
  13500. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  13501. shapeHoles[ i ] = shapeHole.reverse();
  13502. }
  13503. }
  13504. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  13505. // join vertices of inner and outer paths to a single array
  13506. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13507. const shapeHole = shapeHoles[ i ];
  13508. shapeVertices = shapeVertices.concat( shapeHole );
  13509. }
  13510. // vertices, normals, uvs
  13511. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  13512. const vertex = shapeVertices[ i ];
  13513. vertices.push( vertex.x, vertex.y, 0 );
  13514. normals.push( 0, 0, 1 );
  13515. uvs.push( vertex.x, vertex.y ); // world uvs
  13516. }
  13517. // indices
  13518. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  13519. const face = faces[ i ];
  13520. const a = face[ 0 ] + indexOffset;
  13521. const b = face[ 1 ] + indexOffset;
  13522. const c = face[ 2 ] + indexOffset;
  13523. indices.push( a, b, c );
  13524. groupCount += 3;
  13525. }
  13526. }
  13527. }
  13528. copy( source ) {
  13529. super.copy( source );
  13530. this.parameters = Object.assign( {}, source.parameters );
  13531. return this;
  13532. }
  13533. toJSON() {
  13534. const data = super.toJSON();
  13535. const shapes = this.parameters.shapes;
  13536. return toJSON( shapes, data );
  13537. }
  13538. static fromJSON( data, shapes ) {
  13539. const geometryShapes = [];
  13540. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13541. const shape = shapes[ data.shapes[ j ] ];
  13542. geometryShapes.push( shape );
  13543. }
  13544. return new ShapeGeometry( geometryShapes, data.curveSegments );
  13545. }
  13546. }
  13547. function toJSON( shapes, data ) {
  13548. data.shapes = [];
  13549. if ( Array.isArray( shapes ) ) {
  13550. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13551. const shape = shapes[ i ];
  13552. data.shapes.push( shape.uuid );
  13553. }
  13554. } else {
  13555. data.shapes.push( shapes.uuid );
  13556. }
  13557. return data;
  13558. }
  13559. class SphereGeometry extends BufferGeometry {
  13560. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  13561. super();
  13562. this.type = 'SphereGeometry';
  13563. this.parameters = {
  13564. radius: radius,
  13565. widthSegments: widthSegments,
  13566. heightSegments: heightSegments,
  13567. phiStart: phiStart,
  13568. phiLength: phiLength,
  13569. thetaStart: thetaStart,
  13570. thetaLength: thetaLength
  13571. };
  13572. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  13573. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  13574. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  13575. let index = 0;
  13576. const grid = [];
  13577. const vertex = new Vector3();
  13578. const normal = new Vector3();
  13579. // buffers
  13580. const indices = [];
  13581. const vertices = [];
  13582. const normals = [];
  13583. const uvs = [];
  13584. // generate vertices, normals and uvs
  13585. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  13586. const verticesRow = [];
  13587. const v = iy / heightSegments;
  13588. // special case for the poles
  13589. let uOffset = 0;
  13590. if ( iy === 0 && thetaStart === 0 ) {
  13591. uOffset = 0.5 / widthSegments;
  13592. } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
  13593. uOffset = - 0.5 / widthSegments;
  13594. }
  13595. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  13596. const u = ix / widthSegments;
  13597. // vertex
  13598. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13599. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  13600. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13601. vertices.push( vertex.x, vertex.y, vertex.z );
  13602. // normal
  13603. normal.copy( vertex ).normalize();
  13604. normals.push( normal.x, normal.y, normal.z );
  13605. // uv
  13606. uvs.push( u + uOffset, 1 - v );
  13607. verticesRow.push( index ++ );
  13608. }
  13609. grid.push( verticesRow );
  13610. }
  13611. // indices
  13612. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  13613. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  13614. const a = grid[ iy ][ ix + 1 ];
  13615. const b = grid[ iy ][ ix ];
  13616. const c = grid[ iy + 1 ][ ix ];
  13617. const d = grid[ iy + 1 ][ ix + 1 ];
  13618. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  13619. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  13620. }
  13621. }
  13622. // build geometry
  13623. this.setIndex( indices );
  13624. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13625. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13626. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13627. }
  13628. copy( source ) {
  13629. super.copy( source );
  13630. this.parameters = Object.assign( {}, source.parameters );
  13631. return this;
  13632. }
  13633. static fromJSON( data ) {
  13634. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  13635. }
  13636. }
  13637. class TetrahedronGeometry extends PolyhedronGeometry {
  13638. constructor( radius = 1, detail = 0 ) {
  13639. const vertices = [
  13640. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  13641. ];
  13642. const indices = [
  13643. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  13644. ];
  13645. super( vertices, indices, radius, detail );
  13646. this.type = 'TetrahedronGeometry';
  13647. this.parameters = {
  13648. radius: radius,
  13649. detail: detail
  13650. };
  13651. }
  13652. static fromJSON( data ) {
  13653. return new TetrahedronGeometry( data.radius, data.detail );
  13654. }
  13655. }
  13656. class TorusGeometry extends BufferGeometry {
  13657. constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
  13658. super();
  13659. this.type = 'TorusGeometry';
  13660. this.parameters = {
  13661. radius: radius,
  13662. tube: tube,
  13663. radialSegments: radialSegments,
  13664. tubularSegments: tubularSegments,
  13665. arc: arc
  13666. };
  13667. radialSegments = Math.floor( radialSegments );
  13668. tubularSegments = Math.floor( tubularSegments );
  13669. // buffers
  13670. const indices = [];
  13671. const vertices = [];
  13672. const normals = [];
  13673. const uvs = [];
  13674. // helper variables
  13675. const center = new Vector3();
  13676. const vertex = new Vector3();
  13677. const normal = new Vector3();
  13678. // generate vertices, normals and uvs
  13679. for ( let j = 0; j <= radialSegments; j ++ ) {
  13680. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13681. const u = i / tubularSegments * arc;
  13682. const v = j / radialSegments * Math.PI * 2;
  13683. // vertex
  13684. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  13685. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  13686. vertex.z = tube * Math.sin( v );
  13687. vertices.push( vertex.x, vertex.y, vertex.z );
  13688. // normal
  13689. center.x = radius * Math.cos( u );
  13690. center.y = radius * Math.sin( u );
  13691. normal.subVectors( vertex, center ).normalize();
  13692. normals.push( normal.x, normal.y, normal.z );
  13693. // uv
  13694. uvs.push( i / tubularSegments );
  13695. uvs.push( j / radialSegments );
  13696. }
  13697. }
  13698. // generate indices
  13699. for ( let j = 1; j <= radialSegments; j ++ ) {
  13700. for ( let i = 1; i <= tubularSegments; i ++ ) {
  13701. // indices
  13702. const a = ( tubularSegments + 1 ) * j + i - 1;
  13703. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  13704. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  13705. const d = ( tubularSegments + 1 ) * j + i;
  13706. // faces
  13707. indices.push( a, b, d );
  13708. indices.push( b, c, d );
  13709. }
  13710. }
  13711. // build geometry
  13712. this.setIndex( indices );
  13713. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13714. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13715. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13716. }
  13717. copy( source ) {
  13718. super.copy( source );
  13719. this.parameters = Object.assign( {}, source.parameters );
  13720. return this;
  13721. }
  13722. static fromJSON( data ) {
  13723. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  13724. }
  13725. }
  13726. class TorusKnotGeometry extends BufferGeometry {
  13727. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  13728. super();
  13729. this.type = 'TorusKnotGeometry';
  13730. this.parameters = {
  13731. radius: radius,
  13732. tube: tube,
  13733. tubularSegments: tubularSegments,
  13734. radialSegments: radialSegments,
  13735. p: p,
  13736. q: q
  13737. };
  13738. tubularSegments = Math.floor( tubularSegments );
  13739. radialSegments = Math.floor( radialSegments );
  13740. // buffers
  13741. const indices = [];
  13742. const vertices = [];
  13743. const normals = [];
  13744. const uvs = [];
  13745. // helper variables
  13746. const vertex = new Vector3();
  13747. const normal = new Vector3();
  13748. const P1 = new Vector3();
  13749. const P2 = new Vector3();
  13750. const B = new Vector3();
  13751. const T = new Vector3();
  13752. const N = new Vector3();
  13753. // generate vertices, normals and uvs
  13754. for ( let i = 0; i <= tubularSegments; ++ i ) {
  13755. // the radian "u" is used to calculate the position on the torus curve of the current tubular segment
  13756. const u = i / tubularSegments * p * Math.PI * 2;
  13757. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  13758. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  13759. calculatePositionOnCurve( u, p, q, radius, P1 );
  13760. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  13761. // calculate orthonormal basis
  13762. T.subVectors( P2, P1 );
  13763. N.addVectors( P2, P1 );
  13764. B.crossVectors( T, N );
  13765. N.crossVectors( B, T );
  13766. // normalize B, N. T can be ignored, we don't use it
  13767. B.normalize();
  13768. N.normalize();
  13769. for ( let j = 0; j <= radialSegments; ++ j ) {
  13770. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  13771. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  13772. const v = j / radialSegments * Math.PI * 2;
  13773. const cx = - tube * Math.cos( v );
  13774. const cy = tube * Math.sin( v );
  13775. // now calculate the final vertex position.
  13776. // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve
  13777. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  13778. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  13779. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  13780. vertices.push( vertex.x, vertex.y, vertex.z );
  13781. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  13782. normal.subVectors( vertex, P1 ).normalize();
  13783. normals.push( normal.x, normal.y, normal.z );
  13784. // uv
  13785. uvs.push( i / tubularSegments );
  13786. uvs.push( j / radialSegments );
  13787. }
  13788. }
  13789. // generate indices
  13790. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13791. for ( let i = 1; i <= radialSegments; i ++ ) {
  13792. // indices
  13793. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13794. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13795. const c = ( radialSegments + 1 ) * j + i;
  13796. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13797. // faces
  13798. indices.push( a, b, d );
  13799. indices.push( b, c, d );
  13800. }
  13801. }
  13802. // build geometry
  13803. this.setIndex( indices );
  13804. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13805. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13806. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13807. // this function calculates the current position on the torus curve
  13808. function calculatePositionOnCurve( u, p, q, radius, position ) {
  13809. const cu = Math.cos( u );
  13810. const su = Math.sin( u );
  13811. const quOverP = q / p * u;
  13812. const cs = Math.cos( quOverP );
  13813. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  13814. position.y = radius * ( 2 + cs ) * su * 0.5;
  13815. position.z = radius * Math.sin( quOverP ) * 0.5;
  13816. }
  13817. }
  13818. copy( source ) {
  13819. super.copy( source );
  13820. this.parameters = Object.assign( {}, source.parameters );
  13821. return this;
  13822. }
  13823. static fromJSON( data ) {
  13824. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  13825. }
  13826. }
  13827. class TubeGeometry extends BufferGeometry {
  13828. constructor( path = new QuadraticBezierCurve3( new Vector3( - 1, - 1, 0 ), new Vector3( - 1, 1, 0 ), new Vector3( 1, 1, 0 ) ), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  13829. super();
  13830. this.type = 'TubeGeometry';
  13831. this.parameters = {
  13832. path: path,
  13833. tubularSegments: tubularSegments,
  13834. radius: radius,
  13835. radialSegments: radialSegments,
  13836. closed: closed
  13837. };
  13838. const frames = path.computeFrenetFrames( tubularSegments, closed );
  13839. // expose internals
  13840. this.tangents = frames.tangents;
  13841. this.normals = frames.normals;
  13842. this.binormals = frames.binormals;
  13843. // helper variables
  13844. const vertex = new Vector3();
  13845. const normal = new Vector3();
  13846. const uv = new Vector2();
  13847. let P = new Vector3();
  13848. // buffer
  13849. const vertices = [];
  13850. const normals = [];
  13851. const uvs = [];
  13852. const indices = [];
  13853. // create buffer data
  13854. generateBufferData();
  13855. // build geometry
  13856. this.setIndex( indices );
  13857. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13858. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13859. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13860. // functions
  13861. function generateBufferData() {
  13862. for ( let i = 0; i < tubularSegments; i ++ ) {
  13863. generateSegment( i );
  13864. }
  13865. // if the geometry is not closed, generate the last row of vertices and normals
  13866. // at the regular position on the given path
  13867. //
  13868. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  13869. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  13870. // uvs are generated in a separate function.
  13871. // this makes it easy compute correct values for closed geometries
  13872. generateUVs();
  13873. // finally create faces
  13874. generateIndices();
  13875. }
  13876. function generateSegment( i ) {
  13877. // we use getPointAt to sample evenly distributed points from the given path
  13878. P = path.getPointAt( i / tubularSegments, P );
  13879. // retrieve corresponding normal and binormal
  13880. const N = frames.normals[ i ];
  13881. const B = frames.binormals[ i ];
  13882. // generate normals and vertices for the current segment
  13883. for ( let j = 0; j <= radialSegments; j ++ ) {
  13884. const v = j / radialSegments * Math.PI * 2;
  13885. const sin = Math.sin( v );
  13886. const cos = - Math.cos( v );
  13887. // normal
  13888. normal.x = ( cos * N.x + sin * B.x );
  13889. normal.y = ( cos * N.y + sin * B.y );
  13890. normal.z = ( cos * N.z + sin * B.z );
  13891. normal.normalize();
  13892. normals.push( normal.x, normal.y, normal.z );
  13893. // vertex
  13894. vertex.x = P.x + radius * normal.x;
  13895. vertex.y = P.y + radius * normal.y;
  13896. vertex.z = P.z + radius * normal.z;
  13897. vertices.push( vertex.x, vertex.y, vertex.z );
  13898. }
  13899. }
  13900. function generateIndices() {
  13901. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13902. for ( let i = 1; i <= radialSegments; i ++ ) {
  13903. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13904. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13905. const c = ( radialSegments + 1 ) * j + i;
  13906. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13907. // faces
  13908. indices.push( a, b, d );
  13909. indices.push( b, c, d );
  13910. }
  13911. }
  13912. }
  13913. function generateUVs() {
  13914. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13915. for ( let j = 0; j <= radialSegments; j ++ ) {
  13916. uv.x = i / tubularSegments;
  13917. uv.y = j / radialSegments;
  13918. uvs.push( uv.x, uv.y );
  13919. }
  13920. }
  13921. }
  13922. }
  13923. copy( source ) {
  13924. super.copy( source );
  13925. this.parameters = Object.assign( {}, source.parameters );
  13926. return this;
  13927. }
  13928. toJSON() {
  13929. const data = super.toJSON();
  13930. data.path = this.parameters.path.toJSON();
  13931. return data;
  13932. }
  13933. static fromJSON( data ) {
  13934. // This only works for built-in curves (e.g. CatmullRomCurve3).
  13935. // User defined curves or instances of CurvePath will not be deserialized.
  13936. return new TubeGeometry(
  13937. new Curves[ data.path.type ]().fromJSON( data.path ),
  13938. data.tubularSegments,
  13939. data.radius,
  13940. data.radialSegments,
  13941. data.closed
  13942. );
  13943. }
  13944. }
  13945. class WireframeGeometry extends BufferGeometry {
  13946. constructor( geometry = null ) {
  13947. super();
  13948. this.type = 'WireframeGeometry';
  13949. this.parameters = {
  13950. geometry: geometry
  13951. };
  13952. if ( geometry !== null ) {
  13953. // buffer
  13954. const vertices = [];
  13955. const edges = new Set();
  13956. // helper variables
  13957. const start = new Vector3();
  13958. const end = new Vector3();
  13959. if ( geometry.index !== null ) {
  13960. // indexed BufferGeometry
  13961. const position = geometry.attributes.position;
  13962. const indices = geometry.index;
  13963. let groups = geometry.groups;
  13964. if ( groups.length === 0 ) {
  13965. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  13966. }
  13967. // create a data structure that contains all edges without duplicates
  13968. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  13969. const group = groups[ o ];
  13970. const groupStart = group.start;
  13971. const groupCount = group.count;
  13972. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  13973. for ( let j = 0; j < 3; j ++ ) {
  13974. const index1 = indices.getX( i + j );
  13975. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  13976. start.fromBufferAttribute( position, index1 );
  13977. end.fromBufferAttribute( position, index2 );
  13978. if ( isUniqueEdge( start, end, edges ) === true ) {
  13979. vertices.push( start.x, start.y, start.z );
  13980. vertices.push( end.x, end.y, end.z );
  13981. }
  13982. }
  13983. }
  13984. }
  13985. } else {
  13986. // non-indexed BufferGeometry
  13987. const position = geometry.attributes.position;
  13988. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  13989. for ( let j = 0; j < 3; j ++ ) {
  13990. // three edges per triangle, an edge is represented as (index1, index2)
  13991. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  13992. const index1 = 3 * i + j;
  13993. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  13994. start.fromBufferAttribute( position, index1 );
  13995. end.fromBufferAttribute( position, index2 );
  13996. if ( isUniqueEdge( start, end, edges ) === true ) {
  13997. vertices.push( start.x, start.y, start.z );
  13998. vertices.push( end.x, end.y, end.z );
  13999. }
  14000. }
  14001. }
  14002. }
  14003. // build geometry
  14004. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14005. }
  14006. }
  14007. copy( source ) {
  14008. super.copy( source );
  14009. this.parameters = Object.assign( {}, source.parameters );
  14010. return this;
  14011. }
  14012. }
  14013. function isUniqueEdge( start, end, edges ) {
  14014. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  14015. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  14016. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  14017. return false;
  14018. } else {
  14019. edges.add( hash1 );
  14020. edges.add( hash2 );
  14021. return true;
  14022. }
  14023. }
  14024. var Geometries = /*#__PURE__*/Object.freeze({
  14025. __proto__: null,
  14026. BoxGeometry: BoxGeometry,
  14027. CapsuleGeometry: CapsuleGeometry,
  14028. CircleGeometry: CircleGeometry,
  14029. ConeGeometry: ConeGeometry,
  14030. CylinderGeometry: CylinderGeometry,
  14031. DodecahedronGeometry: DodecahedronGeometry,
  14032. EdgesGeometry: EdgesGeometry,
  14033. ExtrudeGeometry: ExtrudeGeometry,
  14034. IcosahedronGeometry: IcosahedronGeometry,
  14035. LatheGeometry: LatheGeometry,
  14036. OctahedronGeometry: OctahedronGeometry,
  14037. PlaneGeometry: PlaneGeometry,
  14038. PolyhedronGeometry: PolyhedronGeometry,
  14039. RingGeometry: RingGeometry,
  14040. ShapeGeometry: ShapeGeometry,
  14041. SphereGeometry: SphereGeometry,
  14042. TetrahedronGeometry: TetrahedronGeometry,
  14043. TorusGeometry: TorusGeometry,
  14044. TorusKnotGeometry: TorusKnotGeometry,
  14045. TubeGeometry: TubeGeometry,
  14046. WireframeGeometry: WireframeGeometry
  14047. });
  14048. class ShadowMaterial extends Material {
  14049. constructor( parameters ) {
  14050. super();
  14051. this.isShadowMaterial = true;
  14052. this.type = 'ShadowMaterial';
  14053. this.color = new Color( 0x000000 );
  14054. this.transparent = true;
  14055. this.fog = true;
  14056. this.setValues( parameters );
  14057. }
  14058. copy( source ) {
  14059. super.copy( source );
  14060. this.color.copy( source.color );
  14061. this.fog = source.fog;
  14062. return this;
  14063. }
  14064. }
  14065. class RawShaderMaterial extends ShaderMaterial {
  14066. constructor( parameters ) {
  14067. super( parameters );
  14068. this.isRawShaderMaterial = true;
  14069. this.type = 'RawShaderMaterial';
  14070. }
  14071. }
  14072. class MeshStandardMaterial extends Material {
  14073. constructor( parameters ) {
  14074. super();
  14075. this.isMeshStandardMaterial = true;
  14076. this.type = 'MeshStandardMaterial';
  14077. this.defines = { 'STANDARD': '' };
  14078. this.color = new Color( 0xffffff ); // diffuse
  14079. this.roughness = 1.0;
  14080. this.metalness = 0.0;
  14081. this.map = null;
  14082. this.lightMap = null;
  14083. this.lightMapIntensity = 1.0;
  14084. this.aoMap = null;
  14085. this.aoMapIntensity = 1.0;
  14086. this.emissive = new Color( 0x000000 );
  14087. this.emissiveIntensity = 1.0;
  14088. this.emissiveMap = null;
  14089. this.bumpMap = null;
  14090. this.bumpScale = 1;
  14091. this.normalMap = null;
  14092. this.normalMapType = TangentSpaceNormalMap;
  14093. this.normalScale = new Vector2( 1, 1 );
  14094. this.displacementMap = null;
  14095. this.displacementScale = 1;
  14096. this.displacementBias = 0;
  14097. this.roughnessMap = null;
  14098. this.metalnessMap = null;
  14099. this.alphaMap = null;
  14100. this.envMap = null;
  14101. this.envMapRotation = new Euler();
  14102. this.envMapIntensity = 1.0;
  14103. this.wireframe = false;
  14104. this.wireframeLinewidth = 1;
  14105. this.wireframeLinecap = 'round';
  14106. this.wireframeLinejoin = 'round';
  14107. this.flatShading = false;
  14108. this.fog = true;
  14109. this.setValues( parameters );
  14110. }
  14111. copy( source ) {
  14112. super.copy( source );
  14113. this.defines = { 'STANDARD': '' };
  14114. this.color.copy( source.color );
  14115. this.roughness = source.roughness;
  14116. this.metalness = source.metalness;
  14117. this.map = source.map;
  14118. this.lightMap = source.lightMap;
  14119. this.lightMapIntensity = source.lightMapIntensity;
  14120. this.aoMap = source.aoMap;
  14121. this.aoMapIntensity = source.aoMapIntensity;
  14122. this.emissive.copy( source.emissive );
  14123. this.emissiveMap = source.emissiveMap;
  14124. this.emissiveIntensity = source.emissiveIntensity;
  14125. this.bumpMap = source.bumpMap;
  14126. this.bumpScale = source.bumpScale;
  14127. this.normalMap = source.normalMap;
  14128. this.normalMapType = source.normalMapType;
  14129. this.normalScale.copy( source.normalScale );
  14130. this.displacementMap = source.displacementMap;
  14131. this.displacementScale = source.displacementScale;
  14132. this.displacementBias = source.displacementBias;
  14133. this.roughnessMap = source.roughnessMap;
  14134. this.metalnessMap = source.metalnessMap;
  14135. this.alphaMap = source.alphaMap;
  14136. this.envMap = source.envMap;
  14137. this.envMapRotation.copy( source.envMapRotation );
  14138. this.envMapIntensity = source.envMapIntensity;
  14139. this.wireframe = source.wireframe;
  14140. this.wireframeLinewidth = source.wireframeLinewidth;
  14141. this.wireframeLinecap = source.wireframeLinecap;
  14142. this.wireframeLinejoin = source.wireframeLinejoin;
  14143. this.flatShading = source.flatShading;
  14144. this.fog = source.fog;
  14145. return this;
  14146. }
  14147. }
  14148. class MeshPhysicalMaterial extends MeshStandardMaterial {
  14149. constructor( parameters ) {
  14150. super();
  14151. this.isMeshPhysicalMaterial = true;
  14152. this.defines = {
  14153. 'STANDARD': '',
  14154. 'PHYSICAL': ''
  14155. };
  14156. this.type = 'MeshPhysicalMaterial';
  14157. this.anisotropyRotation = 0;
  14158. this.anisotropyMap = null;
  14159. this.clearcoatMap = null;
  14160. this.clearcoatRoughness = 0.0;
  14161. this.clearcoatRoughnessMap = null;
  14162. this.clearcoatNormalScale = new Vector2( 1, 1 );
  14163. this.clearcoatNormalMap = null;
  14164. this.ior = 1.5;
  14165. Object.defineProperty( this, 'reflectivity', {
  14166. get: function () {
  14167. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  14168. },
  14169. set: function ( reflectivity ) {
  14170. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  14171. }
  14172. } );
  14173. this.iridescenceMap = null;
  14174. this.iridescenceIOR = 1.3;
  14175. this.iridescenceThicknessRange = [ 100, 400 ];
  14176. this.iridescenceThicknessMap = null;
  14177. this.sheenColor = new Color( 0x000000 );
  14178. this.sheenColorMap = null;
  14179. this.sheenRoughness = 1.0;
  14180. this.sheenRoughnessMap = null;
  14181. this.transmissionMap = null;
  14182. this.thickness = 0;
  14183. this.thicknessMap = null;
  14184. this.attenuationDistance = Infinity;
  14185. this.attenuationColor = new Color( 1, 1, 1 );
  14186. this.specularIntensity = 1.0;
  14187. this.specularIntensityMap = null;
  14188. this.specularColor = new Color( 1, 1, 1 );
  14189. this.specularColorMap = null;
  14190. this._anisotropy = 0;
  14191. this._clearcoat = 0;
  14192. this._dispersion = 0;
  14193. this._iridescence = 0;
  14194. this._sheen = 0.0;
  14195. this._transmission = 0;
  14196. this.setValues( parameters );
  14197. }
  14198. get anisotropy() {
  14199. return this._anisotropy;
  14200. }
  14201. set anisotropy( value ) {
  14202. if ( this._anisotropy > 0 !== value > 0 ) {
  14203. this.version ++;
  14204. }
  14205. this._anisotropy = value;
  14206. }
  14207. get clearcoat() {
  14208. return this._clearcoat;
  14209. }
  14210. set clearcoat( value ) {
  14211. if ( this._clearcoat > 0 !== value > 0 ) {
  14212. this.version ++;
  14213. }
  14214. this._clearcoat = value;
  14215. }
  14216. get iridescence() {
  14217. return this._iridescence;
  14218. }
  14219. set iridescence( value ) {
  14220. if ( this._iridescence > 0 !== value > 0 ) {
  14221. this.version ++;
  14222. }
  14223. this._iridescence = value;
  14224. }
  14225. get dispersion() {
  14226. return this._dispersion;
  14227. }
  14228. set dispersion( value ) {
  14229. if ( this._dispersion > 0 !== value > 0 ) {
  14230. this.version ++;
  14231. }
  14232. this._dispersion = value;
  14233. }
  14234. get sheen() {
  14235. return this._sheen;
  14236. }
  14237. set sheen( value ) {
  14238. if ( this._sheen > 0 !== value > 0 ) {
  14239. this.version ++;
  14240. }
  14241. this._sheen = value;
  14242. }
  14243. get transmission() {
  14244. return this._transmission;
  14245. }
  14246. set transmission( value ) {
  14247. if ( this._transmission > 0 !== value > 0 ) {
  14248. this.version ++;
  14249. }
  14250. this._transmission = value;
  14251. }
  14252. copy( source ) {
  14253. super.copy( source );
  14254. this.defines = {
  14255. 'STANDARD': '',
  14256. 'PHYSICAL': ''
  14257. };
  14258. this.anisotropy = source.anisotropy;
  14259. this.anisotropyRotation = source.anisotropyRotation;
  14260. this.anisotropyMap = source.anisotropyMap;
  14261. this.clearcoat = source.clearcoat;
  14262. this.clearcoatMap = source.clearcoatMap;
  14263. this.clearcoatRoughness = source.clearcoatRoughness;
  14264. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  14265. this.clearcoatNormalMap = source.clearcoatNormalMap;
  14266. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  14267. this.dispersion = source.dispersion;
  14268. this.ior = source.ior;
  14269. this.iridescence = source.iridescence;
  14270. this.iridescenceMap = source.iridescenceMap;
  14271. this.iridescenceIOR = source.iridescenceIOR;
  14272. this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ];
  14273. this.iridescenceThicknessMap = source.iridescenceThicknessMap;
  14274. this.sheen = source.sheen;
  14275. this.sheenColor.copy( source.sheenColor );
  14276. this.sheenColorMap = source.sheenColorMap;
  14277. this.sheenRoughness = source.sheenRoughness;
  14278. this.sheenRoughnessMap = source.sheenRoughnessMap;
  14279. this.transmission = source.transmission;
  14280. this.transmissionMap = source.transmissionMap;
  14281. this.thickness = source.thickness;
  14282. this.thicknessMap = source.thicknessMap;
  14283. this.attenuationDistance = source.attenuationDistance;
  14284. this.attenuationColor.copy( source.attenuationColor );
  14285. this.specularIntensity = source.specularIntensity;
  14286. this.specularIntensityMap = source.specularIntensityMap;
  14287. this.specularColor.copy( source.specularColor );
  14288. this.specularColorMap = source.specularColorMap;
  14289. return this;
  14290. }
  14291. }
  14292. class MeshPhongMaterial extends Material {
  14293. constructor( parameters ) {
  14294. super();
  14295. this.isMeshPhongMaterial = true;
  14296. this.type = 'MeshPhongMaterial';
  14297. this.color = new Color( 0xffffff ); // diffuse
  14298. this.specular = new Color( 0x111111 );
  14299. this.shininess = 30;
  14300. this.map = null;
  14301. this.lightMap = null;
  14302. this.lightMapIntensity = 1.0;
  14303. this.aoMap = null;
  14304. this.aoMapIntensity = 1.0;
  14305. this.emissive = new Color( 0x000000 );
  14306. this.emissiveIntensity = 1.0;
  14307. this.emissiveMap = null;
  14308. this.bumpMap = null;
  14309. this.bumpScale = 1;
  14310. this.normalMap = null;
  14311. this.normalMapType = TangentSpaceNormalMap;
  14312. this.normalScale = new Vector2( 1, 1 );
  14313. this.displacementMap = null;
  14314. this.displacementScale = 1;
  14315. this.displacementBias = 0;
  14316. this.specularMap = null;
  14317. this.alphaMap = null;
  14318. this.envMap = null;
  14319. this.envMapRotation = new Euler();
  14320. this.combine = MultiplyOperation;
  14321. this.reflectivity = 1;
  14322. this.refractionRatio = 0.98;
  14323. this.wireframe = false;
  14324. this.wireframeLinewidth = 1;
  14325. this.wireframeLinecap = 'round';
  14326. this.wireframeLinejoin = 'round';
  14327. this.flatShading = false;
  14328. this.fog = true;
  14329. this.setValues( parameters );
  14330. }
  14331. copy( source ) {
  14332. super.copy( source );
  14333. this.color.copy( source.color );
  14334. this.specular.copy( source.specular );
  14335. this.shininess = source.shininess;
  14336. this.map = source.map;
  14337. this.lightMap = source.lightMap;
  14338. this.lightMapIntensity = source.lightMapIntensity;
  14339. this.aoMap = source.aoMap;
  14340. this.aoMapIntensity = source.aoMapIntensity;
  14341. this.emissive.copy( source.emissive );
  14342. this.emissiveMap = source.emissiveMap;
  14343. this.emissiveIntensity = source.emissiveIntensity;
  14344. this.bumpMap = source.bumpMap;
  14345. this.bumpScale = source.bumpScale;
  14346. this.normalMap = source.normalMap;
  14347. this.normalMapType = source.normalMapType;
  14348. this.normalScale.copy( source.normalScale );
  14349. this.displacementMap = source.displacementMap;
  14350. this.displacementScale = source.displacementScale;
  14351. this.displacementBias = source.displacementBias;
  14352. this.specularMap = source.specularMap;
  14353. this.alphaMap = source.alphaMap;
  14354. this.envMap = source.envMap;
  14355. this.envMapRotation.copy( source.envMapRotation );
  14356. this.combine = source.combine;
  14357. this.reflectivity = source.reflectivity;
  14358. this.refractionRatio = source.refractionRatio;
  14359. this.wireframe = source.wireframe;
  14360. this.wireframeLinewidth = source.wireframeLinewidth;
  14361. this.wireframeLinecap = source.wireframeLinecap;
  14362. this.wireframeLinejoin = source.wireframeLinejoin;
  14363. this.flatShading = source.flatShading;
  14364. this.fog = source.fog;
  14365. return this;
  14366. }
  14367. }
  14368. class MeshToonMaterial extends Material {
  14369. constructor( parameters ) {
  14370. super();
  14371. this.isMeshToonMaterial = true;
  14372. this.defines = { 'TOON': '' };
  14373. this.type = 'MeshToonMaterial';
  14374. this.color = new Color( 0xffffff );
  14375. this.map = null;
  14376. this.gradientMap = null;
  14377. this.lightMap = null;
  14378. this.lightMapIntensity = 1.0;
  14379. this.aoMap = null;
  14380. this.aoMapIntensity = 1.0;
  14381. this.emissive = new Color( 0x000000 );
  14382. this.emissiveIntensity = 1.0;
  14383. this.emissiveMap = null;
  14384. this.bumpMap = null;
  14385. this.bumpScale = 1;
  14386. this.normalMap = null;
  14387. this.normalMapType = TangentSpaceNormalMap;
  14388. this.normalScale = new Vector2( 1, 1 );
  14389. this.displacementMap = null;
  14390. this.displacementScale = 1;
  14391. this.displacementBias = 0;
  14392. this.alphaMap = null;
  14393. this.wireframe = false;
  14394. this.wireframeLinewidth = 1;
  14395. this.wireframeLinecap = 'round';
  14396. this.wireframeLinejoin = 'round';
  14397. this.fog = true;
  14398. this.setValues( parameters );
  14399. }
  14400. copy( source ) {
  14401. super.copy( source );
  14402. this.color.copy( source.color );
  14403. this.map = source.map;
  14404. this.gradientMap = source.gradientMap;
  14405. this.lightMap = source.lightMap;
  14406. this.lightMapIntensity = source.lightMapIntensity;
  14407. this.aoMap = source.aoMap;
  14408. this.aoMapIntensity = source.aoMapIntensity;
  14409. this.emissive.copy( source.emissive );
  14410. this.emissiveMap = source.emissiveMap;
  14411. this.emissiveIntensity = source.emissiveIntensity;
  14412. this.bumpMap = source.bumpMap;
  14413. this.bumpScale = source.bumpScale;
  14414. this.normalMap = source.normalMap;
  14415. this.normalMapType = source.normalMapType;
  14416. this.normalScale.copy( source.normalScale );
  14417. this.displacementMap = source.displacementMap;
  14418. this.displacementScale = source.displacementScale;
  14419. this.displacementBias = source.displacementBias;
  14420. this.alphaMap = source.alphaMap;
  14421. this.wireframe = source.wireframe;
  14422. this.wireframeLinewidth = source.wireframeLinewidth;
  14423. this.wireframeLinecap = source.wireframeLinecap;
  14424. this.wireframeLinejoin = source.wireframeLinejoin;
  14425. this.fog = source.fog;
  14426. return this;
  14427. }
  14428. }
  14429. class MeshNormalMaterial extends Material {
  14430. constructor( parameters ) {
  14431. super();
  14432. this.isMeshNormalMaterial = true;
  14433. this.type = 'MeshNormalMaterial';
  14434. this.bumpMap = null;
  14435. this.bumpScale = 1;
  14436. this.normalMap = null;
  14437. this.normalMapType = TangentSpaceNormalMap;
  14438. this.normalScale = new Vector2( 1, 1 );
  14439. this.displacementMap = null;
  14440. this.displacementScale = 1;
  14441. this.displacementBias = 0;
  14442. this.wireframe = false;
  14443. this.wireframeLinewidth = 1;
  14444. this.flatShading = false;
  14445. this.setValues( parameters );
  14446. }
  14447. copy( source ) {
  14448. super.copy( source );
  14449. this.bumpMap = source.bumpMap;
  14450. this.bumpScale = source.bumpScale;
  14451. this.normalMap = source.normalMap;
  14452. this.normalMapType = source.normalMapType;
  14453. this.normalScale.copy( source.normalScale );
  14454. this.displacementMap = source.displacementMap;
  14455. this.displacementScale = source.displacementScale;
  14456. this.displacementBias = source.displacementBias;
  14457. this.wireframe = source.wireframe;
  14458. this.wireframeLinewidth = source.wireframeLinewidth;
  14459. this.flatShading = source.flatShading;
  14460. return this;
  14461. }
  14462. }
  14463. class MeshLambertMaterial extends Material {
  14464. constructor( parameters ) {
  14465. super();
  14466. this.isMeshLambertMaterial = true;
  14467. this.type = 'MeshLambertMaterial';
  14468. this.color = new Color( 0xffffff ); // diffuse
  14469. this.map = null;
  14470. this.lightMap = null;
  14471. this.lightMapIntensity = 1.0;
  14472. this.aoMap = null;
  14473. this.aoMapIntensity = 1.0;
  14474. this.emissive = new Color( 0x000000 );
  14475. this.emissiveIntensity = 1.0;
  14476. this.emissiveMap = null;
  14477. this.bumpMap = null;
  14478. this.bumpScale = 1;
  14479. this.normalMap = null;
  14480. this.normalMapType = TangentSpaceNormalMap;
  14481. this.normalScale = new Vector2( 1, 1 );
  14482. this.displacementMap = null;
  14483. this.displacementScale = 1;
  14484. this.displacementBias = 0;
  14485. this.specularMap = null;
  14486. this.alphaMap = null;
  14487. this.envMap = null;
  14488. this.envMapRotation = new Euler();
  14489. this.combine = MultiplyOperation;
  14490. this.reflectivity = 1;
  14491. this.refractionRatio = 0.98;
  14492. this.wireframe = false;
  14493. this.wireframeLinewidth = 1;
  14494. this.wireframeLinecap = 'round';
  14495. this.wireframeLinejoin = 'round';
  14496. this.flatShading = false;
  14497. this.fog = true;
  14498. this.setValues( parameters );
  14499. }
  14500. copy( source ) {
  14501. super.copy( source );
  14502. this.color.copy( source.color );
  14503. this.map = source.map;
  14504. this.lightMap = source.lightMap;
  14505. this.lightMapIntensity = source.lightMapIntensity;
  14506. this.aoMap = source.aoMap;
  14507. this.aoMapIntensity = source.aoMapIntensity;
  14508. this.emissive.copy( source.emissive );
  14509. this.emissiveMap = source.emissiveMap;
  14510. this.emissiveIntensity = source.emissiveIntensity;
  14511. this.bumpMap = source.bumpMap;
  14512. this.bumpScale = source.bumpScale;
  14513. this.normalMap = source.normalMap;
  14514. this.normalMapType = source.normalMapType;
  14515. this.normalScale.copy( source.normalScale );
  14516. this.displacementMap = source.displacementMap;
  14517. this.displacementScale = source.displacementScale;
  14518. this.displacementBias = source.displacementBias;
  14519. this.specularMap = source.specularMap;
  14520. this.alphaMap = source.alphaMap;
  14521. this.envMap = source.envMap;
  14522. this.envMapRotation.copy( source.envMapRotation );
  14523. this.combine = source.combine;
  14524. this.reflectivity = source.reflectivity;
  14525. this.refractionRatio = source.refractionRatio;
  14526. this.wireframe = source.wireframe;
  14527. this.wireframeLinewidth = source.wireframeLinewidth;
  14528. this.wireframeLinecap = source.wireframeLinecap;
  14529. this.wireframeLinejoin = source.wireframeLinejoin;
  14530. this.flatShading = source.flatShading;
  14531. this.fog = source.fog;
  14532. return this;
  14533. }
  14534. }
  14535. class MeshDepthMaterial extends Material {
  14536. constructor( parameters ) {
  14537. super();
  14538. this.isMeshDepthMaterial = true;
  14539. this.type = 'MeshDepthMaterial';
  14540. this.depthPacking = BasicDepthPacking;
  14541. this.map = null;
  14542. this.alphaMap = null;
  14543. this.displacementMap = null;
  14544. this.displacementScale = 1;
  14545. this.displacementBias = 0;
  14546. this.wireframe = false;
  14547. this.wireframeLinewidth = 1;
  14548. this.setValues( parameters );
  14549. }
  14550. copy( source ) {
  14551. super.copy( source );
  14552. this.depthPacking = source.depthPacking;
  14553. this.map = source.map;
  14554. this.alphaMap = source.alphaMap;
  14555. this.displacementMap = source.displacementMap;
  14556. this.displacementScale = source.displacementScale;
  14557. this.displacementBias = source.displacementBias;
  14558. this.wireframe = source.wireframe;
  14559. this.wireframeLinewidth = source.wireframeLinewidth;
  14560. return this;
  14561. }
  14562. }
  14563. class MeshDistanceMaterial extends Material {
  14564. constructor( parameters ) {
  14565. super();
  14566. this.isMeshDistanceMaterial = true;
  14567. this.type = 'MeshDistanceMaterial';
  14568. this.map = null;
  14569. this.alphaMap = null;
  14570. this.displacementMap = null;
  14571. this.displacementScale = 1;
  14572. this.displacementBias = 0;
  14573. this.setValues( parameters );
  14574. }
  14575. copy( source ) {
  14576. super.copy( source );
  14577. this.map = source.map;
  14578. this.alphaMap = source.alphaMap;
  14579. this.displacementMap = source.displacementMap;
  14580. this.displacementScale = source.displacementScale;
  14581. this.displacementBias = source.displacementBias;
  14582. return this;
  14583. }
  14584. }
  14585. class MeshMatcapMaterial extends Material {
  14586. constructor( parameters ) {
  14587. super();
  14588. this.isMeshMatcapMaterial = true;
  14589. this.defines = { 'MATCAP': '' };
  14590. this.type = 'MeshMatcapMaterial';
  14591. this.color = new Color( 0xffffff ); // diffuse
  14592. this.matcap = null;
  14593. this.map = null;
  14594. this.bumpMap = null;
  14595. this.bumpScale = 1;
  14596. this.normalMap = null;
  14597. this.normalMapType = TangentSpaceNormalMap;
  14598. this.normalScale = new Vector2( 1, 1 );
  14599. this.displacementMap = null;
  14600. this.displacementScale = 1;
  14601. this.displacementBias = 0;
  14602. this.alphaMap = null;
  14603. this.flatShading = false;
  14604. this.fog = true;
  14605. this.setValues( parameters );
  14606. }
  14607. copy( source ) {
  14608. super.copy( source );
  14609. this.defines = { 'MATCAP': '' };
  14610. this.color.copy( source.color );
  14611. this.matcap = source.matcap;
  14612. this.map = source.map;
  14613. this.bumpMap = source.bumpMap;
  14614. this.bumpScale = source.bumpScale;
  14615. this.normalMap = source.normalMap;
  14616. this.normalMapType = source.normalMapType;
  14617. this.normalScale.copy( source.normalScale );
  14618. this.displacementMap = source.displacementMap;
  14619. this.displacementScale = source.displacementScale;
  14620. this.displacementBias = source.displacementBias;
  14621. this.alphaMap = source.alphaMap;
  14622. this.flatShading = source.flatShading;
  14623. this.fog = source.fog;
  14624. return this;
  14625. }
  14626. }
  14627. class LineDashedMaterial extends LineBasicMaterial {
  14628. constructor( parameters ) {
  14629. super();
  14630. this.isLineDashedMaterial = true;
  14631. this.type = 'LineDashedMaterial';
  14632. this.scale = 1;
  14633. this.dashSize = 3;
  14634. this.gapSize = 1;
  14635. this.setValues( parameters );
  14636. }
  14637. copy( source ) {
  14638. super.copy( source );
  14639. this.scale = source.scale;
  14640. this.dashSize = source.dashSize;
  14641. this.gapSize = source.gapSize;
  14642. return this;
  14643. }
  14644. }
  14645. // converts an array to a specific type
  14646. function convertArray( array, type, forceClone ) {
  14647. if ( ! array || // let 'undefined' and 'null' pass
  14648. ! forceClone && array.constructor === type ) return array;
  14649. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  14650. return new type( array ); // create typed array
  14651. }
  14652. return Array.prototype.slice.call( array ); // create Array
  14653. }
  14654. function isTypedArray( object ) {
  14655. return ArrayBuffer.isView( object ) &&
  14656. ! ( object instanceof DataView );
  14657. }
  14658. // returns an array by which times and values can be sorted
  14659. function getKeyframeOrder( times ) {
  14660. function compareTime( i, j ) {
  14661. return times[ i ] - times[ j ];
  14662. }
  14663. const n = times.length;
  14664. const result = new Array( n );
  14665. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  14666. result.sort( compareTime );
  14667. return result;
  14668. }
  14669. // uses the array previously returned by 'getKeyframeOrder' to sort data
  14670. function sortedArray( values, stride, order ) {
  14671. const nValues = values.length;
  14672. const result = new values.constructor( nValues );
  14673. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  14674. const srcOffset = order[ i ] * stride;
  14675. for ( let j = 0; j !== stride; ++ j ) {
  14676. result[ dstOffset ++ ] = values[ srcOffset + j ];
  14677. }
  14678. }
  14679. return result;
  14680. }
  14681. // function for parsing AOS keyframe formats
  14682. function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
  14683. let i = 1, key = jsonKeys[ 0 ];
  14684. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  14685. key = jsonKeys[ i ++ ];
  14686. }
  14687. if ( key === undefined ) return; // no data
  14688. let value = key[ valuePropertyName ];
  14689. if ( value === undefined ) return; // no data
  14690. if ( Array.isArray( value ) ) {
  14691. do {
  14692. value = key[ valuePropertyName ];
  14693. if ( value !== undefined ) {
  14694. times.push( key.time );
  14695. values.push.apply( values, value ); // push all elements
  14696. }
  14697. key = jsonKeys[ i ++ ];
  14698. } while ( key !== undefined );
  14699. } else if ( value.toArray !== undefined ) {
  14700. // ...assume THREE.Math-ish
  14701. do {
  14702. value = key[ valuePropertyName ];
  14703. if ( value !== undefined ) {
  14704. times.push( key.time );
  14705. value.toArray( values, values.length );
  14706. }
  14707. key = jsonKeys[ i ++ ];
  14708. } while ( key !== undefined );
  14709. } else {
  14710. // otherwise push as-is
  14711. do {
  14712. value = key[ valuePropertyName ];
  14713. if ( value !== undefined ) {
  14714. times.push( key.time );
  14715. values.push( value );
  14716. }
  14717. key = jsonKeys[ i ++ ];
  14718. } while ( key !== undefined );
  14719. }
  14720. }
  14721. function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  14722. const clip = sourceClip.clone();
  14723. clip.name = name;
  14724. const tracks = [];
  14725. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14726. const track = clip.tracks[ i ];
  14727. const valueSize = track.getValueSize();
  14728. const times = [];
  14729. const values = [];
  14730. for ( let j = 0; j < track.times.length; ++ j ) {
  14731. const frame = track.times[ j ] * fps;
  14732. if ( frame < startFrame || frame >= endFrame ) continue;
  14733. times.push( track.times[ j ] );
  14734. for ( let k = 0; k < valueSize; ++ k ) {
  14735. values.push( track.values[ j * valueSize + k ] );
  14736. }
  14737. }
  14738. if ( times.length === 0 ) continue;
  14739. track.times = convertArray( times, track.times.constructor );
  14740. track.values = convertArray( values, track.values.constructor );
  14741. tracks.push( track );
  14742. }
  14743. clip.tracks = tracks;
  14744. // find minimum .times value across all tracks in the trimmed clip
  14745. let minStartTime = Infinity;
  14746. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14747. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  14748. minStartTime = clip.tracks[ i ].times[ 0 ];
  14749. }
  14750. }
  14751. // shift all tracks such that clip begins at t=0
  14752. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14753. clip.tracks[ i ].shift( - 1 * minStartTime );
  14754. }
  14755. clip.resetDuration();
  14756. return clip;
  14757. }
  14758. function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  14759. if ( fps <= 0 ) fps = 30;
  14760. const numTracks = referenceClip.tracks.length;
  14761. const referenceTime = referenceFrame / fps;
  14762. // Make each track's values relative to the values at the reference frame
  14763. for ( let i = 0; i < numTracks; ++ i ) {
  14764. const referenceTrack = referenceClip.tracks[ i ];
  14765. const referenceTrackType = referenceTrack.ValueTypeName;
  14766. // Skip this track if it's non-numeric
  14767. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  14768. // Find the track in the target clip whose name and type matches the reference track
  14769. const targetTrack = targetClip.tracks.find( function ( track ) {
  14770. return track.name === referenceTrack.name
  14771. && track.ValueTypeName === referenceTrackType;
  14772. } );
  14773. if ( targetTrack === undefined ) continue;
  14774. let referenceOffset = 0;
  14775. const referenceValueSize = referenceTrack.getValueSize();
  14776. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14777. referenceOffset = referenceValueSize / 3;
  14778. }
  14779. let targetOffset = 0;
  14780. const targetValueSize = targetTrack.getValueSize();
  14781. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14782. targetOffset = targetValueSize / 3;
  14783. }
  14784. const lastIndex = referenceTrack.times.length - 1;
  14785. let referenceValue;
  14786. // Find the value to subtract out of the track
  14787. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  14788. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  14789. const startIndex = referenceOffset;
  14790. const endIndex = referenceValueSize - referenceOffset;
  14791. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14792. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  14793. // Reference frame is after the last keyframe, so just use the last keyframe
  14794. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  14795. const endIndex = startIndex + referenceValueSize - referenceOffset;
  14796. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14797. } else {
  14798. // Interpolate to the reference value
  14799. const interpolant = referenceTrack.createInterpolant();
  14800. const startIndex = referenceOffset;
  14801. const endIndex = referenceValueSize - referenceOffset;
  14802. interpolant.evaluate( referenceTime );
  14803. referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
  14804. }
  14805. // Conjugate the quaternion
  14806. if ( referenceTrackType === 'quaternion' ) {
  14807. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  14808. referenceQuat.toArray( referenceValue );
  14809. }
  14810. // Subtract the reference value from all of the track values
  14811. const numTimes = targetTrack.times.length;
  14812. for ( let j = 0; j < numTimes; ++ j ) {
  14813. const valueStart = j * targetValueSize + targetOffset;
  14814. if ( referenceTrackType === 'quaternion' ) {
  14815. // Multiply the conjugate for quaternion track types
  14816. Quaternion.multiplyQuaternionsFlat(
  14817. targetTrack.values,
  14818. valueStart,
  14819. referenceValue,
  14820. 0,
  14821. targetTrack.values,
  14822. valueStart
  14823. );
  14824. } else {
  14825. const valueEnd = targetValueSize - targetOffset * 2;
  14826. // Subtract each value for all other numeric track types
  14827. for ( let k = 0; k < valueEnd; ++ k ) {
  14828. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  14829. }
  14830. }
  14831. }
  14832. }
  14833. targetClip.blendMode = AdditiveAnimationBlendMode;
  14834. return targetClip;
  14835. }
  14836. const AnimationUtils = {
  14837. convertArray: convertArray,
  14838. isTypedArray: isTypedArray,
  14839. getKeyframeOrder: getKeyframeOrder,
  14840. sortedArray: sortedArray,
  14841. flattenJSON: flattenJSON,
  14842. subclip: subclip,
  14843. makeClipAdditive: makeClipAdditive
  14844. };
  14845. /**
  14846. * Abstract base class of interpolants over parametric samples.
  14847. *
  14848. * The parameter domain is one dimensional, typically the time or a path
  14849. * along a curve defined by the data.
  14850. *
  14851. * The sample values can have any dimensionality and derived classes may
  14852. * apply special interpretations to the data.
  14853. *
  14854. * This class provides the interval seek in a Template Method, deferring
  14855. * the actual interpolation to derived classes.
  14856. *
  14857. * Time complexity is O(1) for linear access crossing at most two points
  14858. * and O(log N) for random access, where N is the number of positions.
  14859. *
  14860. * References:
  14861. *
  14862. * http://www.oodesign.com/template-method-pattern.html
  14863. *
  14864. */
  14865. class Interpolant {
  14866. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  14867. this.parameterPositions = parameterPositions;
  14868. this._cachedIndex = 0;
  14869. this.resultBuffer = resultBuffer !== undefined ?
  14870. resultBuffer : new sampleValues.constructor( sampleSize );
  14871. this.sampleValues = sampleValues;
  14872. this.valueSize = sampleSize;
  14873. this.settings = null;
  14874. this.DefaultSettings_ = {};
  14875. }
  14876. evaluate( t ) {
  14877. const pp = this.parameterPositions;
  14878. let i1 = this._cachedIndex,
  14879. t1 = pp[ i1 ],
  14880. t0 = pp[ i1 - 1 ];
  14881. validate_interval: {
  14882. seek: {
  14883. let right;
  14884. linear_scan: {
  14885. //- See http://jsperf.com/comparison-to-undefined/3
  14886. //- slower code:
  14887. //-
  14888. //- if ( t >= t1 || t1 === undefined ) {
  14889. forward_scan: if ( ! ( t < t1 ) ) {
  14890. for ( let giveUpAt = i1 + 2; ; ) {
  14891. if ( t1 === undefined ) {
  14892. if ( t < t0 ) break forward_scan;
  14893. // after end
  14894. i1 = pp.length;
  14895. this._cachedIndex = i1;
  14896. return this.copySampleValue_( i1 - 1 );
  14897. }
  14898. if ( i1 === giveUpAt ) break; // this loop
  14899. t0 = t1;
  14900. t1 = pp[ ++ i1 ];
  14901. if ( t < t1 ) {
  14902. // we have arrived at the sought interval
  14903. break seek;
  14904. }
  14905. }
  14906. // prepare binary search on the right side of the index
  14907. right = pp.length;
  14908. break linear_scan;
  14909. }
  14910. //- slower code:
  14911. //- if ( t < t0 || t0 === undefined ) {
  14912. if ( ! ( t >= t0 ) ) {
  14913. // looping?
  14914. const t1global = pp[ 1 ];
  14915. if ( t < t1global ) {
  14916. i1 = 2; // + 1, using the scan for the details
  14917. t0 = t1global;
  14918. }
  14919. // linear reverse scan
  14920. for ( let giveUpAt = i1 - 2; ; ) {
  14921. if ( t0 === undefined ) {
  14922. // before start
  14923. this._cachedIndex = 0;
  14924. return this.copySampleValue_( 0 );
  14925. }
  14926. if ( i1 === giveUpAt ) break; // this loop
  14927. t1 = t0;
  14928. t0 = pp[ -- i1 - 1 ];
  14929. if ( t >= t0 ) {
  14930. // we have arrived at the sought interval
  14931. break seek;
  14932. }
  14933. }
  14934. // prepare binary search on the left side of the index
  14935. right = i1;
  14936. i1 = 0;
  14937. break linear_scan;
  14938. }
  14939. // the interval is valid
  14940. break validate_interval;
  14941. } // linear scan
  14942. // binary search
  14943. while ( i1 < right ) {
  14944. const mid = ( i1 + right ) >>> 1;
  14945. if ( t < pp[ mid ] ) {
  14946. right = mid;
  14947. } else {
  14948. i1 = mid + 1;
  14949. }
  14950. }
  14951. t1 = pp[ i1 ];
  14952. t0 = pp[ i1 - 1 ];
  14953. // check boundary cases, again
  14954. if ( t0 === undefined ) {
  14955. this._cachedIndex = 0;
  14956. return this.copySampleValue_( 0 );
  14957. }
  14958. if ( t1 === undefined ) {
  14959. i1 = pp.length;
  14960. this._cachedIndex = i1;
  14961. return this.copySampleValue_( i1 - 1 );
  14962. }
  14963. } // seek
  14964. this._cachedIndex = i1;
  14965. this.intervalChanged_( i1, t0, t1 );
  14966. } // validate_interval
  14967. return this.interpolate_( i1, t0, t, t1 );
  14968. }
  14969. getSettings_() {
  14970. return this.settings || this.DefaultSettings_;
  14971. }
  14972. copySampleValue_( index ) {
  14973. // copies a sample value to the result buffer
  14974. const result = this.resultBuffer,
  14975. values = this.sampleValues,
  14976. stride = this.valueSize,
  14977. offset = index * stride;
  14978. for ( let i = 0; i !== stride; ++ i ) {
  14979. result[ i ] = values[ offset + i ];
  14980. }
  14981. return result;
  14982. }
  14983. // Template methods for derived classes:
  14984. interpolate_( /* i1, t0, t, t1 */ ) {
  14985. throw new Error( 'call to abstract method' );
  14986. // implementations shall return this.resultBuffer
  14987. }
  14988. intervalChanged_( /* i1, t0, t1 */ ) {
  14989. // empty
  14990. }
  14991. }
  14992. /**
  14993. * Fast and simple cubic spline interpolant.
  14994. *
  14995. * It was derived from a Hermitian construction setting the first derivative
  14996. * at each sample position to the linear slope between neighboring positions
  14997. * over their parameter interval.
  14998. */
  14999. class CubicInterpolant extends Interpolant {
  15000. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15001. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15002. this._weightPrev = - 0;
  15003. this._offsetPrev = - 0;
  15004. this._weightNext = - 0;
  15005. this._offsetNext = - 0;
  15006. this.DefaultSettings_ = {
  15007. endingStart: ZeroCurvatureEnding,
  15008. endingEnd: ZeroCurvatureEnding
  15009. };
  15010. }
  15011. intervalChanged_( i1, t0, t1 ) {
  15012. const pp = this.parameterPositions;
  15013. let iPrev = i1 - 2,
  15014. iNext = i1 + 1,
  15015. tPrev = pp[ iPrev ],
  15016. tNext = pp[ iNext ];
  15017. if ( tPrev === undefined ) {
  15018. switch ( this.getSettings_().endingStart ) {
  15019. case ZeroSlopeEnding:
  15020. // f'(t0) = 0
  15021. iPrev = i1;
  15022. tPrev = 2 * t0 - t1;
  15023. break;
  15024. case WrapAroundEnding:
  15025. // use the other end of the curve
  15026. iPrev = pp.length - 2;
  15027. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  15028. break;
  15029. default: // ZeroCurvatureEnding
  15030. // f''(t0) = 0 a.k.a. Natural Spline
  15031. iPrev = i1;
  15032. tPrev = t1;
  15033. }
  15034. }
  15035. if ( tNext === undefined ) {
  15036. switch ( this.getSettings_().endingEnd ) {
  15037. case ZeroSlopeEnding:
  15038. // f'(tN) = 0
  15039. iNext = i1;
  15040. tNext = 2 * t1 - t0;
  15041. break;
  15042. case WrapAroundEnding:
  15043. // use the other end of the curve
  15044. iNext = 1;
  15045. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  15046. break;
  15047. default: // ZeroCurvatureEnding
  15048. // f''(tN) = 0, a.k.a. Natural Spline
  15049. iNext = i1 - 1;
  15050. tNext = t0;
  15051. }
  15052. }
  15053. const halfDt = ( t1 - t0 ) * 0.5,
  15054. stride = this.valueSize;
  15055. this._weightPrev = halfDt / ( t0 - tPrev );
  15056. this._weightNext = halfDt / ( tNext - t1 );
  15057. this._offsetPrev = iPrev * stride;
  15058. this._offsetNext = iNext * stride;
  15059. }
  15060. interpolate_( i1, t0, t, t1 ) {
  15061. const result = this.resultBuffer,
  15062. values = this.sampleValues,
  15063. stride = this.valueSize,
  15064. o1 = i1 * stride, o0 = o1 - stride,
  15065. oP = this._offsetPrev, oN = this._offsetNext,
  15066. wP = this._weightPrev, wN = this._weightNext,
  15067. p = ( t - t0 ) / ( t1 - t0 ),
  15068. pp = p * p,
  15069. ppp = pp * p;
  15070. // evaluate polynomials
  15071. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  15072. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  15073. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  15074. const sN = wN * ppp - wN * pp;
  15075. // combine data linearly
  15076. for ( let i = 0; i !== stride; ++ i ) {
  15077. result[ i ] =
  15078. sP * values[ oP + i ] +
  15079. s0 * values[ o0 + i ] +
  15080. s1 * values[ o1 + i ] +
  15081. sN * values[ oN + i ];
  15082. }
  15083. return result;
  15084. }
  15085. }
  15086. class LinearInterpolant extends Interpolant {
  15087. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15088. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15089. }
  15090. interpolate_( i1, t0, t, t1 ) {
  15091. const result = this.resultBuffer,
  15092. values = this.sampleValues,
  15093. stride = this.valueSize,
  15094. offset1 = i1 * stride,
  15095. offset0 = offset1 - stride,
  15096. weight1 = ( t - t0 ) / ( t1 - t0 ),
  15097. weight0 = 1 - weight1;
  15098. for ( let i = 0; i !== stride; ++ i ) {
  15099. result[ i ] =
  15100. values[ offset0 + i ] * weight0 +
  15101. values[ offset1 + i ] * weight1;
  15102. }
  15103. return result;
  15104. }
  15105. }
  15106. /**
  15107. *
  15108. * Interpolant that evaluates to the sample value at the position preceding
  15109. * the parameter.
  15110. */
  15111. class DiscreteInterpolant extends Interpolant {
  15112. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15113. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15114. }
  15115. interpolate_( i1 /*, t0, t, t1 */ ) {
  15116. return this.copySampleValue_( i1 - 1 );
  15117. }
  15118. }
  15119. class KeyframeTrack {
  15120. constructor( name, times, values, interpolation ) {
  15121. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  15122. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  15123. this.name = name;
  15124. this.times = convertArray( times, this.TimeBufferType );
  15125. this.values = convertArray( values, this.ValueBufferType );
  15126. this.setInterpolation( interpolation || this.DefaultInterpolation );
  15127. }
  15128. // Serialization (in static context, because of constructor invocation
  15129. // and automatic invocation of .toJSON):
  15130. static toJSON( track ) {
  15131. const trackType = track.constructor;
  15132. let json;
  15133. // derived classes can define a static toJSON method
  15134. if ( trackType.toJSON !== this.toJSON ) {
  15135. json = trackType.toJSON( track );
  15136. } else {
  15137. // by default, we assume the data can be serialized as-is
  15138. json = {
  15139. 'name': track.name,
  15140. 'times': convertArray( track.times, Array ),
  15141. 'values': convertArray( track.values, Array )
  15142. };
  15143. const interpolation = track.getInterpolation();
  15144. if ( interpolation !== track.DefaultInterpolation ) {
  15145. json.interpolation = interpolation;
  15146. }
  15147. }
  15148. json.type = track.ValueTypeName; // mandatory
  15149. return json;
  15150. }
  15151. InterpolantFactoryMethodDiscrete( result ) {
  15152. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  15153. }
  15154. InterpolantFactoryMethodLinear( result ) {
  15155. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15156. }
  15157. InterpolantFactoryMethodSmooth( result ) {
  15158. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  15159. }
  15160. setInterpolation( interpolation ) {
  15161. let factoryMethod;
  15162. switch ( interpolation ) {
  15163. case InterpolateDiscrete:
  15164. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  15165. break;
  15166. case InterpolateLinear:
  15167. factoryMethod = this.InterpolantFactoryMethodLinear;
  15168. break;
  15169. case InterpolateSmooth:
  15170. factoryMethod = this.InterpolantFactoryMethodSmooth;
  15171. break;
  15172. }
  15173. if ( factoryMethod === undefined ) {
  15174. const message = 'unsupported interpolation for ' +
  15175. this.ValueTypeName + ' keyframe track named ' + this.name;
  15176. if ( this.createInterpolant === undefined ) {
  15177. // fall back to default, unless the default itself is messed up
  15178. if ( interpolation !== this.DefaultInterpolation ) {
  15179. this.setInterpolation( this.DefaultInterpolation );
  15180. } else {
  15181. throw new Error( message ); // fatal, in this case
  15182. }
  15183. }
  15184. console.warn( 'THREE.KeyframeTrack:', message );
  15185. return this;
  15186. }
  15187. this.createInterpolant = factoryMethod;
  15188. return this;
  15189. }
  15190. getInterpolation() {
  15191. switch ( this.createInterpolant ) {
  15192. case this.InterpolantFactoryMethodDiscrete:
  15193. return InterpolateDiscrete;
  15194. case this.InterpolantFactoryMethodLinear:
  15195. return InterpolateLinear;
  15196. case this.InterpolantFactoryMethodSmooth:
  15197. return InterpolateSmooth;
  15198. }
  15199. }
  15200. getValueSize() {
  15201. return this.values.length / this.times.length;
  15202. }
  15203. // move all keyframes either forwards or backwards in time
  15204. shift( timeOffset ) {
  15205. if ( timeOffset !== 0.0 ) {
  15206. const times = this.times;
  15207. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15208. times[ i ] += timeOffset;
  15209. }
  15210. }
  15211. return this;
  15212. }
  15213. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  15214. scale( timeScale ) {
  15215. if ( timeScale !== 1.0 ) {
  15216. const times = this.times;
  15217. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15218. times[ i ] *= timeScale;
  15219. }
  15220. }
  15221. return this;
  15222. }
  15223. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  15224. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  15225. trim( startTime, endTime ) {
  15226. const times = this.times,
  15227. nKeys = times.length;
  15228. let from = 0,
  15229. to = nKeys - 1;
  15230. while ( from !== nKeys && times[ from ] < startTime ) {
  15231. ++ from;
  15232. }
  15233. while ( to !== - 1 && times[ to ] > endTime ) {
  15234. -- to;
  15235. }
  15236. ++ to; // inclusive -> exclusive bound
  15237. if ( from !== 0 || to !== nKeys ) {
  15238. // empty tracks are forbidden, so keep at least one keyframe
  15239. if ( from >= to ) {
  15240. to = Math.max( to, 1 );
  15241. from = to - 1;
  15242. }
  15243. const stride = this.getValueSize();
  15244. this.times = times.slice( from, to );
  15245. this.values = this.values.slice( from * stride, to * stride );
  15246. }
  15247. return this;
  15248. }
  15249. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  15250. validate() {
  15251. let valid = true;
  15252. const valueSize = this.getValueSize();
  15253. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  15254. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  15255. valid = false;
  15256. }
  15257. const times = this.times,
  15258. values = this.values,
  15259. nKeys = times.length;
  15260. if ( nKeys === 0 ) {
  15261. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  15262. valid = false;
  15263. }
  15264. let prevTime = null;
  15265. for ( let i = 0; i !== nKeys; i ++ ) {
  15266. const currTime = times[ i ];
  15267. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  15268. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  15269. valid = false;
  15270. break;
  15271. }
  15272. if ( prevTime !== null && prevTime > currTime ) {
  15273. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  15274. valid = false;
  15275. break;
  15276. }
  15277. prevTime = currTime;
  15278. }
  15279. if ( values !== undefined ) {
  15280. if ( isTypedArray( values ) ) {
  15281. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  15282. const value = values[ i ];
  15283. if ( isNaN( value ) ) {
  15284. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  15285. valid = false;
  15286. break;
  15287. }
  15288. }
  15289. }
  15290. }
  15291. return valid;
  15292. }
  15293. // removes equivalent sequential keys as common in morph target sequences
  15294. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  15295. optimize() {
  15296. // times or values may be shared with other tracks, so overwriting is unsafe
  15297. const times = this.times.slice(),
  15298. values = this.values.slice(),
  15299. stride = this.getValueSize(),
  15300. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  15301. lastIndex = times.length - 1;
  15302. let writeIndex = 1;
  15303. for ( let i = 1; i < lastIndex; ++ i ) {
  15304. let keep = false;
  15305. const time = times[ i ];
  15306. const timeNext = times[ i + 1 ];
  15307. // remove adjacent keyframes scheduled at the same time
  15308. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  15309. if ( ! smoothInterpolation ) {
  15310. // remove unnecessary keyframes same as their neighbors
  15311. const offset = i * stride,
  15312. offsetP = offset - stride,
  15313. offsetN = offset + stride;
  15314. for ( let j = 0; j !== stride; ++ j ) {
  15315. const value = values[ offset + j ];
  15316. if ( value !== values[ offsetP + j ] ||
  15317. value !== values[ offsetN + j ] ) {
  15318. keep = true;
  15319. break;
  15320. }
  15321. }
  15322. } else {
  15323. keep = true;
  15324. }
  15325. }
  15326. // in-place compaction
  15327. if ( keep ) {
  15328. if ( i !== writeIndex ) {
  15329. times[ writeIndex ] = times[ i ];
  15330. const readOffset = i * stride,
  15331. writeOffset = writeIndex * stride;
  15332. for ( let j = 0; j !== stride; ++ j ) {
  15333. values[ writeOffset + j ] = values[ readOffset + j ];
  15334. }
  15335. }
  15336. ++ writeIndex;
  15337. }
  15338. }
  15339. // flush last keyframe (compaction looks ahead)
  15340. if ( lastIndex > 0 ) {
  15341. times[ writeIndex ] = times[ lastIndex ];
  15342. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  15343. values[ writeOffset + j ] = values[ readOffset + j ];
  15344. }
  15345. ++ writeIndex;
  15346. }
  15347. if ( writeIndex !== times.length ) {
  15348. this.times = times.slice( 0, writeIndex );
  15349. this.values = values.slice( 0, writeIndex * stride );
  15350. } else {
  15351. this.times = times;
  15352. this.values = values;
  15353. }
  15354. return this;
  15355. }
  15356. clone() {
  15357. const times = this.times.slice();
  15358. const values = this.values.slice();
  15359. const TypedKeyframeTrack = this.constructor;
  15360. const track = new TypedKeyframeTrack( this.name, times, values );
  15361. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  15362. track.createInterpolant = this.createInterpolant;
  15363. return track;
  15364. }
  15365. }
  15366. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  15367. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  15368. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  15369. /**
  15370. * A Track of Boolean keyframe values.
  15371. */
  15372. class BooleanKeyframeTrack extends KeyframeTrack {
  15373. // No interpolation parameter because only InterpolateDiscrete is valid.
  15374. constructor( name, times, values ) {
  15375. super( name, times, values );
  15376. }
  15377. }
  15378. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  15379. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  15380. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15381. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15382. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15383. /**
  15384. * A Track of keyframe values that represent color.
  15385. */
  15386. class ColorKeyframeTrack extends KeyframeTrack {}
  15387. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  15388. /**
  15389. * A Track of numeric keyframe values.
  15390. */
  15391. class NumberKeyframeTrack extends KeyframeTrack {}
  15392. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  15393. /**
  15394. * Spherical linear unit quaternion interpolant.
  15395. */
  15396. class QuaternionLinearInterpolant extends Interpolant {
  15397. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15398. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15399. }
  15400. interpolate_( i1, t0, t, t1 ) {
  15401. const result = this.resultBuffer,
  15402. values = this.sampleValues,
  15403. stride = this.valueSize,
  15404. alpha = ( t - t0 ) / ( t1 - t0 );
  15405. let offset = i1 * stride;
  15406. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  15407. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  15408. }
  15409. return result;
  15410. }
  15411. }
  15412. /**
  15413. * A Track of quaternion keyframe values.
  15414. */
  15415. class QuaternionKeyframeTrack extends KeyframeTrack {
  15416. InterpolantFactoryMethodLinear( result ) {
  15417. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15418. }
  15419. }
  15420. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  15421. // ValueBufferType is inherited
  15422. // DefaultInterpolation is inherited;
  15423. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15424. /**
  15425. * A Track that interpolates Strings
  15426. */
  15427. class StringKeyframeTrack extends KeyframeTrack {
  15428. // No interpolation parameter because only InterpolateDiscrete is valid.
  15429. constructor( name, times, values ) {
  15430. super( name, times, values );
  15431. }
  15432. }
  15433. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  15434. StringKeyframeTrack.prototype.ValueBufferType = Array;
  15435. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15436. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15437. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15438. /**
  15439. * A Track of vectored keyframe values.
  15440. */
  15441. class VectorKeyframeTrack extends KeyframeTrack {}
  15442. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  15443. class AnimationClip {
  15444. constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) {
  15445. this.name = name;
  15446. this.tracks = tracks;
  15447. this.duration = duration;
  15448. this.blendMode = blendMode;
  15449. this.uuid = generateUUID();
  15450. // this means it should figure out its duration by scanning the tracks
  15451. if ( this.duration < 0 ) {
  15452. this.resetDuration();
  15453. }
  15454. }
  15455. static parse( json ) {
  15456. const tracks = [],
  15457. jsonTracks = json.tracks,
  15458. frameTime = 1.0 / ( json.fps || 1.0 );
  15459. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  15460. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  15461. }
  15462. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  15463. clip.uuid = json.uuid;
  15464. return clip;
  15465. }
  15466. static toJSON( clip ) {
  15467. const tracks = [],
  15468. clipTracks = clip.tracks;
  15469. const json = {
  15470. 'name': clip.name,
  15471. 'duration': clip.duration,
  15472. 'tracks': tracks,
  15473. 'uuid': clip.uuid,
  15474. 'blendMode': clip.blendMode
  15475. };
  15476. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  15477. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  15478. }
  15479. return json;
  15480. }
  15481. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  15482. const numMorphTargets = morphTargetSequence.length;
  15483. const tracks = [];
  15484. for ( let i = 0; i < numMorphTargets; i ++ ) {
  15485. let times = [];
  15486. let values = [];
  15487. times.push(
  15488. ( i + numMorphTargets - 1 ) % numMorphTargets,
  15489. i,
  15490. ( i + 1 ) % numMorphTargets );
  15491. values.push( 0, 1, 0 );
  15492. const order = getKeyframeOrder( times );
  15493. times = sortedArray( times, 1, order );
  15494. values = sortedArray( values, 1, order );
  15495. // if there is a key at the first frame, duplicate it as the
  15496. // last frame as well for perfect loop.
  15497. if ( ! noLoop && times[ 0 ] === 0 ) {
  15498. times.push( numMorphTargets );
  15499. values.push( values[ 0 ] );
  15500. }
  15501. tracks.push(
  15502. new NumberKeyframeTrack(
  15503. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  15504. times, values
  15505. ).scale( 1.0 / fps ) );
  15506. }
  15507. return new this( name, - 1, tracks );
  15508. }
  15509. static findByName( objectOrClipArray, name ) {
  15510. let clipArray = objectOrClipArray;
  15511. if ( ! Array.isArray( objectOrClipArray ) ) {
  15512. const o = objectOrClipArray;
  15513. clipArray = o.geometry && o.geometry.animations || o.animations;
  15514. }
  15515. for ( let i = 0; i < clipArray.length; i ++ ) {
  15516. if ( clipArray[ i ].name === name ) {
  15517. return clipArray[ i ];
  15518. }
  15519. }
  15520. return null;
  15521. }
  15522. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  15523. const animationToMorphTargets = {};
  15524. // tested with https://regex101.com/ on trick sequences
  15525. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  15526. const pattern = /^([\w-]*?)([\d]+)$/;
  15527. // sort morph target names into animation groups based
  15528. // patterns like Walk_001, Walk_002, Run_001, Run_002
  15529. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  15530. const morphTarget = morphTargets[ i ];
  15531. const parts = morphTarget.name.match( pattern );
  15532. if ( parts && parts.length > 1 ) {
  15533. const name = parts[ 1 ];
  15534. let animationMorphTargets = animationToMorphTargets[ name ];
  15535. if ( ! animationMorphTargets ) {
  15536. animationToMorphTargets[ name ] = animationMorphTargets = [];
  15537. }
  15538. animationMorphTargets.push( morphTarget );
  15539. }
  15540. }
  15541. const clips = [];
  15542. for ( const name in animationToMorphTargets ) {
  15543. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  15544. }
  15545. return clips;
  15546. }
  15547. // parse the animation.hierarchy format
  15548. static parseAnimation( animation, bones ) {
  15549. if ( ! animation ) {
  15550. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  15551. return null;
  15552. }
  15553. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  15554. // only return track if there are actually keys.
  15555. if ( animationKeys.length !== 0 ) {
  15556. const times = [];
  15557. const values = [];
  15558. flattenJSON( animationKeys, times, values, propertyName );
  15559. // empty keys are filtered out, so check again
  15560. if ( times.length !== 0 ) {
  15561. destTracks.push( new trackType( trackName, times, values ) );
  15562. }
  15563. }
  15564. };
  15565. const tracks = [];
  15566. const clipName = animation.name || 'default';
  15567. const fps = animation.fps || 30;
  15568. const blendMode = animation.blendMode;
  15569. // automatic length determination in AnimationClip.
  15570. let duration = animation.length || - 1;
  15571. const hierarchyTracks = animation.hierarchy || [];
  15572. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  15573. const animationKeys = hierarchyTracks[ h ].keys;
  15574. // skip empty tracks
  15575. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  15576. // process morph targets
  15577. if ( animationKeys[ 0 ].morphTargets ) {
  15578. // figure out all morph targets used in this track
  15579. const morphTargetNames = {};
  15580. let k;
  15581. for ( k = 0; k < animationKeys.length; k ++ ) {
  15582. if ( animationKeys[ k ].morphTargets ) {
  15583. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  15584. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  15585. }
  15586. }
  15587. }
  15588. // create a track for each morph target with all zero
  15589. // morphTargetInfluences except for the keys in which
  15590. // the morphTarget is named.
  15591. for ( const morphTargetName in morphTargetNames ) {
  15592. const times = [];
  15593. const values = [];
  15594. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  15595. const animationKey = animationKeys[ k ];
  15596. times.push( animationKey.time );
  15597. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  15598. }
  15599. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  15600. }
  15601. duration = morphTargetNames.length * fps;
  15602. } else {
  15603. // ...assume skeletal animation
  15604. const boneName = '.bones[' + bones[ h ].name + ']';
  15605. addNonemptyTrack(
  15606. VectorKeyframeTrack, boneName + '.position',
  15607. animationKeys, 'pos', tracks );
  15608. addNonemptyTrack(
  15609. QuaternionKeyframeTrack, boneName + '.quaternion',
  15610. animationKeys, 'rot', tracks );
  15611. addNonemptyTrack(
  15612. VectorKeyframeTrack, boneName + '.scale',
  15613. animationKeys, 'scl', tracks );
  15614. }
  15615. }
  15616. if ( tracks.length === 0 ) {
  15617. return null;
  15618. }
  15619. const clip = new this( clipName, duration, tracks, blendMode );
  15620. return clip;
  15621. }
  15622. resetDuration() {
  15623. const tracks = this.tracks;
  15624. let duration = 0;
  15625. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  15626. const track = this.tracks[ i ];
  15627. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  15628. }
  15629. this.duration = duration;
  15630. return this;
  15631. }
  15632. trim() {
  15633. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15634. this.tracks[ i ].trim( 0, this.duration );
  15635. }
  15636. return this;
  15637. }
  15638. validate() {
  15639. let valid = true;
  15640. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15641. valid = valid && this.tracks[ i ].validate();
  15642. }
  15643. return valid;
  15644. }
  15645. optimize() {
  15646. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15647. this.tracks[ i ].optimize();
  15648. }
  15649. return this;
  15650. }
  15651. clone() {
  15652. const tracks = [];
  15653. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15654. tracks.push( this.tracks[ i ].clone() );
  15655. }
  15656. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  15657. }
  15658. toJSON() {
  15659. return this.constructor.toJSON( this );
  15660. }
  15661. }
  15662. function getTrackTypeForValueTypeName( typeName ) {
  15663. switch ( typeName.toLowerCase() ) {
  15664. case 'scalar':
  15665. case 'double':
  15666. case 'float':
  15667. case 'number':
  15668. case 'integer':
  15669. return NumberKeyframeTrack;
  15670. case 'vector':
  15671. case 'vector2':
  15672. case 'vector3':
  15673. case 'vector4':
  15674. return VectorKeyframeTrack;
  15675. case 'color':
  15676. return ColorKeyframeTrack;
  15677. case 'quaternion':
  15678. return QuaternionKeyframeTrack;
  15679. case 'bool':
  15680. case 'boolean':
  15681. return BooleanKeyframeTrack;
  15682. case 'string':
  15683. return StringKeyframeTrack;
  15684. }
  15685. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  15686. }
  15687. function parseKeyframeTrack( json ) {
  15688. if ( json.type === undefined ) {
  15689. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  15690. }
  15691. const trackType = getTrackTypeForValueTypeName( json.type );
  15692. if ( json.times === undefined ) {
  15693. const times = [], values = [];
  15694. flattenJSON( json.keys, times, values, 'value' );
  15695. json.times = times;
  15696. json.values = values;
  15697. }
  15698. // derived classes can define a static parse method
  15699. if ( trackType.parse !== undefined ) {
  15700. return trackType.parse( json );
  15701. } else {
  15702. // by default, we assume a constructor compatible with the base
  15703. return new trackType( json.name, json.times, json.values, json.interpolation );
  15704. }
  15705. }
  15706. const Cache = {
  15707. enabled: false,
  15708. files: {},
  15709. add: function ( key, file ) {
  15710. if ( this.enabled === false ) return;
  15711. // console.log( 'THREE.Cache', 'Adding key:', key );
  15712. this.files[ key ] = file;
  15713. },
  15714. get: function ( key ) {
  15715. if ( this.enabled === false ) return;
  15716. // console.log( 'THREE.Cache', 'Checking key:', key );
  15717. return this.files[ key ];
  15718. },
  15719. remove: function ( key ) {
  15720. delete this.files[ key ];
  15721. },
  15722. clear: function () {
  15723. this.files = {};
  15724. }
  15725. };
  15726. class LoadingManager {
  15727. constructor( onLoad, onProgress, onError ) {
  15728. const scope = this;
  15729. let isLoading = false;
  15730. let itemsLoaded = 0;
  15731. let itemsTotal = 0;
  15732. let urlModifier = undefined;
  15733. const handlers = [];
  15734. // Refer to #5689 for the reason why we don't set .onStart
  15735. // in the constructor
  15736. this.onStart = undefined;
  15737. this.onLoad = onLoad;
  15738. this.onProgress = onProgress;
  15739. this.onError = onError;
  15740. this.itemStart = function ( url ) {
  15741. itemsTotal ++;
  15742. if ( isLoading === false ) {
  15743. if ( scope.onStart !== undefined ) {
  15744. scope.onStart( url, itemsLoaded, itemsTotal );
  15745. }
  15746. }
  15747. isLoading = true;
  15748. };
  15749. this.itemEnd = function ( url ) {
  15750. itemsLoaded ++;
  15751. if ( scope.onProgress !== undefined ) {
  15752. scope.onProgress( url, itemsLoaded, itemsTotal );
  15753. }
  15754. if ( itemsLoaded === itemsTotal ) {
  15755. isLoading = false;
  15756. if ( scope.onLoad !== undefined ) {
  15757. scope.onLoad();
  15758. }
  15759. }
  15760. };
  15761. this.itemError = function ( url ) {
  15762. if ( scope.onError !== undefined ) {
  15763. scope.onError( url );
  15764. }
  15765. };
  15766. this.resolveURL = function ( url ) {
  15767. if ( urlModifier ) {
  15768. return urlModifier( url );
  15769. }
  15770. return url;
  15771. };
  15772. this.setURLModifier = function ( transform ) {
  15773. urlModifier = transform;
  15774. return this;
  15775. };
  15776. this.addHandler = function ( regex, loader ) {
  15777. handlers.push( regex, loader );
  15778. return this;
  15779. };
  15780. this.removeHandler = function ( regex ) {
  15781. const index = handlers.indexOf( regex );
  15782. if ( index !== - 1 ) {
  15783. handlers.splice( index, 2 );
  15784. }
  15785. return this;
  15786. };
  15787. this.getHandler = function ( file ) {
  15788. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  15789. const regex = handlers[ i ];
  15790. const loader = handlers[ i + 1 ];
  15791. if ( regex.global ) regex.lastIndex = 0; // see #17920
  15792. if ( regex.test( file ) ) {
  15793. return loader;
  15794. }
  15795. }
  15796. return null;
  15797. };
  15798. }
  15799. }
  15800. const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager();
  15801. class Loader {
  15802. constructor( manager ) {
  15803. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  15804. this.crossOrigin = 'anonymous';
  15805. this.withCredentials = false;
  15806. this.path = '';
  15807. this.resourcePath = '';
  15808. this.requestHeader = {};
  15809. }
  15810. load( /* url, onLoad, onProgress, onError */ ) {}
  15811. loadAsync( url, onProgress ) {
  15812. const scope = this;
  15813. return new Promise( function ( resolve, reject ) {
  15814. scope.load( url, resolve, onProgress, reject );
  15815. } );
  15816. }
  15817. parse( /* data */ ) {}
  15818. setCrossOrigin( crossOrigin ) {
  15819. this.crossOrigin = crossOrigin;
  15820. return this;
  15821. }
  15822. setWithCredentials( value ) {
  15823. this.withCredentials = value;
  15824. return this;
  15825. }
  15826. setPath( path ) {
  15827. this.path = path;
  15828. return this;
  15829. }
  15830. setResourcePath( resourcePath ) {
  15831. this.resourcePath = resourcePath;
  15832. return this;
  15833. }
  15834. setRequestHeader( requestHeader ) {
  15835. this.requestHeader = requestHeader;
  15836. return this;
  15837. }
  15838. }
  15839. Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT';
  15840. const loading = {};
  15841. class HttpError extends Error {
  15842. constructor( message, response ) {
  15843. super( message );
  15844. this.response = response;
  15845. }
  15846. }
  15847. class FileLoader extends Loader {
  15848. constructor( manager ) {
  15849. super( manager );
  15850. }
  15851. load( url, onLoad, onProgress, onError ) {
  15852. if ( url === undefined ) url = '';
  15853. if ( this.path !== undefined ) url = this.path + url;
  15854. url = this.manager.resolveURL( url );
  15855. const cached = Cache.get( url );
  15856. if ( cached !== undefined ) {
  15857. this.manager.itemStart( url );
  15858. setTimeout( () => {
  15859. if ( onLoad ) onLoad( cached );
  15860. this.manager.itemEnd( url );
  15861. }, 0 );
  15862. return cached;
  15863. }
  15864. // Check if request is duplicate
  15865. if ( loading[ url ] !== undefined ) {
  15866. loading[ url ].push( {
  15867. onLoad: onLoad,
  15868. onProgress: onProgress,
  15869. onError: onError
  15870. } );
  15871. return;
  15872. }
  15873. // Initialise array for duplicate requests
  15874. loading[ url ] = [];
  15875. loading[ url ].push( {
  15876. onLoad: onLoad,
  15877. onProgress: onProgress,
  15878. onError: onError,
  15879. } );
  15880. // create request
  15881. const req = new Request( url, {
  15882. headers: new Headers( this.requestHeader ),
  15883. credentials: this.withCredentials ? 'include' : 'same-origin',
  15884. // An abort controller could be added within a future PR
  15885. } );
  15886. // record states ( avoid data race )
  15887. const mimeType = this.mimeType;
  15888. const responseType = this.responseType;
  15889. // start the fetch
  15890. fetch( req )
  15891. .then( response => {
  15892. if ( response.status === 200 || response.status === 0 ) {
  15893. // Some browsers return HTTP Status 0 when using non-http protocol
  15894. // e.g. 'file://' or 'data://'. Handle as success.
  15895. if ( response.status === 0 ) {
  15896. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  15897. }
  15898. // Workaround: Checking if response.body === undefined for Alipay browser #23548
  15899. if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) {
  15900. return response;
  15901. }
  15902. const callbacks = loading[ url ];
  15903. const reader = response.body.getReader();
  15904. // Nginx needs X-File-Size check
  15905. // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
  15906. const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' );
  15907. const total = contentLength ? parseInt( contentLength ) : 0;
  15908. const lengthComputable = total !== 0;
  15909. let loaded = 0;
  15910. // periodically read data into the new stream tracking while download progress
  15911. const stream = new ReadableStream( {
  15912. start( controller ) {
  15913. readData();
  15914. function readData() {
  15915. reader.read().then( ( { done, value } ) => {
  15916. if ( done ) {
  15917. controller.close();
  15918. } else {
  15919. loaded += value.byteLength;
  15920. const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
  15921. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15922. const callback = callbacks[ i ];
  15923. if ( callback.onProgress ) callback.onProgress( event );
  15924. }
  15925. controller.enqueue( value );
  15926. readData();
  15927. }
  15928. }, ( e ) => {
  15929. controller.error( e );
  15930. } );
  15931. }
  15932. }
  15933. } );
  15934. return new Response( stream );
  15935. } else {
  15936. throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response );
  15937. }
  15938. } )
  15939. .then( response => {
  15940. switch ( responseType ) {
  15941. case 'arraybuffer':
  15942. return response.arrayBuffer();
  15943. case 'blob':
  15944. return response.blob();
  15945. case 'document':
  15946. return response.text()
  15947. .then( text => {
  15948. const parser = new DOMParser();
  15949. return parser.parseFromString( text, mimeType );
  15950. } );
  15951. case 'json':
  15952. return response.json();
  15953. default:
  15954. if ( mimeType === undefined ) {
  15955. return response.text();
  15956. } else {
  15957. // sniff encoding
  15958. const re = /charset="?([^;"\s]*)"?/i;
  15959. const exec = re.exec( mimeType );
  15960. const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined;
  15961. const decoder = new TextDecoder( label );
  15962. return response.arrayBuffer().then( ab => decoder.decode( ab ) );
  15963. }
  15964. }
  15965. } )
  15966. .then( data => {
  15967. // Add to cache only on HTTP success, so that we do not cache
  15968. // error response bodies as proper responses to requests.
  15969. Cache.add( url, data );
  15970. const callbacks = loading[ url ];
  15971. delete loading[ url ];
  15972. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15973. const callback = callbacks[ i ];
  15974. if ( callback.onLoad ) callback.onLoad( data );
  15975. }
  15976. } )
  15977. .catch( err => {
  15978. // Abort errors and other errors are handled the same
  15979. const callbacks = loading[ url ];
  15980. if ( callbacks === undefined ) {
  15981. // When onLoad was called and url was deleted in `loading`
  15982. this.manager.itemError( url );
  15983. throw err;
  15984. }
  15985. delete loading[ url ];
  15986. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15987. const callback = callbacks[ i ];
  15988. if ( callback.onError ) callback.onError( err );
  15989. }
  15990. this.manager.itemError( url );
  15991. } )
  15992. .finally( () => {
  15993. this.manager.itemEnd( url );
  15994. } );
  15995. this.manager.itemStart( url );
  15996. }
  15997. setResponseType( value ) {
  15998. this.responseType = value;
  15999. return this;
  16000. }
  16001. setMimeType( value ) {
  16002. this.mimeType = value;
  16003. return this;
  16004. }
  16005. }
  16006. class AnimationLoader extends Loader {
  16007. constructor( manager ) {
  16008. super( manager );
  16009. }
  16010. load( url, onLoad, onProgress, onError ) {
  16011. const scope = this;
  16012. const loader = new FileLoader( this.manager );
  16013. loader.setPath( this.path );
  16014. loader.setRequestHeader( this.requestHeader );
  16015. loader.setWithCredentials( this.withCredentials );
  16016. loader.load( url, function ( text ) {
  16017. try {
  16018. onLoad( scope.parse( JSON.parse( text ) ) );
  16019. } catch ( e ) {
  16020. if ( onError ) {
  16021. onError( e );
  16022. } else {
  16023. console.error( e );
  16024. }
  16025. scope.manager.itemError( url );
  16026. }
  16027. }, onProgress, onError );
  16028. }
  16029. parse( json ) {
  16030. const animations = [];
  16031. for ( let i = 0; i < json.length; i ++ ) {
  16032. const clip = AnimationClip.parse( json[ i ] );
  16033. animations.push( clip );
  16034. }
  16035. return animations;
  16036. }
  16037. }
  16038. /**
  16039. * Abstract Base class to block based textures loader (dds, pvr, ...)
  16040. *
  16041. * Sub classes have to implement the parse() method which will be used in load().
  16042. */
  16043. class CompressedTextureLoader extends Loader {
  16044. constructor( manager ) {
  16045. super( manager );
  16046. }
  16047. load( url, onLoad, onProgress, onError ) {
  16048. const scope = this;
  16049. const images = [];
  16050. const texture = new CompressedTexture();
  16051. const loader = new FileLoader( this.manager );
  16052. loader.setPath( this.path );
  16053. loader.setResponseType( 'arraybuffer' );
  16054. loader.setRequestHeader( this.requestHeader );
  16055. loader.setWithCredentials( scope.withCredentials );
  16056. let loaded = 0;
  16057. function loadTexture( i ) {
  16058. loader.load( url[ i ], function ( buffer ) {
  16059. const texDatas = scope.parse( buffer, true );
  16060. images[ i ] = {
  16061. width: texDatas.width,
  16062. height: texDatas.height,
  16063. format: texDatas.format,
  16064. mipmaps: texDatas.mipmaps
  16065. };
  16066. loaded += 1;
  16067. if ( loaded === 6 ) {
  16068. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  16069. texture.image = images;
  16070. texture.format = texDatas.format;
  16071. texture.needsUpdate = true;
  16072. if ( onLoad ) onLoad( texture );
  16073. }
  16074. }, onProgress, onError );
  16075. }
  16076. if ( Array.isArray( url ) ) {
  16077. for ( let i = 0, il = url.length; i < il; ++ i ) {
  16078. loadTexture( i );
  16079. }
  16080. } else {
  16081. // compressed cubemap texture stored in a single DDS file
  16082. loader.load( url, function ( buffer ) {
  16083. const texDatas = scope.parse( buffer, true );
  16084. if ( texDatas.isCubemap ) {
  16085. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  16086. for ( let f = 0; f < faces; f ++ ) {
  16087. images[ f ] = { mipmaps: [] };
  16088. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  16089. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  16090. images[ f ].format = texDatas.format;
  16091. images[ f ].width = texDatas.width;
  16092. images[ f ].height = texDatas.height;
  16093. }
  16094. }
  16095. texture.image = images;
  16096. } else {
  16097. texture.image.width = texDatas.width;
  16098. texture.image.height = texDatas.height;
  16099. texture.mipmaps = texDatas.mipmaps;
  16100. }
  16101. if ( texDatas.mipmapCount === 1 ) {
  16102. texture.minFilter = LinearFilter;
  16103. }
  16104. texture.format = texDatas.format;
  16105. texture.needsUpdate = true;
  16106. if ( onLoad ) onLoad( texture );
  16107. }, onProgress, onError );
  16108. }
  16109. return texture;
  16110. }
  16111. }
  16112. class ImageLoader extends Loader {
  16113. constructor( manager ) {
  16114. super( manager );
  16115. }
  16116. load( url, onLoad, onProgress, onError ) {
  16117. if ( this.path !== undefined ) url = this.path + url;
  16118. url = this.manager.resolveURL( url );
  16119. const scope = this;
  16120. const cached = Cache.get( url );
  16121. if ( cached !== undefined ) {
  16122. scope.manager.itemStart( url );
  16123. setTimeout( function () {
  16124. if ( onLoad ) onLoad( cached );
  16125. scope.manager.itemEnd( url );
  16126. }, 0 );
  16127. return cached;
  16128. }
  16129. const image = createElementNS( 'img' );
  16130. function onImageLoad() {
  16131. removeEventListeners();
  16132. Cache.add( url, this );
  16133. if ( onLoad ) onLoad( this );
  16134. scope.manager.itemEnd( url );
  16135. }
  16136. function onImageError( event ) {
  16137. removeEventListeners();
  16138. if ( onError ) onError( event );
  16139. scope.manager.itemError( url );
  16140. scope.manager.itemEnd( url );
  16141. }
  16142. function removeEventListeners() {
  16143. image.removeEventListener( 'load', onImageLoad, false );
  16144. image.removeEventListener( 'error', onImageError, false );
  16145. }
  16146. image.addEventListener( 'load', onImageLoad, false );
  16147. image.addEventListener( 'error', onImageError, false );
  16148. if ( url.slice( 0, 5 ) !== 'data:' ) {
  16149. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  16150. }
  16151. scope.manager.itemStart( url );
  16152. image.src = url;
  16153. return image;
  16154. }
  16155. }
  16156. class CubeTextureLoader extends Loader {
  16157. constructor( manager ) {
  16158. super( manager );
  16159. }
  16160. load( urls, onLoad, onProgress, onError ) {
  16161. const texture = new CubeTexture();
  16162. texture.colorSpace = SRGBColorSpace;
  16163. const loader = new ImageLoader( this.manager );
  16164. loader.setCrossOrigin( this.crossOrigin );
  16165. loader.setPath( this.path );
  16166. let loaded = 0;
  16167. function loadTexture( i ) {
  16168. loader.load( urls[ i ], function ( image ) {
  16169. texture.images[ i ] = image;
  16170. loaded ++;
  16171. if ( loaded === 6 ) {
  16172. texture.needsUpdate = true;
  16173. if ( onLoad ) onLoad( texture );
  16174. }
  16175. }, undefined, onError );
  16176. }
  16177. for ( let i = 0; i < urls.length; ++ i ) {
  16178. loadTexture( i );
  16179. }
  16180. return texture;
  16181. }
  16182. }
  16183. /**
  16184. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  16185. *
  16186. * Sub classes have to implement the parse() method which will be used in load().
  16187. */
  16188. class DataTextureLoader extends Loader {
  16189. constructor( manager ) {
  16190. super( manager );
  16191. }
  16192. load( url, onLoad, onProgress, onError ) {
  16193. const scope = this;
  16194. const texture = new DataTexture();
  16195. const loader = new FileLoader( this.manager );
  16196. loader.setResponseType( 'arraybuffer' );
  16197. loader.setRequestHeader( this.requestHeader );
  16198. loader.setPath( this.path );
  16199. loader.setWithCredentials( scope.withCredentials );
  16200. loader.load( url, function ( buffer ) {
  16201. let texData;
  16202. try {
  16203. texData = scope.parse( buffer );
  16204. } catch ( error ) {
  16205. if ( onError !== undefined ) {
  16206. onError( error );
  16207. } else {
  16208. console.error( error );
  16209. return;
  16210. }
  16211. }
  16212. if ( texData.image !== undefined ) {
  16213. texture.image = texData.image;
  16214. } else if ( texData.data !== undefined ) {
  16215. texture.image.width = texData.width;
  16216. texture.image.height = texData.height;
  16217. texture.image.data = texData.data;
  16218. }
  16219. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  16220. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  16221. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  16222. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  16223. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  16224. if ( texData.colorSpace !== undefined ) {
  16225. texture.colorSpace = texData.colorSpace;
  16226. }
  16227. if ( texData.flipY !== undefined ) {
  16228. texture.flipY = texData.flipY;
  16229. }
  16230. if ( texData.format !== undefined ) {
  16231. texture.format = texData.format;
  16232. }
  16233. if ( texData.type !== undefined ) {
  16234. texture.type = texData.type;
  16235. }
  16236. if ( texData.mipmaps !== undefined ) {
  16237. texture.mipmaps = texData.mipmaps;
  16238. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  16239. }
  16240. if ( texData.mipmapCount === 1 ) {
  16241. texture.minFilter = LinearFilter;
  16242. }
  16243. if ( texData.generateMipmaps !== undefined ) {
  16244. texture.generateMipmaps = texData.generateMipmaps;
  16245. }
  16246. texture.needsUpdate = true;
  16247. if ( onLoad ) onLoad( texture, texData );
  16248. }, onProgress, onError );
  16249. return texture;
  16250. }
  16251. }
  16252. class TextureLoader extends Loader {
  16253. constructor( manager ) {
  16254. super( manager );
  16255. }
  16256. load( url, onLoad, onProgress, onError ) {
  16257. const texture = new Texture();
  16258. const loader = new ImageLoader( this.manager );
  16259. loader.setCrossOrigin( this.crossOrigin );
  16260. loader.setPath( this.path );
  16261. loader.load( url, function ( image ) {
  16262. texture.image = image;
  16263. texture.needsUpdate = true;
  16264. if ( onLoad !== undefined ) {
  16265. onLoad( texture );
  16266. }
  16267. }, onProgress, onError );
  16268. return texture;
  16269. }
  16270. }
  16271. class Light extends Object3D {
  16272. constructor( color, intensity = 1 ) {
  16273. super();
  16274. this.isLight = true;
  16275. this.type = 'Light';
  16276. this.color = new Color( color );
  16277. this.intensity = intensity;
  16278. }
  16279. dispose() {
  16280. // Empty here in base class; some subclasses override.
  16281. }
  16282. copy( source, recursive ) {
  16283. super.copy( source, recursive );
  16284. this.color.copy( source.color );
  16285. this.intensity = source.intensity;
  16286. return this;
  16287. }
  16288. toJSON( meta ) {
  16289. const data = super.toJSON( meta );
  16290. data.object.color = this.color.getHex();
  16291. data.object.intensity = this.intensity;
  16292. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  16293. if ( this.distance !== undefined ) data.object.distance = this.distance;
  16294. if ( this.angle !== undefined ) data.object.angle = this.angle;
  16295. if ( this.decay !== undefined ) data.object.decay = this.decay;
  16296. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  16297. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  16298. if ( this.target !== undefined ) data.object.target = this.target.uuid;
  16299. return data;
  16300. }
  16301. }
  16302. class HemisphereLight extends Light {
  16303. constructor( skyColor, groundColor, intensity ) {
  16304. super( skyColor, intensity );
  16305. this.isHemisphereLight = true;
  16306. this.type = 'HemisphereLight';
  16307. this.position.copy( Object3D.DEFAULT_UP );
  16308. this.updateMatrix();
  16309. this.groundColor = new Color( groundColor );
  16310. }
  16311. copy( source, recursive ) {
  16312. super.copy( source, recursive );
  16313. this.groundColor.copy( source.groundColor );
  16314. return this;
  16315. }
  16316. }
  16317. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  16318. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  16319. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  16320. class LightShadow {
  16321. constructor( camera ) {
  16322. this.camera = camera;
  16323. this.intensity = 1;
  16324. this.bias = 0;
  16325. this.normalBias = 0;
  16326. this.radius = 1;
  16327. this.blurSamples = 8;
  16328. this.mapSize = new Vector2( 512, 512 );
  16329. this.map = null;
  16330. this.mapPass = null;
  16331. this.matrix = new Matrix4();
  16332. this.autoUpdate = true;
  16333. this.needsUpdate = false;
  16334. this._frustum = new Frustum();
  16335. this._frameExtents = new Vector2( 1, 1 );
  16336. this._viewportCount = 1;
  16337. this._viewports = [
  16338. new Vector4( 0, 0, 1, 1 )
  16339. ];
  16340. }
  16341. getViewportCount() {
  16342. return this._viewportCount;
  16343. }
  16344. getFrustum() {
  16345. return this._frustum;
  16346. }
  16347. updateMatrices( light ) {
  16348. const shadowCamera = this.camera;
  16349. const shadowMatrix = this.matrix;
  16350. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  16351. shadowCamera.position.copy( _lightPositionWorld$1 );
  16352. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  16353. shadowCamera.lookAt( _lookTarget$1 );
  16354. shadowCamera.updateMatrixWorld();
  16355. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  16356. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  16357. shadowMatrix.set(
  16358. 0.5, 0.0, 0.0, 0.5,
  16359. 0.0, 0.5, 0.0, 0.5,
  16360. 0.0, 0.0, 0.5, 0.5,
  16361. 0.0, 0.0, 0.0, 1.0
  16362. );
  16363. shadowMatrix.multiply( _projScreenMatrix$1 );
  16364. }
  16365. getViewport( viewportIndex ) {
  16366. return this._viewports[ viewportIndex ];
  16367. }
  16368. getFrameExtents() {
  16369. return this._frameExtents;
  16370. }
  16371. dispose() {
  16372. if ( this.map ) {
  16373. this.map.dispose();
  16374. }
  16375. if ( this.mapPass ) {
  16376. this.mapPass.dispose();
  16377. }
  16378. }
  16379. copy( source ) {
  16380. this.camera = source.camera.clone();
  16381. this.intensity = source.intensity;
  16382. this.bias = source.bias;
  16383. this.radius = source.radius;
  16384. this.mapSize.copy( source.mapSize );
  16385. return this;
  16386. }
  16387. clone() {
  16388. return new this.constructor().copy( this );
  16389. }
  16390. toJSON() {
  16391. const object = {};
  16392. if ( this.intensity !== 1 ) object.intensity = this.intensity;
  16393. if ( this.bias !== 0 ) object.bias = this.bias;
  16394. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  16395. if ( this.radius !== 1 ) object.radius = this.radius;
  16396. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  16397. object.camera = this.camera.toJSON( false ).object;
  16398. delete object.camera.matrix;
  16399. return object;
  16400. }
  16401. }
  16402. class SpotLightShadow extends LightShadow {
  16403. constructor() {
  16404. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  16405. this.isSpotLightShadow = true;
  16406. this.focus = 1;
  16407. }
  16408. updateMatrices( light ) {
  16409. const camera = this.camera;
  16410. const fov = RAD2DEG * 2 * light.angle * this.focus;
  16411. const aspect = this.mapSize.width / this.mapSize.height;
  16412. const far = light.distance || camera.far;
  16413. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  16414. camera.fov = fov;
  16415. camera.aspect = aspect;
  16416. camera.far = far;
  16417. camera.updateProjectionMatrix();
  16418. }
  16419. super.updateMatrices( light );
  16420. }
  16421. copy( source ) {
  16422. super.copy( source );
  16423. this.focus = source.focus;
  16424. return this;
  16425. }
  16426. }
  16427. class SpotLight extends Light {
  16428. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
  16429. super( color, intensity );
  16430. this.isSpotLight = true;
  16431. this.type = 'SpotLight';
  16432. this.position.copy( Object3D.DEFAULT_UP );
  16433. this.updateMatrix();
  16434. this.target = new Object3D();
  16435. this.distance = distance;
  16436. this.angle = angle;
  16437. this.penumbra = penumbra;
  16438. this.decay = decay;
  16439. this.map = null;
  16440. this.shadow = new SpotLightShadow();
  16441. }
  16442. get power() {
  16443. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16444. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  16445. return this.intensity * Math.PI;
  16446. }
  16447. set power( power ) {
  16448. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16449. this.intensity = power / Math.PI;
  16450. }
  16451. dispose() {
  16452. this.shadow.dispose();
  16453. }
  16454. copy( source, recursive ) {
  16455. super.copy( source, recursive );
  16456. this.distance = source.distance;
  16457. this.angle = source.angle;
  16458. this.penumbra = source.penumbra;
  16459. this.decay = source.decay;
  16460. this.target = source.target.clone();
  16461. this.shadow = source.shadow.clone();
  16462. return this;
  16463. }
  16464. }
  16465. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  16466. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  16467. const _lookTarget = /*@__PURE__*/ new Vector3();
  16468. class PointLightShadow extends LightShadow {
  16469. constructor() {
  16470. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  16471. this.isPointLightShadow = true;
  16472. this._frameExtents = new Vector2( 4, 2 );
  16473. this._viewportCount = 6;
  16474. this._viewports = [
  16475. // These viewports map a cube-map onto a 2D texture with the
  16476. // following orientation:
  16477. //
  16478. // xzXZ
  16479. // y Y
  16480. //
  16481. // X - Positive x direction
  16482. // x - Negative x direction
  16483. // Y - Positive y direction
  16484. // y - Negative y direction
  16485. // Z - Positive z direction
  16486. // z - Negative z direction
  16487. // positive X
  16488. new Vector4( 2, 1, 1, 1 ),
  16489. // negative X
  16490. new Vector4( 0, 1, 1, 1 ),
  16491. // positive Z
  16492. new Vector4( 3, 1, 1, 1 ),
  16493. // negative Z
  16494. new Vector4( 1, 1, 1, 1 ),
  16495. // positive Y
  16496. new Vector4( 3, 0, 1, 1 ),
  16497. // negative Y
  16498. new Vector4( 1, 0, 1, 1 )
  16499. ];
  16500. this._cubeDirections = [
  16501. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  16502. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  16503. ];
  16504. this._cubeUps = [
  16505. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  16506. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  16507. ];
  16508. }
  16509. updateMatrices( light, viewportIndex = 0 ) {
  16510. const camera = this.camera;
  16511. const shadowMatrix = this.matrix;
  16512. const far = light.distance || camera.far;
  16513. if ( far !== camera.far ) {
  16514. camera.far = far;
  16515. camera.updateProjectionMatrix();
  16516. }
  16517. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  16518. camera.position.copy( _lightPositionWorld );
  16519. _lookTarget.copy( camera.position );
  16520. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  16521. camera.up.copy( this._cubeUps[ viewportIndex ] );
  16522. camera.lookAt( _lookTarget );
  16523. camera.updateMatrixWorld();
  16524. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  16525. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  16526. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  16527. }
  16528. }
  16529. class PointLight extends Light {
  16530. constructor( color, intensity, distance = 0, decay = 2 ) {
  16531. super( color, intensity );
  16532. this.isPointLight = true;
  16533. this.type = 'PointLight';
  16534. this.distance = distance;
  16535. this.decay = decay;
  16536. this.shadow = new PointLightShadow();
  16537. }
  16538. get power() {
  16539. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16540. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  16541. return this.intensity * 4 * Math.PI;
  16542. }
  16543. set power( power ) {
  16544. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16545. this.intensity = power / ( 4 * Math.PI );
  16546. }
  16547. dispose() {
  16548. this.shadow.dispose();
  16549. }
  16550. copy( source, recursive ) {
  16551. super.copy( source, recursive );
  16552. this.distance = source.distance;
  16553. this.decay = source.decay;
  16554. this.shadow = source.shadow.clone();
  16555. return this;
  16556. }
  16557. }
  16558. class OrthographicCamera extends Camera {
  16559. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  16560. super();
  16561. this.isOrthographicCamera = true;
  16562. this.type = 'OrthographicCamera';
  16563. this.zoom = 1;
  16564. this.view = null;
  16565. this.left = left;
  16566. this.right = right;
  16567. this.top = top;
  16568. this.bottom = bottom;
  16569. this.near = near;
  16570. this.far = far;
  16571. this.updateProjectionMatrix();
  16572. }
  16573. copy( source, recursive ) {
  16574. super.copy( source, recursive );
  16575. this.left = source.left;
  16576. this.right = source.right;
  16577. this.top = source.top;
  16578. this.bottom = source.bottom;
  16579. this.near = source.near;
  16580. this.far = source.far;
  16581. this.zoom = source.zoom;
  16582. this.view = source.view === null ? null : Object.assign( {}, source.view );
  16583. return this;
  16584. }
  16585. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  16586. if ( this.view === null ) {
  16587. this.view = {
  16588. enabled: true,
  16589. fullWidth: 1,
  16590. fullHeight: 1,
  16591. offsetX: 0,
  16592. offsetY: 0,
  16593. width: 1,
  16594. height: 1
  16595. };
  16596. }
  16597. this.view.enabled = true;
  16598. this.view.fullWidth = fullWidth;
  16599. this.view.fullHeight = fullHeight;
  16600. this.view.offsetX = x;
  16601. this.view.offsetY = y;
  16602. this.view.width = width;
  16603. this.view.height = height;
  16604. this.updateProjectionMatrix();
  16605. }
  16606. clearViewOffset() {
  16607. if ( this.view !== null ) {
  16608. this.view.enabled = false;
  16609. }
  16610. this.updateProjectionMatrix();
  16611. }
  16612. updateProjectionMatrix() {
  16613. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  16614. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  16615. const cx = ( this.right + this.left ) / 2;
  16616. const cy = ( this.top + this.bottom ) / 2;
  16617. let left = cx - dx;
  16618. let right = cx + dx;
  16619. let top = cy + dy;
  16620. let bottom = cy - dy;
  16621. if ( this.view !== null && this.view.enabled ) {
  16622. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  16623. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  16624. left += scaleW * this.view.offsetX;
  16625. right = left + scaleW * this.view.width;
  16626. top -= scaleH * this.view.offsetY;
  16627. bottom = top - scaleH * this.view.height;
  16628. }
  16629. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
  16630. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  16631. }
  16632. toJSON( meta ) {
  16633. const data = super.toJSON( meta );
  16634. data.object.zoom = this.zoom;
  16635. data.object.left = this.left;
  16636. data.object.right = this.right;
  16637. data.object.top = this.top;
  16638. data.object.bottom = this.bottom;
  16639. data.object.near = this.near;
  16640. data.object.far = this.far;
  16641. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  16642. return data;
  16643. }
  16644. }
  16645. class DirectionalLightShadow extends LightShadow {
  16646. constructor() {
  16647. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  16648. this.isDirectionalLightShadow = true;
  16649. }
  16650. }
  16651. class DirectionalLight extends Light {
  16652. constructor( color, intensity ) {
  16653. super( color, intensity );
  16654. this.isDirectionalLight = true;
  16655. this.type = 'DirectionalLight';
  16656. this.position.copy( Object3D.DEFAULT_UP );
  16657. this.updateMatrix();
  16658. this.target = new Object3D();
  16659. this.shadow = new DirectionalLightShadow();
  16660. }
  16661. dispose() {
  16662. this.shadow.dispose();
  16663. }
  16664. copy( source ) {
  16665. super.copy( source );
  16666. this.target = source.target.clone();
  16667. this.shadow = source.shadow.clone();
  16668. return this;
  16669. }
  16670. }
  16671. class AmbientLight extends Light {
  16672. constructor( color, intensity ) {
  16673. super( color, intensity );
  16674. this.isAmbientLight = true;
  16675. this.type = 'AmbientLight';
  16676. }
  16677. }
  16678. class RectAreaLight extends Light {
  16679. constructor( color, intensity, width = 10, height = 10 ) {
  16680. super( color, intensity );
  16681. this.isRectAreaLight = true;
  16682. this.type = 'RectAreaLight';
  16683. this.width = width;
  16684. this.height = height;
  16685. }
  16686. get power() {
  16687. // compute the light's luminous power (in lumens) from its intensity (in nits)
  16688. return this.intensity * this.width * this.height * Math.PI;
  16689. }
  16690. set power( power ) {
  16691. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  16692. this.intensity = power / ( this.width * this.height * Math.PI );
  16693. }
  16694. copy( source ) {
  16695. super.copy( source );
  16696. this.width = source.width;
  16697. this.height = source.height;
  16698. return this;
  16699. }
  16700. toJSON( meta ) {
  16701. const data = super.toJSON( meta );
  16702. data.object.width = this.width;
  16703. data.object.height = this.height;
  16704. return data;
  16705. }
  16706. }
  16707. /**
  16708. * Primary reference:
  16709. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16710. *
  16711. * Secondary reference:
  16712. * https://www.ppsloan.org/publications/StupidSH36.pdf
  16713. */
  16714. // 3-band SH defined by 9 coefficients
  16715. class SphericalHarmonics3 {
  16716. constructor() {
  16717. this.isSphericalHarmonics3 = true;
  16718. this.coefficients = [];
  16719. for ( let i = 0; i < 9; i ++ ) {
  16720. this.coefficients.push( new Vector3() );
  16721. }
  16722. }
  16723. set( coefficients ) {
  16724. for ( let i = 0; i < 9; i ++ ) {
  16725. this.coefficients[ i ].copy( coefficients[ i ] );
  16726. }
  16727. return this;
  16728. }
  16729. zero() {
  16730. for ( let i = 0; i < 9; i ++ ) {
  16731. this.coefficients[ i ].set( 0, 0, 0 );
  16732. }
  16733. return this;
  16734. }
  16735. // get the radiance in the direction of the normal
  16736. // target is a Vector3
  16737. getAt( normal, target ) {
  16738. // normal is assumed to be unit length
  16739. const x = normal.x, y = normal.y, z = normal.z;
  16740. const coeff = this.coefficients;
  16741. // band 0
  16742. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  16743. // band 1
  16744. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  16745. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  16746. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  16747. // band 2
  16748. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  16749. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  16750. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  16751. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  16752. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  16753. return target;
  16754. }
  16755. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  16756. // target is a Vector3
  16757. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16758. getIrradianceAt( normal, target ) {
  16759. // normal is assumed to be unit length
  16760. const x = normal.x, y = normal.y, z = normal.z;
  16761. const coeff = this.coefficients;
  16762. // band 0
  16763. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  16764. // band 1
  16765. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  16766. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  16767. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  16768. // band 2
  16769. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  16770. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  16771. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  16772. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  16773. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  16774. return target;
  16775. }
  16776. add( sh ) {
  16777. for ( let i = 0; i < 9; i ++ ) {
  16778. this.coefficients[ i ].add( sh.coefficients[ i ] );
  16779. }
  16780. return this;
  16781. }
  16782. addScaledSH( sh, s ) {
  16783. for ( let i = 0; i < 9; i ++ ) {
  16784. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  16785. }
  16786. return this;
  16787. }
  16788. scale( s ) {
  16789. for ( let i = 0; i < 9; i ++ ) {
  16790. this.coefficients[ i ].multiplyScalar( s );
  16791. }
  16792. return this;
  16793. }
  16794. lerp( sh, alpha ) {
  16795. for ( let i = 0; i < 9; i ++ ) {
  16796. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  16797. }
  16798. return this;
  16799. }
  16800. equals( sh ) {
  16801. for ( let i = 0; i < 9; i ++ ) {
  16802. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  16803. return false;
  16804. }
  16805. }
  16806. return true;
  16807. }
  16808. copy( sh ) {
  16809. return this.set( sh.coefficients );
  16810. }
  16811. clone() {
  16812. return new this.constructor().copy( this );
  16813. }
  16814. fromArray( array, offset = 0 ) {
  16815. const coefficients = this.coefficients;
  16816. for ( let i = 0; i < 9; i ++ ) {
  16817. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  16818. }
  16819. return this;
  16820. }
  16821. toArray( array = [], offset = 0 ) {
  16822. const coefficients = this.coefficients;
  16823. for ( let i = 0; i < 9; i ++ ) {
  16824. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  16825. }
  16826. return array;
  16827. }
  16828. // evaluate the basis functions
  16829. // shBasis is an Array[ 9 ]
  16830. static getBasisAt( normal, shBasis ) {
  16831. // normal is assumed to be unit length
  16832. const x = normal.x, y = normal.y, z = normal.z;
  16833. // band 0
  16834. shBasis[ 0 ] = 0.282095;
  16835. // band 1
  16836. shBasis[ 1 ] = 0.488603 * y;
  16837. shBasis[ 2 ] = 0.488603 * z;
  16838. shBasis[ 3 ] = 0.488603 * x;
  16839. // band 2
  16840. shBasis[ 4 ] = 1.092548 * x * y;
  16841. shBasis[ 5 ] = 1.092548 * y * z;
  16842. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  16843. shBasis[ 7 ] = 1.092548 * x * z;
  16844. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  16845. }
  16846. }
  16847. class LightProbe extends Light {
  16848. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  16849. super( undefined, intensity );
  16850. this.isLightProbe = true;
  16851. this.sh = sh;
  16852. }
  16853. copy( source ) {
  16854. super.copy( source );
  16855. this.sh.copy( source.sh );
  16856. return this;
  16857. }
  16858. fromJSON( json ) {
  16859. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  16860. this.sh.fromArray( json.sh );
  16861. return this;
  16862. }
  16863. toJSON( meta ) {
  16864. const data = super.toJSON( meta );
  16865. data.object.sh = this.sh.toArray();
  16866. return data;
  16867. }
  16868. }
  16869. class MaterialLoader extends Loader {
  16870. constructor( manager ) {
  16871. super( manager );
  16872. this.textures = {};
  16873. }
  16874. load( url, onLoad, onProgress, onError ) {
  16875. const scope = this;
  16876. const loader = new FileLoader( scope.manager );
  16877. loader.setPath( scope.path );
  16878. loader.setRequestHeader( scope.requestHeader );
  16879. loader.setWithCredentials( scope.withCredentials );
  16880. loader.load( url, function ( text ) {
  16881. try {
  16882. onLoad( scope.parse( JSON.parse( text ) ) );
  16883. } catch ( e ) {
  16884. if ( onError ) {
  16885. onError( e );
  16886. } else {
  16887. console.error( e );
  16888. }
  16889. scope.manager.itemError( url );
  16890. }
  16891. }, onProgress, onError );
  16892. }
  16893. parse( json ) {
  16894. const textures = this.textures;
  16895. function getTexture( name ) {
  16896. if ( textures[ name ] === undefined ) {
  16897. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  16898. }
  16899. return textures[ name ];
  16900. }
  16901. const material = this.createMaterialFromType( json.type );
  16902. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  16903. if ( json.name !== undefined ) material.name = json.name;
  16904. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  16905. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  16906. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  16907. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  16908. if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor );
  16909. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  16910. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  16911. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  16912. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  16913. if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor );
  16914. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  16915. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  16916. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  16917. if ( json.dispersion !== undefined ) material.dispersion = json.dispersion;
  16918. if ( json.iridescence !== undefined ) material.iridescence = json.iridescence;
  16919. if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR;
  16920. if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
  16921. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  16922. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  16923. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  16924. if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor );
  16925. if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy;
  16926. if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation;
  16927. if ( json.fog !== undefined ) material.fog = json.fog;
  16928. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  16929. if ( json.blending !== undefined ) material.blending = json.blending;
  16930. if ( json.combine !== undefined ) material.combine = json.combine;
  16931. if ( json.side !== undefined ) material.side = json.side;
  16932. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  16933. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  16934. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  16935. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  16936. if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
  16937. if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
  16938. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  16939. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  16940. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  16941. if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
  16942. if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
  16943. if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
  16944. if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
  16945. if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
  16946. if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
  16947. if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
  16948. if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
  16949. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  16950. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  16951. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  16952. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  16953. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  16954. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  16955. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  16956. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  16957. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  16958. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  16959. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  16960. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  16961. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  16962. if ( json.linewidth !== undefined ) material.linewidth = json.linewidth;
  16963. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  16964. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  16965. if ( json.scale !== undefined ) material.scale = json.scale;
  16966. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  16967. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  16968. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  16969. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  16970. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  16971. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  16972. if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
  16973. if ( json.visible !== undefined ) material.visible = json.visible;
  16974. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  16975. if ( json.userData !== undefined ) material.userData = json.userData;
  16976. if ( json.vertexColors !== undefined ) {
  16977. if ( typeof json.vertexColors === 'number' ) {
  16978. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  16979. } else {
  16980. material.vertexColors = json.vertexColors;
  16981. }
  16982. }
  16983. // Shader Material
  16984. if ( json.uniforms !== undefined ) {
  16985. for ( const name in json.uniforms ) {
  16986. const uniform = json.uniforms[ name ];
  16987. material.uniforms[ name ] = {};
  16988. switch ( uniform.type ) {
  16989. case 't':
  16990. material.uniforms[ name ].value = getTexture( uniform.value );
  16991. break;
  16992. case 'c':
  16993. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  16994. break;
  16995. case 'v2':
  16996. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  16997. break;
  16998. case 'v3':
  16999. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  17000. break;
  17001. case 'v4':
  17002. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  17003. break;
  17004. case 'm3':
  17005. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  17006. break;
  17007. case 'm4':
  17008. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  17009. break;
  17010. default:
  17011. material.uniforms[ name ].value = uniform.value;
  17012. }
  17013. }
  17014. }
  17015. if ( json.defines !== undefined ) material.defines = json.defines;
  17016. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  17017. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  17018. if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion;
  17019. if ( json.extensions !== undefined ) {
  17020. for ( const key in json.extensions ) {
  17021. material.extensions[ key ] = json.extensions[ key ];
  17022. }
  17023. }
  17024. if ( json.lights !== undefined ) material.lights = json.lights;
  17025. if ( json.clipping !== undefined ) material.clipping = json.clipping;
  17026. // for PointsMaterial
  17027. if ( json.size !== undefined ) material.size = json.size;
  17028. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  17029. // maps
  17030. if ( json.map !== undefined ) material.map = getTexture( json.map );
  17031. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  17032. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  17033. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  17034. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  17035. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  17036. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  17037. if ( json.normalScale !== undefined ) {
  17038. let normalScale = json.normalScale;
  17039. if ( Array.isArray( normalScale ) === false ) {
  17040. // Blender exporter used to export a scalar. See #7459
  17041. normalScale = [ normalScale, normalScale ];
  17042. }
  17043. material.normalScale = new Vector2().fromArray( normalScale );
  17044. }
  17045. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  17046. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  17047. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  17048. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  17049. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  17050. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  17051. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  17052. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  17053. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  17054. if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
  17055. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  17056. if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
  17057. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  17058. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  17059. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  17060. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  17061. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  17062. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  17063. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  17064. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  17065. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  17066. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  17067. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  17068. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  17069. if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap );
  17070. if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap );
  17071. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  17072. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  17073. if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap );
  17074. if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap );
  17075. if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap );
  17076. return material;
  17077. }
  17078. setTextures( value ) {
  17079. this.textures = value;
  17080. return this;
  17081. }
  17082. createMaterialFromType( type ) {
  17083. return MaterialLoader.createMaterialFromType( type );
  17084. }
  17085. static createMaterialFromType( type ) {
  17086. const materialLib = {
  17087. ShadowMaterial,
  17088. SpriteMaterial,
  17089. RawShaderMaterial,
  17090. ShaderMaterial,
  17091. PointsMaterial,
  17092. MeshPhysicalMaterial,
  17093. MeshStandardMaterial,
  17094. MeshPhongMaterial,
  17095. MeshToonMaterial,
  17096. MeshNormalMaterial,
  17097. MeshLambertMaterial,
  17098. MeshDepthMaterial,
  17099. MeshDistanceMaterial,
  17100. MeshBasicMaterial,
  17101. MeshMatcapMaterial,
  17102. LineDashedMaterial,
  17103. LineBasicMaterial,
  17104. Material
  17105. };
  17106. return new materialLib[ type ]();
  17107. }
  17108. }
  17109. class LoaderUtils {
  17110. static decodeText( array ) { // @deprecated, r165
  17111. console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
  17112. if ( typeof TextDecoder !== 'undefined' ) {
  17113. return new TextDecoder().decode( array );
  17114. }
  17115. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  17116. // throws a "maximum call stack size exceeded" error for large arrays.
  17117. let s = '';
  17118. for ( let i = 0, il = array.length; i < il; i ++ ) {
  17119. // Implicitly assumes little-endian.
  17120. s += String.fromCharCode( array[ i ] );
  17121. }
  17122. try {
  17123. // merges multi-byte utf-8 characters.
  17124. return decodeURIComponent( escape( s ) );
  17125. } catch ( e ) { // see #16358
  17126. return s;
  17127. }
  17128. }
  17129. static extractUrlBase( url ) {
  17130. const index = url.lastIndexOf( '/' );
  17131. if ( index === - 1 ) return './';
  17132. return url.slice( 0, index + 1 );
  17133. }
  17134. static resolveURL( url, path ) {
  17135. // Invalid URL
  17136. if ( typeof url !== 'string' || url === '' ) return '';
  17137. // Host Relative URL
  17138. if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
  17139. path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
  17140. }
  17141. // Absolute URL http://,https://,//
  17142. if ( /^(https?:)?\/\//i.test( url ) ) return url;
  17143. // Data URI
  17144. if ( /^data:.*,.*$/i.test( url ) ) return url;
  17145. // Blob URL
  17146. if ( /^blob:.*$/i.test( url ) ) return url;
  17147. // Relative URL
  17148. return path + url;
  17149. }
  17150. }
  17151. class InstancedBufferGeometry extends BufferGeometry {
  17152. constructor() {
  17153. super();
  17154. this.isInstancedBufferGeometry = true;
  17155. this.type = 'InstancedBufferGeometry';
  17156. this.instanceCount = Infinity;
  17157. }
  17158. copy( source ) {
  17159. super.copy( source );
  17160. this.instanceCount = source.instanceCount;
  17161. return this;
  17162. }
  17163. toJSON() {
  17164. const data = super.toJSON();
  17165. data.instanceCount = this.instanceCount;
  17166. data.isInstancedBufferGeometry = true;
  17167. return data;
  17168. }
  17169. }
  17170. class BufferGeometryLoader extends Loader {
  17171. constructor( manager ) {
  17172. super( manager );
  17173. }
  17174. load( url, onLoad, onProgress, onError ) {
  17175. const scope = this;
  17176. const loader = new FileLoader( scope.manager );
  17177. loader.setPath( scope.path );
  17178. loader.setRequestHeader( scope.requestHeader );
  17179. loader.setWithCredentials( scope.withCredentials );
  17180. loader.load( url, function ( text ) {
  17181. try {
  17182. onLoad( scope.parse( JSON.parse( text ) ) );
  17183. } catch ( e ) {
  17184. if ( onError ) {
  17185. onError( e );
  17186. } else {
  17187. console.error( e );
  17188. }
  17189. scope.manager.itemError( url );
  17190. }
  17191. }, onProgress, onError );
  17192. }
  17193. parse( json ) {
  17194. const interleavedBufferMap = {};
  17195. const arrayBufferMap = {};
  17196. function getInterleavedBuffer( json, uuid ) {
  17197. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  17198. const interleavedBuffers = json.interleavedBuffers;
  17199. const interleavedBuffer = interleavedBuffers[ uuid ];
  17200. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  17201. const array = getTypedArray( interleavedBuffer.type, buffer );
  17202. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  17203. ib.uuid = interleavedBuffer.uuid;
  17204. interleavedBufferMap[ uuid ] = ib;
  17205. return ib;
  17206. }
  17207. function getArrayBuffer( json, uuid ) {
  17208. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  17209. const arrayBuffers = json.arrayBuffers;
  17210. const arrayBuffer = arrayBuffers[ uuid ];
  17211. const ab = new Uint32Array( arrayBuffer ).buffer;
  17212. arrayBufferMap[ uuid ] = ab;
  17213. return ab;
  17214. }
  17215. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  17216. const index = json.data.index;
  17217. if ( index !== undefined ) {
  17218. const typedArray = getTypedArray( index.type, index.array );
  17219. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  17220. }
  17221. const attributes = json.data.attributes;
  17222. for ( const key in attributes ) {
  17223. const attribute = attributes[ key ];
  17224. let bufferAttribute;
  17225. if ( attribute.isInterleavedBufferAttribute ) {
  17226. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17227. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17228. } else {
  17229. const typedArray = getTypedArray( attribute.type, attribute.array );
  17230. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  17231. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  17232. }
  17233. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17234. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  17235. geometry.setAttribute( key, bufferAttribute );
  17236. }
  17237. const morphAttributes = json.data.morphAttributes;
  17238. if ( morphAttributes ) {
  17239. for ( const key in morphAttributes ) {
  17240. const attributeArray = morphAttributes[ key ];
  17241. const array = [];
  17242. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  17243. const attribute = attributeArray[ i ];
  17244. let bufferAttribute;
  17245. if ( attribute.isInterleavedBufferAttribute ) {
  17246. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17247. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17248. } else {
  17249. const typedArray = getTypedArray( attribute.type, attribute.array );
  17250. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  17251. }
  17252. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17253. array.push( bufferAttribute );
  17254. }
  17255. geometry.morphAttributes[ key ] = array;
  17256. }
  17257. }
  17258. const morphTargetsRelative = json.data.morphTargetsRelative;
  17259. if ( morphTargetsRelative ) {
  17260. geometry.morphTargetsRelative = true;
  17261. }
  17262. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  17263. if ( groups !== undefined ) {
  17264. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  17265. const group = groups[ i ];
  17266. geometry.addGroup( group.start, group.count, group.materialIndex );
  17267. }
  17268. }
  17269. const boundingSphere = json.data.boundingSphere;
  17270. if ( boundingSphere !== undefined ) {
  17271. const center = new Vector3();
  17272. if ( boundingSphere.center !== undefined ) {
  17273. center.fromArray( boundingSphere.center );
  17274. }
  17275. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  17276. }
  17277. if ( json.name ) geometry.name = json.name;
  17278. if ( json.userData ) geometry.userData = json.userData;
  17279. return geometry;
  17280. }
  17281. }
  17282. class ObjectLoader extends Loader {
  17283. constructor( manager ) {
  17284. super( manager );
  17285. }
  17286. load( url, onLoad, onProgress, onError ) {
  17287. const scope = this;
  17288. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17289. this.resourcePath = this.resourcePath || path;
  17290. const loader = new FileLoader( this.manager );
  17291. loader.setPath( this.path );
  17292. loader.setRequestHeader( this.requestHeader );
  17293. loader.setWithCredentials( this.withCredentials );
  17294. loader.load( url, function ( text ) {
  17295. let json = null;
  17296. try {
  17297. json = JSON.parse( text );
  17298. } catch ( error ) {
  17299. if ( onError !== undefined ) onError( error );
  17300. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  17301. return;
  17302. }
  17303. const metadata = json.metadata;
  17304. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17305. if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) );
  17306. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17307. return;
  17308. }
  17309. scope.parse( json, onLoad );
  17310. }, onProgress, onError );
  17311. }
  17312. async loadAsync( url, onProgress ) {
  17313. const scope = this;
  17314. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17315. this.resourcePath = this.resourcePath || path;
  17316. const loader = new FileLoader( this.manager );
  17317. loader.setPath( this.path );
  17318. loader.setRequestHeader( this.requestHeader );
  17319. loader.setWithCredentials( this.withCredentials );
  17320. const text = await loader.loadAsync( url, onProgress );
  17321. const json = JSON.parse( text );
  17322. const metadata = json.metadata;
  17323. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17324. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17325. }
  17326. return await scope.parseAsync( json );
  17327. }
  17328. parse( json, onLoad ) {
  17329. const animations = this.parseAnimations( json.animations );
  17330. const shapes = this.parseShapes( json.shapes );
  17331. const geometries = this.parseGeometries( json.geometries, shapes );
  17332. const images = this.parseImages( json.images, function () {
  17333. if ( onLoad !== undefined ) onLoad( object );
  17334. } );
  17335. const textures = this.parseTextures( json.textures, images );
  17336. const materials = this.parseMaterials( json.materials, textures );
  17337. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17338. const skeletons = this.parseSkeletons( json.skeletons, object );
  17339. this.bindSkeletons( object, skeletons );
  17340. this.bindLightTargets( object );
  17341. //
  17342. if ( onLoad !== undefined ) {
  17343. let hasImages = false;
  17344. for ( const uuid in images ) {
  17345. if ( images[ uuid ].data instanceof HTMLImageElement ) {
  17346. hasImages = true;
  17347. break;
  17348. }
  17349. }
  17350. if ( hasImages === false ) onLoad( object );
  17351. }
  17352. return object;
  17353. }
  17354. async parseAsync( json ) {
  17355. const animations = this.parseAnimations( json.animations );
  17356. const shapes = this.parseShapes( json.shapes );
  17357. const geometries = this.parseGeometries( json.geometries, shapes );
  17358. const images = await this.parseImagesAsync( json.images );
  17359. const textures = this.parseTextures( json.textures, images );
  17360. const materials = this.parseMaterials( json.materials, textures );
  17361. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17362. const skeletons = this.parseSkeletons( json.skeletons, object );
  17363. this.bindSkeletons( object, skeletons );
  17364. this.bindLightTargets( object );
  17365. return object;
  17366. }
  17367. parseShapes( json ) {
  17368. const shapes = {};
  17369. if ( json !== undefined ) {
  17370. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17371. const shape = new Shape().fromJSON( json[ i ] );
  17372. shapes[ shape.uuid ] = shape;
  17373. }
  17374. }
  17375. return shapes;
  17376. }
  17377. parseSkeletons( json, object ) {
  17378. const skeletons = {};
  17379. const bones = {};
  17380. // generate bone lookup table
  17381. object.traverse( function ( child ) {
  17382. if ( child.isBone ) bones[ child.uuid ] = child;
  17383. } );
  17384. // create skeletons
  17385. if ( json !== undefined ) {
  17386. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17387. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  17388. skeletons[ skeleton.uuid ] = skeleton;
  17389. }
  17390. }
  17391. return skeletons;
  17392. }
  17393. parseGeometries( json, shapes ) {
  17394. const geometries = {};
  17395. if ( json !== undefined ) {
  17396. const bufferGeometryLoader = new BufferGeometryLoader();
  17397. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17398. let geometry;
  17399. const data = json[ i ];
  17400. switch ( data.type ) {
  17401. case 'BufferGeometry':
  17402. case 'InstancedBufferGeometry':
  17403. geometry = bufferGeometryLoader.parse( data );
  17404. break;
  17405. default:
  17406. if ( data.type in Geometries ) {
  17407. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  17408. } else {
  17409. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  17410. }
  17411. }
  17412. geometry.uuid = data.uuid;
  17413. if ( data.name !== undefined ) geometry.name = data.name;
  17414. if ( data.userData !== undefined ) geometry.userData = data.userData;
  17415. geometries[ data.uuid ] = geometry;
  17416. }
  17417. }
  17418. return geometries;
  17419. }
  17420. parseMaterials( json, textures ) {
  17421. const cache = {}; // MultiMaterial
  17422. const materials = {};
  17423. if ( json !== undefined ) {
  17424. const loader = new MaterialLoader();
  17425. loader.setTextures( textures );
  17426. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17427. const data = json[ i ];
  17428. if ( cache[ data.uuid ] === undefined ) {
  17429. cache[ data.uuid ] = loader.parse( data );
  17430. }
  17431. materials[ data.uuid ] = cache[ data.uuid ];
  17432. }
  17433. }
  17434. return materials;
  17435. }
  17436. parseAnimations( json ) {
  17437. const animations = {};
  17438. if ( json !== undefined ) {
  17439. for ( let i = 0; i < json.length; i ++ ) {
  17440. const data = json[ i ];
  17441. const clip = AnimationClip.parse( data );
  17442. animations[ clip.uuid ] = clip;
  17443. }
  17444. }
  17445. return animations;
  17446. }
  17447. parseImages( json, onLoad ) {
  17448. const scope = this;
  17449. const images = {};
  17450. let loader;
  17451. function loadImage( url ) {
  17452. scope.manager.itemStart( url );
  17453. return loader.load( url, function () {
  17454. scope.manager.itemEnd( url );
  17455. }, undefined, function () {
  17456. scope.manager.itemError( url );
  17457. scope.manager.itemEnd( url );
  17458. } );
  17459. }
  17460. function deserializeImage( image ) {
  17461. if ( typeof image === 'string' ) {
  17462. const url = image;
  17463. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17464. return loadImage( path );
  17465. } else {
  17466. if ( image.data ) {
  17467. return {
  17468. data: getTypedArray( image.type, image.data ),
  17469. width: image.width,
  17470. height: image.height
  17471. };
  17472. } else {
  17473. return null;
  17474. }
  17475. }
  17476. }
  17477. if ( json !== undefined && json.length > 0 ) {
  17478. const manager = new LoadingManager( onLoad );
  17479. loader = new ImageLoader( manager );
  17480. loader.setCrossOrigin( this.crossOrigin );
  17481. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17482. const image = json[ i ];
  17483. const url = image.url;
  17484. if ( Array.isArray( url ) ) {
  17485. // load array of images e.g CubeTexture
  17486. const imageArray = [];
  17487. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17488. const currentUrl = url[ j ];
  17489. const deserializedImage = deserializeImage( currentUrl );
  17490. if ( deserializedImage !== null ) {
  17491. if ( deserializedImage instanceof HTMLImageElement ) {
  17492. imageArray.push( deserializedImage );
  17493. } else {
  17494. // special case: handle array of data textures for cube textures
  17495. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17496. }
  17497. }
  17498. }
  17499. images[ image.uuid ] = new Source( imageArray );
  17500. } else {
  17501. // load single image
  17502. const deserializedImage = deserializeImage( image.url );
  17503. images[ image.uuid ] = new Source( deserializedImage );
  17504. }
  17505. }
  17506. }
  17507. return images;
  17508. }
  17509. async parseImagesAsync( json ) {
  17510. const scope = this;
  17511. const images = {};
  17512. let loader;
  17513. async function deserializeImage( image ) {
  17514. if ( typeof image === 'string' ) {
  17515. const url = image;
  17516. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17517. return await loader.loadAsync( path );
  17518. } else {
  17519. if ( image.data ) {
  17520. return {
  17521. data: getTypedArray( image.type, image.data ),
  17522. width: image.width,
  17523. height: image.height
  17524. };
  17525. } else {
  17526. return null;
  17527. }
  17528. }
  17529. }
  17530. if ( json !== undefined && json.length > 0 ) {
  17531. loader = new ImageLoader( this.manager );
  17532. loader.setCrossOrigin( this.crossOrigin );
  17533. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17534. const image = json[ i ];
  17535. const url = image.url;
  17536. if ( Array.isArray( url ) ) {
  17537. // load array of images e.g CubeTexture
  17538. const imageArray = [];
  17539. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17540. const currentUrl = url[ j ];
  17541. const deserializedImage = await deserializeImage( currentUrl );
  17542. if ( deserializedImage !== null ) {
  17543. if ( deserializedImage instanceof HTMLImageElement ) {
  17544. imageArray.push( deserializedImage );
  17545. } else {
  17546. // special case: handle array of data textures for cube textures
  17547. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17548. }
  17549. }
  17550. }
  17551. images[ image.uuid ] = new Source( imageArray );
  17552. } else {
  17553. // load single image
  17554. const deserializedImage = await deserializeImage( image.url );
  17555. images[ image.uuid ] = new Source( deserializedImage );
  17556. }
  17557. }
  17558. }
  17559. return images;
  17560. }
  17561. parseTextures( json, images ) {
  17562. function parseConstant( value, type ) {
  17563. if ( typeof value === 'number' ) return value;
  17564. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  17565. return type[ value ];
  17566. }
  17567. const textures = {};
  17568. if ( json !== undefined ) {
  17569. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17570. const data = json[ i ];
  17571. if ( data.image === undefined ) {
  17572. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  17573. }
  17574. if ( images[ data.image ] === undefined ) {
  17575. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  17576. }
  17577. const source = images[ data.image ];
  17578. const image = source.data;
  17579. let texture;
  17580. if ( Array.isArray( image ) ) {
  17581. texture = new CubeTexture();
  17582. if ( image.length === 6 ) texture.needsUpdate = true;
  17583. } else {
  17584. if ( image && image.data ) {
  17585. texture = new DataTexture();
  17586. } else {
  17587. texture = new Texture();
  17588. }
  17589. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  17590. }
  17591. texture.source = source;
  17592. texture.uuid = data.uuid;
  17593. if ( data.name !== undefined ) texture.name = data.name;
  17594. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  17595. if ( data.channel !== undefined ) texture.channel = data.channel;
  17596. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  17597. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  17598. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  17599. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  17600. if ( data.wrap !== undefined ) {
  17601. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  17602. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  17603. }
  17604. if ( data.format !== undefined ) texture.format = data.format;
  17605. if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
  17606. if ( data.type !== undefined ) texture.type = data.type;
  17607. if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
  17608. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  17609. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  17610. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  17611. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  17612. if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps;
  17613. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  17614. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  17615. if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
  17616. if ( data.userData !== undefined ) texture.userData = data.userData;
  17617. textures[ data.uuid ] = texture;
  17618. }
  17619. }
  17620. return textures;
  17621. }
  17622. parseObject( data, geometries, materials, textures, animations ) {
  17623. let object;
  17624. function getGeometry( name ) {
  17625. if ( geometries[ name ] === undefined ) {
  17626. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  17627. }
  17628. return geometries[ name ];
  17629. }
  17630. function getMaterial( name ) {
  17631. if ( name === undefined ) return undefined;
  17632. if ( Array.isArray( name ) ) {
  17633. const array = [];
  17634. for ( let i = 0, l = name.length; i < l; i ++ ) {
  17635. const uuid = name[ i ];
  17636. if ( materials[ uuid ] === undefined ) {
  17637. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  17638. }
  17639. array.push( materials[ uuid ] );
  17640. }
  17641. return array;
  17642. }
  17643. if ( materials[ name ] === undefined ) {
  17644. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  17645. }
  17646. return materials[ name ];
  17647. }
  17648. function getTexture( uuid ) {
  17649. if ( textures[ uuid ] === undefined ) {
  17650. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  17651. }
  17652. return textures[ uuid ];
  17653. }
  17654. let geometry, material;
  17655. switch ( data.type ) {
  17656. case 'Scene':
  17657. object = new Scene();
  17658. if ( data.background !== undefined ) {
  17659. if ( Number.isInteger( data.background ) ) {
  17660. object.background = new Color( data.background );
  17661. } else {
  17662. object.background = getTexture( data.background );
  17663. }
  17664. }
  17665. if ( data.environment !== undefined ) {
  17666. object.environment = getTexture( data.environment );
  17667. }
  17668. if ( data.fog !== undefined ) {
  17669. if ( data.fog.type === 'Fog' ) {
  17670. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  17671. } else if ( data.fog.type === 'FogExp2' ) {
  17672. object.fog = new FogExp2( data.fog.color, data.fog.density );
  17673. }
  17674. if ( data.fog.name !== '' ) {
  17675. object.fog.name = data.fog.name;
  17676. }
  17677. }
  17678. if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
  17679. if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
  17680. if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
  17681. if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
  17682. if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
  17683. break;
  17684. case 'PerspectiveCamera':
  17685. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  17686. if ( data.focus !== undefined ) object.focus = data.focus;
  17687. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17688. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  17689. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  17690. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17691. break;
  17692. case 'OrthographicCamera':
  17693. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  17694. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17695. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17696. break;
  17697. case 'AmbientLight':
  17698. object = new AmbientLight( data.color, data.intensity );
  17699. break;
  17700. case 'DirectionalLight':
  17701. object = new DirectionalLight( data.color, data.intensity );
  17702. object.target = data.target || '';
  17703. break;
  17704. case 'PointLight':
  17705. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  17706. break;
  17707. case 'RectAreaLight':
  17708. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  17709. break;
  17710. case 'SpotLight':
  17711. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  17712. object.target = data.target || '';
  17713. break;
  17714. case 'HemisphereLight':
  17715. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  17716. break;
  17717. case 'LightProbe':
  17718. object = new LightProbe().fromJSON( data );
  17719. break;
  17720. case 'SkinnedMesh':
  17721. geometry = getGeometry( data.geometry );
  17722. material = getMaterial( data.material );
  17723. object = new SkinnedMesh( geometry, material );
  17724. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  17725. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  17726. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  17727. break;
  17728. case 'Mesh':
  17729. geometry = getGeometry( data.geometry );
  17730. material = getMaterial( data.material );
  17731. object = new Mesh( geometry, material );
  17732. break;
  17733. case 'InstancedMesh':
  17734. geometry = getGeometry( data.geometry );
  17735. material = getMaterial( data.material );
  17736. const count = data.count;
  17737. const instanceMatrix = data.instanceMatrix;
  17738. const instanceColor = data.instanceColor;
  17739. object = new InstancedMesh( geometry, material, count );
  17740. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  17741. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  17742. break;
  17743. case 'BatchedMesh':
  17744. geometry = getGeometry( data.geometry );
  17745. material = getMaterial( data.material );
  17746. object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material );
  17747. object.geometry = geometry;
  17748. object.perObjectFrustumCulled = data.perObjectFrustumCulled;
  17749. object.sortObjects = data.sortObjects;
  17750. object._drawRanges = data.drawRanges;
  17751. object._reservedRanges = data.reservedRanges;
  17752. object._visibility = data.visibility;
  17753. object._active = data.active;
  17754. object._bounds = data.bounds.map( bound => {
  17755. const box = new Box3();
  17756. box.min.fromArray( bound.boxMin );
  17757. box.max.fromArray( bound.boxMax );
  17758. const sphere = new Sphere();
  17759. sphere.radius = bound.sphereRadius;
  17760. sphere.center.fromArray( bound.sphereCenter );
  17761. return {
  17762. boxInitialized: bound.boxInitialized,
  17763. box: box,
  17764. sphereInitialized: bound.sphereInitialized,
  17765. sphere: sphere
  17766. };
  17767. } );
  17768. object._maxInstanceCount = data.maxInstanceCount;
  17769. object._maxVertexCount = data.maxVertexCount;
  17770. object._maxIndexCount = data.maxIndexCount;
  17771. object._geometryInitialized = data.geometryInitialized;
  17772. object._geometryCount = data.geometryCount;
  17773. object._matricesTexture = getTexture( data.matricesTexture.uuid );
  17774. if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
  17775. break;
  17776. case 'LOD':
  17777. object = new LOD();
  17778. break;
  17779. case 'Line':
  17780. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  17781. break;
  17782. case 'LineLoop':
  17783. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  17784. break;
  17785. case 'LineSegments':
  17786. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  17787. break;
  17788. case 'PointCloud':
  17789. case 'Points':
  17790. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  17791. break;
  17792. case 'Sprite':
  17793. object = new Sprite( getMaterial( data.material ) );
  17794. break;
  17795. case 'Group':
  17796. object = new Group();
  17797. break;
  17798. case 'Bone':
  17799. object = new Bone();
  17800. break;
  17801. default:
  17802. object = new Object3D();
  17803. }
  17804. object.uuid = data.uuid;
  17805. if ( data.name !== undefined ) object.name = data.name;
  17806. if ( data.matrix !== undefined ) {
  17807. object.matrix.fromArray( data.matrix );
  17808. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  17809. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  17810. } else {
  17811. if ( data.position !== undefined ) object.position.fromArray( data.position );
  17812. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  17813. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  17814. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  17815. }
  17816. if ( data.up !== undefined ) object.up.fromArray( data.up );
  17817. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  17818. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  17819. if ( data.shadow ) {
  17820. if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
  17821. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  17822. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  17823. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  17824. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  17825. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  17826. }
  17827. if ( data.visible !== undefined ) object.visible = data.visible;
  17828. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  17829. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  17830. if ( data.userData !== undefined ) object.userData = data.userData;
  17831. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  17832. if ( data.children !== undefined ) {
  17833. const children = data.children;
  17834. for ( let i = 0; i < children.length; i ++ ) {
  17835. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  17836. }
  17837. }
  17838. if ( data.animations !== undefined ) {
  17839. const objectAnimations = data.animations;
  17840. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  17841. const uuid = objectAnimations[ i ];
  17842. object.animations.push( animations[ uuid ] );
  17843. }
  17844. }
  17845. if ( data.type === 'LOD' ) {
  17846. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  17847. const levels = data.levels;
  17848. for ( let l = 0; l < levels.length; l ++ ) {
  17849. const level = levels[ l ];
  17850. const child = object.getObjectByProperty( 'uuid', level.object );
  17851. if ( child !== undefined ) {
  17852. object.addLevel( child, level.distance, level.hysteresis );
  17853. }
  17854. }
  17855. }
  17856. return object;
  17857. }
  17858. bindSkeletons( object, skeletons ) {
  17859. if ( Object.keys( skeletons ).length === 0 ) return;
  17860. object.traverse( function ( child ) {
  17861. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  17862. const skeleton = skeletons[ child.skeleton ];
  17863. if ( skeleton === undefined ) {
  17864. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  17865. } else {
  17866. child.bind( skeleton, child.bindMatrix );
  17867. }
  17868. }
  17869. } );
  17870. }
  17871. bindLightTargets( object ) {
  17872. object.traverse( function ( child ) {
  17873. if ( child.isDirectionalLight || child.isSpotLight ) {
  17874. const uuid = child.target;
  17875. const target = object.getObjectByProperty( 'uuid', uuid );
  17876. if ( target !== undefined ) {
  17877. child.target = target;
  17878. } else {
  17879. child.target = new Object3D();
  17880. }
  17881. }
  17882. } );
  17883. }
  17884. }
  17885. const TEXTURE_MAPPING = {
  17886. UVMapping: UVMapping,
  17887. CubeReflectionMapping: CubeReflectionMapping,
  17888. CubeRefractionMapping: CubeRefractionMapping,
  17889. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  17890. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  17891. CubeUVReflectionMapping: CubeUVReflectionMapping
  17892. };
  17893. const TEXTURE_WRAPPING = {
  17894. RepeatWrapping: RepeatWrapping,
  17895. ClampToEdgeWrapping: ClampToEdgeWrapping,
  17896. MirroredRepeatWrapping: MirroredRepeatWrapping
  17897. };
  17898. const TEXTURE_FILTER = {
  17899. NearestFilter: NearestFilter,
  17900. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  17901. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  17902. LinearFilter: LinearFilter,
  17903. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  17904. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  17905. };
  17906. class ImageBitmapLoader extends Loader {
  17907. constructor( manager ) {
  17908. super( manager );
  17909. this.isImageBitmapLoader = true;
  17910. if ( typeof createImageBitmap === 'undefined' ) {
  17911. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  17912. }
  17913. if ( typeof fetch === 'undefined' ) {
  17914. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  17915. }
  17916. this.options = { premultiplyAlpha: 'none' };
  17917. }
  17918. setOptions( options ) {
  17919. this.options = options;
  17920. return this;
  17921. }
  17922. load( url, onLoad, onProgress, onError ) {
  17923. if ( url === undefined ) url = '';
  17924. if ( this.path !== undefined ) url = this.path + url;
  17925. url = this.manager.resolveURL( url );
  17926. const scope = this;
  17927. const cached = Cache.get( url );
  17928. if ( cached !== undefined ) {
  17929. scope.manager.itemStart( url );
  17930. // If cached is a promise, wait for it to resolve
  17931. if ( cached.then ) {
  17932. cached.then( imageBitmap => {
  17933. if ( onLoad ) onLoad( imageBitmap );
  17934. scope.manager.itemEnd( url );
  17935. } ).catch( e => {
  17936. if ( onError ) onError( e );
  17937. } );
  17938. return;
  17939. }
  17940. // If cached is not a promise (i.e., it's already an imageBitmap)
  17941. setTimeout( function () {
  17942. if ( onLoad ) onLoad( cached );
  17943. scope.manager.itemEnd( url );
  17944. }, 0 );
  17945. return cached;
  17946. }
  17947. const fetchOptions = {};
  17948. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  17949. fetchOptions.headers = this.requestHeader;
  17950. const promise = fetch( url, fetchOptions ).then( function ( res ) {
  17951. return res.blob();
  17952. } ).then( function ( blob ) {
  17953. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  17954. } ).then( function ( imageBitmap ) {
  17955. Cache.add( url, imageBitmap );
  17956. if ( onLoad ) onLoad( imageBitmap );
  17957. scope.manager.itemEnd( url );
  17958. return imageBitmap;
  17959. } ).catch( function ( e ) {
  17960. if ( onError ) onError( e );
  17961. Cache.remove( url );
  17962. scope.manager.itemError( url );
  17963. scope.manager.itemEnd( url );
  17964. } );
  17965. Cache.add( url, promise );
  17966. scope.manager.itemStart( url );
  17967. }
  17968. }
  17969. let _context;
  17970. class AudioContext {
  17971. static getContext() {
  17972. if ( _context === undefined ) {
  17973. _context = new ( window.AudioContext || window.webkitAudioContext )();
  17974. }
  17975. return _context;
  17976. }
  17977. static setContext( value ) {
  17978. _context = value;
  17979. }
  17980. }
  17981. class AudioLoader extends Loader {
  17982. constructor( manager ) {
  17983. super( manager );
  17984. }
  17985. load( url, onLoad, onProgress, onError ) {
  17986. const scope = this;
  17987. const loader = new FileLoader( this.manager );
  17988. loader.setResponseType( 'arraybuffer' );
  17989. loader.setPath( this.path );
  17990. loader.setRequestHeader( this.requestHeader );
  17991. loader.setWithCredentials( this.withCredentials );
  17992. loader.load( url, function ( buffer ) {
  17993. try {
  17994. // Create a copy of the buffer. The `decodeAudioData` method
  17995. // detaches the buffer when complete, preventing reuse.
  17996. const bufferCopy = buffer.slice( 0 );
  17997. const context = AudioContext.getContext();
  17998. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  17999. onLoad( audioBuffer );
  18000. } ).catch( handleError );
  18001. } catch ( e ) {
  18002. handleError( e );
  18003. }
  18004. }, onProgress, onError );
  18005. function handleError( e ) {
  18006. if ( onError ) {
  18007. onError( e );
  18008. } else {
  18009. console.error( e );
  18010. }
  18011. scope.manager.itemError( url );
  18012. }
  18013. }
  18014. }
  18015. const _eyeRight = /*@__PURE__*/ new Matrix4();
  18016. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  18017. const _projectionMatrix = /*@__PURE__*/ new Matrix4();
  18018. class StereoCamera {
  18019. constructor() {
  18020. this.type = 'StereoCamera';
  18021. this.aspect = 1;
  18022. this.eyeSep = 0.064;
  18023. this.cameraL = new PerspectiveCamera();
  18024. this.cameraL.layers.enable( 1 );
  18025. this.cameraL.matrixAutoUpdate = false;
  18026. this.cameraR = new PerspectiveCamera();
  18027. this.cameraR.layers.enable( 2 );
  18028. this.cameraR.matrixAutoUpdate = false;
  18029. this._cache = {
  18030. focus: null,
  18031. fov: null,
  18032. aspect: null,
  18033. near: null,
  18034. far: null,
  18035. zoom: null,
  18036. eyeSep: null
  18037. };
  18038. }
  18039. update( camera ) {
  18040. const cache = this._cache;
  18041. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  18042. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  18043. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  18044. if ( needsUpdate ) {
  18045. cache.focus = camera.focus;
  18046. cache.fov = camera.fov;
  18047. cache.aspect = camera.aspect * this.aspect;
  18048. cache.near = camera.near;
  18049. cache.far = camera.far;
  18050. cache.zoom = camera.zoom;
  18051. cache.eyeSep = this.eyeSep;
  18052. // Off-axis stereoscopic effect based on
  18053. // http://paulbourke.net/stereographics/stereorender/
  18054. _projectionMatrix.copy( camera.projectionMatrix );
  18055. const eyeSepHalf = cache.eyeSep / 2;
  18056. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  18057. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  18058. let xmin, xmax;
  18059. // translate xOffset
  18060. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  18061. _eyeRight.elements[ 12 ] = eyeSepHalf;
  18062. // for left eye
  18063. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  18064. xmax = ymax * cache.aspect + eyeSepOnProjection;
  18065. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18066. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18067. this.cameraL.projectionMatrix.copy( _projectionMatrix );
  18068. // for right eye
  18069. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  18070. xmax = ymax * cache.aspect - eyeSepOnProjection;
  18071. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18072. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18073. this.cameraR.projectionMatrix.copy( _projectionMatrix );
  18074. }
  18075. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  18076. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  18077. }
  18078. }
  18079. class ArrayCamera extends PerspectiveCamera {
  18080. constructor( array = [] ) {
  18081. super();
  18082. this.isArrayCamera = true;
  18083. this.cameras = array;
  18084. }
  18085. }
  18086. class Clock {
  18087. constructor( autoStart = true ) {
  18088. this.autoStart = autoStart;
  18089. this.startTime = 0;
  18090. this.oldTime = 0;
  18091. this.elapsedTime = 0;
  18092. this.running = false;
  18093. }
  18094. start() {
  18095. this.startTime = now();
  18096. this.oldTime = this.startTime;
  18097. this.elapsedTime = 0;
  18098. this.running = true;
  18099. }
  18100. stop() {
  18101. this.getElapsedTime();
  18102. this.running = false;
  18103. this.autoStart = false;
  18104. }
  18105. getElapsedTime() {
  18106. this.getDelta();
  18107. return this.elapsedTime;
  18108. }
  18109. getDelta() {
  18110. let diff = 0;
  18111. if ( this.autoStart && ! this.running ) {
  18112. this.start();
  18113. return 0;
  18114. }
  18115. if ( this.running ) {
  18116. const newTime = now();
  18117. diff = ( newTime - this.oldTime ) / 1000;
  18118. this.oldTime = newTime;
  18119. this.elapsedTime += diff;
  18120. }
  18121. return diff;
  18122. }
  18123. }
  18124. function now() {
  18125. return performance.now();
  18126. }
  18127. const _position$1 = /*@__PURE__*/ new Vector3();
  18128. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  18129. const _scale$1 = /*@__PURE__*/ new Vector3();
  18130. const _orientation$1 = /*@__PURE__*/ new Vector3();
  18131. class AudioListener extends Object3D {
  18132. constructor() {
  18133. super();
  18134. this.type = 'AudioListener';
  18135. this.context = AudioContext.getContext();
  18136. this.gain = this.context.createGain();
  18137. this.gain.connect( this.context.destination );
  18138. this.filter = null;
  18139. this.timeDelta = 0;
  18140. // private
  18141. this._clock = new Clock();
  18142. }
  18143. getInput() {
  18144. return this.gain;
  18145. }
  18146. removeFilter() {
  18147. if ( this.filter !== null ) {
  18148. this.gain.disconnect( this.filter );
  18149. this.filter.disconnect( this.context.destination );
  18150. this.gain.connect( this.context.destination );
  18151. this.filter = null;
  18152. }
  18153. return this;
  18154. }
  18155. getFilter() {
  18156. return this.filter;
  18157. }
  18158. setFilter( value ) {
  18159. if ( this.filter !== null ) {
  18160. this.gain.disconnect( this.filter );
  18161. this.filter.disconnect( this.context.destination );
  18162. } else {
  18163. this.gain.disconnect( this.context.destination );
  18164. }
  18165. this.filter = value;
  18166. this.gain.connect( this.filter );
  18167. this.filter.connect( this.context.destination );
  18168. return this;
  18169. }
  18170. getMasterVolume() {
  18171. return this.gain.gain.value;
  18172. }
  18173. setMasterVolume( value ) {
  18174. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18175. return this;
  18176. }
  18177. updateMatrixWorld( force ) {
  18178. super.updateMatrixWorld( force );
  18179. const listener = this.context.listener;
  18180. const up = this.up;
  18181. this.timeDelta = this._clock.getDelta();
  18182. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  18183. _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 );
  18184. if ( listener.positionX ) {
  18185. // code path for Chrome (see #14393)
  18186. const endTime = this.context.currentTime + this.timeDelta;
  18187. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  18188. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  18189. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  18190. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  18191. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  18192. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  18193. listener.upX.linearRampToValueAtTime( up.x, endTime );
  18194. listener.upY.linearRampToValueAtTime( up.y, endTime );
  18195. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  18196. } else {
  18197. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  18198. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  18199. }
  18200. }
  18201. }
  18202. class Audio extends Object3D {
  18203. constructor( listener ) {
  18204. super();
  18205. this.type = 'Audio';
  18206. this.listener = listener;
  18207. this.context = listener.context;
  18208. this.gain = this.context.createGain();
  18209. this.gain.connect( listener.getInput() );
  18210. this.autoplay = false;
  18211. this.buffer = null;
  18212. this.detune = 0;
  18213. this.loop = false;
  18214. this.loopStart = 0;
  18215. this.loopEnd = 0;
  18216. this.offset = 0;
  18217. this.duration = undefined;
  18218. this.playbackRate = 1;
  18219. this.isPlaying = false;
  18220. this.hasPlaybackControl = true;
  18221. this.source = null;
  18222. this.sourceType = 'empty';
  18223. this._startedAt = 0;
  18224. this._progress = 0;
  18225. this._connected = false;
  18226. this.filters = [];
  18227. }
  18228. getOutput() {
  18229. return this.gain;
  18230. }
  18231. setNodeSource( audioNode ) {
  18232. this.hasPlaybackControl = false;
  18233. this.sourceType = 'audioNode';
  18234. this.source = audioNode;
  18235. this.connect();
  18236. return this;
  18237. }
  18238. setMediaElementSource( mediaElement ) {
  18239. this.hasPlaybackControl = false;
  18240. this.sourceType = 'mediaNode';
  18241. this.source = this.context.createMediaElementSource( mediaElement );
  18242. this.connect();
  18243. return this;
  18244. }
  18245. setMediaStreamSource( mediaStream ) {
  18246. this.hasPlaybackControl = false;
  18247. this.sourceType = 'mediaStreamNode';
  18248. this.source = this.context.createMediaStreamSource( mediaStream );
  18249. this.connect();
  18250. return this;
  18251. }
  18252. setBuffer( audioBuffer ) {
  18253. this.buffer = audioBuffer;
  18254. this.sourceType = 'buffer';
  18255. if ( this.autoplay ) this.play();
  18256. return this;
  18257. }
  18258. play( delay = 0 ) {
  18259. if ( this.isPlaying === true ) {
  18260. console.warn( 'THREE.Audio: Audio is already playing.' );
  18261. return;
  18262. }
  18263. if ( this.hasPlaybackControl === false ) {
  18264. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18265. return;
  18266. }
  18267. this._startedAt = this.context.currentTime + delay;
  18268. const source = this.context.createBufferSource();
  18269. source.buffer = this.buffer;
  18270. source.loop = this.loop;
  18271. source.loopStart = this.loopStart;
  18272. source.loopEnd = this.loopEnd;
  18273. source.onended = this.onEnded.bind( this );
  18274. source.start( this._startedAt, this._progress + this.offset, this.duration );
  18275. this.isPlaying = true;
  18276. this.source = source;
  18277. this.setDetune( this.detune );
  18278. this.setPlaybackRate( this.playbackRate );
  18279. return this.connect();
  18280. }
  18281. pause() {
  18282. if ( this.hasPlaybackControl === false ) {
  18283. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18284. return;
  18285. }
  18286. if ( this.isPlaying === true ) {
  18287. // update current progress
  18288. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  18289. if ( this.loop === true ) {
  18290. // ensure _progress does not exceed duration with looped audios
  18291. this._progress = this._progress % ( this.duration || this.buffer.duration );
  18292. }
  18293. this.source.stop();
  18294. this.source.onended = null;
  18295. this.isPlaying = false;
  18296. }
  18297. return this;
  18298. }
  18299. stop( delay = 0 ) {
  18300. if ( this.hasPlaybackControl === false ) {
  18301. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18302. return;
  18303. }
  18304. this._progress = 0;
  18305. if ( this.source !== null ) {
  18306. this.source.stop( this.context.currentTime + delay );
  18307. this.source.onended = null;
  18308. }
  18309. this.isPlaying = false;
  18310. return this;
  18311. }
  18312. connect() {
  18313. if ( this.filters.length > 0 ) {
  18314. this.source.connect( this.filters[ 0 ] );
  18315. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18316. this.filters[ i - 1 ].connect( this.filters[ i ] );
  18317. }
  18318. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  18319. } else {
  18320. this.source.connect( this.getOutput() );
  18321. }
  18322. this._connected = true;
  18323. return this;
  18324. }
  18325. disconnect() {
  18326. if ( this._connected === false ) {
  18327. return;
  18328. }
  18329. if ( this.filters.length > 0 ) {
  18330. this.source.disconnect( this.filters[ 0 ] );
  18331. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18332. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  18333. }
  18334. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  18335. } else {
  18336. this.source.disconnect( this.getOutput() );
  18337. }
  18338. this._connected = false;
  18339. return this;
  18340. }
  18341. getFilters() {
  18342. return this.filters;
  18343. }
  18344. setFilters( value ) {
  18345. if ( ! value ) value = [];
  18346. if ( this._connected === true ) {
  18347. this.disconnect();
  18348. this.filters = value.slice();
  18349. this.connect();
  18350. } else {
  18351. this.filters = value.slice();
  18352. }
  18353. return this;
  18354. }
  18355. setDetune( value ) {
  18356. this.detune = value;
  18357. if ( this.isPlaying === true && this.source.detune !== undefined ) {
  18358. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  18359. }
  18360. return this;
  18361. }
  18362. getDetune() {
  18363. return this.detune;
  18364. }
  18365. getFilter() {
  18366. return this.getFilters()[ 0 ];
  18367. }
  18368. setFilter( filter ) {
  18369. return this.setFilters( filter ? [ filter ] : [] );
  18370. }
  18371. setPlaybackRate( value ) {
  18372. if ( this.hasPlaybackControl === false ) {
  18373. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18374. return;
  18375. }
  18376. this.playbackRate = value;
  18377. if ( this.isPlaying === true ) {
  18378. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  18379. }
  18380. return this;
  18381. }
  18382. getPlaybackRate() {
  18383. return this.playbackRate;
  18384. }
  18385. onEnded() {
  18386. this.isPlaying = false;
  18387. this._progress = 0;
  18388. }
  18389. getLoop() {
  18390. if ( this.hasPlaybackControl === false ) {
  18391. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18392. return false;
  18393. }
  18394. return this.loop;
  18395. }
  18396. setLoop( value ) {
  18397. if ( this.hasPlaybackControl === false ) {
  18398. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18399. return;
  18400. }
  18401. this.loop = value;
  18402. if ( this.isPlaying === true ) {
  18403. this.source.loop = this.loop;
  18404. }
  18405. return this;
  18406. }
  18407. setLoopStart( value ) {
  18408. this.loopStart = value;
  18409. return this;
  18410. }
  18411. setLoopEnd( value ) {
  18412. this.loopEnd = value;
  18413. return this;
  18414. }
  18415. getVolume() {
  18416. return this.gain.gain.value;
  18417. }
  18418. setVolume( value ) {
  18419. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18420. return this;
  18421. }
  18422. copy( source, recursive ) {
  18423. super.copy( source, recursive );
  18424. if ( source.sourceType !== 'buffer' ) {
  18425. console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
  18426. return this;
  18427. }
  18428. this.autoplay = source.autoplay;
  18429. this.buffer = source.buffer;
  18430. this.detune = source.detune;
  18431. this.loop = source.loop;
  18432. this.loopStart = source.loopStart;
  18433. this.loopEnd = source.loopEnd;
  18434. this.offset = source.offset;
  18435. this.duration = source.duration;
  18436. this.playbackRate = source.playbackRate;
  18437. this.hasPlaybackControl = source.hasPlaybackControl;
  18438. this.sourceType = source.sourceType;
  18439. this.filters = source.filters.slice();
  18440. return this;
  18441. }
  18442. clone( recursive ) {
  18443. return new this.constructor( this.listener ).copy( this, recursive );
  18444. }
  18445. }
  18446. const _position = /*@__PURE__*/ new Vector3();
  18447. const _quaternion = /*@__PURE__*/ new Quaternion();
  18448. const _scale = /*@__PURE__*/ new Vector3();
  18449. const _orientation = /*@__PURE__*/ new Vector3();
  18450. class PositionalAudio extends Audio {
  18451. constructor( listener ) {
  18452. super( listener );
  18453. this.panner = this.context.createPanner();
  18454. this.panner.panningModel = 'HRTF';
  18455. this.panner.connect( this.gain );
  18456. }
  18457. connect() {
  18458. super.connect();
  18459. this.panner.connect( this.gain );
  18460. }
  18461. disconnect() {
  18462. super.disconnect();
  18463. this.panner.disconnect( this.gain );
  18464. }
  18465. getOutput() {
  18466. return this.panner;
  18467. }
  18468. getRefDistance() {
  18469. return this.panner.refDistance;
  18470. }
  18471. setRefDistance( value ) {
  18472. this.panner.refDistance = value;
  18473. return this;
  18474. }
  18475. getRolloffFactor() {
  18476. return this.panner.rolloffFactor;
  18477. }
  18478. setRolloffFactor( value ) {
  18479. this.panner.rolloffFactor = value;
  18480. return this;
  18481. }
  18482. getDistanceModel() {
  18483. return this.panner.distanceModel;
  18484. }
  18485. setDistanceModel( value ) {
  18486. this.panner.distanceModel = value;
  18487. return this;
  18488. }
  18489. getMaxDistance() {
  18490. return this.panner.maxDistance;
  18491. }
  18492. setMaxDistance( value ) {
  18493. this.panner.maxDistance = value;
  18494. return this;
  18495. }
  18496. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  18497. this.panner.coneInnerAngle = coneInnerAngle;
  18498. this.panner.coneOuterAngle = coneOuterAngle;
  18499. this.panner.coneOuterGain = coneOuterGain;
  18500. return this;
  18501. }
  18502. updateMatrixWorld( force ) {
  18503. super.updateMatrixWorld( force );
  18504. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  18505. this.matrixWorld.decompose( _position, _quaternion, _scale );
  18506. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  18507. const panner = this.panner;
  18508. if ( panner.positionX ) {
  18509. // code path for Chrome and Firefox (see #14393)
  18510. const endTime = this.context.currentTime + this.listener.timeDelta;
  18511. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  18512. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  18513. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  18514. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  18515. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  18516. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  18517. } else {
  18518. panner.setPosition( _position.x, _position.y, _position.z );
  18519. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  18520. }
  18521. }
  18522. }
  18523. class AudioAnalyser {
  18524. constructor( audio, fftSize = 2048 ) {
  18525. this.analyser = audio.context.createAnalyser();
  18526. this.analyser.fftSize = fftSize;
  18527. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  18528. audio.getOutput().connect( this.analyser );
  18529. }
  18530. getFrequencyData() {
  18531. this.analyser.getByteFrequencyData( this.data );
  18532. return this.data;
  18533. }
  18534. getAverageFrequency() {
  18535. let value = 0;
  18536. const data = this.getFrequencyData();
  18537. for ( let i = 0; i < data.length; i ++ ) {
  18538. value += data[ i ];
  18539. }
  18540. return value / data.length;
  18541. }
  18542. }
  18543. class PropertyMixer {
  18544. constructor( binding, typeName, valueSize ) {
  18545. this.binding = binding;
  18546. this.valueSize = valueSize;
  18547. let mixFunction,
  18548. mixFunctionAdditive,
  18549. setIdentity;
  18550. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  18551. //
  18552. // interpolators can use .buffer as their .result
  18553. // the data then goes to 'incoming'
  18554. //
  18555. // 'accu0' and 'accu1' are used frame-interleaved for
  18556. // the cumulative result and are compared to detect
  18557. // changes
  18558. //
  18559. // 'orig' stores the original state of the property
  18560. //
  18561. // 'add' is used for additive cumulative results
  18562. //
  18563. // 'work' is optional and is only present for quaternion types. It is used
  18564. // to store intermediate quaternion multiplication results
  18565. switch ( typeName ) {
  18566. case 'quaternion':
  18567. mixFunction = this._slerp;
  18568. mixFunctionAdditive = this._slerpAdditive;
  18569. setIdentity = this._setAdditiveIdentityQuaternion;
  18570. this.buffer = new Float64Array( valueSize * 6 );
  18571. this._workIndex = 5;
  18572. break;
  18573. case 'string':
  18574. case 'bool':
  18575. mixFunction = this._select;
  18576. // Use the regular mix function and for additive on these types,
  18577. // additive is not relevant for non-numeric types
  18578. mixFunctionAdditive = this._select;
  18579. setIdentity = this._setAdditiveIdentityOther;
  18580. this.buffer = new Array( valueSize * 5 );
  18581. break;
  18582. default:
  18583. mixFunction = this._lerp;
  18584. mixFunctionAdditive = this._lerpAdditive;
  18585. setIdentity = this._setAdditiveIdentityNumeric;
  18586. this.buffer = new Float64Array( valueSize * 5 );
  18587. }
  18588. this._mixBufferRegion = mixFunction;
  18589. this._mixBufferRegionAdditive = mixFunctionAdditive;
  18590. this._setIdentity = setIdentity;
  18591. this._origIndex = 3;
  18592. this._addIndex = 4;
  18593. this.cumulativeWeight = 0;
  18594. this.cumulativeWeightAdditive = 0;
  18595. this.useCount = 0;
  18596. this.referenceCount = 0;
  18597. }
  18598. // accumulate data in the 'incoming' region into 'accu<i>'
  18599. accumulate( accuIndex, weight ) {
  18600. // note: happily accumulating nothing when weight = 0, the caller knows
  18601. // the weight and shouldn't have made the call in the first place
  18602. const buffer = this.buffer,
  18603. stride = this.valueSize,
  18604. offset = accuIndex * stride + stride;
  18605. let currentWeight = this.cumulativeWeight;
  18606. if ( currentWeight === 0 ) {
  18607. // accuN := incoming * weight
  18608. for ( let i = 0; i !== stride; ++ i ) {
  18609. buffer[ offset + i ] = buffer[ i ];
  18610. }
  18611. currentWeight = weight;
  18612. } else {
  18613. // accuN := accuN + incoming * weight
  18614. currentWeight += weight;
  18615. const mix = weight / currentWeight;
  18616. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  18617. }
  18618. this.cumulativeWeight = currentWeight;
  18619. }
  18620. // accumulate data in the 'incoming' region into 'add'
  18621. accumulateAdditive( weight ) {
  18622. const buffer = this.buffer,
  18623. stride = this.valueSize,
  18624. offset = stride * this._addIndex;
  18625. if ( this.cumulativeWeightAdditive === 0 ) {
  18626. // add = identity
  18627. this._setIdentity();
  18628. }
  18629. // add := add + incoming * weight
  18630. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  18631. this.cumulativeWeightAdditive += weight;
  18632. }
  18633. // apply the state of 'accu<i>' to the binding when accus differ
  18634. apply( accuIndex ) {
  18635. const stride = this.valueSize,
  18636. buffer = this.buffer,
  18637. offset = accuIndex * stride + stride,
  18638. weight = this.cumulativeWeight,
  18639. weightAdditive = this.cumulativeWeightAdditive,
  18640. binding = this.binding;
  18641. this.cumulativeWeight = 0;
  18642. this.cumulativeWeightAdditive = 0;
  18643. if ( weight < 1 ) {
  18644. // accuN := accuN + original * ( 1 - cumulativeWeight )
  18645. const originalValueOffset = stride * this._origIndex;
  18646. this._mixBufferRegion(
  18647. buffer, offset, originalValueOffset, 1 - weight, stride );
  18648. }
  18649. if ( weightAdditive > 0 ) {
  18650. // accuN := accuN + additive accuN
  18651. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  18652. }
  18653. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  18654. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  18655. // value has changed -> update scene graph
  18656. binding.setValue( buffer, offset );
  18657. break;
  18658. }
  18659. }
  18660. }
  18661. // remember the state of the bound property and copy it to both accus
  18662. saveOriginalState() {
  18663. const binding = this.binding;
  18664. const buffer = this.buffer,
  18665. stride = this.valueSize,
  18666. originalValueOffset = stride * this._origIndex;
  18667. binding.getValue( buffer, originalValueOffset );
  18668. // accu[0..1] := orig -- initially detect changes against the original
  18669. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  18670. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  18671. }
  18672. // Add to identity for additive
  18673. this._setIdentity();
  18674. this.cumulativeWeight = 0;
  18675. this.cumulativeWeightAdditive = 0;
  18676. }
  18677. // apply the state previously taken via 'saveOriginalState' to the binding
  18678. restoreOriginalState() {
  18679. const originalValueOffset = this.valueSize * 3;
  18680. this.binding.setValue( this.buffer, originalValueOffset );
  18681. }
  18682. _setAdditiveIdentityNumeric() {
  18683. const startIndex = this._addIndex * this.valueSize;
  18684. const endIndex = startIndex + this.valueSize;
  18685. for ( let i = startIndex; i < endIndex; i ++ ) {
  18686. this.buffer[ i ] = 0;
  18687. }
  18688. }
  18689. _setAdditiveIdentityQuaternion() {
  18690. this._setAdditiveIdentityNumeric();
  18691. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  18692. }
  18693. _setAdditiveIdentityOther() {
  18694. const startIndex = this._origIndex * this.valueSize;
  18695. const targetIndex = this._addIndex * this.valueSize;
  18696. for ( let i = 0; i < this.valueSize; i ++ ) {
  18697. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  18698. }
  18699. }
  18700. // mix functions
  18701. _select( buffer, dstOffset, srcOffset, t, stride ) {
  18702. if ( t >= 0.5 ) {
  18703. for ( let i = 0; i !== stride; ++ i ) {
  18704. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  18705. }
  18706. }
  18707. }
  18708. _slerp( buffer, dstOffset, srcOffset, t ) {
  18709. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  18710. }
  18711. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18712. const workOffset = this._workIndex * stride;
  18713. // Store result in intermediate buffer offset
  18714. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  18715. // Slerp to the intermediate result
  18716. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  18717. }
  18718. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  18719. const s = 1 - t;
  18720. for ( let i = 0; i !== stride; ++ i ) {
  18721. const j = dstOffset + i;
  18722. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  18723. }
  18724. }
  18725. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18726. for ( let i = 0; i !== stride; ++ i ) {
  18727. const j = dstOffset + i;
  18728. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  18729. }
  18730. }
  18731. }
  18732. // Characters [].:/ are reserved for track binding syntax.
  18733. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  18734. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  18735. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  18736. // only latin characters, and the unicode \p{L} is not yet supported. So
  18737. // instead, we exclude reserved characters and match everything else.
  18738. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  18739. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  18740. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  18741. // be matched to parse the rest of the track name.
  18742. const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  18743. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  18744. const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  18745. // Object on target node, and accessor. May not contain reserved
  18746. // characters. Accessor may contain any character except closing bracket.
  18747. const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  18748. // Property and accessor. May not contain reserved characters. Accessor may
  18749. // contain any non-bracket characters.
  18750. const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  18751. const _trackRe = new RegExp( ''
  18752. + '^'
  18753. + _directoryRe
  18754. + _nodeRe
  18755. + _objectRe
  18756. + _propertyRe
  18757. + '$'
  18758. );
  18759. const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
  18760. class Composite {
  18761. constructor( targetGroup, path, optionalParsedPath ) {
  18762. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  18763. this._targetGroup = targetGroup;
  18764. this._bindings = targetGroup.subscribe_( path, parsedPath );
  18765. }
  18766. getValue( array, offset ) {
  18767. this.bind(); // bind all binding
  18768. const firstValidIndex = this._targetGroup.nCachedObjects_,
  18769. binding = this._bindings[ firstValidIndex ];
  18770. // and only call .getValue on the first
  18771. if ( binding !== undefined ) binding.getValue( array, offset );
  18772. }
  18773. setValue( array, offset ) {
  18774. const bindings = this._bindings;
  18775. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18776. bindings[ i ].setValue( array, offset );
  18777. }
  18778. }
  18779. bind() {
  18780. const bindings = this._bindings;
  18781. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18782. bindings[ i ].bind();
  18783. }
  18784. }
  18785. unbind() {
  18786. const bindings = this._bindings;
  18787. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18788. bindings[ i ].unbind();
  18789. }
  18790. }
  18791. }
  18792. // Note: This class uses a State pattern on a per-method basis:
  18793. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  18794. // prototype version of these methods with one that represents
  18795. // the bound state. When the property is not found, the methods
  18796. // become no-ops.
  18797. class PropertyBinding {
  18798. constructor( rootNode, path, parsedPath ) {
  18799. this.path = path;
  18800. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  18801. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
  18802. this.rootNode = rootNode;
  18803. // initial state of these methods that calls 'bind'
  18804. this.getValue = this._getValue_unbound;
  18805. this.setValue = this._setValue_unbound;
  18806. }
  18807. static create( root, path, parsedPath ) {
  18808. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  18809. return new PropertyBinding( root, path, parsedPath );
  18810. } else {
  18811. return new PropertyBinding.Composite( root, path, parsedPath );
  18812. }
  18813. }
  18814. /**
  18815. * Replaces spaces with underscores and removes unsupported characters from
  18816. * node names, to ensure compatibility with parseTrackName().
  18817. *
  18818. * @param {string} name Node name to be sanitized.
  18819. * @return {string}
  18820. */
  18821. static sanitizeNodeName( name ) {
  18822. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  18823. }
  18824. static parseTrackName( trackName ) {
  18825. const matches = _trackRe.exec( trackName );
  18826. if ( matches === null ) {
  18827. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  18828. }
  18829. const results = {
  18830. // directoryName: matches[ 1 ], // (tschw) currently unused
  18831. nodeName: matches[ 2 ],
  18832. objectName: matches[ 3 ],
  18833. objectIndex: matches[ 4 ],
  18834. propertyName: matches[ 5 ], // required
  18835. propertyIndex: matches[ 6 ]
  18836. };
  18837. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  18838. if ( lastDot !== undefined && lastDot !== - 1 ) {
  18839. const objectName = results.nodeName.substring( lastDot + 1 );
  18840. // Object names must be checked against an allowlist. Otherwise, there
  18841. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  18842. // 'bar' could be the objectName, or part of a nodeName (which can
  18843. // include '.' characters).
  18844. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  18845. results.nodeName = results.nodeName.substring( 0, lastDot );
  18846. results.objectName = objectName;
  18847. }
  18848. }
  18849. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  18850. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  18851. }
  18852. return results;
  18853. }
  18854. static findNode( root, nodeName ) {
  18855. if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  18856. return root;
  18857. }
  18858. // search into skeleton bones.
  18859. if ( root.skeleton ) {
  18860. const bone = root.skeleton.getBoneByName( nodeName );
  18861. if ( bone !== undefined ) {
  18862. return bone;
  18863. }
  18864. }
  18865. // search into node subtree.
  18866. if ( root.children ) {
  18867. const searchNodeSubtree = function ( children ) {
  18868. for ( let i = 0; i < children.length; i ++ ) {
  18869. const childNode = children[ i ];
  18870. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  18871. return childNode;
  18872. }
  18873. const result = searchNodeSubtree( childNode.children );
  18874. if ( result ) return result;
  18875. }
  18876. return null;
  18877. };
  18878. const subTreeNode = searchNodeSubtree( root.children );
  18879. if ( subTreeNode ) {
  18880. return subTreeNode;
  18881. }
  18882. }
  18883. return null;
  18884. }
  18885. // these are used to "bind" a nonexistent property
  18886. _getValue_unavailable() {}
  18887. _setValue_unavailable() {}
  18888. // Getters
  18889. _getValue_direct( buffer, offset ) {
  18890. buffer[ offset ] = this.targetObject[ this.propertyName ];
  18891. }
  18892. _getValue_array( buffer, offset ) {
  18893. const source = this.resolvedProperty;
  18894. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  18895. buffer[ offset ++ ] = source[ i ];
  18896. }
  18897. }
  18898. _getValue_arrayElement( buffer, offset ) {
  18899. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  18900. }
  18901. _getValue_toArray( buffer, offset ) {
  18902. this.resolvedProperty.toArray( buffer, offset );
  18903. }
  18904. // Direct
  18905. _setValue_direct( buffer, offset ) {
  18906. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18907. }
  18908. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  18909. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18910. this.targetObject.needsUpdate = true;
  18911. }
  18912. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18913. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18914. this.targetObject.matrixWorldNeedsUpdate = true;
  18915. }
  18916. // EntireArray
  18917. _setValue_array( buffer, offset ) {
  18918. const dest = this.resolvedProperty;
  18919. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18920. dest[ i ] = buffer[ offset ++ ];
  18921. }
  18922. }
  18923. _setValue_array_setNeedsUpdate( buffer, offset ) {
  18924. const dest = this.resolvedProperty;
  18925. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18926. dest[ i ] = buffer[ offset ++ ];
  18927. }
  18928. this.targetObject.needsUpdate = true;
  18929. }
  18930. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18931. const dest = this.resolvedProperty;
  18932. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18933. dest[ i ] = buffer[ offset ++ ];
  18934. }
  18935. this.targetObject.matrixWorldNeedsUpdate = true;
  18936. }
  18937. // ArrayElement
  18938. _setValue_arrayElement( buffer, offset ) {
  18939. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18940. }
  18941. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  18942. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18943. this.targetObject.needsUpdate = true;
  18944. }
  18945. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18946. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18947. this.targetObject.matrixWorldNeedsUpdate = true;
  18948. }
  18949. // HasToFromArray
  18950. _setValue_fromArray( buffer, offset ) {
  18951. this.resolvedProperty.fromArray( buffer, offset );
  18952. }
  18953. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  18954. this.resolvedProperty.fromArray( buffer, offset );
  18955. this.targetObject.needsUpdate = true;
  18956. }
  18957. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18958. this.resolvedProperty.fromArray( buffer, offset );
  18959. this.targetObject.matrixWorldNeedsUpdate = true;
  18960. }
  18961. _getValue_unbound( targetArray, offset ) {
  18962. this.bind();
  18963. this.getValue( targetArray, offset );
  18964. }
  18965. _setValue_unbound( sourceArray, offset ) {
  18966. this.bind();
  18967. this.setValue( sourceArray, offset );
  18968. }
  18969. // create getter / setter pair for a property in the scene graph
  18970. bind() {
  18971. let targetObject = this.node;
  18972. const parsedPath = this.parsedPath;
  18973. const objectName = parsedPath.objectName;
  18974. const propertyName = parsedPath.propertyName;
  18975. let propertyIndex = parsedPath.propertyIndex;
  18976. if ( ! targetObject ) {
  18977. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
  18978. this.node = targetObject;
  18979. }
  18980. // set fail state so we can just 'return' on error
  18981. this.getValue = this._getValue_unavailable;
  18982. this.setValue = this._setValue_unavailable;
  18983. // ensure there is a value node
  18984. if ( ! targetObject ) {
  18985. console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
  18986. return;
  18987. }
  18988. if ( objectName ) {
  18989. let objectIndex = parsedPath.objectIndex;
  18990. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  18991. switch ( objectName ) {
  18992. case 'materials':
  18993. if ( ! targetObject.material ) {
  18994. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  18995. return;
  18996. }
  18997. if ( ! targetObject.material.materials ) {
  18998. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  18999. return;
  19000. }
  19001. targetObject = targetObject.material.materials;
  19002. break;
  19003. case 'bones':
  19004. if ( ! targetObject.skeleton ) {
  19005. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  19006. return;
  19007. }
  19008. // potential future optimization: skip this if propertyIndex is already an integer
  19009. // and convert the integer string to a true integer.
  19010. targetObject = targetObject.skeleton.bones;
  19011. // support resolving morphTarget names into indices.
  19012. for ( let i = 0; i < targetObject.length; i ++ ) {
  19013. if ( targetObject[ i ].name === objectIndex ) {
  19014. objectIndex = i;
  19015. break;
  19016. }
  19017. }
  19018. break;
  19019. case 'map':
  19020. if ( 'map' in targetObject ) {
  19021. targetObject = targetObject.map;
  19022. break;
  19023. }
  19024. if ( ! targetObject.material ) {
  19025. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19026. return;
  19027. }
  19028. if ( ! targetObject.material.map ) {
  19029. console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
  19030. return;
  19031. }
  19032. targetObject = targetObject.material.map;
  19033. break;
  19034. default:
  19035. if ( targetObject[ objectName ] === undefined ) {
  19036. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  19037. return;
  19038. }
  19039. targetObject = targetObject[ objectName ];
  19040. }
  19041. if ( objectIndex !== undefined ) {
  19042. if ( targetObject[ objectIndex ] === undefined ) {
  19043. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  19044. return;
  19045. }
  19046. targetObject = targetObject[ objectIndex ];
  19047. }
  19048. }
  19049. // resolve property
  19050. const nodeProperty = targetObject[ propertyName ];
  19051. if ( nodeProperty === undefined ) {
  19052. const nodeName = parsedPath.nodeName;
  19053. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  19054. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  19055. return;
  19056. }
  19057. // determine versioning scheme
  19058. let versioning = this.Versioning.None;
  19059. this.targetObject = targetObject;
  19060. if ( targetObject.needsUpdate !== undefined ) { // material
  19061. versioning = this.Versioning.NeedsUpdate;
  19062. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  19063. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  19064. }
  19065. // determine how the property gets bound
  19066. let bindingType = this.BindingType.Direct;
  19067. if ( propertyIndex !== undefined ) {
  19068. // access a sub element of the property array (only primitives are supported right now)
  19069. if ( propertyName === 'morphTargetInfluences' ) {
  19070. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  19071. // support resolving morphTarget names into indices.
  19072. if ( ! targetObject.geometry ) {
  19073. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  19074. return;
  19075. }
  19076. if ( ! targetObject.geometry.morphAttributes ) {
  19077. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  19078. return;
  19079. }
  19080. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  19081. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  19082. }
  19083. }
  19084. bindingType = this.BindingType.ArrayElement;
  19085. this.resolvedProperty = nodeProperty;
  19086. this.propertyIndex = propertyIndex;
  19087. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  19088. // must use copy for Object3D.Euler/Quaternion
  19089. bindingType = this.BindingType.HasFromToArray;
  19090. this.resolvedProperty = nodeProperty;
  19091. } else if ( Array.isArray( nodeProperty ) ) {
  19092. bindingType = this.BindingType.EntireArray;
  19093. this.resolvedProperty = nodeProperty;
  19094. } else {
  19095. this.propertyName = propertyName;
  19096. }
  19097. // select getter / setter
  19098. this.getValue = this.GetterByBindingType[ bindingType ];
  19099. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  19100. }
  19101. unbind() {
  19102. this.node = null;
  19103. // back to the prototype version of getValue / setValue
  19104. // note: avoiding to mutate the shape of 'this' via 'delete'
  19105. this.getValue = this._getValue_unbound;
  19106. this.setValue = this._setValue_unbound;
  19107. }
  19108. }
  19109. PropertyBinding.Composite = Composite;
  19110. PropertyBinding.prototype.BindingType = {
  19111. Direct: 0,
  19112. EntireArray: 1,
  19113. ArrayElement: 2,
  19114. HasFromToArray: 3
  19115. };
  19116. PropertyBinding.prototype.Versioning = {
  19117. None: 0,
  19118. NeedsUpdate: 1,
  19119. MatrixWorldNeedsUpdate: 2
  19120. };
  19121. PropertyBinding.prototype.GetterByBindingType = [
  19122. PropertyBinding.prototype._getValue_direct,
  19123. PropertyBinding.prototype._getValue_array,
  19124. PropertyBinding.prototype._getValue_arrayElement,
  19125. PropertyBinding.prototype._getValue_toArray,
  19126. ];
  19127. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  19128. [
  19129. // Direct
  19130. PropertyBinding.prototype._setValue_direct,
  19131. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  19132. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  19133. ], [
  19134. // EntireArray
  19135. PropertyBinding.prototype._setValue_array,
  19136. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  19137. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  19138. ], [
  19139. // ArrayElement
  19140. PropertyBinding.prototype._setValue_arrayElement,
  19141. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  19142. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  19143. ], [
  19144. // HasToFromArray
  19145. PropertyBinding.prototype._setValue_fromArray,
  19146. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  19147. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  19148. ]
  19149. ];
  19150. /**
  19151. *
  19152. * A group of objects that receives a shared animation state.
  19153. *
  19154. * Usage:
  19155. *
  19156. * - Add objects you would otherwise pass as 'root' to the
  19157. * constructor or the .clipAction method of AnimationMixer.
  19158. *
  19159. * - Instead pass this object as 'root'.
  19160. *
  19161. * - You can also add and remove objects later when the mixer
  19162. * is running.
  19163. *
  19164. * Note:
  19165. *
  19166. * Objects of this class appear as one object to the mixer,
  19167. * so cache control of the individual objects must be done
  19168. * on the group.
  19169. *
  19170. * Limitation:
  19171. *
  19172. * - The animated properties must be compatible among the
  19173. * all objects in the group.
  19174. *
  19175. * - A single property can either be controlled through a
  19176. * target group or directly, but not both.
  19177. */
  19178. class AnimationObjectGroup {
  19179. constructor() {
  19180. this.isAnimationObjectGroup = true;
  19181. this.uuid = generateUUID();
  19182. // cached objects followed by the active ones
  19183. this._objects = Array.prototype.slice.call( arguments );
  19184. this.nCachedObjects_ = 0; // threshold
  19185. // note: read by PropertyBinding.Composite
  19186. const indices = {};
  19187. this._indicesByUUID = indices; // for bookkeeping
  19188. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19189. indices[ arguments[ i ].uuid ] = i;
  19190. }
  19191. this._paths = []; // inside: string
  19192. this._parsedPaths = []; // inside: { we don't care, here }
  19193. this._bindings = []; // inside: Array< PropertyBinding >
  19194. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  19195. const scope = this;
  19196. this.stats = {
  19197. objects: {
  19198. get total() {
  19199. return scope._objects.length;
  19200. },
  19201. get inUse() {
  19202. return this.total - scope.nCachedObjects_;
  19203. }
  19204. },
  19205. get bindingsPerObject() {
  19206. return scope._bindings.length;
  19207. }
  19208. };
  19209. }
  19210. add() {
  19211. const objects = this._objects,
  19212. indicesByUUID = this._indicesByUUID,
  19213. paths = this._paths,
  19214. parsedPaths = this._parsedPaths,
  19215. bindings = this._bindings,
  19216. nBindings = bindings.length;
  19217. let knownObject = undefined,
  19218. nObjects = objects.length,
  19219. nCachedObjects = this.nCachedObjects_;
  19220. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19221. const object = arguments[ i ],
  19222. uuid = object.uuid;
  19223. let index = indicesByUUID[ uuid ];
  19224. if ( index === undefined ) {
  19225. // unknown object -> add it to the ACTIVE region
  19226. index = nObjects ++;
  19227. indicesByUUID[ uuid ] = index;
  19228. objects.push( object );
  19229. // accounting is done, now do the same for all bindings
  19230. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19231. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  19232. }
  19233. } else if ( index < nCachedObjects ) {
  19234. knownObject = objects[ index ];
  19235. // move existing object to the ACTIVE region
  19236. const firstActiveIndex = -- nCachedObjects,
  19237. lastCachedObject = objects[ firstActiveIndex ];
  19238. indicesByUUID[ lastCachedObject.uuid ] = index;
  19239. objects[ index ] = lastCachedObject;
  19240. indicesByUUID[ uuid ] = firstActiveIndex;
  19241. objects[ firstActiveIndex ] = object;
  19242. // accounting is done, now do the same for all bindings
  19243. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19244. const bindingsForPath = bindings[ j ],
  19245. lastCached = bindingsForPath[ firstActiveIndex ];
  19246. let binding = bindingsForPath[ index ];
  19247. bindingsForPath[ index ] = lastCached;
  19248. if ( binding === undefined ) {
  19249. // since we do not bother to create new bindings
  19250. // for objects that are cached, the binding may
  19251. // or may not exist
  19252. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  19253. }
  19254. bindingsForPath[ firstActiveIndex ] = binding;
  19255. }
  19256. } else if ( objects[ index ] !== knownObject ) {
  19257. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  19258. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  19259. } // else the object is already where we want it to be
  19260. } // for arguments
  19261. this.nCachedObjects_ = nCachedObjects;
  19262. }
  19263. remove() {
  19264. const objects = this._objects,
  19265. indicesByUUID = this._indicesByUUID,
  19266. bindings = this._bindings,
  19267. nBindings = bindings.length;
  19268. let nCachedObjects = this.nCachedObjects_;
  19269. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19270. const object = arguments[ i ],
  19271. uuid = object.uuid,
  19272. index = indicesByUUID[ uuid ];
  19273. if ( index !== undefined && index >= nCachedObjects ) {
  19274. // move existing object into the CACHED region
  19275. const lastCachedIndex = nCachedObjects ++,
  19276. firstActiveObject = objects[ lastCachedIndex ];
  19277. indicesByUUID[ firstActiveObject.uuid ] = index;
  19278. objects[ index ] = firstActiveObject;
  19279. indicesByUUID[ uuid ] = lastCachedIndex;
  19280. objects[ lastCachedIndex ] = object;
  19281. // accounting is done, now do the same for all bindings
  19282. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19283. const bindingsForPath = bindings[ j ],
  19284. firstActive = bindingsForPath[ lastCachedIndex ],
  19285. binding = bindingsForPath[ index ];
  19286. bindingsForPath[ index ] = firstActive;
  19287. bindingsForPath[ lastCachedIndex ] = binding;
  19288. }
  19289. }
  19290. } // for arguments
  19291. this.nCachedObjects_ = nCachedObjects;
  19292. }
  19293. // remove & forget
  19294. uncache() {
  19295. const objects = this._objects,
  19296. indicesByUUID = this._indicesByUUID,
  19297. bindings = this._bindings,
  19298. nBindings = bindings.length;
  19299. let nCachedObjects = this.nCachedObjects_,
  19300. nObjects = objects.length;
  19301. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19302. const object = arguments[ i ],
  19303. uuid = object.uuid,
  19304. index = indicesByUUID[ uuid ];
  19305. if ( index !== undefined ) {
  19306. delete indicesByUUID[ uuid ];
  19307. if ( index < nCachedObjects ) {
  19308. // object is cached, shrink the CACHED region
  19309. const firstActiveIndex = -- nCachedObjects,
  19310. lastCachedObject = objects[ firstActiveIndex ],
  19311. lastIndex = -- nObjects,
  19312. lastObject = objects[ lastIndex ];
  19313. // last cached object takes this object's place
  19314. indicesByUUID[ lastCachedObject.uuid ] = index;
  19315. objects[ index ] = lastCachedObject;
  19316. // last object goes to the activated slot and pop
  19317. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  19318. objects[ firstActiveIndex ] = lastObject;
  19319. objects.pop();
  19320. // accounting is done, now do the same for all bindings
  19321. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19322. const bindingsForPath = bindings[ j ],
  19323. lastCached = bindingsForPath[ firstActiveIndex ],
  19324. last = bindingsForPath[ lastIndex ];
  19325. bindingsForPath[ index ] = lastCached;
  19326. bindingsForPath[ firstActiveIndex ] = last;
  19327. bindingsForPath.pop();
  19328. }
  19329. } else {
  19330. // object is active, just swap with the last and pop
  19331. const lastIndex = -- nObjects,
  19332. lastObject = objects[ lastIndex ];
  19333. if ( lastIndex > 0 ) {
  19334. indicesByUUID[ lastObject.uuid ] = index;
  19335. }
  19336. objects[ index ] = lastObject;
  19337. objects.pop();
  19338. // accounting is done, now do the same for all bindings
  19339. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19340. const bindingsForPath = bindings[ j ];
  19341. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  19342. bindingsForPath.pop();
  19343. }
  19344. } // cached or active
  19345. } // if object is known
  19346. } // for arguments
  19347. this.nCachedObjects_ = nCachedObjects;
  19348. }
  19349. // Internal interface used by befriended PropertyBinding.Composite:
  19350. subscribe_( path, parsedPath ) {
  19351. // returns an array of bindings for the given path that is changed
  19352. // according to the contained objects in the group
  19353. const indicesByPath = this._bindingsIndicesByPath;
  19354. let index = indicesByPath[ path ];
  19355. const bindings = this._bindings;
  19356. if ( index !== undefined ) return bindings[ index ];
  19357. const paths = this._paths,
  19358. parsedPaths = this._parsedPaths,
  19359. objects = this._objects,
  19360. nObjects = objects.length,
  19361. nCachedObjects = this.nCachedObjects_,
  19362. bindingsForPath = new Array( nObjects );
  19363. index = bindings.length;
  19364. indicesByPath[ path ] = index;
  19365. paths.push( path );
  19366. parsedPaths.push( parsedPath );
  19367. bindings.push( bindingsForPath );
  19368. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  19369. const object = objects[ i ];
  19370. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  19371. }
  19372. return bindingsForPath;
  19373. }
  19374. unsubscribe_( path ) {
  19375. // tells the group to forget about a property path and no longer
  19376. // update the array previously obtained with 'subscribe_'
  19377. const indicesByPath = this._bindingsIndicesByPath,
  19378. index = indicesByPath[ path ];
  19379. if ( index !== undefined ) {
  19380. const paths = this._paths,
  19381. parsedPaths = this._parsedPaths,
  19382. bindings = this._bindings,
  19383. lastBindingsIndex = bindings.length - 1,
  19384. lastBindings = bindings[ lastBindingsIndex ],
  19385. lastBindingsPath = path[ lastBindingsIndex ];
  19386. indicesByPath[ lastBindingsPath ] = index;
  19387. bindings[ index ] = lastBindings;
  19388. bindings.pop();
  19389. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  19390. parsedPaths.pop();
  19391. paths[ index ] = paths[ lastBindingsIndex ];
  19392. paths.pop();
  19393. }
  19394. }
  19395. }
  19396. class AnimationAction {
  19397. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  19398. this._mixer = mixer;
  19399. this._clip = clip;
  19400. this._localRoot = localRoot;
  19401. this.blendMode = blendMode;
  19402. const tracks = clip.tracks,
  19403. nTracks = tracks.length,
  19404. interpolants = new Array( nTracks );
  19405. const interpolantSettings = {
  19406. endingStart: ZeroCurvatureEnding,
  19407. endingEnd: ZeroCurvatureEnding
  19408. };
  19409. for ( let i = 0; i !== nTracks; ++ i ) {
  19410. const interpolant = tracks[ i ].createInterpolant( null );
  19411. interpolants[ i ] = interpolant;
  19412. interpolant.settings = interpolantSettings;
  19413. }
  19414. this._interpolantSettings = interpolantSettings;
  19415. this._interpolants = interpolants; // bound by the mixer
  19416. // inside: PropertyMixer (managed by the mixer)
  19417. this._propertyBindings = new Array( nTracks );
  19418. this._cacheIndex = null; // for the memory manager
  19419. this._byClipCacheIndex = null; // for the memory manager
  19420. this._timeScaleInterpolant = null;
  19421. this._weightInterpolant = null;
  19422. this.loop = LoopRepeat;
  19423. this._loopCount = - 1;
  19424. // global mixer time when the action is to be started
  19425. // it's set back to 'null' upon start of the action
  19426. this._startTime = null;
  19427. // scaled local time of the action
  19428. // gets clamped or wrapped to 0..clip.duration according to loop
  19429. this.time = 0;
  19430. this.timeScale = 1;
  19431. this._effectiveTimeScale = 1;
  19432. this.weight = 1;
  19433. this._effectiveWeight = 1;
  19434. this.repetitions = Infinity; // no. of repetitions when looping
  19435. this.paused = false; // true -> zero effective time scale
  19436. this.enabled = true; // false -> zero effective weight
  19437. this.clampWhenFinished = false;// keep feeding the last frame?
  19438. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  19439. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  19440. }
  19441. // State & Scheduling
  19442. play() {
  19443. this._mixer._activateAction( this );
  19444. return this;
  19445. }
  19446. stop() {
  19447. this._mixer._deactivateAction( this );
  19448. return this.reset();
  19449. }
  19450. reset() {
  19451. this.paused = false;
  19452. this.enabled = true;
  19453. this.time = 0; // restart clip
  19454. this._loopCount = - 1;// forget previous loops
  19455. this._startTime = null;// forget scheduling
  19456. return this.stopFading().stopWarping();
  19457. }
  19458. isRunning() {
  19459. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  19460. this._startTime === null && this._mixer._isActiveAction( this );
  19461. }
  19462. // return true when play has been called
  19463. isScheduled() {
  19464. return this._mixer._isActiveAction( this );
  19465. }
  19466. startAt( time ) {
  19467. this._startTime = time;
  19468. return this;
  19469. }
  19470. setLoop( mode, repetitions ) {
  19471. this.loop = mode;
  19472. this.repetitions = repetitions;
  19473. return this;
  19474. }
  19475. // Weight
  19476. // set the weight stopping any scheduled fading
  19477. // although .enabled = false yields an effective weight of zero, this
  19478. // method does *not* change .enabled, because it would be confusing
  19479. setEffectiveWeight( weight ) {
  19480. this.weight = weight;
  19481. // note: same logic as when updated at runtime
  19482. this._effectiveWeight = this.enabled ? weight : 0;
  19483. return this.stopFading();
  19484. }
  19485. // return the weight considering fading and .enabled
  19486. getEffectiveWeight() {
  19487. return this._effectiveWeight;
  19488. }
  19489. fadeIn( duration ) {
  19490. return this._scheduleFading( duration, 0, 1 );
  19491. }
  19492. fadeOut( duration ) {
  19493. return this._scheduleFading( duration, 1, 0 );
  19494. }
  19495. crossFadeFrom( fadeOutAction, duration, warp ) {
  19496. fadeOutAction.fadeOut( duration );
  19497. this.fadeIn( duration );
  19498. if ( warp ) {
  19499. const fadeInDuration = this._clip.duration,
  19500. fadeOutDuration = fadeOutAction._clip.duration,
  19501. startEndRatio = fadeOutDuration / fadeInDuration,
  19502. endStartRatio = fadeInDuration / fadeOutDuration;
  19503. fadeOutAction.warp( 1.0, startEndRatio, duration );
  19504. this.warp( endStartRatio, 1.0, duration );
  19505. }
  19506. return this;
  19507. }
  19508. crossFadeTo( fadeInAction, duration, warp ) {
  19509. return fadeInAction.crossFadeFrom( this, duration, warp );
  19510. }
  19511. stopFading() {
  19512. const weightInterpolant = this._weightInterpolant;
  19513. if ( weightInterpolant !== null ) {
  19514. this._weightInterpolant = null;
  19515. this._mixer._takeBackControlInterpolant( weightInterpolant );
  19516. }
  19517. return this;
  19518. }
  19519. // Time Scale Control
  19520. // set the time scale stopping any scheduled warping
  19521. // although .paused = true yields an effective time scale of zero, this
  19522. // method does *not* change .paused, because it would be confusing
  19523. setEffectiveTimeScale( timeScale ) {
  19524. this.timeScale = timeScale;
  19525. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  19526. return this.stopWarping();
  19527. }
  19528. // return the time scale considering warping and .paused
  19529. getEffectiveTimeScale() {
  19530. return this._effectiveTimeScale;
  19531. }
  19532. setDuration( duration ) {
  19533. this.timeScale = this._clip.duration / duration;
  19534. return this.stopWarping();
  19535. }
  19536. syncWith( action ) {
  19537. this.time = action.time;
  19538. this.timeScale = action.timeScale;
  19539. return this.stopWarping();
  19540. }
  19541. halt( duration ) {
  19542. return this.warp( this._effectiveTimeScale, 0, duration );
  19543. }
  19544. warp( startTimeScale, endTimeScale, duration ) {
  19545. const mixer = this._mixer,
  19546. now = mixer.time,
  19547. timeScale = this.timeScale;
  19548. let interpolant = this._timeScaleInterpolant;
  19549. if ( interpolant === null ) {
  19550. interpolant = mixer._lendControlInterpolant();
  19551. this._timeScaleInterpolant = interpolant;
  19552. }
  19553. const times = interpolant.parameterPositions,
  19554. values = interpolant.sampleValues;
  19555. times[ 0 ] = now;
  19556. times[ 1 ] = now + duration;
  19557. values[ 0 ] = startTimeScale / timeScale;
  19558. values[ 1 ] = endTimeScale / timeScale;
  19559. return this;
  19560. }
  19561. stopWarping() {
  19562. const timeScaleInterpolant = this._timeScaleInterpolant;
  19563. if ( timeScaleInterpolant !== null ) {
  19564. this._timeScaleInterpolant = null;
  19565. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  19566. }
  19567. return this;
  19568. }
  19569. // Object Accessors
  19570. getMixer() {
  19571. return this._mixer;
  19572. }
  19573. getClip() {
  19574. return this._clip;
  19575. }
  19576. getRoot() {
  19577. return this._localRoot || this._mixer._root;
  19578. }
  19579. // Interna
  19580. _update( time, deltaTime, timeDirection, accuIndex ) {
  19581. // called by the mixer
  19582. if ( ! this.enabled ) {
  19583. // call ._updateWeight() to update ._effectiveWeight
  19584. this._updateWeight( time );
  19585. return;
  19586. }
  19587. const startTime = this._startTime;
  19588. if ( startTime !== null ) {
  19589. // check for scheduled start of action
  19590. const timeRunning = ( time - startTime ) * timeDirection;
  19591. if ( timeRunning < 0 || timeDirection === 0 ) {
  19592. deltaTime = 0;
  19593. } else {
  19594. this._startTime = null; // unschedule
  19595. deltaTime = timeDirection * timeRunning;
  19596. }
  19597. }
  19598. // apply time scale and advance time
  19599. deltaTime *= this._updateTimeScale( time );
  19600. const clipTime = this._updateTime( deltaTime );
  19601. // note: _updateTime may disable the action resulting in
  19602. // an effective weight of 0
  19603. const weight = this._updateWeight( time );
  19604. if ( weight > 0 ) {
  19605. const interpolants = this._interpolants;
  19606. const propertyMixers = this._propertyBindings;
  19607. switch ( this.blendMode ) {
  19608. case AdditiveAnimationBlendMode:
  19609. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19610. interpolants[ j ].evaluate( clipTime );
  19611. propertyMixers[ j ].accumulateAdditive( weight );
  19612. }
  19613. break;
  19614. case NormalAnimationBlendMode:
  19615. default:
  19616. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19617. interpolants[ j ].evaluate( clipTime );
  19618. propertyMixers[ j ].accumulate( accuIndex, weight );
  19619. }
  19620. }
  19621. }
  19622. }
  19623. _updateWeight( time ) {
  19624. let weight = 0;
  19625. if ( this.enabled ) {
  19626. weight = this.weight;
  19627. const interpolant = this._weightInterpolant;
  19628. if ( interpolant !== null ) {
  19629. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19630. weight *= interpolantValue;
  19631. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19632. this.stopFading();
  19633. if ( interpolantValue === 0 ) {
  19634. // faded out, disable
  19635. this.enabled = false;
  19636. }
  19637. }
  19638. }
  19639. }
  19640. this._effectiveWeight = weight;
  19641. return weight;
  19642. }
  19643. _updateTimeScale( time ) {
  19644. let timeScale = 0;
  19645. if ( ! this.paused ) {
  19646. timeScale = this.timeScale;
  19647. const interpolant = this._timeScaleInterpolant;
  19648. if ( interpolant !== null ) {
  19649. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19650. timeScale *= interpolantValue;
  19651. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19652. this.stopWarping();
  19653. if ( timeScale === 0 ) {
  19654. // motion has halted, pause
  19655. this.paused = true;
  19656. } else {
  19657. // warp done - apply final time scale
  19658. this.timeScale = timeScale;
  19659. }
  19660. }
  19661. }
  19662. }
  19663. this._effectiveTimeScale = timeScale;
  19664. return timeScale;
  19665. }
  19666. _updateTime( deltaTime ) {
  19667. const duration = this._clip.duration;
  19668. const loop = this.loop;
  19669. let time = this.time + deltaTime;
  19670. let loopCount = this._loopCount;
  19671. const pingPong = ( loop === LoopPingPong );
  19672. if ( deltaTime === 0 ) {
  19673. if ( loopCount === - 1 ) return time;
  19674. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  19675. }
  19676. if ( loop === LoopOnce ) {
  19677. if ( loopCount === - 1 ) {
  19678. // just started
  19679. this._loopCount = 0;
  19680. this._setEndings( true, true, false );
  19681. }
  19682. handle_stop: {
  19683. if ( time >= duration ) {
  19684. time = duration;
  19685. } else if ( time < 0 ) {
  19686. time = 0;
  19687. } else {
  19688. this.time = time;
  19689. break handle_stop;
  19690. }
  19691. if ( this.clampWhenFinished ) this.paused = true;
  19692. else this.enabled = false;
  19693. this.time = time;
  19694. this._mixer.dispatchEvent( {
  19695. type: 'finished', action: this,
  19696. direction: deltaTime < 0 ? - 1 : 1
  19697. } );
  19698. }
  19699. } else { // repetitive Repeat or PingPong
  19700. if ( loopCount === - 1 ) {
  19701. // just started
  19702. if ( deltaTime >= 0 ) {
  19703. loopCount = 0;
  19704. this._setEndings( true, this.repetitions === 0, pingPong );
  19705. } else {
  19706. // when looping in reverse direction, the initial
  19707. // transition through zero counts as a repetition,
  19708. // so leave loopCount at -1
  19709. this._setEndings( this.repetitions === 0, true, pingPong );
  19710. }
  19711. }
  19712. if ( time >= duration || time < 0 ) {
  19713. // wrap around
  19714. const loopDelta = Math.floor( time / duration ); // signed
  19715. time -= duration * loopDelta;
  19716. loopCount += Math.abs( loopDelta );
  19717. const pending = this.repetitions - loopCount;
  19718. if ( pending <= 0 ) {
  19719. // have to stop (switch state, clamp time, fire event)
  19720. if ( this.clampWhenFinished ) this.paused = true;
  19721. else this.enabled = false;
  19722. time = deltaTime > 0 ? duration : 0;
  19723. this.time = time;
  19724. this._mixer.dispatchEvent( {
  19725. type: 'finished', action: this,
  19726. direction: deltaTime > 0 ? 1 : - 1
  19727. } );
  19728. } else {
  19729. // keep running
  19730. if ( pending === 1 ) {
  19731. // entering the last round
  19732. const atStart = deltaTime < 0;
  19733. this._setEndings( atStart, ! atStart, pingPong );
  19734. } else {
  19735. this._setEndings( false, false, pingPong );
  19736. }
  19737. this._loopCount = loopCount;
  19738. this.time = time;
  19739. this._mixer.dispatchEvent( {
  19740. type: 'loop', action: this, loopDelta: loopDelta
  19741. } );
  19742. }
  19743. } else {
  19744. this.time = time;
  19745. }
  19746. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  19747. // invert time for the "pong round"
  19748. return duration - time;
  19749. }
  19750. }
  19751. return time;
  19752. }
  19753. _setEndings( atStart, atEnd, pingPong ) {
  19754. const settings = this._interpolantSettings;
  19755. if ( pingPong ) {
  19756. settings.endingStart = ZeroSlopeEnding;
  19757. settings.endingEnd = ZeroSlopeEnding;
  19758. } else {
  19759. // assuming for LoopOnce atStart == atEnd == true
  19760. if ( atStart ) {
  19761. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19762. } else {
  19763. settings.endingStart = WrapAroundEnding;
  19764. }
  19765. if ( atEnd ) {
  19766. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19767. } else {
  19768. settings.endingEnd = WrapAroundEnding;
  19769. }
  19770. }
  19771. }
  19772. _scheduleFading( duration, weightNow, weightThen ) {
  19773. const mixer = this._mixer, now = mixer.time;
  19774. let interpolant = this._weightInterpolant;
  19775. if ( interpolant === null ) {
  19776. interpolant = mixer._lendControlInterpolant();
  19777. this._weightInterpolant = interpolant;
  19778. }
  19779. const times = interpolant.parameterPositions,
  19780. values = interpolant.sampleValues;
  19781. times[ 0 ] = now;
  19782. values[ 0 ] = weightNow;
  19783. times[ 1 ] = now + duration;
  19784. values[ 1 ] = weightThen;
  19785. return this;
  19786. }
  19787. }
  19788. const _controlInterpolantsResultBuffer = new Float32Array( 1 );
  19789. class AnimationMixer extends EventDispatcher {
  19790. constructor( root ) {
  19791. super();
  19792. this._root = root;
  19793. this._initMemoryManager();
  19794. this._accuIndex = 0;
  19795. this.time = 0;
  19796. this.timeScale = 1.0;
  19797. }
  19798. _bindAction( action, prototypeAction ) {
  19799. const root = action._localRoot || this._root,
  19800. tracks = action._clip.tracks,
  19801. nTracks = tracks.length,
  19802. bindings = action._propertyBindings,
  19803. interpolants = action._interpolants,
  19804. rootUuid = root.uuid,
  19805. bindingsByRoot = this._bindingsByRootAndName;
  19806. let bindingsByName = bindingsByRoot[ rootUuid ];
  19807. if ( bindingsByName === undefined ) {
  19808. bindingsByName = {};
  19809. bindingsByRoot[ rootUuid ] = bindingsByName;
  19810. }
  19811. for ( let i = 0; i !== nTracks; ++ i ) {
  19812. const track = tracks[ i ],
  19813. trackName = track.name;
  19814. let binding = bindingsByName[ trackName ];
  19815. if ( binding !== undefined ) {
  19816. ++ binding.referenceCount;
  19817. bindings[ i ] = binding;
  19818. } else {
  19819. binding = bindings[ i ];
  19820. if ( binding !== undefined ) {
  19821. // existing binding, make sure the cache knows
  19822. if ( binding._cacheIndex === null ) {
  19823. ++ binding.referenceCount;
  19824. this._addInactiveBinding( binding, rootUuid, trackName );
  19825. }
  19826. continue;
  19827. }
  19828. const path = prototypeAction && prototypeAction.
  19829. _propertyBindings[ i ].binding.parsedPath;
  19830. binding = new PropertyMixer(
  19831. PropertyBinding.create( root, trackName, path ),
  19832. track.ValueTypeName, track.getValueSize() );
  19833. ++ binding.referenceCount;
  19834. this._addInactiveBinding( binding, rootUuid, trackName );
  19835. bindings[ i ] = binding;
  19836. }
  19837. interpolants[ i ].resultBuffer = binding.buffer;
  19838. }
  19839. }
  19840. _activateAction( action ) {
  19841. if ( ! this._isActiveAction( action ) ) {
  19842. if ( action._cacheIndex === null ) {
  19843. // this action has been forgotten by the cache, but the user
  19844. // appears to be still using it -> rebind
  19845. const rootUuid = ( action._localRoot || this._root ).uuid,
  19846. clipUuid = action._clip.uuid,
  19847. actionsForClip = this._actionsByClip[ clipUuid ];
  19848. this._bindAction( action,
  19849. actionsForClip && actionsForClip.knownActions[ 0 ] );
  19850. this._addInactiveAction( action, clipUuid, rootUuid );
  19851. }
  19852. const bindings = action._propertyBindings;
  19853. // increment reference counts / sort out state
  19854. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19855. const binding = bindings[ i ];
  19856. if ( binding.useCount ++ === 0 ) {
  19857. this._lendBinding( binding );
  19858. binding.saveOriginalState();
  19859. }
  19860. }
  19861. this._lendAction( action );
  19862. }
  19863. }
  19864. _deactivateAction( action ) {
  19865. if ( this._isActiveAction( action ) ) {
  19866. const bindings = action._propertyBindings;
  19867. // decrement reference counts / sort out state
  19868. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19869. const binding = bindings[ i ];
  19870. if ( -- binding.useCount === 0 ) {
  19871. binding.restoreOriginalState();
  19872. this._takeBackBinding( binding );
  19873. }
  19874. }
  19875. this._takeBackAction( action );
  19876. }
  19877. }
  19878. // Memory manager
  19879. _initMemoryManager() {
  19880. this._actions = []; // 'nActiveActions' followed by inactive ones
  19881. this._nActiveActions = 0;
  19882. this._actionsByClip = {};
  19883. // inside:
  19884. // {
  19885. // knownActions: Array< AnimationAction > - used as prototypes
  19886. // actionByRoot: AnimationAction - lookup
  19887. // }
  19888. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  19889. this._nActiveBindings = 0;
  19890. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  19891. this._controlInterpolants = []; // same game as above
  19892. this._nActiveControlInterpolants = 0;
  19893. const scope = this;
  19894. this.stats = {
  19895. actions: {
  19896. get total() {
  19897. return scope._actions.length;
  19898. },
  19899. get inUse() {
  19900. return scope._nActiveActions;
  19901. }
  19902. },
  19903. bindings: {
  19904. get total() {
  19905. return scope._bindings.length;
  19906. },
  19907. get inUse() {
  19908. return scope._nActiveBindings;
  19909. }
  19910. },
  19911. controlInterpolants: {
  19912. get total() {
  19913. return scope._controlInterpolants.length;
  19914. },
  19915. get inUse() {
  19916. return scope._nActiveControlInterpolants;
  19917. }
  19918. }
  19919. };
  19920. }
  19921. // Memory management for AnimationAction objects
  19922. _isActiveAction( action ) {
  19923. const index = action._cacheIndex;
  19924. return index !== null && index < this._nActiveActions;
  19925. }
  19926. _addInactiveAction( action, clipUuid, rootUuid ) {
  19927. const actions = this._actions,
  19928. actionsByClip = this._actionsByClip;
  19929. let actionsForClip = actionsByClip[ clipUuid ];
  19930. if ( actionsForClip === undefined ) {
  19931. actionsForClip = {
  19932. knownActions: [ action ],
  19933. actionByRoot: {}
  19934. };
  19935. action._byClipCacheIndex = 0;
  19936. actionsByClip[ clipUuid ] = actionsForClip;
  19937. } else {
  19938. const knownActions = actionsForClip.knownActions;
  19939. action._byClipCacheIndex = knownActions.length;
  19940. knownActions.push( action );
  19941. }
  19942. action._cacheIndex = actions.length;
  19943. actions.push( action );
  19944. actionsForClip.actionByRoot[ rootUuid ] = action;
  19945. }
  19946. _removeInactiveAction( action ) {
  19947. const actions = this._actions,
  19948. lastInactiveAction = actions[ actions.length - 1 ],
  19949. cacheIndex = action._cacheIndex;
  19950. lastInactiveAction._cacheIndex = cacheIndex;
  19951. actions[ cacheIndex ] = lastInactiveAction;
  19952. actions.pop();
  19953. action._cacheIndex = null;
  19954. const clipUuid = action._clip.uuid,
  19955. actionsByClip = this._actionsByClip,
  19956. actionsForClip = actionsByClip[ clipUuid ],
  19957. knownActionsForClip = actionsForClip.knownActions,
  19958. lastKnownAction =
  19959. knownActionsForClip[ knownActionsForClip.length - 1 ],
  19960. byClipCacheIndex = action._byClipCacheIndex;
  19961. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  19962. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  19963. knownActionsForClip.pop();
  19964. action._byClipCacheIndex = null;
  19965. const actionByRoot = actionsForClip.actionByRoot,
  19966. rootUuid = ( action._localRoot || this._root ).uuid;
  19967. delete actionByRoot[ rootUuid ];
  19968. if ( knownActionsForClip.length === 0 ) {
  19969. delete actionsByClip[ clipUuid ];
  19970. }
  19971. this._removeInactiveBindingsForAction( action );
  19972. }
  19973. _removeInactiveBindingsForAction( action ) {
  19974. const bindings = action._propertyBindings;
  19975. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19976. const binding = bindings[ i ];
  19977. if ( -- binding.referenceCount === 0 ) {
  19978. this._removeInactiveBinding( binding );
  19979. }
  19980. }
  19981. }
  19982. _lendAction( action ) {
  19983. // [ active actions | inactive actions ]
  19984. // [ active actions >| inactive actions ]
  19985. // s a
  19986. // <-swap->
  19987. // a s
  19988. const actions = this._actions,
  19989. prevIndex = action._cacheIndex,
  19990. lastActiveIndex = this._nActiveActions ++,
  19991. firstInactiveAction = actions[ lastActiveIndex ];
  19992. action._cacheIndex = lastActiveIndex;
  19993. actions[ lastActiveIndex ] = action;
  19994. firstInactiveAction._cacheIndex = prevIndex;
  19995. actions[ prevIndex ] = firstInactiveAction;
  19996. }
  19997. _takeBackAction( action ) {
  19998. // [ active actions | inactive actions ]
  19999. // [ active actions |< inactive actions ]
  20000. // a s
  20001. // <-swap->
  20002. // s a
  20003. const actions = this._actions,
  20004. prevIndex = action._cacheIndex,
  20005. firstInactiveIndex = -- this._nActiveActions,
  20006. lastActiveAction = actions[ firstInactiveIndex ];
  20007. action._cacheIndex = firstInactiveIndex;
  20008. actions[ firstInactiveIndex ] = action;
  20009. lastActiveAction._cacheIndex = prevIndex;
  20010. actions[ prevIndex ] = lastActiveAction;
  20011. }
  20012. // Memory management for PropertyMixer objects
  20013. _addInactiveBinding( binding, rootUuid, trackName ) {
  20014. const bindingsByRoot = this._bindingsByRootAndName,
  20015. bindings = this._bindings;
  20016. let bindingByName = bindingsByRoot[ rootUuid ];
  20017. if ( bindingByName === undefined ) {
  20018. bindingByName = {};
  20019. bindingsByRoot[ rootUuid ] = bindingByName;
  20020. }
  20021. bindingByName[ trackName ] = binding;
  20022. binding._cacheIndex = bindings.length;
  20023. bindings.push( binding );
  20024. }
  20025. _removeInactiveBinding( binding ) {
  20026. const bindings = this._bindings,
  20027. propBinding = binding.binding,
  20028. rootUuid = propBinding.rootNode.uuid,
  20029. trackName = propBinding.path,
  20030. bindingsByRoot = this._bindingsByRootAndName,
  20031. bindingByName = bindingsByRoot[ rootUuid ],
  20032. lastInactiveBinding = bindings[ bindings.length - 1 ],
  20033. cacheIndex = binding._cacheIndex;
  20034. lastInactiveBinding._cacheIndex = cacheIndex;
  20035. bindings[ cacheIndex ] = lastInactiveBinding;
  20036. bindings.pop();
  20037. delete bindingByName[ trackName ];
  20038. if ( Object.keys( bindingByName ).length === 0 ) {
  20039. delete bindingsByRoot[ rootUuid ];
  20040. }
  20041. }
  20042. _lendBinding( binding ) {
  20043. const bindings = this._bindings,
  20044. prevIndex = binding._cacheIndex,
  20045. lastActiveIndex = this._nActiveBindings ++,
  20046. firstInactiveBinding = bindings[ lastActiveIndex ];
  20047. binding._cacheIndex = lastActiveIndex;
  20048. bindings[ lastActiveIndex ] = binding;
  20049. firstInactiveBinding._cacheIndex = prevIndex;
  20050. bindings[ prevIndex ] = firstInactiveBinding;
  20051. }
  20052. _takeBackBinding( binding ) {
  20053. const bindings = this._bindings,
  20054. prevIndex = binding._cacheIndex,
  20055. firstInactiveIndex = -- this._nActiveBindings,
  20056. lastActiveBinding = bindings[ firstInactiveIndex ];
  20057. binding._cacheIndex = firstInactiveIndex;
  20058. bindings[ firstInactiveIndex ] = binding;
  20059. lastActiveBinding._cacheIndex = prevIndex;
  20060. bindings[ prevIndex ] = lastActiveBinding;
  20061. }
  20062. // Memory management of Interpolants for weight and time scale
  20063. _lendControlInterpolant() {
  20064. const interpolants = this._controlInterpolants,
  20065. lastActiveIndex = this._nActiveControlInterpolants ++;
  20066. let interpolant = interpolants[ lastActiveIndex ];
  20067. if ( interpolant === undefined ) {
  20068. interpolant = new LinearInterpolant(
  20069. new Float32Array( 2 ), new Float32Array( 2 ),
  20070. 1, _controlInterpolantsResultBuffer );
  20071. interpolant.__cacheIndex = lastActiveIndex;
  20072. interpolants[ lastActiveIndex ] = interpolant;
  20073. }
  20074. return interpolant;
  20075. }
  20076. _takeBackControlInterpolant( interpolant ) {
  20077. const interpolants = this._controlInterpolants,
  20078. prevIndex = interpolant.__cacheIndex,
  20079. firstInactiveIndex = -- this._nActiveControlInterpolants,
  20080. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  20081. interpolant.__cacheIndex = firstInactiveIndex;
  20082. interpolants[ firstInactiveIndex ] = interpolant;
  20083. lastActiveInterpolant.__cacheIndex = prevIndex;
  20084. interpolants[ prevIndex ] = lastActiveInterpolant;
  20085. }
  20086. // return an action for a clip optionally using a custom root target
  20087. // object (this method allocates a lot of dynamic memory in case a
  20088. // previously unknown clip/root combination is specified)
  20089. clipAction( clip, optionalRoot, blendMode ) {
  20090. const root = optionalRoot || this._root,
  20091. rootUuid = root.uuid;
  20092. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  20093. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  20094. const actionsForClip = this._actionsByClip[ clipUuid ];
  20095. let prototypeAction = null;
  20096. if ( blendMode === undefined ) {
  20097. if ( clipObject !== null ) {
  20098. blendMode = clipObject.blendMode;
  20099. } else {
  20100. blendMode = NormalAnimationBlendMode;
  20101. }
  20102. }
  20103. if ( actionsForClip !== undefined ) {
  20104. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  20105. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  20106. return existingAction;
  20107. }
  20108. // we know the clip, so we don't have to parse all
  20109. // the bindings again but can just copy
  20110. prototypeAction = actionsForClip.knownActions[ 0 ];
  20111. // also, take the clip from the prototype action
  20112. if ( clipObject === null )
  20113. clipObject = prototypeAction._clip;
  20114. }
  20115. // clip must be known when specified via string
  20116. if ( clipObject === null ) return null;
  20117. // allocate all resources required to run it
  20118. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  20119. this._bindAction( newAction, prototypeAction );
  20120. // and make the action known to the memory manager
  20121. this._addInactiveAction( newAction, clipUuid, rootUuid );
  20122. return newAction;
  20123. }
  20124. // get an existing action
  20125. existingAction( clip, optionalRoot ) {
  20126. const root = optionalRoot || this._root,
  20127. rootUuid = root.uuid,
  20128. clipObject = typeof clip === 'string' ?
  20129. AnimationClip.findByName( root, clip ) : clip,
  20130. clipUuid = clipObject ? clipObject.uuid : clip,
  20131. actionsForClip = this._actionsByClip[ clipUuid ];
  20132. if ( actionsForClip !== undefined ) {
  20133. return actionsForClip.actionByRoot[ rootUuid ] || null;
  20134. }
  20135. return null;
  20136. }
  20137. // deactivates all previously scheduled actions
  20138. stopAllAction() {
  20139. const actions = this._actions,
  20140. nActions = this._nActiveActions;
  20141. for ( let i = nActions - 1; i >= 0; -- i ) {
  20142. actions[ i ].stop();
  20143. }
  20144. return this;
  20145. }
  20146. // advance the time and update apply the animation
  20147. update( deltaTime ) {
  20148. deltaTime *= this.timeScale;
  20149. const actions = this._actions,
  20150. nActions = this._nActiveActions,
  20151. time = this.time += deltaTime,
  20152. timeDirection = Math.sign( deltaTime ),
  20153. accuIndex = this._accuIndex ^= 1;
  20154. // run active actions
  20155. for ( let i = 0; i !== nActions; ++ i ) {
  20156. const action = actions[ i ];
  20157. action._update( time, deltaTime, timeDirection, accuIndex );
  20158. }
  20159. // update scene graph
  20160. const bindings = this._bindings,
  20161. nBindings = this._nActiveBindings;
  20162. for ( let i = 0; i !== nBindings; ++ i ) {
  20163. bindings[ i ].apply( accuIndex );
  20164. }
  20165. return this;
  20166. }
  20167. // Allows you to seek to a specific time in an animation.
  20168. setTime( timeInSeconds ) {
  20169. this.time = 0; // Zero out time attribute for AnimationMixer object;
  20170. for ( let i = 0; i < this._actions.length; i ++ ) {
  20171. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  20172. }
  20173. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  20174. }
  20175. // return this mixer's root target object
  20176. getRoot() {
  20177. return this._root;
  20178. }
  20179. // free all resources specific to a particular clip
  20180. uncacheClip( clip ) {
  20181. const actions = this._actions,
  20182. clipUuid = clip.uuid,
  20183. actionsByClip = this._actionsByClip,
  20184. actionsForClip = actionsByClip[ clipUuid ];
  20185. if ( actionsForClip !== undefined ) {
  20186. // note: just calling _removeInactiveAction would mess up the
  20187. // iteration state and also require updating the state we can
  20188. // just throw away
  20189. const actionsToRemove = actionsForClip.knownActions;
  20190. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  20191. const action = actionsToRemove[ i ];
  20192. this._deactivateAction( action );
  20193. const cacheIndex = action._cacheIndex,
  20194. lastInactiveAction = actions[ actions.length - 1 ];
  20195. action._cacheIndex = null;
  20196. action._byClipCacheIndex = null;
  20197. lastInactiveAction._cacheIndex = cacheIndex;
  20198. actions[ cacheIndex ] = lastInactiveAction;
  20199. actions.pop();
  20200. this._removeInactiveBindingsForAction( action );
  20201. }
  20202. delete actionsByClip[ clipUuid ];
  20203. }
  20204. }
  20205. // free all resources specific to a particular root target object
  20206. uncacheRoot( root ) {
  20207. const rootUuid = root.uuid,
  20208. actionsByClip = this._actionsByClip;
  20209. for ( const clipUuid in actionsByClip ) {
  20210. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  20211. action = actionByRoot[ rootUuid ];
  20212. if ( action !== undefined ) {
  20213. this._deactivateAction( action );
  20214. this._removeInactiveAction( action );
  20215. }
  20216. }
  20217. const bindingsByRoot = this._bindingsByRootAndName,
  20218. bindingByName = bindingsByRoot[ rootUuid ];
  20219. if ( bindingByName !== undefined ) {
  20220. for ( const trackName in bindingByName ) {
  20221. const binding = bindingByName[ trackName ];
  20222. binding.restoreOriginalState();
  20223. this._removeInactiveBinding( binding );
  20224. }
  20225. }
  20226. }
  20227. // remove a targeted clip from the cache
  20228. uncacheAction( clip, optionalRoot ) {
  20229. const action = this.existingAction( clip, optionalRoot );
  20230. if ( action !== null ) {
  20231. this._deactivateAction( action );
  20232. this._removeInactiveAction( action );
  20233. }
  20234. }
  20235. }
  20236. class Uniform {
  20237. constructor( value ) {
  20238. this.value = value;
  20239. }
  20240. clone() {
  20241. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  20242. }
  20243. }
  20244. let _id = 0;
  20245. class UniformsGroup extends EventDispatcher {
  20246. constructor() {
  20247. super();
  20248. this.isUniformsGroup = true;
  20249. Object.defineProperty( this, 'id', { value: _id ++ } );
  20250. this.name = '';
  20251. this.usage = StaticDrawUsage;
  20252. this.uniforms = [];
  20253. }
  20254. add( uniform ) {
  20255. this.uniforms.push( uniform );
  20256. return this;
  20257. }
  20258. remove( uniform ) {
  20259. const index = this.uniforms.indexOf( uniform );
  20260. if ( index !== - 1 ) this.uniforms.splice( index, 1 );
  20261. return this;
  20262. }
  20263. setName( name ) {
  20264. this.name = name;
  20265. return this;
  20266. }
  20267. setUsage( value ) {
  20268. this.usage = value;
  20269. return this;
  20270. }
  20271. dispose() {
  20272. this.dispatchEvent( { type: 'dispose' } );
  20273. return this;
  20274. }
  20275. copy( source ) {
  20276. this.name = source.name;
  20277. this.usage = source.usage;
  20278. const uniformsSource = source.uniforms;
  20279. this.uniforms.length = 0;
  20280. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  20281. const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
  20282. for ( let j = 0; j < uniforms.length; j ++ ) {
  20283. this.uniforms.push( uniforms[ j ].clone() );
  20284. }
  20285. }
  20286. return this;
  20287. }
  20288. clone() {
  20289. return new this.constructor().copy( this );
  20290. }
  20291. }
  20292. class InstancedInterleavedBuffer extends InterleavedBuffer {
  20293. constructor( array, stride, meshPerAttribute = 1 ) {
  20294. super( array, stride );
  20295. this.isInstancedInterleavedBuffer = true;
  20296. this.meshPerAttribute = meshPerAttribute;
  20297. }
  20298. copy( source ) {
  20299. super.copy( source );
  20300. this.meshPerAttribute = source.meshPerAttribute;
  20301. return this;
  20302. }
  20303. clone( data ) {
  20304. const ib = super.clone( data );
  20305. ib.meshPerAttribute = this.meshPerAttribute;
  20306. return ib;
  20307. }
  20308. toJSON( data ) {
  20309. const json = super.toJSON( data );
  20310. json.isInstancedInterleavedBuffer = true;
  20311. json.meshPerAttribute = this.meshPerAttribute;
  20312. return json;
  20313. }
  20314. }
  20315. class GLBufferAttribute {
  20316. constructor( buffer, type, itemSize, elementSize, count ) {
  20317. this.isGLBufferAttribute = true;
  20318. this.name = '';
  20319. this.buffer = buffer;
  20320. this.type = type;
  20321. this.itemSize = itemSize;
  20322. this.elementSize = elementSize;
  20323. this.count = count;
  20324. this.version = 0;
  20325. }
  20326. set needsUpdate( value ) {
  20327. if ( value === true ) this.version ++;
  20328. }
  20329. setBuffer( buffer ) {
  20330. this.buffer = buffer;
  20331. return this;
  20332. }
  20333. setType( type, elementSize ) {
  20334. this.type = type;
  20335. this.elementSize = elementSize;
  20336. return this;
  20337. }
  20338. setItemSize( itemSize ) {
  20339. this.itemSize = itemSize;
  20340. return this;
  20341. }
  20342. setCount( count ) {
  20343. this.count = count;
  20344. return this;
  20345. }
  20346. }
  20347. const _matrix = /*@__PURE__*/ new Matrix4();
  20348. class Raycaster {
  20349. constructor( origin, direction, near = 0, far = Infinity ) {
  20350. this.ray = new Ray( origin, direction );
  20351. // direction is assumed to be normalized (for accurate distance calculations)
  20352. this.near = near;
  20353. this.far = far;
  20354. this.camera = null;
  20355. this.layers = new Layers();
  20356. this.params = {
  20357. Mesh: {},
  20358. Line: { threshold: 1 },
  20359. LOD: {},
  20360. Points: { threshold: 1 },
  20361. Sprite: {}
  20362. };
  20363. }
  20364. set( origin, direction ) {
  20365. // direction is assumed to be normalized (for accurate distance calculations)
  20366. this.ray.set( origin, direction );
  20367. }
  20368. setFromCamera( coords, camera ) {
  20369. if ( camera.isPerspectiveCamera ) {
  20370. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  20371. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  20372. this.camera = camera;
  20373. } else if ( camera.isOrthographicCamera ) {
  20374. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  20375. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  20376. this.camera = camera;
  20377. } else {
  20378. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  20379. }
  20380. }
  20381. setFromXRController( controller ) {
  20382. _matrix.identity().extractRotation( controller.matrixWorld );
  20383. this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
  20384. this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
  20385. return this;
  20386. }
  20387. intersectObject( object, recursive = true, intersects = [] ) {
  20388. intersect( object, this, intersects, recursive );
  20389. intersects.sort( ascSort );
  20390. return intersects;
  20391. }
  20392. intersectObjects( objects, recursive = true, intersects = [] ) {
  20393. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  20394. intersect( objects[ i ], this, intersects, recursive );
  20395. }
  20396. intersects.sort( ascSort );
  20397. return intersects;
  20398. }
  20399. }
  20400. function ascSort( a, b ) {
  20401. return a.distance - b.distance;
  20402. }
  20403. function intersect( object, raycaster, intersects, recursive ) {
  20404. let propagate = true;
  20405. if ( object.layers.test( raycaster.layers ) ) {
  20406. const result = object.raycast( raycaster, intersects );
  20407. if ( result === false ) propagate = false;
  20408. }
  20409. if ( propagate === true && recursive === true ) {
  20410. const children = object.children;
  20411. for ( let i = 0, l = children.length; i < l; i ++ ) {
  20412. intersect( children[ i ], raycaster, intersects, true );
  20413. }
  20414. }
  20415. }
  20416. /**
  20417. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  20418. *
  20419. * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up.
  20420. * theta (the azimuthal angle) is measured from the positive z-axis.
  20421. */
  20422. class Spherical {
  20423. constructor( radius = 1, phi = 0, theta = 0 ) {
  20424. this.radius = radius;
  20425. this.phi = phi; // polar angle
  20426. this.theta = theta; // azimuthal angle
  20427. return this;
  20428. }
  20429. set( radius, phi, theta ) {
  20430. this.radius = radius;
  20431. this.phi = phi;
  20432. this.theta = theta;
  20433. return this;
  20434. }
  20435. copy( other ) {
  20436. this.radius = other.radius;
  20437. this.phi = other.phi;
  20438. this.theta = other.theta;
  20439. return this;
  20440. }
  20441. // restrict phi to be between EPS and PI-EPS
  20442. makeSafe() {
  20443. const EPS = 0.000001;
  20444. this.phi = clamp( this.phi, EPS, Math.PI - EPS );
  20445. return this;
  20446. }
  20447. setFromVector3( v ) {
  20448. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20449. }
  20450. setFromCartesianCoords( x, y, z ) {
  20451. this.radius = Math.sqrt( x * x + y * y + z * z );
  20452. if ( this.radius === 0 ) {
  20453. this.theta = 0;
  20454. this.phi = 0;
  20455. } else {
  20456. this.theta = Math.atan2( x, z );
  20457. this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );
  20458. }
  20459. return this;
  20460. }
  20461. clone() {
  20462. return new this.constructor().copy( this );
  20463. }
  20464. }
  20465. /**
  20466. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  20467. */
  20468. class Cylindrical {
  20469. constructor( radius = 1, theta = 0, y = 0 ) {
  20470. this.radius = radius; // distance from the origin to a point in the x-z plane
  20471. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  20472. this.y = y; // height above the x-z plane
  20473. return this;
  20474. }
  20475. set( radius, theta, y ) {
  20476. this.radius = radius;
  20477. this.theta = theta;
  20478. this.y = y;
  20479. return this;
  20480. }
  20481. copy( other ) {
  20482. this.radius = other.radius;
  20483. this.theta = other.theta;
  20484. this.y = other.y;
  20485. return this;
  20486. }
  20487. setFromVector3( v ) {
  20488. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20489. }
  20490. setFromCartesianCoords( x, y, z ) {
  20491. this.radius = Math.sqrt( x * x + z * z );
  20492. this.theta = Math.atan2( x, z );
  20493. this.y = y;
  20494. return this;
  20495. }
  20496. clone() {
  20497. return new this.constructor().copy( this );
  20498. }
  20499. }
  20500. class Matrix2 {
  20501. constructor( n11, n12, n21, n22 ) {
  20502. Matrix2.prototype.isMatrix2 = true;
  20503. this.elements = [
  20504. 1, 0,
  20505. 0, 1,
  20506. ];
  20507. if ( n11 !== undefined ) {
  20508. this.set( n11, n12, n21, n22 );
  20509. }
  20510. }
  20511. identity() {
  20512. this.set(
  20513. 1, 0,
  20514. 0, 1,
  20515. );
  20516. return this;
  20517. }
  20518. fromArray( array, offset = 0 ) {
  20519. for ( let i = 0; i < 4; i ++ ) {
  20520. this.elements[ i ] = array[ i + offset ];
  20521. }
  20522. return this;
  20523. }
  20524. set( n11, n12, n21, n22 ) {
  20525. const te = this.elements;
  20526. te[ 0 ] = n11; te[ 2 ] = n12;
  20527. te[ 1 ] = n21; te[ 3 ] = n22;
  20528. return this;
  20529. }
  20530. }
  20531. const _vector$4 = /*@__PURE__*/ new Vector2();
  20532. class Box2 {
  20533. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  20534. this.isBox2 = true;
  20535. this.min = min;
  20536. this.max = max;
  20537. }
  20538. set( min, max ) {
  20539. this.min.copy( min );
  20540. this.max.copy( max );
  20541. return this;
  20542. }
  20543. setFromPoints( points ) {
  20544. this.makeEmpty();
  20545. for ( let i = 0, il = points.length; i < il; i ++ ) {
  20546. this.expandByPoint( points[ i ] );
  20547. }
  20548. return this;
  20549. }
  20550. setFromCenterAndSize( center, size ) {
  20551. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  20552. this.min.copy( center ).sub( halfSize );
  20553. this.max.copy( center ).add( halfSize );
  20554. return this;
  20555. }
  20556. clone() {
  20557. return new this.constructor().copy( this );
  20558. }
  20559. copy( box ) {
  20560. this.min.copy( box.min );
  20561. this.max.copy( box.max );
  20562. return this;
  20563. }
  20564. makeEmpty() {
  20565. this.min.x = this.min.y = + Infinity;
  20566. this.max.x = this.max.y = - Infinity;
  20567. return this;
  20568. }
  20569. isEmpty() {
  20570. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  20571. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  20572. }
  20573. getCenter( target ) {
  20574. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  20575. }
  20576. getSize( target ) {
  20577. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  20578. }
  20579. expandByPoint( point ) {
  20580. this.min.min( point );
  20581. this.max.max( point );
  20582. return this;
  20583. }
  20584. expandByVector( vector ) {
  20585. this.min.sub( vector );
  20586. this.max.add( vector );
  20587. return this;
  20588. }
  20589. expandByScalar( scalar ) {
  20590. this.min.addScalar( - scalar );
  20591. this.max.addScalar( scalar );
  20592. return this;
  20593. }
  20594. containsPoint( point ) {
  20595. return point.x >= this.min.x && point.x <= this.max.x &&
  20596. point.y >= this.min.y && point.y <= this.max.y;
  20597. }
  20598. containsBox( box ) {
  20599. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  20600. this.min.y <= box.min.y && box.max.y <= this.max.y;
  20601. }
  20602. getParameter( point, target ) {
  20603. // This can potentially have a divide by zero if the box
  20604. // has a size dimension of 0.
  20605. return target.set(
  20606. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  20607. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  20608. );
  20609. }
  20610. intersectsBox( box ) {
  20611. // using 4 splitting planes to rule out intersections
  20612. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  20613. box.max.y >= this.min.y && box.min.y <= this.max.y;
  20614. }
  20615. clampPoint( point, target ) {
  20616. return target.copy( point ).clamp( this.min, this.max );
  20617. }
  20618. distanceToPoint( point ) {
  20619. return this.clampPoint( point, _vector$4 ).distanceTo( point );
  20620. }
  20621. intersect( box ) {
  20622. this.min.max( box.min );
  20623. this.max.min( box.max );
  20624. if ( this.isEmpty() ) this.makeEmpty();
  20625. return this;
  20626. }
  20627. union( box ) {
  20628. this.min.min( box.min );
  20629. this.max.max( box.max );
  20630. return this;
  20631. }
  20632. translate( offset ) {
  20633. this.min.add( offset );
  20634. this.max.add( offset );
  20635. return this;
  20636. }
  20637. equals( box ) {
  20638. return box.min.equals( this.min ) && box.max.equals( this.max );
  20639. }
  20640. }
  20641. const _startP = /*@__PURE__*/ new Vector3();
  20642. const _startEnd = /*@__PURE__*/ new Vector3();
  20643. class Line3 {
  20644. constructor( start = new Vector3(), end = new Vector3() ) {
  20645. this.start = start;
  20646. this.end = end;
  20647. }
  20648. set( start, end ) {
  20649. this.start.copy( start );
  20650. this.end.copy( end );
  20651. return this;
  20652. }
  20653. copy( line ) {
  20654. this.start.copy( line.start );
  20655. this.end.copy( line.end );
  20656. return this;
  20657. }
  20658. getCenter( target ) {
  20659. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  20660. }
  20661. delta( target ) {
  20662. return target.subVectors( this.end, this.start );
  20663. }
  20664. distanceSq() {
  20665. return this.start.distanceToSquared( this.end );
  20666. }
  20667. distance() {
  20668. return this.start.distanceTo( this.end );
  20669. }
  20670. at( t, target ) {
  20671. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20672. }
  20673. closestPointToPointParameter( point, clampToLine ) {
  20674. _startP.subVectors( point, this.start );
  20675. _startEnd.subVectors( this.end, this.start );
  20676. const startEnd2 = _startEnd.dot( _startEnd );
  20677. const startEnd_startP = _startEnd.dot( _startP );
  20678. let t = startEnd_startP / startEnd2;
  20679. if ( clampToLine ) {
  20680. t = clamp( t, 0, 1 );
  20681. }
  20682. return t;
  20683. }
  20684. closestPointToPoint( point, clampToLine, target ) {
  20685. const t = this.closestPointToPointParameter( point, clampToLine );
  20686. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20687. }
  20688. applyMatrix4( matrix ) {
  20689. this.start.applyMatrix4( matrix );
  20690. this.end.applyMatrix4( matrix );
  20691. return this;
  20692. }
  20693. equals( line ) {
  20694. return line.start.equals( this.start ) && line.end.equals( this.end );
  20695. }
  20696. clone() {
  20697. return new this.constructor().copy( this );
  20698. }
  20699. }
  20700. const _vector$3 = /*@__PURE__*/ new Vector3();
  20701. class SpotLightHelper extends Object3D {
  20702. constructor( light, color ) {
  20703. super();
  20704. this.light = light;
  20705. this.matrixAutoUpdate = false;
  20706. this.color = color;
  20707. this.type = 'SpotLightHelper';
  20708. const geometry = new BufferGeometry();
  20709. const positions = [
  20710. 0, 0, 0, 0, 0, 1,
  20711. 0, 0, 0, 1, 0, 1,
  20712. 0, 0, 0, - 1, 0, 1,
  20713. 0, 0, 0, 0, 1, 1,
  20714. 0, 0, 0, 0, - 1, 1
  20715. ];
  20716. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  20717. const p1 = ( i / l ) * Math.PI * 2;
  20718. const p2 = ( j / l ) * Math.PI * 2;
  20719. positions.push(
  20720. Math.cos( p1 ), Math.sin( p1 ), 1,
  20721. Math.cos( p2 ), Math.sin( p2 ), 1
  20722. );
  20723. }
  20724. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  20725. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  20726. this.cone = new LineSegments( geometry, material );
  20727. this.add( this.cone );
  20728. this.update();
  20729. }
  20730. dispose() {
  20731. this.cone.geometry.dispose();
  20732. this.cone.material.dispose();
  20733. }
  20734. update() {
  20735. this.light.updateWorldMatrix( true, false );
  20736. this.light.target.updateWorldMatrix( true, false );
  20737. // update the local matrix based on the parent and light target transforms
  20738. if ( this.parent ) {
  20739. this.parent.updateWorldMatrix( true );
  20740. this.matrix
  20741. .copy( this.parent.matrixWorld )
  20742. .invert()
  20743. .multiply( this.light.matrixWorld );
  20744. } else {
  20745. this.matrix.copy( this.light.matrixWorld );
  20746. }
  20747. this.matrixWorld.copy( this.light.matrixWorld );
  20748. const coneLength = this.light.distance ? this.light.distance : 1000;
  20749. const coneWidth = coneLength * Math.tan( this.light.angle );
  20750. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20751. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  20752. this.cone.lookAt( _vector$3 );
  20753. if ( this.color !== undefined ) {
  20754. this.cone.material.color.set( this.color );
  20755. } else {
  20756. this.cone.material.color.copy( this.light.color );
  20757. }
  20758. }
  20759. }
  20760. const _vector$2 = /*@__PURE__*/ new Vector3();
  20761. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  20762. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  20763. class SkeletonHelper extends LineSegments {
  20764. constructor( object ) {
  20765. const bones = getBoneList( object );
  20766. const geometry = new BufferGeometry();
  20767. const vertices = [];
  20768. const colors = [];
  20769. const color1 = new Color( 0, 0, 1 );
  20770. const color2 = new Color( 0, 1, 0 );
  20771. for ( let i = 0; i < bones.length; i ++ ) {
  20772. const bone = bones[ i ];
  20773. if ( bone.parent && bone.parent.isBone ) {
  20774. vertices.push( 0, 0, 0 );
  20775. vertices.push( 0, 0, 0 );
  20776. colors.push( color1.r, color1.g, color1.b );
  20777. colors.push( color2.r, color2.g, color2.b );
  20778. }
  20779. }
  20780. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20781. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20782. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  20783. super( geometry, material );
  20784. this.isSkeletonHelper = true;
  20785. this.type = 'SkeletonHelper';
  20786. this.root = object;
  20787. this.bones = bones;
  20788. this.matrix = object.matrixWorld;
  20789. this.matrixAutoUpdate = false;
  20790. }
  20791. updateMatrixWorld( force ) {
  20792. const bones = this.bones;
  20793. const geometry = this.geometry;
  20794. const position = geometry.getAttribute( 'position' );
  20795. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  20796. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  20797. const bone = bones[ i ];
  20798. if ( bone.parent && bone.parent.isBone ) {
  20799. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  20800. _vector$2.setFromMatrixPosition( _boneMatrix );
  20801. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  20802. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  20803. _vector$2.setFromMatrixPosition( _boneMatrix );
  20804. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  20805. j += 2;
  20806. }
  20807. }
  20808. geometry.getAttribute( 'position' ).needsUpdate = true;
  20809. super.updateMatrixWorld( force );
  20810. }
  20811. dispose() {
  20812. this.geometry.dispose();
  20813. this.material.dispose();
  20814. }
  20815. }
  20816. function getBoneList( object ) {
  20817. const boneList = [];
  20818. if ( object.isBone === true ) {
  20819. boneList.push( object );
  20820. }
  20821. for ( let i = 0; i < object.children.length; i ++ ) {
  20822. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  20823. }
  20824. return boneList;
  20825. }
  20826. class PointLightHelper extends Mesh {
  20827. constructor( light, sphereSize, color ) {
  20828. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  20829. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20830. super( geometry, material );
  20831. this.light = light;
  20832. this.color = color;
  20833. this.type = 'PointLightHelper';
  20834. this.matrix = this.light.matrixWorld;
  20835. this.matrixAutoUpdate = false;
  20836. this.update();
  20837. /*
  20838. // TODO: delete this comment?
  20839. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20840. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20841. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20842. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20843. const d = light.distance;
  20844. if ( d === 0.0 ) {
  20845. this.lightDistance.visible = false;
  20846. } else {
  20847. this.lightDistance.scale.set( d, d, d );
  20848. }
  20849. this.add( this.lightDistance );
  20850. */
  20851. }
  20852. dispose() {
  20853. this.geometry.dispose();
  20854. this.material.dispose();
  20855. }
  20856. update() {
  20857. this.light.updateWorldMatrix( true, false );
  20858. if ( this.color !== undefined ) {
  20859. this.material.color.set( this.color );
  20860. } else {
  20861. this.material.color.copy( this.light.color );
  20862. }
  20863. /*
  20864. const d = this.light.distance;
  20865. if ( d === 0.0 ) {
  20866. this.lightDistance.visible = false;
  20867. } else {
  20868. this.lightDistance.visible = true;
  20869. this.lightDistance.scale.set( d, d, d );
  20870. }
  20871. */
  20872. }
  20873. }
  20874. const _vector$1 = /*@__PURE__*/ new Vector3();
  20875. const _color1 = /*@__PURE__*/ new Color();
  20876. const _color2 = /*@__PURE__*/ new Color();
  20877. class HemisphereLightHelper extends Object3D {
  20878. constructor( light, size, color ) {
  20879. super();
  20880. this.light = light;
  20881. this.matrix = light.matrixWorld;
  20882. this.matrixAutoUpdate = false;
  20883. this.color = color;
  20884. this.type = 'HemisphereLightHelper';
  20885. const geometry = new OctahedronGeometry( size );
  20886. geometry.rotateY( Math.PI * 0.5 );
  20887. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20888. if ( this.color === undefined ) this.material.vertexColors = true;
  20889. const position = geometry.getAttribute( 'position' );
  20890. const colors = new Float32Array( position.count * 3 );
  20891. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  20892. this.add( new Mesh( geometry, this.material ) );
  20893. this.update();
  20894. }
  20895. dispose() {
  20896. this.children[ 0 ].geometry.dispose();
  20897. this.children[ 0 ].material.dispose();
  20898. }
  20899. update() {
  20900. const mesh = this.children[ 0 ];
  20901. if ( this.color !== undefined ) {
  20902. this.material.color.set( this.color );
  20903. } else {
  20904. const colors = mesh.geometry.getAttribute( 'color' );
  20905. _color1.copy( this.light.color );
  20906. _color2.copy( this.light.groundColor );
  20907. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  20908. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  20909. colors.setXYZ( i, color.r, color.g, color.b );
  20910. }
  20911. colors.needsUpdate = true;
  20912. }
  20913. this.light.updateWorldMatrix( true, false );
  20914. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20915. }
  20916. }
  20917. class GridHelper extends LineSegments {
  20918. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  20919. color1 = new Color( color1 );
  20920. color2 = new Color( color2 );
  20921. const center = divisions / 2;
  20922. const step = size / divisions;
  20923. const halfSize = size / 2;
  20924. const vertices = [], colors = [];
  20925. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  20926. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  20927. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  20928. const color = i === center ? color1 : color2;
  20929. color.toArray( colors, j ); j += 3;
  20930. color.toArray( colors, j ); j += 3;
  20931. color.toArray( colors, j ); j += 3;
  20932. color.toArray( colors, j ); j += 3;
  20933. }
  20934. const geometry = new BufferGeometry();
  20935. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20936. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20937. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  20938. super( geometry, material );
  20939. this.type = 'GridHelper';
  20940. }
  20941. dispose() {
  20942. this.geometry.dispose();
  20943. this.material.dispose();
  20944. }
  20945. }
  20946. class PolarGridHelper extends LineSegments {
  20947. constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  20948. color1 = new Color( color1 );
  20949. color2 = new Color( color2 );
  20950. const vertices = [];
  20951. const colors = [];
  20952. // create the sectors
  20953. if ( sectors > 1 ) {
  20954. for ( let i = 0; i < sectors; i ++ ) {
  20955. const v = ( i / sectors ) * ( Math.PI * 2 );
  20956. const x = Math.sin( v ) * radius;
  20957. const z = Math.cos( v ) * radius;
  20958. vertices.push( 0, 0, 0 );
  20959. vertices.push( x, 0, z );
  20960. const color = ( i & 1 ) ? color1 : color2;
  20961. colors.push( color.r, color.g, color.b );
  20962. colors.push( color.r, color.g, color.b );
  20963. }
  20964. }
  20965. // create the rings
  20966. for ( let i = 0; i < rings; i ++ ) {
  20967. const color = ( i & 1 ) ? color1 : color2;
  20968. const r = radius - ( radius / rings * i );
  20969. for ( let j = 0; j < divisions; j ++ ) {
  20970. // first vertex
  20971. let v = ( j / divisions ) * ( Math.PI * 2 );
  20972. let x = Math.sin( v ) * r;
  20973. let z = Math.cos( v ) * r;
  20974. vertices.push( x, 0, z );
  20975. colors.push( color.r, color.g, color.b );
  20976. // second vertex
  20977. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  20978. x = Math.sin( v ) * r;
  20979. z = Math.cos( v ) * r;
  20980. vertices.push( x, 0, z );
  20981. colors.push( color.r, color.g, color.b );
  20982. }
  20983. }
  20984. const geometry = new BufferGeometry();
  20985. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20986. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20987. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  20988. super( geometry, material );
  20989. this.type = 'PolarGridHelper';
  20990. }
  20991. dispose() {
  20992. this.geometry.dispose();
  20993. this.material.dispose();
  20994. }
  20995. }
  20996. const _v1 = /*@__PURE__*/ new Vector3();
  20997. const _v2 = /*@__PURE__*/ new Vector3();
  20998. const _v3 = /*@__PURE__*/ new Vector3();
  20999. class DirectionalLightHelper extends Object3D {
  21000. constructor( light, size, color ) {
  21001. super();
  21002. this.light = light;
  21003. this.matrix = light.matrixWorld;
  21004. this.matrixAutoUpdate = false;
  21005. this.color = color;
  21006. this.type = 'DirectionalLightHelper';
  21007. if ( size === undefined ) size = 1;
  21008. let geometry = new BufferGeometry();
  21009. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  21010. - size, size, 0,
  21011. size, size, 0,
  21012. size, - size, 0,
  21013. - size, - size, 0,
  21014. - size, size, 0
  21015. ], 3 ) );
  21016. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  21017. this.lightPlane = new Line( geometry, material );
  21018. this.add( this.lightPlane );
  21019. geometry = new BufferGeometry();
  21020. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  21021. this.targetLine = new Line( geometry, material );
  21022. this.add( this.targetLine );
  21023. this.update();
  21024. }
  21025. dispose() {
  21026. this.lightPlane.geometry.dispose();
  21027. this.lightPlane.material.dispose();
  21028. this.targetLine.geometry.dispose();
  21029. this.targetLine.material.dispose();
  21030. }
  21031. update() {
  21032. this.light.updateWorldMatrix( true, false );
  21033. this.light.target.updateWorldMatrix( true, false );
  21034. _v1.setFromMatrixPosition( this.light.matrixWorld );
  21035. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21036. _v3.subVectors( _v2, _v1 );
  21037. this.lightPlane.lookAt( _v2 );
  21038. if ( this.color !== undefined ) {
  21039. this.lightPlane.material.color.set( this.color );
  21040. this.targetLine.material.color.set( this.color );
  21041. } else {
  21042. this.lightPlane.material.color.copy( this.light.color );
  21043. this.targetLine.material.color.copy( this.light.color );
  21044. }
  21045. this.targetLine.lookAt( _v2 );
  21046. this.targetLine.scale.z = _v3.length();
  21047. }
  21048. }
  21049. const _vector = /*@__PURE__*/ new Vector3();
  21050. const _camera = /*@__PURE__*/ new Camera();
  21051. /**
  21052. * - shows frustum, line of sight and up of the camera
  21053. * - suitable for fast updates
  21054. * - based on frustum visualization in lightgl.js shadowmap example
  21055. * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html
  21056. */
  21057. class CameraHelper extends LineSegments {
  21058. constructor( camera ) {
  21059. const geometry = new BufferGeometry();
  21060. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  21061. const vertices = [];
  21062. const colors = [];
  21063. const pointMap = {};
  21064. // near
  21065. addLine( 'n1', 'n2' );
  21066. addLine( 'n2', 'n4' );
  21067. addLine( 'n4', 'n3' );
  21068. addLine( 'n3', 'n1' );
  21069. // far
  21070. addLine( 'f1', 'f2' );
  21071. addLine( 'f2', 'f4' );
  21072. addLine( 'f4', 'f3' );
  21073. addLine( 'f3', 'f1' );
  21074. // sides
  21075. addLine( 'n1', 'f1' );
  21076. addLine( 'n2', 'f2' );
  21077. addLine( 'n3', 'f3' );
  21078. addLine( 'n4', 'f4' );
  21079. // cone
  21080. addLine( 'p', 'n1' );
  21081. addLine( 'p', 'n2' );
  21082. addLine( 'p', 'n3' );
  21083. addLine( 'p', 'n4' );
  21084. // up
  21085. addLine( 'u1', 'u2' );
  21086. addLine( 'u2', 'u3' );
  21087. addLine( 'u3', 'u1' );
  21088. // target
  21089. addLine( 'c', 't' );
  21090. addLine( 'p', 'c' );
  21091. // cross
  21092. addLine( 'cn1', 'cn2' );
  21093. addLine( 'cn3', 'cn4' );
  21094. addLine( 'cf1', 'cf2' );
  21095. addLine( 'cf3', 'cf4' );
  21096. function addLine( a, b ) {
  21097. addPoint( a );
  21098. addPoint( b );
  21099. }
  21100. function addPoint( id ) {
  21101. vertices.push( 0, 0, 0 );
  21102. colors.push( 0, 0, 0 );
  21103. if ( pointMap[ id ] === undefined ) {
  21104. pointMap[ id ] = [];
  21105. }
  21106. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  21107. }
  21108. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21109. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21110. super( geometry, material );
  21111. this.type = 'CameraHelper';
  21112. this.camera = camera;
  21113. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  21114. this.matrix = camera.matrixWorld;
  21115. this.matrixAutoUpdate = false;
  21116. this.pointMap = pointMap;
  21117. this.update();
  21118. // colors
  21119. const colorFrustum = new Color( 0xffaa00 );
  21120. const colorCone = new Color( 0xff0000 );
  21121. const colorUp = new Color( 0x00aaff );
  21122. const colorTarget = new Color( 0xffffff );
  21123. const colorCross = new Color( 0x333333 );
  21124. this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross );
  21125. }
  21126. setColors( frustum, cone, up, target, cross ) {
  21127. const geometry = this.geometry;
  21128. const colorAttribute = geometry.getAttribute( 'color' );
  21129. // near
  21130. colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2
  21131. colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4
  21132. colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3
  21133. colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1
  21134. // far
  21135. colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2
  21136. colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4
  21137. colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3
  21138. colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1
  21139. // sides
  21140. colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1
  21141. colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2
  21142. colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3
  21143. colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4
  21144. // cone
  21145. colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1
  21146. colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2
  21147. colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3
  21148. colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4
  21149. // up
  21150. colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2
  21151. colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3
  21152. colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1
  21153. // target
  21154. colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t
  21155. colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c
  21156. // cross
  21157. colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2
  21158. colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4
  21159. colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2
  21160. colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4
  21161. colorAttribute.needsUpdate = true;
  21162. }
  21163. update() {
  21164. const geometry = this.geometry;
  21165. const pointMap = this.pointMap;
  21166. const w = 1, h = 1;
  21167. // we need just camera projection matrix inverse
  21168. // world matrix must be identity
  21169. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  21170. // center / target
  21171. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  21172. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  21173. // near
  21174. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  21175. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  21176. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  21177. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  21178. // far
  21179. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  21180. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  21181. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  21182. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  21183. // up
  21184. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  21185. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  21186. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  21187. // cross
  21188. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  21189. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  21190. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  21191. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  21192. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  21193. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  21194. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  21195. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  21196. geometry.getAttribute( 'position' ).needsUpdate = true;
  21197. }
  21198. dispose() {
  21199. this.geometry.dispose();
  21200. this.material.dispose();
  21201. }
  21202. }
  21203. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  21204. _vector.set( x, y, z ).unproject( camera );
  21205. const points = pointMap[ point ];
  21206. if ( points !== undefined ) {
  21207. const position = geometry.getAttribute( 'position' );
  21208. for ( let i = 0, l = points.length; i < l; i ++ ) {
  21209. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  21210. }
  21211. }
  21212. }
  21213. const _box = /*@__PURE__*/ new Box3();
  21214. class BoxHelper extends LineSegments {
  21215. constructor( object, color = 0xffff00 ) {
  21216. const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  21217. const positions = new Float32Array( 8 * 3 );
  21218. const geometry = new BufferGeometry();
  21219. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21220. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  21221. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21222. this.object = object;
  21223. this.type = 'BoxHelper';
  21224. this.matrixAutoUpdate = false;
  21225. this.update();
  21226. }
  21227. update( object ) {
  21228. if ( object !== undefined ) {
  21229. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  21230. }
  21231. if ( this.object !== undefined ) {
  21232. _box.setFromObject( this.object );
  21233. }
  21234. if ( _box.isEmpty() ) return;
  21235. const min = _box.min;
  21236. const max = _box.max;
  21237. /*
  21238. 5____4
  21239. 1/___0/|
  21240. | 6__|_7
  21241. 2/___3/
  21242. 0: max.x, max.y, max.z
  21243. 1: min.x, max.y, max.z
  21244. 2: min.x, min.y, max.z
  21245. 3: max.x, min.y, max.z
  21246. 4: max.x, max.y, min.z
  21247. 5: min.x, max.y, min.z
  21248. 6: min.x, min.y, min.z
  21249. 7: max.x, min.y, min.z
  21250. */
  21251. const position = this.geometry.attributes.position;
  21252. const array = position.array;
  21253. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21254. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21255. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21256. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21257. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21258. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21259. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21260. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21261. position.needsUpdate = true;
  21262. this.geometry.computeBoundingSphere();
  21263. }
  21264. setFromObject( object ) {
  21265. this.object = object;
  21266. this.update();
  21267. return this;
  21268. }
  21269. copy( source, recursive ) {
  21270. super.copy( source, recursive );
  21271. this.object = source.object;
  21272. return this;
  21273. }
  21274. dispose() {
  21275. this.geometry.dispose();
  21276. this.material.dispose();
  21277. }
  21278. }
  21279. class Box3Helper extends LineSegments {
  21280. constructor( box, color = 0xffff00 ) {
  21281. const indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  21282. const positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
  21283. const geometry = new BufferGeometry();
  21284. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21285. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21286. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21287. this.box = box;
  21288. this.type = 'Box3Helper';
  21289. this.geometry.computeBoundingSphere();
  21290. }
  21291. updateMatrixWorld( force ) {
  21292. const box = this.box;
  21293. if ( box.isEmpty() ) return;
  21294. box.getCenter( this.position );
  21295. box.getSize( this.scale );
  21296. this.scale.multiplyScalar( 0.5 );
  21297. super.updateMatrixWorld( force );
  21298. }
  21299. dispose() {
  21300. this.geometry.dispose();
  21301. this.material.dispose();
  21302. }
  21303. }
  21304. class PlaneHelper extends Line {
  21305. constructor( plane, size = 1, hex = 0xffff00 ) {
  21306. const color = hex;
  21307. const positions = [ 1, - 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  21308. const geometry = new BufferGeometry();
  21309. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21310. geometry.computeBoundingSphere();
  21311. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21312. this.type = 'PlaneHelper';
  21313. this.plane = plane;
  21314. this.size = size;
  21315. const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  21316. const geometry2 = new BufferGeometry();
  21317. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  21318. geometry2.computeBoundingSphere();
  21319. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  21320. }
  21321. updateMatrixWorld( force ) {
  21322. this.position.set( 0, 0, 0 );
  21323. this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 );
  21324. this.lookAt( this.plane.normal );
  21325. this.translateZ( - this.plane.constant );
  21326. super.updateMatrixWorld( force );
  21327. }
  21328. dispose() {
  21329. this.geometry.dispose();
  21330. this.material.dispose();
  21331. this.children[ 0 ].geometry.dispose();
  21332. this.children[ 0 ].material.dispose();
  21333. }
  21334. }
  21335. const _axis = /*@__PURE__*/ new Vector3();
  21336. let _lineGeometry, _coneGeometry;
  21337. class ArrowHelper extends Object3D {
  21338. // dir is assumed to be normalized
  21339. constructor( dir = new Vector3( 0, 0, 1 ), origin = new Vector3( 0, 0, 0 ), length = 1, color = 0xffff00, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21340. super();
  21341. this.type = 'ArrowHelper';
  21342. if ( _lineGeometry === undefined ) {
  21343. _lineGeometry = new BufferGeometry();
  21344. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  21345. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21346. _coneGeometry.translate( 0, - 0.5, 0 );
  21347. }
  21348. this.position.copy( origin );
  21349. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21350. this.line.matrixAutoUpdate = false;
  21351. this.add( this.line );
  21352. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  21353. this.cone.matrixAutoUpdate = false;
  21354. this.add( this.cone );
  21355. this.setDirection( dir );
  21356. this.setLength( length, headLength, headWidth );
  21357. }
  21358. setDirection( dir ) {
  21359. // dir is assumed to be normalized
  21360. if ( dir.y > 0.99999 ) {
  21361. this.quaternion.set( 0, 0, 0, 1 );
  21362. } else if ( dir.y < - 0.99999 ) {
  21363. this.quaternion.set( 1, 0, 0, 0 );
  21364. } else {
  21365. _axis.set( dir.z, 0, - dir.x ).normalize();
  21366. const radians = Math.acos( dir.y );
  21367. this.quaternion.setFromAxisAngle( _axis, radians );
  21368. }
  21369. }
  21370. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21371. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  21372. this.line.updateMatrix();
  21373. this.cone.scale.set( headWidth, headLength, headWidth );
  21374. this.cone.position.y = length;
  21375. this.cone.updateMatrix();
  21376. }
  21377. setColor( color ) {
  21378. this.line.material.color.set( color );
  21379. this.cone.material.color.set( color );
  21380. }
  21381. copy( source ) {
  21382. super.copy( source, false );
  21383. this.line.copy( source.line );
  21384. this.cone.copy( source.cone );
  21385. return this;
  21386. }
  21387. dispose() {
  21388. this.line.geometry.dispose();
  21389. this.line.material.dispose();
  21390. this.cone.geometry.dispose();
  21391. this.cone.material.dispose();
  21392. }
  21393. }
  21394. class AxesHelper extends LineSegments {
  21395. constructor( size = 1 ) {
  21396. const vertices = [
  21397. 0, 0, 0, size, 0, 0,
  21398. 0, 0, 0, 0, size, 0,
  21399. 0, 0, 0, 0, 0, size
  21400. ];
  21401. const colors = [
  21402. 1, 0, 0, 1, 0.6, 0,
  21403. 0, 1, 0, 0.6, 1, 0,
  21404. 0, 0, 1, 0, 0.6, 1
  21405. ];
  21406. const geometry = new BufferGeometry();
  21407. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21408. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21409. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21410. super( geometry, material );
  21411. this.type = 'AxesHelper';
  21412. }
  21413. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  21414. const color = new Color();
  21415. const array = this.geometry.attributes.color.array;
  21416. color.set( xAxisColor );
  21417. color.toArray( array, 0 );
  21418. color.toArray( array, 3 );
  21419. color.set( yAxisColor );
  21420. color.toArray( array, 6 );
  21421. color.toArray( array, 9 );
  21422. color.set( zAxisColor );
  21423. color.toArray( array, 12 );
  21424. color.toArray( array, 15 );
  21425. this.geometry.attributes.color.needsUpdate = true;
  21426. return this;
  21427. }
  21428. dispose() {
  21429. this.geometry.dispose();
  21430. this.material.dispose();
  21431. }
  21432. }
  21433. class ShapePath {
  21434. constructor() {
  21435. this.type = 'ShapePath';
  21436. this.color = new Color();
  21437. this.subPaths = [];
  21438. this.currentPath = null;
  21439. }
  21440. moveTo( x, y ) {
  21441. this.currentPath = new Path();
  21442. this.subPaths.push( this.currentPath );
  21443. this.currentPath.moveTo( x, y );
  21444. return this;
  21445. }
  21446. lineTo( x, y ) {
  21447. this.currentPath.lineTo( x, y );
  21448. return this;
  21449. }
  21450. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21451. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21452. return this;
  21453. }
  21454. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21455. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21456. return this;
  21457. }
  21458. splineThru( pts ) {
  21459. this.currentPath.splineThru( pts );
  21460. return this;
  21461. }
  21462. toShapes( isCCW ) {
  21463. function toShapesNoHoles( inSubpaths ) {
  21464. const shapes = [];
  21465. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21466. const tmpPath = inSubpaths[ i ];
  21467. const tmpShape = new Shape();
  21468. tmpShape.curves = tmpPath.curves;
  21469. shapes.push( tmpShape );
  21470. }
  21471. return shapes;
  21472. }
  21473. function isPointInsidePolygon( inPt, inPolygon ) {
  21474. const polyLen = inPolygon.length;
  21475. // inPt on polygon contour => immediate success or
  21476. // toggling of inside/outside at every single! intersection point of an edge
  21477. // with the horizontal line through inPt, left of inPt
  21478. // not counting lowerY endpoints of edges and whole edges on that line
  21479. let inside = false;
  21480. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21481. let edgeLowPt = inPolygon[ p ];
  21482. let edgeHighPt = inPolygon[ q ];
  21483. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  21484. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  21485. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21486. // not parallel
  21487. if ( edgeDy < 0 ) {
  21488. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21489. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21490. }
  21491. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21492. if ( inPt.y === edgeLowPt.y ) {
  21493. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21494. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21495. } else {
  21496. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21497. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21498. if ( perpEdge < 0 ) continue;
  21499. inside = ! inside; // true intersection left of inPt
  21500. }
  21501. } else {
  21502. // parallel or collinear
  21503. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21504. // edge lies on the same horizontal line as inPt
  21505. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21506. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21507. // continue;
  21508. }
  21509. }
  21510. return inside;
  21511. }
  21512. const isClockWise = ShapeUtils.isClockWise;
  21513. const subPaths = this.subPaths;
  21514. if ( subPaths.length === 0 ) return [];
  21515. let solid, tmpPath, tmpShape;
  21516. const shapes = [];
  21517. if ( subPaths.length === 1 ) {
  21518. tmpPath = subPaths[ 0 ];
  21519. tmpShape = new Shape();
  21520. tmpShape.curves = tmpPath.curves;
  21521. shapes.push( tmpShape );
  21522. return shapes;
  21523. }
  21524. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21525. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21526. // console.log("Holes first", holesFirst);
  21527. const betterShapeHoles = [];
  21528. const newShapes = [];
  21529. let newShapeHoles = [];
  21530. let mainIdx = 0;
  21531. let tmpPoints;
  21532. newShapes[ mainIdx ] = undefined;
  21533. newShapeHoles[ mainIdx ] = [];
  21534. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  21535. tmpPath = subPaths[ i ];
  21536. tmpPoints = tmpPath.getPoints();
  21537. solid = isClockWise( tmpPoints );
  21538. solid = isCCW ? ! solid : solid;
  21539. if ( solid ) {
  21540. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21541. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21542. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21543. if ( holesFirst ) mainIdx ++;
  21544. newShapeHoles[ mainIdx ] = [];
  21545. //console.log('cw', i);
  21546. } else {
  21547. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21548. //console.log('ccw', i);
  21549. }
  21550. }
  21551. // only Holes? -> probably all Shapes with wrong orientation
  21552. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21553. if ( newShapes.length > 1 ) {
  21554. let ambiguous = false;
  21555. let toChange = 0;
  21556. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21557. betterShapeHoles[ sIdx ] = [];
  21558. }
  21559. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21560. const sho = newShapeHoles[ sIdx ];
  21561. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21562. const ho = sho[ hIdx ];
  21563. let hole_unassigned = true;
  21564. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21565. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21566. if ( sIdx !== s2Idx ) toChange ++;
  21567. if ( hole_unassigned ) {
  21568. hole_unassigned = false;
  21569. betterShapeHoles[ s2Idx ].push( ho );
  21570. } else {
  21571. ambiguous = true;
  21572. }
  21573. }
  21574. }
  21575. if ( hole_unassigned ) {
  21576. betterShapeHoles[ sIdx ].push( ho );
  21577. }
  21578. }
  21579. }
  21580. if ( toChange > 0 && ambiguous === false ) {
  21581. newShapeHoles = betterShapeHoles;
  21582. }
  21583. }
  21584. let tmpHoles;
  21585. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  21586. tmpShape = newShapes[ i ].s;
  21587. shapes.push( tmpShape );
  21588. tmpHoles = newShapeHoles[ i ];
  21589. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21590. tmpShape.holes.push( tmpHoles[ j ].h );
  21591. }
  21592. }
  21593. //console.log("shape", shapes);
  21594. return shapes;
  21595. }
  21596. }
  21597. class Controls extends EventDispatcher {
  21598. constructor( object, domElement = null ) {
  21599. super();
  21600. this.object = object;
  21601. this.domElement = domElement;
  21602. this.enabled = true;
  21603. this.state = - 1;
  21604. this.keys = {};
  21605. this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
  21606. this.touches = { ONE: null, TWO: null };
  21607. }
  21608. connect() {}
  21609. disconnect() {}
  21610. dispose() {}
  21611. update( /* delta */ ) {}
  21612. }
  21613. function contain( texture, aspect ) {
  21614. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21615. if ( imageAspect > aspect ) {
  21616. texture.repeat.x = 1;
  21617. texture.repeat.y = imageAspect / aspect;
  21618. texture.offset.x = 0;
  21619. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21620. } else {
  21621. texture.repeat.x = aspect / imageAspect;
  21622. texture.repeat.y = 1;
  21623. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21624. texture.offset.y = 0;
  21625. }
  21626. return texture;
  21627. }
  21628. function cover( texture, aspect ) {
  21629. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21630. if ( imageAspect > aspect ) {
  21631. texture.repeat.x = aspect / imageAspect;
  21632. texture.repeat.y = 1;
  21633. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21634. texture.offset.y = 0;
  21635. } else {
  21636. texture.repeat.x = 1;
  21637. texture.repeat.y = imageAspect / aspect;
  21638. texture.offset.x = 0;
  21639. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21640. }
  21641. return texture;
  21642. }
  21643. function fill( texture ) {
  21644. texture.repeat.x = 1;
  21645. texture.repeat.y = 1;
  21646. texture.offset.x = 0;
  21647. texture.offset.y = 0;
  21648. return texture;
  21649. }
  21650. /**
  21651. * Given the width, height, format, and type of a texture. Determines how many
  21652. * bytes must be used to represent the texture.
  21653. */
  21654. function getByteLength( width, height, format, type ) {
  21655. const typeByteLength = getTextureTypeByteLength( type );
  21656. switch ( format ) {
  21657. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
  21658. case AlphaFormat:
  21659. return width * height;
  21660. case LuminanceFormat:
  21661. return width * height;
  21662. case LuminanceAlphaFormat:
  21663. return width * height * 2;
  21664. case RedFormat:
  21665. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21666. case RedIntegerFormat:
  21667. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21668. case RGFormat:
  21669. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21670. case RGIntegerFormat:
  21671. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21672. case RGBFormat:
  21673. return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21674. case RGBAFormat:
  21675. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21676. case RGBAIntegerFormat:
  21677. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21678. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
  21679. case RGB_S3TC_DXT1_Format:
  21680. case RGBA_S3TC_DXT1_Format:
  21681. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21682. case RGBA_S3TC_DXT3_Format:
  21683. case RGBA_S3TC_DXT5_Format:
  21684. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21685. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
  21686. case RGB_PVRTC_2BPPV1_Format:
  21687. case RGBA_PVRTC_2BPPV1_Format:
  21688. return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
  21689. case RGB_PVRTC_4BPPV1_Format:
  21690. case RGBA_PVRTC_4BPPV1_Format:
  21691. return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
  21692. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
  21693. case RGB_ETC1_Format:
  21694. case RGB_ETC2_Format:
  21695. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21696. case RGBA_ETC2_EAC_Format:
  21697. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21698. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
  21699. case RGBA_ASTC_4x4_Format:
  21700. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21701. case RGBA_ASTC_5x4_Format:
  21702. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21703. case RGBA_ASTC_5x5_Format:
  21704. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21705. case RGBA_ASTC_6x5_Format:
  21706. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21707. case RGBA_ASTC_6x6_Format:
  21708. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21709. case RGBA_ASTC_8x5_Format:
  21710. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21711. case RGBA_ASTC_8x6_Format:
  21712. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21713. case RGBA_ASTC_8x8_Format:
  21714. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21715. case RGBA_ASTC_10x5_Format:
  21716. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21717. case RGBA_ASTC_10x6_Format:
  21718. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21719. case RGBA_ASTC_10x8_Format:
  21720. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21721. case RGBA_ASTC_10x10_Format:
  21722. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21723. case RGBA_ASTC_12x10_Format:
  21724. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21725. case RGBA_ASTC_12x12_Format:
  21726. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
  21727. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
  21728. case RGBA_BPTC_Format:
  21729. case RGB_BPTC_SIGNED_Format:
  21730. case RGB_BPTC_UNSIGNED_Format:
  21731. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21732. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
  21733. case RED_RGTC1_Format:
  21734. case SIGNED_RED_RGTC1_Format:
  21735. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
  21736. case RED_GREEN_RGTC2_Format:
  21737. case SIGNED_RED_GREEN_RGTC2_Format:
  21738. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21739. }
  21740. throw new Error(
  21741. `Unable to determine texture byte length for ${format} format.`,
  21742. );
  21743. }
  21744. function getTextureTypeByteLength( type ) {
  21745. switch ( type ) {
  21746. case UnsignedByteType:
  21747. case ByteType:
  21748. return { byteLength: 1, components: 1 };
  21749. case UnsignedShortType:
  21750. case ShortType:
  21751. case HalfFloatType:
  21752. return { byteLength: 2, components: 1 };
  21753. case UnsignedShort4444Type:
  21754. case UnsignedShort5551Type:
  21755. return { byteLength: 2, components: 4 };
  21756. case UnsignedIntType:
  21757. case IntType:
  21758. case FloatType:
  21759. return { byteLength: 4, components: 1 };
  21760. case UnsignedInt5999Type:
  21761. return { byteLength: 4, components: 3 };
  21762. }
  21763. throw new Error( `Unknown texture type ${type}.` );
  21764. }
  21765. const TextureUtils = {
  21766. contain,
  21767. cover,
  21768. fill,
  21769. getByteLength
  21770. };
  21771. class WebGLMultipleRenderTargets extends WebGLRenderTarget { // @deprecated, r162
  21772. constructor( width = 1, height = 1, count = 1, options = {} ) {
  21773. console.warn( 'THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.' );
  21774. super( width, height, { ...options, count } );
  21775. this.isWebGLMultipleRenderTargets = true;
  21776. }
  21777. get texture() {
  21778. return this.textures;
  21779. }
  21780. }
  21781. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  21782. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  21783. revision: REVISION,
  21784. } } ) );
  21785. }
  21786. if ( typeof window !== 'undefined' ) {
  21787. if ( window.__THREE__ ) {
  21788. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  21789. } else {
  21790. window.__THREE__ = REVISION;
  21791. }
  21792. }
  21793. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BackSide, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, Color, ColorKeyframeTrack, ColorManagement, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, ConstantAlphaFactor, ConstantColorFactor, Controls, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FramebufferTexture, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, NormalAnimationBlendMode, NormalBlending, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, Path, PerspectiveCamera, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RAD2DEG, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RedFormat, RedIntegerFormat, ReinhardToneMapping, RenderTarget, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingGeometry, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, ShaderMaterial, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronGeometry, Texture, TextureLoader, TextureUtils, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLMultipleRenderTargets, WebGLRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, arrayNeedsUint32, cloneUniforms, createCanvasElement, createElementNS, getByteLength, getUnlitUniformColorSpace, mergeUniforms, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce };
粤ICP备19079148号