three.module.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094
  1. /**
  2. * @license
  3. * Copyright 2010-2021 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '133dev';
  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 FlatShading = 1;
  21. const SmoothShading = 2;
  22. const NoBlending = 0;
  23. const NormalBlending = 1;
  24. const AdditiveBlending = 2;
  25. const SubtractiveBlending = 3;
  26. const MultiplyBlending = 4;
  27. const CustomBlending = 5;
  28. const AddEquation = 100;
  29. const SubtractEquation = 101;
  30. const ReverseSubtractEquation = 102;
  31. const MinEquation = 103;
  32. const MaxEquation = 104;
  33. const ZeroFactor = 200;
  34. const OneFactor = 201;
  35. const SrcColorFactor = 202;
  36. const OneMinusSrcColorFactor = 203;
  37. const SrcAlphaFactor = 204;
  38. const OneMinusSrcAlphaFactor = 205;
  39. const DstAlphaFactor = 206;
  40. const OneMinusDstAlphaFactor = 207;
  41. const DstColorFactor = 208;
  42. const OneMinusDstColorFactor = 209;
  43. const SrcAlphaSaturateFactor = 210;
  44. const NeverDepth = 0;
  45. const AlwaysDepth = 1;
  46. const LessDepth = 2;
  47. const LessEqualDepth = 3;
  48. const EqualDepth = 4;
  49. const GreaterEqualDepth = 5;
  50. const GreaterDepth = 6;
  51. const NotEqualDepth = 7;
  52. const MultiplyOperation = 0;
  53. const MixOperation = 1;
  54. const AddOperation = 2;
  55. const NoToneMapping = 0;
  56. const LinearToneMapping = 1;
  57. const ReinhardToneMapping = 2;
  58. const CineonToneMapping = 3;
  59. const ACESFilmicToneMapping = 4;
  60. const CustomToneMapping = 5;
  61. const UVMapping = 300;
  62. const CubeReflectionMapping = 301;
  63. const CubeRefractionMapping = 302;
  64. const EquirectangularReflectionMapping = 303;
  65. const EquirectangularRefractionMapping = 304;
  66. const CubeUVReflectionMapping = 306;
  67. const CubeUVRefractionMapping = 307;
  68. const RepeatWrapping = 1000;
  69. const ClampToEdgeWrapping = 1001;
  70. const MirroredRepeatWrapping = 1002;
  71. const NearestFilter = 1003;
  72. const NearestMipmapNearestFilter = 1004;
  73. const NearestMipMapNearestFilter = 1004;
  74. const NearestMipmapLinearFilter = 1005;
  75. const NearestMipMapLinearFilter = 1005;
  76. const LinearFilter = 1006;
  77. const LinearMipmapNearestFilter = 1007;
  78. const LinearMipMapNearestFilter = 1007;
  79. const LinearMipmapLinearFilter = 1008;
  80. const LinearMipMapLinearFilter = 1008;
  81. const UnsignedByteType = 1009;
  82. const ByteType = 1010;
  83. const ShortType = 1011;
  84. const UnsignedShortType = 1012;
  85. const IntType = 1013;
  86. const UnsignedIntType = 1014;
  87. const FloatType = 1015;
  88. const HalfFloatType = 1016;
  89. const UnsignedShort4444Type = 1017;
  90. const UnsignedShort5551Type = 1018;
  91. const UnsignedShort565Type = 1019;
  92. const UnsignedInt248Type = 1020;
  93. const AlphaFormat = 1021;
  94. const RGBFormat = 1022;
  95. const RGBAFormat = 1023;
  96. const LuminanceFormat = 1024;
  97. const LuminanceAlphaFormat = 1025;
  98. const RGBEFormat = RGBAFormat;
  99. const DepthFormat = 1026;
  100. const DepthStencilFormat = 1027;
  101. const RedFormat = 1028;
  102. const RedIntegerFormat = 1029;
  103. const RGFormat = 1030;
  104. const RGIntegerFormat = 1031;
  105. const RGBIntegerFormat = 1032;
  106. const RGBAIntegerFormat = 1033;
  107. const RGB_S3TC_DXT1_Format = 33776;
  108. const RGBA_S3TC_DXT1_Format = 33777;
  109. const RGBA_S3TC_DXT3_Format = 33778;
  110. const RGBA_S3TC_DXT5_Format = 33779;
  111. const RGB_PVRTC_4BPPV1_Format = 35840;
  112. const RGB_PVRTC_2BPPV1_Format = 35841;
  113. const RGBA_PVRTC_4BPPV1_Format = 35842;
  114. const RGBA_PVRTC_2BPPV1_Format = 35843;
  115. const RGB_ETC1_Format = 36196;
  116. const RGB_ETC2_Format = 37492;
  117. const RGBA_ETC2_EAC_Format = 37496;
  118. const RGBA_ASTC_4x4_Format = 37808;
  119. const RGBA_ASTC_5x4_Format = 37809;
  120. const RGBA_ASTC_5x5_Format = 37810;
  121. const RGBA_ASTC_6x5_Format = 37811;
  122. const RGBA_ASTC_6x6_Format = 37812;
  123. const RGBA_ASTC_8x5_Format = 37813;
  124. const RGBA_ASTC_8x6_Format = 37814;
  125. const RGBA_ASTC_8x8_Format = 37815;
  126. const RGBA_ASTC_10x5_Format = 37816;
  127. const RGBA_ASTC_10x6_Format = 37817;
  128. const RGBA_ASTC_10x8_Format = 37818;
  129. const RGBA_ASTC_10x10_Format = 37819;
  130. const RGBA_ASTC_12x10_Format = 37820;
  131. const RGBA_ASTC_12x12_Format = 37821;
  132. const RGBA_BPTC_Format = 36492;
  133. const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  134. const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  135. const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  136. const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  137. const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  138. const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  139. const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  140. const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  141. const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  142. const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  143. const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  144. const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  145. const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  146. const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  147. const LoopOnce = 2200;
  148. const LoopRepeat = 2201;
  149. const LoopPingPong = 2202;
  150. const InterpolateDiscrete = 2300;
  151. const InterpolateLinear = 2301;
  152. const InterpolateSmooth = 2302;
  153. const ZeroCurvatureEnding = 2400;
  154. const ZeroSlopeEnding = 2401;
  155. const WrapAroundEnding = 2402;
  156. const NormalAnimationBlendMode = 2500;
  157. const AdditiveAnimationBlendMode = 2501;
  158. const TrianglesDrawMode = 0;
  159. const TriangleStripDrawMode = 1;
  160. const TriangleFanDrawMode = 2;
  161. const LinearEncoding = 3000;
  162. const sRGBEncoding = 3001;
  163. const GammaEncoding = 3007;
  164. const RGBEEncoding = 3002;
  165. const LogLuvEncoding = 3003;
  166. const RGBM7Encoding = 3004;
  167. const RGBM16Encoding = 3005;
  168. const RGBDEncoding = 3006;
  169. const BasicDepthPacking = 3200;
  170. const RGBADepthPacking = 3201;
  171. const TangentSpaceNormalMap = 0;
  172. const ObjectSpaceNormalMap = 1;
  173. const ZeroStencilOp = 0;
  174. const KeepStencilOp = 7680;
  175. const ReplaceStencilOp = 7681;
  176. const IncrementStencilOp = 7682;
  177. const DecrementStencilOp = 7683;
  178. const IncrementWrapStencilOp = 34055;
  179. const DecrementWrapStencilOp = 34056;
  180. const InvertStencilOp = 5386;
  181. const NeverStencilFunc = 512;
  182. const LessStencilFunc = 513;
  183. const EqualStencilFunc = 514;
  184. const LessEqualStencilFunc = 515;
  185. const GreaterStencilFunc = 516;
  186. const NotEqualStencilFunc = 517;
  187. const GreaterEqualStencilFunc = 518;
  188. const AlwaysStencilFunc = 519;
  189. const StaticDrawUsage = 35044;
  190. const DynamicDrawUsage = 35048;
  191. const StreamDrawUsage = 35040;
  192. const StaticReadUsage = 35045;
  193. const DynamicReadUsage = 35049;
  194. const StreamReadUsage = 35041;
  195. const StaticCopyUsage = 35046;
  196. const DynamicCopyUsage = 35050;
  197. const StreamCopyUsage = 35042;
  198. const GLSL1 = '100';
  199. const GLSL3 = '300 es';
  200. /**
  201. * https://github.com/mrdoob/eventdispatcher.js/
  202. */
  203. class EventDispatcher {
  204. addEventListener( type, listener ) {
  205. if ( this._listeners === undefined ) this._listeners = {};
  206. const listeners = this._listeners;
  207. if ( listeners[ type ] === undefined ) {
  208. listeners[ type ] = [];
  209. }
  210. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  211. listeners[ type ].push( listener );
  212. }
  213. }
  214. hasEventListener( type, listener ) {
  215. if ( this._listeners === undefined ) return false;
  216. const listeners = this._listeners;
  217. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  218. }
  219. removeEventListener( type, listener ) {
  220. if ( this._listeners === undefined ) return;
  221. const listeners = this._listeners;
  222. const listenerArray = listeners[ type ];
  223. if ( listenerArray !== undefined ) {
  224. const index = listenerArray.indexOf( listener );
  225. if ( index !== - 1 ) {
  226. listenerArray.splice( index, 1 );
  227. }
  228. }
  229. }
  230. dispatchEvent( event ) {
  231. if ( this._listeners === undefined ) return;
  232. const listeners = this._listeners;
  233. const listenerArray = listeners[ event.type ];
  234. if ( listenerArray !== undefined ) {
  235. event.target = this;
  236. // Make a copy, in case listeners are removed while iterating.
  237. const array = listenerArray.slice( 0 );
  238. for ( let i = 0, l = array.length; i < l; i ++ ) {
  239. array[ i ].call( this, event );
  240. }
  241. event.target = null;
  242. }
  243. }
  244. }
  245. const _lut = [];
  246. for ( let i = 0; i < 256; i ++ ) {
  247. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  248. }
  249. let _seed = 1234567;
  250. const DEG2RAD = Math.PI / 180;
  251. const RAD2DEG = 180 / Math.PI;
  252. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  253. function generateUUID() {
  254. const d0 = Math.random() * 0xffffffff | 0;
  255. const d1 = Math.random() * 0xffffffff | 0;
  256. const d2 = Math.random() * 0xffffffff | 0;
  257. const d3 = Math.random() * 0xffffffff | 0;
  258. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  259. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  260. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  261. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  262. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  263. return uuid.toUpperCase();
  264. }
  265. function clamp( value, min, max ) {
  266. return Math.max( min, Math.min( max, value ) );
  267. }
  268. // compute euclidian modulo of m % n
  269. // https://en.wikipedia.org/wiki/Modulo_operation
  270. function euclideanModulo( n, m ) {
  271. return ( ( n % m ) + m ) % m;
  272. }
  273. // Linear mapping from range <a1, a2> to range <b1, b2>
  274. function mapLinear( x, a1, a2, b1, b2 ) {
  275. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  276. }
  277. // https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/
  278. function inverseLerp( x, y, value ) {
  279. if ( x !== y ) {
  280. return ( value - x ) / ( y - x );
  281. } else {
  282. return 0;
  283. }
  284. }
  285. // https://en.wikipedia.org/wiki/Linear_interpolation
  286. function lerp( x, y, t ) {
  287. return ( 1 - t ) * x + t * y;
  288. }
  289. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  290. function damp( x, y, lambda, dt ) {
  291. return lerp( x, y, 1 - Math.exp( - lambda * dt ) );
  292. }
  293. // https://www.desmos.com/calculator/vcsjnyz7x4
  294. function pingpong( x, length = 1 ) {
  295. return length - Math.abs( euclideanModulo( x, length * 2 ) - length );
  296. }
  297. // http://en.wikipedia.org/wiki/Smoothstep
  298. function smoothstep( x, min, max ) {
  299. if ( x <= min ) return 0;
  300. if ( x >= max ) return 1;
  301. x = ( x - min ) / ( max - min );
  302. return x * x * ( 3 - 2 * x );
  303. }
  304. function smootherstep( x, min, max ) {
  305. if ( x <= min ) return 0;
  306. if ( x >= max ) return 1;
  307. x = ( x - min ) / ( max - min );
  308. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  309. }
  310. // Random integer from <low, high> interval
  311. function randInt( low, high ) {
  312. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  313. }
  314. // Random float from <low, high> interval
  315. function randFloat( low, high ) {
  316. return low + Math.random() * ( high - low );
  317. }
  318. // Random float from <-range/2, range/2> interval
  319. function randFloatSpread( range ) {
  320. return range * ( 0.5 - Math.random() );
  321. }
  322. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  323. function seededRandom( s ) {
  324. if ( s !== undefined ) _seed = s % 2147483647;
  325. // Park-Miller algorithm
  326. _seed = _seed * 16807 % 2147483647;
  327. return ( _seed - 1 ) / 2147483646;
  328. }
  329. function degToRad( degrees ) {
  330. return degrees * DEG2RAD;
  331. }
  332. function radToDeg( radians ) {
  333. return radians * RAD2DEG;
  334. }
  335. function isPowerOfTwo( value ) {
  336. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  337. }
  338. function ceilPowerOfTwo( value ) {
  339. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  340. }
  341. function floorPowerOfTwo( value ) {
  342. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  343. }
  344. function setQuaternionFromProperEuler( q, a, b, c, order ) {
  345. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  346. // rotations are applied to the axes in the order specified by 'order'
  347. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  348. // angles are in radians
  349. const cos = Math.cos;
  350. const sin = Math.sin;
  351. const c2 = cos( b / 2 );
  352. const s2 = sin( b / 2 );
  353. const c13 = cos( ( a + c ) / 2 );
  354. const s13 = sin( ( a + c ) / 2 );
  355. const c1_3 = cos( ( a - c ) / 2 );
  356. const s1_3 = sin( ( a - c ) / 2 );
  357. const c3_1 = cos( ( c - a ) / 2 );
  358. const s3_1 = sin( ( c - a ) / 2 );
  359. switch ( order ) {
  360. case 'XYX':
  361. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  362. break;
  363. case 'YZY':
  364. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  365. break;
  366. case 'ZXZ':
  367. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  368. break;
  369. case 'XZX':
  370. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  371. break;
  372. case 'YXY':
  373. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  374. break;
  375. case 'ZYZ':
  376. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  377. break;
  378. default:
  379. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  380. }
  381. }
  382. var MathUtils = /*#__PURE__*/Object.freeze({
  383. __proto__: null,
  384. DEG2RAD: DEG2RAD,
  385. RAD2DEG: RAD2DEG,
  386. generateUUID: generateUUID,
  387. clamp: clamp,
  388. euclideanModulo: euclideanModulo,
  389. mapLinear: mapLinear,
  390. inverseLerp: inverseLerp,
  391. lerp: lerp,
  392. damp: damp,
  393. pingpong: pingpong,
  394. smoothstep: smoothstep,
  395. smootherstep: smootherstep,
  396. randInt: randInt,
  397. randFloat: randFloat,
  398. randFloatSpread: randFloatSpread,
  399. seededRandom: seededRandom,
  400. degToRad: degToRad,
  401. radToDeg: radToDeg,
  402. isPowerOfTwo: isPowerOfTwo,
  403. ceilPowerOfTwo: ceilPowerOfTwo,
  404. floorPowerOfTwo: floorPowerOfTwo,
  405. setQuaternionFromProperEuler: setQuaternionFromProperEuler
  406. });
  407. class Vector2 {
  408. constructor( x = 0, y = 0 ) {
  409. this.x = x;
  410. this.y = y;
  411. }
  412. get width() {
  413. return this.x;
  414. }
  415. set width( value ) {
  416. this.x = value;
  417. }
  418. get height() {
  419. return this.y;
  420. }
  421. set height( value ) {
  422. this.y = value;
  423. }
  424. set( x, y ) {
  425. this.x = x;
  426. this.y = y;
  427. return this;
  428. }
  429. setScalar( scalar ) {
  430. this.x = scalar;
  431. this.y = scalar;
  432. return this;
  433. }
  434. setX( x ) {
  435. this.x = x;
  436. return this;
  437. }
  438. setY( y ) {
  439. this.y = y;
  440. return this;
  441. }
  442. setComponent( index, value ) {
  443. switch ( index ) {
  444. case 0: this.x = value; break;
  445. case 1: this.y = value; break;
  446. default: throw new Error( 'index is out of range: ' + index );
  447. }
  448. return this;
  449. }
  450. getComponent( index ) {
  451. switch ( index ) {
  452. case 0: return this.x;
  453. case 1: return this.y;
  454. default: throw new Error( 'index is out of range: ' + index );
  455. }
  456. }
  457. clone() {
  458. return new this.constructor( this.x, this.y );
  459. }
  460. copy( v ) {
  461. this.x = v.x;
  462. this.y = v.y;
  463. return this;
  464. }
  465. add( v, w ) {
  466. if ( w !== undefined ) {
  467. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  468. return this.addVectors( v, w );
  469. }
  470. this.x += v.x;
  471. this.y += v.y;
  472. return this;
  473. }
  474. addScalar( s ) {
  475. this.x += s;
  476. this.y += s;
  477. return this;
  478. }
  479. addVectors( a, b ) {
  480. this.x = a.x + b.x;
  481. this.y = a.y + b.y;
  482. return this;
  483. }
  484. addScaledVector( v, s ) {
  485. this.x += v.x * s;
  486. this.y += v.y * s;
  487. return this;
  488. }
  489. sub( v, w ) {
  490. if ( w !== undefined ) {
  491. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  492. return this.subVectors( v, w );
  493. }
  494. this.x -= v.x;
  495. this.y -= v.y;
  496. return this;
  497. }
  498. subScalar( s ) {
  499. this.x -= s;
  500. this.y -= s;
  501. return this;
  502. }
  503. subVectors( a, b ) {
  504. this.x = a.x - b.x;
  505. this.y = a.y - b.y;
  506. return this;
  507. }
  508. multiply( v ) {
  509. this.x *= v.x;
  510. this.y *= v.y;
  511. return this;
  512. }
  513. multiplyScalar( scalar ) {
  514. this.x *= scalar;
  515. this.y *= scalar;
  516. return this;
  517. }
  518. divide( v ) {
  519. this.x /= v.x;
  520. this.y /= v.y;
  521. return this;
  522. }
  523. divideScalar( scalar ) {
  524. return this.multiplyScalar( 1 / scalar );
  525. }
  526. applyMatrix3( m ) {
  527. const x = this.x, y = this.y;
  528. const e = m.elements;
  529. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  530. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  531. return this;
  532. }
  533. min( v ) {
  534. this.x = Math.min( this.x, v.x );
  535. this.y = Math.min( this.y, v.y );
  536. return this;
  537. }
  538. max( v ) {
  539. this.x = Math.max( this.x, v.x );
  540. this.y = Math.max( this.y, v.y );
  541. return this;
  542. }
  543. clamp( min, max ) {
  544. // assumes min < max, componentwise
  545. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  546. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  547. return this;
  548. }
  549. clampScalar( minVal, maxVal ) {
  550. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  551. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  552. return this;
  553. }
  554. clampLength( min, max ) {
  555. const length = this.length();
  556. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  557. }
  558. floor() {
  559. this.x = Math.floor( this.x );
  560. this.y = Math.floor( this.y );
  561. return this;
  562. }
  563. ceil() {
  564. this.x = Math.ceil( this.x );
  565. this.y = Math.ceil( this.y );
  566. return this;
  567. }
  568. round() {
  569. this.x = Math.round( this.x );
  570. this.y = Math.round( this.y );
  571. return this;
  572. }
  573. roundToZero() {
  574. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  575. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  576. return this;
  577. }
  578. negate() {
  579. this.x = - this.x;
  580. this.y = - this.y;
  581. return this;
  582. }
  583. dot( v ) {
  584. return this.x * v.x + this.y * v.y;
  585. }
  586. cross( v ) {
  587. return this.x * v.y - this.y * v.x;
  588. }
  589. lengthSq() {
  590. return this.x * this.x + this.y * this.y;
  591. }
  592. length() {
  593. return Math.sqrt( this.x * this.x + this.y * this.y );
  594. }
  595. manhattanLength() {
  596. return Math.abs( this.x ) + Math.abs( this.y );
  597. }
  598. normalize() {
  599. return this.divideScalar( this.length() || 1 );
  600. }
  601. angle() {
  602. // computes the angle in radians with respect to the positive x-axis
  603. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  604. return angle;
  605. }
  606. distanceTo( v ) {
  607. return Math.sqrt( this.distanceToSquared( v ) );
  608. }
  609. distanceToSquared( v ) {
  610. const dx = this.x - v.x, dy = this.y - v.y;
  611. return dx * dx + dy * dy;
  612. }
  613. manhattanDistanceTo( v ) {
  614. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  615. }
  616. setLength( length ) {
  617. return this.normalize().multiplyScalar( length );
  618. }
  619. lerp( v, alpha ) {
  620. this.x += ( v.x - this.x ) * alpha;
  621. this.y += ( v.y - this.y ) * alpha;
  622. return this;
  623. }
  624. lerpVectors( v1, v2, alpha ) {
  625. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  626. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  627. return this;
  628. }
  629. equals( v ) {
  630. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  631. }
  632. fromArray( array, offset = 0 ) {
  633. this.x = array[ offset ];
  634. this.y = array[ offset + 1 ];
  635. return this;
  636. }
  637. toArray( array = [], offset = 0 ) {
  638. array[ offset ] = this.x;
  639. array[ offset + 1 ] = this.y;
  640. return array;
  641. }
  642. fromBufferAttribute( attribute, index, offset ) {
  643. if ( offset !== undefined ) {
  644. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  645. }
  646. this.x = attribute.getX( index );
  647. this.y = attribute.getY( index );
  648. return this;
  649. }
  650. rotateAround( center, angle ) {
  651. const c = Math.cos( angle ), s = Math.sin( angle );
  652. const x = this.x - center.x;
  653. const y = this.y - center.y;
  654. this.x = x * c - y * s + center.x;
  655. this.y = x * s + y * c + center.y;
  656. return this;
  657. }
  658. random() {
  659. this.x = Math.random();
  660. this.y = Math.random();
  661. return this;
  662. }
  663. }
  664. Vector2.prototype.isVector2 = true;
  665. class Matrix3 {
  666. constructor() {
  667. this.elements = [
  668. 1, 0, 0,
  669. 0, 1, 0,
  670. 0, 0, 1
  671. ];
  672. if ( arguments.length > 0 ) {
  673. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  674. }
  675. }
  676. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  677. const te = this.elements;
  678. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  679. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  680. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  681. return this;
  682. }
  683. identity() {
  684. this.set(
  685. 1, 0, 0,
  686. 0, 1, 0,
  687. 0, 0, 1
  688. );
  689. return this;
  690. }
  691. copy( m ) {
  692. const te = this.elements;
  693. const me = m.elements;
  694. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  695. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  696. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  697. return this;
  698. }
  699. extractBasis( xAxis, yAxis, zAxis ) {
  700. xAxis.setFromMatrix3Column( this, 0 );
  701. yAxis.setFromMatrix3Column( this, 1 );
  702. zAxis.setFromMatrix3Column( this, 2 );
  703. return this;
  704. }
  705. setFromMatrix4( m ) {
  706. const me = m.elements;
  707. this.set(
  708. me[ 0 ], me[ 4 ], me[ 8 ],
  709. me[ 1 ], me[ 5 ], me[ 9 ],
  710. me[ 2 ], me[ 6 ], me[ 10 ]
  711. );
  712. return this;
  713. }
  714. multiply( m ) {
  715. return this.multiplyMatrices( this, m );
  716. }
  717. premultiply( m ) {
  718. return this.multiplyMatrices( m, this );
  719. }
  720. multiplyMatrices( a, b ) {
  721. const ae = a.elements;
  722. const be = b.elements;
  723. const te = this.elements;
  724. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  725. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  726. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  727. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  728. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  729. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  730. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  731. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  732. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  733. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  734. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  735. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  736. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  737. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  738. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  739. return this;
  740. }
  741. multiplyScalar( s ) {
  742. const te = this.elements;
  743. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  744. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  745. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  746. return this;
  747. }
  748. determinant() {
  749. const te = this.elements;
  750. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  751. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  752. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  753. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  754. }
  755. invert() {
  756. const te = this.elements,
  757. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  758. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  759. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  760. t11 = n33 * n22 - n32 * n23,
  761. t12 = n32 * n13 - n33 * n12,
  762. t13 = n23 * n12 - n22 * n13,
  763. det = n11 * t11 + n21 * t12 + n31 * t13;
  764. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  765. const detInv = 1 / det;
  766. te[ 0 ] = t11 * detInv;
  767. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  768. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  769. te[ 3 ] = t12 * detInv;
  770. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  771. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  772. te[ 6 ] = t13 * detInv;
  773. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  774. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  775. return this;
  776. }
  777. transpose() {
  778. let tmp;
  779. const m = this.elements;
  780. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  781. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  782. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  783. return this;
  784. }
  785. getNormalMatrix( matrix4 ) {
  786. return this.setFromMatrix4( matrix4 ).invert().transpose();
  787. }
  788. transposeIntoArray( r ) {
  789. const m = this.elements;
  790. r[ 0 ] = m[ 0 ];
  791. r[ 1 ] = m[ 3 ];
  792. r[ 2 ] = m[ 6 ];
  793. r[ 3 ] = m[ 1 ];
  794. r[ 4 ] = m[ 4 ];
  795. r[ 5 ] = m[ 7 ];
  796. r[ 6 ] = m[ 2 ];
  797. r[ 7 ] = m[ 5 ];
  798. r[ 8 ] = m[ 8 ];
  799. return this;
  800. }
  801. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  802. const c = Math.cos( rotation );
  803. const s = Math.sin( rotation );
  804. this.set(
  805. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  806. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  807. 0, 0, 1
  808. );
  809. return this;
  810. }
  811. scale( sx, sy ) {
  812. const te = this.elements;
  813. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  814. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  815. return this;
  816. }
  817. rotate( theta ) {
  818. const c = Math.cos( theta );
  819. const s = Math.sin( theta );
  820. const te = this.elements;
  821. const a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  822. const a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  823. te[ 0 ] = c * a11 + s * a21;
  824. te[ 3 ] = c * a12 + s * a22;
  825. te[ 6 ] = c * a13 + s * a23;
  826. te[ 1 ] = - s * a11 + c * a21;
  827. te[ 4 ] = - s * a12 + c * a22;
  828. te[ 7 ] = - s * a13 + c * a23;
  829. return this;
  830. }
  831. translate( tx, ty ) {
  832. const te = this.elements;
  833. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  834. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  835. return this;
  836. }
  837. equals( matrix ) {
  838. const te = this.elements;
  839. const me = matrix.elements;
  840. for ( let i = 0; i < 9; i ++ ) {
  841. if ( te[ i ] !== me[ i ] ) return false;
  842. }
  843. return true;
  844. }
  845. fromArray( array, offset = 0 ) {
  846. for ( let i = 0; i < 9; i ++ ) {
  847. this.elements[ i ] = array[ i + offset ];
  848. }
  849. return this;
  850. }
  851. toArray( array = [], offset = 0 ) {
  852. const te = this.elements;
  853. array[ offset ] = te[ 0 ];
  854. array[ offset + 1 ] = te[ 1 ];
  855. array[ offset + 2 ] = te[ 2 ];
  856. array[ offset + 3 ] = te[ 3 ];
  857. array[ offset + 4 ] = te[ 4 ];
  858. array[ offset + 5 ] = te[ 5 ];
  859. array[ offset + 6 ] = te[ 6 ];
  860. array[ offset + 7 ] = te[ 7 ];
  861. array[ offset + 8 ] = te[ 8 ];
  862. return array;
  863. }
  864. clone() {
  865. return new this.constructor().fromArray( this.elements );
  866. }
  867. }
  868. Matrix3.prototype.isMatrix3 = true;
  869. function arrayMax( array ) {
  870. if ( array.length === 0 ) return - Infinity;
  871. let max = array[ 0 ];
  872. for ( let i = 1, l = array.length; i < l; ++ i ) {
  873. if ( array[ i ] > max ) max = array[ i ];
  874. }
  875. return max;
  876. }
  877. const TYPED_ARRAYS = {
  878. Int8Array: Int8Array,
  879. Uint8Array: Uint8Array,
  880. Uint8ClampedArray: Uint8ClampedArray,
  881. Int16Array: Int16Array,
  882. Uint16Array: Uint16Array,
  883. Int32Array: Int32Array,
  884. Uint32Array: Uint32Array,
  885. Float32Array: Float32Array,
  886. Float64Array: Float64Array
  887. };
  888. function getTypedArray( type, buffer ) {
  889. return new TYPED_ARRAYS[ type ]( buffer );
  890. }
  891. function createElementNS( name ) {
  892. return document.createElementNS( 'http://www.w3.org/1999/xhtml', name );
  893. }
  894. let _canvas;
  895. class ImageUtils {
  896. static getDataURL( image ) {
  897. if ( /^data:/i.test( image.src ) ) {
  898. return image.src;
  899. }
  900. if ( typeof HTMLCanvasElement == 'undefined' ) {
  901. return image.src;
  902. }
  903. let canvas;
  904. if ( image instanceof HTMLCanvasElement ) {
  905. canvas = image;
  906. } else {
  907. if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );
  908. _canvas.width = image.width;
  909. _canvas.height = image.height;
  910. const context = _canvas.getContext( '2d' );
  911. if ( image instanceof ImageData ) {
  912. context.putImageData( image, 0, 0 );
  913. } else {
  914. context.drawImage( image, 0, 0, image.width, image.height );
  915. }
  916. canvas = _canvas;
  917. }
  918. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  919. console.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image );
  920. return canvas.toDataURL( 'image/jpeg', 0.6 );
  921. } else {
  922. return canvas.toDataURL( 'image/png' );
  923. }
  924. }
  925. }
  926. let textureId = 0;
  927. class Texture extends EventDispatcher {
  928. constructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1, encoding = LinearEncoding ) {
  929. super();
  930. Object.defineProperty( this, 'id', { value: textureId ++ } );
  931. this.uuid = generateUUID();
  932. this.name = '';
  933. this.image = image;
  934. this.mipmaps = [];
  935. this.mapping = mapping;
  936. this.wrapS = wrapS;
  937. this.wrapT = wrapT;
  938. this.magFilter = magFilter;
  939. this.minFilter = minFilter;
  940. this.anisotropy = anisotropy;
  941. this.format = format;
  942. this.internalFormat = null;
  943. this.type = type;
  944. this.offset = new Vector2( 0, 0 );
  945. this.repeat = new Vector2( 1, 1 );
  946. this.center = new Vector2( 0, 0 );
  947. this.rotation = 0;
  948. this.matrixAutoUpdate = true;
  949. this.matrix = new Matrix3();
  950. this.generateMipmaps = true;
  951. this.premultiplyAlpha = false;
  952. this.flipY = true;
  953. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  954. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  955. //
  956. // Also changing the encoding after already used by a Material will not automatically make the Material
  957. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  958. this.encoding = encoding;
  959. this.version = 0;
  960. this.onUpdate = null;
  961. this.isRenderTargetTexture = false;
  962. }
  963. updateMatrix() {
  964. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  965. }
  966. clone() {
  967. return new this.constructor().copy( this );
  968. }
  969. copy( source ) {
  970. this.name = source.name;
  971. this.image = source.image;
  972. this.mipmaps = source.mipmaps.slice( 0 );
  973. this.mapping = source.mapping;
  974. this.wrapS = source.wrapS;
  975. this.wrapT = source.wrapT;
  976. this.magFilter = source.magFilter;
  977. this.minFilter = source.minFilter;
  978. this.anisotropy = source.anisotropy;
  979. this.format = source.format;
  980. this.internalFormat = source.internalFormat;
  981. this.type = source.type;
  982. this.offset.copy( source.offset );
  983. this.repeat.copy( source.repeat );
  984. this.center.copy( source.center );
  985. this.rotation = source.rotation;
  986. this.matrixAutoUpdate = source.matrixAutoUpdate;
  987. this.matrix.copy( source.matrix );
  988. this.generateMipmaps = source.generateMipmaps;
  989. this.premultiplyAlpha = source.premultiplyAlpha;
  990. this.flipY = source.flipY;
  991. this.unpackAlignment = source.unpackAlignment;
  992. this.encoding = source.encoding;
  993. return this;
  994. }
  995. toJSON( meta ) {
  996. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  997. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  998. return meta.textures[ this.uuid ];
  999. }
  1000. const output = {
  1001. metadata: {
  1002. version: 4.5,
  1003. type: 'Texture',
  1004. generator: 'Texture.toJSON'
  1005. },
  1006. uuid: this.uuid,
  1007. name: this.name,
  1008. mapping: this.mapping,
  1009. repeat: [ this.repeat.x, this.repeat.y ],
  1010. offset: [ this.offset.x, this.offset.y ],
  1011. center: [ this.center.x, this.center.y ],
  1012. rotation: this.rotation,
  1013. wrap: [ this.wrapS, this.wrapT ],
  1014. format: this.format,
  1015. type: this.type,
  1016. encoding: this.encoding,
  1017. minFilter: this.minFilter,
  1018. magFilter: this.magFilter,
  1019. anisotropy: this.anisotropy,
  1020. flipY: this.flipY,
  1021. premultiplyAlpha: this.premultiplyAlpha,
  1022. unpackAlignment: this.unpackAlignment
  1023. };
  1024. if ( this.image !== undefined ) {
  1025. // TODO: Move to THREE.Image
  1026. const image = this.image;
  1027. if ( image.uuid === undefined ) {
  1028. image.uuid = generateUUID(); // UGH
  1029. }
  1030. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1031. let url;
  1032. if ( Array.isArray( image ) ) {
  1033. // process array of images e.g. CubeTexture
  1034. url = [];
  1035. for ( let i = 0, l = image.length; i < l; i ++ ) {
  1036. // check cube texture with data textures
  1037. if ( image[ i ].isDataTexture ) {
  1038. url.push( serializeImage( image[ i ].image ) );
  1039. } else {
  1040. url.push( serializeImage( image[ i ] ) );
  1041. }
  1042. }
  1043. } else {
  1044. // process single image
  1045. url = serializeImage( image );
  1046. }
  1047. meta.images[ image.uuid ] = {
  1048. uuid: image.uuid,
  1049. url: url
  1050. };
  1051. }
  1052. output.image = image.uuid;
  1053. }
  1054. if ( ! isRootObject ) {
  1055. meta.textures[ this.uuid ] = output;
  1056. }
  1057. return output;
  1058. }
  1059. dispose() {
  1060. this.dispatchEvent( { type: 'dispose' } );
  1061. }
  1062. transformUv( uv ) {
  1063. if ( this.mapping !== UVMapping ) return uv;
  1064. uv.applyMatrix3( this.matrix );
  1065. if ( uv.x < 0 || uv.x > 1 ) {
  1066. switch ( this.wrapS ) {
  1067. case RepeatWrapping:
  1068. uv.x = uv.x - Math.floor( uv.x );
  1069. break;
  1070. case ClampToEdgeWrapping:
  1071. uv.x = uv.x < 0 ? 0 : 1;
  1072. break;
  1073. case MirroredRepeatWrapping:
  1074. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1075. uv.x = Math.ceil( uv.x ) - uv.x;
  1076. } else {
  1077. uv.x = uv.x - Math.floor( uv.x );
  1078. }
  1079. break;
  1080. }
  1081. }
  1082. if ( uv.y < 0 || uv.y > 1 ) {
  1083. switch ( this.wrapT ) {
  1084. case RepeatWrapping:
  1085. uv.y = uv.y - Math.floor( uv.y );
  1086. break;
  1087. case ClampToEdgeWrapping:
  1088. uv.y = uv.y < 0 ? 0 : 1;
  1089. break;
  1090. case MirroredRepeatWrapping:
  1091. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1092. uv.y = Math.ceil( uv.y ) - uv.y;
  1093. } else {
  1094. uv.y = uv.y - Math.floor( uv.y );
  1095. }
  1096. break;
  1097. }
  1098. }
  1099. if ( this.flipY ) {
  1100. uv.y = 1 - uv.y;
  1101. }
  1102. return uv;
  1103. }
  1104. set needsUpdate( value ) {
  1105. if ( value === true ) this.version ++;
  1106. }
  1107. }
  1108. Texture.DEFAULT_IMAGE = undefined;
  1109. Texture.DEFAULT_MAPPING = UVMapping;
  1110. Texture.prototype.isTexture = true;
  1111. function serializeImage( image ) {
  1112. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1113. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1114. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1115. // default images
  1116. return ImageUtils.getDataURL( image );
  1117. } else {
  1118. if ( image.data ) {
  1119. // images of DataTexture
  1120. return {
  1121. data: Array.prototype.slice.call( image.data ),
  1122. width: image.width,
  1123. height: image.height,
  1124. type: image.data.constructor.name
  1125. };
  1126. } else {
  1127. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1128. return {};
  1129. }
  1130. }
  1131. }
  1132. class Vector4 {
  1133. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1134. this.x = x;
  1135. this.y = y;
  1136. this.z = z;
  1137. this.w = w;
  1138. }
  1139. get width() {
  1140. return this.z;
  1141. }
  1142. set width( value ) {
  1143. this.z = value;
  1144. }
  1145. get height() {
  1146. return this.w;
  1147. }
  1148. set height( value ) {
  1149. this.w = value;
  1150. }
  1151. set( x, y, z, w ) {
  1152. this.x = x;
  1153. this.y = y;
  1154. this.z = z;
  1155. this.w = w;
  1156. return this;
  1157. }
  1158. setScalar( scalar ) {
  1159. this.x = scalar;
  1160. this.y = scalar;
  1161. this.z = scalar;
  1162. this.w = scalar;
  1163. return this;
  1164. }
  1165. setX( x ) {
  1166. this.x = x;
  1167. return this;
  1168. }
  1169. setY( y ) {
  1170. this.y = y;
  1171. return this;
  1172. }
  1173. setZ( z ) {
  1174. this.z = z;
  1175. return this;
  1176. }
  1177. setW( w ) {
  1178. this.w = w;
  1179. return this;
  1180. }
  1181. setComponent( index, value ) {
  1182. switch ( index ) {
  1183. case 0: this.x = value; break;
  1184. case 1: this.y = value; break;
  1185. case 2: this.z = value; break;
  1186. case 3: this.w = value; break;
  1187. default: throw new Error( 'index is out of range: ' + index );
  1188. }
  1189. return this;
  1190. }
  1191. getComponent( index ) {
  1192. switch ( index ) {
  1193. case 0: return this.x;
  1194. case 1: return this.y;
  1195. case 2: return this.z;
  1196. case 3: return this.w;
  1197. default: throw new Error( 'index is out of range: ' + index );
  1198. }
  1199. }
  1200. clone() {
  1201. return new this.constructor( this.x, this.y, this.z, this.w );
  1202. }
  1203. copy( v ) {
  1204. this.x = v.x;
  1205. this.y = v.y;
  1206. this.z = v.z;
  1207. this.w = ( v.w !== undefined ) ? v.w : 1;
  1208. return this;
  1209. }
  1210. add( v, w ) {
  1211. if ( w !== undefined ) {
  1212. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1213. return this.addVectors( v, w );
  1214. }
  1215. this.x += v.x;
  1216. this.y += v.y;
  1217. this.z += v.z;
  1218. this.w += v.w;
  1219. return this;
  1220. }
  1221. addScalar( s ) {
  1222. this.x += s;
  1223. this.y += s;
  1224. this.z += s;
  1225. this.w += s;
  1226. return this;
  1227. }
  1228. addVectors( a, b ) {
  1229. this.x = a.x + b.x;
  1230. this.y = a.y + b.y;
  1231. this.z = a.z + b.z;
  1232. this.w = a.w + b.w;
  1233. return this;
  1234. }
  1235. addScaledVector( v, s ) {
  1236. this.x += v.x * s;
  1237. this.y += v.y * s;
  1238. this.z += v.z * s;
  1239. this.w += v.w * s;
  1240. return this;
  1241. }
  1242. sub( v, w ) {
  1243. if ( w !== undefined ) {
  1244. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1245. return this.subVectors( v, w );
  1246. }
  1247. this.x -= v.x;
  1248. this.y -= v.y;
  1249. this.z -= v.z;
  1250. this.w -= v.w;
  1251. return this;
  1252. }
  1253. subScalar( s ) {
  1254. this.x -= s;
  1255. this.y -= s;
  1256. this.z -= s;
  1257. this.w -= s;
  1258. return this;
  1259. }
  1260. subVectors( a, b ) {
  1261. this.x = a.x - b.x;
  1262. this.y = a.y - b.y;
  1263. this.z = a.z - b.z;
  1264. this.w = a.w - b.w;
  1265. return this;
  1266. }
  1267. multiply( v ) {
  1268. this.x *= v.x;
  1269. this.y *= v.y;
  1270. this.z *= v.z;
  1271. this.w *= v.w;
  1272. return this;
  1273. }
  1274. multiplyScalar( scalar ) {
  1275. this.x *= scalar;
  1276. this.y *= scalar;
  1277. this.z *= scalar;
  1278. this.w *= scalar;
  1279. return this;
  1280. }
  1281. applyMatrix4( m ) {
  1282. const x = this.x, y = this.y, z = this.z, w = this.w;
  1283. const e = m.elements;
  1284. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1285. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1286. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1287. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1288. return this;
  1289. }
  1290. divideScalar( scalar ) {
  1291. return this.multiplyScalar( 1 / scalar );
  1292. }
  1293. setAxisAngleFromQuaternion( q ) {
  1294. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1295. // q is assumed to be normalized
  1296. this.w = 2 * Math.acos( q.w );
  1297. const s = Math.sqrt( 1 - q.w * q.w );
  1298. if ( s < 0.0001 ) {
  1299. this.x = 1;
  1300. this.y = 0;
  1301. this.z = 0;
  1302. } else {
  1303. this.x = q.x / s;
  1304. this.y = q.y / s;
  1305. this.z = q.z / s;
  1306. }
  1307. return this;
  1308. }
  1309. setAxisAngleFromRotationMatrix( m ) {
  1310. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1311. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1312. let angle, x, y, z; // variables for result
  1313. const epsilon = 0.01, // margin to allow for rounding errors
  1314. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1315. te = m.elements,
  1316. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1317. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1318. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1319. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1320. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1321. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1322. // singularity found
  1323. // first check for identity matrix which must have +1 for all terms
  1324. // in leading diagonal and zero in other terms
  1325. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1326. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1327. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1328. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1329. // this singularity is identity matrix so angle = 0
  1330. this.set( 1, 0, 0, 0 );
  1331. return this; // zero angle, arbitrary axis
  1332. }
  1333. // otherwise this singularity is angle = 180
  1334. angle = Math.PI;
  1335. const xx = ( m11 + 1 ) / 2;
  1336. const yy = ( m22 + 1 ) / 2;
  1337. const zz = ( m33 + 1 ) / 2;
  1338. const xy = ( m12 + m21 ) / 4;
  1339. const xz = ( m13 + m31 ) / 4;
  1340. const yz = ( m23 + m32 ) / 4;
  1341. if ( ( xx > yy ) && ( xx > zz ) ) {
  1342. // m11 is the largest diagonal term
  1343. if ( xx < epsilon ) {
  1344. x = 0;
  1345. y = 0.707106781;
  1346. z = 0.707106781;
  1347. } else {
  1348. x = Math.sqrt( xx );
  1349. y = xy / x;
  1350. z = xz / x;
  1351. }
  1352. } else if ( yy > zz ) {
  1353. // m22 is the largest diagonal term
  1354. if ( yy < epsilon ) {
  1355. x = 0.707106781;
  1356. y = 0;
  1357. z = 0.707106781;
  1358. } else {
  1359. y = Math.sqrt( yy );
  1360. x = xy / y;
  1361. z = yz / y;
  1362. }
  1363. } else {
  1364. // m33 is the largest diagonal term so base result on this
  1365. if ( zz < epsilon ) {
  1366. x = 0.707106781;
  1367. y = 0.707106781;
  1368. z = 0;
  1369. } else {
  1370. z = Math.sqrt( zz );
  1371. x = xz / z;
  1372. y = yz / z;
  1373. }
  1374. }
  1375. this.set( x, y, z, angle );
  1376. return this; // return 180 deg rotation
  1377. }
  1378. // as we have reached here there are no singularities so we can handle normally
  1379. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1380. ( m13 - m31 ) * ( m13 - m31 ) +
  1381. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1382. if ( Math.abs( s ) < 0.001 ) s = 1;
  1383. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1384. // caught by singularity test above, but I've left it in just in case
  1385. this.x = ( m32 - m23 ) / s;
  1386. this.y = ( m13 - m31 ) / s;
  1387. this.z = ( m21 - m12 ) / s;
  1388. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1389. return this;
  1390. }
  1391. min( v ) {
  1392. this.x = Math.min( this.x, v.x );
  1393. this.y = Math.min( this.y, v.y );
  1394. this.z = Math.min( this.z, v.z );
  1395. this.w = Math.min( this.w, v.w );
  1396. return this;
  1397. }
  1398. max( v ) {
  1399. this.x = Math.max( this.x, v.x );
  1400. this.y = Math.max( this.y, v.y );
  1401. this.z = Math.max( this.z, v.z );
  1402. this.w = Math.max( this.w, v.w );
  1403. return this;
  1404. }
  1405. clamp( min, max ) {
  1406. // assumes min < max, componentwise
  1407. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1408. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1409. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1410. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1411. return this;
  1412. }
  1413. clampScalar( minVal, maxVal ) {
  1414. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1415. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1416. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1417. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1418. return this;
  1419. }
  1420. clampLength( min, max ) {
  1421. const length = this.length();
  1422. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1423. }
  1424. floor() {
  1425. this.x = Math.floor( this.x );
  1426. this.y = Math.floor( this.y );
  1427. this.z = Math.floor( this.z );
  1428. this.w = Math.floor( this.w );
  1429. return this;
  1430. }
  1431. ceil() {
  1432. this.x = Math.ceil( this.x );
  1433. this.y = Math.ceil( this.y );
  1434. this.z = Math.ceil( this.z );
  1435. this.w = Math.ceil( this.w );
  1436. return this;
  1437. }
  1438. round() {
  1439. this.x = Math.round( this.x );
  1440. this.y = Math.round( this.y );
  1441. this.z = Math.round( this.z );
  1442. this.w = Math.round( this.w );
  1443. return this;
  1444. }
  1445. roundToZero() {
  1446. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1447. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1448. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1449. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1450. return this;
  1451. }
  1452. negate() {
  1453. this.x = - this.x;
  1454. this.y = - this.y;
  1455. this.z = - this.z;
  1456. this.w = - this.w;
  1457. return this;
  1458. }
  1459. dot( v ) {
  1460. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1461. }
  1462. lengthSq() {
  1463. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1464. }
  1465. length() {
  1466. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1467. }
  1468. manhattanLength() {
  1469. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1470. }
  1471. normalize() {
  1472. return this.divideScalar( this.length() || 1 );
  1473. }
  1474. setLength( length ) {
  1475. return this.normalize().multiplyScalar( length );
  1476. }
  1477. lerp( v, alpha ) {
  1478. this.x += ( v.x - this.x ) * alpha;
  1479. this.y += ( v.y - this.y ) * alpha;
  1480. this.z += ( v.z - this.z ) * alpha;
  1481. this.w += ( v.w - this.w ) * alpha;
  1482. return this;
  1483. }
  1484. lerpVectors( v1, v2, alpha ) {
  1485. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1486. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1487. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1488. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1489. return this;
  1490. }
  1491. equals( v ) {
  1492. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1493. }
  1494. fromArray( array, offset = 0 ) {
  1495. this.x = array[ offset ];
  1496. this.y = array[ offset + 1 ];
  1497. this.z = array[ offset + 2 ];
  1498. this.w = array[ offset + 3 ];
  1499. return this;
  1500. }
  1501. toArray( array = [], offset = 0 ) {
  1502. array[ offset ] = this.x;
  1503. array[ offset + 1 ] = this.y;
  1504. array[ offset + 2 ] = this.z;
  1505. array[ offset + 3 ] = this.w;
  1506. return array;
  1507. }
  1508. fromBufferAttribute( attribute, index, offset ) {
  1509. if ( offset !== undefined ) {
  1510. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1511. }
  1512. this.x = attribute.getX( index );
  1513. this.y = attribute.getY( index );
  1514. this.z = attribute.getZ( index );
  1515. this.w = attribute.getW( index );
  1516. return this;
  1517. }
  1518. random() {
  1519. this.x = Math.random();
  1520. this.y = Math.random();
  1521. this.z = Math.random();
  1522. this.w = Math.random();
  1523. return this;
  1524. }
  1525. }
  1526. Vector4.prototype.isVector4 = true;
  1527. /*
  1528. In options, we can specify:
  1529. * Texture parameters for an auto-generated target texture
  1530. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1531. */
  1532. class WebGLRenderTarget extends EventDispatcher {
  1533. constructor( width, height, options = {} ) {
  1534. super();
  1535. this.width = width;
  1536. this.height = height;
  1537. this.depth = 1;
  1538. this.scissor = new Vector4( 0, 0, width, height );
  1539. this.scissorTest = false;
  1540. this.viewport = new Vector4( 0, 0, width, height );
  1541. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1542. this.texture.isRenderTargetTexture = true;
  1543. this.texture.image = { width: width, height: height, depth: 1 };
  1544. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1545. this.texture.internalFormat = options.internalFormat !== undefined ? options.internalFormat : null;
  1546. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1547. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1548. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1549. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1550. }
  1551. setTexture( texture ) {
  1552. texture.image = {
  1553. width: this.width,
  1554. height: this.height,
  1555. depth: this.depth
  1556. };
  1557. this.texture = texture;
  1558. }
  1559. setSize( width, height, depth = 1 ) {
  1560. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1561. this.width = width;
  1562. this.height = height;
  1563. this.depth = depth;
  1564. this.texture.image.width = width;
  1565. this.texture.image.height = height;
  1566. this.texture.image.depth = depth;
  1567. this.dispose();
  1568. }
  1569. this.viewport.set( 0, 0, width, height );
  1570. this.scissor.set( 0, 0, width, height );
  1571. }
  1572. clone() {
  1573. return new this.constructor().copy( this );
  1574. }
  1575. copy( source ) {
  1576. this.width = source.width;
  1577. this.height = source.height;
  1578. this.depth = source.depth;
  1579. this.viewport.copy( source.viewport );
  1580. this.texture = source.texture.clone();
  1581. this.texture.image = { ...this.texture.image }; // See #20328.
  1582. this.depthBuffer = source.depthBuffer;
  1583. this.stencilBuffer = source.stencilBuffer;
  1584. this.depthTexture = source.depthTexture;
  1585. return this;
  1586. }
  1587. dispose() {
  1588. this.dispatchEvent( { type: 'dispose' } );
  1589. }
  1590. }
  1591. WebGLRenderTarget.prototype.isWebGLRenderTarget = true;
  1592. class WebGLMultipleRenderTargets extends WebGLRenderTarget {
  1593. constructor( width, height, count ) {
  1594. super( width, height );
  1595. const texture = this.texture;
  1596. this.texture = [];
  1597. for ( let i = 0; i < count; i ++ ) {
  1598. this.texture[ i ] = texture.clone();
  1599. }
  1600. }
  1601. setSize( width, height, depth = 1 ) {
  1602. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1603. this.width = width;
  1604. this.height = height;
  1605. this.depth = depth;
  1606. for ( let i = 0, il = this.texture.length; i < il; i ++ ) {
  1607. this.texture[ i ].image.width = width;
  1608. this.texture[ i ].image.height = height;
  1609. this.texture[ i ].image.depth = depth;
  1610. }
  1611. this.dispose();
  1612. }
  1613. this.viewport.set( 0, 0, width, height );
  1614. this.scissor.set( 0, 0, width, height );
  1615. return this;
  1616. }
  1617. copy( source ) {
  1618. this.dispose();
  1619. this.width = source.width;
  1620. this.height = source.height;
  1621. this.depth = source.depth;
  1622. this.viewport.set( 0, 0, this.width, this.height );
  1623. this.scissor.set( 0, 0, this.width, this.height );
  1624. this.depthBuffer = source.depthBuffer;
  1625. this.stencilBuffer = source.stencilBuffer;
  1626. this.depthTexture = source.depthTexture;
  1627. this.texture.length = 0;
  1628. for ( let i = 0, il = source.texture.length; i < il; i ++ ) {
  1629. this.texture[ i ] = source.texture[ i ].clone();
  1630. }
  1631. return this;
  1632. }
  1633. }
  1634. WebGLMultipleRenderTargets.prototype.isWebGLMultipleRenderTargets = true;
  1635. class WebGLMultisampleRenderTarget extends WebGLRenderTarget {
  1636. constructor( width, height, options ) {
  1637. super( width, height, options );
  1638. this.samples = 4;
  1639. }
  1640. copy( source ) {
  1641. super.copy.call( this, source );
  1642. this.samples = source.samples;
  1643. return this;
  1644. }
  1645. }
  1646. WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
  1647. class Quaternion {
  1648. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1649. this._x = x;
  1650. this._y = y;
  1651. this._z = z;
  1652. this._w = w;
  1653. }
  1654. static slerp( qa, qb, qm, t ) {
  1655. console.warn( 'THREE.Quaternion: Static .slerp() has been deprecated. Use qm.slerpQuaternions( qa, qb, t ) instead.' );
  1656. return qm.slerpQuaternions( qa, qb, t );
  1657. }
  1658. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1659. // fuzz-free, array-based Quaternion SLERP operation
  1660. let x0 = src0[ srcOffset0 + 0 ],
  1661. y0 = src0[ srcOffset0 + 1 ],
  1662. z0 = src0[ srcOffset0 + 2 ],
  1663. w0 = src0[ srcOffset0 + 3 ];
  1664. const x1 = src1[ srcOffset1 + 0 ],
  1665. y1 = src1[ srcOffset1 + 1 ],
  1666. z1 = src1[ srcOffset1 + 2 ],
  1667. w1 = src1[ srcOffset1 + 3 ];
  1668. if ( t === 0 ) {
  1669. dst[ dstOffset + 0 ] = x0;
  1670. dst[ dstOffset + 1 ] = y0;
  1671. dst[ dstOffset + 2 ] = z0;
  1672. dst[ dstOffset + 3 ] = w0;
  1673. return;
  1674. }
  1675. if ( t === 1 ) {
  1676. dst[ dstOffset + 0 ] = x1;
  1677. dst[ dstOffset + 1 ] = y1;
  1678. dst[ dstOffset + 2 ] = z1;
  1679. dst[ dstOffset + 3 ] = w1;
  1680. return;
  1681. }
  1682. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1683. let s = 1 - t;
  1684. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1685. dir = ( cos >= 0 ? 1 : - 1 ),
  1686. sqrSin = 1 - cos * cos;
  1687. // Skip the Slerp for tiny steps to avoid numeric problems:
  1688. if ( sqrSin > Number.EPSILON ) {
  1689. const sin = Math.sqrt( sqrSin ),
  1690. len = Math.atan2( sin, cos * dir );
  1691. s = Math.sin( s * len ) / sin;
  1692. t = Math.sin( t * len ) / sin;
  1693. }
  1694. const tDir = t * dir;
  1695. x0 = x0 * s + x1 * tDir;
  1696. y0 = y0 * s + y1 * tDir;
  1697. z0 = z0 * s + z1 * tDir;
  1698. w0 = w0 * s + w1 * tDir;
  1699. // Normalize in case we just did a lerp:
  1700. if ( s === 1 - t ) {
  1701. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1702. x0 *= f;
  1703. y0 *= f;
  1704. z0 *= f;
  1705. w0 *= f;
  1706. }
  1707. }
  1708. dst[ dstOffset ] = x0;
  1709. dst[ dstOffset + 1 ] = y0;
  1710. dst[ dstOffset + 2 ] = z0;
  1711. dst[ dstOffset + 3 ] = w0;
  1712. }
  1713. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1714. const x0 = src0[ srcOffset0 ];
  1715. const y0 = src0[ srcOffset0 + 1 ];
  1716. const z0 = src0[ srcOffset0 + 2 ];
  1717. const w0 = src0[ srcOffset0 + 3 ];
  1718. const x1 = src1[ srcOffset1 ];
  1719. const y1 = src1[ srcOffset1 + 1 ];
  1720. const z1 = src1[ srcOffset1 + 2 ];
  1721. const w1 = src1[ srcOffset1 + 3 ];
  1722. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1723. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1724. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1725. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1726. return dst;
  1727. }
  1728. get x() {
  1729. return this._x;
  1730. }
  1731. set x( value ) {
  1732. this._x = value;
  1733. this._onChangeCallback();
  1734. }
  1735. get y() {
  1736. return this._y;
  1737. }
  1738. set y( value ) {
  1739. this._y = value;
  1740. this._onChangeCallback();
  1741. }
  1742. get z() {
  1743. return this._z;
  1744. }
  1745. set z( value ) {
  1746. this._z = value;
  1747. this._onChangeCallback();
  1748. }
  1749. get w() {
  1750. return this._w;
  1751. }
  1752. set w( value ) {
  1753. this._w = value;
  1754. this._onChangeCallback();
  1755. }
  1756. set( x, y, z, w ) {
  1757. this._x = x;
  1758. this._y = y;
  1759. this._z = z;
  1760. this._w = w;
  1761. this._onChangeCallback();
  1762. return this;
  1763. }
  1764. clone() {
  1765. return new this.constructor( this._x, this._y, this._z, this._w );
  1766. }
  1767. copy( quaternion ) {
  1768. this._x = quaternion.x;
  1769. this._y = quaternion.y;
  1770. this._z = quaternion.z;
  1771. this._w = quaternion.w;
  1772. this._onChangeCallback();
  1773. return this;
  1774. }
  1775. setFromEuler( euler, update ) {
  1776. if ( ! ( euler && euler.isEuler ) ) {
  1777. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1778. }
  1779. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  1780. // http://www.mathworks.com/matlabcentral/fileexchange/
  1781. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1782. // content/SpinCalc.m
  1783. const cos = Math.cos;
  1784. const sin = Math.sin;
  1785. const c1 = cos( x / 2 );
  1786. const c2 = cos( y / 2 );
  1787. const c3 = cos( z / 2 );
  1788. const s1 = sin( x / 2 );
  1789. const s2 = sin( y / 2 );
  1790. const s3 = sin( z / 2 );
  1791. switch ( order ) {
  1792. case 'XYZ':
  1793. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1794. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1795. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1796. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1797. break;
  1798. case 'YXZ':
  1799. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1800. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1801. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1802. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1803. break;
  1804. case 'ZXY':
  1805. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1806. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1807. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1808. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1809. break;
  1810. case 'ZYX':
  1811. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1812. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1813. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1814. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1815. break;
  1816. case 'YZX':
  1817. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1818. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1819. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1820. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1821. break;
  1822. case 'XZY':
  1823. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1824. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1825. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1826. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1827. break;
  1828. default:
  1829. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1830. }
  1831. if ( update !== false ) this._onChangeCallback();
  1832. return this;
  1833. }
  1834. setFromAxisAngle( axis, angle ) {
  1835. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1836. // assumes axis is normalized
  1837. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  1838. this._x = axis.x * s;
  1839. this._y = axis.y * s;
  1840. this._z = axis.z * s;
  1841. this._w = Math.cos( halfAngle );
  1842. this._onChangeCallback();
  1843. return this;
  1844. }
  1845. setFromRotationMatrix( m ) {
  1846. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1847. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1848. const te = m.elements,
  1849. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1850. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1851. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1852. trace = m11 + m22 + m33;
  1853. if ( trace > 0 ) {
  1854. const s = 0.5 / Math.sqrt( trace + 1.0 );
  1855. this._w = 0.25 / s;
  1856. this._x = ( m32 - m23 ) * s;
  1857. this._y = ( m13 - m31 ) * s;
  1858. this._z = ( m21 - m12 ) * s;
  1859. } else if ( m11 > m22 && m11 > m33 ) {
  1860. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1861. this._w = ( m32 - m23 ) / s;
  1862. this._x = 0.25 * s;
  1863. this._y = ( m12 + m21 ) / s;
  1864. this._z = ( m13 + m31 ) / s;
  1865. } else if ( m22 > m33 ) {
  1866. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1867. this._w = ( m13 - m31 ) / s;
  1868. this._x = ( m12 + m21 ) / s;
  1869. this._y = 0.25 * s;
  1870. this._z = ( m23 + m32 ) / s;
  1871. } else {
  1872. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1873. this._w = ( m21 - m12 ) / s;
  1874. this._x = ( m13 + m31 ) / s;
  1875. this._y = ( m23 + m32 ) / s;
  1876. this._z = 0.25 * s;
  1877. }
  1878. this._onChangeCallback();
  1879. return this;
  1880. }
  1881. setFromUnitVectors( vFrom, vTo ) {
  1882. // assumes direction vectors vFrom and vTo are normalized
  1883. let r = vFrom.dot( vTo ) + 1;
  1884. if ( r < Number.EPSILON ) {
  1885. // vFrom and vTo point in opposite directions
  1886. r = 0;
  1887. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1888. this._x = - vFrom.y;
  1889. this._y = vFrom.x;
  1890. this._z = 0;
  1891. this._w = r;
  1892. } else {
  1893. this._x = 0;
  1894. this._y = - vFrom.z;
  1895. this._z = vFrom.y;
  1896. this._w = r;
  1897. }
  1898. } else {
  1899. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1900. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1901. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1902. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1903. this._w = r;
  1904. }
  1905. return this.normalize();
  1906. }
  1907. angleTo( q ) {
  1908. return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );
  1909. }
  1910. rotateTowards( q, step ) {
  1911. const angle = this.angleTo( q );
  1912. if ( angle === 0 ) return this;
  1913. const t = Math.min( 1, step / angle );
  1914. this.slerp( q, t );
  1915. return this;
  1916. }
  1917. identity() {
  1918. return this.set( 0, 0, 0, 1 );
  1919. }
  1920. invert() {
  1921. // quaternion is assumed to have unit length
  1922. return this.conjugate();
  1923. }
  1924. conjugate() {
  1925. this._x *= - 1;
  1926. this._y *= - 1;
  1927. this._z *= - 1;
  1928. this._onChangeCallback();
  1929. return this;
  1930. }
  1931. dot( v ) {
  1932. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1933. }
  1934. lengthSq() {
  1935. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1936. }
  1937. length() {
  1938. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1939. }
  1940. normalize() {
  1941. let l = this.length();
  1942. if ( l === 0 ) {
  1943. this._x = 0;
  1944. this._y = 0;
  1945. this._z = 0;
  1946. this._w = 1;
  1947. } else {
  1948. l = 1 / l;
  1949. this._x = this._x * l;
  1950. this._y = this._y * l;
  1951. this._z = this._z * l;
  1952. this._w = this._w * l;
  1953. }
  1954. this._onChangeCallback();
  1955. return this;
  1956. }
  1957. multiply( q, p ) {
  1958. if ( p !== undefined ) {
  1959. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1960. return this.multiplyQuaternions( q, p );
  1961. }
  1962. return this.multiplyQuaternions( this, q );
  1963. }
  1964. premultiply( q ) {
  1965. return this.multiplyQuaternions( q, this );
  1966. }
  1967. multiplyQuaternions( a, b ) {
  1968. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1969. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1970. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1971. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1972. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1973. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1974. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1975. this._onChangeCallback();
  1976. return this;
  1977. }
  1978. slerp( qb, t ) {
  1979. if ( t === 0 ) return this;
  1980. if ( t === 1 ) return this.copy( qb );
  1981. const x = this._x, y = this._y, z = this._z, w = this._w;
  1982. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1983. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1984. if ( cosHalfTheta < 0 ) {
  1985. this._w = - qb._w;
  1986. this._x = - qb._x;
  1987. this._y = - qb._y;
  1988. this._z = - qb._z;
  1989. cosHalfTheta = - cosHalfTheta;
  1990. } else {
  1991. this.copy( qb );
  1992. }
  1993. if ( cosHalfTheta >= 1.0 ) {
  1994. this._w = w;
  1995. this._x = x;
  1996. this._y = y;
  1997. this._z = z;
  1998. return this;
  1999. }
  2000. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2001. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  2002. const s = 1 - t;
  2003. this._w = s * w + t * this._w;
  2004. this._x = s * x + t * this._x;
  2005. this._y = s * y + t * this._y;
  2006. this._z = s * z + t * this._z;
  2007. this.normalize();
  2008. this._onChangeCallback();
  2009. return this;
  2010. }
  2011. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  2012. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  2013. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2014. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2015. this._w = ( w * ratioA + this._w * ratioB );
  2016. this._x = ( x * ratioA + this._x * ratioB );
  2017. this._y = ( y * ratioA + this._y * ratioB );
  2018. this._z = ( z * ratioA + this._z * ratioB );
  2019. this._onChangeCallback();
  2020. return this;
  2021. }
  2022. slerpQuaternions( qa, qb, t ) {
  2023. this.copy( qa ).slerp( qb, t );
  2024. }
  2025. random() {
  2026. // Derived from http://planning.cs.uiuc.edu/node198.html
  2027. // Note, this source uses w, x, y, z ordering,
  2028. // so we swap the order below.
  2029. const u1 = Math.random();
  2030. const sqrt1u1 = Math.sqrt( 1 - u1 );
  2031. const sqrtu1 = Math.sqrt( u1 );
  2032. const u2 = 2 * Math.PI * Math.random();
  2033. const u3 = 2 * Math.PI * Math.random();
  2034. return this.set(
  2035. sqrt1u1 * Math.cos( u2 ),
  2036. sqrtu1 * Math.sin( u3 ),
  2037. sqrtu1 * Math.cos( u3 ),
  2038. sqrt1u1 * Math.sin( u2 ),
  2039. );
  2040. }
  2041. equals( quaternion ) {
  2042. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  2043. }
  2044. fromArray( array, offset = 0 ) {
  2045. this._x = array[ offset ];
  2046. this._y = array[ offset + 1 ];
  2047. this._z = array[ offset + 2 ];
  2048. this._w = array[ offset + 3 ];
  2049. this._onChangeCallback();
  2050. return this;
  2051. }
  2052. toArray( array = [], offset = 0 ) {
  2053. array[ offset ] = this._x;
  2054. array[ offset + 1 ] = this._y;
  2055. array[ offset + 2 ] = this._z;
  2056. array[ offset + 3 ] = this._w;
  2057. return array;
  2058. }
  2059. fromBufferAttribute( attribute, index ) {
  2060. this._x = attribute.getX( index );
  2061. this._y = attribute.getY( index );
  2062. this._z = attribute.getZ( index );
  2063. this._w = attribute.getW( index );
  2064. return this;
  2065. }
  2066. _onChange( callback ) {
  2067. this._onChangeCallback = callback;
  2068. return this;
  2069. }
  2070. _onChangeCallback() {}
  2071. }
  2072. Quaternion.prototype.isQuaternion = true;
  2073. class Vector3 {
  2074. constructor( x = 0, y = 0, z = 0 ) {
  2075. this.x = x;
  2076. this.y = y;
  2077. this.z = z;
  2078. }
  2079. set( x, y, z ) {
  2080. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  2081. this.x = x;
  2082. this.y = y;
  2083. this.z = z;
  2084. return this;
  2085. }
  2086. setScalar( scalar ) {
  2087. this.x = scalar;
  2088. this.y = scalar;
  2089. this.z = scalar;
  2090. return this;
  2091. }
  2092. setX( x ) {
  2093. this.x = x;
  2094. return this;
  2095. }
  2096. setY( y ) {
  2097. this.y = y;
  2098. return this;
  2099. }
  2100. setZ( z ) {
  2101. this.z = z;
  2102. return this;
  2103. }
  2104. setComponent( index, value ) {
  2105. switch ( index ) {
  2106. case 0: this.x = value; break;
  2107. case 1: this.y = value; break;
  2108. case 2: this.z = value; break;
  2109. default: throw new Error( 'index is out of range: ' + index );
  2110. }
  2111. return this;
  2112. }
  2113. getComponent( index ) {
  2114. switch ( index ) {
  2115. case 0: return this.x;
  2116. case 1: return this.y;
  2117. case 2: return this.z;
  2118. default: throw new Error( 'index is out of range: ' + index );
  2119. }
  2120. }
  2121. clone() {
  2122. return new this.constructor( this.x, this.y, this.z );
  2123. }
  2124. copy( v ) {
  2125. this.x = v.x;
  2126. this.y = v.y;
  2127. this.z = v.z;
  2128. return this;
  2129. }
  2130. add( v, w ) {
  2131. if ( w !== undefined ) {
  2132. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2133. return this.addVectors( v, w );
  2134. }
  2135. this.x += v.x;
  2136. this.y += v.y;
  2137. this.z += v.z;
  2138. return this;
  2139. }
  2140. addScalar( s ) {
  2141. this.x += s;
  2142. this.y += s;
  2143. this.z += s;
  2144. return this;
  2145. }
  2146. addVectors( a, b ) {
  2147. this.x = a.x + b.x;
  2148. this.y = a.y + b.y;
  2149. this.z = a.z + b.z;
  2150. return this;
  2151. }
  2152. addScaledVector( v, s ) {
  2153. this.x += v.x * s;
  2154. this.y += v.y * s;
  2155. this.z += v.z * s;
  2156. return this;
  2157. }
  2158. sub( v, w ) {
  2159. if ( w !== undefined ) {
  2160. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2161. return this.subVectors( v, w );
  2162. }
  2163. this.x -= v.x;
  2164. this.y -= v.y;
  2165. this.z -= v.z;
  2166. return this;
  2167. }
  2168. subScalar( s ) {
  2169. this.x -= s;
  2170. this.y -= s;
  2171. this.z -= s;
  2172. return this;
  2173. }
  2174. subVectors( a, b ) {
  2175. this.x = a.x - b.x;
  2176. this.y = a.y - b.y;
  2177. this.z = a.z - b.z;
  2178. return this;
  2179. }
  2180. multiply( v, w ) {
  2181. if ( w !== undefined ) {
  2182. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2183. return this.multiplyVectors( v, w );
  2184. }
  2185. this.x *= v.x;
  2186. this.y *= v.y;
  2187. this.z *= v.z;
  2188. return this;
  2189. }
  2190. multiplyScalar( scalar ) {
  2191. this.x *= scalar;
  2192. this.y *= scalar;
  2193. this.z *= scalar;
  2194. return this;
  2195. }
  2196. multiplyVectors( a, b ) {
  2197. this.x = a.x * b.x;
  2198. this.y = a.y * b.y;
  2199. this.z = a.z * b.z;
  2200. return this;
  2201. }
  2202. applyEuler( euler ) {
  2203. if ( ! ( euler && euler.isEuler ) ) {
  2204. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2205. }
  2206. return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );
  2207. }
  2208. applyAxisAngle( axis, angle ) {
  2209. return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );
  2210. }
  2211. applyMatrix3( m ) {
  2212. const x = this.x, y = this.y, z = this.z;
  2213. const e = m.elements;
  2214. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2215. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2216. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2217. return this;
  2218. }
  2219. applyNormalMatrix( m ) {
  2220. return this.applyMatrix3( m ).normalize();
  2221. }
  2222. applyMatrix4( m ) {
  2223. const x = this.x, y = this.y, z = this.z;
  2224. const e = m.elements;
  2225. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2226. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2227. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2228. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2229. return this;
  2230. }
  2231. applyQuaternion( q ) {
  2232. const x = this.x, y = this.y, z = this.z;
  2233. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2234. // calculate quat * vector
  2235. const ix = qw * x + qy * z - qz * y;
  2236. const iy = qw * y + qz * x - qx * z;
  2237. const iz = qw * z + qx * y - qy * x;
  2238. const iw = - qx * x - qy * y - qz * z;
  2239. // calculate result * inverse quat
  2240. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2241. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2242. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2243. return this;
  2244. }
  2245. project( camera ) {
  2246. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2247. }
  2248. unproject( camera ) {
  2249. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2250. }
  2251. transformDirection( m ) {
  2252. // input: THREE.Matrix4 affine matrix
  2253. // vector interpreted as a direction
  2254. const x = this.x, y = this.y, z = this.z;
  2255. const e = m.elements;
  2256. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2257. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2258. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2259. return this.normalize();
  2260. }
  2261. divide( v ) {
  2262. this.x /= v.x;
  2263. this.y /= v.y;
  2264. this.z /= v.z;
  2265. return this;
  2266. }
  2267. divideScalar( scalar ) {
  2268. return this.multiplyScalar( 1 / scalar );
  2269. }
  2270. min( v ) {
  2271. this.x = Math.min( this.x, v.x );
  2272. this.y = Math.min( this.y, v.y );
  2273. this.z = Math.min( this.z, v.z );
  2274. return this;
  2275. }
  2276. max( v ) {
  2277. this.x = Math.max( this.x, v.x );
  2278. this.y = Math.max( this.y, v.y );
  2279. this.z = Math.max( this.z, v.z );
  2280. return this;
  2281. }
  2282. clamp( min, max ) {
  2283. // assumes min < max, componentwise
  2284. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2285. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2286. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2287. return this;
  2288. }
  2289. clampScalar( minVal, maxVal ) {
  2290. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2291. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2292. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2293. return this;
  2294. }
  2295. clampLength( min, max ) {
  2296. const length = this.length();
  2297. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2298. }
  2299. floor() {
  2300. this.x = Math.floor( this.x );
  2301. this.y = Math.floor( this.y );
  2302. this.z = Math.floor( this.z );
  2303. return this;
  2304. }
  2305. ceil() {
  2306. this.x = Math.ceil( this.x );
  2307. this.y = Math.ceil( this.y );
  2308. this.z = Math.ceil( this.z );
  2309. return this;
  2310. }
  2311. round() {
  2312. this.x = Math.round( this.x );
  2313. this.y = Math.round( this.y );
  2314. this.z = Math.round( this.z );
  2315. return this;
  2316. }
  2317. roundToZero() {
  2318. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2319. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2320. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2321. return this;
  2322. }
  2323. negate() {
  2324. this.x = - this.x;
  2325. this.y = - this.y;
  2326. this.z = - this.z;
  2327. return this;
  2328. }
  2329. dot( v ) {
  2330. return this.x * v.x + this.y * v.y + this.z * v.z;
  2331. }
  2332. // TODO lengthSquared?
  2333. lengthSq() {
  2334. return this.x * this.x + this.y * this.y + this.z * this.z;
  2335. }
  2336. length() {
  2337. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2338. }
  2339. manhattanLength() {
  2340. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2341. }
  2342. normalize() {
  2343. return this.divideScalar( this.length() || 1 );
  2344. }
  2345. setLength( length ) {
  2346. return this.normalize().multiplyScalar( length );
  2347. }
  2348. lerp( v, alpha ) {
  2349. this.x += ( v.x - this.x ) * alpha;
  2350. this.y += ( v.y - this.y ) * alpha;
  2351. this.z += ( v.z - this.z ) * alpha;
  2352. return this;
  2353. }
  2354. lerpVectors( v1, v2, alpha ) {
  2355. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2356. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2357. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2358. return this;
  2359. }
  2360. cross( v, w ) {
  2361. if ( w !== undefined ) {
  2362. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2363. return this.crossVectors( v, w );
  2364. }
  2365. return this.crossVectors( this, v );
  2366. }
  2367. crossVectors( a, b ) {
  2368. const ax = a.x, ay = a.y, az = a.z;
  2369. const bx = b.x, by = b.y, bz = b.z;
  2370. this.x = ay * bz - az * by;
  2371. this.y = az * bx - ax * bz;
  2372. this.z = ax * by - ay * bx;
  2373. return this;
  2374. }
  2375. projectOnVector( v ) {
  2376. const denominator = v.lengthSq();
  2377. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2378. const scalar = v.dot( this ) / denominator;
  2379. return this.copy( v ).multiplyScalar( scalar );
  2380. }
  2381. projectOnPlane( planeNormal ) {
  2382. _vector$c.copy( this ).projectOnVector( planeNormal );
  2383. return this.sub( _vector$c );
  2384. }
  2385. reflect( normal ) {
  2386. // reflect incident vector off plane orthogonal to normal
  2387. // normal is assumed to have unit length
  2388. return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2389. }
  2390. angleTo( v ) {
  2391. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2392. if ( denominator === 0 ) return Math.PI / 2;
  2393. const theta = this.dot( v ) / denominator;
  2394. // clamp, to handle numerical problems
  2395. return Math.acos( clamp( theta, - 1, 1 ) );
  2396. }
  2397. distanceTo( v ) {
  2398. return Math.sqrt( this.distanceToSquared( v ) );
  2399. }
  2400. distanceToSquared( v ) {
  2401. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2402. return dx * dx + dy * dy + dz * dz;
  2403. }
  2404. manhattanDistanceTo( v ) {
  2405. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2406. }
  2407. setFromSpherical( s ) {
  2408. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2409. }
  2410. setFromSphericalCoords( radius, phi, theta ) {
  2411. const sinPhiRadius = Math.sin( phi ) * radius;
  2412. this.x = sinPhiRadius * Math.sin( theta );
  2413. this.y = Math.cos( phi ) * radius;
  2414. this.z = sinPhiRadius * Math.cos( theta );
  2415. return this;
  2416. }
  2417. setFromCylindrical( c ) {
  2418. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2419. }
  2420. setFromCylindricalCoords( radius, theta, y ) {
  2421. this.x = radius * Math.sin( theta );
  2422. this.y = y;
  2423. this.z = radius * Math.cos( theta );
  2424. return this;
  2425. }
  2426. setFromMatrixPosition( m ) {
  2427. const e = m.elements;
  2428. this.x = e[ 12 ];
  2429. this.y = e[ 13 ];
  2430. this.z = e[ 14 ];
  2431. return this;
  2432. }
  2433. setFromMatrixScale( m ) {
  2434. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2435. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2436. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2437. this.x = sx;
  2438. this.y = sy;
  2439. this.z = sz;
  2440. return this;
  2441. }
  2442. setFromMatrixColumn( m, index ) {
  2443. return this.fromArray( m.elements, index * 4 );
  2444. }
  2445. setFromMatrix3Column( m, index ) {
  2446. return this.fromArray( m.elements, index * 3 );
  2447. }
  2448. equals( v ) {
  2449. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2450. }
  2451. fromArray( array, offset = 0 ) {
  2452. this.x = array[ offset ];
  2453. this.y = array[ offset + 1 ];
  2454. this.z = array[ offset + 2 ];
  2455. return this;
  2456. }
  2457. toArray( array = [], offset = 0 ) {
  2458. array[ offset ] = this.x;
  2459. array[ offset + 1 ] = this.y;
  2460. array[ offset + 2 ] = this.z;
  2461. return array;
  2462. }
  2463. fromBufferAttribute( attribute, index, offset ) {
  2464. if ( offset !== undefined ) {
  2465. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2466. }
  2467. this.x = attribute.getX( index );
  2468. this.y = attribute.getY( index );
  2469. this.z = attribute.getZ( index );
  2470. return this;
  2471. }
  2472. random() {
  2473. this.x = Math.random();
  2474. this.y = Math.random();
  2475. this.z = Math.random();
  2476. return this;
  2477. }
  2478. randomDirection() {
  2479. // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
  2480. const u = ( Math.random() - 0.5 ) * 2;
  2481. const t = Math.random() * Math.PI * 2;
  2482. const f = Math.sqrt( 1 - u ** 2 );
  2483. this.x = f * Math.cos( t );
  2484. this.y = f * Math.sin( t );
  2485. this.z = u;
  2486. return this;
  2487. }
  2488. }
  2489. Vector3.prototype.isVector3 = true;
  2490. const _vector$c = /*@__PURE__*/ new Vector3();
  2491. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  2492. class Box3 {
  2493. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2494. this.min = min;
  2495. this.max = max;
  2496. }
  2497. set( min, max ) {
  2498. this.min.copy( min );
  2499. this.max.copy( max );
  2500. return this;
  2501. }
  2502. setFromArray( array ) {
  2503. let minX = + Infinity;
  2504. let minY = + Infinity;
  2505. let minZ = + Infinity;
  2506. let maxX = - Infinity;
  2507. let maxY = - Infinity;
  2508. let maxZ = - Infinity;
  2509. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  2510. const x = array[ i ];
  2511. const y = array[ i + 1 ];
  2512. const z = array[ i + 2 ];
  2513. if ( x < minX ) minX = x;
  2514. if ( y < minY ) minY = y;
  2515. if ( z < minZ ) minZ = z;
  2516. if ( x > maxX ) maxX = x;
  2517. if ( y > maxY ) maxY = y;
  2518. if ( z > maxZ ) maxZ = z;
  2519. }
  2520. this.min.set( minX, minY, minZ );
  2521. this.max.set( maxX, maxY, maxZ );
  2522. return this;
  2523. }
  2524. setFromBufferAttribute( attribute ) {
  2525. let minX = + Infinity;
  2526. let minY = + Infinity;
  2527. let minZ = + Infinity;
  2528. let maxX = - Infinity;
  2529. let maxY = - Infinity;
  2530. let maxZ = - Infinity;
  2531. for ( let i = 0, l = attribute.count; i < l; i ++ ) {
  2532. const x = attribute.getX( i );
  2533. const y = attribute.getY( i );
  2534. const z = attribute.getZ( i );
  2535. if ( x < minX ) minX = x;
  2536. if ( y < minY ) minY = y;
  2537. if ( z < minZ ) minZ = z;
  2538. if ( x > maxX ) maxX = x;
  2539. if ( y > maxY ) maxY = y;
  2540. if ( z > maxZ ) maxZ = z;
  2541. }
  2542. this.min.set( minX, minY, minZ );
  2543. this.max.set( maxX, maxY, maxZ );
  2544. return this;
  2545. }
  2546. setFromPoints( points ) {
  2547. this.makeEmpty();
  2548. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2549. this.expandByPoint( points[ i ] );
  2550. }
  2551. return this;
  2552. }
  2553. setFromCenterAndSize( center, size ) {
  2554. const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );
  2555. this.min.copy( center ).sub( halfSize );
  2556. this.max.copy( center ).add( halfSize );
  2557. return this;
  2558. }
  2559. setFromObject( object ) {
  2560. this.makeEmpty();
  2561. return this.expandByObject( object );
  2562. }
  2563. clone() {
  2564. return new this.constructor().copy( this );
  2565. }
  2566. copy( box ) {
  2567. this.min.copy( box.min );
  2568. this.max.copy( box.max );
  2569. return this;
  2570. }
  2571. makeEmpty() {
  2572. this.min.x = this.min.y = this.min.z = + Infinity;
  2573. this.max.x = this.max.y = this.max.z = - Infinity;
  2574. return this;
  2575. }
  2576. isEmpty() {
  2577. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2578. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2579. }
  2580. getCenter( target ) {
  2581. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2582. }
  2583. getSize( target ) {
  2584. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2585. }
  2586. expandByPoint( point ) {
  2587. this.min.min( point );
  2588. this.max.max( point );
  2589. return this;
  2590. }
  2591. expandByVector( vector ) {
  2592. this.min.sub( vector );
  2593. this.max.add( vector );
  2594. return this;
  2595. }
  2596. expandByScalar( scalar ) {
  2597. this.min.addScalar( - scalar );
  2598. this.max.addScalar( scalar );
  2599. return this;
  2600. }
  2601. expandByObject( object ) {
  2602. // Computes the world-axis-aligned bounding box of an object (including its children),
  2603. // accounting for both the object's, and children's, world transforms
  2604. object.updateWorldMatrix( false, false );
  2605. const geometry = object.geometry;
  2606. if ( geometry !== undefined ) {
  2607. if ( geometry.boundingBox === null ) {
  2608. geometry.computeBoundingBox();
  2609. }
  2610. _box$3.copy( geometry.boundingBox );
  2611. _box$3.applyMatrix4( object.matrixWorld );
  2612. this.union( _box$3 );
  2613. }
  2614. const children = object.children;
  2615. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2616. this.expandByObject( children[ i ] );
  2617. }
  2618. return this;
  2619. }
  2620. containsPoint( point ) {
  2621. return point.x < this.min.x || point.x > this.max.x ||
  2622. point.y < this.min.y || point.y > this.max.y ||
  2623. point.z < this.min.z || point.z > this.max.z ? false : true;
  2624. }
  2625. containsBox( box ) {
  2626. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2627. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2628. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2629. }
  2630. getParameter( point, target ) {
  2631. // This can potentially have a divide by zero if the box
  2632. // has a size dimension of 0.
  2633. return target.set(
  2634. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2635. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2636. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2637. );
  2638. }
  2639. intersectsBox( box ) {
  2640. // using 6 splitting planes to rule out intersections.
  2641. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2642. box.max.y < this.min.y || box.min.y > this.max.y ||
  2643. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2644. }
  2645. intersectsSphere( sphere ) {
  2646. // Find the point on the AABB closest to the sphere center.
  2647. this.clampPoint( sphere.center, _vector$b );
  2648. // If that point is inside the sphere, the AABB and sphere intersect.
  2649. return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2650. }
  2651. intersectsPlane( plane ) {
  2652. // We compute the minimum and maximum dot product values. If those values
  2653. // are on the same side (back or front) of the plane, then there is no intersection.
  2654. let min, max;
  2655. if ( plane.normal.x > 0 ) {
  2656. min = plane.normal.x * this.min.x;
  2657. max = plane.normal.x * this.max.x;
  2658. } else {
  2659. min = plane.normal.x * this.max.x;
  2660. max = plane.normal.x * this.min.x;
  2661. }
  2662. if ( plane.normal.y > 0 ) {
  2663. min += plane.normal.y * this.min.y;
  2664. max += plane.normal.y * this.max.y;
  2665. } else {
  2666. min += plane.normal.y * this.max.y;
  2667. max += plane.normal.y * this.min.y;
  2668. }
  2669. if ( plane.normal.z > 0 ) {
  2670. min += plane.normal.z * this.min.z;
  2671. max += plane.normal.z * this.max.z;
  2672. } else {
  2673. min += plane.normal.z * this.max.z;
  2674. max += plane.normal.z * this.min.z;
  2675. }
  2676. return ( min <= - plane.constant && max >= - plane.constant );
  2677. }
  2678. intersectsTriangle( triangle ) {
  2679. if ( this.isEmpty() ) {
  2680. return false;
  2681. }
  2682. // compute box center and extents
  2683. this.getCenter( _center );
  2684. _extents.subVectors( this.max, _center );
  2685. // translate triangle to aabb origin
  2686. _v0$2.subVectors( triangle.a, _center );
  2687. _v1$7.subVectors( triangle.b, _center );
  2688. _v2$3.subVectors( triangle.c, _center );
  2689. // compute edge vectors for triangle
  2690. _f0.subVectors( _v1$7, _v0$2 );
  2691. _f1.subVectors( _v2$3, _v1$7 );
  2692. _f2.subVectors( _v0$2, _v2$3 );
  2693. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2694. // 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
  2695. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2696. let axes = [
  2697. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  2698. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  2699. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  2700. ];
  2701. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$3, _extents ) ) {
  2702. return false;
  2703. }
  2704. // test 3 face normals from the aabb
  2705. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2706. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$3, _extents ) ) {
  2707. return false;
  2708. }
  2709. // finally testing the face normal of the triangle
  2710. // use already existing triangle edge vectors here
  2711. _triangleNormal.crossVectors( _f0, _f1 );
  2712. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  2713. return satForAxes( axes, _v0$2, _v1$7, _v2$3, _extents );
  2714. }
  2715. clampPoint( point, target ) {
  2716. return target.copy( point ).clamp( this.min, this.max );
  2717. }
  2718. distanceToPoint( point ) {
  2719. const clampedPoint = _vector$b.copy( point ).clamp( this.min, this.max );
  2720. return clampedPoint.sub( point ).length();
  2721. }
  2722. getBoundingSphere( target ) {
  2723. this.getCenter( target.center );
  2724. target.radius = this.getSize( _vector$b ).length() * 0.5;
  2725. return target;
  2726. }
  2727. intersect( box ) {
  2728. this.min.max( box.min );
  2729. this.max.min( box.max );
  2730. // 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.
  2731. if ( this.isEmpty() ) this.makeEmpty();
  2732. return this;
  2733. }
  2734. union( box ) {
  2735. this.min.min( box.min );
  2736. this.max.max( box.max );
  2737. return this;
  2738. }
  2739. applyMatrix4( matrix ) {
  2740. // transform of empty box is an empty box.
  2741. if ( this.isEmpty() ) return this;
  2742. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2743. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2744. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2745. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2746. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2747. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2748. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2749. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2750. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2751. this.setFromPoints( _points );
  2752. return this;
  2753. }
  2754. translate( offset ) {
  2755. this.min.add( offset );
  2756. this.max.add( offset );
  2757. return this;
  2758. }
  2759. equals( box ) {
  2760. return box.min.equals( this.min ) && box.max.equals( this.max );
  2761. }
  2762. }
  2763. Box3.prototype.isBox3 = true;
  2764. const _points = [
  2765. /*@__PURE__*/ new Vector3(),
  2766. /*@__PURE__*/ new Vector3(),
  2767. /*@__PURE__*/ new Vector3(),
  2768. /*@__PURE__*/ new Vector3(),
  2769. /*@__PURE__*/ new Vector3(),
  2770. /*@__PURE__*/ new Vector3(),
  2771. /*@__PURE__*/ new Vector3(),
  2772. /*@__PURE__*/ new Vector3()
  2773. ];
  2774. const _vector$b = /*@__PURE__*/ new Vector3();
  2775. const _box$3 = /*@__PURE__*/ new Box3();
  2776. // triangle centered vertices
  2777. const _v0$2 = /*@__PURE__*/ new Vector3();
  2778. const _v1$7 = /*@__PURE__*/ new Vector3();
  2779. const _v2$3 = /*@__PURE__*/ new Vector3();
  2780. // triangle edge vectors
  2781. const _f0 = /*@__PURE__*/ new Vector3();
  2782. const _f1 = /*@__PURE__*/ new Vector3();
  2783. const _f2 = /*@__PURE__*/ new Vector3();
  2784. const _center = /*@__PURE__*/ new Vector3();
  2785. const _extents = /*@__PURE__*/ new Vector3();
  2786. const _triangleNormal = /*@__PURE__*/ new Vector3();
  2787. const _testAxis = /*@__PURE__*/ new Vector3();
  2788. function satForAxes( axes, v0, v1, v2, extents ) {
  2789. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2790. _testAxis.fromArray( axes, i );
  2791. // project the aabb onto the seperating axis
  2792. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  2793. // project all 3 vertices of the triangle onto the seperating axis
  2794. const p0 = v0.dot( _testAxis );
  2795. const p1 = v1.dot( _testAxis );
  2796. const p2 = v2.dot( _testAxis );
  2797. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2798. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2799. // points of the projected triangle are outside the projected half-length of the aabb
  2800. // the axis is seperating and we can exit
  2801. return false;
  2802. }
  2803. }
  2804. return true;
  2805. }
  2806. const _box$2 = /*@__PURE__*/ new Box3();
  2807. const _v1$6 = /*@__PURE__*/ new Vector3();
  2808. const _toFarthestPoint = /*@__PURE__*/ new Vector3();
  2809. const _toPoint = /*@__PURE__*/ new Vector3();
  2810. class Sphere {
  2811. constructor( center = new Vector3(), radius = - 1 ) {
  2812. this.center = center;
  2813. this.radius = radius;
  2814. }
  2815. set( center, radius ) {
  2816. this.center.copy( center );
  2817. this.radius = radius;
  2818. return this;
  2819. }
  2820. setFromPoints( points, optionalCenter ) {
  2821. const center = this.center;
  2822. if ( optionalCenter !== undefined ) {
  2823. center.copy( optionalCenter );
  2824. } else {
  2825. _box$2.setFromPoints( points ).getCenter( center );
  2826. }
  2827. let maxRadiusSq = 0;
  2828. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2829. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2830. }
  2831. this.radius = Math.sqrt( maxRadiusSq );
  2832. return this;
  2833. }
  2834. copy( sphere ) {
  2835. this.center.copy( sphere.center );
  2836. this.radius = sphere.radius;
  2837. return this;
  2838. }
  2839. isEmpty() {
  2840. return ( this.radius < 0 );
  2841. }
  2842. makeEmpty() {
  2843. this.center.set( 0, 0, 0 );
  2844. this.radius = - 1;
  2845. return this;
  2846. }
  2847. containsPoint( point ) {
  2848. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2849. }
  2850. distanceToPoint( point ) {
  2851. return ( point.distanceTo( this.center ) - this.radius );
  2852. }
  2853. intersectsSphere( sphere ) {
  2854. const radiusSum = this.radius + sphere.radius;
  2855. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2856. }
  2857. intersectsBox( box ) {
  2858. return box.intersectsSphere( this );
  2859. }
  2860. intersectsPlane( plane ) {
  2861. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2862. }
  2863. clampPoint( point, target ) {
  2864. const deltaLengthSq = this.center.distanceToSquared( point );
  2865. target.copy( point );
  2866. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2867. target.sub( this.center ).normalize();
  2868. target.multiplyScalar( this.radius ).add( this.center );
  2869. }
  2870. return target;
  2871. }
  2872. getBoundingBox( target ) {
  2873. if ( this.isEmpty() ) {
  2874. // Empty sphere produces empty bounding box
  2875. target.makeEmpty();
  2876. return target;
  2877. }
  2878. target.set( this.center, this.center );
  2879. target.expandByScalar( this.radius );
  2880. return target;
  2881. }
  2882. applyMatrix4( matrix ) {
  2883. this.center.applyMatrix4( matrix );
  2884. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2885. return this;
  2886. }
  2887. translate( offset ) {
  2888. this.center.add( offset );
  2889. return this;
  2890. }
  2891. expandByPoint( point ) {
  2892. // from https://github.com/juj/MathGeoLib/blob/2940b99b99cfe575dd45103ef20f4019dee15b54/src/Geometry/Sphere.cpp#L649-L671
  2893. _toPoint.subVectors( point, this.center );
  2894. const lengthSq = _toPoint.lengthSq();
  2895. if ( lengthSq > ( this.radius * this.radius ) ) {
  2896. const length = Math.sqrt( lengthSq );
  2897. const missingRadiusHalf = ( length - this.radius ) * 0.5;
  2898. // Nudge this sphere towards the target point. Add half the missing distance to radius,
  2899. // and the other half to position. This gives a tighter enclosure, instead of if
  2900. // the whole missing distance were just added to radius.
  2901. this.center.add( _toPoint.multiplyScalar( missingRadiusHalf / length ) );
  2902. this.radius += missingRadiusHalf;
  2903. }
  2904. return this;
  2905. }
  2906. union( sphere ) {
  2907. // from https://github.com/juj/MathGeoLib/blob/2940b99b99cfe575dd45103ef20f4019dee15b54/src/Geometry/Sphere.cpp#L759-L769
  2908. // To enclose another sphere into this sphere, we only need to enclose two points:
  2909. // 1) Enclose the farthest point on the other sphere into this sphere.
  2910. // 2) Enclose the opposite point of the farthest point into this sphere.
  2911. _toFarthestPoint.subVectors( sphere.center, this.center ).normalize().multiplyScalar( sphere.radius );
  2912. this.expandByPoint( _v1$6.copy( sphere.center ).add( _toFarthestPoint ) );
  2913. this.expandByPoint( _v1$6.copy( sphere.center ).sub( _toFarthestPoint ) );
  2914. return this;
  2915. }
  2916. equals( sphere ) {
  2917. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2918. }
  2919. clone() {
  2920. return new this.constructor().copy( this );
  2921. }
  2922. }
  2923. const _vector$a = /*@__PURE__*/ new Vector3();
  2924. const _segCenter = /*@__PURE__*/ new Vector3();
  2925. const _segDir = /*@__PURE__*/ new Vector3();
  2926. const _diff = /*@__PURE__*/ new Vector3();
  2927. const _edge1 = /*@__PURE__*/ new Vector3();
  2928. const _edge2 = /*@__PURE__*/ new Vector3();
  2929. const _normal$1 = /*@__PURE__*/ new Vector3();
  2930. class Ray {
  2931. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
  2932. this.origin = origin;
  2933. this.direction = direction;
  2934. }
  2935. set( origin, direction ) {
  2936. this.origin.copy( origin );
  2937. this.direction.copy( direction );
  2938. return this;
  2939. }
  2940. copy( ray ) {
  2941. this.origin.copy( ray.origin );
  2942. this.direction.copy( ray.direction );
  2943. return this;
  2944. }
  2945. at( t, target ) {
  2946. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  2947. }
  2948. lookAt( v ) {
  2949. this.direction.copy( v ).sub( this.origin ).normalize();
  2950. return this;
  2951. }
  2952. recast( t ) {
  2953. this.origin.copy( this.at( t, _vector$a ) );
  2954. return this;
  2955. }
  2956. closestPointToPoint( point, target ) {
  2957. target.subVectors( point, this.origin );
  2958. const directionDistance = target.dot( this.direction );
  2959. if ( directionDistance < 0 ) {
  2960. return target.copy( this.origin );
  2961. }
  2962. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2963. }
  2964. distanceToPoint( point ) {
  2965. return Math.sqrt( this.distanceSqToPoint( point ) );
  2966. }
  2967. distanceSqToPoint( point ) {
  2968. const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );
  2969. // point behind the ray
  2970. if ( directionDistance < 0 ) {
  2971. return this.origin.distanceToSquared( point );
  2972. }
  2973. _vector$a.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2974. return _vector$a.distanceToSquared( point );
  2975. }
  2976. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  2977. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  2978. // It returns the min distance between the ray and the segment
  2979. // defined by v0 and v1
  2980. // It can also set two optional targets :
  2981. // - The closest point on the ray
  2982. // - The closest point on the segment
  2983. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  2984. _segDir.copy( v1 ).sub( v0 ).normalize();
  2985. _diff.copy( this.origin ).sub( _segCenter );
  2986. const segExtent = v0.distanceTo( v1 ) * 0.5;
  2987. const a01 = - this.direction.dot( _segDir );
  2988. const b0 = _diff.dot( this.direction );
  2989. const b1 = - _diff.dot( _segDir );
  2990. const c = _diff.lengthSq();
  2991. const det = Math.abs( 1 - a01 * a01 );
  2992. let s0, s1, sqrDist, extDet;
  2993. if ( det > 0 ) {
  2994. // The ray and segment are not parallel.
  2995. s0 = a01 * b1 - b0;
  2996. s1 = a01 * b0 - b1;
  2997. extDet = segExtent * det;
  2998. if ( s0 >= 0 ) {
  2999. if ( s1 >= - extDet ) {
  3000. if ( s1 <= extDet ) {
  3001. // region 0
  3002. // Minimum at interior points of ray and segment.
  3003. const invDet = 1 / det;
  3004. s0 *= invDet;
  3005. s1 *= invDet;
  3006. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3007. } else {
  3008. // region 1
  3009. s1 = segExtent;
  3010. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3011. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3012. }
  3013. } else {
  3014. // region 5
  3015. s1 = - segExtent;
  3016. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3017. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3018. }
  3019. } else {
  3020. if ( s1 <= - extDet ) {
  3021. // region 4
  3022. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3023. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3024. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3025. } else if ( s1 <= extDet ) {
  3026. // region 3
  3027. s0 = 0;
  3028. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3029. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3030. } else {
  3031. // region 2
  3032. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3033. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3034. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3035. }
  3036. }
  3037. } else {
  3038. // Ray and segment are parallel.
  3039. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3040. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3041. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3042. }
  3043. if ( optionalPointOnRay ) {
  3044. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3045. }
  3046. if ( optionalPointOnSegment ) {
  3047. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  3048. }
  3049. return sqrDist;
  3050. }
  3051. intersectSphere( sphere, target ) {
  3052. _vector$a.subVectors( sphere.center, this.origin );
  3053. const tca = _vector$a.dot( this.direction );
  3054. const d2 = _vector$a.dot( _vector$a ) - tca * tca;
  3055. const radius2 = sphere.radius * sphere.radius;
  3056. if ( d2 > radius2 ) return null;
  3057. const thc = Math.sqrt( radius2 - d2 );
  3058. // t0 = first intersect point - entrance on front of sphere
  3059. const t0 = tca - thc;
  3060. // t1 = second intersect point - exit point on back of sphere
  3061. const t1 = tca + thc;
  3062. // test to see if both t0 and t1 are behind the ray - if so, return null
  3063. if ( t0 < 0 && t1 < 0 ) return null;
  3064. // test to see if t0 is behind the ray:
  3065. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3066. // in order to always return an intersect point that is in front of the ray.
  3067. if ( t0 < 0 ) return this.at( t1, target );
  3068. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3069. return this.at( t0, target );
  3070. }
  3071. intersectsSphere( sphere ) {
  3072. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  3073. }
  3074. distanceToPlane( plane ) {
  3075. const denominator = plane.normal.dot( this.direction );
  3076. if ( denominator === 0 ) {
  3077. // line is coplanar, return origin
  3078. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3079. return 0;
  3080. }
  3081. // Null is preferable to undefined since undefined means.... it is undefined
  3082. return null;
  3083. }
  3084. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3085. // Return if the ray never intersects the plane
  3086. return t >= 0 ? t : null;
  3087. }
  3088. intersectPlane( plane, target ) {
  3089. const t = this.distanceToPlane( plane );
  3090. if ( t === null ) {
  3091. return null;
  3092. }
  3093. return this.at( t, target );
  3094. }
  3095. intersectsPlane( plane ) {
  3096. // check if the ray lies on the plane first
  3097. const distToPoint = plane.distanceToPoint( this.origin );
  3098. if ( distToPoint === 0 ) {
  3099. return true;
  3100. }
  3101. const denominator = plane.normal.dot( this.direction );
  3102. if ( denominator * distToPoint < 0 ) {
  3103. return true;
  3104. }
  3105. // ray origin is behind the plane (and is pointing behind it)
  3106. return false;
  3107. }
  3108. intersectBox( box, target ) {
  3109. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  3110. const invdirx = 1 / this.direction.x,
  3111. invdiry = 1 / this.direction.y,
  3112. invdirz = 1 / this.direction.z;
  3113. const origin = this.origin;
  3114. if ( invdirx >= 0 ) {
  3115. tmin = ( box.min.x - origin.x ) * invdirx;
  3116. tmax = ( box.max.x - origin.x ) * invdirx;
  3117. } else {
  3118. tmin = ( box.max.x - origin.x ) * invdirx;
  3119. tmax = ( box.min.x - origin.x ) * invdirx;
  3120. }
  3121. if ( invdiry >= 0 ) {
  3122. tymin = ( box.min.y - origin.y ) * invdiry;
  3123. tymax = ( box.max.y - origin.y ) * invdiry;
  3124. } else {
  3125. tymin = ( box.max.y - origin.y ) * invdiry;
  3126. tymax = ( box.min.y - origin.y ) * invdiry;
  3127. }
  3128. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3129. // These lines also handle the case where tmin or tmax is NaN
  3130. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3131. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3132. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3133. if ( invdirz >= 0 ) {
  3134. tzmin = ( box.min.z - origin.z ) * invdirz;
  3135. tzmax = ( box.max.z - origin.z ) * invdirz;
  3136. } else {
  3137. tzmin = ( box.max.z - origin.z ) * invdirz;
  3138. tzmax = ( box.min.z - origin.z ) * invdirz;
  3139. }
  3140. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3141. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3142. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3143. //return point closest to the ray (positive side)
  3144. if ( tmax < 0 ) return null;
  3145. return this.at( tmin >= 0 ? tmin : tmax, target );
  3146. }
  3147. intersectsBox( box ) {
  3148. return this.intersectBox( box, _vector$a ) !== null;
  3149. }
  3150. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3151. // Compute the offset origin, edges, and normal.
  3152. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3153. _edge1.subVectors( b, a );
  3154. _edge2.subVectors( c, a );
  3155. _normal$1.crossVectors( _edge1, _edge2 );
  3156. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3157. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3158. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3159. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3160. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3161. let DdN = this.direction.dot( _normal$1 );
  3162. let sign;
  3163. if ( DdN > 0 ) {
  3164. if ( backfaceCulling ) return null;
  3165. sign = 1;
  3166. } else if ( DdN < 0 ) {
  3167. sign = - 1;
  3168. DdN = - DdN;
  3169. } else {
  3170. return null;
  3171. }
  3172. _diff.subVectors( this.origin, a );
  3173. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3174. // b1 < 0, no intersection
  3175. if ( DdQxE2 < 0 ) {
  3176. return null;
  3177. }
  3178. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3179. // b2 < 0, no intersection
  3180. if ( DdE1xQ < 0 ) {
  3181. return null;
  3182. }
  3183. // b1+b2 > 1, no intersection
  3184. if ( DdQxE2 + DdE1xQ > DdN ) {
  3185. return null;
  3186. }
  3187. // Line intersects triangle, check if ray does.
  3188. const QdN = - sign * _diff.dot( _normal$1 );
  3189. // t < 0, no intersection
  3190. if ( QdN < 0 ) {
  3191. return null;
  3192. }
  3193. // Ray intersects triangle.
  3194. return this.at( QdN / DdN, target );
  3195. }
  3196. applyMatrix4( matrix4 ) {
  3197. this.origin.applyMatrix4( matrix4 );
  3198. this.direction.transformDirection( matrix4 );
  3199. return this;
  3200. }
  3201. equals( ray ) {
  3202. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3203. }
  3204. clone() {
  3205. return new this.constructor().copy( this );
  3206. }
  3207. }
  3208. class Matrix4 {
  3209. constructor() {
  3210. this.elements = [
  3211. 1, 0, 0, 0,
  3212. 0, 1, 0, 0,
  3213. 0, 0, 1, 0,
  3214. 0, 0, 0, 1
  3215. ];
  3216. if ( arguments.length > 0 ) {
  3217. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3218. }
  3219. }
  3220. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3221. const te = this.elements;
  3222. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3223. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3224. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3225. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3226. return this;
  3227. }
  3228. identity() {
  3229. this.set(
  3230. 1, 0, 0, 0,
  3231. 0, 1, 0, 0,
  3232. 0, 0, 1, 0,
  3233. 0, 0, 0, 1
  3234. );
  3235. return this;
  3236. }
  3237. clone() {
  3238. return new Matrix4().fromArray( this.elements );
  3239. }
  3240. copy( m ) {
  3241. const te = this.elements;
  3242. const me = m.elements;
  3243. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3244. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3245. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3246. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3247. return this;
  3248. }
  3249. copyPosition( m ) {
  3250. const te = this.elements, me = m.elements;
  3251. te[ 12 ] = me[ 12 ];
  3252. te[ 13 ] = me[ 13 ];
  3253. te[ 14 ] = me[ 14 ];
  3254. return this;
  3255. }
  3256. setFromMatrix3( m ) {
  3257. const me = m.elements;
  3258. this.set(
  3259. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3260. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3261. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3262. 0, 0, 0, 1
  3263. );
  3264. return this;
  3265. }
  3266. extractBasis( xAxis, yAxis, zAxis ) {
  3267. xAxis.setFromMatrixColumn( this, 0 );
  3268. yAxis.setFromMatrixColumn( this, 1 );
  3269. zAxis.setFromMatrixColumn( this, 2 );
  3270. return this;
  3271. }
  3272. makeBasis( xAxis, yAxis, zAxis ) {
  3273. this.set(
  3274. xAxis.x, yAxis.x, zAxis.x, 0,
  3275. xAxis.y, yAxis.y, zAxis.y, 0,
  3276. xAxis.z, yAxis.z, zAxis.z, 0,
  3277. 0, 0, 0, 1
  3278. );
  3279. return this;
  3280. }
  3281. extractRotation( m ) {
  3282. // this method does not support reflection matrices
  3283. const te = this.elements;
  3284. const me = m.elements;
  3285. const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();
  3286. const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();
  3287. const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();
  3288. te[ 0 ] = me[ 0 ] * scaleX;
  3289. te[ 1 ] = me[ 1 ] * scaleX;
  3290. te[ 2 ] = me[ 2 ] * scaleX;
  3291. te[ 3 ] = 0;
  3292. te[ 4 ] = me[ 4 ] * scaleY;
  3293. te[ 5 ] = me[ 5 ] * scaleY;
  3294. te[ 6 ] = me[ 6 ] * scaleY;
  3295. te[ 7 ] = 0;
  3296. te[ 8 ] = me[ 8 ] * scaleZ;
  3297. te[ 9 ] = me[ 9 ] * scaleZ;
  3298. te[ 10 ] = me[ 10 ] * scaleZ;
  3299. te[ 11 ] = 0;
  3300. te[ 12 ] = 0;
  3301. te[ 13 ] = 0;
  3302. te[ 14 ] = 0;
  3303. te[ 15 ] = 1;
  3304. return this;
  3305. }
  3306. makeRotationFromEuler( euler ) {
  3307. if ( ! ( euler && euler.isEuler ) ) {
  3308. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3309. }
  3310. const te = this.elements;
  3311. const x = euler.x, y = euler.y, z = euler.z;
  3312. const a = Math.cos( x ), b = Math.sin( x );
  3313. const c = Math.cos( y ), d = Math.sin( y );
  3314. const e = Math.cos( z ), f = Math.sin( z );
  3315. if ( euler.order === 'XYZ' ) {
  3316. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3317. te[ 0 ] = c * e;
  3318. te[ 4 ] = - c * f;
  3319. te[ 8 ] = d;
  3320. te[ 1 ] = af + be * d;
  3321. te[ 5 ] = ae - bf * d;
  3322. te[ 9 ] = - b * c;
  3323. te[ 2 ] = bf - ae * d;
  3324. te[ 6 ] = be + af * d;
  3325. te[ 10 ] = a * c;
  3326. } else if ( euler.order === 'YXZ' ) {
  3327. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3328. te[ 0 ] = ce + df * b;
  3329. te[ 4 ] = de * b - cf;
  3330. te[ 8 ] = a * d;
  3331. te[ 1 ] = a * f;
  3332. te[ 5 ] = a * e;
  3333. te[ 9 ] = - b;
  3334. te[ 2 ] = cf * b - de;
  3335. te[ 6 ] = df + ce * b;
  3336. te[ 10 ] = a * c;
  3337. } else if ( euler.order === 'ZXY' ) {
  3338. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3339. te[ 0 ] = ce - df * b;
  3340. te[ 4 ] = - a * f;
  3341. te[ 8 ] = de + cf * b;
  3342. te[ 1 ] = cf + de * b;
  3343. te[ 5 ] = a * e;
  3344. te[ 9 ] = df - ce * b;
  3345. te[ 2 ] = - a * d;
  3346. te[ 6 ] = b;
  3347. te[ 10 ] = a * c;
  3348. } else if ( euler.order === 'ZYX' ) {
  3349. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3350. te[ 0 ] = c * e;
  3351. te[ 4 ] = be * d - af;
  3352. te[ 8 ] = ae * d + bf;
  3353. te[ 1 ] = c * f;
  3354. te[ 5 ] = bf * d + ae;
  3355. te[ 9 ] = af * d - be;
  3356. te[ 2 ] = - d;
  3357. te[ 6 ] = b * c;
  3358. te[ 10 ] = a * c;
  3359. } else if ( euler.order === 'YZX' ) {
  3360. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3361. te[ 0 ] = c * e;
  3362. te[ 4 ] = bd - ac * f;
  3363. te[ 8 ] = bc * f + ad;
  3364. te[ 1 ] = f;
  3365. te[ 5 ] = a * e;
  3366. te[ 9 ] = - b * e;
  3367. te[ 2 ] = - d * e;
  3368. te[ 6 ] = ad * f + bc;
  3369. te[ 10 ] = ac - bd * f;
  3370. } else if ( euler.order === 'XZY' ) {
  3371. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3372. te[ 0 ] = c * e;
  3373. te[ 4 ] = - f;
  3374. te[ 8 ] = d * e;
  3375. te[ 1 ] = ac * f + bd;
  3376. te[ 5 ] = a * e;
  3377. te[ 9 ] = ad * f - bc;
  3378. te[ 2 ] = bc * f - ad;
  3379. te[ 6 ] = b * e;
  3380. te[ 10 ] = bd * f + ac;
  3381. }
  3382. // bottom row
  3383. te[ 3 ] = 0;
  3384. te[ 7 ] = 0;
  3385. te[ 11 ] = 0;
  3386. // last column
  3387. te[ 12 ] = 0;
  3388. te[ 13 ] = 0;
  3389. te[ 14 ] = 0;
  3390. te[ 15 ] = 1;
  3391. return this;
  3392. }
  3393. makeRotationFromQuaternion( q ) {
  3394. return this.compose( _zero, q, _one );
  3395. }
  3396. lookAt( eye, target, up ) {
  3397. const te = this.elements;
  3398. _z.subVectors( eye, target );
  3399. if ( _z.lengthSq() === 0 ) {
  3400. // eye and target are in the same position
  3401. _z.z = 1;
  3402. }
  3403. _z.normalize();
  3404. _x.crossVectors( up, _z );
  3405. if ( _x.lengthSq() === 0 ) {
  3406. // up and z are parallel
  3407. if ( Math.abs( up.z ) === 1 ) {
  3408. _z.x += 0.0001;
  3409. } else {
  3410. _z.z += 0.0001;
  3411. }
  3412. _z.normalize();
  3413. _x.crossVectors( up, _z );
  3414. }
  3415. _x.normalize();
  3416. _y.crossVectors( _z, _x );
  3417. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3418. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3419. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3420. return this;
  3421. }
  3422. multiply( m, n ) {
  3423. if ( n !== undefined ) {
  3424. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3425. return this.multiplyMatrices( m, n );
  3426. }
  3427. return this.multiplyMatrices( this, m );
  3428. }
  3429. premultiply( m ) {
  3430. return this.multiplyMatrices( m, this );
  3431. }
  3432. multiplyMatrices( a, b ) {
  3433. const ae = a.elements;
  3434. const be = b.elements;
  3435. const te = this.elements;
  3436. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3437. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3438. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3439. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3440. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3441. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3442. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3443. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3444. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3445. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3446. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3447. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3448. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3449. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3450. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3451. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3452. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3453. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3454. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3455. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3456. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3457. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3458. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3459. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3460. return this;
  3461. }
  3462. multiplyScalar( s ) {
  3463. const te = this.elements;
  3464. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3465. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3466. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3467. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3468. return this;
  3469. }
  3470. determinant() {
  3471. const te = this.elements;
  3472. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3473. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3474. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3475. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3476. //TODO: make this more efficient
  3477. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3478. return (
  3479. n41 * (
  3480. + n14 * n23 * n32
  3481. - n13 * n24 * n32
  3482. - n14 * n22 * n33
  3483. + n12 * n24 * n33
  3484. + n13 * n22 * n34
  3485. - n12 * n23 * n34
  3486. ) +
  3487. n42 * (
  3488. + n11 * n23 * n34
  3489. - n11 * n24 * n33
  3490. + n14 * n21 * n33
  3491. - n13 * n21 * n34
  3492. + n13 * n24 * n31
  3493. - n14 * n23 * n31
  3494. ) +
  3495. n43 * (
  3496. + n11 * n24 * n32
  3497. - n11 * n22 * n34
  3498. - n14 * n21 * n32
  3499. + n12 * n21 * n34
  3500. + n14 * n22 * n31
  3501. - n12 * n24 * n31
  3502. ) +
  3503. n44 * (
  3504. - n13 * n22 * n31
  3505. - n11 * n23 * n32
  3506. + n11 * n22 * n33
  3507. + n13 * n21 * n32
  3508. - n12 * n21 * n33
  3509. + n12 * n23 * n31
  3510. )
  3511. );
  3512. }
  3513. transpose() {
  3514. const te = this.elements;
  3515. let tmp;
  3516. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3517. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3518. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3519. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3520. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3521. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3522. return this;
  3523. }
  3524. setPosition( x, y, z ) {
  3525. const te = this.elements;
  3526. if ( x.isVector3 ) {
  3527. te[ 12 ] = x.x;
  3528. te[ 13 ] = x.y;
  3529. te[ 14 ] = x.z;
  3530. } else {
  3531. te[ 12 ] = x;
  3532. te[ 13 ] = y;
  3533. te[ 14 ] = z;
  3534. }
  3535. return this;
  3536. }
  3537. invert() {
  3538. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3539. const te = this.elements,
  3540. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3541. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3542. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3543. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3544. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3545. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3546. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3547. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3548. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3549. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3550. const detInv = 1 / det;
  3551. te[ 0 ] = t11 * detInv;
  3552. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3553. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3554. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3555. te[ 4 ] = t12 * detInv;
  3556. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3557. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3558. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3559. te[ 8 ] = t13 * detInv;
  3560. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3561. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3562. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3563. te[ 12 ] = t14 * detInv;
  3564. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3565. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3566. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3567. return this;
  3568. }
  3569. scale( v ) {
  3570. const te = this.elements;
  3571. const x = v.x, y = v.y, z = v.z;
  3572. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3573. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3574. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3575. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3576. return this;
  3577. }
  3578. getMaxScaleOnAxis() {
  3579. const te = this.elements;
  3580. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3581. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3582. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3583. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3584. }
  3585. makeTranslation( x, y, z ) {
  3586. this.set(
  3587. 1, 0, 0, x,
  3588. 0, 1, 0, y,
  3589. 0, 0, 1, z,
  3590. 0, 0, 0, 1
  3591. );
  3592. return this;
  3593. }
  3594. makeRotationX( theta ) {
  3595. const c = Math.cos( theta ), s = Math.sin( theta );
  3596. this.set(
  3597. 1, 0, 0, 0,
  3598. 0, c, - s, 0,
  3599. 0, s, c, 0,
  3600. 0, 0, 0, 1
  3601. );
  3602. return this;
  3603. }
  3604. makeRotationY( theta ) {
  3605. const c = Math.cos( theta ), s = Math.sin( theta );
  3606. this.set(
  3607. c, 0, s, 0,
  3608. 0, 1, 0, 0,
  3609. - s, 0, c, 0,
  3610. 0, 0, 0, 1
  3611. );
  3612. return this;
  3613. }
  3614. makeRotationZ( theta ) {
  3615. const c = Math.cos( theta ), s = Math.sin( theta );
  3616. this.set(
  3617. c, - s, 0, 0,
  3618. s, c, 0, 0,
  3619. 0, 0, 1, 0,
  3620. 0, 0, 0, 1
  3621. );
  3622. return this;
  3623. }
  3624. makeRotationAxis( axis, angle ) {
  3625. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3626. const c = Math.cos( angle );
  3627. const s = Math.sin( angle );
  3628. const t = 1 - c;
  3629. const x = axis.x, y = axis.y, z = axis.z;
  3630. const tx = t * x, ty = t * y;
  3631. this.set(
  3632. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3633. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3634. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3635. 0, 0, 0, 1
  3636. );
  3637. return this;
  3638. }
  3639. makeScale( x, y, z ) {
  3640. this.set(
  3641. x, 0, 0, 0,
  3642. 0, y, 0, 0,
  3643. 0, 0, z, 0,
  3644. 0, 0, 0, 1
  3645. );
  3646. return this;
  3647. }
  3648. makeShear( xy, xz, yx, yz, zx, zy ) {
  3649. this.set(
  3650. 1, yx, zx, 0,
  3651. xy, 1, zy, 0,
  3652. xz, yz, 1, 0,
  3653. 0, 0, 0, 1
  3654. );
  3655. return this;
  3656. }
  3657. compose( position, quaternion, scale ) {
  3658. const te = this.elements;
  3659. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3660. const x2 = x + x, y2 = y + y, z2 = z + z;
  3661. const xx = x * x2, xy = x * y2, xz = x * z2;
  3662. const yy = y * y2, yz = y * z2, zz = z * z2;
  3663. const wx = w * x2, wy = w * y2, wz = w * z2;
  3664. const sx = scale.x, sy = scale.y, sz = scale.z;
  3665. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3666. te[ 1 ] = ( xy + wz ) * sx;
  3667. te[ 2 ] = ( xz - wy ) * sx;
  3668. te[ 3 ] = 0;
  3669. te[ 4 ] = ( xy - wz ) * sy;
  3670. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3671. te[ 6 ] = ( yz + wx ) * sy;
  3672. te[ 7 ] = 0;
  3673. te[ 8 ] = ( xz + wy ) * sz;
  3674. te[ 9 ] = ( yz - wx ) * sz;
  3675. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3676. te[ 11 ] = 0;
  3677. te[ 12 ] = position.x;
  3678. te[ 13 ] = position.y;
  3679. te[ 14 ] = position.z;
  3680. te[ 15 ] = 1;
  3681. return this;
  3682. }
  3683. decompose( position, quaternion, scale ) {
  3684. const te = this.elements;
  3685. let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3686. const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3687. const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3688. // if determine is negative, we need to invert one scale
  3689. const det = this.determinant();
  3690. if ( det < 0 ) sx = - sx;
  3691. position.x = te[ 12 ];
  3692. position.y = te[ 13 ];
  3693. position.z = te[ 14 ];
  3694. // scale the rotation part
  3695. _m1$2.copy( this );
  3696. const invSX = 1 / sx;
  3697. const invSY = 1 / sy;
  3698. const invSZ = 1 / sz;
  3699. _m1$2.elements[ 0 ] *= invSX;
  3700. _m1$2.elements[ 1 ] *= invSX;
  3701. _m1$2.elements[ 2 ] *= invSX;
  3702. _m1$2.elements[ 4 ] *= invSY;
  3703. _m1$2.elements[ 5 ] *= invSY;
  3704. _m1$2.elements[ 6 ] *= invSY;
  3705. _m1$2.elements[ 8 ] *= invSZ;
  3706. _m1$2.elements[ 9 ] *= invSZ;
  3707. _m1$2.elements[ 10 ] *= invSZ;
  3708. quaternion.setFromRotationMatrix( _m1$2 );
  3709. scale.x = sx;
  3710. scale.y = sy;
  3711. scale.z = sz;
  3712. return this;
  3713. }
  3714. makePerspective( left, right, top, bottom, near, far ) {
  3715. if ( far === undefined ) {
  3716. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3717. }
  3718. const te = this.elements;
  3719. const x = 2 * near / ( right - left );
  3720. const y = 2 * near / ( top - bottom );
  3721. const a = ( right + left ) / ( right - left );
  3722. const b = ( top + bottom ) / ( top - bottom );
  3723. const c = - ( far + near ) / ( far - near );
  3724. const d = - 2 * far * near / ( far - near );
  3725. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3726. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3727. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3728. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3729. return this;
  3730. }
  3731. makeOrthographic( left, right, top, bottom, near, far ) {
  3732. const te = this.elements;
  3733. const w = 1.0 / ( right - left );
  3734. const h = 1.0 / ( top - bottom );
  3735. const p = 1.0 / ( far - near );
  3736. const x = ( right + left ) * w;
  3737. const y = ( top + bottom ) * h;
  3738. const z = ( far + near ) * p;
  3739. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3740. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3741. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3742. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3743. return this;
  3744. }
  3745. equals( matrix ) {
  3746. const te = this.elements;
  3747. const me = matrix.elements;
  3748. for ( let i = 0; i < 16; i ++ ) {
  3749. if ( te[ i ] !== me[ i ] ) return false;
  3750. }
  3751. return true;
  3752. }
  3753. fromArray( array, offset = 0 ) {
  3754. for ( let i = 0; i < 16; i ++ ) {
  3755. this.elements[ i ] = array[ i + offset ];
  3756. }
  3757. return this;
  3758. }
  3759. toArray( array = [], offset = 0 ) {
  3760. const te = this.elements;
  3761. array[ offset ] = te[ 0 ];
  3762. array[ offset + 1 ] = te[ 1 ];
  3763. array[ offset + 2 ] = te[ 2 ];
  3764. array[ offset + 3 ] = te[ 3 ];
  3765. array[ offset + 4 ] = te[ 4 ];
  3766. array[ offset + 5 ] = te[ 5 ];
  3767. array[ offset + 6 ] = te[ 6 ];
  3768. array[ offset + 7 ] = te[ 7 ];
  3769. array[ offset + 8 ] = te[ 8 ];
  3770. array[ offset + 9 ] = te[ 9 ];
  3771. array[ offset + 10 ] = te[ 10 ];
  3772. array[ offset + 11 ] = te[ 11 ];
  3773. array[ offset + 12 ] = te[ 12 ];
  3774. array[ offset + 13 ] = te[ 13 ];
  3775. array[ offset + 14 ] = te[ 14 ];
  3776. array[ offset + 15 ] = te[ 15 ];
  3777. return array;
  3778. }
  3779. }
  3780. Matrix4.prototype.isMatrix4 = true;
  3781. const _v1$5 = /*@__PURE__*/ new Vector3();
  3782. const _m1$2 = /*@__PURE__*/ new Matrix4();
  3783. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  3784. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  3785. const _x = /*@__PURE__*/ new Vector3();
  3786. const _y = /*@__PURE__*/ new Vector3();
  3787. const _z = /*@__PURE__*/ new Vector3();
  3788. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  3789. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  3790. class Euler {
  3791. constructor( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
  3792. this._x = x;
  3793. this._y = y;
  3794. this._z = z;
  3795. this._order = order;
  3796. }
  3797. get x() {
  3798. return this._x;
  3799. }
  3800. set x( value ) {
  3801. this._x = value;
  3802. this._onChangeCallback();
  3803. }
  3804. get y() {
  3805. return this._y;
  3806. }
  3807. set y( value ) {
  3808. this._y = value;
  3809. this._onChangeCallback();
  3810. }
  3811. get z() {
  3812. return this._z;
  3813. }
  3814. set z( value ) {
  3815. this._z = value;
  3816. this._onChangeCallback();
  3817. }
  3818. get order() {
  3819. return this._order;
  3820. }
  3821. set order( value ) {
  3822. this._order = value;
  3823. this._onChangeCallback();
  3824. }
  3825. set( x, y, z, order = this._order ) {
  3826. this._x = x;
  3827. this._y = y;
  3828. this._z = z;
  3829. this._order = order;
  3830. this._onChangeCallback();
  3831. return this;
  3832. }
  3833. clone() {
  3834. return new this.constructor( this._x, this._y, this._z, this._order );
  3835. }
  3836. copy( euler ) {
  3837. this._x = euler._x;
  3838. this._y = euler._y;
  3839. this._z = euler._z;
  3840. this._order = euler._order;
  3841. this._onChangeCallback();
  3842. return this;
  3843. }
  3844. setFromRotationMatrix( m, order = this._order, update = true ) {
  3845. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3846. const te = m.elements;
  3847. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3848. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3849. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3850. switch ( order ) {
  3851. case 'XYZ':
  3852. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3853. if ( Math.abs( m13 ) < 0.9999999 ) {
  3854. this._x = Math.atan2( - m23, m33 );
  3855. this._z = Math.atan2( - m12, m11 );
  3856. } else {
  3857. this._x = Math.atan2( m32, m22 );
  3858. this._z = 0;
  3859. }
  3860. break;
  3861. case 'YXZ':
  3862. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3863. if ( Math.abs( m23 ) < 0.9999999 ) {
  3864. this._y = Math.atan2( m13, m33 );
  3865. this._z = Math.atan2( m21, m22 );
  3866. } else {
  3867. this._y = Math.atan2( - m31, m11 );
  3868. this._z = 0;
  3869. }
  3870. break;
  3871. case 'ZXY':
  3872. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3873. if ( Math.abs( m32 ) < 0.9999999 ) {
  3874. this._y = Math.atan2( - m31, m33 );
  3875. this._z = Math.atan2( - m12, m22 );
  3876. } else {
  3877. this._y = 0;
  3878. this._z = Math.atan2( m21, m11 );
  3879. }
  3880. break;
  3881. case 'ZYX':
  3882. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3883. if ( Math.abs( m31 ) < 0.9999999 ) {
  3884. this._x = Math.atan2( m32, m33 );
  3885. this._z = Math.atan2( m21, m11 );
  3886. } else {
  3887. this._x = 0;
  3888. this._z = Math.atan2( - m12, m22 );
  3889. }
  3890. break;
  3891. case 'YZX':
  3892. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3893. if ( Math.abs( m21 ) < 0.9999999 ) {
  3894. this._x = Math.atan2( - m23, m22 );
  3895. this._y = Math.atan2( - m31, m11 );
  3896. } else {
  3897. this._x = 0;
  3898. this._y = Math.atan2( m13, m33 );
  3899. }
  3900. break;
  3901. case 'XZY':
  3902. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3903. if ( Math.abs( m12 ) < 0.9999999 ) {
  3904. this._x = Math.atan2( m32, m22 );
  3905. this._y = Math.atan2( m13, m11 );
  3906. } else {
  3907. this._x = Math.atan2( - m23, m33 );
  3908. this._y = 0;
  3909. }
  3910. break;
  3911. default:
  3912. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3913. }
  3914. this._order = order;
  3915. if ( update === true ) this._onChangeCallback();
  3916. return this;
  3917. }
  3918. setFromQuaternion( q, order, update ) {
  3919. _matrix$1.makeRotationFromQuaternion( q );
  3920. return this.setFromRotationMatrix( _matrix$1, order, update );
  3921. }
  3922. setFromVector3( v, order = this._order ) {
  3923. return this.set( v.x, v.y, v.z, order );
  3924. }
  3925. reorder( newOrder ) {
  3926. // WARNING: this discards revolution information -bhouston
  3927. _quaternion$3.setFromEuler( this );
  3928. return this.setFromQuaternion( _quaternion$3, newOrder );
  3929. }
  3930. equals( euler ) {
  3931. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3932. }
  3933. fromArray( array ) {
  3934. this._x = array[ 0 ];
  3935. this._y = array[ 1 ];
  3936. this._z = array[ 2 ];
  3937. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3938. this._onChangeCallback();
  3939. return this;
  3940. }
  3941. toArray( array = [], offset = 0 ) {
  3942. array[ offset ] = this._x;
  3943. array[ offset + 1 ] = this._y;
  3944. array[ offset + 2 ] = this._z;
  3945. array[ offset + 3 ] = this._order;
  3946. return array;
  3947. }
  3948. toVector3( optionalResult ) {
  3949. if ( optionalResult ) {
  3950. return optionalResult.set( this._x, this._y, this._z );
  3951. } else {
  3952. return new Vector3( this._x, this._y, this._z );
  3953. }
  3954. }
  3955. _onChange( callback ) {
  3956. this._onChangeCallback = callback;
  3957. return this;
  3958. }
  3959. _onChangeCallback() {}
  3960. }
  3961. Euler.prototype.isEuler = true;
  3962. Euler.DefaultOrder = 'XYZ';
  3963. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3964. class Layers {
  3965. constructor() {
  3966. this.mask = 1 | 0;
  3967. }
  3968. set( channel ) {
  3969. this.mask = 1 << channel | 0;
  3970. }
  3971. enable( channel ) {
  3972. this.mask |= 1 << channel | 0;
  3973. }
  3974. enableAll() {
  3975. this.mask = 0xffffffff | 0;
  3976. }
  3977. toggle( channel ) {
  3978. this.mask ^= 1 << channel | 0;
  3979. }
  3980. disable( channel ) {
  3981. this.mask &= ~ ( 1 << channel | 0 );
  3982. }
  3983. disableAll() {
  3984. this.mask = 0;
  3985. }
  3986. test( layers ) {
  3987. return ( this.mask & layers.mask ) !== 0;
  3988. }
  3989. }
  3990. let _object3DId = 0;
  3991. const _v1$4 = /*@__PURE__*/ new Vector3();
  3992. const _q1 = /*@__PURE__*/ new Quaternion();
  3993. const _m1$1 = /*@__PURE__*/ new Matrix4();
  3994. const _target = /*@__PURE__*/ new Vector3();
  3995. const _position$3 = /*@__PURE__*/ new Vector3();
  3996. const _scale$2 = /*@__PURE__*/ new Vector3();
  3997. const _quaternion$2 = /*@__PURE__*/ new Quaternion();
  3998. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  3999. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4000. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  4001. const _addedEvent = { type: 'added' };
  4002. const _removedEvent = { type: 'removed' };
  4003. class Object3D extends EventDispatcher {
  4004. constructor() {
  4005. super();
  4006. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  4007. this.uuid = generateUUID();
  4008. this.name = '';
  4009. this.type = 'Object3D';
  4010. this.parent = null;
  4011. this.children = [];
  4012. this.up = Object3D.DefaultUp.clone();
  4013. const position = new Vector3();
  4014. const rotation = new Euler();
  4015. const quaternion = new Quaternion();
  4016. const scale = new Vector3( 1, 1, 1 );
  4017. function onRotationChange() {
  4018. quaternion.setFromEuler( rotation, false );
  4019. }
  4020. function onQuaternionChange() {
  4021. rotation.setFromQuaternion( quaternion, undefined, false );
  4022. }
  4023. rotation._onChange( onRotationChange );
  4024. quaternion._onChange( onQuaternionChange );
  4025. Object.defineProperties( this, {
  4026. position: {
  4027. configurable: true,
  4028. enumerable: true,
  4029. value: position
  4030. },
  4031. rotation: {
  4032. configurable: true,
  4033. enumerable: true,
  4034. value: rotation
  4035. },
  4036. quaternion: {
  4037. configurable: true,
  4038. enumerable: true,
  4039. value: quaternion
  4040. },
  4041. scale: {
  4042. configurable: true,
  4043. enumerable: true,
  4044. value: scale
  4045. },
  4046. modelViewMatrix: {
  4047. value: new Matrix4()
  4048. },
  4049. normalMatrix: {
  4050. value: new Matrix3()
  4051. }
  4052. } );
  4053. this.matrix = new Matrix4();
  4054. this.matrixWorld = new Matrix4();
  4055. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  4056. this.matrixWorldNeedsUpdate = false;
  4057. this.layers = new Layers();
  4058. this.visible = true;
  4059. this.castShadow = false;
  4060. this.receiveShadow = false;
  4061. this.frustumCulled = true;
  4062. this.renderOrder = 0;
  4063. this.animations = [];
  4064. this.userData = {};
  4065. }
  4066. onBeforeRender() {}
  4067. onAfterRender() {}
  4068. applyMatrix4( matrix ) {
  4069. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4070. this.matrix.premultiply( matrix );
  4071. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4072. }
  4073. applyQuaternion( q ) {
  4074. this.quaternion.premultiply( q );
  4075. return this;
  4076. }
  4077. setRotationFromAxisAngle( axis, angle ) {
  4078. // assumes axis is normalized
  4079. this.quaternion.setFromAxisAngle( axis, angle );
  4080. }
  4081. setRotationFromEuler( euler ) {
  4082. this.quaternion.setFromEuler( euler, true );
  4083. }
  4084. setRotationFromMatrix( m ) {
  4085. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4086. this.quaternion.setFromRotationMatrix( m );
  4087. }
  4088. setRotationFromQuaternion( q ) {
  4089. // assumes q is normalized
  4090. this.quaternion.copy( q );
  4091. }
  4092. rotateOnAxis( axis, angle ) {
  4093. // rotate object on axis in object space
  4094. // axis is assumed to be normalized
  4095. _q1.setFromAxisAngle( axis, angle );
  4096. this.quaternion.multiply( _q1 );
  4097. return this;
  4098. }
  4099. rotateOnWorldAxis( axis, angle ) {
  4100. // rotate object on axis in world space
  4101. // axis is assumed to be normalized
  4102. // method assumes no rotated parent
  4103. _q1.setFromAxisAngle( axis, angle );
  4104. this.quaternion.premultiply( _q1 );
  4105. return this;
  4106. }
  4107. rotateX( angle ) {
  4108. return this.rotateOnAxis( _xAxis, angle );
  4109. }
  4110. rotateY( angle ) {
  4111. return this.rotateOnAxis( _yAxis, angle );
  4112. }
  4113. rotateZ( angle ) {
  4114. return this.rotateOnAxis( _zAxis, angle );
  4115. }
  4116. translateOnAxis( axis, distance ) {
  4117. // translate object by distance along axis in object space
  4118. // axis is assumed to be normalized
  4119. _v1$4.copy( axis ).applyQuaternion( this.quaternion );
  4120. this.position.add( _v1$4.multiplyScalar( distance ) );
  4121. return this;
  4122. }
  4123. translateX( distance ) {
  4124. return this.translateOnAxis( _xAxis, distance );
  4125. }
  4126. translateY( distance ) {
  4127. return this.translateOnAxis( _yAxis, distance );
  4128. }
  4129. translateZ( distance ) {
  4130. return this.translateOnAxis( _zAxis, distance );
  4131. }
  4132. localToWorld( vector ) {
  4133. return vector.applyMatrix4( this.matrixWorld );
  4134. }
  4135. worldToLocal( vector ) {
  4136. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4137. }
  4138. lookAt( x, y, z ) {
  4139. // This method does not support objects having non-uniformly-scaled parent(s)
  4140. if ( x.isVector3 ) {
  4141. _target.copy( x );
  4142. } else {
  4143. _target.set( x, y, z );
  4144. }
  4145. const parent = this.parent;
  4146. this.updateWorldMatrix( true, false );
  4147. _position$3.setFromMatrixPosition( this.matrixWorld );
  4148. if ( this.isCamera || this.isLight ) {
  4149. _m1$1.lookAt( _position$3, _target, this.up );
  4150. } else {
  4151. _m1$1.lookAt( _target, _position$3, this.up );
  4152. }
  4153. this.quaternion.setFromRotationMatrix( _m1$1 );
  4154. if ( parent ) {
  4155. _m1$1.extractRotation( parent.matrixWorld );
  4156. _q1.setFromRotationMatrix( _m1$1 );
  4157. this.quaternion.premultiply( _q1.invert() );
  4158. }
  4159. }
  4160. add( object ) {
  4161. if ( arguments.length > 1 ) {
  4162. for ( let i = 0; i < arguments.length; i ++ ) {
  4163. this.add( arguments[ i ] );
  4164. }
  4165. return this;
  4166. }
  4167. if ( object === this ) {
  4168. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4169. return this;
  4170. }
  4171. if ( object && object.isObject3D ) {
  4172. if ( object.parent !== null ) {
  4173. object.parent.remove( object );
  4174. }
  4175. object.parent = this;
  4176. this.children.push( object );
  4177. object.dispatchEvent( _addedEvent );
  4178. } else {
  4179. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4180. }
  4181. return this;
  4182. }
  4183. remove( object ) {
  4184. if ( arguments.length > 1 ) {
  4185. for ( let i = 0; i < arguments.length; i ++ ) {
  4186. this.remove( arguments[ i ] );
  4187. }
  4188. return this;
  4189. }
  4190. const index = this.children.indexOf( object );
  4191. if ( index !== - 1 ) {
  4192. object.parent = null;
  4193. this.children.splice( index, 1 );
  4194. object.dispatchEvent( _removedEvent );
  4195. }
  4196. return this;
  4197. }
  4198. removeFromParent() {
  4199. const parent = this.parent;
  4200. if ( parent !== null ) {
  4201. parent.remove( this );
  4202. }
  4203. return this;
  4204. }
  4205. clear() {
  4206. for ( let i = 0; i < this.children.length; i ++ ) {
  4207. const object = this.children[ i ];
  4208. object.parent = null;
  4209. object.dispatchEvent( _removedEvent );
  4210. }
  4211. this.children.length = 0;
  4212. return this;
  4213. }
  4214. attach( object ) {
  4215. // adds object as a child of this, while maintaining the object's world transform
  4216. this.updateWorldMatrix( true, false );
  4217. _m1$1.copy( this.matrixWorld ).invert();
  4218. if ( object.parent !== null ) {
  4219. object.parent.updateWorldMatrix( true, false );
  4220. _m1$1.multiply( object.parent.matrixWorld );
  4221. }
  4222. object.applyMatrix4( _m1$1 );
  4223. this.add( object );
  4224. object.updateWorldMatrix( false, true );
  4225. return this;
  4226. }
  4227. getObjectById( id ) {
  4228. return this.getObjectByProperty( 'id', id );
  4229. }
  4230. getObjectByName( name ) {
  4231. return this.getObjectByProperty( 'name', name );
  4232. }
  4233. getObjectByProperty( name, value ) {
  4234. if ( this[ name ] === value ) return this;
  4235. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4236. const child = this.children[ i ];
  4237. const object = child.getObjectByProperty( name, value );
  4238. if ( object !== undefined ) {
  4239. return object;
  4240. }
  4241. }
  4242. return undefined;
  4243. }
  4244. getWorldPosition( target ) {
  4245. this.updateWorldMatrix( true, false );
  4246. return target.setFromMatrixPosition( this.matrixWorld );
  4247. }
  4248. getWorldQuaternion( target ) {
  4249. this.updateWorldMatrix( true, false );
  4250. this.matrixWorld.decompose( _position$3, target, _scale$2 );
  4251. return target;
  4252. }
  4253. getWorldScale( target ) {
  4254. this.updateWorldMatrix( true, false );
  4255. this.matrixWorld.decompose( _position$3, _quaternion$2, target );
  4256. return target;
  4257. }
  4258. getWorldDirection( target ) {
  4259. this.updateWorldMatrix( true, false );
  4260. const e = this.matrixWorld.elements;
  4261. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4262. }
  4263. raycast() {}
  4264. traverse( callback ) {
  4265. callback( this );
  4266. const children = this.children;
  4267. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4268. children[ i ].traverse( callback );
  4269. }
  4270. }
  4271. traverseVisible( callback ) {
  4272. if ( this.visible === false ) return;
  4273. callback( this );
  4274. const children = this.children;
  4275. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4276. children[ i ].traverseVisible( callback );
  4277. }
  4278. }
  4279. traverseAncestors( callback ) {
  4280. const parent = this.parent;
  4281. if ( parent !== null ) {
  4282. callback( parent );
  4283. parent.traverseAncestors( callback );
  4284. }
  4285. }
  4286. updateMatrix() {
  4287. this.matrix.compose( this.position, this.quaternion, this.scale );
  4288. this.matrixWorldNeedsUpdate = true;
  4289. }
  4290. updateMatrixWorld( force ) {
  4291. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4292. if ( this.matrixWorldNeedsUpdate || force ) {
  4293. if ( this.parent === null ) {
  4294. this.matrixWorld.copy( this.matrix );
  4295. } else {
  4296. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4297. }
  4298. this.matrixWorldNeedsUpdate = false;
  4299. force = true;
  4300. }
  4301. // update children
  4302. const children = this.children;
  4303. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4304. children[ i ].updateMatrixWorld( force );
  4305. }
  4306. }
  4307. updateWorldMatrix( updateParents, updateChildren ) {
  4308. const parent = this.parent;
  4309. if ( updateParents === true && parent !== null ) {
  4310. parent.updateWorldMatrix( true, false );
  4311. }
  4312. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4313. if ( this.parent === null ) {
  4314. this.matrixWorld.copy( this.matrix );
  4315. } else {
  4316. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4317. }
  4318. // update children
  4319. if ( updateChildren === true ) {
  4320. const children = this.children;
  4321. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4322. children[ i ].updateWorldMatrix( false, true );
  4323. }
  4324. }
  4325. }
  4326. toJSON( meta ) {
  4327. // meta is a string when called from JSON.stringify
  4328. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4329. const output = {};
  4330. // meta is a hash used to collect geometries, materials.
  4331. // not providing it implies that this is the root object
  4332. // being serialized.
  4333. if ( isRootObject ) {
  4334. // initialize meta obj
  4335. meta = {
  4336. geometries: {},
  4337. materials: {},
  4338. textures: {},
  4339. images: {},
  4340. shapes: {},
  4341. skeletons: {},
  4342. animations: {}
  4343. };
  4344. output.metadata = {
  4345. version: 4.5,
  4346. type: 'Object',
  4347. generator: 'Object3D.toJSON'
  4348. };
  4349. }
  4350. // standard Object3D serialization
  4351. const object = {};
  4352. object.uuid = this.uuid;
  4353. object.type = this.type;
  4354. if ( this.name !== '' ) object.name = this.name;
  4355. if ( this.castShadow === true ) object.castShadow = true;
  4356. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4357. if ( this.visible === false ) object.visible = false;
  4358. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4359. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4360. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4361. object.layers = this.layers.mask;
  4362. object.matrix = this.matrix.toArray();
  4363. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4364. // object specific properties
  4365. if ( this.isInstancedMesh ) {
  4366. object.type = 'InstancedMesh';
  4367. object.count = this.count;
  4368. object.instanceMatrix = this.instanceMatrix.toJSON();
  4369. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  4370. }
  4371. //
  4372. function serialize( library, element ) {
  4373. if ( library[ element.uuid ] === undefined ) {
  4374. library[ element.uuid ] = element.toJSON( meta );
  4375. }
  4376. return element.uuid;
  4377. }
  4378. if ( this.isScene ) {
  4379. if ( this.background ) {
  4380. if ( this.background.isColor ) {
  4381. object.background = this.background.toJSON();
  4382. } else if ( this.background.isTexture ) {
  4383. object.background = this.background.toJSON( meta ).uuid;
  4384. }
  4385. }
  4386. if ( this.environment && this.environment.isTexture ) {
  4387. object.environment = this.environment.toJSON( meta ).uuid;
  4388. }
  4389. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  4390. object.geometry = serialize( meta.geometries, this.geometry );
  4391. const parameters = this.geometry.parameters;
  4392. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4393. const shapes = parameters.shapes;
  4394. if ( Array.isArray( shapes ) ) {
  4395. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4396. const shape = shapes[ i ];
  4397. serialize( meta.shapes, shape );
  4398. }
  4399. } else {
  4400. serialize( meta.shapes, shapes );
  4401. }
  4402. }
  4403. }
  4404. if ( this.isSkinnedMesh ) {
  4405. object.bindMode = this.bindMode;
  4406. object.bindMatrix = this.bindMatrix.toArray();
  4407. if ( this.skeleton !== undefined ) {
  4408. serialize( meta.skeletons, this.skeleton );
  4409. object.skeleton = this.skeleton.uuid;
  4410. }
  4411. }
  4412. if ( this.material !== undefined ) {
  4413. if ( Array.isArray( this.material ) ) {
  4414. const uuids = [];
  4415. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4416. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4417. }
  4418. object.material = uuids;
  4419. } else {
  4420. object.material = serialize( meta.materials, this.material );
  4421. }
  4422. }
  4423. //
  4424. if ( this.children.length > 0 ) {
  4425. object.children = [];
  4426. for ( let i = 0; i < this.children.length; i ++ ) {
  4427. object.children.push( this.children[ i ].toJSON( meta ).object );
  4428. }
  4429. }
  4430. //
  4431. if ( this.animations.length > 0 ) {
  4432. object.animations = [];
  4433. for ( let i = 0; i < this.animations.length; i ++ ) {
  4434. const animation = this.animations[ i ];
  4435. object.animations.push( serialize( meta.animations, animation ) );
  4436. }
  4437. }
  4438. if ( isRootObject ) {
  4439. const geometries = extractFromCache( meta.geometries );
  4440. const materials = extractFromCache( meta.materials );
  4441. const textures = extractFromCache( meta.textures );
  4442. const images = extractFromCache( meta.images );
  4443. const shapes = extractFromCache( meta.shapes );
  4444. const skeletons = extractFromCache( meta.skeletons );
  4445. const animations = extractFromCache( meta.animations );
  4446. if ( geometries.length > 0 ) output.geometries = geometries;
  4447. if ( materials.length > 0 ) output.materials = materials;
  4448. if ( textures.length > 0 ) output.textures = textures;
  4449. if ( images.length > 0 ) output.images = images;
  4450. if ( shapes.length > 0 ) output.shapes = shapes;
  4451. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4452. if ( animations.length > 0 ) output.animations = animations;
  4453. }
  4454. output.object = object;
  4455. return output;
  4456. // extract data from the cache hash
  4457. // remove metadata on each item
  4458. // and return as array
  4459. function extractFromCache( cache ) {
  4460. const values = [];
  4461. for ( const key in cache ) {
  4462. const data = cache[ key ];
  4463. delete data.metadata;
  4464. values.push( data );
  4465. }
  4466. return values;
  4467. }
  4468. }
  4469. clone( recursive ) {
  4470. return new this.constructor().copy( this, recursive );
  4471. }
  4472. copy( source, recursive = true ) {
  4473. this.name = source.name;
  4474. this.up.copy( source.up );
  4475. this.position.copy( source.position );
  4476. this.rotation.order = source.rotation.order;
  4477. this.quaternion.copy( source.quaternion );
  4478. this.scale.copy( source.scale );
  4479. this.matrix.copy( source.matrix );
  4480. this.matrixWorld.copy( source.matrixWorld );
  4481. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4482. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4483. this.layers.mask = source.layers.mask;
  4484. this.visible = source.visible;
  4485. this.castShadow = source.castShadow;
  4486. this.receiveShadow = source.receiveShadow;
  4487. this.frustumCulled = source.frustumCulled;
  4488. this.renderOrder = source.renderOrder;
  4489. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4490. if ( recursive === true ) {
  4491. for ( let i = 0; i < source.children.length; i ++ ) {
  4492. const child = source.children[ i ];
  4493. this.add( child.clone() );
  4494. }
  4495. }
  4496. return this;
  4497. }
  4498. }
  4499. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  4500. Object3D.DefaultMatrixAutoUpdate = true;
  4501. Object3D.prototype.isObject3D = true;
  4502. const _v0$1 = /*@__PURE__*/ new Vector3();
  4503. const _v1$3 = /*@__PURE__*/ new Vector3();
  4504. const _v2$2 = /*@__PURE__*/ new Vector3();
  4505. const _v3$1 = /*@__PURE__*/ new Vector3();
  4506. const _vab = /*@__PURE__*/ new Vector3();
  4507. const _vac = /*@__PURE__*/ new Vector3();
  4508. const _vbc = /*@__PURE__*/ new Vector3();
  4509. const _vap = /*@__PURE__*/ new Vector3();
  4510. const _vbp = /*@__PURE__*/ new Vector3();
  4511. const _vcp = /*@__PURE__*/ new Vector3();
  4512. class Triangle {
  4513. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4514. this.a = a;
  4515. this.b = b;
  4516. this.c = c;
  4517. }
  4518. static getNormal( a, b, c, target ) {
  4519. target.subVectors( c, b );
  4520. _v0$1.subVectors( a, b );
  4521. target.cross( _v0$1 );
  4522. const targetLengthSq = target.lengthSq();
  4523. if ( targetLengthSq > 0 ) {
  4524. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4525. }
  4526. return target.set( 0, 0, 0 );
  4527. }
  4528. // static/instance method to calculate barycentric coordinates
  4529. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4530. static getBarycoord( point, a, b, c, target ) {
  4531. _v0$1.subVectors( c, a );
  4532. _v1$3.subVectors( b, a );
  4533. _v2$2.subVectors( point, a );
  4534. const dot00 = _v0$1.dot( _v0$1 );
  4535. const dot01 = _v0$1.dot( _v1$3 );
  4536. const dot02 = _v0$1.dot( _v2$2 );
  4537. const dot11 = _v1$3.dot( _v1$3 );
  4538. const dot12 = _v1$3.dot( _v2$2 );
  4539. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4540. // collinear or singular triangle
  4541. if ( denom === 0 ) {
  4542. // arbitrary location outside of triangle?
  4543. // not sure if this is the best idea, maybe should be returning undefined
  4544. return target.set( - 2, - 1, - 1 );
  4545. }
  4546. const invDenom = 1 / denom;
  4547. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4548. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4549. // barycentric coordinates must always sum to 1
  4550. return target.set( 1 - u - v, v, u );
  4551. }
  4552. static containsPoint( point, a, b, c ) {
  4553. this.getBarycoord( point, a, b, c, _v3$1 );
  4554. return ( _v3$1.x >= 0 ) && ( _v3$1.y >= 0 ) && ( ( _v3$1.x + _v3$1.y ) <= 1 );
  4555. }
  4556. static getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4557. this.getBarycoord( point, p1, p2, p3, _v3$1 );
  4558. target.set( 0, 0 );
  4559. target.addScaledVector( uv1, _v3$1.x );
  4560. target.addScaledVector( uv2, _v3$1.y );
  4561. target.addScaledVector( uv3, _v3$1.z );
  4562. return target;
  4563. }
  4564. static isFrontFacing( a, b, c, direction ) {
  4565. _v0$1.subVectors( c, b );
  4566. _v1$3.subVectors( a, b );
  4567. // strictly front facing
  4568. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4569. }
  4570. set( a, b, c ) {
  4571. this.a.copy( a );
  4572. this.b.copy( b );
  4573. this.c.copy( c );
  4574. return this;
  4575. }
  4576. setFromPointsAndIndices( points, i0, i1, i2 ) {
  4577. this.a.copy( points[ i0 ] );
  4578. this.b.copy( points[ i1 ] );
  4579. this.c.copy( points[ i2 ] );
  4580. return this;
  4581. }
  4582. setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
  4583. this.a.fromBufferAttribute( attribute, i0 );
  4584. this.b.fromBufferAttribute( attribute, i1 );
  4585. this.c.fromBufferAttribute( attribute, i2 );
  4586. return this;
  4587. }
  4588. clone() {
  4589. return new this.constructor().copy( this );
  4590. }
  4591. copy( triangle ) {
  4592. this.a.copy( triangle.a );
  4593. this.b.copy( triangle.b );
  4594. this.c.copy( triangle.c );
  4595. return this;
  4596. }
  4597. getArea() {
  4598. _v0$1.subVectors( this.c, this.b );
  4599. _v1$3.subVectors( this.a, this.b );
  4600. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4601. }
  4602. getMidpoint( target ) {
  4603. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4604. }
  4605. getNormal( target ) {
  4606. return Triangle.getNormal( this.a, this.b, this.c, target );
  4607. }
  4608. getPlane( target ) {
  4609. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4610. }
  4611. getBarycoord( point, target ) {
  4612. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4613. }
  4614. getUV( point, uv1, uv2, uv3, target ) {
  4615. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4616. }
  4617. containsPoint( point ) {
  4618. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4619. }
  4620. isFrontFacing( direction ) {
  4621. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4622. }
  4623. intersectsBox( box ) {
  4624. return box.intersectsTriangle( this );
  4625. }
  4626. closestPointToPoint( p, target ) {
  4627. const a = this.a, b = this.b, c = this.c;
  4628. let v, w;
  4629. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4630. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4631. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4632. // basically, we're distinguishing which of the voronoi regions of the triangle
  4633. // the point lies in with the minimum amount of redundant computation.
  4634. _vab.subVectors( b, a );
  4635. _vac.subVectors( c, a );
  4636. _vap.subVectors( p, a );
  4637. const d1 = _vab.dot( _vap );
  4638. const d2 = _vac.dot( _vap );
  4639. if ( d1 <= 0 && d2 <= 0 ) {
  4640. // vertex region of A; barycentric coords (1, 0, 0)
  4641. return target.copy( a );
  4642. }
  4643. _vbp.subVectors( p, b );
  4644. const d3 = _vab.dot( _vbp );
  4645. const d4 = _vac.dot( _vbp );
  4646. if ( d3 >= 0 && d4 <= d3 ) {
  4647. // vertex region of B; barycentric coords (0, 1, 0)
  4648. return target.copy( b );
  4649. }
  4650. const vc = d1 * d4 - d3 * d2;
  4651. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4652. v = d1 / ( d1 - d3 );
  4653. // edge region of AB; barycentric coords (1-v, v, 0)
  4654. return target.copy( a ).addScaledVector( _vab, v );
  4655. }
  4656. _vcp.subVectors( p, c );
  4657. const d5 = _vab.dot( _vcp );
  4658. const d6 = _vac.dot( _vcp );
  4659. if ( d6 >= 0 && d5 <= d6 ) {
  4660. // vertex region of C; barycentric coords (0, 0, 1)
  4661. return target.copy( c );
  4662. }
  4663. const vb = d5 * d2 - d1 * d6;
  4664. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4665. w = d2 / ( d2 - d6 );
  4666. // edge region of AC; barycentric coords (1-w, 0, w)
  4667. return target.copy( a ).addScaledVector( _vac, w );
  4668. }
  4669. const va = d3 * d6 - d5 * d4;
  4670. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4671. _vbc.subVectors( c, b );
  4672. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4673. // edge region of BC; barycentric coords (0, 1-w, w)
  4674. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4675. }
  4676. // face region
  4677. const denom = 1 / ( va + vb + vc );
  4678. // u = va * denom
  4679. v = vb * denom;
  4680. w = vc * denom;
  4681. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4682. }
  4683. equals( triangle ) {
  4684. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4685. }
  4686. }
  4687. let materialId = 0;
  4688. class Material extends EventDispatcher {
  4689. constructor() {
  4690. super();
  4691. Object.defineProperty( this, 'id', { value: materialId ++ } );
  4692. this.uuid = generateUUID();
  4693. this.name = '';
  4694. this.type = 'Material';
  4695. this.fog = true;
  4696. this.blending = NormalBlending;
  4697. this.side = FrontSide;
  4698. this.vertexColors = false;
  4699. this.opacity = 1;
  4700. this.format = RGBAFormat;
  4701. this.transparent = false;
  4702. this.blendSrc = SrcAlphaFactor;
  4703. this.blendDst = OneMinusSrcAlphaFactor;
  4704. this.blendEquation = AddEquation;
  4705. this.blendSrcAlpha = null;
  4706. this.blendDstAlpha = null;
  4707. this.blendEquationAlpha = null;
  4708. this.depthFunc = LessEqualDepth;
  4709. this.depthTest = true;
  4710. this.depthWrite = true;
  4711. this.stencilWriteMask = 0xff;
  4712. this.stencilFunc = AlwaysStencilFunc;
  4713. this.stencilRef = 0;
  4714. this.stencilFuncMask = 0xff;
  4715. this.stencilFail = KeepStencilOp;
  4716. this.stencilZFail = KeepStencilOp;
  4717. this.stencilZPass = KeepStencilOp;
  4718. this.stencilWrite = false;
  4719. this.clippingPlanes = null;
  4720. this.clipIntersection = false;
  4721. this.clipShadows = false;
  4722. this.shadowSide = null;
  4723. this.colorWrite = true;
  4724. this.precision = null; // override the renderer's default precision for this material
  4725. this.polygonOffset = false;
  4726. this.polygonOffsetFactor = 0;
  4727. this.polygonOffsetUnits = 0;
  4728. this.dithering = false;
  4729. this.alphaToCoverage = false;
  4730. this.premultipliedAlpha = false;
  4731. this.visible = true;
  4732. this.toneMapped = true;
  4733. this.userData = {};
  4734. this.version = 0;
  4735. this._alphaTest = 0;
  4736. }
  4737. get alphaTest() {
  4738. return this._alphaTest;
  4739. }
  4740. set alphaTest( value ) {
  4741. if ( this._alphaTest > 0 !== value > 0 ) {
  4742. this.version ++;
  4743. }
  4744. this._alphaTest = value;
  4745. }
  4746. onBuild( /* shaderobject, renderer */ ) {}
  4747. onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}
  4748. onBeforeCompile( /* shaderobject, renderer */ ) {}
  4749. customProgramCacheKey() {
  4750. return this.onBeforeCompile.toString();
  4751. }
  4752. setValues( values ) {
  4753. if ( values === undefined ) return;
  4754. for ( const key in values ) {
  4755. const newValue = values[ key ];
  4756. if ( newValue === undefined ) {
  4757. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  4758. continue;
  4759. }
  4760. // for backward compatability if shading is set in the constructor
  4761. if ( key === 'shading' ) {
  4762. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  4763. this.flatShading = ( newValue === FlatShading ) ? true : false;
  4764. continue;
  4765. }
  4766. const currentValue = this[ key ];
  4767. if ( currentValue === undefined ) {
  4768. console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  4769. continue;
  4770. }
  4771. if ( currentValue && currentValue.isColor ) {
  4772. currentValue.set( newValue );
  4773. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  4774. currentValue.copy( newValue );
  4775. } else {
  4776. this[ key ] = newValue;
  4777. }
  4778. }
  4779. }
  4780. toJSON( meta ) {
  4781. const isRoot = ( meta === undefined || typeof meta === 'string' );
  4782. if ( isRoot ) {
  4783. meta = {
  4784. textures: {},
  4785. images: {}
  4786. };
  4787. }
  4788. const data = {
  4789. metadata: {
  4790. version: 4.5,
  4791. type: 'Material',
  4792. generator: 'Material.toJSON'
  4793. }
  4794. };
  4795. // standard Material serialization
  4796. data.uuid = this.uuid;
  4797. data.type = this.type;
  4798. if ( this.name !== '' ) data.name = this.name;
  4799. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  4800. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  4801. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  4802. if ( this.sheen !== undefined ) data.sheen = this.sheen;
  4803. if ( this.sheenTint && this.sheenTint.isColor ) data.sheenTint = this.sheenTint.getHex();
  4804. if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
  4805. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  4806. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  4807. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  4808. if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
  4809. if ( this.specularTint && this.specularTint.isColor ) data.specularTint = this.specularTint.getHex();
  4810. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  4811. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  4812. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  4813. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  4814. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  4815. }
  4816. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  4817. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  4818. }
  4819. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  4820. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  4821. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  4822. }
  4823. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  4824. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  4825. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  4826. if ( this.lightMap && this.lightMap.isTexture ) {
  4827. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  4828. data.lightMapIntensity = this.lightMapIntensity;
  4829. }
  4830. if ( this.aoMap && this.aoMap.isTexture ) {
  4831. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  4832. data.aoMapIntensity = this.aoMapIntensity;
  4833. }
  4834. if ( this.bumpMap && this.bumpMap.isTexture ) {
  4835. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  4836. data.bumpScale = this.bumpScale;
  4837. }
  4838. if ( this.normalMap && this.normalMap.isTexture ) {
  4839. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  4840. data.normalMapType = this.normalMapType;
  4841. data.normalScale = this.normalScale.toArray();
  4842. }
  4843. if ( this.displacementMap && this.displacementMap.isTexture ) {
  4844. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  4845. data.displacementScale = this.displacementScale;
  4846. data.displacementBias = this.displacementBias;
  4847. }
  4848. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  4849. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  4850. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  4851. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  4852. if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;
  4853. if ( this.specularTintMap && this.specularTintMap.isTexture ) data.specularTintMap = this.specularTintMap.toJSON( meta ).uuid;
  4854. if ( this.envMap && this.envMap.isTexture ) {
  4855. data.envMap = this.envMap.toJSON( meta ).uuid;
  4856. if ( this.combine !== undefined ) data.combine = this.combine;
  4857. }
  4858. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  4859. if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
  4860. if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
  4861. if ( this.gradientMap && this.gradientMap.isTexture ) {
  4862. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  4863. }
  4864. if ( this.transmission !== undefined ) data.transmission = this.transmission;
  4865. if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
  4866. if ( this.thickness !== undefined ) data.thickness = this.thickness;
  4867. if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
  4868. if ( this.attenuationDistance !== undefined ) data.attenuationDistance = this.attenuationDistance;
  4869. if ( this.attenuationTint !== undefined ) data.attenuationTint = this.attenuationTint.getHex();
  4870. if ( this.size !== undefined ) data.size = this.size;
  4871. if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
  4872. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  4873. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  4874. if ( this.side !== FrontSide ) data.side = this.side;
  4875. if ( this.vertexColors ) data.vertexColors = true;
  4876. if ( this.opacity < 1 ) data.opacity = this.opacity;
  4877. if ( this.format !== RGBAFormat ) data.format = this.format;
  4878. if ( this.transparent === true ) data.transparent = this.transparent;
  4879. data.depthFunc = this.depthFunc;
  4880. data.depthTest = this.depthTest;
  4881. data.depthWrite = this.depthWrite;
  4882. data.colorWrite = this.colorWrite;
  4883. data.stencilWrite = this.stencilWrite;
  4884. data.stencilWriteMask = this.stencilWriteMask;
  4885. data.stencilFunc = this.stencilFunc;
  4886. data.stencilRef = this.stencilRef;
  4887. data.stencilFuncMask = this.stencilFuncMask;
  4888. data.stencilFail = this.stencilFail;
  4889. data.stencilZFail = this.stencilZFail;
  4890. data.stencilZPass = this.stencilZPass;
  4891. // rotation (SpriteMaterial)
  4892. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  4893. if ( this.polygonOffset === true ) data.polygonOffset = true;
  4894. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  4895. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  4896. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  4897. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  4898. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  4899. if ( this.scale !== undefined ) data.scale = this.scale;
  4900. if ( this.dithering === true ) data.dithering = true;
  4901. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  4902. if ( this.alphaToCoverage === true ) data.alphaToCoverage = this.alphaToCoverage;
  4903. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  4904. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  4905. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  4906. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  4907. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  4908. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  4909. if ( this.visible === false ) data.visible = false;
  4910. if ( this.toneMapped === false ) data.toneMapped = false;
  4911. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4912. // TODO: Copied from Object3D.toJSON
  4913. function extractFromCache( cache ) {
  4914. const values = [];
  4915. for ( const key in cache ) {
  4916. const data = cache[ key ];
  4917. delete data.metadata;
  4918. values.push( data );
  4919. }
  4920. return values;
  4921. }
  4922. if ( isRoot ) {
  4923. const textures = extractFromCache( meta.textures );
  4924. const images = extractFromCache( meta.images );
  4925. if ( textures.length > 0 ) data.textures = textures;
  4926. if ( images.length > 0 ) data.images = images;
  4927. }
  4928. return data;
  4929. }
  4930. clone() {
  4931. return new this.constructor().copy( this );
  4932. }
  4933. copy( source ) {
  4934. this.name = source.name;
  4935. this.fog = source.fog;
  4936. this.blending = source.blending;
  4937. this.side = source.side;
  4938. this.vertexColors = source.vertexColors;
  4939. this.opacity = source.opacity;
  4940. this.format = source.format;
  4941. this.transparent = source.transparent;
  4942. this.blendSrc = source.blendSrc;
  4943. this.blendDst = source.blendDst;
  4944. this.blendEquation = source.blendEquation;
  4945. this.blendSrcAlpha = source.blendSrcAlpha;
  4946. this.blendDstAlpha = source.blendDstAlpha;
  4947. this.blendEquationAlpha = source.blendEquationAlpha;
  4948. this.depthFunc = source.depthFunc;
  4949. this.depthTest = source.depthTest;
  4950. this.depthWrite = source.depthWrite;
  4951. this.stencilWriteMask = source.stencilWriteMask;
  4952. this.stencilFunc = source.stencilFunc;
  4953. this.stencilRef = source.stencilRef;
  4954. this.stencilFuncMask = source.stencilFuncMask;
  4955. this.stencilFail = source.stencilFail;
  4956. this.stencilZFail = source.stencilZFail;
  4957. this.stencilZPass = source.stencilZPass;
  4958. this.stencilWrite = source.stencilWrite;
  4959. const srcPlanes = source.clippingPlanes;
  4960. let dstPlanes = null;
  4961. if ( srcPlanes !== null ) {
  4962. const n = srcPlanes.length;
  4963. dstPlanes = new Array( n );
  4964. for ( let i = 0; i !== n; ++ i ) {
  4965. dstPlanes[ i ] = srcPlanes[ i ].clone();
  4966. }
  4967. }
  4968. this.clippingPlanes = dstPlanes;
  4969. this.clipIntersection = source.clipIntersection;
  4970. this.clipShadows = source.clipShadows;
  4971. this.shadowSide = source.shadowSide;
  4972. this.colorWrite = source.colorWrite;
  4973. this.precision = source.precision;
  4974. this.polygonOffset = source.polygonOffset;
  4975. this.polygonOffsetFactor = source.polygonOffsetFactor;
  4976. this.polygonOffsetUnits = source.polygonOffsetUnits;
  4977. this.dithering = source.dithering;
  4978. this.alphaTest = source.alphaTest;
  4979. this.alphaToCoverage = source.alphaToCoverage;
  4980. this.premultipliedAlpha = source.premultipliedAlpha;
  4981. this.visible = source.visible;
  4982. this.toneMapped = source.toneMapped;
  4983. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4984. return this;
  4985. }
  4986. dispose() {
  4987. this.dispatchEvent( { type: 'dispose' } );
  4988. }
  4989. set needsUpdate( value ) {
  4990. if ( value === true ) this.version ++;
  4991. }
  4992. }
  4993. Material.prototype.isMaterial = true;
  4994. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4995. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4996. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4997. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4998. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4999. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5000. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5001. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5002. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5003. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5004. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5005. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5006. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5007. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5008. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5009. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5010. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5011. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5012. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5013. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5014. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5015. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5016. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5017. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5018. const _hslA = { h: 0, s: 0, l: 0 };
  5019. const _hslB = { h: 0, s: 0, l: 0 };
  5020. function hue2rgb( p, q, t ) {
  5021. if ( t < 0 ) t += 1;
  5022. if ( t > 1 ) t -= 1;
  5023. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5024. if ( t < 1 / 2 ) return q;
  5025. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5026. return p;
  5027. }
  5028. function SRGBToLinear( c ) {
  5029. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  5030. }
  5031. function LinearToSRGB( c ) {
  5032. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  5033. }
  5034. class Color {
  5035. constructor( r, g, b ) {
  5036. if ( g === undefined && b === undefined ) {
  5037. // r is THREE.Color, hex or string
  5038. return this.set( r );
  5039. }
  5040. return this.setRGB( r, g, b );
  5041. }
  5042. set( value ) {
  5043. if ( value && value.isColor ) {
  5044. this.copy( value );
  5045. } else if ( typeof value === 'number' ) {
  5046. this.setHex( value );
  5047. } else if ( typeof value === 'string' ) {
  5048. this.setStyle( value );
  5049. }
  5050. return this;
  5051. }
  5052. setScalar( scalar ) {
  5053. this.r = scalar;
  5054. this.g = scalar;
  5055. this.b = scalar;
  5056. return this;
  5057. }
  5058. setHex( hex ) {
  5059. hex = Math.floor( hex );
  5060. this.r = ( hex >> 16 & 255 ) / 255;
  5061. this.g = ( hex >> 8 & 255 ) / 255;
  5062. this.b = ( hex & 255 ) / 255;
  5063. return this;
  5064. }
  5065. setRGB( r, g, b ) {
  5066. this.r = r;
  5067. this.g = g;
  5068. this.b = b;
  5069. return this;
  5070. }
  5071. setHSL( h, s, l ) {
  5072. // h,s,l ranges are in 0.0 - 1.0
  5073. h = euclideanModulo( h, 1 );
  5074. s = clamp( s, 0, 1 );
  5075. l = clamp( l, 0, 1 );
  5076. if ( s === 0 ) {
  5077. this.r = this.g = this.b = l;
  5078. } else {
  5079. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5080. const q = ( 2 * l ) - p;
  5081. this.r = hue2rgb( q, p, h + 1 / 3 );
  5082. this.g = hue2rgb( q, p, h );
  5083. this.b = hue2rgb( q, p, h - 1 / 3 );
  5084. }
  5085. return this;
  5086. }
  5087. setStyle( style ) {
  5088. function handleAlpha( string ) {
  5089. if ( string === undefined ) return;
  5090. if ( parseFloat( string ) < 1 ) {
  5091. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5092. }
  5093. }
  5094. let m;
  5095. if ( m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec( style ) ) {
  5096. // rgb / hsl
  5097. let color;
  5098. const name = m[ 1 ];
  5099. const components = m[ 2 ];
  5100. switch ( name ) {
  5101. case 'rgb':
  5102. case 'rgba':
  5103. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5104. // rgb(255,0,0) rgba(255,0,0,0.5)
  5105. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  5106. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  5107. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  5108. handleAlpha( color[ 4 ] );
  5109. return this;
  5110. }
  5111. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5112. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5113. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  5114. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  5115. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  5116. handleAlpha( color[ 4 ] );
  5117. return this;
  5118. }
  5119. break;
  5120. case 'hsl':
  5121. case 'hsla':
  5122. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5123. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5124. const h = parseFloat( color[ 1 ] ) / 360;
  5125. const s = parseInt( color[ 2 ], 10 ) / 100;
  5126. const l = parseInt( color[ 3 ], 10 ) / 100;
  5127. handleAlpha( color[ 4 ] );
  5128. return this.setHSL( h, s, l );
  5129. }
  5130. break;
  5131. }
  5132. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5133. // hex color
  5134. const hex = m[ 1 ];
  5135. const size = hex.length;
  5136. if ( size === 3 ) {
  5137. // #ff0
  5138. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  5139. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  5140. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  5141. return this;
  5142. } else if ( size === 6 ) {
  5143. // #ff0000
  5144. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  5145. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  5146. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  5147. return this;
  5148. }
  5149. }
  5150. if ( style && style.length > 0 ) {
  5151. return this.setColorName( style );
  5152. }
  5153. return this;
  5154. }
  5155. setColorName( style ) {
  5156. // color keywords
  5157. const hex = _colorKeywords[ style.toLowerCase() ];
  5158. if ( hex !== undefined ) {
  5159. // red
  5160. this.setHex( hex );
  5161. } else {
  5162. // unknown color
  5163. console.warn( 'THREE.Color: Unknown color ' + style );
  5164. }
  5165. return this;
  5166. }
  5167. clone() {
  5168. return new this.constructor( this.r, this.g, this.b );
  5169. }
  5170. copy( color ) {
  5171. this.r = color.r;
  5172. this.g = color.g;
  5173. this.b = color.b;
  5174. return this;
  5175. }
  5176. copyGammaToLinear( color, gammaFactor = 2.0 ) {
  5177. this.r = Math.pow( color.r, gammaFactor );
  5178. this.g = Math.pow( color.g, gammaFactor );
  5179. this.b = Math.pow( color.b, gammaFactor );
  5180. return this;
  5181. }
  5182. copyLinearToGamma( color, gammaFactor = 2.0 ) {
  5183. const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5184. this.r = Math.pow( color.r, safeInverse );
  5185. this.g = Math.pow( color.g, safeInverse );
  5186. this.b = Math.pow( color.b, safeInverse );
  5187. return this;
  5188. }
  5189. convertGammaToLinear( gammaFactor ) {
  5190. this.copyGammaToLinear( this, gammaFactor );
  5191. return this;
  5192. }
  5193. convertLinearToGamma( gammaFactor ) {
  5194. this.copyLinearToGamma( this, gammaFactor );
  5195. return this;
  5196. }
  5197. copySRGBToLinear( color ) {
  5198. this.r = SRGBToLinear( color.r );
  5199. this.g = SRGBToLinear( color.g );
  5200. this.b = SRGBToLinear( color.b );
  5201. return this;
  5202. }
  5203. copyLinearToSRGB( color ) {
  5204. this.r = LinearToSRGB( color.r );
  5205. this.g = LinearToSRGB( color.g );
  5206. this.b = LinearToSRGB( color.b );
  5207. return this;
  5208. }
  5209. convertSRGBToLinear() {
  5210. this.copySRGBToLinear( this );
  5211. return this;
  5212. }
  5213. convertLinearToSRGB() {
  5214. this.copyLinearToSRGB( this );
  5215. return this;
  5216. }
  5217. getHex() {
  5218. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5219. }
  5220. getHexString() {
  5221. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5222. }
  5223. getHSL( target ) {
  5224. // h,s,l ranges are in 0.0 - 1.0
  5225. const r = this.r, g = this.g, b = this.b;
  5226. const max = Math.max( r, g, b );
  5227. const min = Math.min( r, g, b );
  5228. let hue, saturation;
  5229. const lightness = ( min + max ) / 2.0;
  5230. if ( min === max ) {
  5231. hue = 0;
  5232. saturation = 0;
  5233. } else {
  5234. const delta = max - min;
  5235. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5236. switch ( max ) {
  5237. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5238. case g: hue = ( b - r ) / delta + 2; break;
  5239. case b: hue = ( r - g ) / delta + 4; break;
  5240. }
  5241. hue /= 6;
  5242. }
  5243. target.h = hue;
  5244. target.s = saturation;
  5245. target.l = lightness;
  5246. return target;
  5247. }
  5248. getStyle() {
  5249. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5250. }
  5251. offsetHSL( h, s, l ) {
  5252. this.getHSL( _hslA );
  5253. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  5254. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  5255. return this;
  5256. }
  5257. add( color ) {
  5258. this.r += color.r;
  5259. this.g += color.g;
  5260. this.b += color.b;
  5261. return this;
  5262. }
  5263. addColors( color1, color2 ) {
  5264. this.r = color1.r + color2.r;
  5265. this.g = color1.g + color2.g;
  5266. this.b = color1.b + color2.b;
  5267. return this;
  5268. }
  5269. addScalar( s ) {
  5270. this.r += s;
  5271. this.g += s;
  5272. this.b += s;
  5273. return this;
  5274. }
  5275. sub( color ) {
  5276. this.r = Math.max( 0, this.r - color.r );
  5277. this.g = Math.max( 0, this.g - color.g );
  5278. this.b = Math.max( 0, this.b - color.b );
  5279. return this;
  5280. }
  5281. multiply( color ) {
  5282. this.r *= color.r;
  5283. this.g *= color.g;
  5284. this.b *= color.b;
  5285. return this;
  5286. }
  5287. multiplyScalar( s ) {
  5288. this.r *= s;
  5289. this.g *= s;
  5290. this.b *= s;
  5291. return this;
  5292. }
  5293. lerp( color, alpha ) {
  5294. this.r += ( color.r - this.r ) * alpha;
  5295. this.g += ( color.g - this.g ) * alpha;
  5296. this.b += ( color.b - this.b ) * alpha;
  5297. return this;
  5298. }
  5299. lerpColors( color1, color2, alpha ) {
  5300. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5301. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5302. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5303. return this;
  5304. }
  5305. lerpHSL( color, alpha ) {
  5306. this.getHSL( _hslA );
  5307. color.getHSL( _hslB );
  5308. const h = lerp( _hslA.h, _hslB.h, alpha );
  5309. const s = lerp( _hslA.s, _hslB.s, alpha );
  5310. const l = lerp( _hslA.l, _hslB.l, alpha );
  5311. this.setHSL( h, s, l );
  5312. return this;
  5313. }
  5314. equals( c ) {
  5315. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5316. }
  5317. fromArray( array, offset = 0 ) {
  5318. this.r = array[ offset ];
  5319. this.g = array[ offset + 1 ];
  5320. this.b = array[ offset + 2 ];
  5321. return this;
  5322. }
  5323. toArray( array = [], offset = 0 ) {
  5324. array[ offset ] = this.r;
  5325. array[ offset + 1 ] = this.g;
  5326. array[ offset + 2 ] = this.b;
  5327. return array;
  5328. }
  5329. fromBufferAttribute( attribute, index ) {
  5330. this.r = attribute.getX( index );
  5331. this.g = attribute.getY( index );
  5332. this.b = attribute.getZ( index );
  5333. if ( attribute.normalized === true ) {
  5334. // assuming Uint8Array
  5335. this.r /= 255;
  5336. this.g /= 255;
  5337. this.b /= 255;
  5338. }
  5339. return this;
  5340. }
  5341. toJSON() {
  5342. return this.getHex();
  5343. }
  5344. }
  5345. Color.NAMES = _colorKeywords;
  5346. Color.prototype.isColor = true;
  5347. Color.prototype.r = 1;
  5348. Color.prototype.g = 1;
  5349. Color.prototype.b = 1;
  5350. /**
  5351. * parameters = {
  5352. * color: <hex>,
  5353. * opacity: <float>,
  5354. * map: new THREE.Texture( <Image> ),
  5355. *
  5356. * lightMap: new THREE.Texture( <Image> ),
  5357. * lightMapIntensity: <float>
  5358. *
  5359. * aoMap: new THREE.Texture( <Image> ),
  5360. * aoMapIntensity: <float>
  5361. *
  5362. * specularMap: new THREE.Texture( <Image> ),
  5363. *
  5364. * alphaMap: new THREE.Texture( <Image> ),
  5365. *
  5366. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5367. * combine: THREE.Multiply,
  5368. * reflectivity: <float>,
  5369. * refractionRatio: <float>,
  5370. *
  5371. * depthTest: <bool>,
  5372. * depthWrite: <bool>,
  5373. *
  5374. * wireframe: <boolean>,
  5375. * wireframeLinewidth: <float>,
  5376. * }
  5377. */
  5378. class MeshBasicMaterial extends Material {
  5379. constructor( parameters ) {
  5380. super();
  5381. this.type = 'MeshBasicMaterial';
  5382. this.color = new Color( 0xffffff ); // emissive
  5383. this.map = null;
  5384. this.lightMap = null;
  5385. this.lightMapIntensity = 1.0;
  5386. this.aoMap = null;
  5387. this.aoMapIntensity = 1.0;
  5388. this.specularMap = null;
  5389. this.alphaMap = null;
  5390. this.envMap = null;
  5391. this.combine = MultiplyOperation;
  5392. this.reflectivity = 1;
  5393. this.refractionRatio = 0.98;
  5394. this.wireframe = false;
  5395. this.wireframeLinewidth = 1;
  5396. this.wireframeLinecap = 'round';
  5397. this.wireframeLinejoin = 'round';
  5398. this.setValues( parameters );
  5399. }
  5400. copy( source ) {
  5401. super.copy( source );
  5402. this.color.copy( source.color );
  5403. this.map = source.map;
  5404. this.lightMap = source.lightMap;
  5405. this.lightMapIntensity = source.lightMapIntensity;
  5406. this.aoMap = source.aoMap;
  5407. this.aoMapIntensity = source.aoMapIntensity;
  5408. this.specularMap = source.specularMap;
  5409. this.alphaMap = source.alphaMap;
  5410. this.envMap = source.envMap;
  5411. this.combine = source.combine;
  5412. this.reflectivity = source.reflectivity;
  5413. this.refractionRatio = source.refractionRatio;
  5414. this.wireframe = source.wireframe;
  5415. this.wireframeLinewidth = source.wireframeLinewidth;
  5416. this.wireframeLinecap = source.wireframeLinecap;
  5417. this.wireframeLinejoin = source.wireframeLinejoin;
  5418. return this;
  5419. }
  5420. }
  5421. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5422. const _vector$9 = /*@__PURE__*/ new Vector3();
  5423. const _vector2$1 = /*@__PURE__*/ new Vector2();
  5424. class BufferAttribute {
  5425. constructor( array, itemSize, normalized ) {
  5426. if ( Array.isArray( array ) ) {
  5427. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5428. }
  5429. this.name = '';
  5430. this.array = array;
  5431. this.itemSize = itemSize;
  5432. this.count = array !== undefined ? array.length / itemSize : 0;
  5433. this.normalized = normalized === true;
  5434. this.usage = StaticDrawUsage;
  5435. this.updateRange = { offset: 0, count: - 1 };
  5436. this.version = 0;
  5437. }
  5438. onUploadCallback() {}
  5439. set needsUpdate( value ) {
  5440. if ( value === true ) this.version ++;
  5441. }
  5442. setUsage( value ) {
  5443. this.usage = value;
  5444. return this;
  5445. }
  5446. copy( source ) {
  5447. this.name = source.name;
  5448. this.array = new source.array.constructor( source.array );
  5449. this.itemSize = source.itemSize;
  5450. this.count = source.count;
  5451. this.normalized = source.normalized;
  5452. this.usage = source.usage;
  5453. return this;
  5454. }
  5455. copyAt( index1, attribute, index2 ) {
  5456. index1 *= this.itemSize;
  5457. index2 *= attribute.itemSize;
  5458. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  5459. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5460. }
  5461. return this;
  5462. }
  5463. copyArray( array ) {
  5464. this.array.set( array );
  5465. return this;
  5466. }
  5467. copyColorsArray( colors ) {
  5468. const array = this.array;
  5469. let offset = 0;
  5470. for ( let i = 0, l = colors.length; i < l; i ++ ) {
  5471. let color = colors[ i ];
  5472. if ( color === undefined ) {
  5473. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5474. color = new Color();
  5475. }
  5476. array[ offset ++ ] = color.r;
  5477. array[ offset ++ ] = color.g;
  5478. array[ offset ++ ] = color.b;
  5479. }
  5480. return this;
  5481. }
  5482. copyVector2sArray( vectors ) {
  5483. const array = this.array;
  5484. let offset = 0;
  5485. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5486. let vector = vectors[ i ];
  5487. if ( vector === undefined ) {
  5488. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5489. vector = new Vector2();
  5490. }
  5491. array[ offset ++ ] = vector.x;
  5492. array[ offset ++ ] = vector.y;
  5493. }
  5494. return this;
  5495. }
  5496. copyVector3sArray( vectors ) {
  5497. const array = this.array;
  5498. let offset = 0;
  5499. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5500. let vector = vectors[ i ];
  5501. if ( vector === undefined ) {
  5502. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5503. vector = new Vector3();
  5504. }
  5505. array[ offset ++ ] = vector.x;
  5506. array[ offset ++ ] = vector.y;
  5507. array[ offset ++ ] = vector.z;
  5508. }
  5509. return this;
  5510. }
  5511. copyVector4sArray( vectors ) {
  5512. const array = this.array;
  5513. let offset = 0;
  5514. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5515. let vector = vectors[ i ];
  5516. if ( vector === undefined ) {
  5517. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5518. vector = new Vector4();
  5519. }
  5520. array[ offset ++ ] = vector.x;
  5521. array[ offset ++ ] = vector.y;
  5522. array[ offset ++ ] = vector.z;
  5523. array[ offset ++ ] = vector.w;
  5524. }
  5525. return this;
  5526. }
  5527. applyMatrix3( m ) {
  5528. if ( this.itemSize === 2 ) {
  5529. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5530. _vector2$1.fromBufferAttribute( this, i );
  5531. _vector2$1.applyMatrix3( m );
  5532. this.setXY( i, _vector2$1.x, _vector2$1.y );
  5533. }
  5534. } else if ( this.itemSize === 3 ) {
  5535. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5536. _vector$9.fromBufferAttribute( this, i );
  5537. _vector$9.applyMatrix3( m );
  5538. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  5539. }
  5540. }
  5541. return this;
  5542. }
  5543. applyMatrix4( m ) {
  5544. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5545. _vector$9.x = this.getX( i );
  5546. _vector$9.y = this.getY( i );
  5547. _vector$9.z = this.getZ( i );
  5548. _vector$9.applyMatrix4( m );
  5549. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  5550. }
  5551. return this;
  5552. }
  5553. applyNormalMatrix( m ) {
  5554. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5555. _vector$9.x = this.getX( i );
  5556. _vector$9.y = this.getY( i );
  5557. _vector$9.z = this.getZ( i );
  5558. _vector$9.applyNormalMatrix( m );
  5559. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  5560. }
  5561. return this;
  5562. }
  5563. transformDirection( m ) {
  5564. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5565. _vector$9.x = this.getX( i );
  5566. _vector$9.y = this.getY( i );
  5567. _vector$9.z = this.getZ( i );
  5568. _vector$9.transformDirection( m );
  5569. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  5570. }
  5571. return this;
  5572. }
  5573. set( value, offset = 0 ) {
  5574. this.array.set( value, offset );
  5575. return this;
  5576. }
  5577. getX( index ) {
  5578. return this.array[ index * this.itemSize ];
  5579. }
  5580. setX( index, x ) {
  5581. this.array[ index * this.itemSize ] = x;
  5582. return this;
  5583. }
  5584. getY( index ) {
  5585. return this.array[ index * this.itemSize + 1 ];
  5586. }
  5587. setY( index, y ) {
  5588. this.array[ index * this.itemSize + 1 ] = y;
  5589. return this;
  5590. }
  5591. getZ( index ) {
  5592. return this.array[ index * this.itemSize + 2 ];
  5593. }
  5594. setZ( index, z ) {
  5595. this.array[ index * this.itemSize + 2 ] = z;
  5596. return this;
  5597. }
  5598. getW( index ) {
  5599. return this.array[ index * this.itemSize + 3 ];
  5600. }
  5601. setW( index, w ) {
  5602. this.array[ index * this.itemSize + 3 ] = w;
  5603. return this;
  5604. }
  5605. setXY( index, x, y ) {
  5606. index *= this.itemSize;
  5607. this.array[ index + 0 ] = x;
  5608. this.array[ index + 1 ] = y;
  5609. return this;
  5610. }
  5611. setXYZ( index, x, y, z ) {
  5612. index *= this.itemSize;
  5613. this.array[ index + 0 ] = x;
  5614. this.array[ index + 1 ] = y;
  5615. this.array[ index + 2 ] = z;
  5616. return this;
  5617. }
  5618. setXYZW( index, x, y, z, w ) {
  5619. index *= this.itemSize;
  5620. this.array[ index + 0 ] = x;
  5621. this.array[ index + 1 ] = y;
  5622. this.array[ index + 2 ] = z;
  5623. this.array[ index + 3 ] = w;
  5624. return this;
  5625. }
  5626. onUpload( callback ) {
  5627. this.onUploadCallback = callback;
  5628. return this;
  5629. }
  5630. clone() {
  5631. return new this.constructor( this.array, this.itemSize ).copy( this );
  5632. }
  5633. toJSON() {
  5634. const data = {
  5635. itemSize: this.itemSize,
  5636. type: this.array.constructor.name,
  5637. array: Array.prototype.slice.call( this.array ),
  5638. normalized: this.normalized
  5639. };
  5640. if ( this.name !== '' ) data.name = this.name;
  5641. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  5642. if ( this.updateRange.offset !== 0 || this.updateRange.count !== - 1 ) data.updateRange = this.updateRange;
  5643. return data;
  5644. }
  5645. }
  5646. BufferAttribute.prototype.isBufferAttribute = true;
  5647. //
  5648. class Int8BufferAttribute extends BufferAttribute {
  5649. constructor( array, itemSize, normalized ) {
  5650. super( new Int8Array( array ), itemSize, normalized );
  5651. }
  5652. }
  5653. class Uint8BufferAttribute extends BufferAttribute {
  5654. constructor( array, itemSize, normalized ) {
  5655. super( new Uint8Array( array ), itemSize, normalized );
  5656. }
  5657. }
  5658. class Uint8ClampedBufferAttribute extends BufferAttribute {
  5659. constructor( array, itemSize, normalized ) {
  5660. super( new Uint8ClampedArray( array ), itemSize, normalized );
  5661. }
  5662. }
  5663. class Int16BufferAttribute extends BufferAttribute {
  5664. constructor( array, itemSize, normalized ) {
  5665. super( new Int16Array( array ), itemSize, normalized );
  5666. }
  5667. }
  5668. class Uint16BufferAttribute extends BufferAttribute {
  5669. constructor( array, itemSize, normalized ) {
  5670. super( new Uint16Array( array ), itemSize, normalized );
  5671. }
  5672. }
  5673. class Int32BufferAttribute extends BufferAttribute {
  5674. constructor( array, itemSize, normalized ) {
  5675. super( new Int32Array( array ), itemSize, normalized );
  5676. }
  5677. }
  5678. class Uint32BufferAttribute extends BufferAttribute {
  5679. constructor( array, itemSize, normalized ) {
  5680. super( new Uint32Array( array ), itemSize, normalized );
  5681. }
  5682. }
  5683. class Float16BufferAttribute extends BufferAttribute {
  5684. constructor( array, itemSize, normalized ) {
  5685. super( new Uint16Array( array ), itemSize, normalized );
  5686. }
  5687. }
  5688. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  5689. class Float32BufferAttribute extends BufferAttribute {
  5690. constructor( array, itemSize, normalized ) {
  5691. super( new Float32Array( array ), itemSize, normalized );
  5692. }
  5693. }
  5694. class Float64BufferAttribute extends BufferAttribute {
  5695. constructor( array, itemSize, normalized ) {
  5696. super( new Float64Array( array ), itemSize, normalized );
  5697. }
  5698. }
  5699. let _id = 0;
  5700. const _m1 = /*@__PURE__*/ new Matrix4();
  5701. const _obj = /*@__PURE__*/ new Object3D();
  5702. const _offset = /*@__PURE__*/ new Vector3();
  5703. const _box$1 = /*@__PURE__*/ new Box3();
  5704. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  5705. const _vector$8 = /*@__PURE__*/ new Vector3();
  5706. class BufferGeometry extends EventDispatcher {
  5707. constructor() {
  5708. super();
  5709. Object.defineProperty( this, 'id', { value: _id ++ } );
  5710. this.uuid = generateUUID();
  5711. this.name = '';
  5712. this.type = 'BufferGeometry';
  5713. this.index = null;
  5714. this.attributes = {};
  5715. this.morphAttributes = {};
  5716. this.morphTargetsRelative = false;
  5717. this.groups = [];
  5718. this.boundingBox = null;
  5719. this.boundingSphere = null;
  5720. this.drawRange = { start: 0, count: Infinity };
  5721. this.userData = {};
  5722. }
  5723. getIndex() {
  5724. return this.index;
  5725. }
  5726. setIndex( index ) {
  5727. if ( Array.isArray( index ) ) {
  5728. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5729. } else {
  5730. this.index = index;
  5731. }
  5732. return this;
  5733. }
  5734. getAttribute( name ) {
  5735. return this.attributes[ name ];
  5736. }
  5737. setAttribute( name, attribute ) {
  5738. this.attributes[ name ] = attribute;
  5739. return this;
  5740. }
  5741. deleteAttribute( name ) {
  5742. delete this.attributes[ name ];
  5743. return this;
  5744. }
  5745. hasAttribute( name ) {
  5746. return this.attributes[ name ] !== undefined;
  5747. }
  5748. addGroup( start, count, materialIndex = 0 ) {
  5749. this.groups.push( {
  5750. start: start,
  5751. count: count,
  5752. materialIndex: materialIndex
  5753. } );
  5754. }
  5755. clearGroups() {
  5756. this.groups = [];
  5757. }
  5758. setDrawRange( start, count ) {
  5759. this.drawRange.start = start;
  5760. this.drawRange.count = count;
  5761. }
  5762. applyMatrix4( matrix ) {
  5763. const position = this.attributes.position;
  5764. if ( position !== undefined ) {
  5765. position.applyMatrix4( matrix );
  5766. position.needsUpdate = true;
  5767. }
  5768. const normal = this.attributes.normal;
  5769. if ( normal !== undefined ) {
  5770. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5771. normal.applyNormalMatrix( normalMatrix );
  5772. normal.needsUpdate = true;
  5773. }
  5774. const tangent = this.attributes.tangent;
  5775. if ( tangent !== undefined ) {
  5776. tangent.transformDirection( matrix );
  5777. tangent.needsUpdate = true;
  5778. }
  5779. if ( this.boundingBox !== null ) {
  5780. this.computeBoundingBox();
  5781. }
  5782. if ( this.boundingSphere !== null ) {
  5783. this.computeBoundingSphere();
  5784. }
  5785. return this;
  5786. }
  5787. applyQuaternion( q ) {
  5788. _m1.makeRotationFromQuaternion( q );
  5789. this.applyMatrix4( _m1 );
  5790. return this;
  5791. }
  5792. rotateX( angle ) {
  5793. // rotate geometry around world x-axis
  5794. _m1.makeRotationX( angle );
  5795. this.applyMatrix4( _m1 );
  5796. return this;
  5797. }
  5798. rotateY( angle ) {
  5799. // rotate geometry around world y-axis
  5800. _m1.makeRotationY( angle );
  5801. this.applyMatrix4( _m1 );
  5802. return this;
  5803. }
  5804. rotateZ( angle ) {
  5805. // rotate geometry around world z-axis
  5806. _m1.makeRotationZ( angle );
  5807. this.applyMatrix4( _m1 );
  5808. return this;
  5809. }
  5810. translate( x, y, z ) {
  5811. // translate geometry
  5812. _m1.makeTranslation( x, y, z );
  5813. this.applyMatrix4( _m1 );
  5814. return this;
  5815. }
  5816. scale( x, y, z ) {
  5817. // scale geometry
  5818. _m1.makeScale( x, y, z );
  5819. this.applyMatrix4( _m1 );
  5820. return this;
  5821. }
  5822. lookAt( vector ) {
  5823. _obj.lookAt( vector );
  5824. _obj.updateMatrix();
  5825. this.applyMatrix4( _obj.matrix );
  5826. return this;
  5827. }
  5828. center() {
  5829. this.computeBoundingBox();
  5830. this.boundingBox.getCenter( _offset ).negate();
  5831. this.translate( _offset.x, _offset.y, _offset.z );
  5832. return this;
  5833. }
  5834. setFromPoints( points ) {
  5835. const position = [];
  5836. for ( let i = 0, l = points.length; i < l; i ++ ) {
  5837. const point = points[ i ];
  5838. position.push( point.x, point.y, point.z || 0 );
  5839. }
  5840. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5841. return this;
  5842. }
  5843. computeBoundingBox() {
  5844. if ( this.boundingBox === null ) {
  5845. this.boundingBox = new Box3();
  5846. }
  5847. const position = this.attributes.position;
  5848. const morphAttributesPosition = this.morphAttributes.position;
  5849. if ( position && position.isGLBufferAttribute ) {
  5850. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this );
  5851. this.boundingBox.set(
  5852. new Vector3( - Infinity, - Infinity, - Infinity ),
  5853. new Vector3( + Infinity, + Infinity, + Infinity )
  5854. );
  5855. return;
  5856. }
  5857. if ( position !== undefined ) {
  5858. this.boundingBox.setFromBufferAttribute( position );
  5859. // process morph attributes if present
  5860. if ( morphAttributesPosition ) {
  5861. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5862. const morphAttribute = morphAttributesPosition[ i ];
  5863. _box$1.setFromBufferAttribute( morphAttribute );
  5864. if ( this.morphTargetsRelative ) {
  5865. _vector$8.addVectors( this.boundingBox.min, _box$1.min );
  5866. this.boundingBox.expandByPoint( _vector$8 );
  5867. _vector$8.addVectors( this.boundingBox.max, _box$1.max );
  5868. this.boundingBox.expandByPoint( _vector$8 );
  5869. } else {
  5870. this.boundingBox.expandByPoint( _box$1.min );
  5871. this.boundingBox.expandByPoint( _box$1.max );
  5872. }
  5873. }
  5874. }
  5875. } else {
  5876. this.boundingBox.makeEmpty();
  5877. }
  5878. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  5879. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  5880. }
  5881. }
  5882. computeBoundingSphere() {
  5883. if ( this.boundingSphere === null ) {
  5884. this.boundingSphere = new Sphere();
  5885. }
  5886. const position = this.attributes.position;
  5887. const morphAttributesPosition = this.morphAttributes.position;
  5888. if ( position && position.isGLBufferAttribute ) {
  5889. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this );
  5890. this.boundingSphere.set( new Vector3(), Infinity );
  5891. return;
  5892. }
  5893. if ( position ) {
  5894. // first, find the center of the bounding sphere
  5895. const center = this.boundingSphere.center;
  5896. _box$1.setFromBufferAttribute( position );
  5897. // process morph attributes if present
  5898. if ( morphAttributesPosition ) {
  5899. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5900. const morphAttribute = morphAttributesPosition[ i ];
  5901. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  5902. if ( this.morphTargetsRelative ) {
  5903. _vector$8.addVectors( _box$1.min, _boxMorphTargets.min );
  5904. _box$1.expandByPoint( _vector$8 );
  5905. _vector$8.addVectors( _box$1.max, _boxMorphTargets.max );
  5906. _box$1.expandByPoint( _vector$8 );
  5907. } else {
  5908. _box$1.expandByPoint( _boxMorphTargets.min );
  5909. _box$1.expandByPoint( _boxMorphTargets.max );
  5910. }
  5911. }
  5912. }
  5913. _box$1.getCenter( center );
  5914. // second, try to find a boundingSphere with a radius smaller than the
  5915. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  5916. let maxRadiusSq = 0;
  5917. for ( let i = 0, il = position.count; i < il; i ++ ) {
  5918. _vector$8.fromBufferAttribute( position, i );
  5919. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  5920. }
  5921. // process morph attributes if present
  5922. if ( morphAttributesPosition ) {
  5923. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5924. const morphAttribute = morphAttributesPosition[ i ];
  5925. const morphTargetsRelative = this.morphTargetsRelative;
  5926. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  5927. _vector$8.fromBufferAttribute( morphAttribute, j );
  5928. if ( morphTargetsRelative ) {
  5929. _offset.fromBufferAttribute( position, j );
  5930. _vector$8.add( _offset );
  5931. }
  5932. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  5933. }
  5934. }
  5935. }
  5936. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  5937. if ( isNaN( this.boundingSphere.radius ) ) {
  5938. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  5939. }
  5940. }
  5941. }
  5942. computeTangents() {
  5943. const index = this.index;
  5944. const attributes = this.attributes;
  5945. // based on http://www.terathon.com/code/tangent.html
  5946. // (per vertex tangents)
  5947. if ( index === null ||
  5948. attributes.position === undefined ||
  5949. attributes.normal === undefined ||
  5950. attributes.uv === undefined ) {
  5951. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  5952. return;
  5953. }
  5954. const indices = index.array;
  5955. const positions = attributes.position.array;
  5956. const normals = attributes.normal.array;
  5957. const uvs = attributes.uv.array;
  5958. const nVertices = positions.length / 3;
  5959. if ( attributes.tangent === undefined ) {
  5960. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  5961. }
  5962. const tangents = attributes.tangent.array;
  5963. const tan1 = [], tan2 = [];
  5964. for ( let i = 0; i < nVertices; i ++ ) {
  5965. tan1[ i ] = new Vector3();
  5966. tan2[ i ] = new Vector3();
  5967. }
  5968. const vA = new Vector3(),
  5969. vB = new Vector3(),
  5970. vC = new Vector3(),
  5971. uvA = new Vector2(),
  5972. uvB = new Vector2(),
  5973. uvC = new Vector2(),
  5974. sdir = new Vector3(),
  5975. tdir = new Vector3();
  5976. function handleTriangle( a, b, c ) {
  5977. vA.fromArray( positions, a * 3 );
  5978. vB.fromArray( positions, b * 3 );
  5979. vC.fromArray( positions, c * 3 );
  5980. uvA.fromArray( uvs, a * 2 );
  5981. uvB.fromArray( uvs, b * 2 );
  5982. uvC.fromArray( uvs, c * 2 );
  5983. vB.sub( vA );
  5984. vC.sub( vA );
  5985. uvB.sub( uvA );
  5986. uvC.sub( uvA );
  5987. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  5988. // silently ignore degenerate uv triangles having coincident or colinear vertices
  5989. if ( ! isFinite( r ) ) return;
  5990. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  5991. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  5992. tan1[ a ].add( sdir );
  5993. tan1[ b ].add( sdir );
  5994. tan1[ c ].add( sdir );
  5995. tan2[ a ].add( tdir );
  5996. tan2[ b ].add( tdir );
  5997. tan2[ c ].add( tdir );
  5998. }
  5999. let groups = this.groups;
  6000. if ( groups.length === 0 ) {
  6001. groups = [ {
  6002. start: 0,
  6003. count: indices.length
  6004. } ];
  6005. }
  6006. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6007. const group = groups[ i ];
  6008. const start = group.start;
  6009. const count = group.count;
  6010. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6011. handleTriangle(
  6012. indices[ j + 0 ],
  6013. indices[ j + 1 ],
  6014. indices[ j + 2 ]
  6015. );
  6016. }
  6017. }
  6018. const tmp = new Vector3(), tmp2 = new Vector3();
  6019. const n = new Vector3(), n2 = new Vector3();
  6020. function handleVertex( v ) {
  6021. n.fromArray( normals, v * 3 );
  6022. n2.copy( n );
  6023. const t = tan1[ v ];
  6024. // Gram-Schmidt orthogonalize
  6025. tmp.copy( t );
  6026. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6027. // Calculate handedness
  6028. tmp2.crossVectors( n2, t );
  6029. const test = tmp2.dot( tan2[ v ] );
  6030. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6031. tangents[ v * 4 ] = tmp.x;
  6032. tangents[ v * 4 + 1 ] = tmp.y;
  6033. tangents[ v * 4 + 2 ] = tmp.z;
  6034. tangents[ v * 4 + 3 ] = w;
  6035. }
  6036. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6037. const group = groups[ i ];
  6038. const start = group.start;
  6039. const count = group.count;
  6040. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6041. handleVertex( indices[ j + 0 ] );
  6042. handleVertex( indices[ j + 1 ] );
  6043. handleVertex( indices[ j + 2 ] );
  6044. }
  6045. }
  6046. }
  6047. computeVertexNormals() {
  6048. const index = this.index;
  6049. const positionAttribute = this.getAttribute( 'position' );
  6050. if ( positionAttribute !== undefined ) {
  6051. let normalAttribute = this.getAttribute( 'normal' );
  6052. if ( normalAttribute === undefined ) {
  6053. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6054. this.setAttribute( 'normal', normalAttribute );
  6055. } else {
  6056. // reset existing normals to zero
  6057. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6058. normalAttribute.setXYZ( i, 0, 0, 0 );
  6059. }
  6060. }
  6061. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6062. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6063. const cb = new Vector3(), ab = new Vector3();
  6064. // indexed elements
  6065. if ( index ) {
  6066. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6067. const vA = index.getX( i + 0 );
  6068. const vB = index.getX( i + 1 );
  6069. const vC = index.getX( i + 2 );
  6070. pA.fromBufferAttribute( positionAttribute, vA );
  6071. pB.fromBufferAttribute( positionAttribute, vB );
  6072. pC.fromBufferAttribute( positionAttribute, vC );
  6073. cb.subVectors( pC, pB );
  6074. ab.subVectors( pA, pB );
  6075. cb.cross( ab );
  6076. nA.fromBufferAttribute( normalAttribute, vA );
  6077. nB.fromBufferAttribute( normalAttribute, vB );
  6078. nC.fromBufferAttribute( normalAttribute, vC );
  6079. nA.add( cb );
  6080. nB.add( cb );
  6081. nC.add( cb );
  6082. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6083. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6084. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6085. }
  6086. } else {
  6087. // non-indexed elements (unconnected triangle soup)
  6088. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6089. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6090. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6091. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6092. cb.subVectors( pC, pB );
  6093. ab.subVectors( pA, pB );
  6094. cb.cross( ab );
  6095. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6096. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6097. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6098. }
  6099. }
  6100. this.normalizeNormals();
  6101. normalAttribute.needsUpdate = true;
  6102. }
  6103. }
  6104. merge( geometry, offset ) {
  6105. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6106. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6107. return;
  6108. }
  6109. if ( offset === undefined ) {
  6110. offset = 0;
  6111. console.warn(
  6112. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6113. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6114. );
  6115. }
  6116. const attributes = this.attributes;
  6117. for ( const key in attributes ) {
  6118. if ( geometry.attributes[ key ] === undefined ) continue;
  6119. const attribute1 = attributes[ key ];
  6120. const attributeArray1 = attribute1.array;
  6121. const attribute2 = geometry.attributes[ key ];
  6122. const attributeArray2 = attribute2.array;
  6123. const attributeOffset = attribute2.itemSize * offset;
  6124. const length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6125. for ( let i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6126. attributeArray1[ j ] = attributeArray2[ i ];
  6127. }
  6128. }
  6129. return this;
  6130. }
  6131. normalizeNormals() {
  6132. const normals = this.attributes.normal;
  6133. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6134. _vector$8.fromBufferAttribute( normals, i );
  6135. _vector$8.normalize();
  6136. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6137. }
  6138. }
  6139. toNonIndexed() {
  6140. function convertBufferAttribute( attribute, indices ) {
  6141. const array = attribute.array;
  6142. const itemSize = attribute.itemSize;
  6143. const normalized = attribute.normalized;
  6144. const array2 = new array.constructor( indices.length * itemSize );
  6145. let index = 0, index2 = 0;
  6146. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6147. if ( attribute.isInterleavedBufferAttribute ) {
  6148. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6149. } else {
  6150. index = indices[ i ] * itemSize;
  6151. }
  6152. for ( let j = 0; j < itemSize; j ++ ) {
  6153. array2[ index2 ++ ] = array[ index ++ ];
  6154. }
  6155. }
  6156. return new BufferAttribute( array2, itemSize, normalized );
  6157. }
  6158. //
  6159. if ( this.index === null ) {
  6160. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6161. return this;
  6162. }
  6163. const geometry2 = new BufferGeometry();
  6164. const indices = this.index.array;
  6165. const attributes = this.attributes;
  6166. // attributes
  6167. for ( const name in attributes ) {
  6168. const attribute = attributes[ name ];
  6169. const newAttribute = convertBufferAttribute( attribute, indices );
  6170. geometry2.setAttribute( name, newAttribute );
  6171. }
  6172. // morph attributes
  6173. const morphAttributes = this.morphAttributes;
  6174. for ( const name in morphAttributes ) {
  6175. const morphArray = [];
  6176. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6177. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6178. const attribute = morphAttribute[ i ];
  6179. const newAttribute = convertBufferAttribute( attribute, indices );
  6180. morphArray.push( newAttribute );
  6181. }
  6182. geometry2.morphAttributes[ name ] = morphArray;
  6183. }
  6184. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6185. // groups
  6186. const groups = this.groups;
  6187. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6188. const group = groups[ i ];
  6189. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6190. }
  6191. return geometry2;
  6192. }
  6193. toJSON() {
  6194. const data = {
  6195. metadata: {
  6196. version: 4.5,
  6197. type: 'BufferGeometry',
  6198. generator: 'BufferGeometry.toJSON'
  6199. }
  6200. };
  6201. // standard BufferGeometry serialization
  6202. data.uuid = this.uuid;
  6203. data.type = this.type;
  6204. if ( this.name !== '' ) data.name = this.name;
  6205. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6206. if ( this.parameters !== undefined ) {
  6207. const parameters = this.parameters;
  6208. for ( const key in parameters ) {
  6209. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6210. }
  6211. return data;
  6212. }
  6213. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6214. data.data = { attributes: {} };
  6215. const index = this.index;
  6216. if ( index !== null ) {
  6217. data.data.index = {
  6218. type: index.array.constructor.name,
  6219. array: Array.prototype.slice.call( index.array )
  6220. };
  6221. }
  6222. const attributes = this.attributes;
  6223. for ( const key in attributes ) {
  6224. const attribute = attributes[ key ];
  6225. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6226. }
  6227. const morphAttributes = {};
  6228. let hasMorphAttributes = false;
  6229. for ( const key in this.morphAttributes ) {
  6230. const attributeArray = this.morphAttributes[ key ];
  6231. const array = [];
  6232. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6233. const attribute = attributeArray[ i ];
  6234. array.push( attribute.toJSON( data.data ) );
  6235. }
  6236. if ( array.length > 0 ) {
  6237. morphAttributes[ key ] = array;
  6238. hasMorphAttributes = true;
  6239. }
  6240. }
  6241. if ( hasMorphAttributes ) {
  6242. data.data.morphAttributes = morphAttributes;
  6243. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6244. }
  6245. const groups = this.groups;
  6246. if ( groups.length > 0 ) {
  6247. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6248. }
  6249. const boundingSphere = this.boundingSphere;
  6250. if ( boundingSphere !== null ) {
  6251. data.data.boundingSphere = {
  6252. center: boundingSphere.center.toArray(),
  6253. radius: boundingSphere.radius
  6254. };
  6255. }
  6256. return data;
  6257. }
  6258. clone() {
  6259. /*
  6260. // Handle primitives
  6261. const parameters = this.parameters;
  6262. if ( parameters !== undefined ) {
  6263. const values = [];
  6264. for ( const key in parameters ) {
  6265. values.push( parameters[ key ] );
  6266. }
  6267. const geometry = Object.create( this.constructor.prototype );
  6268. this.constructor.apply( geometry, values );
  6269. return geometry;
  6270. }
  6271. return new this.constructor().copy( this );
  6272. */
  6273. return new BufferGeometry().copy( this );
  6274. }
  6275. copy( source ) {
  6276. // reset
  6277. this.index = null;
  6278. this.attributes = {};
  6279. this.morphAttributes = {};
  6280. this.groups = [];
  6281. this.boundingBox = null;
  6282. this.boundingSphere = null;
  6283. // used for storing cloned, shared data
  6284. const data = {};
  6285. // name
  6286. this.name = source.name;
  6287. // index
  6288. const index = source.index;
  6289. if ( index !== null ) {
  6290. this.setIndex( index.clone( data ) );
  6291. }
  6292. // attributes
  6293. const attributes = source.attributes;
  6294. for ( const name in attributes ) {
  6295. const attribute = attributes[ name ];
  6296. this.setAttribute( name, attribute.clone( data ) );
  6297. }
  6298. // morph attributes
  6299. const morphAttributes = source.morphAttributes;
  6300. for ( const name in morphAttributes ) {
  6301. const array = [];
  6302. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6303. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6304. array.push( morphAttribute[ i ].clone( data ) );
  6305. }
  6306. this.morphAttributes[ name ] = array;
  6307. }
  6308. this.morphTargetsRelative = source.morphTargetsRelative;
  6309. // groups
  6310. const groups = source.groups;
  6311. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6312. const group = groups[ i ];
  6313. this.addGroup( group.start, group.count, group.materialIndex );
  6314. }
  6315. // bounding box
  6316. const boundingBox = source.boundingBox;
  6317. if ( boundingBox !== null ) {
  6318. this.boundingBox = boundingBox.clone();
  6319. }
  6320. // bounding sphere
  6321. const boundingSphere = source.boundingSphere;
  6322. if ( boundingSphere !== null ) {
  6323. this.boundingSphere = boundingSphere.clone();
  6324. }
  6325. // draw range
  6326. this.drawRange.start = source.drawRange.start;
  6327. this.drawRange.count = source.drawRange.count;
  6328. // user data
  6329. this.userData = source.userData;
  6330. return this;
  6331. }
  6332. dispose() {
  6333. this.dispatchEvent( { type: 'dispose' } );
  6334. }
  6335. }
  6336. BufferGeometry.prototype.isBufferGeometry = true;
  6337. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  6338. const _ray$2 = /*@__PURE__*/ new Ray();
  6339. const _sphere$3 = /*@__PURE__*/ new Sphere();
  6340. const _vA$1 = /*@__PURE__*/ new Vector3();
  6341. const _vB$1 = /*@__PURE__*/ new Vector3();
  6342. const _vC$1 = /*@__PURE__*/ new Vector3();
  6343. const _tempA = /*@__PURE__*/ new Vector3();
  6344. const _tempB = /*@__PURE__*/ new Vector3();
  6345. const _tempC = /*@__PURE__*/ new Vector3();
  6346. const _morphA = /*@__PURE__*/ new Vector3();
  6347. const _morphB = /*@__PURE__*/ new Vector3();
  6348. const _morphC = /*@__PURE__*/ new Vector3();
  6349. const _uvA$1 = /*@__PURE__*/ new Vector2();
  6350. const _uvB$1 = /*@__PURE__*/ new Vector2();
  6351. const _uvC$1 = /*@__PURE__*/ new Vector2();
  6352. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6353. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6354. class Mesh extends Object3D {
  6355. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6356. super();
  6357. this.type = 'Mesh';
  6358. this.geometry = geometry;
  6359. this.material = material;
  6360. this.updateMorphTargets();
  6361. }
  6362. copy( source ) {
  6363. super.copy( source );
  6364. if ( source.morphTargetInfluences !== undefined ) {
  6365. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6366. }
  6367. if ( source.morphTargetDictionary !== undefined ) {
  6368. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6369. }
  6370. this.material = source.material;
  6371. this.geometry = source.geometry;
  6372. return this;
  6373. }
  6374. updateMorphTargets() {
  6375. const geometry = this.geometry;
  6376. if ( geometry.isBufferGeometry ) {
  6377. const morphAttributes = geometry.morphAttributes;
  6378. const keys = Object.keys( morphAttributes );
  6379. if ( keys.length > 0 ) {
  6380. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6381. if ( morphAttribute !== undefined ) {
  6382. this.morphTargetInfluences = [];
  6383. this.morphTargetDictionary = {};
  6384. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6385. const name = morphAttribute[ m ].name || String( m );
  6386. this.morphTargetInfluences.push( 0 );
  6387. this.morphTargetDictionary[ name ] = m;
  6388. }
  6389. }
  6390. }
  6391. } else {
  6392. const morphTargets = geometry.morphTargets;
  6393. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6394. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6395. }
  6396. }
  6397. }
  6398. raycast( raycaster, intersects ) {
  6399. const geometry = this.geometry;
  6400. const material = this.material;
  6401. const matrixWorld = this.matrixWorld;
  6402. if ( material === undefined ) return;
  6403. // Checking boundingSphere distance to ray
  6404. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6405. _sphere$3.copy( geometry.boundingSphere );
  6406. _sphere$3.applyMatrix4( matrixWorld );
  6407. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  6408. //
  6409. _inverseMatrix$2.copy( matrixWorld ).invert();
  6410. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  6411. // Check boundingBox before continuing
  6412. if ( geometry.boundingBox !== null ) {
  6413. if ( _ray$2.intersectsBox( geometry.boundingBox ) === false ) return;
  6414. }
  6415. let intersection;
  6416. if ( geometry.isBufferGeometry ) {
  6417. const index = geometry.index;
  6418. const position = geometry.attributes.position;
  6419. const morphPosition = geometry.morphAttributes.position;
  6420. const morphTargetsRelative = geometry.morphTargetsRelative;
  6421. const uv = geometry.attributes.uv;
  6422. const uv2 = geometry.attributes.uv2;
  6423. const groups = geometry.groups;
  6424. const drawRange = geometry.drawRange;
  6425. if ( index !== null ) {
  6426. // indexed buffer geometry
  6427. if ( Array.isArray( material ) ) {
  6428. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6429. const group = groups[ i ];
  6430. const groupMaterial = material[ group.materialIndex ];
  6431. const start = Math.max( group.start, drawRange.start );
  6432. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  6433. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6434. const a = index.getX( j );
  6435. const b = index.getX( j + 1 );
  6436. const c = index.getX( j + 2 );
  6437. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6438. if ( intersection ) {
  6439. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6440. intersection.face.materialIndex = group.materialIndex;
  6441. intersects.push( intersection );
  6442. }
  6443. }
  6444. }
  6445. } else {
  6446. const start = Math.max( 0, drawRange.start );
  6447. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6448. for ( let i = start, il = end; i < il; i += 3 ) {
  6449. const a = index.getX( i );
  6450. const b = index.getX( i + 1 );
  6451. const c = index.getX( i + 2 );
  6452. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6453. if ( intersection ) {
  6454. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6455. intersects.push( intersection );
  6456. }
  6457. }
  6458. }
  6459. } else if ( position !== undefined ) {
  6460. // non-indexed buffer geometry
  6461. if ( Array.isArray( material ) ) {
  6462. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6463. const group = groups[ i ];
  6464. const groupMaterial = material[ group.materialIndex ];
  6465. const start = Math.max( group.start, drawRange.start );
  6466. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  6467. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6468. const a = j;
  6469. const b = j + 1;
  6470. const c = j + 2;
  6471. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6472. if ( intersection ) {
  6473. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6474. intersection.face.materialIndex = group.materialIndex;
  6475. intersects.push( intersection );
  6476. }
  6477. }
  6478. }
  6479. } else {
  6480. const start = Math.max( 0, drawRange.start );
  6481. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6482. for ( let i = start, il = end; i < il; i += 3 ) {
  6483. const a = i;
  6484. const b = i + 1;
  6485. const c = i + 2;
  6486. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6487. if ( intersection ) {
  6488. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6489. intersects.push( intersection );
  6490. }
  6491. }
  6492. }
  6493. }
  6494. } else if ( geometry.isGeometry ) {
  6495. console.error( 'THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6496. }
  6497. }
  6498. }
  6499. Mesh.prototype.isMesh = true;
  6500. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6501. let intersect;
  6502. if ( material.side === BackSide ) {
  6503. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6504. } else {
  6505. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6506. }
  6507. if ( intersect === null ) return null;
  6508. _intersectionPointWorld.copy( point );
  6509. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6510. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6511. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6512. return {
  6513. distance: distance,
  6514. point: _intersectionPointWorld.clone(),
  6515. object: object
  6516. };
  6517. }
  6518. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6519. _vA$1.fromBufferAttribute( position, a );
  6520. _vB$1.fromBufferAttribute( position, b );
  6521. _vC$1.fromBufferAttribute( position, c );
  6522. const morphInfluences = object.morphTargetInfluences;
  6523. if ( morphPosition && morphInfluences ) {
  6524. _morphA.set( 0, 0, 0 );
  6525. _morphB.set( 0, 0, 0 );
  6526. _morphC.set( 0, 0, 0 );
  6527. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  6528. const influence = morphInfluences[ i ];
  6529. const morphAttribute = morphPosition[ i ];
  6530. if ( influence === 0 ) continue;
  6531. _tempA.fromBufferAttribute( morphAttribute, a );
  6532. _tempB.fromBufferAttribute( morphAttribute, b );
  6533. _tempC.fromBufferAttribute( morphAttribute, c );
  6534. if ( morphTargetsRelative ) {
  6535. _morphA.addScaledVector( _tempA, influence );
  6536. _morphB.addScaledVector( _tempB, influence );
  6537. _morphC.addScaledVector( _tempC, influence );
  6538. } else {
  6539. _morphA.addScaledVector( _tempA.sub( _vA$1 ), influence );
  6540. _morphB.addScaledVector( _tempB.sub( _vB$1 ), influence );
  6541. _morphC.addScaledVector( _tempC.sub( _vC$1 ), influence );
  6542. }
  6543. }
  6544. _vA$1.add( _morphA );
  6545. _vB$1.add( _morphB );
  6546. _vC$1.add( _morphC );
  6547. }
  6548. if ( object.isSkinnedMesh ) {
  6549. object.boneTransform( a, _vA$1 );
  6550. object.boneTransform( b, _vB$1 );
  6551. object.boneTransform( c, _vC$1 );
  6552. }
  6553. const intersection = checkIntersection( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  6554. if ( intersection ) {
  6555. if ( uv ) {
  6556. _uvA$1.fromBufferAttribute( uv, a );
  6557. _uvB$1.fromBufferAttribute( uv, b );
  6558. _uvC$1.fromBufferAttribute( uv, c );
  6559. intersection.uv = Triangle.getUV( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );
  6560. }
  6561. if ( uv2 ) {
  6562. _uvA$1.fromBufferAttribute( uv2, a );
  6563. _uvB$1.fromBufferAttribute( uv2, b );
  6564. _uvC$1.fromBufferAttribute( uv2, c );
  6565. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );
  6566. }
  6567. const face = {
  6568. a: a,
  6569. b: b,
  6570. c: c,
  6571. normal: new Vector3(),
  6572. materialIndex: 0
  6573. };
  6574. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  6575. intersection.face = face;
  6576. }
  6577. return intersection;
  6578. }
  6579. class BoxGeometry extends BufferGeometry {
  6580. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  6581. super();
  6582. this.type = 'BoxGeometry';
  6583. this.parameters = {
  6584. width: width,
  6585. height: height,
  6586. depth: depth,
  6587. widthSegments: widthSegments,
  6588. heightSegments: heightSegments,
  6589. depthSegments: depthSegments
  6590. };
  6591. const scope = this;
  6592. // segments
  6593. widthSegments = Math.floor( widthSegments );
  6594. heightSegments = Math.floor( heightSegments );
  6595. depthSegments = Math.floor( depthSegments );
  6596. // buffers
  6597. const indices = [];
  6598. const vertices = [];
  6599. const normals = [];
  6600. const uvs = [];
  6601. // helper variables
  6602. let numberOfVertices = 0;
  6603. let groupStart = 0;
  6604. // build each side of the box geometry
  6605. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  6606. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  6607. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  6608. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  6609. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  6610. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  6611. // build geometry
  6612. this.setIndex( indices );
  6613. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  6614. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  6615. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  6616. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  6617. const segmentWidth = width / gridX;
  6618. const segmentHeight = height / gridY;
  6619. const widthHalf = width / 2;
  6620. const heightHalf = height / 2;
  6621. const depthHalf = depth / 2;
  6622. const gridX1 = gridX + 1;
  6623. const gridY1 = gridY + 1;
  6624. let vertexCounter = 0;
  6625. let groupCount = 0;
  6626. const vector = new Vector3();
  6627. // generate vertices, normals and uvs
  6628. for ( let iy = 0; iy < gridY1; iy ++ ) {
  6629. const y = iy * segmentHeight - heightHalf;
  6630. for ( let ix = 0; ix < gridX1; ix ++ ) {
  6631. const x = ix * segmentWidth - widthHalf;
  6632. // set values to correct vector component
  6633. vector[ u ] = x * udir;
  6634. vector[ v ] = y * vdir;
  6635. vector[ w ] = depthHalf;
  6636. // now apply vector to vertex buffer
  6637. vertices.push( vector.x, vector.y, vector.z );
  6638. // set values to correct vector component
  6639. vector[ u ] = 0;
  6640. vector[ v ] = 0;
  6641. vector[ w ] = depth > 0 ? 1 : - 1;
  6642. // now apply vector to normal buffer
  6643. normals.push( vector.x, vector.y, vector.z );
  6644. // uvs
  6645. uvs.push( ix / gridX );
  6646. uvs.push( 1 - ( iy / gridY ) );
  6647. // counters
  6648. vertexCounter += 1;
  6649. }
  6650. }
  6651. // indices
  6652. // 1. you need three indices to draw a single face
  6653. // 2. a single segment consists of two faces
  6654. // 3. so we need to generate six (2*3) indices per segment
  6655. for ( let iy = 0; iy < gridY; iy ++ ) {
  6656. for ( let ix = 0; ix < gridX; ix ++ ) {
  6657. const a = numberOfVertices + ix + gridX1 * iy;
  6658. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  6659. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  6660. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  6661. // faces
  6662. indices.push( a, b, d );
  6663. indices.push( b, c, d );
  6664. // increase counter
  6665. groupCount += 6;
  6666. }
  6667. }
  6668. // add a group to the geometry. this will ensure multi material support
  6669. scope.addGroup( groupStart, groupCount, materialIndex );
  6670. // calculate new start value for groups
  6671. groupStart += groupCount;
  6672. // update total number of vertices
  6673. numberOfVertices += vertexCounter;
  6674. }
  6675. }
  6676. static fromJSON( data ) {
  6677. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  6678. }
  6679. }
  6680. /**
  6681. * Uniform Utilities
  6682. */
  6683. function cloneUniforms( src ) {
  6684. const dst = {};
  6685. for ( const u in src ) {
  6686. dst[ u ] = {};
  6687. for ( const p in src[ u ] ) {
  6688. const property = src[ u ][ p ];
  6689. if ( property && ( property.isColor ||
  6690. property.isMatrix3 || property.isMatrix4 ||
  6691. property.isVector2 || property.isVector3 || property.isVector4 ||
  6692. property.isTexture || property.isQuaternion ) ) {
  6693. dst[ u ][ p ] = property.clone();
  6694. } else if ( Array.isArray( property ) ) {
  6695. dst[ u ][ p ] = property.slice();
  6696. } else {
  6697. dst[ u ][ p ] = property;
  6698. }
  6699. }
  6700. }
  6701. return dst;
  6702. }
  6703. function mergeUniforms( uniforms ) {
  6704. const merged = {};
  6705. for ( let u = 0; u < uniforms.length; u ++ ) {
  6706. const tmp = cloneUniforms( uniforms[ u ] );
  6707. for ( const p in tmp ) {
  6708. merged[ p ] = tmp[ p ];
  6709. }
  6710. }
  6711. return merged;
  6712. }
  6713. // Legacy
  6714. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  6715. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  6716. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  6717. /**
  6718. * parameters = {
  6719. * defines: { "label" : "value" },
  6720. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  6721. *
  6722. * fragmentShader: <string>,
  6723. * vertexShader: <string>,
  6724. *
  6725. * wireframe: <boolean>,
  6726. * wireframeLinewidth: <float>,
  6727. *
  6728. * lights: <bool>
  6729. * }
  6730. */
  6731. class ShaderMaterial extends Material {
  6732. constructor( parameters ) {
  6733. super();
  6734. this.type = 'ShaderMaterial';
  6735. this.defines = {};
  6736. this.uniforms = {};
  6737. this.vertexShader = default_vertex;
  6738. this.fragmentShader = default_fragment;
  6739. this.linewidth = 1;
  6740. this.wireframe = false;
  6741. this.wireframeLinewidth = 1;
  6742. this.fog = false; // set to use scene fog
  6743. this.lights = false; // set to use scene lights
  6744. this.clipping = false; // set to use user-defined clipping planes
  6745. this.extensions = {
  6746. derivatives: false, // set to use derivatives
  6747. fragDepth: false, // set to use fragment depth values
  6748. drawBuffers: false, // set to use draw buffers
  6749. shaderTextureLOD: false // set to use shader texture LOD
  6750. };
  6751. // When rendered geometry doesn't include these attributes but the material does,
  6752. // use these default values in WebGL. This avoids errors when buffer data is missing.
  6753. this.defaultAttributeValues = {
  6754. 'color': [ 1, 1, 1 ],
  6755. 'uv': [ 0, 0 ],
  6756. 'uv2': [ 0, 0 ]
  6757. };
  6758. this.index0AttributeName = undefined;
  6759. this.uniformsNeedUpdate = false;
  6760. this.glslVersion = null;
  6761. if ( parameters !== undefined ) {
  6762. if ( parameters.attributes !== undefined ) {
  6763. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  6764. }
  6765. this.setValues( parameters );
  6766. }
  6767. }
  6768. copy( source ) {
  6769. super.copy( source );
  6770. this.fragmentShader = source.fragmentShader;
  6771. this.vertexShader = source.vertexShader;
  6772. this.uniforms = cloneUniforms( source.uniforms );
  6773. this.defines = Object.assign( {}, source.defines );
  6774. this.wireframe = source.wireframe;
  6775. this.wireframeLinewidth = source.wireframeLinewidth;
  6776. this.lights = source.lights;
  6777. this.clipping = source.clipping;
  6778. this.extensions = Object.assign( {}, source.extensions );
  6779. this.glslVersion = source.glslVersion;
  6780. return this;
  6781. }
  6782. toJSON( meta ) {
  6783. const data = super.toJSON( meta );
  6784. data.glslVersion = this.glslVersion;
  6785. data.uniforms = {};
  6786. for ( const name in this.uniforms ) {
  6787. const uniform = this.uniforms[ name ];
  6788. const value = uniform.value;
  6789. if ( value && value.isTexture ) {
  6790. data.uniforms[ name ] = {
  6791. type: 't',
  6792. value: value.toJSON( meta ).uuid
  6793. };
  6794. } else if ( value && value.isColor ) {
  6795. data.uniforms[ name ] = {
  6796. type: 'c',
  6797. value: value.getHex()
  6798. };
  6799. } else if ( value && value.isVector2 ) {
  6800. data.uniforms[ name ] = {
  6801. type: 'v2',
  6802. value: value.toArray()
  6803. };
  6804. } else if ( value && value.isVector3 ) {
  6805. data.uniforms[ name ] = {
  6806. type: 'v3',
  6807. value: value.toArray()
  6808. };
  6809. } else if ( value && value.isVector4 ) {
  6810. data.uniforms[ name ] = {
  6811. type: 'v4',
  6812. value: value.toArray()
  6813. };
  6814. } else if ( value && value.isMatrix3 ) {
  6815. data.uniforms[ name ] = {
  6816. type: 'm3',
  6817. value: value.toArray()
  6818. };
  6819. } else if ( value && value.isMatrix4 ) {
  6820. data.uniforms[ name ] = {
  6821. type: 'm4',
  6822. value: value.toArray()
  6823. };
  6824. } else {
  6825. data.uniforms[ name ] = {
  6826. value: value
  6827. };
  6828. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  6829. }
  6830. }
  6831. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  6832. data.vertexShader = this.vertexShader;
  6833. data.fragmentShader = this.fragmentShader;
  6834. const extensions = {};
  6835. for ( const key in this.extensions ) {
  6836. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  6837. }
  6838. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  6839. return data;
  6840. }
  6841. }
  6842. ShaderMaterial.prototype.isShaderMaterial = true;
  6843. class Camera extends Object3D {
  6844. constructor() {
  6845. super();
  6846. this.type = 'Camera';
  6847. this.matrixWorldInverse = new Matrix4();
  6848. this.projectionMatrix = new Matrix4();
  6849. this.projectionMatrixInverse = new Matrix4();
  6850. }
  6851. copy( source, recursive ) {
  6852. super.copy( source, recursive );
  6853. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6854. this.projectionMatrix.copy( source.projectionMatrix );
  6855. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  6856. return this;
  6857. }
  6858. getWorldDirection( target ) {
  6859. this.updateWorldMatrix( true, false );
  6860. const e = this.matrixWorld.elements;
  6861. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  6862. }
  6863. updateMatrixWorld( force ) {
  6864. super.updateMatrixWorld( force );
  6865. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  6866. }
  6867. updateWorldMatrix( updateParents, updateChildren ) {
  6868. super.updateWorldMatrix( updateParents, updateChildren );
  6869. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  6870. }
  6871. clone() {
  6872. return new this.constructor().copy( this );
  6873. }
  6874. }
  6875. Camera.prototype.isCamera = true;
  6876. class PerspectiveCamera extends Camera {
  6877. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  6878. super();
  6879. this.type = 'PerspectiveCamera';
  6880. this.fov = fov;
  6881. this.zoom = 1;
  6882. this.near = near;
  6883. this.far = far;
  6884. this.focus = 10;
  6885. this.aspect = aspect;
  6886. this.view = null;
  6887. this.filmGauge = 35; // width of the film (default in millimeters)
  6888. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  6889. this.updateProjectionMatrix();
  6890. }
  6891. copy( source, recursive ) {
  6892. super.copy( source, recursive );
  6893. this.fov = source.fov;
  6894. this.zoom = source.zoom;
  6895. this.near = source.near;
  6896. this.far = source.far;
  6897. this.focus = source.focus;
  6898. this.aspect = source.aspect;
  6899. this.view = source.view === null ? null : Object.assign( {}, source.view );
  6900. this.filmGauge = source.filmGauge;
  6901. this.filmOffset = source.filmOffset;
  6902. return this;
  6903. }
  6904. /**
  6905. * Sets the FOV by focal length in respect to the current .filmGauge.
  6906. *
  6907. * The default film gauge is 35, so that the focal length can be specified for
  6908. * a 35mm (full frame) camera.
  6909. *
  6910. * Values for focal length and film gauge must have the same unit.
  6911. */
  6912. setFocalLength( focalLength ) {
  6913. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  6914. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  6915. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  6916. this.updateProjectionMatrix();
  6917. }
  6918. /**
  6919. * Calculates the focal length from the current .fov and .filmGauge.
  6920. */
  6921. getFocalLength() {
  6922. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  6923. return 0.5 * this.getFilmHeight() / vExtentSlope;
  6924. }
  6925. getEffectiveFOV() {
  6926. return RAD2DEG * 2 * Math.atan(
  6927. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  6928. }
  6929. getFilmWidth() {
  6930. // film not completely covered in portrait format (aspect < 1)
  6931. return this.filmGauge * Math.min( this.aspect, 1 );
  6932. }
  6933. getFilmHeight() {
  6934. // film not completely covered in landscape format (aspect > 1)
  6935. return this.filmGauge / Math.max( this.aspect, 1 );
  6936. }
  6937. /**
  6938. * Sets an offset in a larger frustum. This is useful for multi-window or
  6939. * multi-monitor/multi-machine setups.
  6940. *
  6941. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6942. * the monitors are in grid like this
  6943. *
  6944. * +---+---+---+
  6945. * | A | B | C |
  6946. * +---+---+---+
  6947. * | D | E | F |
  6948. * +---+---+---+
  6949. *
  6950. * then for each monitor you would call it like this
  6951. *
  6952. * const w = 1920;
  6953. * const h = 1080;
  6954. * const fullWidth = w * 3;
  6955. * const fullHeight = h * 2;
  6956. *
  6957. * --A--
  6958. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  6959. * --B--
  6960. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  6961. * --C--
  6962. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  6963. * --D--
  6964. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  6965. * --E--
  6966. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  6967. * --F--
  6968. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  6969. *
  6970. * Note there is no reason monitors have to be the same size or in a grid.
  6971. */
  6972. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  6973. this.aspect = fullWidth / fullHeight;
  6974. if ( this.view === null ) {
  6975. this.view = {
  6976. enabled: true,
  6977. fullWidth: 1,
  6978. fullHeight: 1,
  6979. offsetX: 0,
  6980. offsetY: 0,
  6981. width: 1,
  6982. height: 1
  6983. };
  6984. }
  6985. this.view.enabled = true;
  6986. this.view.fullWidth = fullWidth;
  6987. this.view.fullHeight = fullHeight;
  6988. this.view.offsetX = x;
  6989. this.view.offsetY = y;
  6990. this.view.width = width;
  6991. this.view.height = height;
  6992. this.updateProjectionMatrix();
  6993. }
  6994. clearViewOffset() {
  6995. if ( this.view !== null ) {
  6996. this.view.enabled = false;
  6997. }
  6998. this.updateProjectionMatrix();
  6999. }
  7000. updateProjectionMatrix() {
  7001. const near = this.near;
  7002. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7003. let height = 2 * top;
  7004. let width = this.aspect * height;
  7005. let left = - 0.5 * width;
  7006. const view = this.view;
  7007. if ( this.view !== null && this.view.enabled ) {
  7008. const fullWidth = view.fullWidth,
  7009. fullHeight = view.fullHeight;
  7010. left += view.offsetX * width / fullWidth;
  7011. top -= view.offsetY * height / fullHeight;
  7012. width *= view.width / fullWidth;
  7013. height *= view.height / fullHeight;
  7014. }
  7015. const skew = this.filmOffset;
  7016. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7017. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  7018. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7019. }
  7020. toJSON( meta ) {
  7021. const data = super.toJSON( meta );
  7022. data.object.fov = this.fov;
  7023. data.object.zoom = this.zoom;
  7024. data.object.near = this.near;
  7025. data.object.far = this.far;
  7026. data.object.focus = this.focus;
  7027. data.object.aspect = this.aspect;
  7028. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7029. data.object.filmGauge = this.filmGauge;
  7030. data.object.filmOffset = this.filmOffset;
  7031. return data;
  7032. }
  7033. }
  7034. PerspectiveCamera.prototype.isPerspectiveCamera = true;
  7035. const fov = 90, aspect = 1;
  7036. class CubeCamera extends Object3D {
  7037. constructor( near, far, renderTarget ) {
  7038. super();
  7039. this.type = 'CubeCamera';
  7040. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  7041. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  7042. return;
  7043. }
  7044. this.renderTarget = renderTarget;
  7045. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7046. cameraPX.layers = this.layers;
  7047. cameraPX.up.set( 0, - 1, 0 );
  7048. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  7049. this.add( cameraPX );
  7050. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7051. cameraNX.layers = this.layers;
  7052. cameraNX.up.set( 0, - 1, 0 );
  7053. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  7054. this.add( cameraNX );
  7055. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7056. cameraPY.layers = this.layers;
  7057. cameraPY.up.set( 0, 0, 1 );
  7058. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  7059. this.add( cameraPY );
  7060. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7061. cameraNY.layers = this.layers;
  7062. cameraNY.up.set( 0, 0, - 1 );
  7063. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  7064. this.add( cameraNY );
  7065. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7066. cameraPZ.layers = this.layers;
  7067. cameraPZ.up.set( 0, - 1, 0 );
  7068. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  7069. this.add( cameraPZ );
  7070. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7071. cameraNZ.layers = this.layers;
  7072. cameraNZ.up.set( 0, - 1, 0 );
  7073. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  7074. this.add( cameraNZ );
  7075. }
  7076. update( renderer, scene ) {
  7077. if ( this.parent === null ) this.updateMatrixWorld();
  7078. const renderTarget = this.renderTarget;
  7079. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7080. const currentXrEnabled = renderer.xr.enabled;
  7081. const currentRenderTarget = renderer.getRenderTarget();
  7082. renderer.xr.enabled = false;
  7083. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7084. renderTarget.texture.generateMipmaps = false;
  7085. renderer.setRenderTarget( renderTarget, 0 );
  7086. renderer.render( scene, cameraPX );
  7087. renderer.setRenderTarget( renderTarget, 1 );
  7088. renderer.render( scene, cameraNX );
  7089. renderer.setRenderTarget( renderTarget, 2 );
  7090. renderer.render( scene, cameraPY );
  7091. renderer.setRenderTarget( renderTarget, 3 );
  7092. renderer.render( scene, cameraNY );
  7093. renderer.setRenderTarget( renderTarget, 4 );
  7094. renderer.render( scene, cameraPZ );
  7095. renderTarget.texture.generateMipmaps = generateMipmaps;
  7096. renderer.setRenderTarget( renderTarget, 5 );
  7097. renderer.render( scene, cameraNZ );
  7098. renderer.setRenderTarget( currentRenderTarget );
  7099. renderer.xr.enabled = currentXrEnabled;
  7100. }
  7101. }
  7102. class CubeTexture extends Texture {
  7103. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  7104. images = images !== undefined ? images : [];
  7105. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7106. format = format !== undefined ? format : RGBFormat;
  7107. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7108. this.flipY = false;
  7109. }
  7110. get images() {
  7111. return this.image;
  7112. }
  7113. set images( value ) {
  7114. this.image = value;
  7115. }
  7116. }
  7117. CubeTexture.prototype.isCubeTexture = true;
  7118. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7119. constructor( size, options, dummy ) {
  7120. if ( Number.isInteger( options ) ) {
  7121. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  7122. options = dummy;
  7123. }
  7124. super( size, size, options );
  7125. options = options || {};
  7126. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7127. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7128. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7129. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7130. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7131. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7132. this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  7133. this.texture.isRenderTargetTexture = true;
  7134. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7135. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7136. this.texture._needsFlipEnvMap = false;
  7137. }
  7138. fromEquirectangularTexture( renderer, texture ) {
  7139. this.texture.type = texture.type;
  7140. this.texture.format = RGBAFormat; // see #18859
  7141. this.texture.encoding = texture.encoding;
  7142. this.texture.generateMipmaps = texture.generateMipmaps;
  7143. this.texture.minFilter = texture.minFilter;
  7144. this.texture.magFilter = texture.magFilter;
  7145. const shader = {
  7146. uniforms: {
  7147. tEquirect: { value: null },
  7148. },
  7149. vertexShader: /* glsl */`
  7150. varying vec3 vWorldDirection;
  7151. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7152. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7153. }
  7154. void main() {
  7155. vWorldDirection = transformDirection( position, modelMatrix );
  7156. #include <begin_vertex>
  7157. #include <project_vertex>
  7158. }
  7159. `,
  7160. fragmentShader: /* glsl */`
  7161. uniform sampler2D tEquirect;
  7162. varying vec3 vWorldDirection;
  7163. #include <common>
  7164. void main() {
  7165. vec3 direction = normalize( vWorldDirection );
  7166. vec2 sampleUV = equirectUv( direction );
  7167. gl_FragColor = texture2D( tEquirect, sampleUV );
  7168. }
  7169. `
  7170. };
  7171. const geometry = new BoxGeometry( 5, 5, 5 );
  7172. const material = new ShaderMaterial( {
  7173. name: 'CubemapFromEquirect',
  7174. uniforms: cloneUniforms( shader.uniforms ),
  7175. vertexShader: shader.vertexShader,
  7176. fragmentShader: shader.fragmentShader,
  7177. side: BackSide,
  7178. blending: NoBlending
  7179. } );
  7180. material.uniforms.tEquirect.value = texture;
  7181. const mesh = new Mesh( geometry, material );
  7182. const currentMinFilter = texture.minFilter;
  7183. // Avoid blurred poles
  7184. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7185. const camera = new CubeCamera( 1, 10, this );
  7186. camera.update( renderer, mesh );
  7187. texture.minFilter = currentMinFilter;
  7188. mesh.geometry.dispose();
  7189. mesh.material.dispose();
  7190. return this;
  7191. }
  7192. clear( renderer, color, depth, stencil ) {
  7193. const currentRenderTarget = renderer.getRenderTarget();
  7194. for ( let i = 0; i < 6; i ++ ) {
  7195. renderer.setRenderTarget( this, i );
  7196. renderer.clear( color, depth, stencil );
  7197. }
  7198. renderer.setRenderTarget( currentRenderTarget );
  7199. }
  7200. }
  7201. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7202. const _vector1 = /*@__PURE__*/ new Vector3();
  7203. const _vector2 = /*@__PURE__*/ new Vector3();
  7204. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  7205. class Plane {
  7206. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  7207. // normal is assumed to be normalized
  7208. this.normal = normal;
  7209. this.constant = constant;
  7210. }
  7211. set( normal, constant ) {
  7212. this.normal.copy( normal );
  7213. this.constant = constant;
  7214. return this;
  7215. }
  7216. setComponents( x, y, z, w ) {
  7217. this.normal.set( x, y, z );
  7218. this.constant = w;
  7219. return this;
  7220. }
  7221. setFromNormalAndCoplanarPoint( normal, point ) {
  7222. this.normal.copy( normal );
  7223. this.constant = - point.dot( this.normal );
  7224. return this;
  7225. }
  7226. setFromCoplanarPoints( a, b, c ) {
  7227. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  7228. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  7229. this.setFromNormalAndCoplanarPoint( normal, a );
  7230. return this;
  7231. }
  7232. copy( plane ) {
  7233. this.normal.copy( plane.normal );
  7234. this.constant = plane.constant;
  7235. return this;
  7236. }
  7237. normalize() {
  7238. // Note: will lead to a divide by zero if the plane is invalid.
  7239. const inverseNormalLength = 1.0 / this.normal.length();
  7240. this.normal.multiplyScalar( inverseNormalLength );
  7241. this.constant *= inverseNormalLength;
  7242. return this;
  7243. }
  7244. negate() {
  7245. this.constant *= - 1;
  7246. this.normal.negate();
  7247. return this;
  7248. }
  7249. distanceToPoint( point ) {
  7250. return this.normal.dot( point ) + this.constant;
  7251. }
  7252. distanceToSphere( sphere ) {
  7253. return this.distanceToPoint( sphere.center ) - sphere.radius;
  7254. }
  7255. projectPoint( point, target ) {
  7256. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  7257. }
  7258. intersectLine( line, target ) {
  7259. const direction = line.delta( _vector1 );
  7260. const denominator = this.normal.dot( direction );
  7261. if ( denominator === 0 ) {
  7262. // line is coplanar, return origin
  7263. if ( this.distanceToPoint( line.start ) === 0 ) {
  7264. return target.copy( line.start );
  7265. }
  7266. // Unsure if this is the correct method to handle this case.
  7267. return null;
  7268. }
  7269. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  7270. if ( t < 0 || t > 1 ) {
  7271. return null;
  7272. }
  7273. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  7274. }
  7275. intersectsLine( line ) {
  7276. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  7277. const startSign = this.distanceToPoint( line.start );
  7278. const endSign = this.distanceToPoint( line.end );
  7279. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  7280. }
  7281. intersectsBox( box ) {
  7282. return box.intersectsPlane( this );
  7283. }
  7284. intersectsSphere( sphere ) {
  7285. return sphere.intersectsPlane( this );
  7286. }
  7287. coplanarPoint( target ) {
  7288. return target.copy( this.normal ).multiplyScalar( - this.constant );
  7289. }
  7290. applyMatrix4( matrix, optionalNormalMatrix ) {
  7291. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  7292. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  7293. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  7294. this.constant = - referencePoint.dot( normal );
  7295. return this;
  7296. }
  7297. translate( offset ) {
  7298. this.constant -= offset.dot( this.normal );
  7299. return this;
  7300. }
  7301. equals( plane ) {
  7302. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  7303. }
  7304. clone() {
  7305. return new this.constructor().copy( this );
  7306. }
  7307. }
  7308. Plane.prototype.isPlane = true;
  7309. const _sphere$2 = /*@__PURE__*/ new Sphere();
  7310. const _vector$7 = /*@__PURE__*/ new Vector3();
  7311. class Frustum {
  7312. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  7313. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  7314. }
  7315. set( p0, p1, p2, p3, p4, p5 ) {
  7316. const planes = this.planes;
  7317. planes[ 0 ].copy( p0 );
  7318. planes[ 1 ].copy( p1 );
  7319. planes[ 2 ].copy( p2 );
  7320. planes[ 3 ].copy( p3 );
  7321. planes[ 4 ].copy( p4 );
  7322. planes[ 5 ].copy( p5 );
  7323. return this;
  7324. }
  7325. copy( frustum ) {
  7326. const planes = this.planes;
  7327. for ( let i = 0; i < 6; i ++ ) {
  7328. planes[ i ].copy( frustum.planes[ i ] );
  7329. }
  7330. return this;
  7331. }
  7332. setFromProjectionMatrix( m ) {
  7333. const planes = this.planes;
  7334. const me = m.elements;
  7335. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  7336. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  7337. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  7338. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  7339. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  7340. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  7341. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  7342. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  7343. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  7344. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  7345. return this;
  7346. }
  7347. intersectsObject( object ) {
  7348. const geometry = object.geometry;
  7349. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7350. _sphere$2.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  7351. return this.intersectsSphere( _sphere$2 );
  7352. }
  7353. intersectsSprite( sprite ) {
  7354. _sphere$2.center.set( 0, 0, 0 );
  7355. _sphere$2.radius = 0.7071067811865476;
  7356. _sphere$2.applyMatrix4( sprite.matrixWorld );
  7357. return this.intersectsSphere( _sphere$2 );
  7358. }
  7359. intersectsSphere( sphere ) {
  7360. const planes = this.planes;
  7361. const center = sphere.center;
  7362. const negRadius = - sphere.radius;
  7363. for ( let i = 0; i < 6; i ++ ) {
  7364. const distance = planes[ i ].distanceToPoint( center );
  7365. if ( distance < negRadius ) {
  7366. return false;
  7367. }
  7368. }
  7369. return true;
  7370. }
  7371. intersectsBox( box ) {
  7372. const planes = this.planes;
  7373. for ( let i = 0; i < 6; i ++ ) {
  7374. const plane = planes[ i ];
  7375. // corner at max distance
  7376. _vector$7.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7377. _vector$7.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7378. _vector$7.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7379. if ( plane.distanceToPoint( _vector$7 ) < 0 ) {
  7380. return false;
  7381. }
  7382. }
  7383. return true;
  7384. }
  7385. containsPoint( point ) {
  7386. const planes = this.planes;
  7387. for ( let i = 0; i < 6; i ++ ) {
  7388. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  7389. return false;
  7390. }
  7391. }
  7392. return true;
  7393. }
  7394. clone() {
  7395. return new this.constructor().copy( this );
  7396. }
  7397. }
  7398. function WebGLAnimation() {
  7399. let context = null;
  7400. let isAnimating = false;
  7401. let animationLoop = null;
  7402. let requestId = null;
  7403. function onAnimationFrame( time, frame ) {
  7404. animationLoop( time, frame );
  7405. requestId = context.requestAnimationFrame( onAnimationFrame );
  7406. }
  7407. return {
  7408. start: function () {
  7409. if ( isAnimating === true ) return;
  7410. if ( animationLoop === null ) return;
  7411. requestId = context.requestAnimationFrame( onAnimationFrame );
  7412. isAnimating = true;
  7413. },
  7414. stop: function () {
  7415. context.cancelAnimationFrame( requestId );
  7416. isAnimating = false;
  7417. },
  7418. setAnimationLoop: function ( callback ) {
  7419. animationLoop = callback;
  7420. },
  7421. setContext: function ( value ) {
  7422. context = value;
  7423. }
  7424. };
  7425. }
  7426. function WebGLAttributes( gl, capabilities ) {
  7427. const isWebGL2 = capabilities.isWebGL2;
  7428. const buffers = new WeakMap();
  7429. function createBuffer( attribute, bufferType ) {
  7430. const array = attribute.array;
  7431. const usage = attribute.usage;
  7432. const buffer = gl.createBuffer();
  7433. gl.bindBuffer( bufferType, buffer );
  7434. gl.bufferData( bufferType, array, usage );
  7435. attribute.onUploadCallback();
  7436. let type = 5126;
  7437. if ( array instanceof Float32Array ) {
  7438. type = 5126;
  7439. } else if ( array instanceof Float64Array ) {
  7440. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  7441. } else if ( array instanceof Uint16Array ) {
  7442. if ( attribute.isFloat16BufferAttribute ) {
  7443. if ( isWebGL2 ) {
  7444. type = 5131;
  7445. } else {
  7446. console.warn( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
  7447. }
  7448. } else {
  7449. type = 5123;
  7450. }
  7451. } else if ( array instanceof Int16Array ) {
  7452. type = 5122;
  7453. } else if ( array instanceof Uint32Array ) {
  7454. type = 5125;
  7455. } else if ( array instanceof Int32Array ) {
  7456. type = 5124;
  7457. } else if ( array instanceof Int8Array ) {
  7458. type = 5120;
  7459. } else if ( array instanceof Uint8Array ) {
  7460. type = 5121;
  7461. } else if ( array instanceof Uint8ClampedArray ) {
  7462. type = 5121;
  7463. }
  7464. return {
  7465. buffer: buffer,
  7466. type: type,
  7467. bytesPerElement: array.BYTES_PER_ELEMENT,
  7468. version: attribute.version
  7469. };
  7470. }
  7471. function updateBuffer( buffer, attribute, bufferType ) {
  7472. const array = attribute.array;
  7473. const updateRange = attribute.updateRange;
  7474. gl.bindBuffer( bufferType, buffer );
  7475. if ( updateRange.count === - 1 ) {
  7476. // Not using update ranges
  7477. gl.bufferSubData( bufferType, 0, array );
  7478. } else {
  7479. if ( isWebGL2 ) {
  7480. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7481. array, updateRange.offset, updateRange.count );
  7482. } else {
  7483. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7484. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  7485. }
  7486. updateRange.count = - 1; // reset range
  7487. }
  7488. }
  7489. //
  7490. function get( attribute ) {
  7491. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7492. return buffers.get( attribute );
  7493. }
  7494. function remove( attribute ) {
  7495. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7496. const data = buffers.get( attribute );
  7497. if ( data ) {
  7498. gl.deleteBuffer( data.buffer );
  7499. buffers.delete( attribute );
  7500. }
  7501. }
  7502. function update( attribute, bufferType ) {
  7503. if ( attribute.isGLBufferAttribute ) {
  7504. const cached = buffers.get( attribute );
  7505. if ( ! cached || cached.version < attribute.version ) {
  7506. buffers.set( attribute, {
  7507. buffer: attribute.buffer,
  7508. type: attribute.type,
  7509. bytesPerElement: attribute.elementSize,
  7510. version: attribute.version
  7511. } );
  7512. }
  7513. return;
  7514. }
  7515. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7516. const data = buffers.get( attribute );
  7517. if ( data === undefined ) {
  7518. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  7519. } else if ( data.version < attribute.version ) {
  7520. updateBuffer( data.buffer, attribute, bufferType );
  7521. data.version = attribute.version;
  7522. }
  7523. }
  7524. return {
  7525. get: get,
  7526. remove: remove,
  7527. update: update
  7528. };
  7529. }
  7530. class PlaneGeometry extends BufferGeometry {
  7531. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  7532. super();
  7533. this.type = 'PlaneGeometry';
  7534. this.parameters = {
  7535. width: width,
  7536. height: height,
  7537. widthSegments: widthSegments,
  7538. heightSegments: heightSegments
  7539. };
  7540. const width_half = width / 2;
  7541. const height_half = height / 2;
  7542. const gridX = Math.floor( widthSegments );
  7543. const gridY = Math.floor( heightSegments );
  7544. const gridX1 = gridX + 1;
  7545. const gridY1 = gridY + 1;
  7546. const segment_width = width / gridX;
  7547. const segment_height = height / gridY;
  7548. //
  7549. const indices = [];
  7550. const vertices = [];
  7551. const normals = [];
  7552. const uvs = [];
  7553. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7554. const y = iy * segment_height - height_half;
  7555. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7556. const x = ix * segment_width - width_half;
  7557. vertices.push( x, - y, 0 );
  7558. normals.push( 0, 0, 1 );
  7559. uvs.push( ix / gridX );
  7560. uvs.push( 1 - ( iy / gridY ) );
  7561. }
  7562. }
  7563. for ( let iy = 0; iy < gridY; iy ++ ) {
  7564. for ( let ix = 0; ix < gridX; ix ++ ) {
  7565. const a = ix + gridX1 * iy;
  7566. const b = ix + gridX1 * ( iy + 1 );
  7567. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7568. const d = ( ix + 1 ) + gridX1 * iy;
  7569. indices.push( a, b, d );
  7570. indices.push( b, c, d );
  7571. }
  7572. }
  7573. this.setIndex( indices );
  7574. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7575. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7576. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7577. }
  7578. static fromJSON( data ) {
  7579. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  7580. }
  7581. }
  7582. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  7583. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  7584. var alphatest_fragment = "#ifdef USE_ALPHATEST\n\tif ( diffuseColor.a < alphaTest ) discard;\n#endif";
  7585. var alphatest_pars_fragment = "#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif";
  7586. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif";
  7587. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  7588. var begin_vertex = "vec3 transformed = vec3( position );";
  7589. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  7590. var bsdfs = "vec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenTint, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenTint * ( D * V );\n}\n#endif";
  7591. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  7592. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  7593. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  7594. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  7595. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  7596. var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif";
  7597. var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif";
  7598. var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  7599. var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
  7600. var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";
  7601. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";
  7602. var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  7603. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  7604. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  7605. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  7606. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  7607. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  7608. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  7609. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
  7610. var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
  7611. var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  7612. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  7613. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
  7614. var fog_vertex = "#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif";
  7615. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif";
  7616. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  7617. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
  7618. var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
  7619. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tlightMapIrradiance *= PI;\n\t#endif\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif";
  7620. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  7621. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointLightInfo( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotLightInfo( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
  7622. var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\t#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#else\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#endif\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif";
  7623. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 reflectVec;\n\t\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\t\treflectVec = reflect( - viewDir, normal );\n\t\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\t#else\n\t\t\t\treflectVec = refract( - viewDir, normal, refractionRatio );\n\t\t\t#endif\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n#endif";
  7624. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  7625. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";
  7626. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  7627. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
  7628. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\t#ifdef SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularTintFactor = specularTint;\n\t\t#ifdef USE_SPECULARINTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n\t\t#endif\n\t\t#ifdef USE_SPECULARTINTMAP\n\t\t\tspecularTintFactor *= specularTintMapTexelToLinear( texture2D( specularTintMap, vUv ) ).rgb;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularTintFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularTintFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenTint = sheenTint;\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n#endif";
  7629. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenTint;\n\t\tfloat sheenRoughness;\n\t#endif\n};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\tvec3 FssEss = specularColor * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenTint, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tcomputeMultiscattering( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  7630. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef USE_CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
  7631. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometry.normal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";
  7632. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
  7633. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  7634. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";
  7635. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  7636. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
  7637. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  7638. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  7639. var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
  7640. var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  7641. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  7642. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  7643. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1, 2 ) * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif";
  7644. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform vec2 morphTargetsTextureSize;\n\t\tvec3 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset, const in int stride ) {\n\t\t\tfloat texelIndex = float( vertexIndex * stride + offset );\n\t\t\tfloat y = floor( texelIndex / morphTargetsTextureSize.x );\n\t\t\tfloat x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tvec3 morphUV = vec3( ( x + 0.5 ) / morphTargetsTextureSize.x, y / morphTargetsTextureSize.y, morphTargetIndex );\n\t\t\treturn texture( morphTargetsTexture, morphUV ).xyz;\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif";
  7645. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\t#ifndef USE_MORPHNORMALS\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 1 ) * morphTargetInfluences[ i ];\n\t\t\t#else\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 2 ) * morphTargetInfluences[ i ];\n\t\t\t#endif\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\n#endif";
  7646. var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  7647. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  7648. var normal_pars_fragment = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif";
  7649. var normal_pars_vertex = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif";
  7650. var normal_vertex = "#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif";
  7651. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\t\treturn normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\t}\n#endif";
  7652. var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  7653. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  7654. var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
  7655. var output_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= transmissionAlpha + 0.1;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );";
  7656. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
  7657. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  7658. var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";
  7659. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  7660. var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  7661. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  7662. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  7663. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  7664. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
  7665. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
  7666. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  7667. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  7668. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  7669. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
  7670. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  7671. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  7672. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  7673. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  7674. var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
  7675. var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tfloat transmissionAlpha = 1.0;\n\tfloat transmissionFactor = transmission;\n\tfloat thicknessFactor = thickness;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\ttransmissionFactor *= texture2D( transmissionMap, vUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tthicknessFactor *= texture2D( thicknessMap, vUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmission = getIBLVolumeRefraction(\n\t\tn, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,\n\t\tattenuationTint, attenuationDistance );\n\ttotalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );\n\ttransmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );\n#endif";
  7676. var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationTint;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tvec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( float roughness, float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {\n\t\tfloat framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\treturn texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#else\n\t\t\treturn texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#endif\n\t}\n\tvec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {\n\t\tif ( attenuationDistance == 0.0 ) {\n\t\t\treturn radiance;\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance * radiance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,\n\t\tvec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,\n\t\tvec3 attenuationColor, float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n\t}\n#endif";
  7677. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  7678. var uv_pars_vertex = "#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";
  7679. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  7680. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  7681. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";
  7682. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  7683. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
  7684. const vertex$g = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  7685. const fragment$g = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  7686. const vertex$f = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  7687. const fragment$f = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  7688. const vertex$e = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";
  7689. const fragment$e = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";
  7690. const vertex$d = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
  7691. const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
  7692. const vertex$c = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  7693. const fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  7694. const vertex$b = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  7695. const fragment$b = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  7696. const vertex$a = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  7697. const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7698. const vertex$9 = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7699. const fragment$9 = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7700. const vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  7701. const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7702. const vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  7703. const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  7704. const vertex$6 = "#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7705. const fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7706. const vertex$5 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}";
  7707. const fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularTint;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARTINTMAP\n\t\tuniform sampler2D specularTintMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenTint;\n\tuniform float sheenRoughness;\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - clearcoat * Fcc ) + clearcoatSpecular * clearcoat;\n\t#endif\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7708. const vertex$4 = "#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7709. const fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  7710. const vertex$3 = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  7711. const fragment$3 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  7712. const vertex$2 = "#include <common>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7713. const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  7714. const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  7715. const fragment$1 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  7716. const ShaderChunk = {
  7717. alphamap_fragment: alphamap_fragment,
  7718. alphamap_pars_fragment: alphamap_pars_fragment,
  7719. alphatest_fragment: alphatest_fragment,
  7720. alphatest_pars_fragment: alphatest_pars_fragment,
  7721. aomap_fragment: aomap_fragment,
  7722. aomap_pars_fragment: aomap_pars_fragment,
  7723. begin_vertex: begin_vertex,
  7724. beginnormal_vertex: beginnormal_vertex,
  7725. bsdfs: bsdfs,
  7726. bumpmap_pars_fragment: bumpmap_pars_fragment,
  7727. clipping_planes_fragment: clipping_planes_fragment,
  7728. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  7729. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  7730. clipping_planes_vertex: clipping_planes_vertex,
  7731. color_fragment: color_fragment,
  7732. color_pars_fragment: color_pars_fragment,
  7733. color_pars_vertex: color_pars_vertex,
  7734. color_vertex: color_vertex,
  7735. common: common,
  7736. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  7737. defaultnormal_vertex: defaultnormal_vertex,
  7738. displacementmap_pars_vertex: displacementmap_pars_vertex,
  7739. displacementmap_vertex: displacementmap_vertex,
  7740. emissivemap_fragment: emissivemap_fragment,
  7741. emissivemap_pars_fragment: emissivemap_pars_fragment,
  7742. encodings_fragment: encodings_fragment,
  7743. encodings_pars_fragment: encodings_pars_fragment,
  7744. envmap_fragment: envmap_fragment,
  7745. envmap_common_pars_fragment: envmap_common_pars_fragment,
  7746. envmap_pars_fragment: envmap_pars_fragment,
  7747. envmap_pars_vertex: envmap_pars_vertex,
  7748. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  7749. envmap_vertex: envmap_vertex,
  7750. fog_vertex: fog_vertex,
  7751. fog_pars_vertex: fog_pars_vertex,
  7752. fog_fragment: fog_fragment,
  7753. fog_pars_fragment: fog_pars_fragment,
  7754. gradientmap_pars_fragment: gradientmap_pars_fragment,
  7755. lightmap_fragment: lightmap_fragment,
  7756. lightmap_pars_fragment: lightmap_pars_fragment,
  7757. lights_lambert_vertex: lights_lambert_vertex,
  7758. lights_pars_begin: lights_pars_begin,
  7759. lights_toon_fragment: lights_toon_fragment,
  7760. lights_toon_pars_fragment: lights_toon_pars_fragment,
  7761. lights_phong_fragment: lights_phong_fragment,
  7762. lights_phong_pars_fragment: lights_phong_pars_fragment,
  7763. lights_physical_fragment: lights_physical_fragment,
  7764. lights_physical_pars_fragment: lights_physical_pars_fragment,
  7765. lights_fragment_begin: lights_fragment_begin,
  7766. lights_fragment_maps: lights_fragment_maps,
  7767. lights_fragment_end: lights_fragment_end,
  7768. logdepthbuf_fragment: logdepthbuf_fragment,
  7769. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  7770. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  7771. logdepthbuf_vertex: logdepthbuf_vertex,
  7772. map_fragment: map_fragment,
  7773. map_pars_fragment: map_pars_fragment,
  7774. map_particle_fragment: map_particle_fragment,
  7775. map_particle_pars_fragment: map_particle_pars_fragment,
  7776. metalnessmap_fragment: metalnessmap_fragment,
  7777. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  7778. morphnormal_vertex: morphnormal_vertex,
  7779. morphtarget_pars_vertex: morphtarget_pars_vertex,
  7780. morphtarget_vertex: morphtarget_vertex,
  7781. normal_fragment_begin: normal_fragment_begin,
  7782. normal_fragment_maps: normal_fragment_maps,
  7783. normal_pars_fragment: normal_pars_fragment,
  7784. normal_pars_vertex: normal_pars_vertex,
  7785. normal_vertex: normal_vertex,
  7786. normalmap_pars_fragment: normalmap_pars_fragment,
  7787. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  7788. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  7789. clearcoat_pars_fragment: clearcoat_pars_fragment,
  7790. output_fragment: output_fragment,
  7791. packing: packing,
  7792. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  7793. project_vertex: project_vertex,
  7794. dithering_fragment: dithering_fragment,
  7795. dithering_pars_fragment: dithering_pars_fragment,
  7796. roughnessmap_fragment: roughnessmap_fragment,
  7797. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  7798. shadowmap_pars_fragment: shadowmap_pars_fragment,
  7799. shadowmap_pars_vertex: shadowmap_pars_vertex,
  7800. shadowmap_vertex: shadowmap_vertex,
  7801. shadowmask_pars_fragment: shadowmask_pars_fragment,
  7802. skinbase_vertex: skinbase_vertex,
  7803. skinning_pars_vertex: skinning_pars_vertex,
  7804. skinning_vertex: skinning_vertex,
  7805. skinnormal_vertex: skinnormal_vertex,
  7806. specularmap_fragment: specularmap_fragment,
  7807. specularmap_pars_fragment: specularmap_pars_fragment,
  7808. tonemapping_fragment: tonemapping_fragment,
  7809. tonemapping_pars_fragment: tonemapping_pars_fragment,
  7810. transmission_fragment: transmission_fragment,
  7811. transmission_pars_fragment: transmission_pars_fragment,
  7812. uv_pars_fragment: uv_pars_fragment,
  7813. uv_pars_vertex: uv_pars_vertex,
  7814. uv_vertex: uv_vertex,
  7815. uv2_pars_fragment: uv2_pars_fragment,
  7816. uv2_pars_vertex: uv2_pars_vertex,
  7817. uv2_vertex: uv2_vertex,
  7818. worldpos_vertex: worldpos_vertex,
  7819. background_vert: vertex$g,
  7820. background_frag: fragment$g,
  7821. cube_vert: vertex$f,
  7822. cube_frag: fragment$f,
  7823. depth_vert: vertex$e,
  7824. depth_frag: fragment$e,
  7825. distanceRGBA_vert: vertex$d,
  7826. distanceRGBA_frag: fragment$d,
  7827. equirect_vert: vertex$c,
  7828. equirect_frag: fragment$c,
  7829. linedashed_vert: vertex$b,
  7830. linedashed_frag: fragment$b,
  7831. meshbasic_vert: vertex$a,
  7832. meshbasic_frag: fragment$a,
  7833. meshlambert_vert: vertex$9,
  7834. meshlambert_frag: fragment$9,
  7835. meshmatcap_vert: vertex$8,
  7836. meshmatcap_frag: fragment$8,
  7837. meshnormal_vert: vertex$7,
  7838. meshnormal_frag: fragment$7,
  7839. meshphong_vert: vertex$6,
  7840. meshphong_frag: fragment$6,
  7841. meshphysical_vert: vertex$5,
  7842. meshphysical_frag: fragment$5,
  7843. meshtoon_vert: vertex$4,
  7844. meshtoon_frag: fragment$4,
  7845. points_vert: vertex$3,
  7846. points_frag: fragment$3,
  7847. shadow_vert: vertex$2,
  7848. shadow_frag: fragment$2,
  7849. sprite_vert: vertex$1,
  7850. sprite_frag: fragment$1
  7851. };
  7852. /**
  7853. * Uniforms library for shared webgl shaders
  7854. */
  7855. const UniformsLib = {
  7856. common: {
  7857. diffuse: { value: new Color( 0xffffff ) },
  7858. opacity: { value: 1.0 },
  7859. map: { value: null },
  7860. uvTransform: { value: new Matrix3() },
  7861. uv2Transform: { value: new Matrix3() },
  7862. alphaMap: { value: null },
  7863. alphaTest: { value: 0 }
  7864. },
  7865. specularmap: {
  7866. specularMap: { value: null },
  7867. },
  7868. envmap: {
  7869. envMap: { value: null },
  7870. flipEnvMap: { value: - 1 },
  7871. reflectivity: { value: 1.0 }, // basic, lambert, phong
  7872. ior: { value: 1.5 }, // standard, physical
  7873. refractionRatio: { value: 0.98 },
  7874. maxMipLevel: { value: 0 }
  7875. },
  7876. aomap: {
  7877. aoMap: { value: null },
  7878. aoMapIntensity: { value: 1 }
  7879. },
  7880. lightmap: {
  7881. lightMap: { value: null },
  7882. lightMapIntensity: { value: 1 }
  7883. },
  7884. emissivemap: {
  7885. emissiveMap: { value: null }
  7886. },
  7887. bumpmap: {
  7888. bumpMap: { value: null },
  7889. bumpScale: { value: 1 }
  7890. },
  7891. normalmap: {
  7892. normalMap: { value: null },
  7893. normalScale: { value: new Vector2( 1, 1 ) }
  7894. },
  7895. displacementmap: {
  7896. displacementMap: { value: null },
  7897. displacementScale: { value: 1 },
  7898. displacementBias: { value: 0 }
  7899. },
  7900. roughnessmap: {
  7901. roughnessMap: { value: null }
  7902. },
  7903. metalnessmap: {
  7904. metalnessMap: { value: null }
  7905. },
  7906. gradientmap: {
  7907. gradientMap: { value: null }
  7908. },
  7909. fog: {
  7910. fogDensity: { value: 0.00025 },
  7911. fogNear: { value: 1 },
  7912. fogFar: { value: 2000 },
  7913. fogColor: { value: new Color( 0xffffff ) }
  7914. },
  7915. lights: {
  7916. ambientLightColor: { value: [] },
  7917. lightProbe: { value: [] },
  7918. directionalLights: { value: [], properties: {
  7919. direction: {},
  7920. color: {}
  7921. } },
  7922. directionalLightShadows: { value: [], properties: {
  7923. shadowBias: {},
  7924. shadowNormalBias: {},
  7925. shadowRadius: {},
  7926. shadowMapSize: {}
  7927. } },
  7928. directionalShadowMap: { value: [] },
  7929. directionalShadowMatrix: { value: [] },
  7930. spotLights: { value: [], properties: {
  7931. color: {},
  7932. position: {},
  7933. direction: {},
  7934. distance: {},
  7935. coneCos: {},
  7936. penumbraCos: {},
  7937. decay: {}
  7938. } },
  7939. spotLightShadows: { value: [], properties: {
  7940. shadowBias: {},
  7941. shadowNormalBias: {},
  7942. shadowRadius: {},
  7943. shadowMapSize: {}
  7944. } },
  7945. spotShadowMap: { value: [] },
  7946. spotShadowMatrix: { value: [] },
  7947. pointLights: { value: [], properties: {
  7948. color: {},
  7949. position: {},
  7950. decay: {},
  7951. distance: {}
  7952. } },
  7953. pointLightShadows: { value: [], properties: {
  7954. shadowBias: {},
  7955. shadowNormalBias: {},
  7956. shadowRadius: {},
  7957. shadowMapSize: {},
  7958. shadowCameraNear: {},
  7959. shadowCameraFar: {}
  7960. } },
  7961. pointShadowMap: { value: [] },
  7962. pointShadowMatrix: { value: [] },
  7963. hemisphereLights: { value: [], properties: {
  7964. direction: {},
  7965. skyColor: {},
  7966. groundColor: {}
  7967. } },
  7968. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  7969. rectAreaLights: { value: [], properties: {
  7970. color: {},
  7971. position: {},
  7972. width: {},
  7973. height: {}
  7974. } },
  7975. ltc_1: { value: null },
  7976. ltc_2: { value: null }
  7977. },
  7978. points: {
  7979. diffuse: { value: new Color( 0xffffff ) },
  7980. opacity: { value: 1.0 },
  7981. size: { value: 1.0 },
  7982. scale: { value: 1.0 },
  7983. map: { value: null },
  7984. alphaMap: { value: null },
  7985. alphaTest: { value: 0 },
  7986. uvTransform: { value: new Matrix3() }
  7987. },
  7988. sprite: {
  7989. diffuse: { value: new Color( 0xffffff ) },
  7990. opacity: { value: 1.0 },
  7991. center: { value: new Vector2( 0.5, 0.5 ) },
  7992. rotation: { value: 0.0 },
  7993. map: { value: null },
  7994. alphaMap: { value: null },
  7995. alphaTest: { value: 0 },
  7996. uvTransform: { value: new Matrix3() }
  7997. }
  7998. };
  7999. const ShaderLib = {
  8000. basic: {
  8001. uniforms: mergeUniforms( [
  8002. UniformsLib.common,
  8003. UniformsLib.specularmap,
  8004. UniformsLib.envmap,
  8005. UniformsLib.aomap,
  8006. UniformsLib.lightmap,
  8007. UniformsLib.fog
  8008. ] ),
  8009. vertexShader: ShaderChunk.meshbasic_vert,
  8010. fragmentShader: ShaderChunk.meshbasic_frag
  8011. },
  8012. lambert: {
  8013. uniforms: mergeUniforms( [
  8014. UniformsLib.common,
  8015. UniformsLib.specularmap,
  8016. UniformsLib.envmap,
  8017. UniformsLib.aomap,
  8018. UniformsLib.lightmap,
  8019. UniformsLib.emissivemap,
  8020. UniformsLib.fog,
  8021. UniformsLib.lights,
  8022. {
  8023. emissive: { value: new Color( 0x000000 ) }
  8024. }
  8025. ] ),
  8026. vertexShader: ShaderChunk.meshlambert_vert,
  8027. fragmentShader: ShaderChunk.meshlambert_frag
  8028. },
  8029. phong: {
  8030. uniforms: mergeUniforms( [
  8031. UniformsLib.common,
  8032. UniformsLib.specularmap,
  8033. UniformsLib.envmap,
  8034. UniformsLib.aomap,
  8035. UniformsLib.lightmap,
  8036. UniformsLib.emissivemap,
  8037. UniformsLib.bumpmap,
  8038. UniformsLib.normalmap,
  8039. UniformsLib.displacementmap,
  8040. UniformsLib.fog,
  8041. UniformsLib.lights,
  8042. {
  8043. emissive: { value: new Color( 0x000000 ) },
  8044. specular: { value: new Color( 0x111111 ) },
  8045. shininess: { value: 30 }
  8046. }
  8047. ] ),
  8048. vertexShader: ShaderChunk.meshphong_vert,
  8049. fragmentShader: ShaderChunk.meshphong_frag
  8050. },
  8051. standard: {
  8052. uniforms: mergeUniforms( [
  8053. UniformsLib.common,
  8054. UniformsLib.envmap,
  8055. UniformsLib.aomap,
  8056. UniformsLib.lightmap,
  8057. UniformsLib.emissivemap,
  8058. UniformsLib.bumpmap,
  8059. UniformsLib.normalmap,
  8060. UniformsLib.displacementmap,
  8061. UniformsLib.roughnessmap,
  8062. UniformsLib.metalnessmap,
  8063. UniformsLib.fog,
  8064. UniformsLib.lights,
  8065. {
  8066. emissive: { value: new Color( 0x000000 ) },
  8067. roughness: { value: 1.0 },
  8068. metalness: { value: 0.0 },
  8069. envMapIntensity: { value: 1 } // temporary
  8070. }
  8071. ] ),
  8072. vertexShader: ShaderChunk.meshphysical_vert,
  8073. fragmentShader: ShaderChunk.meshphysical_frag
  8074. },
  8075. toon: {
  8076. uniforms: mergeUniforms( [
  8077. UniformsLib.common,
  8078. UniformsLib.aomap,
  8079. UniformsLib.lightmap,
  8080. UniformsLib.emissivemap,
  8081. UniformsLib.bumpmap,
  8082. UniformsLib.normalmap,
  8083. UniformsLib.displacementmap,
  8084. UniformsLib.gradientmap,
  8085. UniformsLib.fog,
  8086. UniformsLib.lights,
  8087. {
  8088. emissive: { value: new Color( 0x000000 ) }
  8089. }
  8090. ] ),
  8091. vertexShader: ShaderChunk.meshtoon_vert,
  8092. fragmentShader: ShaderChunk.meshtoon_frag
  8093. },
  8094. matcap: {
  8095. uniforms: mergeUniforms( [
  8096. UniformsLib.common,
  8097. UniformsLib.bumpmap,
  8098. UniformsLib.normalmap,
  8099. UniformsLib.displacementmap,
  8100. UniformsLib.fog,
  8101. {
  8102. matcap: { value: null }
  8103. }
  8104. ] ),
  8105. vertexShader: ShaderChunk.meshmatcap_vert,
  8106. fragmentShader: ShaderChunk.meshmatcap_frag
  8107. },
  8108. points: {
  8109. uniforms: mergeUniforms( [
  8110. UniformsLib.points,
  8111. UniformsLib.fog
  8112. ] ),
  8113. vertexShader: ShaderChunk.points_vert,
  8114. fragmentShader: ShaderChunk.points_frag
  8115. },
  8116. dashed: {
  8117. uniforms: mergeUniforms( [
  8118. UniformsLib.common,
  8119. UniformsLib.fog,
  8120. {
  8121. scale: { value: 1 },
  8122. dashSize: { value: 1 },
  8123. totalSize: { value: 2 }
  8124. }
  8125. ] ),
  8126. vertexShader: ShaderChunk.linedashed_vert,
  8127. fragmentShader: ShaderChunk.linedashed_frag
  8128. },
  8129. depth: {
  8130. uniforms: mergeUniforms( [
  8131. UniformsLib.common,
  8132. UniformsLib.displacementmap
  8133. ] ),
  8134. vertexShader: ShaderChunk.depth_vert,
  8135. fragmentShader: ShaderChunk.depth_frag
  8136. },
  8137. normal: {
  8138. uniforms: mergeUniforms( [
  8139. UniformsLib.common,
  8140. UniformsLib.bumpmap,
  8141. UniformsLib.normalmap,
  8142. UniformsLib.displacementmap,
  8143. {
  8144. opacity: { value: 1.0 }
  8145. }
  8146. ] ),
  8147. vertexShader: ShaderChunk.meshnormal_vert,
  8148. fragmentShader: ShaderChunk.meshnormal_frag
  8149. },
  8150. sprite: {
  8151. uniforms: mergeUniforms( [
  8152. UniformsLib.sprite,
  8153. UniformsLib.fog
  8154. ] ),
  8155. vertexShader: ShaderChunk.sprite_vert,
  8156. fragmentShader: ShaderChunk.sprite_frag
  8157. },
  8158. background: {
  8159. uniforms: {
  8160. uvTransform: { value: new Matrix3() },
  8161. t2D: { value: null },
  8162. },
  8163. vertexShader: ShaderChunk.background_vert,
  8164. fragmentShader: ShaderChunk.background_frag
  8165. },
  8166. /* -------------------------------------------------------------------------
  8167. // Cube map shader
  8168. ------------------------------------------------------------------------- */
  8169. cube: {
  8170. uniforms: mergeUniforms( [
  8171. UniformsLib.envmap,
  8172. {
  8173. opacity: { value: 1.0 }
  8174. }
  8175. ] ),
  8176. vertexShader: ShaderChunk.cube_vert,
  8177. fragmentShader: ShaderChunk.cube_frag
  8178. },
  8179. equirect: {
  8180. uniforms: {
  8181. tEquirect: { value: null },
  8182. },
  8183. vertexShader: ShaderChunk.equirect_vert,
  8184. fragmentShader: ShaderChunk.equirect_frag
  8185. },
  8186. distanceRGBA: {
  8187. uniforms: mergeUniforms( [
  8188. UniformsLib.common,
  8189. UniformsLib.displacementmap,
  8190. {
  8191. referencePosition: { value: new Vector3() },
  8192. nearDistance: { value: 1 },
  8193. farDistance: { value: 1000 }
  8194. }
  8195. ] ),
  8196. vertexShader: ShaderChunk.distanceRGBA_vert,
  8197. fragmentShader: ShaderChunk.distanceRGBA_frag
  8198. },
  8199. shadow: {
  8200. uniforms: mergeUniforms( [
  8201. UniformsLib.lights,
  8202. UniformsLib.fog,
  8203. {
  8204. color: { value: new Color( 0x00000 ) },
  8205. opacity: { value: 1.0 }
  8206. },
  8207. ] ),
  8208. vertexShader: ShaderChunk.shadow_vert,
  8209. fragmentShader: ShaderChunk.shadow_frag
  8210. }
  8211. };
  8212. ShaderLib.physical = {
  8213. uniforms: mergeUniforms( [
  8214. ShaderLib.standard.uniforms,
  8215. {
  8216. clearcoat: { value: 0 },
  8217. clearcoatMap: { value: null },
  8218. clearcoatRoughness: { value: 0 },
  8219. clearcoatRoughnessMap: { value: null },
  8220. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  8221. clearcoatNormalMap: { value: null },
  8222. sheen: { value: 0 },
  8223. sheenTint: { value: new Color( 0x000000 ) },
  8224. sheenRoughness: { value: 0 },
  8225. transmission: { value: 0 },
  8226. transmissionMap: { value: null },
  8227. transmissionSamplerSize: { value: new Vector2() },
  8228. transmissionSamplerMap: { value: null },
  8229. thickness: { value: 0 },
  8230. thicknessMap: { value: null },
  8231. attenuationDistance: { value: 0 },
  8232. attenuationTint: { value: new Color( 0x000000 ) },
  8233. specularIntensity: { value: 0 },
  8234. specularIntensityMap: { value: null },
  8235. specularTint: { value: new Color( 1, 1, 1 ) },
  8236. specularTintMap: { value: null },
  8237. }
  8238. ] ),
  8239. vertexShader: ShaderChunk.meshphysical_vert,
  8240. fragmentShader: ShaderChunk.meshphysical_frag
  8241. };
  8242. function WebGLBackground( renderer, cubemaps, state, objects, premultipliedAlpha ) {
  8243. const clearColor = new Color( 0x000000 );
  8244. let clearAlpha = 0;
  8245. let planeMesh;
  8246. let boxMesh;
  8247. let currentBackground = null;
  8248. let currentBackgroundVersion = 0;
  8249. let currentTonemapping = null;
  8250. function render( renderList, scene ) {
  8251. let forceClear = false;
  8252. let background = scene.isScene === true ? scene.background : null;
  8253. if ( background && background.isTexture ) {
  8254. background = cubemaps.get( background );
  8255. }
  8256. // Ignore background in AR
  8257. // TODO: Reconsider this.
  8258. const xr = renderer.xr;
  8259. const session = xr.getSession && xr.getSession();
  8260. if ( session && session.environmentBlendMode === 'additive' ) {
  8261. background = null;
  8262. }
  8263. if ( background === null ) {
  8264. setClear( clearColor, clearAlpha );
  8265. } else if ( background && background.isColor ) {
  8266. setClear( background, 1 );
  8267. forceClear = true;
  8268. }
  8269. if ( renderer.autoClear || forceClear ) {
  8270. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8271. }
  8272. if ( background && ( background.isCubeTexture || background.mapping === CubeUVReflectionMapping ) ) {
  8273. if ( boxMesh === undefined ) {
  8274. boxMesh = new Mesh(
  8275. new BoxGeometry( 1, 1, 1 ),
  8276. new ShaderMaterial( {
  8277. name: 'BackgroundCubeMaterial',
  8278. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8279. vertexShader: ShaderLib.cube.vertexShader,
  8280. fragmentShader: ShaderLib.cube.fragmentShader,
  8281. side: BackSide,
  8282. depthTest: false,
  8283. depthWrite: false,
  8284. fog: false
  8285. } )
  8286. );
  8287. boxMesh.geometry.deleteAttribute( 'normal' );
  8288. boxMesh.geometry.deleteAttribute( 'uv' );
  8289. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8290. this.matrixWorld.copyPosition( camera.matrixWorld );
  8291. };
  8292. // enable code injection for non-built-in material
  8293. Object.defineProperty( boxMesh.material, 'envMap', {
  8294. get: function () {
  8295. return this.uniforms.envMap.value;
  8296. }
  8297. } );
  8298. objects.update( boxMesh );
  8299. }
  8300. boxMesh.material.uniforms.envMap.value = background;
  8301. boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? - 1 : 1;
  8302. if ( currentBackground !== background ||
  8303. currentBackgroundVersion !== background.version ||
  8304. currentTonemapping !== renderer.toneMapping ) {
  8305. boxMesh.material.needsUpdate = true;
  8306. currentBackground = background;
  8307. currentBackgroundVersion = background.version;
  8308. currentTonemapping = renderer.toneMapping;
  8309. }
  8310. // push to the pre-sorted opaque render list
  8311. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8312. } else if ( background && background.isTexture ) {
  8313. if ( planeMesh === undefined ) {
  8314. planeMesh = new Mesh(
  8315. new PlaneGeometry( 2, 2 ),
  8316. new ShaderMaterial( {
  8317. name: 'BackgroundMaterial',
  8318. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8319. vertexShader: ShaderLib.background.vertexShader,
  8320. fragmentShader: ShaderLib.background.fragmentShader,
  8321. side: FrontSide,
  8322. depthTest: false,
  8323. depthWrite: false,
  8324. fog: false
  8325. } )
  8326. );
  8327. planeMesh.geometry.deleteAttribute( 'normal' );
  8328. // enable code injection for non-built-in material
  8329. Object.defineProperty( planeMesh.material, 'map', {
  8330. get: function () {
  8331. return this.uniforms.t2D.value;
  8332. }
  8333. } );
  8334. objects.update( planeMesh );
  8335. }
  8336. planeMesh.material.uniforms.t2D.value = background;
  8337. if ( background.matrixAutoUpdate === true ) {
  8338. background.updateMatrix();
  8339. }
  8340. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8341. if ( currentBackground !== background ||
  8342. currentBackgroundVersion !== background.version ||
  8343. currentTonemapping !== renderer.toneMapping ) {
  8344. planeMesh.material.needsUpdate = true;
  8345. currentBackground = background;
  8346. currentBackgroundVersion = background.version;
  8347. currentTonemapping = renderer.toneMapping;
  8348. }
  8349. // push to the pre-sorted opaque render list
  8350. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8351. }
  8352. }
  8353. function setClear( color, alpha ) {
  8354. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8355. }
  8356. return {
  8357. getClearColor: function () {
  8358. return clearColor;
  8359. },
  8360. setClearColor: function ( color, alpha = 1 ) {
  8361. clearColor.set( color );
  8362. clearAlpha = alpha;
  8363. setClear( clearColor, clearAlpha );
  8364. },
  8365. getClearAlpha: function () {
  8366. return clearAlpha;
  8367. },
  8368. setClearAlpha: function ( alpha ) {
  8369. clearAlpha = alpha;
  8370. setClear( clearColor, clearAlpha );
  8371. },
  8372. render: render
  8373. };
  8374. }
  8375. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  8376. const maxVertexAttributes = gl.getParameter( 34921 );
  8377. const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  8378. const vaoAvailable = capabilities.isWebGL2 || extension !== null;
  8379. const bindingStates = {};
  8380. const defaultState = createBindingState( null );
  8381. let currentState = defaultState;
  8382. function setup( object, material, program, geometry, index ) {
  8383. let updateBuffers = false;
  8384. if ( vaoAvailable ) {
  8385. const state = getBindingState( geometry, program, material );
  8386. if ( currentState !== state ) {
  8387. currentState = state;
  8388. bindVertexArrayObject( currentState.object );
  8389. }
  8390. updateBuffers = needsUpdate( geometry, index );
  8391. if ( updateBuffers ) saveCache( geometry, index );
  8392. } else {
  8393. const wireframe = ( material.wireframe === true );
  8394. if ( currentState.geometry !== geometry.id ||
  8395. currentState.program !== program.id ||
  8396. currentState.wireframe !== wireframe ) {
  8397. currentState.geometry = geometry.id;
  8398. currentState.program = program.id;
  8399. currentState.wireframe = wireframe;
  8400. updateBuffers = true;
  8401. }
  8402. }
  8403. if ( object.isInstancedMesh === true ) {
  8404. updateBuffers = true;
  8405. }
  8406. if ( index !== null ) {
  8407. attributes.update( index, 34963 );
  8408. }
  8409. if ( updateBuffers ) {
  8410. setupVertexAttributes( object, material, program, geometry );
  8411. if ( index !== null ) {
  8412. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  8413. }
  8414. }
  8415. }
  8416. function createVertexArrayObject() {
  8417. if ( capabilities.isWebGL2 ) return gl.createVertexArray();
  8418. return extension.createVertexArrayOES();
  8419. }
  8420. function bindVertexArrayObject( vao ) {
  8421. if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
  8422. return extension.bindVertexArrayOES( vao );
  8423. }
  8424. function deleteVertexArrayObject( vao ) {
  8425. if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
  8426. return extension.deleteVertexArrayOES( vao );
  8427. }
  8428. function getBindingState( geometry, program, material ) {
  8429. const wireframe = ( material.wireframe === true );
  8430. let programMap = bindingStates[ geometry.id ];
  8431. if ( programMap === undefined ) {
  8432. programMap = {};
  8433. bindingStates[ geometry.id ] = programMap;
  8434. }
  8435. let stateMap = programMap[ program.id ];
  8436. if ( stateMap === undefined ) {
  8437. stateMap = {};
  8438. programMap[ program.id ] = stateMap;
  8439. }
  8440. let state = stateMap[ wireframe ];
  8441. if ( state === undefined ) {
  8442. state = createBindingState( createVertexArrayObject() );
  8443. stateMap[ wireframe ] = state;
  8444. }
  8445. return state;
  8446. }
  8447. function createBindingState( vao ) {
  8448. const newAttributes = [];
  8449. const enabledAttributes = [];
  8450. const attributeDivisors = [];
  8451. for ( let i = 0; i < maxVertexAttributes; i ++ ) {
  8452. newAttributes[ i ] = 0;
  8453. enabledAttributes[ i ] = 0;
  8454. attributeDivisors[ i ] = 0;
  8455. }
  8456. return {
  8457. // for backward compatibility on non-VAO support browser
  8458. geometry: null,
  8459. program: null,
  8460. wireframe: false,
  8461. newAttributes: newAttributes,
  8462. enabledAttributes: enabledAttributes,
  8463. attributeDivisors: attributeDivisors,
  8464. object: vao,
  8465. attributes: {},
  8466. index: null
  8467. };
  8468. }
  8469. function needsUpdate( geometry, index ) {
  8470. const cachedAttributes = currentState.attributes;
  8471. const geometryAttributes = geometry.attributes;
  8472. let attributesNum = 0;
  8473. for ( const key in geometryAttributes ) {
  8474. const cachedAttribute = cachedAttributes[ key ];
  8475. const geometryAttribute = geometryAttributes[ key ];
  8476. if ( cachedAttribute === undefined ) return true;
  8477. if ( cachedAttribute.attribute !== geometryAttribute ) return true;
  8478. if ( cachedAttribute.data !== geometryAttribute.data ) return true;
  8479. attributesNum ++;
  8480. }
  8481. if ( currentState.attributesNum !== attributesNum ) return true;
  8482. if ( currentState.index !== index ) return true;
  8483. return false;
  8484. }
  8485. function saveCache( geometry, index ) {
  8486. const cache = {};
  8487. const attributes = geometry.attributes;
  8488. let attributesNum = 0;
  8489. for ( const key in attributes ) {
  8490. const attribute = attributes[ key ];
  8491. const data = {};
  8492. data.attribute = attribute;
  8493. if ( attribute.data ) {
  8494. data.data = attribute.data;
  8495. }
  8496. cache[ key ] = data;
  8497. attributesNum ++;
  8498. }
  8499. currentState.attributes = cache;
  8500. currentState.attributesNum = attributesNum;
  8501. currentState.index = index;
  8502. }
  8503. function initAttributes() {
  8504. const newAttributes = currentState.newAttributes;
  8505. for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {
  8506. newAttributes[ i ] = 0;
  8507. }
  8508. }
  8509. function enableAttribute( attribute ) {
  8510. enableAttributeAndDivisor( attribute, 0 );
  8511. }
  8512. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  8513. const newAttributes = currentState.newAttributes;
  8514. const enabledAttributes = currentState.enabledAttributes;
  8515. const attributeDivisors = currentState.attributeDivisors;
  8516. newAttributes[ attribute ] = 1;
  8517. if ( enabledAttributes[ attribute ] === 0 ) {
  8518. gl.enableVertexAttribArray( attribute );
  8519. enabledAttributes[ attribute ] = 1;
  8520. }
  8521. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  8522. const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  8523. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  8524. attributeDivisors[ attribute ] = meshPerAttribute;
  8525. }
  8526. }
  8527. function disableUnusedAttributes() {
  8528. const newAttributes = currentState.newAttributes;
  8529. const enabledAttributes = currentState.enabledAttributes;
  8530. for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  8531. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  8532. gl.disableVertexAttribArray( i );
  8533. enabledAttributes[ i ] = 0;
  8534. }
  8535. }
  8536. }
  8537. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  8538. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  8539. gl.vertexAttribIPointer( index, size, type, stride, offset );
  8540. } else {
  8541. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  8542. }
  8543. }
  8544. function setupVertexAttributes( object, material, program, geometry ) {
  8545. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  8546. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  8547. }
  8548. initAttributes();
  8549. const geometryAttributes = geometry.attributes;
  8550. const programAttributes = program.getAttributes();
  8551. const materialDefaultAttributeValues = material.defaultAttributeValues;
  8552. for ( const name in programAttributes ) {
  8553. const programAttribute = programAttributes[ name ];
  8554. if ( programAttribute.location >= 0 ) {
  8555. let geometryAttribute = geometryAttributes[ name ];
  8556. if ( geometryAttribute === undefined ) {
  8557. if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix;
  8558. if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor;
  8559. }
  8560. if ( geometryAttribute !== undefined ) {
  8561. const normalized = geometryAttribute.normalized;
  8562. const size = geometryAttribute.itemSize;
  8563. const attribute = attributes.get( geometryAttribute );
  8564. // TODO Attribute may not be available on context restore
  8565. if ( attribute === undefined ) continue;
  8566. const buffer = attribute.buffer;
  8567. const type = attribute.type;
  8568. const bytesPerElement = attribute.bytesPerElement;
  8569. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  8570. const data = geometryAttribute.data;
  8571. const stride = data.stride;
  8572. const offset = geometryAttribute.offset;
  8573. if ( data && data.isInstancedInterleavedBuffer ) {
  8574. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8575. enableAttributeAndDivisor( programAttribute.location + i, data.meshPerAttribute );
  8576. }
  8577. if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) {
  8578. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  8579. }
  8580. } else {
  8581. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8582. enableAttribute( programAttribute.location + i );
  8583. }
  8584. }
  8585. gl.bindBuffer( 34962, buffer );
  8586. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8587. vertexAttribPointer(
  8588. programAttribute.location + i,
  8589. size / programAttribute.locationSize,
  8590. type,
  8591. normalized,
  8592. stride * bytesPerElement,
  8593. ( offset + ( size / programAttribute.locationSize ) * i ) * bytesPerElement
  8594. );
  8595. }
  8596. } else {
  8597. if ( geometryAttribute.isInstancedBufferAttribute ) {
  8598. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8599. enableAttributeAndDivisor( programAttribute.location + i, geometryAttribute.meshPerAttribute );
  8600. }
  8601. if ( object.isInstancedMesh !== true && geometry._maxInstanceCount === undefined ) {
  8602. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  8603. }
  8604. } else {
  8605. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8606. enableAttribute( programAttribute.location + i );
  8607. }
  8608. }
  8609. gl.bindBuffer( 34962, buffer );
  8610. for ( let i = 0; i < programAttribute.locationSize; i ++ ) {
  8611. vertexAttribPointer(
  8612. programAttribute.location + i,
  8613. size / programAttribute.locationSize,
  8614. type,
  8615. normalized,
  8616. size * bytesPerElement,
  8617. ( size / programAttribute.locationSize ) * i * bytesPerElement
  8618. );
  8619. }
  8620. }
  8621. } else if ( materialDefaultAttributeValues !== undefined ) {
  8622. const value = materialDefaultAttributeValues[ name ];
  8623. if ( value !== undefined ) {
  8624. switch ( value.length ) {
  8625. case 2:
  8626. gl.vertexAttrib2fv( programAttribute.location, value );
  8627. break;
  8628. case 3:
  8629. gl.vertexAttrib3fv( programAttribute.location, value );
  8630. break;
  8631. case 4:
  8632. gl.vertexAttrib4fv( programAttribute.location, value );
  8633. break;
  8634. default:
  8635. gl.vertexAttrib1fv( programAttribute.location, value );
  8636. }
  8637. }
  8638. }
  8639. }
  8640. }
  8641. disableUnusedAttributes();
  8642. }
  8643. function dispose() {
  8644. reset();
  8645. for ( const geometryId in bindingStates ) {
  8646. const programMap = bindingStates[ geometryId ];
  8647. for ( const programId in programMap ) {
  8648. const stateMap = programMap[ programId ];
  8649. for ( const wireframe in stateMap ) {
  8650. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8651. delete stateMap[ wireframe ];
  8652. }
  8653. delete programMap[ programId ];
  8654. }
  8655. delete bindingStates[ geometryId ];
  8656. }
  8657. }
  8658. function releaseStatesOfGeometry( geometry ) {
  8659. if ( bindingStates[ geometry.id ] === undefined ) return;
  8660. const programMap = bindingStates[ geometry.id ];
  8661. for ( const programId in programMap ) {
  8662. const stateMap = programMap[ programId ];
  8663. for ( const wireframe in stateMap ) {
  8664. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8665. delete stateMap[ wireframe ];
  8666. }
  8667. delete programMap[ programId ];
  8668. }
  8669. delete bindingStates[ geometry.id ];
  8670. }
  8671. function releaseStatesOfProgram( program ) {
  8672. for ( const geometryId in bindingStates ) {
  8673. const programMap = bindingStates[ geometryId ];
  8674. if ( programMap[ program.id ] === undefined ) continue;
  8675. const stateMap = programMap[ program.id ];
  8676. for ( const wireframe in stateMap ) {
  8677. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8678. delete stateMap[ wireframe ];
  8679. }
  8680. delete programMap[ program.id ];
  8681. }
  8682. }
  8683. function reset() {
  8684. resetDefaultState();
  8685. if ( currentState === defaultState ) return;
  8686. currentState = defaultState;
  8687. bindVertexArrayObject( currentState.object );
  8688. }
  8689. // for backward-compatilibity
  8690. function resetDefaultState() {
  8691. defaultState.geometry = null;
  8692. defaultState.program = null;
  8693. defaultState.wireframe = false;
  8694. }
  8695. return {
  8696. setup: setup,
  8697. reset: reset,
  8698. resetDefaultState: resetDefaultState,
  8699. dispose: dispose,
  8700. releaseStatesOfGeometry: releaseStatesOfGeometry,
  8701. releaseStatesOfProgram: releaseStatesOfProgram,
  8702. initAttributes: initAttributes,
  8703. enableAttribute: enableAttribute,
  8704. disableUnusedAttributes: disableUnusedAttributes
  8705. };
  8706. }
  8707. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8708. const isWebGL2 = capabilities.isWebGL2;
  8709. let mode;
  8710. function setMode( value ) {
  8711. mode = value;
  8712. }
  8713. function render( start, count ) {
  8714. gl.drawArrays( mode, start, count );
  8715. info.update( count, mode, 1 );
  8716. }
  8717. function renderInstances( start, count, primcount ) {
  8718. if ( primcount === 0 ) return;
  8719. let extension, methodName;
  8720. if ( isWebGL2 ) {
  8721. extension = gl;
  8722. methodName = 'drawArraysInstanced';
  8723. } else {
  8724. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8725. methodName = 'drawArraysInstancedANGLE';
  8726. if ( extension === null ) {
  8727. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8728. return;
  8729. }
  8730. }
  8731. extension[ methodName ]( mode, start, count, primcount );
  8732. info.update( count, mode, primcount );
  8733. }
  8734. //
  8735. this.setMode = setMode;
  8736. this.render = render;
  8737. this.renderInstances = renderInstances;
  8738. }
  8739. function WebGLCapabilities( gl, extensions, parameters ) {
  8740. let maxAnisotropy;
  8741. function getMaxAnisotropy() {
  8742. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8743. if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
  8744. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8745. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8746. } else {
  8747. maxAnisotropy = 0;
  8748. }
  8749. return maxAnisotropy;
  8750. }
  8751. function getMaxPrecision( precision ) {
  8752. if ( precision === 'highp' ) {
  8753. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8754. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8755. return 'highp';
  8756. }
  8757. precision = 'mediump';
  8758. }
  8759. if ( precision === 'mediump' ) {
  8760. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8761. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8762. return 'mediump';
  8763. }
  8764. }
  8765. return 'lowp';
  8766. }
  8767. /* eslint-disable no-undef */
  8768. const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  8769. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  8770. /* eslint-enable no-undef */
  8771. let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8772. const maxPrecision = getMaxPrecision( precision );
  8773. if ( maxPrecision !== precision ) {
  8774. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8775. precision = maxPrecision;
  8776. }
  8777. const drawBuffers = isWebGL2 || extensions.has( 'WEBGL_draw_buffers' );
  8778. const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8779. const maxTextures = gl.getParameter( 34930 );
  8780. const maxVertexTextures = gl.getParameter( 35660 );
  8781. const maxTextureSize = gl.getParameter( 3379 );
  8782. const maxCubemapSize = gl.getParameter( 34076 );
  8783. const maxAttributes = gl.getParameter( 34921 );
  8784. const maxVertexUniforms = gl.getParameter( 36347 );
  8785. const maxVaryings = gl.getParameter( 36348 );
  8786. const maxFragmentUniforms = gl.getParameter( 36349 );
  8787. const vertexTextures = maxVertexTextures > 0;
  8788. const floatFragmentTextures = isWebGL2 || extensions.has( 'OES_texture_float' );
  8789. const floatVertexTextures = vertexTextures && floatFragmentTextures;
  8790. const maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8791. return {
  8792. isWebGL2: isWebGL2,
  8793. drawBuffers: drawBuffers,
  8794. getMaxAnisotropy: getMaxAnisotropy,
  8795. getMaxPrecision: getMaxPrecision,
  8796. precision: precision,
  8797. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8798. maxTextures: maxTextures,
  8799. maxVertexTextures: maxVertexTextures,
  8800. maxTextureSize: maxTextureSize,
  8801. maxCubemapSize: maxCubemapSize,
  8802. maxAttributes: maxAttributes,
  8803. maxVertexUniforms: maxVertexUniforms,
  8804. maxVaryings: maxVaryings,
  8805. maxFragmentUniforms: maxFragmentUniforms,
  8806. vertexTextures: vertexTextures,
  8807. floatFragmentTextures: floatFragmentTextures,
  8808. floatVertexTextures: floatVertexTextures,
  8809. maxSamples: maxSamples
  8810. };
  8811. }
  8812. function WebGLClipping( properties ) {
  8813. const scope = this;
  8814. let globalState = null,
  8815. numGlobalPlanes = 0,
  8816. localClippingEnabled = false,
  8817. renderingShadows = false;
  8818. const plane = new Plane(),
  8819. viewNormalMatrix = new Matrix3(),
  8820. uniform = { value: null, needsUpdate: false };
  8821. this.uniform = uniform;
  8822. this.numPlanes = 0;
  8823. this.numIntersection = 0;
  8824. this.init = function ( planes, enableLocalClipping, camera ) {
  8825. const enabled =
  8826. planes.length !== 0 ||
  8827. enableLocalClipping ||
  8828. // enable state of previous frame - the clipping code has to
  8829. // run another frame in order to reset the state:
  8830. numGlobalPlanes !== 0 ||
  8831. localClippingEnabled;
  8832. localClippingEnabled = enableLocalClipping;
  8833. globalState = projectPlanes( planes, camera, 0 );
  8834. numGlobalPlanes = planes.length;
  8835. return enabled;
  8836. };
  8837. this.beginShadows = function () {
  8838. renderingShadows = true;
  8839. projectPlanes( null );
  8840. };
  8841. this.endShadows = function () {
  8842. renderingShadows = false;
  8843. resetGlobalState();
  8844. };
  8845. this.setState = function ( material, camera, useCache ) {
  8846. const planes = material.clippingPlanes,
  8847. clipIntersection = material.clipIntersection,
  8848. clipShadows = material.clipShadows;
  8849. const materialProperties = properties.get( material );
  8850. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8851. // there's no local clipping
  8852. if ( renderingShadows ) {
  8853. // there's no global clipping
  8854. projectPlanes( null );
  8855. } else {
  8856. resetGlobalState();
  8857. }
  8858. } else {
  8859. const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8860. lGlobal = nGlobal * 4;
  8861. let dstArray = materialProperties.clippingState || null;
  8862. uniform.value = dstArray; // ensure unique state
  8863. dstArray = projectPlanes( planes, camera, lGlobal, useCache );
  8864. for ( let i = 0; i !== lGlobal; ++ i ) {
  8865. dstArray[ i ] = globalState[ i ];
  8866. }
  8867. materialProperties.clippingState = dstArray;
  8868. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8869. this.numPlanes += nGlobal;
  8870. }
  8871. };
  8872. function resetGlobalState() {
  8873. if ( uniform.value !== globalState ) {
  8874. uniform.value = globalState;
  8875. uniform.needsUpdate = numGlobalPlanes > 0;
  8876. }
  8877. scope.numPlanes = numGlobalPlanes;
  8878. scope.numIntersection = 0;
  8879. }
  8880. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8881. const nPlanes = planes !== null ? planes.length : 0;
  8882. let dstArray = null;
  8883. if ( nPlanes !== 0 ) {
  8884. dstArray = uniform.value;
  8885. if ( skipTransform !== true || dstArray === null ) {
  8886. const flatSize = dstOffset + nPlanes * 4,
  8887. viewMatrix = camera.matrixWorldInverse;
  8888. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8889. if ( dstArray === null || dstArray.length < flatSize ) {
  8890. dstArray = new Float32Array( flatSize );
  8891. }
  8892. for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8893. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8894. plane.normal.toArray( dstArray, i4 );
  8895. dstArray[ i4 + 3 ] = plane.constant;
  8896. }
  8897. }
  8898. uniform.value = dstArray;
  8899. uniform.needsUpdate = true;
  8900. }
  8901. scope.numPlanes = nPlanes;
  8902. scope.numIntersection = 0;
  8903. return dstArray;
  8904. }
  8905. }
  8906. function WebGLCubeMaps( renderer ) {
  8907. let cubemaps = new WeakMap();
  8908. function mapTextureMapping( texture, mapping ) {
  8909. if ( mapping === EquirectangularReflectionMapping ) {
  8910. texture.mapping = CubeReflectionMapping;
  8911. } else if ( mapping === EquirectangularRefractionMapping ) {
  8912. texture.mapping = CubeRefractionMapping;
  8913. }
  8914. return texture;
  8915. }
  8916. function get( texture ) {
  8917. if ( texture && texture.isTexture && texture.isRenderTargetTexture === false ) {
  8918. const mapping = texture.mapping;
  8919. if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
  8920. if ( cubemaps.has( texture ) ) {
  8921. const cubemap = cubemaps.get( texture ).texture;
  8922. return mapTextureMapping( cubemap, texture.mapping );
  8923. } else {
  8924. const image = texture.image;
  8925. if ( image && image.height > 0 ) {
  8926. const currentRenderTarget = renderer.getRenderTarget();
  8927. const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
  8928. renderTarget.fromEquirectangularTexture( renderer, texture );
  8929. cubemaps.set( texture, renderTarget );
  8930. renderer.setRenderTarget( currentRenderTarget );
  8931. texture.addEventListener( 'dispose', onTextureDispose );
  8932. return mapTextureMapping( renderTarget.texture, texture.mapping );
  8933. } else {
  8934. // image not yet ready. try the conversion next frame
  8935. return null;
  8936. }
  8937. }
  8938. }
  8939. }
  8940. return texture;
  8941. }
  8942. function onTextureDispose( event ) {
  8943. const texture = event.target;
  8944. texture.removeEventListener( 'dispose', onTextureDispose );
  8945. const cubemap = cubemaps.get( texture );
  8946. if ( cubemap !== undefined ) {
  8947. cubemaps.delete( texture );
  8948. cubemap.dispose();
  8949. }
  8950. }
  8951. function dispose() {
  8952. cubemaps = new WeakMap();
  8953. }
  8954. return {
  8955. get: get,
  8956. dispose: dispose
  8957. };
  8958. }
  8959. class OrthographicCamera extends Camera {
  8960. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  8961. super();
  8962. this.type = 'OrthographicCamera';
  8963. this.zoom = 1;
  8964. this.view = null;
  8965. this.left = left;
  8966. this.right = right;
  8967. this.top = top;
  8968. this.bottom = bottom;
  8969. this.near = near;
  8970. this.far = far;
  8971. this.updateProjectionMatrix();
  8972. }
  8973. copy( source, recursive ) {
  8974. super.copy( source, recursive );
  8975. this.left = source.left;
  8976. this.right = source.right;
  8977. this.top = source.top;
  8978. this.bottom = source.bottom;
  8979. this.near = source.near;
  8980. this.far = source.far;
  8981. this.zoom = source.zoom;
  8982. this.view = source.view === null ? null : Object.assign( {}, source.view );
  8983. return this;
  8984. }
  8985. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  8986. if ( this.view === null ) {
  8987. this.view = {
  8988. enabled: true,
  8989. fullWidth: 1,
  8990. fullHeight: 1,
  8991. offsetX: 0,
  8992. offsetY: 0,
  8993. width: 1,
  8994. height: 1
  8995. };
  8996. }
  8997. this.view.enabled = true;
  8998. this.view.fullWidth = fullWidth;
  8999. this.view.fullHeight = fullHeight;
  9000. this.view.offsetX = x;
  9001. this.view.offsetY = y;
  9002. this.view.width = width;
  9003. this.view.height = height;
  9004. this.updateProjectionMatrix();
  9005. }
  9006. clearViewOffset() {
  9007. if ( this.view !== null ) {
  9008. this.view.enabled = false;
  9009. }
  9010. this.updateProjectionMatrix();
  9011. }
  9012. updateProjectionMatrix() {
  9013. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9014. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9015. const cx = ( this.right + this.left ) / 2;
  9016. const cy = ( this.top + this.bottom ) / 2;
  9017. let left = cx - dx;
  9018. let right = cx + dx;
  9019. let top = cy + dy;
  9020. let bottom = cy - dy;
  9021. if ( this.view !== null && this.view.enabled ) {
  9022. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  9023. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  9024. left += scaleW * this.view.offsetX;
  9025. right = left + scaleW * this.view.width;
  9026. top -= scaleH * this.view.offsetY;
  9027. bottom = top - scaleH * this.view.height;
  9028. }
  9029. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  9030. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  9031. }
  9032. toJSON( meta ) {
  9033. const data = super.toJSON( meta );
  9034. data.object.zoom = this.zoom;
  9035. data.object.left = this.left;
  9036. data.object.right = this.right;
  9037. data.object.top = this.top;
  9038. data.object.bottom = this.bottom;
  9039. data.object.near = this.near;
  9040. data.object.far = this.far;
  9041. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  9042. return data;
  9043. }
  9044. }
  9045. OrthographicCamera.prototype.isOrthographicCamera = true;
  9046. class RawShaderMaterial extends ShaderMaterial {
  9047. constructor( parameters ) {
  9048. super( parameters );
  9049. this.type = 'RawShaderMaterial';
  9050. }
  9051. }
  9052. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  9053. const LOD_MIN = 4;
  9054. const LOD_MAX = 8;
  9055. const SIZE_MAX = Math.pow( 2, LOD_MAX );
  9056. // The standard deviations (radians) associated with the extra mips. These are
  9057. // chosen to approximate a Trowbridge-Reitz distribution function times the
  9058. // geometric shadowing function. These sigma values squared must match the
  9059. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  9060. const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  9061. const TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  9062. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  9063. // samples and exit early, but not recompile the shader.
  9064. const MAX_SAMPLES = 20;
  9065. const ENCODINGS = {
  9066. [ LinearEncoding ]: 0,
  9067. [ sRGBEncoding ]: 1,
  9068. [ RGBEEncoding ]: 2,
  9069. [ RGBM7Encoding ]: 3,
  9070. [ RGBM16Encoding ]: 4,
  9071. [ RGBDEncoding ]: 5,
  9072. [ GammaEncoding ]: 6
  9073. };
  9074. const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
  9075. const { _lodPlanes, _sizeLods, _sigmas } = /*@__PURE__*/ _createPlanes();
  9076. const _clearColor = /*@__PURE__*/ new Color();
  9077. let _oldTarget = null;
  9078. // Golden Ratio
  9079. const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  9080. const INV_PHI = 1 / PHI;
  9081. // Vertices of a dodecahedron (except the opposites, which represent the
  9082. // same axis), used as axis directions evenly spread on a sphere.
  9083. const _axisDirections = [
  9084. /*@__PURE__*/ new Vector3( 1, 1, 1 ),
  9085. /*@__PURE__*/ new Vector3( - 1, 1, 1 ),
  9086. /*@__PURE__*/ new Vector3( 1, 1, - 1 ),
  9087. /*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
  9088. /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
  9089. /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
  9090. /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
  9091. /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
  9092. /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
  9093. /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ) ];
  9094. /**
  9095. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  9096. * (PMREM) from a cubeMap environment texture. This allows different levels of
  9097. * blur to be quickly accessed based on material roughness. It is packed into a
  9098. * special CubeUV format that allows us to perform custom interpolation so that
  9099. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  9100. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  9101. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  9102. * higher roughness levels. In this way we maintain resolution to smoothly
  9103. * interpolate diffuse lighting while limiting sampling computation.
  9104. *
  9105. * Paper: Fast, Accurate Image-Based Lighting
  9106. * https://drive.google.com/file/d/15y8r_UpKlU9SvV4ILb0C3qCPecS8pvLz/view
  9107. */
  9108. class PMREMGenerator {
  9109. constructor( renderer ) {
  9110. this._renderer = renderer;
  9111. this._pingPongRenderTarget = null;
  9112. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  9113. this._equirectShader = null;
  9114. this._cubemapShader = null;
  9115. this._compileMaterial( this._blurMaterial );
  9116. }
  9117. /**
  9118. * Generates a PMREM from a supplied Scene, which can be faster than using an
  9119. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  9120. * in radians to be applied to the scene before PMREM generation. Optional near
  9121. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  9122. * is placed at the origin).
  9123. */
  9124. fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
  9125. _oldTarget = this._renderer.getRenderTarget();
  9126. const cubeUVRenderTarget = this._allocateTargets();
  9127. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  9128. if ( sigma > 0 ) {
  9129. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  9130. }
  9131. this._applyPMREM( cubeUVRenderTarget );
  9132. this._cleanup( cubeUVRenderTarget );
  9133. return cubeUVRenderTarget;
  9134. }
  9135. /**
  9136. * Generates a PMREM from an equirectangular texture, which can be either LDR
  9137. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  9138. * as this matches best with the 256 x 256 cubemap output.
  9139. */
  9140. fromEquirectangular( equirectangular ) {
  9141. return this._fromTexture( equirectangular );
  9142. }
  9143. /**
  9144. * Generates a PMREM from an cubemap texture, which can be either LDR
  9145. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  9146. * as this matches best with the 256 x 256 cubemap output.
  9147. */
  9148. fromCubemap( cubemap ) {
  9149. return this._fromTexture( cubemap );
  9150. }
  9151. /**
  9152. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  9153. * your texture's network fetch for increased concurrency.
  9154. */
  9155. compileCubemapShader() {
  9156. if ( this._cubemapShader === null ) {
  9157. this._cubemapShader = _getCubemapShader();
  9158. this._compileMaterial( this._cubemapShader );
  9159. }
  9160. }
  9161. /**
  9162. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  9163. * your texture's network fetch for increased concurrency.
  9164. */
  9165. compileEquirectangularShader() {
  9166. if ( this._equirectShader === null ) {
  9167. this._equirectShader = _getEquirectShader();
  9168. this._compileMaterial( this._equirectShader );
  9169. }
  9170. }
  9171. /**
  9172. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  9173. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  9174. * one of them will cause any others to also become unusable.
  9175. */
  9176. dispose() {
  9177. this._blurMaterial.dispose();
  9178. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  9179. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  9180. for ( let i = 0; i < _lodPlanes.length; i ++ ) {
  9181. _lodPlanes[ i ].dispose();
  9182. }
  9183. }
  9184. // private interface
  9185. _cleanup( outputTarget ) {
  9186. this._pingPongRenderTarget.dispose();
  9187. this._renderer.setRenderTarget( _oldTarget );
  9188. outputTarget.scissorTest = false;
  9189. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  9190. }
  9191. _fromTexture( texture ) {
  9192. _oldTarget = this._renderer.getRenderTarget();
  9193. const cubeUVRenderTarget = this._allocateTargets( texture );
  9194. this._textureToCubeUV( texture, cubeUVRenderTarget );
  9195. this._applyPMREM( cubeUVRenderTarget );
  9196. this._cleanup( cubeUVRenderTarget );
  9197. return cubeUVRenderTarget;
  9198. }
  9199. _allocateTargets( texture ) { // warning: null texture is valid
  9200. const params = {
  9201. magFilter: NearestFilter,
  9202. minFilter: NearestFilter,
  9203. generateMipmaps: false,
  9204. type: UnsignedByteType,
  9205. format: RGBEFormat,
  9206. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  9207. depthBuffer: false
  9208. };
  9209. const cubeUVRenderTarget = _createRenderTarget( params );
  9210. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  9211. this._pingPongRenderTarget = _createRenderTarget( params );
  9212. return cubeUVRenderTarget;
  9213. }
  9214. _compileMaterial( material ) {
  9215. const tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  9216. this._renderer.compile( tmpMesh, _flatCamera );
  9217. }
  9218. _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
  9219. const fov = 90;
  9220. const aspect = 1;
  9221. const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  9222. const upSign = [ 1, - 1, 1, 1, 1, 1 ];
  9223. const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  9224. const renderer = this._renderer;
  9225. const originalAutoClear = renderer.autoClear;
  9226. const outputEncoding = renderer.outputEncoding;
  9227. const toneMapping = renderer.toneMapping;
  9228. renderer.getClearColor( _clearColor );
  9229. renderer.toneMapping = NoToneMapping;
  9230. renderer.outputEncoding = LinearEncoding;
  9231. renderer.autoClear = false;
  9232. const backgroundMaterial = new MeshBasicMaterial( {
  9233. name: 'PMREM.Background',
  9234. side: BackSide,
  9235. depthWrite: false,
  9236. depthTest: false,
  9237. } );
  9238. const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
  9239. let useSolidColor = false;
  9240. const background = scene.background;
  9241. if ( background ) {
  9242. if ( background.isColor ) {
  9243. backgroundMaterial.color.copy( background );
  9244. scene.background = null;
  9245. useSolidColor = true;
  9246. }
  9247. } else {
  9248. backgroundMaterial.color.copy( _clearColor );
  9249. useSolidColor = true;
  9250. }
  9251. for ( let i = 0; i < 6; i ++ ) {
  9252. const col = i % 3;
  9253. if ( col == 0 ) {
  9254. cubeCamera.up.set( 0, upSign[ i ], 0 );
  9255. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  9256. } else if ( col == 1 ) {
  9257. cubeCamera.up.set( 0, 0, upSign[ i ] );
  9258. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  9259. } else {
  9260. cubeCamera.up.set( 0, upSign[ i ], 0 );
  9261. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  9262. }
  9263. _setViewport( cubeUVRenderTarget,
  9264. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  9265. renderer.setRenderTarget( cubeUVRenderTarget );
  9266. if ( useSolidColor ) {
  9267. renderer.render( backgroundBox, cubeCamera );
  9268. }
  9269. renderer.render( scene, cubeCamera );
  9270. }
  9271. backgroundBox.geometry.dispose();
  9272. backgroundBox.material.dispose();
  9273. renderer.toneMapping = toneMapping;
  9274. renderer.outputEncoding = outputEncoding;
  9275. renderer.autoClear = originalAutoClear;
  9276. scene.background = background;
  9277. }
  9278. _textureToCubeUV( texture, cubeUVRenderTarget ) {
  9279. const renderer = this._renderer;
  9280. if ( texture.isCubeTexture ) {
  9281. if ( this._cubemapShader == null ) {
  9282. this._cubemapShader = _getCubemapShader();
  9283. }
  9284. } else {
  9285. if ( this._equirectShader == null ) {
  9286. this._equirectShader = _getEquirectShader();
  9287. }
  9288. }
  9289. const material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  9290. const mesh = new Mesh( _lodPlanes[ 0 ], material );
  9291. const uniforms = material.uniforms;
  9292. uniforms[ 'envMap' ].value = texture;
  9293. if ( ! texture.isCubeTexture ) {
  9294. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  9295. }
  9296. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  9297. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  9298. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  9299. renderer.setRenderTarget( cubeUVRenderTarget );
  9300. renderer.render( mesh, _flatCamera );
  9301. }
  9302. _applyPMREM( cubeUVRenderTarget ) {
  9303. const renderer = this._renderer;
  9304. const autoClear = renderer.autoClear;
  9305. renderer.autoClear = false;
  9306. for ( let i = 1; i < TOTAL_LODS; i ++ ) {
  9307. const sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  9308. const poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  9309. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  9310. }
  9311. renderer.autoClear = autoClear;
  9312. }
  9313. /**
  9314. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  9315. * vertically and horizontally, but this breaks down on a cube. Here we apply
  9316. * the blur latitudinally (around the poles), and then longitudinally (towards
  9317. * the poles) to approximate the orthogonally-separable blur. It is least
  9318. * accurate at the poles, but still does a decent job.
  9319. */
  9320. _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  9321. const pingPongRenderTarget = this._pingPongRenderTarget;
  9322. this._halfBlur(
  9323. cubeUVRenderTarget,
  9324. pingPongRenderTarget,
  9325. lodIn,
  9326. lodOut,
  9327. sigma,
  9328. 'latitudinal',
  9329. poleAxis );
  9330. this._halfBlur(
  9331. pingPongRenderTarget,
  9332. cubeUVRenderTarget,
  9333. lodOut,
  9334. lodOut,
  9335. sigma,
  9336. 'longitudinal',
  9337. poleAxis );
  9338. }
  9339. _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  9340. const renderer = this._renderer;
  9341. const blurMaterial = this._blurMaterial;
  9342. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  9343. console.error(
  9344. 'blur direction must be either latitudinal or longitudinal!' );
  9345. }
  9346. // Number of standard deviations at which to cut off the discrete approximation.
  9347. const STANDARD_DEVIATIONS = 3;
  9348. const blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  9349. const blurUniforms = blurMaterial.uniforms;
  9350. const pixels = _sizeLods[ lodIn ] - 1;
  9351. const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  9352. const sigmaPixels = sigmaRadians / radiansPerPixel;
  9353. const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  9354. if ( samples > MAX_SAMPLES ) {
  9355. console.warn( `sigmaRadians, ${
  9356. sigmaRadians}, is too large and will clip, as it requested ${
  9357. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  9358. }
  9359. const weights = [];
  9360. let sum = 0;
  9361. for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
  9362. const x = i / sigmaPixels;
  9363. const weight = Math.exp( - x * x / 2 );
  9364. weights.push( weight );
  9365. if ( i == 0 ) {
  9366. sum += weight;
  9367. } else if ( i < samples ) {
  9368. sum += 2 * weight;
  9369. }
  9370. }
  9371. for ( let i = 0; i < weights.length; i ++ ) {
  9372. weights[ i ] = weights[ i ] / sum;
  9373. }
  9374. blurUniforms[ 'envMap' ].value = targetIn.texture;
  9375. blurUniforms[ 'samples' ].value = samples;
  9376. blurUniforms[ 'weights' ].value = weights;
  9377. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  9378. if ( poleAxis ) {
  9379. blurUniforms[ 'poleAxis' ].value = poleAxis;
  9380. }
  9381. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  9382. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  9383. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  9384. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  9385. const outputSize = _sizeLods[ lodOut ];
  9386. const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  9387. const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  9388. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  9389. renderer.setRenderTarget( targetOut );
  9390. renderer.render( blurMesh, _flatCamera );
  9391. }
  9392. }
  9393. function _isLDR( texture ) {
  9394. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  9395. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  9396. }
  9397. function _createPlanes() {
  9398. const _lodPlanes = [];
  9399. const _sizeLods = [];
  9400. const _sigmas = [];
  9401. let lod = LOD_MAX;
  9402. for ( let i = 0; i < TOTAL_LODS; i ++ ) {
  9403. const sizeLod = Math.pow( 2, lod );
  9404. _sizeLods.push( sizeLod );
  9405. let sigma = 1.0 / sizeLod;
  9406. if ( i > LOD_MAX - LOD_MIN ) {
  9407. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  9408. } else if ( i == 0 ) {
  9409. sigma = 0;
  9410. }
  9411. _sigmas.push( sigma );
  9412. const texelSize = 1.0 / ( sizeLod - 1 );
  9413. const min = - texelSize / 2;
  9414. const max = 1 + texelSize / 2;
  9415. const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  9416. const cubeFaces = 6;
  9417. const vertices = 6;
  9418. const positionSize = 3;
  9419. const uvSize = 2;
  9420. const faceIndexSize = 1;
  9421. const position = new Float32Array( positionSize * vertices * cubeFaces );
  9422. const uv = new Float32Array( uvSize * vertices * cubeFaces );
  9423. const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  9424. for ( let face = 0; face < cubeFaces; face ++ ) {
  9425. const x = ( face % 3 ) * 2 / 3 - 1;
  9426. const y = face > 2 ? 0 : - 1;
  9427. const coordinates = [
  9428. x, y, 0,
  9429. x + 2 / 3, y, 0,
  9430. x + 2 / 3, y + 1, 0,
  9431. x, y, 0,
  9432. x + 2 / 3, y + 1, 0,
  9433. x, y + 1, 0
  9434. ];
  9435. position.set( coordinates, positionSize * vertices * face );
  9436. uv.set( uv1, uvSize * vertices * face );
  9437. const fill = [ face, face, face, face, face, face ];
  9438. faceIndex.set( fill, faceIndexSize * vertices * face );
  9439. }
  9440. const planes = new BufferGeometry();
  9441. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  9442. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  9443. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  9444. _lodPlanes.push( planes );
  9445. if ( lod > LOD_MIN ) {
  9446. lod --;
  9447. }
  9448. }
  9449. return { _lodPlanes, _sizeLods, _sigmas };
  9450. }
  9451. function _createRenderTarget( params ) {
  9452. const cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  9453. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  9454. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  9455. cubeUVRenderTarget.scissorTest = true;
  9456. return cubeUVRenderTarget;
  9457. }
  9458. function _setViewport( target, x, y, width, height ) {
  9459. target.viewport.set( x, y, width, height );
  9460. target.scissor.set( x, y, width, height );
  9461. }
  9462. function _getBlurShader( maxSamples ) {
  9463. const weights = new Float32Array( maxSamples );
  9464. const poleAxis = new Vector3( 0, 1, 0 );
  9465. const shaderMaterial = new RawShaderMaterial( {
  9466. name: 'SphericalGaussianBlur',
  9467. defines: { 'n': maxSamples },
  9468. uniforms: {
  9469. 'envMap': { value: null },
  9470. 'samples': { value: 1 },
  9471. 'weights': { value: weights },
  9472. 'latitudinal': { value: false },
  9473. 'dTheta': { value: 0 },
  9474. 'mipInt': { value: 0 },
  9475. 'poleAxis': { value: poleAxis },
  9476. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  9477. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  9478. },
  9479. vertexShader: _getCommonVertexShader(),
  9480. fragmentShader: /* glsl */`
  9481. precision mediump float;
  9482. precision mediump int;
  9483. varying vec3 vOutputDirection;
  9484. uniform sampler2D envMap;
  9485. uniform int samples;
  9486. uniform float weights[ n ];
  9487. uniform bool latitudinal;
  9488. uniform float dTheta;
  9489. uniform float mipInt;
  9490. uniform vec3 poleAxis;
  9491. ${ _getEncodings() }
  9492. #define ENVMAP_TYPE_CUBE_UV
  9493. #include <cube_uv_reflection_fragment>
  9494. vec3 getSample( float theta, vec3 axis ) {
  9495. float cosTheta = cos( theta );
  9496. // Rodrigues' axis-angle rotation
  9497. vec3 sampleDirection = vOutputDirection * cosTheta
  9498. + cross( axis, vOutputDirection ) * sin( theta )
  9499. + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
  9500. return bilinearCubeUV( envMap, sampleDirection, mipInt );
  9501. }
  9502. void main() {
  9503. vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
  9504. if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
  9505. axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
  9506. }
  9507. axis = normalize( axis );
  9508. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  9509. gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
  9510. for ( int i = 1; i < n; i++ ) {
  9511. if ( i >= samples ) {
  9512. break;
  9513. }
  9514. float theta = dTheta * float( i );
  9515. gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
  9516. gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
  9517. }
  9518. gl_FragColor = linearToOutputTexel( gl_FragColor );
  9519. }
  9520. `,
  9521. blending: NoBlending,
  9522. depthTest: false,
  9523. depthWrite: false
  9524. } );
  9525. return shaderMaterial;
  9526. }
  9527. function _getEquirectShader() {
  9528. const texelSize = new Vector2( 1, 1 );
  9529. const shaderMaterial = new RawShaderMaterial( {
  9530. name: 'EquirectangularToCubeUV',
  9531. uniforms: {
  9532. 'envMap': { value: null },
  9533. 'texelSize': { value: texelSize },
  9534. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  9535. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  9536. },
  9537. vertexShader: _getCommonVertexShader(),
  9538. fragmentShader: /* glsl */`
  9539. precision mediump float;
  9540. precision mediump int;
  9541. varying vec3 vOutputDirection;
  9542. uniform sampler2D envMap;
  9543. uniform vec2 texelSize;
  9544. ${ _getEncodings() }
  9545. #include <common>
  9546. void main() {
  9547. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  9548. vec3 outputDirection = normalize( vOutputDirection );
  9549. vec2 uv = equirectUv( outputDirection );
  9550. vec2 f = fract( uv / texelSize - 0.5 );
  9551. uv -= f * texelSize;
  9552. vec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  9553. uv.x += texelSize.x;
  9554. vec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  9555. uv.y += texelSize.y;
  9556. vec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  9557. uv.x -= texelSize.x;
  9558. vec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  9559. vec3 tm = mix( tl, tr, f.x );
  9560. vec3 bm = mix( bl, br, f.x );
  9561. gl_FragColor.rgb = mix( tm, bm, f.y );
  9562. gl_FragColor = linearToOutputTexel( gl_FragColor );
  9563. }
  9564. `,
  9565. blending: NoBlending,
  9566. depthTest: false,
  9567. depthWrite: false
  9568. } );
  9569. return shaderMaterial;
  9570. }
  9571. function _getCubemapShader() {
  9572. const shaderMaterial = new RawShaderMaterial( {
  9573. name: 'CubemapToCubeUV',
  9574. uniforms: {
  9575. 'envMap': { value: null },
  9576. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  9577. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  9578. },
  9579. vertexShader: _getCommonVertexShader(),
  9580. fragmentShader: /* glsl */`
  9581. precision mediump float;
  9582. precision mediump int;
  9583. varying vec3 vOutputDirection;
  9584. uniform samplerCube envMap;
  9585. ${ _getEncodings() }
  9586. void main() {
  9587. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  9588. gl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;
  9589. gl_FragColor = linearToOutputTexel( gl_FragColor );
  9590. }
  9591. `,
  9592. blending: NoBlending,
  9593. depthTest: false,
  9594. depthWrite: false
  9595. } );
  9596. return shaderMaterial;
  9597. }
  9598. function _getCommonVertexShader() {
  9599. return /* glsl */`
  9600. precision mediump float;
  9601. precision mediump int;
  9602. attribute vec3 position;
  9603. attribute vec2 uv;
  9604. attribute float faceIndex;
  9605. varying vec3 vOutputDirection;
  9606. // RH coordinate system; PMREM face-indexing convention
  9607. vec3 getDirection( vec2 uv, float face ) {
  9608. uv = 2.0 * uv - 1.0;
  9609. vec3 direction = vec3( uv, 1.0 );
  9610. if ( face == 0.0 ) {
  9611. direction = direction.zyx; // ( 1, v, u ) pos x
  9612. } else if ( face == 1.0 ) {
  9613. direction = direction.xzy;
  9614. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  9615. } else if ( face == 2.0 ) {
  9616. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  9617. } else if ( face == 3.0 ) {
  9618. direction = direction.zyx;
  9619. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  9620. } else if ( face == 4.0 ) {
  9621. direction = direction.xzy;
  9622. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  9623. } else if ( face == 5.0 ) {
  9624. direction.z *= -1.0; // ( u, v, -1 ) neg z
  9625. }
  9626. return direction;
  9627. }
  9628. void main() {
  9629. vOutputDirection = getDirection( uv, faceIndex );
  9630. gl_Position = vec4( position, 1.0 );
  9631. }
  9632. `;
  9633. }
  9634. function _getEncodings() {
  9635. return /* glsl */`
  9636. uniform int inputEncoding;
  9637. uniform int outputEncoding;
  9638. #include <encodings_pars_fragment>
  9639. vec4 inputTexelToLinear( vec4 value ) {
  9640. if ( inputEncoding == 0 ) {
  9641. return value;
  9642. } else if ( inputEncoding == 1 ) {
  9643. return sRGBToLinear( value );
  9644. } else if ( inputEncoding == 2 ) {
  9645. return RGBEToLinear( value );
  9646. } else if ( inputEncoding == 3 ) {
  9647. return RGBMToLinear( value, 7.0 );
  9648. } else if ( inputEncoding == 4 ) {
  9649. return RGBMToLinear( value, 16.0 );
  9650. } else if ( inputEncoding == 5 ) {
  9651. return RGBDToLinear( value, 256.0 );
  9652. } else {
  9653. return GammaToLinear( value, 2.2 );
  9654. }
  9655. }
  9656. vec4 linearToOutputTexel( vec4 value ) {
  9657. if ( outputEncoding == 0 ) {
  9658. return value;
  9659. } else if ( outputEncoding == 1 ) {
  9660. return LinearTosRGB( value );
  9661. } else if ( outputEncoding == 2 ) {
  9662. return LinearToRGBE( value );
  9663. } else if ( outputEncoding == 3 ) {
  9664. return LinearToRGBM( value, 7.0 );
  9665. } else if ( outputEncoding == 4 ) {
  9666. return LinearToRGBM( value, 16.0 );
  9667. } else if ( outputEncoding == 5 ) {
  9668. return LinearToRGBD( value, 256.0 );
  9669. } else {
  9670. return LinearToGamma( value, 2.2 );
  9671. }
  9672. }
  9673. vec4 envMapTexelToLinear( vec4 color ) {
  9674. return inputTexelToLinear( color );
  9675. }
  9676. `;
  9677. }
  9678. function WebGLCubeUVMaps( renderer ) {
  9679. let cubeUVmaps = new WeakMap();
  9680. let pmremGenerator = null;
  9681. function get( texture ) {
  9682. if ( texture && texture.isTexture && texture.isRenderTargetTexture === false ) {
  9683. const mapping = texture.mapping;
  9684. const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping );
  9685. const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
  9686. if ( isEquirectMap || isCubeMap ) {
  9687. // equirect/cube map to cubeUV conversion
  9688. if ( cubeUVmaps.has( texture ) ) {
  9689. return cubeUVmaps.get( texture ).texture;
  9690. } else {
  9691. const image = texture.image;
  9692. if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
  9693. const currentRenderTarget = renderer.getRenderTarget();
  9694. if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
  9695. const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
  9696. cubeUVmaps.set( texture, renderTarget );
  9697. renderer.setRenderTarget( currentRenderTarget );
  9698. texture.addEventListener( 'dispose', onTextureDispose );
  9699. return renderTarget.texture;
  9700. } else {
  9701. // image not yet ready. try the conversion next frame
  9702. return null;
  9703. }
  9704. }
  9705. }
  9706. }
  9707. return texture;
  9708. }
  9709. function isCubeTextureComplete( image ) {
  9710. let count = 0;
  9711. const length = 6;
  9712. for ( let i = 0; i < length; i ++ ) {
  9713. if ( image[ i ] !== undefined ) count ++;
  9714. }
  9715. return count === length;
  9716. }
  9717. function onTextureDispose( event ) {
  9718. const texture = event.target;
  9719. texture.removeEventListener( 'dispose', onTextureDispose );
  9720. const cubemapUV = cubeUVmaps.get( texture );
  9721. if ( cubemapUV !== undefined ) {
  9722. cubeUVmaps.delete( texture );
  9723. cubemapUV.dispose();
  9724. }
  9725. }
  9726. function dispose() {
  9727. cubeUVmaps = new WeakMap();
  9728. if ( pmremGenerator !== null ) {
  9729. pmremGenerator.dispose();
  9730. pmremGenerator = null;
  9731. }
  9732. }
  9733. return {
  9734. get: get,
  9735. dispose: dispose
  9736. };
  9737. }
  9738. function WebGLExtensions( gl ) {
  9739. const extensions = {};
  9740. function getExtension( name ) {
  9741. if ( extensions[ name ] !== undefined ) {
  9742. return extensions[ name ];
  9743. }
  9744. let extension;
  9745. switch ( name ) {
  9746. case 'WEBGL_depth_texture':
  9747. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9748. break;
  9749. case 'EXT_texture_filter_anisotropic':
  9750. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9751. break;
  9752. case 'WEBGL_compressed_texture_s3tc':
  9753. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9754. break;
  9755. case 'WEBGL_compressed_texture_pvrtc':
  9756. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9757. break;
  9758. default:
  9759. extension = gl.getExtension( name );
  9760. }
  9761. extensions[ name ] = extension;
  9762. return extension;
  9763. }
  9764. return {
  9765. has: function ( name ) {
  9766. return getExtension( name ) !== null;
  9767. },
  9768. init: function ( capabilities ) {
  9769. if ( capabilities.isWebGL2 ) {
  9770. getExtension( 'EXT_color_buffer_float' );
  9771. } else {
  9772. getExtension( 'WEBGL_depth_texture' );
  9773. getExtension( 'OES_texture_float' );
  9774. getExtension( 'OES_texture_half_float' );
  9775. getExtension( 'OES_texture_half_float_linear' );
  9776. getExtension( 'OES_standard_derivatives' );
  9777. getExtension( 'OES_element_index_uint' );
  9778. getExtension( 'OES_vertex_array_object' );
  9779. getExtension( 'ANGLE_instanced_arrays' );
  9780. }
  9781. getExtension( 'OES_texture_float_linear' );
  9782. getExtension( 'EXT_color_buffer_half_float' );
  9783. },
  9784. get: function ( name ) {
  9785. const extension = getExtension( name );
  9786. if ( extension === null ) {
  9787. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9788. }
  9789. return extension;
  9790. }
  9791. };
  9792. }
  9793. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  9794. const geometries = {};
  9795. const wireframeAttributes = new WeakMap();
  9796. function onGeometryDispose( event ) {
  9797. const geometry = event.target;
  9798. if ( geometry.index !== null ) {
  9799. attributes.remove( geometry.index );
  9800. }
  9801. for ( const name in geometry.attributes ) {
  9802. attributes.remove( geometry.attributes[ name ] );
  9803. }
  9804. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9805. delete geometries[ geometry.id ];
  9806. const attribute = wireframeAttributes.get( geometry );
  9807. if ( attribute ) {
  9808. attributes.remove( attribute );
  9809. wireframeAttributes.delete( geometry );
  9810. }
  9811. bindingStates.releaseStatesOfGeometry( geometry );
  9812. if ( geometry.isInstancedBufferGeometry === true ) {
  9813. delete geometry._maxInstanceCount;
  9814. }
  9815. //
  9816. info.memory.geometries --;
  9817. }
  9818. function get( object, geometry ) {
  9819. if ( geometries[ geometry.id ] === true ) return geometry;
  9820. geometry.addEventListener( 'dispose', onGeometryDispose );
  9821. geometries[ geometry.id ] = true;
  9822. info.memory.geometries ++;
  9823. return geometry;
  9824. }
  9825. function update( geometry ) {
  9826. const geometryAttributes = geometry.attributes;
  9827. // Updating index buffer in VAO now. See WebGLBindingStates.
  9828. for ( const name in geometryAttributes ) {
  9829. attributes.update( geometryAttributes[ name ], 34962 );
  9830. }
  9831. // morph targets
  9832. const morphAttributes = geometry.morphAttributes;
  9833. for ( const name in morphAttributes ) {
  9834. const array = morphAttributes[ name ];
  9835. for ( let i = 0, l = array.length; i < l; i ++ ) {
  9836. attributes.update( array[ i ], 34962 );
  9837. }
  9838. }
  9839. }
  9840. function updateWireframeAttribute( geometry ) {
  9841. const indices = [];
  9842. const geometryIndex = geometry.index;
  9843. const geometryPosition = geometry.attributes.position;
  9844. let version = 0;
  9845. if ( geometryIndex !== null ) {
  9846. const array = geometryIndex.array;
  9847. version = geometryIndex.version;
  9848. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  9849. const a = array[ i + 0 ];
  9850. const b = array[ i + 1 ];
  9851. const c = array[ i + 2 ];
  9852. indices.push( a, b, b, c, c, a );
  9853. }
  9854. } else {
  9855. const array = geometryPosition.array;
  9856. version = geometryPosition.version;
  9857. for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9858. const a = i + 0;
  9859. const b = i + 1;
  9860. const c = i + 2;
  9861. indices.push( a, b, b, c, c, a );
  9862. }
  9863. }
  9864. const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9865. attribute.version = version;
  9866. // Updating index buffer in VAO now. See WebGLBindingStates
  9867. //
  9868. const previousAttribute = wireframeAttributes.get( geometry );
  9869. if ( previousAttribute ) attributes.remove( previousAttribute );
  9870. //
  9871. wireframeAttributes.set( geometry, attribute );
  9872. }
  9873. function getWireframeAttribute( geometry ) {
  9874. const currentAttribute = wireframeAttributes.get( geometry );
  9875. if ( currentAttribute ) {
  9876. const geometryIndex = geometry.index;
  9877. if ( geometryIndex !== null ) {
  9878. // if the attribute is obsolete, create a new one
  9879. if ( currentAttribute.version < geometryIndex.version ) {
  9880. updateWireframeAttribute( geometry );
  9881. }
  9882. }
  9883. } else {
  9884. updateWireframeAttribute( geometry );
  9885. }
  9886. return wireframeAttributes.get( geometry );
  9887. }
  9888. return {
  9889. get: get,
  9890. update: update,
  9891. getWireframeAttribute: getWireframeAttribute
  9892. };
  9893. }
  9894. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9895. const isWebGL2 = capabilities.isWebGL2;
  9896. let mode;
  9897. function setMode( value ) {
  9898. mode = value;
  9899. }
  9900. let type, bytesPerElement;
  9901. function setIndex( value ) {
  9902. type = value.type;
  9903. bytesPerElement = value.bytesPerElement;
  9904. }
  9905. function render( start, count ) {
  9906. gl.drawElements( mode, count, type, start * bytesPerElement );
  9907. info.update( count, mode, 1 );
  9908. }
  9909. function renderInstances( start, count, primcount ) {
  9910. if ( primcount === 0 ) return;
  9911. let extension, methodName;
  9912. if ( isWebGL2 ) {
  9913. extension = gl;
  9914. methodName = 'drawElementsInstanced';
  9915. } else {
  9916. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9917. methodName = 'drawElementsInstancedANGLE';
  9918. if ( extension === null ) {
  9919. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9920. return;
  9921. }
  9922. }
  9923. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9924. info.update( count, mode, primcount );
  9925. }
  9926. //
  9927. this.setMode = setMode;
  9928. this.setIndex = setIndex;
  9929. this.render = render;
  9930. this.renderInstances = renderInstances;
  9931. }
  9932. function WebGLInfo( gl ) {
  9933. const memory = {
  9934. geometries: 0,
  9935. textures: 0
  9936. };
  9937. const render = {
  9938. frame: 0,
  9939. calls: 0,
  9940. triangles: 0,
  9941. points: 0,
  9942. lines: 0
  9943. };
  9944. function update( count, mode, instanceCount ) {
  9945. render.calls ++;
  9946. switch ( mode ) {
  9947. case 4:
  9948. render.triangles += instanceCount * ( count / 3 );
  9949. break;
  9950. case 1:
  9951. render.lines += instanceCount * ( count / 2 );
  9952. break;
  9953. case 3:
  9954. render.lines += instanceCount * ( count - 1 );
  9955. break;
  9956. case 2:
  9957. render.lines += instanceCount * count;
  9958. break;
  9959. case 0:
  9960. render.points += instanceCount * count;
  9961. break;
  9962. default:
  9963. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9964. break;
  9965. }
  9966. }
  9967. function reset() {
  9968. render.frame ++;
  9969. render.calls = 0;
  9970. render.triangles = 0;
  9971. render.points = 0;
  9972. render.lines = 0;
  9973. }
  9974. return {
  9975. memory: memory,
  9976. render: render,
  9977. programs: null,
  9978. autoReset: true,
  9979. reset: reset,
  9980. update: update
  9981. };
  9982. }
  9983. class DataTexture2DArray extends Texture {
  9984. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  9985. super( null );
  9986. this.image = { data, width, height, depth };
  9987. this.magFilter = NearestFilter;
  9988. this.minFilter = NearestFilter;
  9989. this.wrapR = ClampToEdgeWrapping;
  9990. this.generateMipmaps = false;
  9991. this.flipY = false;
  9992. this.unpackAlignment = 1;
  9993. this.needsUpdate = true;
  9994. }
  9995. }
  9996. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9997. function numericalSort( a, b ) {
  9998. return a[ 0 ] - b[ 0 ];
  9999. }
  10000. function absNumericalSort( a, b ) {
  10001. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  10002. }
  10003. function denormalize( morph, attribute ) {
  10004. let denominator = 1;
  10005. const array = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
  10006. if ( array instanceof Int8Array ) denominator = 127;
  10007. else if ( array instanceof Int16Array ) denominator = 32767;
  10008. else if ( array instanceof Int32Array ) denominator = 2147483647;
  10009. else console.error( 'THREE.WebGLMorphtargets: Unsupported morph attribute data type: ', array );
  10010. morph.divideScalar( denominator );
  10011. }
  10012. function WebGLMorphtargets( gl, capabilities, textures ) {
  10013. const influencesList = {};
  10014. const morphInfluences = new Float32Array( 8 );
  10015. const morphTextures = new WeakMap();
  10016. const morph = new Vector3();
  10017. const workInfluences = [];
  10018. for ( let i = 0; i < 8; i ++ ) {
  10019. workInfluences[ i ] = [ i, 0 ];
  10020. }
  10021. function update( object, geometry, material, program ) {
  10022. const objectInfluences = object.morphTargetInfluences;
  10023. if ( capabilities.isWebGL2 === true ) {
  10024. // instead of using attributes, the WebGL 2 code path encodes morph targets
  10025. // into an array of data textures. Each layer represents a single morph target.
  10026. const numberOfMorphTargets = geometry.morphAttributes.position.length;
  10027. let entry = morphTextures.get( geometry );
  10028. if ( entry === undefined || entry.count !== numberOfMorphTargets ) {
  10029. if ( entry !== undefined ) entry.texture.dispose();
  10030. const hasMorphNormals = geometry.morphAttributes.normal !== undefined;
  10031. const morphTargets = geometry.morphAttributes.position;
  10032. const morphNormals = geometry.morphAttributes.normal || [];
  10033. const numberOfVertices = geometry.attributes.position.count;
  10034. const numberOfVertexData = ( hasMorphNormals === true ) ? 2 : 1; // (v,n) vs. (v)
  10035. let width = numberOfVertices * numberOfVertexData;
  10036. let height = 1;
  10037. if ( width > capabilities.maxTextureSize ) {
  10038. height = Math.ceil( width / capabilities.maxTextureSize );
  10039. width = capabilities.maxTextureSize;
  10040. }
  10041. const buffer = new Float32Array( width * height * 4 * numberOfMorphTargets );
  10042. const texture = new DataTexture2DArray( buffer, width, height, numberOfMorphTargets );
  10043. texture.format = RGBAFormat; // using RGBA since RGB might be emulated (and is thus slower)
  10044. texture.type = FloatType;
  10045. // fill buffer
  10046. const vertexDataStride = numberOfVertexData * 4;
  10047. for ( let i = 0; i < numberOfMorphTargets; i ++ ) {
  10048. const morphTarget = morphTargets[ i ];
  10049. const morphNormal = morphNormals[ i ];
  10050. const offset = width * height * 4 * i;
  10051. for ( let j = 0; j < morphTarget.count; j ++ ) {
  10052. morph.fromBufferAttribute( morphTarget, j );
  10053. if ( morphTarget.normalized === true ) denormalize( morph, morphTarget );
  10054. const stride = j * vertexDataStride;
  10055. buffer[ offset + stride + 0 ] = morph.x;
  10056. buffer[ offset + stride + 1 ] = morph.y;
  10057. buffer[ offset + stride + 2 ] = morph.z;
  10058. if ( hasMorphNormals === true ) {
  10059. morph.fromBufferAttribute( morphNormal, j );
  10060. if ( morphNormal.normalized === true ) denormalize( morph, morphNormal );
  10061. buffer[ offset + stride + 3 ] = morph.x;
  10062. buffer[ offset + stride + 4 ] = morph.y;
  10063. buffer[ offset + stride + 5 ] = morph.z;
  10064. }
  10065. }
  10066. }
  10067. entry = {
  10068. count: numberOfMorphTargets,
  10069. texture: texture,
  10070. size: new Vector2( width, height )
  10071. };
  10072. morphTextures.set( geometry, entry );
  10073. }
  10074. //
  10075. let morphInfluencesSum = 0;
  10076. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  10077. morphInfluencesSum += objectInfluences[ i ];
  10078. }
  10079. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10080. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  10081. program.getUniforms().setValue( gl, 'morphTargetInfluences', objectInfluences );
  10082. program.getUniforms().setValue( gl, 'morphTargetsTexture', entry.texture, textures );
  10083. program.getUniforms().setValue( gl, 'morphTargetsTextureSize', entry.size );
  10084. } else {
  10085. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10086. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10087. const length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10088. let influences = influencesList[ geometry.id ];
  10089. if ( influences === undefined || influences.length !== length ) {
  10090. // initialise list
  10091. influences = [];
  10092. for ( let i = 0; i < length; i ++ ) {
  10093. influences[ i ] = [ i, 0 ];
  10094. }
  10095. influencesList[ geometry.id ] = influences;
  10096. }
  10097. // Collect influences
  10098. for ( let i = 0; i < length; i ++ ) {
  10099. const influence = influences[ i ];
  10100. influence[ 0 ] = i;
  10101. influence[ 1 ] = objectInfluences[ i ];
  10102. }
  10103. influences.sort( absNumericalSort );
  10104. for ( let i = 0; i < 8; i ++ ) {
  10105. if ( i < length && influences[ i ][ 1 ] ) {
  10106. workInfluences[ i ][ 0 ] = influences[ i ][ 0 ];
  10107. workInfluences[ i ][ 1 ] = influences[ i ][ 1 ];
  10108. } else {
  10109. workInfluences[ i ][ 0 ] = Number.MAX_SAFE_INTEGER;
  10110. workInfluences[ i ][ 1 ] = 0;
  10111. }
  10112. }
  10113. workInfluences.sort( numericalSort );
  10114. const morphTargets = geometry.morphAttributes.position;
  10115. const morphNormals = geometry.morphAttributes.normal;
  10116. let morphInfluencesSum = 0;
  10117. for ( let i = 0; i < 8; i ++ ) {
  10118. const influence = workInfluences[ i ];
  10119. const index = influence[ 0 ];
  10120. const value = influence[ 1 ];
  10121. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  10122. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== morphTargets[ index ] ) {
  10123. geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  10124. }
  10125. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== morphNormals[ index ] ) {
  10126. geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  10127. }
  10128. morphInfluences[ i ] = value;
  10129. morphInfluencesSum += value;
  10130. } else {
  10131. if ( morphTargets && geometry.hasAttribute( 'morphTarget' + i ) === true ) {
  10132. geometry.deleteAttribute( 'morphTarget' + i );
  10133. }
  10134. if ( morphNormals && geometry.hasAttribute( 'morphNormal' + i ) === true ) {
  10135. geometry.deleteAttribute( 'morphNormal' + i );
  10136. }
  10137. morphInfluences[ i ] = 0;
  10138. }
  10139. }
  10140. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10141. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10142. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10143. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10144. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  10145. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  10146. }
  10147. }
  10148. return {
  10149. update: update
  10150. };
  10151. }
  10152. function WebGLObjects( gl, geometries, attributes, info ) {
  10153. let updateMap = new WeakMap();
  10154. function update( object ) {
  10155. const frame = info.render.frame;
  10156. const geometry = object.geometry;
  10157. const buffergeometry = geometries.get( object, geometry );
  10158. // Update once per frame
  10159. if ( updateMap.get( buffergeometry ) !== frame ) {
  10160. geometries.update( buffergeometry );
  10161. updateMap.set( buffergeometry, frame );
  10162. }
  10163. if ( object.isInstancedMesh ) {
  10164. if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {
  10165. object.addEventListener( 'dispose', onInstancedMeshDispose );
  10166. }
  10167. attributes.update( object.instanceMatrix, 34962 );
  10168. if ( object.instanceColor !== null ) {
  10169. attributes.update( object.instanceColor, 34962 );
  10170. }
  10171. }
  10172. return buffergeometry;
  10173. }
  10174. function dispose() {
  10175. updateMap = new WeakMap();
  10176. }
  10177. function onInstancedMeshDispose( event ) {
  10178. const instancedMesh = event.target;
  10179. instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
  10180. attributes.remove( instancedMesh.instanceMatrix );
  10181. if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
  10182. }
  10183. return {
  10184. update: update,
  10185. dispose: dispose
  10186. };
  10187. }
  10188. class DataTexture3D extends Texture {
  10189. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  10190. // We're going to add .setXXX() methods for setting properties later.
  10191. // Users can still set in DataTexture3D directly.
  10192. //
  10193. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10194. // texture.anisotropy = 16;
  10195. //
  10196. // See #14839
  10197. super( null );
  10198. this.image = { data, width, height, depth };
  10199. this.magFilter = NearestFilter;
  10200. this.minFilter = NearestFilter;
  10201. this.wrapR = ClampToEdgeWrapping;
  10202. this.generateMipmaps = false;
  10203. this.flipY = false;
  10204. this.unpackAlignment = 1;
  10205. this.needsUpdate = true;
  10206. }
  10207. }
  10208. DataTexture3D.prototype.isDataTexture3D = true;
  10209. /**
  10210. * Uniforms of a program.
  10211. * Those form a tree structure with a special top-level container for the root,
  10212. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10213. *
  10214. *
  10215. * Properties of inner nodes including the top-level container:
  10216. *
  10217. * .seq - array of nested uniforms
  10218. * .map - nested uniforms by name
  10219. *
  10220. *
  10221. * Methods of all nodes except the top-level container:
  10222. *
  10223. * .setValue( gl, value, [textures] )
  10224. *
  10225. * uploads a uniform value(s)
  10226. * the 'textures' parameter is needed for sampler uniforms
  10227. *
  10228. *
  10229. * Static methods of the top-level container (textures factorizations):
  10230. *
  10231. * .upload( gl, seq, values, textures )
  10232. *
  10233. * sets uniforms in 'seq' to 'values[id].value'
  10234. *
  10235. * .seqWithValue( seq, values ) : filteredSeq
  10236. *
  10237. * filters 'seq' entries with corresponding entry in values
  10238. *
  10239. *
  10240. * Methods of the top-level container (textures factorizations):
  10241. *
  10242. * .setValue( gl, name, value, textures )
  10243. *
  10244. * sets uniform with name 'name' to 'value'
  10245. *
  10246. * .setOptional( gl, obj, prop )
  10247. *
  10248. * like .set for an optional property of the object
  10249. *
  10250. */
  10251. const emptyTexture = new Texture();
  10252. const emptyTexture2dArray = new DataTexture2DArray();
  10253. const emptyTexture3d = new DataTexture3D();
  10254. const emptyCubeTexture = new CubeTexture();
  10255. // --- Utilities ---
  10256. // Array Caches (provide typed arrays for temporary by size)
  10257. const arrayCacheF32 = [];
  10258. const arrayCacheI32 = [];
  10259. // Float32Array caches used for uploading Matrix uniforms
  10260. const mat4array = new Float32Array( 16 );
  10261. const mat3array = new Float32Array( 9 );
  10262. const mat2array = new Float32Array( 4 );
  10263. // Flattening for arrays of vectors and matrices
  10264. function flatten( array, nBlocks, blockSize ) {
  10265. const firstElem = array[ 0 ];
  10266. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10267. // unoptimized: ! isNaN( firstElem )
  10268. // see http://jacksondunstan.com/articles/983
  10269. const n = nBlocks * blockSize;
  10270. let r = arrayCacheF32[ n ];
  10271. if ( r === undefined ) {
  10272. r = new Float32Array( n );
  10273. arrayCacheF32[ n ] = r;
  10274. }
  10275. if ( nBlocks !== 0 ) {
  10276. firstElem.toArray( r, 0 );
  10277. for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10278. offset += blockSize;
  10279. array[ i ].toArray( r, offset );
  10280. }
  10281. }
  10282. return r;
  10283. }
  10284. function arraysEqual( a, b ) {
  10285. if ( a.length !== b.length ) return false;
  10286. for ( let i = 0, l = a.length; i < l; i ++ ) {
  10287. if ( a[ i ] !== b[ i ] ) return false;
  10288. }
  10289. return true;
  10290. }
  10291. function copyArray( a, b ) {
  10292. for ( let i = 0, l = b.length; i < l; i ++ ) {
  10293. a[ i ] = b[ i ];
  10294. }
  10295. }
  10296. // Texture unit allocation
  10297. function allocTexUnits( textures, n ) {
  10298. let r = arrayCacheI32[ n ];
  10299. if ( r === undefined ) {
  10300. r = new Int32Array( n );
  10301. arrayCacheI32[ n ] = r;
  10302. }
  10303. for ( let i = 0; i !== n; ++ i ) {
  10304. r[ i ] = textures.allocateTextureUnit();
  10305. }
  10306. return r;
  10307. }
  10308. // --- Setters ---
  10309. // Note: Defining these methods externally, because they come in a bunch
  10310. // and this way their names minify.
  10311. // Single scalar
  10312. function setValueV1f( gl, v ) {
  10313. const cache = this.cache;
  10314. if ( cache[ 0 ] === v ) return;
  10315. gl.uniform1f( this.addr, v );
  10316. cache[ 0 ] = v;
  10317. }
  10318. // Single float vector (from flat array or THREE.VectorN)
  10319. function setValueV2f( gl, v ) {
  10320. const cache = this.cache;
  10321. if ( v.x !== undefined ) {
  10322. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10323. gl.uniform2f( this.addr, v.x, v.y );
  10324. cache[ 0 ] = v.x;
  10325. cache[ 1 ] = v.y;
  10326. }
  10327. } else {
  10328. if ( arraysEqual( cache, v ) ) return;
  10329. gl.uniform2fv( this.addr, v );
  10330. copyArray( cache, v );
  10331. }
  10332. }
  10333. function setValueV3f( gl, v ) {
  10334. const cache = this.cache;
  10335. if ( v.x !== undefined ) {
  10336. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10337. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10338. cache[ 0 ] = v.x;
  10339. cache[ 1 ] = v.y;
  10340. cache[ 2 ] = v.z;
  10341. }
  10342. } else if ( v.r !== undefined ) {
  10343. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10344. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10345. cache[ 0 ] = v.r;
  10346. cache[ 1 ] = v.g;
  10347. cache[ 2 ] = v.b;
  10348. }
  10349. } else {
  10350. if ( arraysEqual( cache, v ) ) return;
  10351. gl.uniform3fv( this.addr, v );
  10352. copyArray( cache, v );
  10353. }
  10354. }
  10355. function setValueV4f( gl, v ) {
  10356. const cache = this.cache;
  10357. if ( v.x !== undefined ) {
  10358. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10359. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10360. cache[ 0 ] = v.x;
  10361. cache[ 1 ] = v.y;
  10362. cache[ 2 ] = v.z;
  10363. cache[ 3 ] = v.w;
  10364. }
  10365. } else {
  10366. if ( arraysEqual( cache, v ) ) return;
  10367. gl.uniform4fv( this.addr, v );
  10368. copyArray( cache, v );
  10369. }
  10370. }
  10371. // Single matrix (from flat array or THREE.MatrixN)
  10372. function setValueM2( gl, v ) {
  10373. const cache = this.cache;
  10374. const elements = v.elements;
  10375. if ( elements === undefined ) {
  10376. if ( arraysEqual( cache, v ) ) return;
  10377. gl.uniformMatrix2fv( this.addr, false, v );
  10378. copyArray( cache, v );
  10379. } else {
  10380. if ( arraysEqual( cache, elements ) ) return;
  10381. mat2array.set( elements );
  10382. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10383. copyArray( cache, elements );
  10384. }
  10385. }
  10386. function setValueM3( gl, v ) {
  10387. const cache = this.cache;
  10388. const elements = v.elements;
  10389. if ( elements === undefined ) {
  10390. if ( arraysEqual( cache, v ) ) return;
  10391. gl.uniformMatrix3fv( this.addr, false, v );
  10392. copyArray( cache, v );
  10393. } else {
  10394. if ( arraysEqual( cache, elements ) ) return;
  10395. mat3array.set( elements );
  10396. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10397. copyArray( cache, elements );
  10398. }
  10399. }
  10400. function setValueM4( gl, v ) {
  10401. const cache = this.cache;
  10402. const elements = v.elements;
  10403. if ( elements === undefined ) {
  10404. if ( arraysEqual( cache, v ) ) return;
  10405. gl.uniformMatrix4fv( this.addr, false, v );
  10406. copyArray( cache, v );
  10407. } else {
  10408. if ( arraysEqual( cache, elements ) ) return;
  10409. mat4array.set( elements );
  10410. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10411. copyArray( cache, elements );
  10412. }
  10413. }
  10414. // Single integer / boolean
  10415. function setValueV1i( gl, v ) {
  10416. const cache = this.cache;
  10417. if ( cache[ 0 ] === v ) return;
  10418. gl.uniform1i( this.addr, v );
  10419. cache[ 0 ] = v;
  10420. }
  10421. // Single integer / boolean vector (from flat array)
  10422. function setValueV2i( gl, v ) {
  10423. const cache = this.cache;
  10424. if ( arraysEqual( cache, v ) ) return;
  10425. gl.uniform2iv( this.addr, v );
  10426. copyArray( cache, v );
  10427. }
  10428. function setValueV3i( gl, v ) {
  10429. const cache = this.cache;
  10430. if ( arraysEqual( cache, v ) ) return;
  10431. gl.uniform3iv( this.addr, v );
  10432. copyArray( cache, v );
  10433. }
  10434. function setValueV4i( gl, v ) {
  10435. const cache = this.cache;
  10436. if ( arraysEqual( cache, v ) ) return;
  10437. gl.uniform4iv( this.addr, v );
  10438. copyArray( cache, v );
  10439. }
  10440. // Single unsigned integer
  10441. function setValueV1ui( gl, v ) {
  10442. const cache = this.cache;
  10443. if ( cache[ 0 ] === v ) return;
  10444. gl.uniform1ui( this.addr, v );
  10445. cache[ 0 ] = v;
  10446. }
  10447. // Single unsigned integer vector (from flat array)
  10448. function setValueV2ui( gl, v ) {
  10449. const cache = this.cache;
  10450. if ( arraysEqual( cache, v ) ) return;
  10451. gl.uniform2uiv( this.addr, v );
  10452. copyArray( cache, v );
  10453. }
  10454. function setValueV3ui( gl, v ) {
  10455. const cache = this.cache;
  10456. if ( arraysEqual( cache, v ) ) return;
  10457. gl.uniform3uiv( this.addr, v );
  10458. copyArray( cache, v );
  10459. }
  10460. function setValueV4ui( gl, v ) {
  10461. const cache = this.cache;
  10462. if ( arraysEqual( cache, v ) ) return;
  10463. gl.uniform4uiv( this.addr, v );
  10464. copyArray( cache, v );
  10465. }
  10466. // Single texture (2D / Cube)
  10467. function setValueT1( gl, v, textures ) {
  10468. const cache = this.cache;
  10469. const unit = textures.allocateTextureUnit();
  10470. if ( cache[ 0 ] !== unit ) {
  10471. gl.uniform1i( this.addr, unit );
  10472. cache[ 0 ] = unit;
  10473. }
  10474. textures.safeSetTexture2D( v || emptyTexture, unit );
  10475. }
  10476. function setValueT3D1( gl, v, textures ) {
  10477. const cache = this.cache;
  10478. const unit = textures.allocateTextureUnit();
  10479. if ( cache[ 0 ] !== unit ) {
  10480. gl.uniform1i( this.addr, unit );
  10481. cache[ 0 ] = unit;
  10482. }
  10483. textures.setTexture3D( v || emptyTexture3d, unit );
  10484. }
  10485. function setValueT6( gl, v, textures ) {
  10486. const cache = this.cache;
  10487. const unit = textures.allocateTextureUnit();
  10488. if ( cache[ 0 ] !== unit ) {
  10489. gl.uniform1i( this.addr, unit );
  10490. cache[ 0 ] = unit;
  10491. }
  10492. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10493. }
  10494. function setValueT2DArray1( gl, v, textures ) {
  10495. const cache = this.cache;
  10496. const unit = textures.allocateTextureUnit();
  10497. if ( cache[ 0 ] !== unit ) {
  10498. gl.uniform1i( this.addr, unit );
  10499. cache[ 0 ] = unit;
  10500. }
  10501. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10502. }
  10503. // Helper to pick the right setter for the singular case
  10504. function getSingularSetter( type ) {
  10505. switch ( type ) {
  10506. case 0x1406: return setValueV1f; // FLOAT
  10507. case 0x8b50: return setValueV2f; // _VEC2
  10508. case 0x8b51: return setValueV3f; // _VEC3
  10509. case 0x8b52: return setValueV4f; // _VEC4
  10510. case 0x8b5a: return setValueM2; // _MAT2
  10511. case 0x8b5b: return setValueM3; // _MAT3
  10512. case 0x8b5c: return setValueM4; // _MAT4
  10513. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10514. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10515. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10516. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10517. case 0x1405: return setValueV1ui; // UINT
  10518. case 0x8dc6: return setValueV2ui; // _VEC2
  10519. case 0x8dc7: return setValueV3ui; // _VEC3
  10520. case 0x8dc8: return setValueV4ui; // _VEC4
  10521. case 0x8b5e: // SAMPLER_2D
  10522. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10523. case 0x8dca: // INT_SAMPLER_2D
  10524. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10525. case 0x8b62: // SAMPLER_2D_SHADOW
  10526. return setValueT1;
  10527. case 0x8b5f: // SAMPLER_3D
  10528. case 0x8dcb: // INT_SAMPLER_3D
  10529. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  10530. return setValueT3D1;
  10531. case 0x8b60: // SAMPLER_CUBE
  10532. case 0x8dcc: // INT_SAMPLER_CUBE
  10533. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10534. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10535. return setValueT6;
  10536. case 0x8dc1: // SAMPLER_2D_ARRAY
  10537. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10538. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10539. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  10540. return setValueT2DArray1;
  10541. }
  10542. }
  10543. // Array of scalars
  10544. function setValueV1fArray( gl, v ) {
  10545. gl.uniform1fv( this.addr, v );
  10546. }
  10547. // Array of vectors (from flat array or array of THREE.VectorN)
  10548. function setValueV2fArray( gl, v ) {
  10549. const data = flatten( v, this.size, 2 );
  10550. gl.uniform2fv( this.addr, data );
  10551. }
  10552. function setValueV3fArray( gl, v ) {
  10553. const data = flatten( v, this.size, 3 );
  10554. gl.uniform3fv( this.addr, data );
  10555. }
  10556. function setValueV4fArray( gl, v ) {
  10557. const data = flatten( v, this.size, 4 );
  10558. gl.uniform4fv( this.addr, data );
  10559. }
  10560. // Array of matrices (from flat array or array of THREE.MatrixN)
  10561. function setValueM2Array( gl, v ) {
  10562. const data = flatten( v, this.size, 4 );
  10563. gl.uniformMatrix2fv( this.addr, false, data );
  10564. }
  10565. function setValueM3Array( gl, v ) {
  10566. const data = flatten( v, this.size, 9 );
  10567. gl.uniformMatrix3fv( this.addr, false, data );
  10568. }
  10569. function setValueM4Array( gl, v ) {
  10570. const data = flatten( v, this.size, 16 );
  10571. gl.uniformMatrix4fv( this.addr, false, data );
  10572. }
  10573. // Array of integer / boolean
  10574. function setValueV1iArray( gl, v ) {
  10575. gl.uniform1iv( this.addr, v );
  10576. }
  10577. // Array of integer / boolean vectors (from flat array)
  10578. function setValueV2iArray( gl, v ) {
  10579. gl.uniform2iv( this.addr, v );
  10580. }
  10581. function setValueV3iArray( gl, v ) {
  10582. gl.uniform3iv( this.addr, v );
  10583. }
  10584. function setValueV4iArray( gl, v ) {
  10585. gl.uniform4iv( this.addr, v );
  10586. }
  10587. // Array of unsigned integer
  10588. function setValueV1uiArray( gl, v ) {
  10589. gl.uniform1uiv( this.addr, v );
  10590. }
  10591. // Array of unsigned integer vectors (from flat array)
  10592. function setValueV2uiArray( gl, v ) {
  10593. gl.uniform2uiv( this.addr, v );
  10594. }
  10595. function setValueV3uiArray( gl, v ) {
  10596. gl.uniform3uiv( this.addr, v );
  10597. }
  10598. function setValueV4uiArray( gl, v ) {
  10599. gl.uniform4uiv( this.addr, v );
  10600. }
  10601. // Array of textures (2D / Cube)
  10602. function setValueT1Array( gl, v, textures ) {
  10603. const n = v.length;
  10604. const units = allocTexUnits( textures, n );
  10605. gl.uniform1iv( this.addr, units );
  10606. for ( let i = 0; i !== n; ++ i ) {
  10607. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10608. }
  10609. }
  10610. function setValueT6Array( gl, v, textures ) {
  10611. const n = v.length;
  10612. const units = allocTexUnits( textures, n );
  10613. gl.uniform1iv( this.addr, units );
  10614. for ( let i = 0; i !== n; ++ i ) {
  10615. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10616. }
  10617. }
  10618. // Helper to pick the right setter for a pure (bottom-level) array
  10619. function getPureArraySetter( type ) {
  10620. switch ( type ) {
  10621. case 0x1406: return setValueV1fArray; // FLOAT
  10622. case 0x8b50: return setValueV2fArray; // _VEC2
  10623. case 0x8b51: return setValueV3fArray; // _VEC3
  10624. case 0x8b52: return setValueV4fArray; // _VEC4
  10625. case 0x8b5a: return setValueM2Array; // _MAT2
  10626. case 0x8b5b: return setValueM3Array; // _MAT3
  10627. case 0x8b5c: return setValueM4Array; // _MAT4
  10628. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10629. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10630. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10631. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10632. case 0x1405: return setValueV1uiArray; // UINT
  10633. case 0x8dc6: return setValueV2uiArray; // _VEC2
  10634. case 0x8dc7: return setValueV3uiArray; // _VEC3
  10635. case 0x8dc8: return setValueV4uiArray; // _VEC4
  10636. case 0x8b5e: // SAMPLER_2D
  10637. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10638. case 0x8dca: // INT_SAMPLER_2D
  10639. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10640. case 0x8b62: // SAMPLER_2D_SHADOW
  10641. return setValueT1Array;
  10642. case 0x8b60: // SAMPLER_CUBE
  10643. case 0x8dcc: // INT_SAMPLER_CUBE
  10644. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10645. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10646. return setValueT6Array;
  10647. }
  10648. }
  10649. // --- Uniform Classes ---
  10650. function SingleUniform( id, activeInfo, addr ) {
  10651. this.id = id;
  10652. this.addr = addr;
  10653. this.cache = [];
  10654. this.setValue = getSingularSetter( activeInfo.type );
  10655. // this.path = activeInfo.name; // DEBUG
  10656. }
  10657. function PureArrayUniform( id, activeInfo, addr ) {
  10658. this.id = id;
  10659. this.addr = addr;
  10660. this.cache = [];
  10661. this.size = activeInfo.size;
  10662. this.setValue = getPureArraySetter( activeInfo.type );
  10663. // this.path = activeInfo.name; // DEBUG
  10664. }
  10665. PureArrayUniform.prototype.updateCache = function ( data ) {
  10666. const cache = this.cache;
  10667. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10668. this.cache = new Float32Array( data.length );
  10669. }
  10670. copyArray( cache, data );
  10671. };
  10672. function StructuredUniform( id ) {
  10673. this.id = id;
  10674. this.seq = [];
  10675. this.map = {};
  10676. }
  10677. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10678. const seq = this.seq;
  10679. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10680. const u = seq[ i ];
  10681. u.setValue( gl, value[ u.id ], textures );
  10682. }
  10683. };
  10684. // --- Top-level ---
  10685. // Parser - builds up the property tree from the path strings
  10686. const RePathPart = /(\w+)(\])?(\[|\.)?/g;
  10687. // extracts
  10688. // - the identifier (member name or array index)
  10689. // - followed by an optional right bracket (found when array index)
  10690. // - followed by an optional left bracket or dot (type of subscript)
  10691. //
  10692. // Note: These portions can be read in a non-overlapping fashion and
  10693. // allow straightforward parsing of the hierarchy that WebGL encodes
  10694. // in the uniform names.
  10695. function addUniform( container, uniformObject ) {
  10696. container.seq.push( uniformObject );
  10697. container.map[ uniformObject.id ] = uniformObject;
  10698. }
  10699. function parseUniform( activeInfo, addr, container ) {
  10700. const path = activeInfo.name,
  10701. pathLength = path.length;
  10702. // reset RegExp object, because of the early exit of a previous run
  10703. RePathPart.lastIndex = 0;
  10704. while ( true ) {
  10705. const match = RePathPart.exec( path ),
  10706. matchEnd = RePathPart.lastIndex;
  10707. let id = match[ 1 ];
  10708. const idIsIndex = match[ 2 ] === ']',
  10709. subscript = match[ 3 ];
  10710. if ( idIsIndex ) id = id | 0; // convert to integer
  10711. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10712. // bare name or "pure" bottom-level array "[0]" suffix
  10713. addUniform( container, subscript === undefined ?
  10714. new SingleUniform( id, activeInfo, addr ) :
  10715. new PureArrayUniform( id, activeInfo, addr ) );
  10716. break;
  10717. } else {
  10718. // step into inner node / create it in case it doesn't exist
  10719. const map = container.map;
  10720. let next = map[ id ];
  10721. if ( next === undefined ) {
  10722. next = new StructuredUniform( id );
  10723. addUniform( container, next );
  10724. }
  10725. container = next;
  10726. }
  10727. }
  10728. }
  10729. // Root Container
  10730. function WebGLUniforms( gl, program ) {
  10731. this.seq = [];
  10732. this.map = {};
  10733. const n = gl.getProgramParameter( program, 35718 );
  10734. for ( let i = 0; i < n; ++ i ) {
  10735. const info = gl.getActiveUniform( program, i ),
  10736. addr = gl.getUniformLocation( program, info.name );
  10737. parseUniform( info, addr, this );
  10738. }
  10739. }
  10740. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10741. const u = this.map[ name ];
  10742. if ( u !== undefined ) u.setValue( gl, value, textures );
  10743. };
  10744. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10745. const v = object[ name ];
  10746. if ( v !== undefined ) this.setValue( gl, name, v );
  10747. };
  10748. // Static interface
  10749. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10750. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10751. const u = seq[ i ],
  10752. v = values[ u.id ];
  10753. if ( v.needsUpdate !== false ) {
  10754. // note: always updating when .needsUpdate is undefined
  10755. u.setValue( gl, v.value, textures );
  10756. }
  10757. }
  10758. };
  10759. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10760. const r = [];
  10761. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10762. const u = seq[ i ];
  10763. if ( u.id in values ) r.push( u );
  10764. }
  10765. return r;
  10766. };
  10767. function WebGLShader( gl, type, string ) {
  10768. const shader = gl.createShader( type );
  10769. gl.shaderSource( shader, string );
  10770. gl.compileShader( shader );
  10771. return shader;
  10772. }
  10773. let programIdCount = 0;
  10774. function addLineNumbers( string ) {
  10775. const lines = string.split( '\n' );
  10776. for ( let i = 0; i < lines.length; i ++ ) {
  10777. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10778. }
  10779. return lines.join( '\n' );
  10780. }
  10781. function getEncodingComponents( encoding ) {
  10782. switch ( encoding ) {
  10783. case LinearEncoding:
  10784. return [ 'Linear', '( value )' ];
  10785. case sRGBEncoding:
  10786. return [ 'sRGB', '( value )' ];
  10787. case RGBEEncoding:
  10788. return [ 'RGBE', '( value )' ];
  10789. case RGBM7Encoding:
  10790. return [ 'RGBM', '( value, 7.0 )' ];
  10791. case RGBM16Encoding:
  10792. return [ 'RGBM', '( value, 16.0 )' ];
  10793. case RGBDEncoding:
  10794. return [ 'RGBD', '( value, 256.0 )' ];
  10795. case GammaEncoding:
  10796. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10797. case LogLuvEncoding:
  10798. return [ 'LogLuv', '( value )' ];
  10799. default:
  10800. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  10801. return [ 'Linear', '( value )' ];
  10802. }
  10803. }
  10804. function getShaderErrors( gl, shader, type ) {
  10805. const status = gl.getShaderParameter( shader, 35713 );
  10806. const errors = gl.getShaderInfoLog( shader ).trim();
  10807. if ( status && errors === '' ) return '';
  10808. // --enable-privileged-webgl-extension
  10809. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10810. return type.toUpperCase() + '\n\n' + errors + '\n\n' + addLineNumbers( gl.getShaderSource( shader ) );
  10811. }
  10812. function getTexelDecodingFunction( functionName, encoding ) {
  10813. const components = getEncodingComponents( encoding );
  10814. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10815. }
  10816. function getTexelEncodingFunction( functionName, encoding ) {
  10817. const components = getEncodingComponents( encoding );
  10818. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10819. }
  10820. function getToneMappingFunction( functionName, toneMapping ) {
  10821. let toneMappingName;
  10822. switch ( toneMapping ) {
  10823. case LinearToneMapping:
  10824. toneMappingName = 'Linear';
  10825. break;
  10826. case ReinhardToneMapping:
  10827. toneMappingName = 'Reinhard';
  10828. break;
  10829. case CineonToneMapping:
  10830. toneMappingName = 'OptimizedCineon';
  10831. break;
  10832. case ACESFilmicToneMapping:
  10833. toneMappingName = 'ACESFilmic';
  10834. break;
  10835. case CustomToneMapping:
  10836. toneMappingName = 'Custom';
  10837. break;
  10838. default:
  10839. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  10840. toneMappingName = 'Linear';
  10841. }
  10842. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10843. }
  10844. function generateExtensions( parameters ) {
  10845. const chunks = [
  10846. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10847. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  10848. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10849. ( parameters.extensionShaderTextureLOD || parameters.envMap || parameters.transmission ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10850. ];
  10851. return chunks.filter( filterEmptyLine ).join( '\n' );
  10852. }
  10853. function generateDefines( defines ) {
  10854. const chunks = [];
  10855. for ( const name in defines ) {
  10856. const value = defines[ name ];
  10857. if ( value === false ) continue;
  10858. chunks.push( '#define ' + name + ' ' + value );
  10859. }
  10860. return chunks.join( '\n' );
  10861. }
  10862. function fetchAttributeLocations( gl, program ) {
  10863. const attributes = {};
  10864. const n = gl.getProgramParameter( program, 35721 );
  10865. for ( let i = 0; i < n; i ++ ) {
  10866. const info = gl.getActiveAttrib( program, i );
  10867. const name = info.name;
  10868. let locationSize = 1;
  10869. if ( info.type === 35674 ) locationSize = 2;
  10870. if ( info.type === 35675 ) locationSize = 3;
  10871. if ( info.type === 35676 ) locationSize = 4;
  10872. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10873. attributes[ name ] = {
  10874. type: info.type,
  10875. location: gl.getAttribLocation( program, name ),
  10876. locationSize: locationSize
  10877. };
  10878. }
  10879. return attributes;
  10880. }
  10881. function filterEmptyLine( string ) {
  10882. return string !== '';
  10883. }
  10884. function replaceLightNums( string, parameters ) {
  10885. return string
  10886. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10887. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10888. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10889. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10890. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10891. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10892. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10893. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10894. }
  10895. function replaceClippingPlaneNums( string, parameters ) {
  10896. return string
  10897. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10898. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10899. }
  10900. // Resolve Includes
  10901. const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10902. function resolveIncludes( string ) {
  10903. return string.replace( includePattern, includeReplacer );
  10904. }
  10905. function includeReplacer( match, include ) {
  10906. const string = ShaderChunk[ include ];
  10907. if ( string === undefined ) {
  10908. throw new Error( 'Can not resolve #include <' + include + '>' );
  10909. }
  10910. return resolveIncludes( string );
  10911. }
  10912. // Unroll Loops
  10913. const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10914. const unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
  10915. function unrollLoops( string ) {
  10916. return string
  10917. .replace( unrollLoopPattern, loopReplacer )
  10918. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  10919. }
  10920. function deprecatedLoopReplacer( match, start, end, snippet ) {
  10921. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  10922. return loopReplacer( match, start, end, snippet );
  10923. }
  10924. function loopReplacer( match, start, end, snippet ) {
  10925. let string = '';
  10926. for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10927. string += snippet
  10928. .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )
  10929. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10930. }
  10931. return string;
  10932. }
  10933. //
  10934. function generatePrecision( parameters ) {
  10935. let precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10936. if ( parameters.precision === 'highp' ) {
  10937. precisionstring += '\n#define HIGH_PRECISION';
  10938. } else if ( parameters.precision === 'mediump' ) {
  10939. precisionstring += '\n#define MEDIUM_PRECISION';
  10940. } else if ( parameters.precision === 'lowp' ) {
  10941. precisionstring += '\n#define LOW_PRECISION';
  10942. }
  10943. return precisionstring;
  10944. }
  10945. function generateShadowMapTypeDefine( parameters ) {
  10946. let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10947. if ( parameters.shadowMapType === PCFShadowMap ) {
  10948. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10949. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10950. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10951. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  10952. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10953. }
  10954. return shadowMapTypeDefine;
  10955. }
  10956. function generateEnvMapTypeDefine( parameters ) {
  10957. let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10958. if ( parameters.envMap ) {
  10959. switch ( parameters.envMapMode ) {
  10960. case CubeReflectionMapping:
  10961. case CubeRefractionMapping:
  10962. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10963. break;
  10964. case CubeUVReflectionMapping:
  10965. case CubeUVRefractionMapping:
  10966. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10967. break;
  10968. }
  10969. }
  10970. return envMapTypeDefine;
  10971. }
  10972. function generateEnvMapModeDefine( parameters ) {
  10973. let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10974. if ( parameters.envMap ) {
  10975. switch ( parameters.envMapMode ) {
  10976. case CubeRefractionMapping:
  10977. case CubeUVRefractionMapping:
  10978. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10979. break;
  10980. }
  10981. }
  10982. return envMapModeDefine;
  10983. }
  10984. function generateEnvMapBlendingDefine( parameters ) {
  10985. let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10986. if ( parameters.envMap ) {
  10987. switch ( parameters.combine ) {
  10988. case MultiplyOperation:
  10989. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10990. break;
  10991. case MixOperation:
  10992. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10993. break;
  10994. case AddOperation:
  10995. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10996. break;
  10997. }
  10998. }
  10999. return envMapBlendingDefine;
  11000. }
  11001. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  11002. // TODO Send this event to Three.js DevTools
  11003. // console.log( 'WebGLProgram', cacheKey );
  11004. const gl = renderer.getContext();
  11005. const defines = parameters.defines;
  11006. let vertexShader = parameters.vertexShader;
  11007. let fragmentShader = parameters.fragmentShader;
  11008. const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  11009. const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  11010. const envMapModeDefine = generateEnvMapModeDefine( parameters );
  11011. const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  11012. const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  11013. const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  11014. const customDefines = generateDefines( defines );
  11015. const program = gl.createProgram();
  11016. let prefixVertex, prefixFragment;
  11017. let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11018. if ( parameters.isRawShaderMaterial ) {
  11019. prefixVertex = [
  11020. customDefines
  11021. ].filter( filterEmptyLine ).join( '\n' );
  11022. if ( prefixVertex.length > 0 ) {
  11023. prefixVertex += '\n';
  11024. }
  11025. prefixFragment = [
  11026. customExtensions,
  11027. customDefines
  11028. ].filter( filterEmptyLine ).join( '\n' );
  11029. if ( prefixFragment.length > 0 ) {
  11030. prefixFragment += '\n';
  11031. }
  11032. } else {
  11033. prefixVertex = [
  11034. generatePrecision( parameters ),
  11035. '#define SHADER_NAME ' + parameters.shaderName,
  11036. customDefines,
  11037. parameters.instancing ? '#define USE_INSTANCING' : '',
  11038. parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
  11039. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  11040. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11041. '#define MAX_BONES ' + parameters.maxBones,
  11042. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11043. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11044. parameters.map ? '#define USE_MAP' : '',
  11045. parameters.envMap ? '#define USE_ENVMAP' : '',
  11046. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11047. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11048. parameters.aoMap ? '#define USE_AOMAP' : '',
  11049. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11050. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11051. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11052. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11053. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11054. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11055. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11056. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11057. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  11058. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11059. parameters.specularIntensityMap ? '#define USE_SPECULARINTENSITYMAP' : '',
  11060. parameters.specularTintMap ? '#define USE_SPECULARTINTMAP' : '',
  11061. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11062. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11063. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11064. parameters.transmission ? '#define USE_TRANSMISSION' : '',
  11065. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  11066. parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
  11067. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11068. parameters.vertexColors ? '#define USE_COLOR' : '',
  11069. parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
  11070. parameters.vertexUvs ? '#define USE_UV' : '',
  11071. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11072. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11073. parameters.skinning ? '#define USE_SKINNING' : '',
  11074. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  11075. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  11076. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  11077. ( parameters.morphTargets && parameters.isWebGL2 ) ? '#define MORPHTARGETS_TEXTURE' : '',
  11078. ( parameters.morphTargets && parameters.isWebGL2 ) ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '',
  11079. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11080. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11081. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11082. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11083. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  11084. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11085. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11086. 'uniform mat4 modelMatrix;',
  11087. 'uniform mat4 modelViewMatrix;',
  11088. 'uniform mat4 projectionMatrix;',
  11089. 'uniform mat4 viewMatrix;',
  11090. 'uniform mat3 normalMatrix;',
  11091. 'uniform vec3 cameraPosition;',
  11092. 'uniform bool isOrthographic;',
  11093. '#ifdef USE_INSTANCING',
  11094. ' attribute mat4 instanceMatrix;',
  11095. '#endif',
  11096. '#ifdef USE_INSTANCING_COLOR',
  11097. ' attribute vec3 instanceColor;',
  11098. '#endif',
  11099. 'attribute vec3 position;',
  11100. 'attribute vec3 normal;',
  11101. 'attribute vec2 uv;',
  11102. '#ifdef USE_TANGENT',
  11103. ' attribute vec4 tangent;',
  11104. '#endif',
  11105. '#if defined( USE_COLOR_ALPHA )',
  11106. ' attribute vec4 color;',
  11107. '#elif defined( USE_COLOR )',
  11108. ' attribute vec3 color;',
  11109. '#endif',
  11110. '#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )',
  11111. ' attribute vec3 morphTarget0;',
  11112. ' attribute vec3 morphTarget1;',
  11113. ' attribute vec3 morphTarget2;',
  11114. ' attribute vec3 morphTarget3;',
  11115. ' #ifdef USE_MORPHNORMALS',
  11116. ' attribute vec3 morphNormal0;',
  11117. ' attribute vec3 morphNormal1;',
  11118. ' attribute vec3 morphNormal2;',
  11119. ' attribute vec3 morphNormal3;',
  11120. ' #else',
  11121. ' attribute vec3 morphTarget4;',
  11122. ' attribute vec3 morphTarget5;',
  11123. ' attribute vec3 morphTarget6;',
  11124. ' attribute vec3 morphTarget7;',
  11125. ' #endif',
  11126. '#endif',
  11127. '#ifdef USE_SKINNING',
  11128. ' attribute vec4 skinIndex;',
  11129. ' attribute vec4 skinWeight;',
  11130. '#endif',
  11131. '\n'
  11132. ].filter( filterEmptyLine ).join( '\n' );
  11133. prefixFragment = [
  11134. customExtensions,
  11135. generatePrecision( parameters ),
  11136. '#define SHADER_NAME ' + parameters.shaderName,
  11137. customDefines,
  11138. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11139. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11140. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11141. parameters.map ? '#define USE_MAP' : '',
  11142. parameters.matcap ? '#define USE_MATCAP' : '',
  11143. parameters.envMap ? '#define USE_ENVMAP' : '',
  11144. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  11145. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11146. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  11147. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11148. parameters.aoMap ? '#define USE_AOMAP' : '',
  11149. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11150. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11151. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11152. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11153. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11154. parameters.clearcoat ? '#define USE_CLEARCOAT' : '',
  11155. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11156. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11157. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11158. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11159. parameters.specularIntensityMap ? '#define USE_SPECULARINTENSITYMAP' : '',
  11160. parameters.specularTintMap ? '#define USE_SPECULARTINTMAP' : '',
  11161. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11162. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11163. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11164. parameters.alphaTest ? '#define USE_ALPHATEST' : '',
  11165. parameters.sheen ? '#define USE_SHEEN' : '',
  11166. parameters.transmission ? '#define USE_TRANSMISSION' : '',
  11167. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  11168. parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
  11169. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11170. parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
  11171. parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
  11172. parameters.vertexUvs ? '#define USE_UV' : '',
  11173. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11174. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  11175. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11176. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11177. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11178. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11179. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11180. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  11181. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  11182. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11183. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11184. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  11185. 'uniform mat4 viewMatrix;',
  11186. 'uniform vec3 cameraPosition;',
  11187. 'uniform bool isOrthographic;',
  11188. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  11189. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  11190. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  11191. parameters.dithering ? '#define DITHERING' : '',
  11192. parameters.format === RGBFormat ? '#define OPAQUE' : '',
  11193. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  11194. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  11195. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  11196. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  11197. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  11198. parameters.specularTintMap ? getTexelDecodingFunction( 'specularTintMapTexelToLinear', parameters.specularTintMapEncoding ) : '',
  11199. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  11200. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  11201. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  11202. '\n'
  11203. ].filter( filterEmptyLine ).join( '\n' );
  11204. }
  11205. vertexShader = resolveIncludes( vertexShader );
  11206. vertexShader = replaceLightNums( vertexShader, parameters );
  11207. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  11208. fragmentShader = resolveIncludes( fragmentShader );
  11209. fragmentShader = replaceLightNums( fragmentShader, parameters );
  11210. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  11211. vertexShader = unrollLoops( vertexShader );
  11212. fragmentShader = unrollLoops( fragmentShader );
  11213. if ( parameters.isWebGL2 && parameters.isRawShaderMaterial !== true ) {
  11214. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11215. versionString = '#version 300 es\n';
  11216. prefixVertex = [
  11217. 'precision mediump sampler2DArray;',
  11218. '#define attribute in',
  11219. '#define varying out',
  11220. '#define texture2D texture'
  11221. ].join( '\n' ) + '\n' + prefixVertex;
  11222. prefixFragment = [
  11223. '#define varying in',
  11224. ( parameters.glslVersion === GLSL3 ) ? '' : 'out highp vec4 pc_fragColor;',
  11225. ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor',
  11226. '#define gl_FragDepthEXT gl_FragDepth',
  11227. '#define texture2D texture',
  11228. '#define textureCube texture',
  11229. '#define texture2DProj textureProj',
  11230. '#define texture2DLodEXT textureLod',
  11231. '#define texture2DProjLodEXT textureProjLod',
  11232. '#define textureCubeLodEXT textureLod',
  11233. '#define texture2DGradEXT textureGrad',
  11234. '#define texture2DProjGradEXT textureProjGrad',
  11235. '#define textureCubeGradEXT textureGrad'
  11236. ].join( '\n' ) + '\n' + prefixFragment;
  11237. }
  11238. const vertexGlsl = versionString + prefixVertex + vertexShader;
  11239. const fragmentGlsl = versionString + prefixFragment + fragmentShader;
  11240. // console.log( '*VERTEX*', vertexGlsl );
  11241. // console.log( '*FRAGMENT*', fragmentGlsl );
  11242. const glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  11243. const glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  11244. gl.attachShader( program, glVertexShader );
  11245. gl.attachShader( program, glFragmentShader );
  11246. // Force a particular attribute to index 0.
  11247. if ( parameters.index0AttributeName !== undefined ) {
  11248. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  11249. } else if ( parameters.morphTargets === true ) {
  11250. // programs with morphTargets displace position out of attribute 0
  11251. gl.bindAttribLocation( program, 0, 'position' );
  11252. }
  11253. gl.linkProgram( program );
  11254. // check for link errors
  11255. if ( renderer.debug.checkShaderErrors ) {
  11256. const programLog = gl.getProgramInfoLog( program ).trim();
  11257. const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  11258. const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  11259. let runnable = true;
  11260. let haveDiagnostics = true;
  11261. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  11262. runnable = false;
  11263. const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  11264. const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  11265. console.error(
  11266. 'THREE.WebGLProgram: Shader Error ' + gl.getError() + ' - ' +
  11267. 'VALIDATE_STATUS ' + gl.getProgramParameter( program, 35715 ) + '\n\n' +
  11268. 'Program Info Log: ' + programLog + '\n' +
  11269. vertexErrors + '\n' +
  11270. fragmentErrors
  11271. );
  11272. } else if ( programLog !== '' ) {
  11273. console.warn( 'THREE.WebGLProgram: Program Info Log:', programLog );
  11274. } else if ( vertexLog === '' || fragmentLog === '' ) {
  11275. haveDiagnostics = false;
  11276. }
  11277. if ( haveDiagnostics ) {
  11278. this.diagnostics = {
  11279. runnable: runnable,
  11280. programLog: programLog,
  11281. vertexShader: {
  11282. log: vertexLog,
  11283. prefix: prefixVertex
  11284. },
  11285. fragmentShader: {
  11286. log: fragmentLog,
  11287. prefix: prefixFragment
  11288. }
  11289. };
  11290. }
  11291. }
  11292. // Clean up
  11293. // Crashes in iOS9 and iOS10. #18402
  11294. // gl.detachShader( program, glVertexShader );
  11295. // gl.detachShader( program, glFragmentShader );
  11296. gl.deleteShader( glVertexShader );
  11297. gl.deleteShader( glFragmentShader );
  11298. // set up caching for uniform locations
  11299. let cachedUniforms;
  11300. this.getUniforms = function () {
  11301. if ( cachedUniforms === undefined ) {
  11302. cachedUniforms = new WebGLUniforms( gl, program );
  11303. }
  11304. return cachedUniforms;
  11305. };
  11306. // set up caching for attribute locations
  11307. let cachedAttributes;
  11308. this.getAttributes = function () {
  11309. if ( cachedAttributes === undefined ) {
  11310. cachedAttributes = fetchAttributeLocations( gl, program );
  11311. }
  11312. return cachedAttributes;
  11313. };
  11314. // free resource
  11315. this.destroy = function () {
  11316. bindingStates.releaseStatesOfProgram( this );
  11317. gl.deleteProgram( program );
  11318. this.program = undefined;
  11319. };
  11320. //
  11321. this.name = parameters.shaderName;
  11322. this.id = programIdCount ++;
  11323. this.cacheKey = cacheKey;
  11324. this.usedTimes = 1;
  11325. this.program = program;
  11326. this.vertexShader = glVertexShader;
  11327. this.fragmentShader = glFragmentShader;
  11328. return this;
  11329. }
  11330. function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping ) {
  11331. const programs = [];
  11332. const isWebGL2 = capabilities.isWebGL2;
  11333. const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11334. const floatVertexTextures = capabilities.floatVertexTextures;
  11335. const maxVertexUniforms = capabilities.maxVertexUniforms;
  11336. const vertexTextures = capabilities.vertexTextures;
  11337. let precision = capabilities.precision;
  11338. const shaderIDs = {
  11339. MeshDepthMaterial: 'depth',
  11340. MeshDistanceMaterial: 'distanceRGBA',
  11341. MeshNormalMaterial: 'normal',
  11342. MeshBasicMaterial: 'basic',
  11343. MeshLambertMaterial: 'lambert',
  11344. MeshPhongMaterial: 'phong',
  11345. MeshToonMaterial: 'toon',
  11346. MeshStandardMaterial: 'physical',
  11347. MeshPhysicalMaterial: 'physical',
  11348. MeshMatcapMaterial: 'matcap',
  11349. LineBasicMaterial: 'basic',
  11350. LineDashedMaterial: 'dashed',
  11351. PointsMaterial: 'points',
  11352. ShadowMaterial: 'shadow',
  11353. SpriteMaterial: 'sprite'
  11354. };
  11355. const parameterNames = [
  11356. 'precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor',
  11357. 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV',
  11358. 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap',
  11359. 'objectSpaceNormalMap', 'tangentSpaceNormalMap',
  11360. 'clearcoat', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap',
  11361. 'displacementMap',
  11362. 'specularMap', 'specularIntensityMap', 'specularTintMap', 'specularTintMapEncoding', 'roughnessMap', 'metalnessMap', 'gradientMap',
  11363. 'alphaMap', 'alphaTest', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2',
  11364. 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning',
  11365. 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'morphTargetsCount', 'premultipliedAlpha',
  11366. 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
  11367. 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
  11368. 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
  11369. 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'format',
  11370. 'sheen', 'transmission', 'transmissionMap', 'thicknessMap'
  11371. ];
  11372. function getMaxBones( object ) {
  11373. const skeleton = object.skeleton;
  11374. const bones = skeleton.bones;
  11375. if ( floatVertexTextures ) {
  11376. return 1024;
  11377. } else {
  11378. // default for when object is not specified
  11379. // ( for example when prebuilding shader to be used with multiple objects )
  11380. //
  11381. // - leave some extra space for other uniforms
  11382. // - limit here is ANGLE's 254 max uniform vectors
  11383. // (up to 54 should be safe)
  11384. const nVertexUniforms = maxVertexUniforms;
  11385. const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  11386. const maxBones = Math.min( nVertexMatrices, bones.length );
  11387. if ( maxBones < bones.length ) {
  11388. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  11389. return 0;
  11390. }
  11391. return maxBones;
  11392. }
  11393. }
  11394. function getTextureEncodingFromMap( map ) {
  11395. let encoding;
  11396. if ( map && map.isTexture ) {
  11397. encoding = map.encoding;
  11398. } else if ( map && map.isWebGLRenderTarget ) {
  11399. console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' );
  11400. encoding = map.texture.encoding;
  11401. } else {
  11402. encoding = LinearEncoding;
  11403. }
  11404. return encoding;
  11405. }
  11406. function getParameters( material, lights, shadows, scene, object ) {
  11407. const fog = scene.fog;
  11408. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  11409. const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
  11410. const shaderID = shaderIDs[ material.type ];
  11411. // heuristics to create shader parameters according to lights in the scene
  11412. // (not to blow over maxLights budget)
  11413. const maxBones = object.isSkinnedMesh ? getMaxBones( object ) : 0;
  11414. if ( material.precision !== null ) {
  11415. precision = capabilities.getMaxPrecision( material.precision );
  11416. if ( precision !== material.precision ) {
  11417. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11418. }
  11419. }
  11420. let vertexShader, fragmentShader;
  11421. if ( shaderID ) {
  11422. const shader = ShaderLib[ shaderID ];
  11423. vertexShader = shader.vertexShader;
  11424. fragmentShader = shader.fragmentShader;
  11425. } else {
  11426. vertexShader = material.vertexShader;
  11427. fragmentShader = material.fragmentShader;
  11428. }
  11429. const currentRenderTarget = renderer.getRenderTarget();
  11430. const useAlphaTest = material.alphaTest > 0;
  11431. const useClearcoat = material.clearcoat > 0;
  11432. const parameters = {
  11433. isWebGL2: isWebGL2,
  11434. shaderID: shaderID,
  11435. shaderName: material.type,
  11436. vertexShader: vertexShader,
  11437. fragmentShader: fragmentShader,
  11438. defines: material.defines,
  11439. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11440. glslVersion: material.glslVersion,
  11441. precision: precision,
  11442. instancing: object.isInstancedMesh === true,
  11443. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11444. supportsVertexTextures: vertexTextures,
  11445. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  11446. map: !! material.map,
  11447. mapEncoding: getTextureEncodingFromMap( material.map ),
  11448. matcap: !! material.matcap,
  11449. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  11450. envMap: !! envMap,
  11451. envMapMode: envMap && envMap.mapping,
  11452. envMapEncoding: getTextureEncodingFromMap( envMap ),
  11453. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  11454. lightMap: !! material.lightMap,
  11455. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  11456. aoMap: !! material.aoMap,
  11457. emissiveMap: !! material.emissiveMap,
  11458. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  11459. bumpMap: !! material.bumpMap,
  11460. normalMap: !! material.normalMap,
  11461. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11462. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11463. clearcoat: useClearcoat,
  11464. clearcoatMap: useClearcoat && !! material.clearcoatMap,
  11465. clearcoatRoughnessMap: useClearcoat && !! material.clearcoatRoughnessMap,
  11466. clearcoatNormalMap: useClearcoat && !! material.clearcoatNormalMap,
  11467. displacementMap: !! material.displacementMap,
  11468. roughnessMap: !! material.roughnessMap,
  11469. metalnessMap: !! material.metalnessMap,
  11470. specularMap: !! material.specularMap,
  11471. specularIntensityMap: !! material.specularIntensityMap,
  11472. specularTintMap: !! material.specularTintMap,
  11473. specularTintMapEncoding: getTextureEncodingFromMap( material.specularTintMap ),
  11474. alphaMap: !! material.alphaMap,
  11475. alphaTest: useAlphaTest,
  11476. gradientMap: !! material.gradientMap,
  11477. sheen: material.sheen > 0,
  11478. transmission: material.transmission > 0,
  11479. transmissionMap: !! material.transmissionMap,
  11480. thicknessMap: !! material.thicknessMap,
  11481. combine: material.combine,
  11482. vertexTangents: ( !! material.normalMap && !! object.geometry && !! object.geometry.attributes.tangent ),
  11483. vertexColors: material.vertexColors,
  11484. vertexAlphas: material.vertexColors === true && !! object.geometry && !! object.geometry.attributes.color && object.geometry.attributes.color.itemSize === 4,
  11485. vertexUvs: !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatMap || !! material.clearcoatRoughnessMap || !! material.clearcoatNormalMap || !! material.displacementMap || !! material.transmissionMap || !! material.thicknessMap || !! material.specularIntensityMap || !! material.specularTintMap,
  11486. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || material.transmission > 0 || !! material.transmissionMap || !! material.thicknessMap || !! material.specularIntensityMap || !! material.specularTintMap ) && !! material.displacementMap,
  11487. fog: !! fog,
  11488. useFog: material.fog,
  11489. fogExp2: ( fog && fog.isFogExp2 ),
  11490. flatShading: !! material.flatShading,
  11491. sizeAttenuation: material.sizeAttenuation,
  11492. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11493. skinning: object.isSkinnedMesh === true && maxBones > 0,
  11494. maxBones: maxBones,
  11495. useVertexTexture: floatVertexTextures,
  11496. morphTargets: !! object.geometry && !! object.geometry.morphAttributes.position,
  11497. morphNormals: !! object.geometry && !! object.geometry.morphAttributes.normal,
  11498. morphTargetsCount: ( !! object.geometry && !! object.geometry.morphAttributes.position ) ? object.geometry.morphAttributes.position.length : 0,
  11499. numDirLights: lights.directional.length,
  11500. numPointLights: lights.point.length,
  11501. numSpotLights: lights.spot.length,
  11502. numRectAreaLights: lights.rectArea.length,
  11503. numHemiLights: lights.hemi.length,
  11504. numDirLightShadows: lights.directionalShadowMap.length,
  11505. numPointLightShadows: lights.pointShadowMap.length,
  11506. numSpotLightShadows: lights.spotShadowMap.length,
  11507. numClippingPlanes: clipping.numPlanes,
  11508. numClipIntersection: clipping.numIntersection,
  11509. format: material.format,
  11510. dithering: material.dithering,
  11511. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11512. shadowMapType: renderer.shadowMap.type,
  11513. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11514. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11515. premultipliedAlpha: material.premultipliedAlpha,
  11516. doubleSided: material.side === DoubleSide,
  11517. flipSided: material.side === BackSide,
  11518. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  11519. index0AttributeName: material.index0AttributeName,
  11520. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11521. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11522. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11523. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11524. rendererExtensionFragDepth: isWebGL2 || extensions.has( 'EXT_frag_depth' ),
  11525. rendererExtensionDrawBuffers: isWebGL2 || extensions.has( 'WEBGL_draw_buffers' ),
  11526. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has( 'EXT_shader_texture_lod' ),
  11527. customProgramCacheKey: material.customProgramCacheKey()
  11528. };
  11529. return parameters;
  11530. }
  11531. function getProgramCacheKey( parameters ) {
  11532. const array = [];
  11533. if ( parameters.shaderID ) {
  11534. array.push( parameters.shaderID );
  11535. } else {
  11536. array.push( parameters.fragmentShader );
  11537. array.push( parameters.vertexShader );
  11538. }
  11539. if ( parameters.defines !== undefined ) {
  11540. for ( const name in parameters.defines ) {
  11541. array.push( name );
  11542. array.push( parameters.defines[ name ] );
  11543. }
  11544. }
  11545. if ( parameters.isRawShaderMaterial === false ) {
  11546. for ( let i = 0; i < parameterNames.length; i ++ ) {
  11547. array.push( parameters[ parameterNames[ i ] ] );
  11548. }
  11549. array.push( renderer.outputEncoding );
  11550. array.push( renderer.gammaFactor );
  11551. }
  11552. array.push( parameters.customProgramCacheKey );
  11553. return array.join();
  11554. }
  11555. function getUniforms( material ) {
  11556. const shaderID = shaderIDs[ material.type ];
  11557. let uniforms;
  11558. if ( shaderID ) {
  11559. const shader = ShaderLib[ shaderID ];
  11560. uniforms = UniformsUtils.clone( shader.uniforms );
  11561. } else {
  11562. uniforms = material.uniforms;
  11563. }
  11564. return uniforms;
  11565. }
  11566. function acquireProgram( parameters, cacheKey ) {
  11567. let program;
  11568. // Check if code has been already compiled
  11569. for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
  11570. const preexistingProgram = programs[ p ];
  11571. if ( preexistingProgram.cacheKey === cacheKey ) {
  11572. program = preexistingProgram;
  11573. ++ program.usedTimes;
  11574. break;
  11575. }
  11576. }
  11577. if ( program === undefined ) {
  11578. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  11579. programs.push( program );
  11580. }
  11581. return program;
  11582. }
  11583. function releaseProgram( program ) {
  11584. if ( -- program.usedTimes === 0 ) {
  11585. // Remove from unordered set
  11586. const i = programs.indexOf( program );
  11587. programs[ i ] = programs[ programs.length - 1 ];
  11588. programs.pop();
  11589. // Free WebGL resources
  11590. program.destroy();
  11591. }
  11592. }
  11593. return {
  11594. getParameters: getParameters,
  11595. getProgramCacheKey: getProgramCacheKey,
  11596. getUniforms: getUniforms,
  11597. acquireProgram: acquireProgram,
  11598. releaseProgram: releaseProgram,
  11599. // Exposed for resource monitoring & error feedback via renderer.info:
  11600. programs: programs
  11601. };
  11602. }
  11603. function WebGLProperties() {
  11604. let properties = new WeakMap();
  11605. function get( object ) {
  11606. let map = properties.get( object );
  11607. if ( map === undefined ) {
  11608. map = {};
  11609. properties.set( object, map );
  11610. }
  11611. return map;
  11612. }
  11613. function remove( object ) {
  11614. properties.delete( object );
  11615. }
  11616. function update( object, key, value ) {
  11617. properties.get( object )[ key ] = value;
  11618. }
  11619. function dispose() {
  11620. properties = new WeakMap();
  11621. }
  11622. return {
  11623. get: get,
  11624. remove: remove,
  11625. update: update,
  11626. dispose: dispose
  11627. };
  11628. }
  11629. function painterSortStable( a, b ) {
  11630. if ( a.groupOrder !== b.groupOrder ) {
  11631. return a.groupOrder - b.groupOrder;
  11632. } else if ( a.renderOrder !== b.renderOrder ) {
  11633. return a.renderOrder - b.renderOrder;
  11634. } else if ( a.program !== b.program ) {
  11635. return a.program.id - b.program.id;
  11636. } else if ( a.material.id !== b.material.id ) {
  11637. return a.material.id - b.material.id;
  11638. } else if ( a.z !== b.z ) {
  11639. return a.z - b.z;
  11640. } else {
  11641. return a.id - b.id;
  11642. }
  11643. }
  11644. function reversePainterSortStable( a, b ) {
  11645. if ( a.groupOrder !== b.groupOrder ) {
  11646. return a.groupOrder - b.groupOrder;
  11647. } else if ( a.renderOrder !== b.renderOrder ) {
  11648. return a.renderOrder - b.renderOrder;
  11649. } else if ( a.z !== b.z ) {
  11650. return b.z - a.z;
  11651. } else {
  11652. return a.id - b.id;
  11653. }
  11654. }
  11655. function WebGLRenderList( properties ) {
  11656. const renderItems = [];
  11657. let renderItemsIndex = 0;
  11658. const opaque = [];
  11659. const transmissive = [];
  11660. const transparent = [];
  11661. const defaultProgram = { id: - 1 };
  11662. function init() {
  11663. renderItemsIndex = 0;
  11664. opaque.length = 0;
  11665. transmissive.length = 0;
  11666. transparent.length = 0;
  11667. }
  11668. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11669. let renderItem = renderItems[ renderItemsIndex ];
  11670. const materialProperties = properties.get( material );
  11671. if ( renderItem === undefined ) {
  11672. renderItem = {
  11673. id: object.id,
  11674. object: object,
  11675. geometry: geometry,
  11676. material: material,
  11677. program: materialProperties.program || defaultProgram,
  11678. groupOrder: groupOrder,
  11679. renderOrder: object.renderOrder,
  11680. z: z,
  11681. group: group
  11682. };
  11683. renderItems[ renderItemsIndex ] = renderItem;
  11684. } else {
  11685. renderItem.id = object.id;
  11686. renderItem.object = object;
  11687. renderItem.geometry = geometry;
  11688. renderItem.material = material;
  11689. renderItem.program = materialProperties.program || defaultProgram;
  11690. renderItem.groupOrder = groupOrder;
  11691. renderItem.renderOrder = object.renderOrder;
  11692. renderItem.z = z;
  11693. renderItem.group = group;
  11694. }
  11695. renderItemsIndex ++;
  11696. return renderItem;
  11697. }
  11698. function push( object, geometry, material, groupOrder, z, group ) {
  11699. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11700. if ( material.transmission > 0.0 ) {
  11701. transmissive.push( renderItem );
  11702. } else if ( material.transparent === true ) {
  11703. transparent.push( renderItem );
  11704. } else {
  11705. opaque.push( renderItem );
  11706. }
  11707. }
  11708. function unshift( object, geometry, material, groupOrder, z, group ) {
  11709. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11710. if ( material.transmission > 0.0 ) {
  11711. transmissive.unshift( renderItem );
  11712. } else if ( material.transparent === true ) {
  11713. transparent.unshift( renderItem );
  11714. } else {
  11715. opaque.unshift( renderItem );
  11716. }
  11717. }
  11718. function sort( customOpaqueSort, customTransparentSort ) {
  11719. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  11720. if ( transmissive.length > 1 ) transmissive.sort( customTransparentSort || reversePainterSortStable );
  11721. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  11722. }
  11723. function finish() {
  11724. // Clear references from inactive renderItems in the list
  11725. for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  11726. const renderItem = renderItems[ i ];
  11727. if ( renderItem.id === null ) break;
  11728. renderItem.id = null;
  11729. renderItem.object = null;
  11730. renderItem.geometry = null;
  11731. renderItem.material = null;
  11732. renderItem.program = null;
  11733. renderItem.group = null;
  11734. }
  11735. }
  11736. return {
  11737. opaque: opaque,
  11738. transmissive: transmissive,
  11739. transparent: transparent,
  11740. init: init,
  11741. push: push,
  11742. unshift: unshift,
  11743. finish: finish,
  11744. sort: sort
  11745. };
  11746. }
  11747. function WebGLRenderLists( properties ) {
  11748. let lists = new WeakMap();
  11749. function get( scene, renderCallDepth ) {
  11750. let list;
  11751. if ( lists.has( scene ) === false ) {
  11752. list = new WebGLRenderList( properties );
  11753. lists.set( scene, [ list ] );
  11754. } else {
  11755. if ( renderCallDepth >= lists.get( scene ).length ) {
  11756. list = new WebGLRenderList( properties );
  11757. lists.get( scene ).push( list );
  11758. } else {
  11759. list = lists.get( scene )[ renderCallDepth ];
  11760. }
  11761. }
  11762. return list;
  11763. }
  11764. function dispose() {
  11765. lists = new WeakMap();
  11766. }
  11767. return {
  11768. get: get,
  11769. dispose: dispose
  11770. };
  11771. }
  11772. function UniformsCache() {
  11773. const lights = {};
  11774. return {
  11775. get: function ( light ) {
  11776. if ( lights[ light.id ] !== undefined ) {
  11777. return lights[ light.id ];
  11778. }
  11779. let uniforms;
  11780. switch ( light.type ) {
  11781. case 'DirectionalLight':
  11782. uniforms = {
  11783. direction: new Vector3(),
  11784. color: new Color()
  11785. };
  11786. break;
  11787. case 'SpotLight':
  11788. uniforms = {
  11789. position: new Vector3(),
  11790. direction: new Vector3(),
  11791. color: new Color(),
  11792. distance: 0,
  11793. coneCos: 0,
  11794. penumbraCos: 0,
  11795. decay: 0
  11796. };
  11797. break;
  11798. case 'PointLight':
  11799. uniforms = {
  11800. position: new Vector3(),
  11801. color: new Color(),
  11802. distance: 0,
  11803. decay: 0
  11804. };
  11805. break;
  11806. case 'HemisphereLight':
  11807. uniforms = {
  11808. direction: new Vector3(),
  11809. skyColor: new Color(),
  11810. groundColor: new Color()
  11811. };
  11812. break;
  11813. case 'RectAreaLight':
  11814. uniforms = {
  11815. color: new Color(),
  11816. position: new Vector3(),
  11817. halfWidth: new Vector3(),
  11818. halfHeight: new Vector3()
  11819. };
  11820. break;
  11821. }
  11822. lights[ light.id ] = uniforms;
  11823. return uniforms;
  11824. }
  11825. };
  11826. }
  11827. function ShadowUniformsCache() {
  11828. const lights = {};
  11829. return {
  11830. get: function ( light ) {
  11831. if ( lights[ light.id ] !== undefined ) {
  11832. return lights[ light.id ];
  11833. }
  11834. let uniforms;
  11835. switch ( light.type ) {
  11836. case 'DirectionalLight':
  11837. uniforms = {
  11838. shadowBias: 0,
  11839. shadowNormalBias: 0,
  11840. shadowRadius: 1,
  11841. shadowMapSize: new Vector2()
  11842. };
  11843. break;
  11844. case 'SpotLight':
  11845. uniforms = {
  11846. shadowBias: 0,
  11847. shadowNormalBias: 0,
  11848. shadowRadius: 1,
  11849. shadowMapSize: new Vector2()
  11850. };
  11851. break;
  11852. case 'PointLight':
  11853. uniforms = {
  11854. shadowBias: 0,
  11855. shadowNormalBias: 0,
  11856. shadowRadius: 1,
  11857. shadowMapSize: new Vector2(),
  11858. shadowCameraNear: 1,
  11859. shadowCameraFar: 1000
  11860. };
  11861. break;
  11862. // TODO (abelnation): set RectAreaLight shadow uniforms
  11863. }
  11864. lights[ light.id ] = uniforms;
  11865. return uniforms;
  11866. }
  11867. };
  11868. }
  11869. let nextVersion = 0;
  11870. function shadowCastingLightsFirst( lightA, lightB ) {
  11871. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11872. }
  11873. function WebGLLights( extensions, capabilities ) {
  11874. const cache = new UniformsCache();
  11875. const shadowCache = ShadowUniformsCache();
  11876. const state = {
  11877. version: 0,
  11878. hash: {
  11879. directionalLength: - 1,
  11880. pointLength: - 1,
  11881. spotLength: - 1,
  11882. rectAreaLength: - 1,
  11883. hemiLength: - 1,
  11884. numDirectionalShadows: - 1,
  11885. numPointShadows: - 1,
  11886. numSpotShadows: - 1
  11887. },
  11888. ambient: [ 0, 0, 0 ],
  11889. probe: [],
  11890. directional: [],
  11891. directionalShadow: [],
  11892. directionalShadowMap: [],
  11893. directionalShadowMatrix: [],
  11894. spot: [],
  11895. spotShadow: [],
  11896. spotShadowMap: [],
  11897. spotShadowMatrix: [],
  11898. rectArea: [],
  11899. rectAreaLTC1: null,
  11900. rectAreaLTC2: null,
  11901. point: [],
  11902. pointShadow: [],
  11903. pointShadowMap: [],
  11904. pointShadowMatrix: [],
  11905. hemi: []
  11906. };
  11907. for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11908. const vector3 = new Vector3();
  11909. const matrix4 = new Matrix4();
  11910. const matrix42 = new Matrix4();
  11911. function setup( lights, physicallyCorrectLights ) {
  11912. let r = 0, g = 0, b = 0;
  11913. for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11914. let directionalLength = 0;
  11915. let pointLength = 0;
  11916. let spotLength = 0;
  11917. let rectAreaLength = 0;
  11918. let hemiLength = 0;
  11919. let numDirectionalShadows = 0;
  11920. let numPointShadows = 0;
  11921. let numSpotShadows = 0;
  11922. lights.sort( shadowCastingLightsFirst );
  11923. // artist-friendly light intensity scaling factor
  11924. const scaleFactor = ( physicallyCorrectLights !== true ) ? Math.PI : 1;
  11925. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11926. const light = lights[ i ];
  11927. const color = light.color;
  11928. const intensity = light.intensity;
  11929. const distance = light.distance;
  11930. const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11931. if ( light.isAmbientLight ) {
  11932. r += color.r * intensity * scaleFactor;
  11933. g += color.g * intensity * scaleFactor;
  11934. b += color.b * intensity * scaleFactor;
  11935. } else if ( light.isLightProbe ) {
  11936. for ( let j = 0; j < 9; j ++ ) {
  11937. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11938. }
  11939. } else if ( light.isDirectionalLight ) {
  11940. const uniforms = cache.get( light );
  11941. uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
  11942. if ( light.castShadow ) {
  11943. const shadow = light.shadow;
  11944. const shadowUniforms = shadowCache.get( light );
  11945. shadowUniforms.shadowBias = shadow.bias;
  11946. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11947. shadowUniforms.shadowRadius = shadow.radius;
  11948. shadowUniforms.shadowMapSize = shadow.mapSize;
  11949. state.directionalShadow[ directionalLength ] = shadowUniforms;
  11950. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11951. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11952. numDirectionalShadows ++;
  11953. }
  11954. state.directional[ directionalLength ] = uniforms;
  11955. directionalLength ++;
  11956. } else if ( light.isSpotLight ) {
  11957. const uniforms = cache.get( light );
  11958. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11959. uniforms.color.copy( color ).multiplyScalar( intensity * scaleFactor );
  11960. uniforms.distance = distance;
  11961. uniforms.coneCos = Math.cos( light.angle );
  11962. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11963. uniforms.decay = light.decay;
  11964. if ( light.castShadow ) {
  11965. const shadow = light.shadow;
  11966. const shadowUniforms = shadowCache.get( light );
  11967. shadowUniforms.shadowBias = shadow.bias;
  11968. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11969. shadowUniforms.shadowRadius = shadow.radius;
  11970. shadowUniforms.shadowMapSize = shadow.mapSize;
  11971. state.spotShadow[ spotLength ] = shadowUniforms;
  11972. state.spotShadowMap[ spotLength ] = shadowMap;
  11973. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11974. numSpotShadows ++;
  11975. }
  11976. state.spot[ spotLength ] = uniforms;
  11977. spotLength ++;
  11978. } else if ( light.isRectAreaLight ) {
  11979. const uniforms = cache.get( light );
  11980. // (a) intensity is the total visible light emitted
  11981. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11982. // (b) intensity is the brightness of the light
  11983. uniforms.color.copy( color ).multiplyScalar( intensity );
  11984. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11985. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11986. state.rectArea[ rectAreaLength ] = uniforms;
  11987. rectAreaLength ++;
  11988. } else if ( light.isPointLight ) {
  11989. const uniforms = cache.get( light );
  11990. uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
  11991. uniforms.distance = light.distance;
  11992. uniforms.decay = light.decay;
  11993. if ( light.castShadow ) {
  11994. const shadow = light.shadow;
  11995. const shadowUniforms = shadowCache.get( light );
  11996. shadowUniforms.shadowBias = shadow.bias;
  11997. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11998. shadowUniforms.shadowRadius = shadow.radius;
  11999. shadowUniforms.shadowMapSize = shadow.mapSize;
  12000. shadowUniforms.shadowCameraNear = shadow.camera.near;
  12001. shadowUniforms.shadowCameraFar = shadow.camera.far;
  12002. state.pointShadow[ pointLength ] = shadowUniforms;
  12003. state.pointShadowMap[ pointLength ] = shadowMap;
  12004. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  12005. numPointShadows ++;
  12006. }
  12007. state.point[ pointLength ] = uniforms;
  12008. pointLength ++;
  12009. } else if ( light.isHemisphereLight ) {
  12010. const uniforms = cache.get( light );
  12011. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity * scaleFactor );
  12012. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity * scaleFactor );
  12013. state.hemi[ hemiLength ] = uniforms;
  12014. hemiLength ++;
  12015. }
  12016. }
  12017. if ( rectAreaLength > 0 ) {
  12018. if ( capabilities.isWebGL2 ) {
  12019. // WebGL 2
  12020. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12021. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12022. } else {
  12023. // WebGL 1
  12024. if ( extensions.has( 'OES_texture_float_linear' ) === true ) {
  12025. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12026. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12027. } else if ( extensions.has( 'OES_texture_half_float_linear' ) === true ) {
  12028. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12029. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12030. } else {
  12031. console.error( 'THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.' );
  12032. }
  12033. }
  12034. }
  12035. state.ambient[ 0 ] = r;
  12036. state.ambient[ 1 ] = g;
  12037. state.ambient[ 2 ] = b;
  12038. const hash = state.hash;
  12039. if ( hash.directionalLength !== directionalLength ||
  12040. hash.pointLength !== pointLength ||
  12041. hash.spotLength !== spotLength ||
  12042. hash.rectAreaLength !== rectAreaLength ||
  12043. hash.hemiLength !== hemiLength ||
  12044. hash.numDirectionalShadows !== numDirectionalShadows ||
  12045. hash.numPointShadows !== numPointShadows ||
  12046. hash.numSpotShadows !== numSpotShadows ) {
  12047. state.directional.length = directionalLength;
  12048. state.spot.length = spotLength;
  12049. state.rectArea.length = rectAreaLength;
  12050. state.point.length = pointLength;
  12051. state.hemi.length = hemiLength;
  12052. state.directionalShadow.length = numDirectionalShadows;
  12053. state.directionalShadowMap.length = numDirectionalShadows;
  12054. state.pointShadow.length = numPointShadows;
  12055. state.pointShadowMap.length = numPointShadows;
  12056. state.spotShadow.length = numSpotShadows;
  12057. state.spotShadowMap.length = numSpotShadows;
  12058. state.directionalShadowMatrix.length = numDirectionalShadows;
  12059. state.pointShadowMatrix.length = numPointShadows;
  12060. state.spotShadowMatrix.length = numSpotShadows;
  12061. hash.directionalLength = directionalLength;
  12062. hash.pointLength = pointLength;
  12063. hash.spotLength = spotLength;
  12064. hash.rectAreaLength = rectAreaLength;
  12065. hash.hemiLength = hemiLength;
  12066. hash.numDirectionalShadows = numDirectionalShadows;
  12067. hash.numPointShadows = numPointShadows;
  12068. hash.numSpotShadows = numSpotShadows;
  12069. state.version = nextVersion ++;
  12070. }
  12071. }
  12072. function setupView( lights, camera ) {
  12073. let directionalLength = 0;
  12074. let pointLength = 0;
  12075. let spotLength = 0;
  12076. let rectAreaLength = 0;
  12077. let hemiLength = 0;
  12078. const viewMatrix = camera.matrixWorldInverse;
  12079. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  12080. const light = lights[ i ];
  12081. if ( light.isDirectionalLight ) {
  12082. const uniforms = state.directional[ directionalLength ];
  12083. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12084. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12085. uniforms.direction.sub( vector3 );
  12086. uniforms.direction.transformDirection( viewMatrix );
  12087. directionalLength ++;
  12088. } else if ( light.isSpotLight ) {
  12089. const uniforms = state.spot[ spotLength ];
  12090. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12091. uniforms.position.applyMatrix4( viewMatrix );
  12092. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12093. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12094. uniforms.direction.sub( vector3 );
  12095. uniforms.direction.transformDirection( viewMatrix );
  12096. spotLength ++;
  12097. } else if ( light.isRectAreaLight ) {
  12098. const uniforms = state.rectArea[ rectAreaLength ];
  12099. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12100. uniforms.position.applyMatrix4( viewMatrix );
  12101. // extract local rotation of light to derive width/height half vectors
  12102. matrix42.identity();
  12103. matrix4.copy( light.matrixWorld );
  12104. matrix4.premultiply( viewMatrix );
  12105. matrix42.extractRotation( matrix4 );
  12106. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  12107. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  12108. uniforms.halfWidth.applyMatrix4( matrix42 );
  12109. uniforms.halfHeight.applyMatrix4( matrix42 );
  12110. rectAreaLength ++;
  12111. } else if ( light.isPointLight ) {
  12112. const uniforms = state.point[ pointLength ];
  12113. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12114. uniforms.position.applyMatrix4( viewMatrix );
  12115. pointLength ++;
  12116. } else if ( light.isHemisphereLight ) {
  12117. const uniforms = state.hemi[ hemiLength ];
  12118. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12119. uniforms.direction.transformDirection( viewMatrix );
  12120. uniforms.direction.normalize();
  12121. hemiLength ++;
  12122. }
  12123. }
  12124. }
  12125. return {
  12126. setup: setup,
  12127. setupView: setupView,
  12128. state: state
  12129. };
  12130. }
  12131. function WebGLRenderState( extensions, capabilities ) {
  12132. const lights = new WebGLLights( extensions, capabilities );
  12133. const lightsArray = [];
  12134. const shadowsArray = [];
  12135. function init() {
  12136. lightsArray.length = 0;
  12137. shadowsArray.length = 0;
  12138. }
  12139. function pushLight( light ) {
  12140. lightsArray.push( light );
  12141. }
  12142. function pushShadow( shadowLight ) {
  12143. shadowsArray.push( shadowLight );
  12144. }
  12145. function setupLights( physicallyCorrectLights ) {
  12146. lights.setup( lightsArray, physicallyCorrectLights );
  12147. }
  12148. function setupLightsView( camera ) {
  12149. lights.setupView( lightsArray, camera );
  12150. }
  12151. const state = {
  12152. lightsArray: lightsArray,
  12153. shadowsArray: shadowsArray,
  12154. lights: lights
  12155. };
  12156. return {
  12157. init: init,
  12158. state: state,
  12159. setupLights: setupLights,
  12160. setupLightsView: setupLightsView,
  12161. pushLight: pushLight,
  12162. pushShadow: pushShadow
  12163. };
  12164. }
  12165. function WebGLRenderStates( extensions, capabilities ) {
  12166. let renderStates = new WeakMap();
  12167. function get( scene, renderCallDepth = 0 ) {
  12168. let renderState;
  12169. if ( renderStates.has( scene ) === false ) {
  12170. renderState = new WebGLRenderState( extensions, capabilities );
  12171. renderStates.set( scene, [ renderState ] );
  12172. } else {
  12173. if ( renderCallDepth >= renderStates.get( scene ).length ) {
  12174. renderState = new WebGLRenderState( extensions, capabilities );
  12175. renderStates.get( scene ).push( renderState );
  12176. } else {
  12177. renderState = renderStates.get( scene )[ renderCallDepth ];
  12178. }
  12179. }
  12180. return renderState;
  12181. }
  12182. function dispose() {
  12183. renderStates = new WeakMap();
  12184. }
  12185. return {
  12186. get: get,
  12187. dispose: dispose
  12188. };
  12189. }
  12190. /**
  12191. * parameters = {
  12192. *
  12193. * opacity: <float>,
  12194. *
  12195. * map: new THREE.Texture( <Image> ),
  12196. *
  12197. * alphaMap: new THREE.Texture( <Image> ),
  12198. *
  12199. * displacementMap: new THREE.Texture( <Image> ),
  12200. * displacementScale: <float>,
  12201. * displacementBias: <float>,
  12202. *
  12203. * wireframe: <boolean>,
  12204. * wireframeLinewidth: <float>
  12205. * }
  12206. */
  12207. class MeshDepthMaterial extends Material {
  12208. constructor( parameters ) {
  12209. super();
  12210. this.type = 'MeshDepthMaterial';
  12211. this.depthPacking = BasicDepthPacking;
  12212. this.map = null;
  12213. this.alphaMap = null;
  12214. this.displacementMap = null;
  12215. this.displacementScale = 1;
  12216. this.displacementBias = 0;
  12217. this.wireframe = false;
  12218. this.wireframeLinewidth = 1;
  12219. this.fog = false;
  12220. this.setValues( parameters );
  12221. }
  12222. copy( source ) {
  12223. super.copy( source );
  12224. this.depthPacking = source.depthPacking;
  12225. this.map = source.map;
  12226. this.alphaMap = source.alphaMap;
  12227. this.displacementMap = source.displacementMap;
  12228. this.displacementScale = source.displacementScale;
  12229. this.displacementBias = source.displacementBias;
  12230. this.wireframe = source.wireframe;
  12231. this.wireframeLinewidth = source.wireframeLinewidth;
  12232. return this;
  12233. }
  12234. }
  12235. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12236. /**
  12237. * parameters = {
  12238. *
  12239. * referencePosition: <float>,
  12240. * nearDistance: <float>,
  12241. * farDistance: <float>,
  12242. *
  12243. * map: new THREE.Texture( <Image> ),
  12244. *
  12245. * alphaMap: new THREE.Texture( <Image> ),
  12246. *
  12247. * displacementMap: new THREE.Texture( <Image> ),
  12248. * displacementScale: <float>,
  12249. * displacementBias: <float>
  12250. *
  12251. * }
  12252. */
  12253. class MeshDistanceMaterial extends Material {
  12254. constructor( parameters ) {
  12255. super();
  12256. this.type = 'MeshDistanceMaterial';
  12257. this.referencePosition = new Vector3();
  12258. this.nearDistance = 1;
  12259. this.farDistance = 1000;
  12260. this.map = null;
  12261. this.alphaMap = null;
  12262. this.displacementMap = null;
  12263. this.displacementScale = 1;
  12264. this.displacementBias = 0;
  12265. this.fog = false;
  12266. this.setValues( parameters );
  12267. }
  12268. copy( source ) {
  12269. super.copy( source );
  12270. this.referencePosition.copy( source.referencePosition );
  12271. this.nearDistance = source.nearDistance;
  12272. this.farDistance = source.farDistance;
  12273. this.map = source.map;
  12274. this.alphaMap = source.alphaMap;
  12275. this.displacementMap = source.displacementMap;
  12276. this.displacementScale = source.displacementScale;
  12277. this.displacementBias = source.displacementBias;
  12278. return this;
  12279. }
  12280. }
  12281. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12282. const vertex = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12283. const fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\nuniform float samples;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12284. function WebGLShadowMap( _renderer, _objects, _capabilities ) {
  12285. let _frustum = new Frustum();
  12286. const _shadowMapSize = new Vector2(),
  12287. _viewportSize = new Vector2(),
  12288. _viewport = new Vector4(),
  12289. _depthMaterial = new MeshDepthMaterial( { depthPacking: RGBADepthPacking } ),
  12290. _distanceMaterial = new MeshDistanceMaterial(),
  12291. _materialCache = {},
  12292. _maxTextureSize = _capabilities.maxTextureSize;
  12293. const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  12294. const shadowMaterialVertical = new ShaderMaterial( {
  12295. uniforms: {
  12296. shadow_pass: { value: null },
  12297. resolution: { value: new Vector2() },
  12298. radius: { value: 4.0 },
  12299. samples: { value: 8.0 }
  12300. },
  12301. vertexShader: vertex,
  12302. fragmentShader: fragment
  12303. } );
  12304. const shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12305. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12306. const fullScreenTri = new BufferGeometry();
  12307. fullScreenTri.setAttribute(
  12308. 'position',
  12309. new BufferAttribute(
  12310. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  12311. 3
  12312. )
  12313. );
  12314. const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  12315. const scope = this;
  12316. this.enabled = false;
  12317. this.autoUpdate = true;
  12318. this.needsUpdate = false;
  12319. this.type = PCFShadowMap;
  12320. this.render = function ( lights, scene, camera ) {
  12321. if ( scope.enabled === false ) return;
  12322. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  12323. if ( lights.length === 0 ) return;
  12324. const currentRenderTarget = _renderer.getRenderTarget();
  12325. const activeCubeFace = _renderer.getActiveCubeFace();
  12326. const activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12327. const _state = _renderer.state;
  12328. // Set GL state for depth map.
  12329. _state.setBlending( NoBlending );
  12330. _state.buffers.color.setClear( 1, 1, 1, 1 );
  12331. _state.buffers.depth.setTest( true );
  12332. _state.setScissorTest( false );
  12333. // render depth map
  12334. for ( let i = 0, il = lights.length; i < il; i ++ ) {
  12335. const light = lights[ i ];
  12336. const shadow = light.shadow;
  12337. if ( shadow === undefined ) {
  12338. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  12339. continue;
  12340. }
  12341. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;
  12342. _shadowMapSize.copy( shadow.mapSize );
  12343. const shadowFrameExtents = shadow.getFrameExtents();
  12344. _shadowMapSize.multiply( shadowFrameExtents );
  12345. _viewportSize.copy( shadow.mapSize );
  12346. if ( _shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize ) {
  12347. if ( _shadowMapSize.x > _maxTextureSize ) {
  12348. _viewportSize.x = Math.floor( _maxTextureSize / shadowFrameExtents.x );
  12349. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12350. shadow.mapSize.x = _viewportSize.x;
  12351. }
  12352. if ( _shadowMapSize.y > _maxTextureSize ) {
  12353. _viewportSize.y = Math.floor( _maxTextureSize / shadowFrameExtents.y );
  12354. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12355. shadow.mapSize.y = _viewportSize.y;
  12356. }
  12357. }
  12358. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12359. const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  12360. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12361. shadow.map.texture.name = light.name + '.shadowMap';
  12362. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12363. shadow.camera.updateProjectionMatrix();
  12364. }
  12365. if ( shadow.map === null ) {
  12366. const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  12367. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12368. shadow.map.texture.name = light.name + '.shadowMap';
  12369. shadow.camera.updateProjectionMatrix();
  12370. }
  12371. _renderer.setRenderTarget( shadow.map );
  12372. _renderer.clear();
  12373. const viewportCount = shadow.getViewportCount();
  12374. for ( let vp = 0; vp < viewportCount; vp ++ ) {
  12375. const viewport = shadow.getViewport( vp );
  12376. _viewport.set(
  12377. _viewportSize.x * viewport.x,
  12378. _viewportSize.y * viewport.y,
  12379. _viewportSize.x * viewport.z,
  12380. _viewportSize.y * viewport.w
  12381. );
  12382. _state.viewport( _viewport );
  12383. shadow.updateMatrices( light, vp );
  12384. _frustum = shadow.getFrustum();
  12385. renderObject( scene, camera, shadow.camera, light, this.type );
  12386. }
  12387. // do blur pass for VSM
  12388. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12389. VSMPass( shadow, camera );
  12390. }
  12391. shadow.needsUpdate = false;
  12392. }
  12393. scope.needsUpdate = false;
  12394. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  12395. };
  12396. function VSMPass( shadow, camera ) {
  12397. const geometry = _objects.update( fullScreenMesh );
  12398. // vertical pass
  12399. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12400. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12401. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12402. shadowMaterialVertical.uniforms.samples.value = shadow.blurSamples;
  12403. _renderer.setRenderTarget( shadow.mapPass );
  12404. _renderer.clear();
  12405. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  12406. // horizontal pass
  12407. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12408. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12409. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12410. shadowMaterialHorizontal.uniforms.samples.value = shadow.blurSamples;
  12411. _renderer.setRenderTarget( shadow.map );
  12412. _renderer.clear();
  12413. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );
  12414. }
  12415. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  12416. let result = null;
  12417. const customMaterial = ( light.isPointLight === true ) ? object.customDistanceMaterial : object.customDepthMaterial;
  12418. if ( customMaterial !== undefined ) {
  12419. result = customMaterial;
  12420. } else {
  12421. result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial;
  12422. }
  12423. if ( ( _renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0 ) ||
  12424. ( material.displacementMap && material.displacementScale !== 0 ) ||
  12425. ( material.alphaMap && material.alphaTest > 0 ) ) {
  12426. // in this case we need a unique material instance reflecting the
  12427. // appropriate state
  12428. const keyA = result.uuid, keyB = material.uuid;
  12429. let materialsForVariant = _materialCache[ keyA ];
  12430. if ( materialsForVariant === undefined ) {
  12431. materialsForVariant = {};
  12432. _materialCache[ keyA ] = materialsForVariant;
  12433. }
  12434. let cachedMaterial = materialsForVariant[ keyB ];
  12435. if ( cachedMaterial === undefined ) {
  12436. cachedMaterial = result.clone();
  12437. materialsForVariant[ keyB ] = cachedMaterial;
  12438. }
  12439. result = cachedMaterial;
  12440. }
  12441. result.visible = material.visible;
  12442. result.wireframe = material.wireframe;
  12443. if ( type === VSMShadowMap ) {
  12444. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  12445. } else {
  12446. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  12447. }
  12448. result.alphaMap = material.alphaMap;
  12449. result.alphaTest = material.alphaTest;
  12450. result.clipShadows = material.clipShadows;
  12451. result.clippingPlanes = material.clippingPlanes;
  12452. result.clipIntersection = material.clipIntersection;
  12453. result.displacementMap = material.displacementMap;
  12454. result.displacementScale = material.displacementScale;
  12455. result.displacementBias = material.displacementBias;
  12456. result.wireframeLinewidth = material.wireframeLinewidth;
  12457. result.linewidth = material.linewidth;
  12458. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  12459. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  12460. result.nearDistance = shadowCameraNear;
  12461. result.farDistance = shadowCameraFar;
  12462. }
  12463. return result;
  12464. }
  12465. function renderObject( object, camera, shadowCamera, light, type ) {
  12466. if ( object.visible === false ) return;
  12467. const visible = object.layers.test( camera.layers );
  12468. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  12469. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  12470. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  12471. const geometry = _objects.update( object );
  12472. const material = object.material;
  12473. if ( Array.isArray( material ) ) {
  12474. const groups = geometry.groups;
  12475. for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
  12476. const group = groups[ k ];
  12477. const groupMaterial = material[ group.materialIndex ];
  12478. if ( groupMaterial && groupMaterial.visible ) {
  12479. const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  12480. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  12481. }
  12482. }
  12483. } else if ( material.visible ) {
  12484. const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  12485. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  12486. }
  12487. }
  12488. }
  12489. const children = object.children;
  12490. for ( let i = 0, l = children.length; i < l; i ++ ) {
  12491. renderObject( children[ i ], camera, shadowCamera, light, type );
  12492. }
  12493. }
  12494. }
  12495. function WebGLState( gl, extensions, capabilities ) {
  12496. const isWebGL2 = capabilities.isWebGL2;
  12497. function ColorBuffer() {
  12498. let locked = false;
  12499. const color = new Vector4();
  12500. let currentColorMask = null;
  12501. const currentColorClear = new Vector4( 0, 0, 0, 0 );
  12502. return {
  12503. setMask: function ( colorMask ) {
  12504. if ( currentColorMask !== colorMask && ! locked ) {
  12505. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12506. currentColorMask = colorMask;
  12507. }
  12508. },
  12509. setLocked: function ( lock ) {
  12510. locked = lock;
  12511. },
  12512. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12513. if ( premultipliedAlpha === true ) {
  12514. r *= a; g *= a; b *= a;
  12515. }
  12516. color.set( r, g, b, a );
  12517. if ( currentColorClear.equals( color ) === false ) {
  12518. gl.clearColor( r, g, b, a );
  12519. currentColorClear.copy( color );
  12520. }
  12521. },
  12522. reset: function () {
  12523. locked = false;
  12524. currentColorMask = null;
  12525. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12526. }
  12527. };
  12528. }
  12529. function DepthBuffer() {
  12530. let locked = false;
  12531. let currentDepthMask = null;
  12532. let currentDepthFunc = null;
  12533. let currentDepthClear = null;
  12534. return {
  12535. setTest: function ( depthTest ) {
  12536. if ( depthTest ) {
  12537. enable( 2929 );
  12538. } else {
  12539. disable( 2929 );
  12540. }
  12541. },
  12542. setMask: function ( depthMask ) {
  12543. if ( currentDepthMask !== depthMask && ! locked ) {
  12544. gl.depthMask( depthMask );
  12545. currentDepthMask = depthMask;
  12546. }
  12547. },
  12548. setFunc: function ( depthFunc ) {
  12549. if ( currentDepthFunc !== depthFunc ) {
  12550. if ( depthFunc ) {
  12551. switch ( depthFunc ) {
  12552. case NeverDepth:
  12553. gl.depthFunc( 512 );
  12554. break;
  12555. case AlwaysDepth:
  12556. gl.depthFunc( 519 );
  12557. break;
  12558. case LessDepth:
  12559. gl.depthFunc( 513 );
  12560. break;
  12561. case LessEqualDepth:
  12562. gl.depthFunc( 515 );
  12563. break;
  12564. case EqualDepth:
  12565. gl.depthFunc( 514 );
  12566. break;
  12567. case GreaterEqualDepth:
  12568. gl.depthFunc( 518 );
  12569. break;
  12570. case GreaterDepth:
  12571. gl.depthFunc( 516 );
  12572. break;
  12573. case NotEqualDepth:
  12574. gl.depthFunc( 517 );
  12575. break;
  12576. default:
  12577. gl.depthFunc( 515 );
  12578. }
  12579. } else {
  12580. gl.depthFunc( 515 );
  12581. }
  12582. currentDepthFunc = depthFunc;
  12583. }
  12584. },
  12585. setLocked: function ( lock ) {
  12586. locked = lock;
  12587. },
  12588. setClear: function ( depth ) {
  12589. if ( currentDepthClear !== depth ) {
  12590. gl.clearDepth( depth );
  12591. currentDepthClear = depth;
  12592. }
  12593. },
  12594. reset: function () {
  12595. locked = false;
  12596. currentDepthMask = null;
  12597. currentDepthFunc = null;
  12598. currentDepthClear = null;
  12599. }
  12600. };
  12601. }
  12602. function StencilBuffer() {
  12603. let locked = false;
  12604. let currentStencilMask = null;
  12605. let currentStencilFunc = null;
  12606. let currentStencilRef = null;
  12607. let currentStencilFuncMask = null;
  12608. let currentStencilFail = null;
  12609. let currentStencilZFail = null;
  12610. let currentStencilZPass = null;
  12611. let currentStencilClear = null;
  12612. return {
  12613. setTest: function ( stencilTest ) {
  12614. if ( ! locked ) {
  12615. if ( stencilTest ) {
  12616. enable( 2960 );
  12617. } else {
  12618. disable( 2960 );
  12619. }
  12620. }
  12621. },
  12622. setMask: function ( stencilMask ) {
  12623. if ( currentStencilMask !== stencilMask && ! locked ) {
  12624. gl.stencilMask( stencilMask );
  12625. currentStencilMask = stencilMask;
  12626. }
  12627. },
  12628. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12629. if ( currentStencilFunc !== stencilFunc ||
  12630. currentStencilRef !== stencilRef ||
  12631. currentStencilFuncMask !== stencilMask ) {
  12632. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12633. currentStencilFunc = stencilFunc;
  12634. currentStencilRef = stencilRef;
  12635. currentStencilFuncMask = stencilMask;
  12636. }
  12637. },
  12638. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12639. if ( currentStencilFail !== stencilFail ||
  12640. currentStencilZFail !== stencilZFail ||
  12641. currentStencilZPass !== stencilZPass ) {
  12642. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12643. currentStencilFail = stencilFail;
  12644. currentStencilZFail = stencilZFail;
  12645. currentStencilZPass = stencilZPass;
  12646. }
  12647. },
  12648. setLocked: function ( lock ) {
  12649. locked = lock;
  12650. },
  12651. setClear: function ( stencil ) {
  12652. if ( currentStencilClear !== stencil ) {
  12653. gl.clearStencil( stencil );
  12654. currentStencilClear = stencil;
  12655. }
  12656. },
  12657. reset: function () {
  12658. locked = false;
  12659. currentStencilMask = null;
  12660. currentStencilFunc = null;
  12661. currentStencilRef = null;
  12662. currentStencilFuncMask = null;
  12663. currentStencilFail = null;
  12664. currentStencilZFail = null;
  12665. currentStencilZPass = null;
  12666. currentStencilClear = null;
  12667. }
  12668. };
  12669. }
  12670. //
  12671. const colorBuffer = new ColorBuffer();
  12672. const depthBuffer = new DepthBuffer();
  12673. const stencilBuffer = new StencilBuffer();
  12674. let enabledCapabilities = {};
  12675. let xrFramebuffer = null;
  12676. let currentBoundFramebuffers = {};
  12677. let currentProgram = null;
  12678. let currentBlendingEnabled = false;
  12679. let currentBlending = null;
  12680. let currentBlendEquation = null;
  12681. let currentBlendSrc = null;
  12682. let currentBlendDst = null;
  12683. let currentBlendEquationAlpha = null;
  12684. let currentBlendSrcAlpha = null;
  12685. let currentBlendDstAlpha = null;
  12686. let currentPremultipledAlpha = false;
  12687. let currentFlipSided = null;
  12688. let currentCullFace = null;
  12689. let currentLineWidth = null;
  12690. let currentPolygonOffsetFactor = null;
  12691. let currentPolygonOffsetUnits = null;
  12692. const maxTextures = gl.getParameter( 35661 );
  12693. let lineWidthAvailable = false;
  12694. let version = 0;
  12695. const glVersion = gl.getParameter( 7938 );
  12696. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12697. version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] );
  12698. lineWidthAvailable = ( version >= 1.0 );
  12699. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12700. version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] );
  12701. lineWidthAvailable = ( version >= 2.0 );
  12702. }
  12703. let currentTextureSlot = null;
  12704. let currentBoundTextures = {};
  12705. const scissorParam = gl.getParameter( 3088 );
  12706. const viewportParam = gl.getParameter( 2978 );
  12707. const currentScissor = new Vector4().fromArray( scissorParam );
  12708. const currentViewport = new Vector4().fromArray( viewportParam );
  12709. function createTexture( type, target, count ) {
  12710. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12711. const texture = gl.createTexture();
  12712. gl.bindTexture( type, texture );
  12713. gl.texParameteri( type, 10241, 9728 );
  12714. gl.texParameteri( type, 10240, 9728 );
  12715. for ( let i = 0; i < count; i ++ ) {
  12716. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12717. }
  12718. return texture;
  12719. }
  12720. const emptyTextures = {};
  12721. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12722. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12723. // init
  12724. colorBuffer.setClear( 0, 0, 0, 1 );
  12725. depthBuffer.setClear( 1 );
  12726. stencilBuffer.setClear( 0 );
  12727. enable( 2929 );
  12728. depthBuffer.setFunc( LessEqualDepth );
  12729. setFlipSided( false );
  12730. setCullFace( CullFaceBack );
  12731. enable( 2884 );
  12732. setBlending( NoBlending );
  12733. //
  12734. function enable( id ) {
  12735. if ( enabledCapabilities[ id ] !== true ) {
  12736. gl.enable( id );
  12737. enabledCapabilities[ id ] = true;
  12738. }
  12739. }
  12740. function disable( id ) {
  12741. if ( enabledCapabilities[ id ] !== false ) {
  12742. gl.disable( id );
  12743. enabledCapabilities[ id ] = false;
  12744. }
  12745. }
  12746. function bindXRFramebuffer( framebuffer ) {
  12747. if ( framebuffer !== xrFramebuffer ) {
  12748. gl.bindFramebuffer( 36160, framebuffer );
  12749. xrFramebuffer = framebuffer;
  12750. }
  12751. }
  12752. function bindFramebuffer( target, framebuffer ) {
  12753. if ( framebuffer === null && xrFramebuffer !== null ) framebuffer = xrFramebuffer; // use active XR framebuffer if available
  12754. if ( currentBoundFramebuffers[ target ] !== framebuffer ) {
  12755. gl.bindFramebuffer( target, framebuffer );
  12756. currentBoundFramebuffers[ target ] = framebuffer;
  12757. if ( isWebGL2 ) {
  12758. // 36009 is equivalent to 36160
  12759. if ( target === 36009 ) {
  12760. currentBoundFramebuffers[ 36160 ] = framebuffer;
  12761. }
  12762. if ( target === 36160 ) {
  12763. currentBoundFramebuffers[ 36009 ] = framebuffer;
  12764. }
  12765. }
  12766. return true;
  12767. }
  12768. return false;
  12769. }
  12770. function useProgram( program ) {
  12771. if ( currentProgram !== program ) {
  12772. gl.useProgram( program );
  12773. currentProgram = program;
  12774. return true;
  12775. }
  12776. return false;
  12777. }
  12778. const equationToGL = {
  12779. [ AddEquation ]: 32774,
  12780. [ SubtractEquation ]: 32778,
  12781. [ ReverseSubtractEquation ]: 32779
  12782. };
  12783. if ( isWebGL2 ) {
  12784. equationToGL[ MinEquation ] = 32775;
  12785. equationToGL[ MaxEquation ] = 32776;
  12786. } else {
  12787. const extension = extensions.get( 'EXT_blend_minmax' );
  12788. if ( extension !== null ) {
  12789. equationToGL[ MinEquation ] = extension.MIN_EXT;
  12790. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  12791. }
  12792. }
  12793. const factorToGL = {
  12794. [ ZeroFactor ]: 0,
  12795. [ OneFactor ]: 1,
  12796. [ SrcColorFactor ]: 768,
  12797. [ SrcAlphaFactor ]: 770,
  12798. [ SrcAlphaSaturateFactor ]: 776,
  12799. [ DstColorFactor ]: 774,
  12800. [ DstAlphaFactor ]: 772,
  12801. [ OneMinusSrcColorFactor ]: 769,
  12802. [ OneMinusSrcAlphaFactor ]: 771,
  12803. [ OneMinusDstColorFactor ]: 775,
  12804. [ OneMinusDstAlphaFactor ]: 773
  12805. };
  12806. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12807. if ( blending === NoBlending ) {
  12808. if ( currentBlendingEnabled === true ) {
  12809. disable( 3042 );
  12810. currentBlendingEnabled = false;
  12811. }
  12812. return;
  12813. }
  12814. if ( currentBlendingEnabled === false ) {
  12815. enable( 3042 );
  12816. currentBlendingEnabled = true;
  12817. }
  12818. if ( blending !== CustomBlending ) {
  12819. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12820. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12821. gl.blendEquation( 32774 );
  12822. currentBlendEquation = AddEquation;
  12823. currentBlendEquationAlpha = AddEquation;
  12824. }
  12825. if ( premultipliedAlpha ) {
  12826. switch ( blending ) {
  12827. case NormalBlending:
  12828. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12829. break;
  12830. case AdditiveBlending:
  12831. gl.blendFunc( 1, 1 );
  12832. break;
  12833. case SubtractiveBlending:
  12834. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12835. break;
  12836. case MultiplyBlending:
  12837. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12838. break;
  12839. default:
  12840. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12841. break;
  12842. }
  12843. } else {
  12844. switch ( blending ) {
  12845. case NormalBlending:
  12846. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12847. break;
  12848. case AdditiveBlending:
  12849. gl.blendFunc( 770, 1 );
  12850. break;
  12851. case SubtractiveBlending:
  12852. gl.blendFunc( 0, 769 );
  12853. break;
  12854. case MultiplyBlending:
  12855. gl.blendFunc( 0, 768 );
  12856. break;
  12857. default:
  12858. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12859. break;
  12860. }
  12861. }
  12862. currentBlendSrc = null;
  12863. currentBlendDst = null;
  12864. currentBlendSrcAlpha = null;
  12865. currentBlendDstAlpha = null;
  12866. currentBlending = blending;
  12867. currentPremultipledAlpha = premultipliedAlpha;
  12868. }
  12869. return;
  12870. }
  12871. // custom blending
  12872. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12873. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12874. blendDstAlpha = blendDstAlpha || blendDst;
  12875. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12876. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12877. currentBlendEquation = blendEquation;
  12878. currentBlendEquationAlpha = blendEquationAlpha;
  12879. }
  12880. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12881. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  12882. currentBlendSrc = blendSrc;
  12883. currentBlendDst = blendDst;
  12884. currentBlendSrcAlpha = blendSrcAlpha;
  12885. currentBlendDstAlpha = blendDstAlpha;
  12886. }
  12887. currentBlending = blending;
  12888. currentPremultipledAlpha = null;
  12889. }
  12890. function setMaterial( material, frontFaceCW ) {
  12891. material.side === DoubleSide
  12892. ? disable( 2884 )
  12893. : enable( 2884 );
  12894. let flipSided = ( material.side === BackSide );
  12895. if ( frontFaceCW ) flipSided = ! flipSided;
  12896. setFlipSided( flipSided );
  12897. ( material.blending === NormalBlending && material.transparent === false )
  12898. ? setBlending( NoBlending )
  12899. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12900. depthBuffer.setFunc( material.depthFunc );
  12901. depthBuffer.setTest( material.depthTest );
  12902. depthBuffer.setMask( material.depthWrite );
  12903. colorBuffer.setMask( material.colorWrite );
  12904. const stencilWrite = material.stencilWrite;
  12905. stencilBuffer.setTest( stencilWrite );
  12906. if ( stencilWrite ) {
  12907. stencilBuffer.setMask( material.stencilWriteMask );
  12908. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  12909. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12910. }
  12911. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12912. material.alphaToCoverage === true
  12913. ? enable( 32926 )
  12914. : disable( 32926 );
  12915. }
  12916. //
  12917. function setFlipSided( flipSided ) {
  12918. if ( currentFlipSided !== flipSided ) {
  12919. if ( flipSided ) {
  12920. gl.frontFace( 2304 );
  12921. } else {
  12922. gl.frontFace( 2305 );
  12923. }
  12924. currentFlipSided = flipSided;
  12925. }
  12926. }
  12927. function setCullFace( cullFace ) {
  12928. if ( cullFace !== CullFaceNone ) {
  12929. enable( 2884 );
  12930. if ( cullFace !== currentCullFace ) {
  12931. if ( cullFace === CullFaceBack ) {
  12932. gl.cullFace( 1029 );
  12933. } else if ( cullFace === CullFaceFront ) {
  12934. gl.cullFace( 1028 );
  12935. } else {
  12936. gl.cullFace( 1032 );
  12937. }
  12938. }
  12939. } else {
  12940. disable( 2884 );
  12941. }
  12942. currentCullFace = cullFace;
  12943. }
  12944. function setLineWidth( width ) {
  12945. if ( width !== currentLineWidth ) {
  12946. if ( lineWidthAvailable ) gl.lineWidth( width );
  12947. currentLineWidth = width;
  12948. }
  12949. }
  12950. function setPolygonOffset( polygonOffset, factor, units ) {
  12951. if ( polygonOffset ) {
  12952. enable( 32823 );
  12953. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12954. gl.polygonOffset( factor, units );
  12955. currentPolygonOffsetFactor = factor;
  12956. currentPolygonOffsetUnits = units;
  12957. }
  12958. } else {
  12959. disable( 32823 );
  12960. }
  12961. }
  12962. function setScissorTest( scissorTest ) {
  12963. if ( scissorTest ) {
  12964. enable( 3089 );
  12965. } else {
  12966. disable( 3089 );
  12967. }
  12968. }
  12969. // texture
  12970. function activeTexture( webglSlot ) {
  12971. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12972. if ( currentTextureSlot !== webglSlot ) {
  12973. gl.activeTexture( webglSlot );
  12974. currentTextureSlot = webglSlot;
  12975. }
  12976. }
  12977. function bindTexture( webglType, webglTexture ) {
  12978. if ( currentTextureSlot === null ) {
  12979. activeTexture();
  12980. }
  12981. let boundTexture = currentBoundTextures[ currentTextureSlot ];
  12982. if ( boundTexture === undefined ) {
  12983. boundTexture = { type: undefined, texture: undefined };
  12984. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12985. }
  12986. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12987. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12988. boundTexture.type = webglType;
  12989. boundTexture.texture = webglTexture;
  12990. }
  12991. }
  12992. function unbindTexture() {
  12993. const boundTexture = currentBoundTextures[ currentTextureSlot ];
  12994. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  12995. gl.bindTexture( boundTexture.type, null );
  12996. boundTexture.type = undefined;
  12997. boundTexture.texture = undefined;
  12998. }
  12999. }
  13000. function compressedTexImage2D() {
  13001. try {
  13002. gl.compressedTexImage2D.apply( gl, arguments );
  13003. } catch ( error ) {
  13004. console.error( 'THREE.WebGLState:', error );
  13005. }
  13006. }
  13007. function texImage2D() {
  13008. try {
  13009. gl.texImage2D.apply( gl, arguments );
  13010. } catch ( error ) {
  13011. console.error( 'THREE.WebGLState:', error );
  13012. }
  13013. }
  13014. function texImage3D() {
  13015. try {
  13016. gl.texImage3D.apply( gl, arguments );
  13017. } catch ( error ) {
  13018. console.error( 'THREE.WebGLState:', error );
  13019. }
  13020. }
  13021. //
  13022. function scissor( scissor ) {
  13023. if ( currentScissor.equals( scissor ) === false ) {
  13024. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  13025. currentScissor.copy( scissor );
  13026. }
  13027. }
  13028. function viewport( viewport ) {
  13029. if ( currentViewport.equals( viewport ) === false ) {
  13030. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  13031. currentViewport.copy( viewport );
  13032. }
  13033. }
  13034. //
  13035. function reset() {
  13036. // reset state
  13037. gl.disable( 3042 );
  13038. gl.disable( 2884 );
  13039. gl.disable( 2929 );
  13040. gl.disable( 32823 );
  13041. gl.disable( 3089 );
  13042. gl.disable( 2960 );
  13043. gl.disable( 32926 );
  13044. gl.blendEquation( 32774 );
  13045. gl.blendFunc( 1, 0 );
  13046. gl.blendFuncSeparate( 1, 0, 1, 0 );
  13047. gl.colorMask( true, true, true, true );
  13048. gl.clearColor( 0, 0, 0, 0 );
  13049. gl.depthMask( true );
  13050. gl.depthFunc( 513 );
  13051. gl.clearDepth( 1 );
  13052. gl.stencilMask( 0xffffffff );
  13053. gl.stencilFunc( 519, 0, 0xffffffff );
  13054. gl.stencilOp( 7680, 7680, 7680 );
  13055. gl.clearStencil( 0 );
  13056. gl.cullFace( 1029 );
  13057. gl.frontFace( 2305 );
  13058. gl.polygonOffset( 0, 0 );
  13059. gl.activeTexture( 33984 );
  13060. gl.bindFramebuffer( 36160, null );
  13061. if ( isWebGL2 === true ) {
  13062. gl.bindFramebuffer( 36009, null );
  13063. gl.bindFramebuffer( 36008, null );
  13064. }
  13065. gl.useProgram( null );
  13066. gl.lineWidth( 1 );
  13067. gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
  13068. gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );
  13069. // reset internals
  13070. enabledCapabilities = {};
  13071. currentTextureSlot = null;
  13072. currentBoundTextures = {};
  13073. xrFramebuffer = null;
  13074. currentBoundFramebuffers = {};
  13075. currentProgram = null;
  13076. currentBlendingEnabled = false;
  13077. currentBlending = null;
  13078. currentBlendEquation = null;
  13079. currentBlendSrc = null;
  13080. currentBlendDst = null;
  13081. currentBlendEquationAlpha = null;
  13082. currentBlendSrcAlpha = null;
  13083. currentBlendDstAlpha = null;
  13084. currentPremultipledAlpha = false;
  13085. currentFlipSided = null;
  13086. currentCullFace = null;
  13087. currentLineWidth = null;
  13088. currentPolygonOffsetFactor = null;
  13089. currentPolygonOffsetUnits = null;
  13090. currentScissor.set( 0, 0, gl.canvas.width, gl.canvas.height );
  13091. currentViewport.set( 0, 0, gl.canvas.width, gl.canvas.height );
  13092. colorBuffer.reset();
  13093. depthBuffer.reset();
  13094. stencilBuffer.reset();
  13095. }
  13096. return {
  13097. buffers: {
  13098. color: colorBuffer,
  13099. depth: depthBuffer,
  13100. stencil: stencilBuffer
  13101. },
  13102. enable: enable,
  13103. disable: disable,
  13104. bindFramebuffer: bindFramebuffer,
  13105. bindXRFramebuffer: bindXRFramebuffer,
  13106. useProgram: useProgram,
  13107. setBlending: setBlending,
  13108. setMaterial: setMaterial,
  13109. setFlipSided: setFlipSided,
  13110. setCullFace: setCullFace,
  13111. setLineWidth: setLineWidth,
  13112. setPolygonOffset: setPolygonOffset,
  13113. setScissorTest: setScissorTest,
  13114. activeTexture: activeTexture,
  13115. bindTexture: bindTexture,
  13116. unbindTexture: unbindTexture,
  13117. compressedTexImage2D: compressedTexImage2D,
  13118. texImage2D: texImage2D,
  13119. texImage3D: texImage3D,
  13120. scissor: scissor,
  13121. viewport: viewport,
  13122. reset: reset
  13123. };
  13124. }
  13125. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  13126. const isWebGL2 = capabilities.isWebGL2;
  13127. const maxTextures = capabilities.maxTextures;
  13128. const maxCubemapSize = capabilities.maxCubemapSize;
  13129. const maxTextureSize = capabilities.maxTextureSize;
  13130. const maxSamples = capabilities.maxSamples;
  13131. const _videoTextures = new WeakMap();
  13132. let _canvas;
  13133. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13134. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13135. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13136. let useOffscreenCanvas = false;
  13137. try {
  13138. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  13139. && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;
  13140. } catch ( err ) {
  13141. // Ignore any errors
  13142. }
  13143. function createCanvas( width, height ) {
  13144. // Use OffscreenCanvas when available. Specially needed in web workers
  13145. return useOffscreenCanvas ?
  13146. new OffscreenCanvas( width, height ) : createElementNS( 'canvas' );
  13147. }
  13148. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  13149. let scale = 1;
  13150. // handle case if texture exceeds max size
  13151. if ( image.width > maxSize || image.height > maxSize ) {
  13152. scale = maxSize / Math.max( image.width, image.height );
  13153. }
  13154. // only perform resize if necessary
  13155. if ( scale < 1 || needsPowerOfTwo === true ) {
  13156. // only perform resize for certain image types
  13157. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  13158. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  13159. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  13160. const floor = needsPowerOfTwo ? floorPowerOfTwo : Math.floor;
  13161. const width = floor( scale * image.width );
  13162. const height = floor( scale * image.height );
  13163. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  13164. // cube textures can't reuse the same canvas
  13165. const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  13166. canvas.width = width;
  13167. canvas.height = height;
  13168. const context = canvas.getContext( '2d' );
  13169. context.drawImage( image, 0, 0, width, height );
  13170. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  13171. return canvas;
  13172. } else {
  13173. if ( 'data' in image ) {
  13174. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  13175. }
  13176. return image;
  13177. }
  13178. }
  13179. return image;
  13180. }
  13181. function isPowerOfTwo$1( image ) {
  13182. return isPowerOfTwo( image.width ) && isPowerOfTwo( image.height );
  13183. }
  13184. function textureNeedsPowerOfTwo( texture ) {
  13185. if ( isWebGL2 ) return false;
  13186. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  13187. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  13188. }
  13189. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  13190. return texture.generateMipmaps && supportsMips &&
  13191. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13192. }
  13193. function generateMipmap( target, texture, width, height, depth = 1 ) {
  13194. _gl.generateMipmap( target );
  13195. const textureProperties = properties.get( texture );
  13196. textureProperties.__maxMipLevel = Math.log2( Math.max( width, height, depth ) );
  13197. }
  13198. function getInternalFormat( internalFormatName, glFormat, glType ) {
  13199. if ( isWebGL2 === false ) return glFormat;
  13200. if ( internalFormatName !== null ) {
  13201. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  13202. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  13203. }
  13204. let internalFormat = glFormat;
  13205. if ( glFormat === 6403 ) {
  13206. if ( glType === 5126 ) internalFormat = 33326;
  13207. if ( glType === 5131 ) internalFormat = 33325;
  13208. if ( glType === 5121 ) internalFormat = 33321;
  13209. }
  13210. if ( glFormat === 6407 ) {
  13211. if ( glType === 5126 ) internalFormat = 34837;
  13212. if ( glType === 5131 ) internalFormat = 34843;
  13213. if ( glType === 5121 ) internalFormat = 32849;
  13214. }
  13215. if ( glFormat === 6408 ) {
  13216. if ( glType === 5126 ) internalFormat = 34836;
  13217. if ( glType === 5131 ) internalFormat = 34842;
  13218. if ( glType === 5121 ) internalFormat = 32856;
  13219. }
  13220. if ( internalFormat === 33325 || internalFormat === 33326 ||
  13221. internalFormat === 34842 || internalFormat === 34836 ) {
  13222. extensions.get( 'EXT_color_buffer_float' );
  13223. }
  13224. return internalFormat;
  13225. }
  13226. // Fallback filters for non-power-of-2 textures
  13227. function filterFallback( f ) {
  13228. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  13229. return 9728;
  13230. }
  13231. return 9729;
  13232. }
  13233. //
  13234. function onTextureDispose( event ) {
  13235. const texture = event.target;
  13236. texture.removeEventListener( 'dispose', onTextureDispose );
  13237. deallocateTexture( texture );
  13238. if ( texture.isVideoTexture ) {
  13239. _videoTextures.delete( texture );
  13240. }
  13241. info.memory.textures --;
  13242. }
  13243. function onRenderTargetDispose( event ) {
  13244. const renderTarget = event.target;
  13245. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13246. deallocateRenderTarget( renderTarget );
  13247. }
  13248. //
  13249. function deallocateTexture( texture ) {
  13250. const textureProperties = properties.get( texture );
  13251. if ( textureProperties.__webglInit === undefined ) return;
  13252. _gl.deleteTexture( textureProperties.__webglTexture );
  13253. properties.remove( texture );
  13254. }
  13255. function deallocateRenderTarget( renderTarget ) {
  13256. const texture = renderTarget.texture;
  13257. const renderTargetProperties = properties.get( renderTarget );
  13258. const textureProperties = properties.get( texture );
  13259. if ( ! renderTarget ) return;
  13260. if ( textureProperties.__webglTexture !== undefined ) {
  13261. _gl.deleteTexture( textureProperties.__webglTexture );
  13262. info.memory.textures --;
  13263. }
  13264. if ( renderTarget.depthTexture ) {
  13265. renderTarget.depthTexture.dispose();
  13266. }
  13267. if ( renderTarget.isWebGLCubeRenderTarget ) {
  13268. for ( let i = 0; i < 6; i ++ ) {
  13269. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13270. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  13271. }
  13272. } else {
  13273. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13274. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  13275. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  13276. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  13277. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  13278. }
  13279. if ( renderTarget.isWebGLMultipleRenderTargets ) {
  13280. for ( let i = 0, il = texture.length; i < il; i ++ ) {
  13281. const attachmentProperties = properties.get( texture[ i ] );
  13282. if ( attachmentProperties.__webglTexture ) {
  13283. _gl.deleteTexture( attachmentProperties.__webglTexture );
  13284. info.memory.textures --;
  13285. }
  13286. properties.remove( texture[ i ] );
  13287. }
  13288. }
  13289. properties.remove( texture );
  13290. properties.remove( renderTarget );
  13291. }
  13292. //
  13293. let textureUnits = 0;
  13294. function resetTextureUnits() {
  13295. textureUnits = 0;
  13296. }
  13297. function allocateTextureUnit() {
  13298. const textureUnit = textureUnits;
  13299. if ( textureUnit >= maxTextures ) {
  13300. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  13301. }
  13302. textureUnits += 1;
  13303. return textureUnit;
  13304. }
  13305. //
  13306. function setTexture2D( texture, slot ) {
  13307. const textureProperties = properties.get( texture );
  13308. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  13309. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13310. const image = texture.image;
  13311. if ( image === undefined ) {
  13312. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  13313. } else if ( image.complete === false ) {
  13314. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  13315. } else {
  13316. uploadTexture( textureProperties, texture, slot );
  13317. return;
  13318. }
  13319. }
  13320. state.activeTexture( 33984 + slot );
  13321. state.bindTexture( 3553, textureProperties.__webglTexture );
  13322. }
  13323. function setTexture2DArray( texture, slot ) {
  13324. const textureProperties = properties.get( texture );
  13325. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13326. uploadTexture( textureProperties, texture, slot );
  13327. return;
  13328. }
  13329. state.activeTexture( 33984 + slot );
  13330. state.bindTexture( 35866, textureProperties.__webglTexture );
  13331. }
  13332. function setTexture3D( texture, slot ) {
  13333. const textureProperties = properties.get( texture );
  13334. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13335. uploadTexture( textureProperties, texture, slot );
  13336. return;
  13337. }
  13338. state.activeTexture( 33984 + slot );
  13339. state.bindTexture( 32879, textureProperties.__webglTexture );
  13340. }
  13341. function setTextureCube( texture, slot ) {
  13342. const textureProperties = properties.get( texture );
  13343. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13344. uploadCubeTexture( textureProperties, texture, slot );
  13345. return;
  13346. }
  13347. state.activeTexture( 33984 + slot );
  13348. state.bindTexture( 34067, textureProperties.__webglTexture );
  13349. }
  13350. const wrappingToGL = {
  13351. [ RepeatWrapping ]: 10497,
  13352. [ ClampToEdgeWrapping ]: 33071,
  13353. [ MirroredRepeatWrapping ]: 33648
  13354. };
  13355. const filterToGL = {
  13356. [ NearestFilter ]: 9728,
  13357. [ NearestMipmapNearestFilter ]: 9984,
  13358. [ NearestMipmapLinearFilter ]: 9986,
  13359. [ LinearFilter ]: 9729,
  13360. [ LinearMipmapNearestFilter ]: 9985,
  13361. [ LinearMipmapLinearFilter ]: 9987
  13362. };
  13363. function setTextureParameters( textureType, texture, supportsMips ) {
  13364. if ( supportsMips ) {
  13365. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  13366. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  13367. if ( textureType === 32879 || textureType === 35866 ) {
  13368. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  13369. }
  13370. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  13371. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  13372. } else {
  13373. _gl.texParameteri( textureType, 10242, 33071 );
  13374. _gl.texParameteri( textureType, 10243, 33071 );
  13375. if ( textureType === 32879 || textureType === 35866 ) {
  13376. _gl.texParameteri( textureType, 32882, 33071 );
  13377. }
  13378. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  13379. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  13380. }
  13381. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  13382. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  13383. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  13384. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  13385. }
  13386. }
  13387. if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
  13388. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13389. if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
  13390. if ( isWebGL2 === false && ( texture.type === HalfFloatType && extensions.has( 'OES_texture_half_float_linear' ) === false ) ) return; // verify extension for WebGL 1 only
  13391. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13392. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  13393. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13394. }
  13395. }
  13396. }
  13397. function initTexture( textureProperties, texture ) {
  13398. if ( textureProperties.__webglInit === undefined ) {
  13399. textureProperties.__webglInit = true;
  13400. texture.addEventListener( 'dispose', onTextureDispose );
  13401. textureProperties.__webglTexture = _gl.createTexture();
  13402. info.memory.textures ++;
  13403. }
  13404. }
  13405. function uploadTexture( textureProperties, texture, slot ) {
  13406. let textureType = 3553;
  13407. if ( texture.isDataTexture2DArray ) textureType = 35866;
  13408. if ( texture.isDataTexture3D ) textureType = 32879;
  13409. initTexture( textureProperties, texture );
  13410. state.activeTexture( 33984 + slot );
  13411. state.bindTexture( textureType, textureProperties.__webglTexture );
  13412. _gl.pixelStorei( 37440, texture.flipY );
  13413. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13414. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13415. _gl.pixelStorei( 37443, 0 );
  13416. const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo$1( texture.image ) === false;
  13417. const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  13418. const supportsMips = isPowerOfTwo$1( image ) || isWebGL2,
  13419. glFormat = utils.convert( texture.format );
  13420. let glType = utils.convert( texture.type ),
  13421. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13422. setTextureParameters( textureType, texture, supportsMips );
  13423. let mipmap;
  13424. const mipmaps = texture.mipmaps;
  13425. if ( texture.isDepthTexture ) {
  13426. // populate depth texture with dummy data
  13427. glInternalFormat = 6402;
  13428. if ( isWebGL2 ) {
  13429. if ( texture.type === FloatType ) {
  13430. glInternalFormat = 36012;
  13431. } else if ( texture.type === UnsignedIntType ) {
  13432. glInternalFormat = 33190;
  13433. } else if ( texture.type === UnsignedInt248Type ) {
  13434. glInternalFormat = 35056;
  13435. } else {
  13436. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13437. }
  13438. } else {
  13439. if ( texture.type === FloatType ) {
  13440. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  13441. }
  13442. }
  13443. // validation checks for WebGL 1
  13444. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  13445. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13446. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13447. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13448. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  13449. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  13450. texture.type = UnsignedShortType;
  13451. glType = utils.convert( texture.type );
  13452. }
  13453. }
  13454. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  13455. // Depth stencil textures need the DEPTH_STENCIL internal format
  13456. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13457. glInternalFormat = 34041;
  13458. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13459. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13460. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13461. if ( texture.type !== UnsignedInt248Type ) {
  13462. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  13463. texture.type = UnsignedInt248Type;
  13464. glType = utils.convert( texture.type );
  13465. }
  13466. }
  13467. //
  13468. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  13469. } else if ( texture.isDataTexture ) {
  13470. // use manually created mipmaps if available
  13471. // if there are no manual mipmaps
  13472. // set 0 level mipmap and then use GL to generate other mipmap levels
  13473. if ( mipmaps.length > 0 && supportsMips ) {
  13474. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13475. mipmap = mipmaps[ i ];
  13476. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13477. }
  13478. texture.generateMipmaps = false;
  13479. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13480. } else {
  13481. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13482. textureProperties.__maxMipLevel = 0;
  13483. }
  13484. } else if ( texture.isCompressedTexture ) {
  13485. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13486. mipmap = mipmaps[ i ];
  13487. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13488. if ( glFormat !== null ) {
  13489. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13490. } else {
  13491. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13492. }
  13493. } else {
  13494. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13495. }
  13496. }
  13497. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13498. } else if ( texture.isDataTexture2DArray ) {
  13499. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13500. textureProperties.__maxMipLevel = 0;
  13501. } else if ( texture.isDataTexture3D ) {
  13502. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13503. textureProperties.__maxMipLevel = 0;
  13504. } else {
  13505. // regular Texture (image, video, canvas)
  13506. // use manually created mipmaps if available
  13507. // if there are no manual mipmaps
  13508. // set 0 level mipmap and then use GL to generate other mipmap levels
  13509. if ( mipmaps.length > 0 && supportsMips ) {
  13510. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13511. mipmap = mipmaps[ i ];
  13512. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  13513. }
  13514. texture.generateMipmaps = false;
  13515. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13516. } else {
  13517. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13518. textureProperties.__maxMipLevel = 0;
  13519. }
  13520. }
  13521. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13522. generateMipmap( textureType, texture, image.width, image.height );
  13523. }
  13524. textureProperties.__version = texture.version;
  13525. if ( texture.onUpdate ) texture.onUpdate( texture );
  13526. }
  13527. function uploadCubeTexture( textureProperties, texture, slot ) {
  13528. if ( texture.image.length !== 6 ) return;
  13529. initTexture( textureProperties, texture );
  13530. state.activeTexture( 33984 + slot );
  13531. state.bindTexture( 34067, textureProperties.__webglTexture );
  13532. _gl.pixelStorei( 37440, texture.flipY );
  13533. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13534. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13535. _gl.pixelStorei( 37443, 0 );
  13536. const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  13537. const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  13538. const cubeImage = [];
  13539. for ( let i = 0; i < 6; i ++ ) {
  13540. if ( ! isCompressed && ! isDataTexture ) {
  13541. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  13542. } else {
  13543. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13544. }
  13545. }
  13546. const image = cubeImage[ 0 ],
  13547. supportsMips = isPowerOfTwo$1( image ) || isWebGL2,
  13548. glFormat = utils.convert( texture.format ),
  13549. glType = utils.convert( texture.type ),
  13550. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13551. setTextureParameters( 34067, texture, supportsMips );
  13552. let mipmaps;
  13553. if ( isCompressed ) {
  13554. for ( let i = 0; i < 6; i ++ ) {
  13555. mipmaps = cubeImage[ i ].mipmaps;
  13556. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13557. const mipmap = mipmaps[ j ];
  13558. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13559. if ( glFormat !== null ) {
  13560. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13561. } else {
  13562. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  13563. }
  13564. } else {
  13565. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13566. }
  13567. }
  13568. }
  13569. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13570. } else {
  13571. mipmaps = texture.mipmaps;
  13572. for ( let i = 0; i < 6; i ++ ) {
  13573. if ( isDataTexture ) {
  13574. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13575. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13576. const mipmap = mipmaps[ j ];
  13577. const mipmapImage = mipmap.image[ i ].image;
  13578. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  13579. }
  13580. } else {
  13581. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  13582. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13583. const mipmap = mipmaps[ j ];
  13584. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  13585. }
  13586. }
  13587. }
  13588. textureProperties.__maxMipLevel = mipmaps.length;
  13589. }
  13590. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13591. // We assume images for cube map have the same size.
  13592. generateMipmap( 34067, texture, image.width, image.height );
  13593. }
  13594. textureProperties.__version = texture.version;
  13595. if ( texture.onUpdate ) texture.onUpdate( texture );
  13596. }
  13597. // Render targets
  13598. // Setup storage for target texture and bind it to correct framebuffer
  13599. function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget ) {
  13600. const glFormat = utils.convert( texture.format );
  13601. const glType = utils.convert( texture.type );
  13602. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13603. if ( textureTarget === 32879 || textureTarget === 35866 ) {
  13604. state.texImage3D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null );
  13605. } else {
  13606. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13607. }
  13608. state.bindFramebuffer( 36160, framebuffer );
  13609. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( texture ).__webglTexture, 0 );
  13610. state.bindFramebuffer( 36160, null );
  13611. }
  13612. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13613. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13614. _gl.bindRenderbuffer( 36161, renderbuffer );
  13615. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13616. let glInternalFormat = 33189;
  13617. if ( isMultisample ) {
  13618. const depthTexture = renderTarget.depthTexture;
  13619. if ( depthTexture && depthTexture.isDepthTexture ) {
  13620. if ( depthTexture.type === FloatType ) {
  13621. glInternalFormat = 36012;
  13622. } else if ( depthTexture.type === UnsignedIntType ) {
  13623. glInternalFormat = 33190;
  13624. }
  13625. }
  13626. const samples = getRenderTargetSamples( renderTarget );
  13627. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13628. } else {
  13629. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13630. }
  13631. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13632. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13633. if ( isMultisample ) {
  13634. const samples = getRenderTargetSamples( renderTarget );
  13635. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  13636. } else {
  13637. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13638. }
  13639. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13640. } else {
  13641. // Use the first texture for MRT so far
  13642. const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[ 0 ] : renderTarget.texture;
  13643. const glFormat = utils.convert( texture.format );
  13644. const glType = utils.convert( texture.type );
  13645. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13646. if ( isMultisample ) {
  13647. const samples = getRenderTargetSamples( renderTarget );
  13648. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13649. } else {
  13650. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13651. }
  13652. }
  13653. _gl.bindRenderbuffer( 36161, null );
  13654. }
  13655. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13656. function setupDepthTexture( framebuffer, renderTarget ) {
  13657. const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  13658. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13659. state.bindFramebuffer( 36160, framebuffer );
  13660. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13661. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13662. }
  13663. // upload an empty depth texture with framebuffer size
  13664. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13665. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13666. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13667. renderTarget.depthTexture.image.width = renderTarget.width;
  13668. renderTarget.depthTexture.image.height = renderTarget.height;
  13669. renderTarget.depthTexture.needsUpdate = true;
  13670. }
  13671. setTexture2D( renderTarget.depthTexture, 0 );
  13672. const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13673. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13674. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13675. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13676. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13677. } else {
  13678. throw new Error( 'Unknown depthTexture format' );
  13679. }
  13680. }
  13681. // Setup GL resources for a non-texture depth buffer
  13682. function setupDepthRenderbuffer( renderTarget ) {
  13683. const renderTargetProperties = properties.get( renderTarget );
  13684. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13685. if ( renderTarget.depthTexture ) {
  13686. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13687. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13688. } else {
  13689. if ( isCube ) {
  13690. renderTargetProperties.__webglDepthbuffer = [];
  13691. for ( let i = 0; i < 6; i ++ ) {
  13692. state.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13693. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13694. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  13695. }
  13696. } else {
  13697. state.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13698. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13699. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  13700. }
  13701. }
  13702. state.bindFramebuffer( 36160, null );
  13703. }
  13704. // Set up GL resources for the render target
  13705. function setupRenderTarget( renderTarget ) {
  13706. const texture = renderTarget.texture;
  13707. const renderTargetProperties = properties.get( renderTarget );
  13708. const textureProperties = properties.get( texture );
  13709. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13710. if ( renderTarget.isWebGLMultipleRenderTargets !== true ) {
  13711. textureProperties.__webglTexture = _gl.createTexture();
  13712. textureProperties.__version = texture.version;
  13713. info.memory.textures ++;
  13714. }
  13715. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13716. const isMultipleRenderTargets = ( renderTarget.isWebGLMultipleRenderTargets === true );
  13717. const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13718. const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13719. const supportsMips = isPowerOfTwo$1( renderTarget ) || isWebGL2;
  13720. // Handles WebGL2 RGBFormat fallback - #18858
  13721. if ( isWebGL2 && texture.format === RGBFormat && ( texture.type === FloatType || texture.type === HalfFloatType ) ) {
  13722. texture.format = RGBAFormat;
  13723. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  13724. }
  13725. // Setup framebuffer
  13726. if ( isCube ) {
  13727. renderTargetProperties.__webglFramebuffer = [];
  13728. for ( let i = 0; i < 6; i ++ ) {
  13729. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13730. }
  13731. } else {
  13732. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13733. if ( isMultipleRenderTargets ) {
  13734. if ( capabilities.drawBuffers ) {
  13735. const textures = renderTarget.texture;
  13736. for ( let i = 0, il = textures.length; i < il; i ++ ) {
  13737. const attachmentProperties = properties.get( textures[ i ] );
  13738. if ( attachmentProperties.__webglTexture === undefined ) {
  13739. attachmentProperties.__webglTexture = _gl.createTexture();
  13740. info.memory.textures ++;
  13741. }
  13742. }
  13743. } else {
  13744. console.warn( 'THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension.' );
  13745. }
  13746. } else if ( isMultisample ) {
  13747. if ( isWebGL2 ) {
  13748. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13749. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13750. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13751. const glFormat = utils.convert( texture.format );
  13752. const glType = utils.convert( texture.type );
  13753. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13754. const samples = getRenderTargetSamples( renderTarget );
  13755. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13756. state.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13757. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13758. _gl.bindRenderbuffer( 36161, null );
  13759. if ( renderTarget.depthBuffer ) {
  13760. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13761. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13762. }
  13763. state.bindFramebuffer( 36160, null );
  13764. } else {
  13765. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13766. }
  13767. }
  13768. }
  13769. // Setup color buffer
  13770. if ( isCube ) {
  13771. state.bindTexture( 34067, textureProperties.__webglTexture );
  13772. setTextureParameters( 34067, texture, supportsMips );
  13773. for ( let i = 0; i < 6; i ++ ) {
  13774. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, texture, 36064, 34069 + i );
  13775. }
  13776. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13777. generateMipmap( 34067, texture, renderTarget.width, renderTarget.height );
  13778. }
  13779. state.unbindTexture();
  13780. } else if ( isMultipleRenderTargets ) {
  13781. const textures = renderTarget.texture;
  13782. for ( let i = 0, il = textures.length; i < il; i ++ ) {
  13783. const attachment = textures[ i ];
  13784. const attachmentProperties = properties.get( attachment );
  13785. state.bindTexture( 3553, attachmentProperties.__webglTexture );
  13786. setTextureParameters( 3553, attachment, supportsMips );
  13787. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, attachment, 36064 + i, 3553 );
  13788. if ( textureNeedsGenerateMipmaps( attachment, supportsMips ) ) {
  13789. generateMipmap( 3553, attachment, renderTarget.width, renderTarget.height );
  13790. }
  13791. }
  13792. state.unbindTexture();
  13793. } else {
  13794. let glTextureType = 3553;
  13795. if ( isRenderTarget3D ) {
  13796. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13797. if ( isWebGL2 ) {
  13798. const isTexture3D = texture.isDataTexture3D;
  13799. glTextureType = isTexture3D ? 32879 : 35866;
  13800. } else {
  13801. console.warn( 'THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.' );
  13802. }
  13803. }
  13804. state.bindTexture( glTextureType, textureProperties.__webglTexture );
  13805. setTextureParameters( glTextureType, texture, supportsMips );
  13806. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, texture, 36064, glTextureType );
  13807. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13808. generateMipmap( glTextureType, texture, renderTarget.width, renderTarget.height, renderTarget.depth );
  13809. }
  13810. state.unbindTexture();
  13811. }
  13812. // Setup depth and stencil buffers
  13813. if ( renderTarget.depthBuffer ) {
  13814. setupDepthRenderbuffer( renderTarget );
  13815. }
  13816. }
  13817. function updateRenderTargetMipmap( renderTarget ) {
  13818. const supportsMips = isPowerOfTwo$1( renderTarget ) || isWebGL2;
  13819. const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [ renderTarget.texture ];
  13820. for ( let i = 0, il = textures.length; i < il; i ++ ) {
  13821. const texture = textures[ i ];
  13822. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13823. const target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13824. const webglTexture = properties.get( texture ).__webglTexture;
  13825. state.bindTexture( target, webglTexture );
  13826. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13827. state.unbindTexture();
  13828. }
  13829. }
  13830. }
  13831. function updateMultisampleRenderTarget( renderTarget ) {
  13832. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13833. if ( isWebGL2 ) {
  13834. const width = renderTarget.width;
  13835. const height = renderTarget.height;
  13836. let mask = 16384;
  13837. if ( renderTarget.depthBuffer ) mask |= 256;
  13838. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13839. const renderTargetProperties = properties.get( renderTarget );
  13840. state.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13841. state.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13842. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13843. state.bindFramebuffer( 36008, null );
  13844. state.bindFramebuffer( 36009, renderTargetProperties.__webglMultisampledFramebuffer );
  13845. } else {
  13846. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13847. }
  13848. }
  13849. }
  13850. function getRenderTargetSamples( renderTarget ) {
  13851. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13852. Math.min( maxSamples, renderTarget.samples ) : 0;
  13853. }
  13854. function updateVideoTexture( texture ) {
  13855. const frame = info.render.frame;
  13856. // Check the last frame we updated the VideoTexture
  13857. if ( _videoTextures.get( texture ) !== frame ) {
  13858. _videoTextures.set( texture, frame );
  13859. texture.update();
  13860. }
  13861. }
  13862. // backwards compatibility
  13863. let warnedTexture2D = false;
  13864. let warnedTextureCube = false;
  13865. function safeSetTexture2D( texture, slot ) {
  13866. if ( texture && texture.isWebGLRenderTarget ) {
  13867. if ( warnedTexture2D === false ) {
  13868. console.warn( 'THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.' );
  13869. warnedTexture2D = true;
  13870. }
  13871. texture = texture.texture;
  13872. }
  13873. setTexture2D( texture, slot );
  13874. }
  13875. function safeSetTextureCube( texture, slot ) {
  13876. if ( texture && texture.isWebGLCubeRenderTarget ) {
  13877. if ( warnedTextureCube === false ) {
  13878. console.warn( 'THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.' );
  13879. warnedTextureCube = true;
  13880. }
  13881. texture = texture.texture;
  13882. }
  13883. setTextureCube( texture, slot );
  13884. }
  13885. //
  13886. this.allocateTextureUnit = allocateTextureUnit;
  13887. this.resetTextureUnits = resetTextureUnits;
  13888. this.setTexture2D = setTexture2D;
  13889. this.setTexture2DArray = setTexture2DArray;
  13890. this.setTexture3D = setTexture3D;
  13891. this.setTextureCube = setTextureCube;
  13892. this.setupRenderTarget = setupRenderTarget;
  13893. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13894. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13895. this.safeSetTexture2D = safeSetTexture2D;
  13896. this.safeSetTextureCube = safeSetTextureCube;
  13897. }
  13898. function WebGLUtils( gl, extensions, capabilities ) {
  13899. const isWebGL2 = capabilities.isWebGL2;
  13900. function convert( p ) {
  13901. let extension;
  13902. if ( p === UnsignedByteType ) return 5121;
  13903. if ( p === UnsignedShort4444Type ) return 32819;
  13904. if ( p === UnsignedShort5551Type ) return 32820;
  13905. if ( p === UnsignedShort565Type ) return 33635;
  13906. if ( p === ByteType ) return 5120;
  13907. if ( p === ShortType ) return 5122;
  13908. if ( p === UnsignedShortType ) return 5123;
  13909. if ( p === IntType ) return 5124;
  13910. if ( p === UnsignedIntType ) return 5125;
  13911. if ( p === FloatType ) return 5126;
  13912. if ( p === HalfFloatType ) {
  13913. if ( isWebGL2 ) return 5131;
  13914. extension = extensions.get( 'OES_texture_half_float' );
  13915. if ( extension !== null ) {
  13916. return extension.HALF_FLOAT_OES;
  13917. } else {
  13918. return null;
  13919. }
  13920. }
  13921. if ( p === AlphaFormat ) return 6406;
  13922. if ( p === RGBFormat ) return 6407;
  13923. if ( p === RGBAFormat ) return 6408;
  13924. if ( p === LuminanceFormat ) return 6409;
  13925. if ( p === LuminanceAlphaFormat ) return 6410;
  13926. if ( p === DepthFormat ) return 6402;
  13927. if ( p === DepthStencilFormat ) return 34041;
  13928. if ( p === RedFormat ) return 6403;
  13929. // WebGL2 formats.
  13930. if ( p === RedIntegerFormat ) return 36244;
  13931. if ( p === RGFormat ) return 33319;
  13932. if ( p === RGIntegerFormat ) return 33320;
  13933. if ( p === RGBIntegerFormat ) return 36248;
  13934. if ( p === RGBAIntegerFormat ) return 36249;
  13935. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13936. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13937. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13938. if ( extension !== null ) {
  13939. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13940. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13941. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13942. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13943. } else {
  13944. return null;
  13945. }
  13946. }
  13947. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13948. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13949. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13950. if ( extension !== null ) {
  13951. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13952. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13953. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13954. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13955. } else {
  13956. return null;
  13957. }
  13958. }
  13959. if ( p === RGB_ETC1_Format ) {
  13960. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13961. if ( extension !== null ) {
  13962. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13963. } else {
  13964. return null;
  13965. }
  13966. }
  13967. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  13968. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  13969. if ( extension !== null ) {
  13970. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  13971. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13972. }
  13973. }
  13974. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13975. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13976. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13977. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13978. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  13979. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  13980. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  13981. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  13982. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  13983. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  13984. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13985. if ( extension !== null ) {
  13986. // TODO Complete?
  13987. return p;
  13988. } else {
  13989. return null;
  13990. }
  13991. }
  13992. if ( p === RGBA_BPTC_Format ) {
  13993. extension = extensions.get( 'EXT_texture_compression_bptc' );
  13994. if ( extension !== null ) {
  13995. // TODO Complete?
  13996. return p;
  13997. } else {
  13998. return null;
  13999. }
  14000. }
  14001. if ( p === UnsignedInt248Type ) {
  14002. if ( isWebGL2 ) return 34042;
  14003. extension = extensions.get( 'WEBGL_depth_texture' );
  14004. if ( extension !== null ) {
  14005. return extension.UNSIGNED_INT_24_8_WEBGL;
  14006. } else {
  14007. return null;
  14008. }
  14009. }
  14010. }
  14011. return { convert: convert };
  14012. }
  14013. class ArrayCamera extends PerspectiveCamera {
  14014. constructor( array = [] ) {
  14015. super();
  14016. this.cameras = array;
  14017. }
  14018. }
  14019. ArrayCamera.prototype.isArrayCamera = true;
  14020. class Group extends Object3D {
  14021. constructor() {
  14022. super();
  14023. this.type = 'Group';
  14024. }
  14025. }
  14026. Group.prototype.isGroup = true;
  14027. const _moveEvent = { type: 'move' };
  14028. class WebXRController {
  14029. constructor() {
  14030. this._targetRay = null;
  14031. this._grip = null;
  14032. this._hand = null;
  14033. }
  14034. getHandSpace() {
  14035. if ( this._hand === null ) {
  14036. this._hand = new Group();
  14037. this._hand.matrixAutoUpdate = false;
  14038. this._hand.visible = false;
  14039. this._hand.joints = {};
  14040. this._hand.inputState = { pinching: false };
  14041. }
  14042. return this._hand;
  14043. }
  14044. getTargetRaySpace() {
  14045. if ( this._targetRay === null ) {
  14046. this._targetRay = new Group();
  14047. this._targetRay.matrixAutoUpdate = false;
  14048. this._targetRay.visible = false;
  14049. this._targetRay.hasLinearVelocity = false;
  14050. this._targetRay.linearVelocity = new Vector3();
  14051. this._targetRay.hasAngularVelocity = false;
  14052. this._targetRay.angularVelocity = new Vector3();
  14053. }
  14054. return this._targetRay;
  14055. }
  14056. getGripSpace() {
  14057. if ( this._grip === null ) {
  14058. this._grip = new Group();
  14059. this._grip.matrixAutoUpdate = false;
  14060. this._grip.visible = false;
  14061. this._grip.hasLinearVelocity = false;
  14062. this._grip.linearVelocity = new Vector3();
  14063. this._grip.hasAngularVelocity = false;
  14064. this._grip.angularVelocity = new Vector3();
  14065. }
  14066. return this._grip;
  14067. }
  14068. dispatchEvent( event ) {
  14069. if ( this._targetRay !== null ) {
  14070. this._targetRay.dispatchEvent( event );
  14071. }
  14072. if ( this._grip !== null ) {
  14073. this._grip.dispatchEvent( event );
  14074. }
  14075. if ( this._hand !== null ) {
  14076. this._hand.dispatchEvent( event );
  14077. }
  14078. return this;
  14079. }
  14080. disconnect( inputSource ) {
  14081. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14082. if ( this._targetRay !== null ) {
  14083. this._targetRay.visible = false;
  14084. }
  14085. if ( this._grip !== null ) {
  14086. this._grip.visible = false;
  14087. }
  14088. if ( this._hand !== null ) {
  14089. this._hand.visible = false;
  14090. }
  14091. return this;
  14092. }
  14093. update( inputSource, frame, referenceSpace ) {
  14094. let inputPose = null;
  14095. let gripPose = null;
  14096. let handPose = null;
  14097. const targetRay = this._targetRay;
  14098. const grip = this._grip;
  14099. const hand = this._hand;
  14100. if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) {
  14101. if ( targetRay !== null ) {
  14102. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  14103. if ( inputPose !== null ) {
  14104. targetRay.matrix.fromArray( inputPose.transform.matrix );
  14105. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  14106. if ( inputPose.linearVelocity ) {
  14107. targetRay.hasLinearVelocity = true;
  14108. targetRay.linearVelocity.copy( inputPose.linearVelocity );
  14109. } else {
  14110. targetRay.hasLinearVelocity = false;
  14111. }
  14112. if ( inputPose.angularVelocity ) {
  14113. targetRay.hasAngularVelocity = true;
  14114. targetRay.angularVelocity.copy( inputPose.angularVelocity );
  14115. } else {
  14116. targetRay.hasAngularVelocity = false;
  14117. }
  14118. this.dispatchEvent( _moveEvent );
  14119. }
  14120. }
  14121. if ( hand && inputSource.hand ) {
  14122. handPose = true;
  14123. for ( const inputjoint of inputSource.hand.values() ) {
  14124. // Update the joints groups with the XRJoint poses
  14125. const jointPose = frame.getJointPose( inputjoint, referenceSpace );
  14126. if ( hand.joints[ inputjoint.jointName ] === undefined ) {
  14127. // The transform of this joint will be updated with the joint pose on each frame
  14128. const joint = new Group();
  14129. joint.matrixAutoUpdate = false;
  14130. joint.visible = false;
  14131. hand.joints[ inputjoint.jointName ] = joint;
  14132. // ??
  14133. hand.add( joint );
  14134. }
  14135. const joint = hand.joints[ inputjoint.jointName ];
  14136. if ( jointPose !== null ) {
  14137. joint.matrix.fromArray( jointPose.transform.matrix );
  14138. joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
  14139. joint.jointRadius = jointPose.radius;
  14140. }
  14141. joint.visible = jointPose !== null;
  14142. }
  14143. // Custom events
  14144. // Check pinchz
  14145. const indexTip = hand.joints[ 'index-finger-tip' ];
  14146. const thumbTip = hand.joints[ 'thumb-tip' ];
  14147. const distance = indexTip.position.distanceTo( thumbTip.position );
  14148. const distanceToPinch = 0.02;
  14149. const threshold = 0.005;
  14150. if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
  14151. hand.inputState.pinching = false;
  14152. this.dispatchEvent( {
  14153. type: 'pinchend',
  14154. handedness: inputSource.handedness,
  14155. target: this
  14156. } );
  14157. } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
  14158. hand.inputState.pinching = true;
  14159. this.dispatchEvent( {
  14160. type: 'pinchstart',
  14161. handedness: inputSource.handedness,
  14162. target: this
  14163. } );
  14164. }
  14165. } else {
  14166. if ( grip !== null && inputSource.gripSpace ) {
  14167. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  14168. if ( gripPose !== null ) {
  14169. grip.matrix.fromArray( gripPose.transform.matrix );
  14170. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  14171. if ( gripPose.linearVelocity ) {
  14172. grip.hasLinearVelocity = true;
  14173. grip.linearVelocity.copy( gripPose.linearVelocity );
  14174. } else {
  14175. grip.hasLinearVelocity = false;
  14176. }
  14177. if ( gripPose.angularVelocity ) {
  14178. grip.hasAngularVelocity = true;
  14179. grip.angularVelocity.copy( gripPose.angularVelocity );
  14180. } else {
  14181. grip.hasAngularVelocity = false;
  14182. }
  14183. }
  14184. }
  14185. }
  14186. }
  14187. if ( targetRay !== null ) {
  14188. targetRay.visible = ( inputPose !== null );
  14189. }
  14190. if ( grip !== null ) {
  14191. grip.visible = ( gripPose !== null );
  14192. }
  14193. if ( hand !== null ) {
  14194. hand.visible = ( handPose !== null );
  14195. }
  14196. return this;
  14197. }
  14198. }
  14199. class WebXRManager extends EventDispatcher {
  14200. constructor( renderer, gl ) {
  14201. super();
  14202. const scope = this;
  14203. const state = renderer.state;
  14204. let session = null;
  14205. let framebufferScaleFactor = 1.0;
  14206. let referenceSpace = null;
  14207. let referenceSpaceType = 'local-floor';
  14208. let pose = null;
  14209. let glBinding = null;
  14210. let glFramebuffer = null;
  14211. let glProjLayer = null;
  14212. let glBaseLayer = null;
  14213. let isMultisample = false;
  14214. let glMultisampledFramebuffer = null;
  14215. let glColorRenderbuffer = null;
  14216. let glDepthRenderbuffer = null;
  14217. let xrFrame = null;
  14218. let depthStyle = null;
  14219. let clearStyle = null;
  14220. const controllers = [];
  14221. const inputSourcesMap = new Map();
  14222. //
  14223. const cameraL = new PerspectiveCamera();
  14224. cameraL.layers.enable( 1 );
  14225. cameraL.viewport = new Vector4();
  14226. const cameraR = new PerspectiveCamera();
  14227. cameraR.layers.enable( 2 );
  14228. cameraR.viewport = new Vector4();
  14229. const cameras = [ cameraL, cameraR ];
  14230. const cameraVR = new ArrayCamera();
  14231. cameraVR.layers.enable( 1 );
  14232. cameraVR.layers.enable( 2 );
  14233. let _currentDepthNear = null;
  14234. let _currentDepthFar = null;
  14235. //
  14236. this.cameraAutoUpdate = true;
  14237. this.enabled = false;
  14238. this.isPresenting = false;
  14239. this.getController = function ( index ) {
  14240. let controller = controllers[ index ];
  14241. if ( controller === undefined ) {
  14242. controller = new WebXRController();
  14243. controllers[ index ] = controller;
  14244. }
  14245. return controller.getTargetRaySpace();
  14246. };
  14247. this.getControllerGrip = function ( index ) {
  14248. let controller = controllers[ index ];
  14249. if ( controller === undefined ) {
  14250. controller = new WebXRController();
  14251. controllers[ index ] = controller;
  14252. }
  14253. return controller.getGripSpace();
  14254. };
  14255. this.getHand = function ( index ) {
  14256. let controller = controllers[ index ];
  14257. if ( controller === undefined ) {
  14258. controller = new WebXRController();
  14259. controllers[ index ] = controller;
  14260. }
  14261. return controller.getHandSpace();
  14262. };
  14263. //
  14264. function onSessionEvent( event ) {
  14265. const controller = inputSourcesMap.get( event.inputSource );
  14266. if ( controller ) {
  14267. controller.dispatchEvent( { type: event.type, data: event.inputSource } );
  14268. }
  14269. }
  14270. function onSessionEnd() {
  14271. inputSourcesMap.forEach( function ( controller, inputSource ) {
  14272. controller.disconnect( inputSource );
  14273. } );
  14274. inputSourcesMap.clear();
  14275. _currentDepthNear = null;
  14276. _currentDepthFar = null;
  14277. // restore framebuffer/rendering state
  14278. state.bindXRFramebuffer( null );
  14279. renderer.setRenderTarget( renderer.getRenderTarget() );
  14280. if ( glFramebuffer ) gl.deleteFramebuffer( glFramebuffer );
  14281. if ( glMultisampledFramebuffer ) gl.deleteFramebuffer( glMultisampledFramebuffer );
  14282. if ( glColorRenderbuffer ) gl.deleteRenderbuffer( glColorRenderbuffer );
  14283. if ( glDepthRenderbuffer ) gl.deleteRenderbuffer( glDepthRenderbuffer );
  14284. glFramebuffer = null;
  14285. glMultisampledFramebuffer = null;
  14286. glColorRenderbuffer = null;
  14287. glDepthRenderbuffer = null;
  14288. glBaseLayer = null;
  14289. glProjLayer = null;
  14290. glBinding = null;
  14291. session = null;
  14292. //
  14293. animation.stop();
  14294. scope.isPresenting = false;
  14295. scope.dispatchEvent( { type: 'sessionend' } );
  14296. }
  14297. this.setFramebufferScaleFactor = function ( value ) {
  14298. framebufferScaleFactor = value;
  14299. if ( scope.isPresenting === true ) {
  14300. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  14301. }
  14302. };
  14303. this.setReferenceSpaceType = function ( value ) {
  14304. referenceSpaceType = value;
  14305. if ( scope.isPresenting === true ) {
  14306. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  14307. }
  14308. };
  14309. this.getReferenceSpace = function () {
  14310. return referenceSpace;
  14311. };
  14312. this.getBaseLayer = function () {
  14313. return glProjLayer !== null ? glProjLayer : glBaseLayer;
  14314. };
  14315. this.getBinding = function () {
  14316. return glBinding;
  14317. };
  14318. this.getFrame = function () {
  14319. return xrFrame;
  14320. };
  14321. this.getSession = function () {
  14322. return session;
  14323. };
  14324. this.setSession = async function ( value ) {
  14325. session = value;
  14326. if ( session !== null ) {
  14327. session.addEventListener( 'select', onSessionEvent );
  14328. session.addEventListener( 'selectstart', onSessionEvent );
  14329. session.addEventListener( 'selectend', onSessionEvent );
  14330. session.addEventListener( 'squeeze', onSessionEvent );
  14331. session.addEventListener( 'squeezestart', onSessionEvent );
  14332. session.addEventListener( 'squeezeend', onSessionEvent );
  14333. session.addEventListener( 'end', onSessionEnd );
  14334. session.addEventListener( 'inputsourceschange', onInputSourcesChange );
  14335. const attributes = gl.getContextAttributes();
  14336. if ( attributes.xrCompatible !== true ) {
  14337. await gl.makeXRCompatible();
  14338. }
  14339. if ( session.renderState.layers === undefined ) {
  14340. const layerInit = {
  14341. antialias: attributes.antialias,
  14342. alpha: attributes.alpha,
  14343. depth: attributes.depth,
  14344. stencil: attributes.stencil,
  14345. framebufferScaleFactor: framebufferScaleFactor
  14346. };
  14347. glBaseLayer = new XRWebGLLayer( session, gl, layerInit );
  14348. session.updateRenderState( { baseLayer: glBaseLayer } );
  14349. } else if ( gl instanceof WebGLRenderingContext ) {
  14350. // Use old style webgl layer because we can't use MSAA
  14351. // WebGL2 support.
  14352. const layerInit = {
  14353. antialias: true,
  14354. alpha: attributes.alpha,
  14355. depth: attributes.depth,
  14356. stencil: attributes.stencil,
  14357. framebufferScaleFactor: framebufferScaleFactor
  14358. };
  14359. glBaseLayer = new XRWebGLLayer( session, gl, layerInit );
  14360. session.updateRenderState( { layers: [ glBaseLayer ] } );
  14361. } else {
  14362. isMultisample = attributes.antialias;
  14363. let depthFormat = null;
  14364. if ( attributes.depth ) {
  14365. clearStyle = 256;
  14366. if ( attributes.stencil ) clearStyle |= 1024;
  14367. depthStyle = attributes.stencil ? 33306 : 36096;
  14368. depthFormat = attributes.stencil ? 35056 : 33190;
  14369. }
  14370. const projectionlayerInit = {
  14371. colorFormat: attributes.alpha ? 32856 : 32849,
  14372. depthFormat: depthFormat,
  14373. scaleFactor: framebufferScaleFactor
  14374. };
  14375. glBinding = new XRWebGLBinding( session, gl );
  14376. glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
  14377. glFramebuffer = gl.createFramebuffer();
  14378. session.updateRenderState( { layers: [ glProjLayer ] } );
  14379. if ( isMultisample ) {
  14380. glMultisampledFramebuffer = gl.createFramebuffer();
  14381. glColorRenderbuffer = gl.createRenderbuffer();
  14382. gl.bindRenderbuffer( 36161, glColorRenderbuffer );
  14383. gl.renderbufferStorageMultisample(
  14384. 36161,
  14385. 4,
  14386. 32856,
  14387. glProjLayer.textureWidth,
  14388. glProjLayer.textureHeight );
  14389. state.bindFramebuffer( 36160, glMultisampledFramebuffer );
  14390. gl.framebufferRenderbuffer( 36160, 36064, 36161, glColorRenderbuffer );
  14391. gl.bindRenderbuffer( 36161, null );
  14392. if ( depthFormat !== null ) {
  14393. glDepthRenderbuffer = gl.createRenderbuffer();
  14394. gl.bindRenderbuffer( 36161, glDepthRenderbuffer );
  14395. gl.renderbufferStorageMultisample( 36161, 4, depthFormat, glProjLayer.textureWidth, glProjLayer.textureHeight );
  14396. gl.framebufferRenderbuffer( 36160, depthStyle, 36161, glDepthRenderbuffer );
  14397. gl.bindRenderbuffer( 36161, null );
  14398. }
  14399. state.bindFramebuffer( 36160, null );
  14400. }
  14401. }
  14402. referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
  14403. animation.setContext( session );
  14404. animation.start();
  14405. scope.isPresenting = true;
  14406. scope.dispatchEvent( { type: 'sessionstart' } );
  14407. }
  14408. };
  14409. function onInputSourcesChange( event ) {
  14410. const inputSources = session.inputSources;
  14411. // Assign inputSources to available controllers
  14412. for ( let i = 0; i < controllers.length; i ++ ) {
  14413. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  14414. }
  14415. // Notify disconnected
  14416. for ( let i = 0; i < event.removed.length; i ++ ) {
  14417. const inputSource = event.removed[ i ];
  14418. const controller = inputSourcesMap.get( inputSource );
  14419. if ( controller ) {
  14420. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14421. inputSourcesMap.delete( inputSource );
  14422. }
  14423. }
  14424. // Notify connected
  14425. for ( let i = 0; i < event.added.length; i ++ ) {
  14426. const inputSource = event.added[ i ];
  14427. const controller = inputSourcesMap.get( inputSource );
  14428. if ( controller ) {
  14429. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  14430. }
  14431. }
  14432. }
  14433. //
  14434. const cameraLPos = new Vector3();
  14435. const cameraRPos = new Vector3();
  14436. /**
  14437. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14438. * the cameras' projection and world matrices have already been set.
  14439. * And that near and far planes are identical for both cameras.
  14440. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14441. */
  14442. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  14443. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  14444. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  14445. const ipd = cameraLPos.distanceTo( cameraRPos );
  14446. const projL = cameraL.projectionMatrix.elements;
  14447. const projR = cameraR.projectionMatrix.elements;
  14448. // VR systems will have identical far and near planes, and
  14449. // most likely identical top and bottom frustum extents.
  14450. // Use the left camera for these values.
  14451. const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  14452. const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  14453. const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  14454. const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  14455. const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  14456. const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  14457. const left = near * leftFov;
  14458. const right = near * rightFov;
  14459. // Calculate the new camera's position offset from the
  14460. // left camera. xOffset should be roughly half `ipd`.
  14461. const zOffset = ipd / ( - leftFov + rightFov );
  14462. const xOffset = zOffset * - leftFov;
  14463. // TODO: Better way to apply this offset?
  14464. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  14465. camera.translateX( xOffset );
  14466. camera.translateZ( zOffset );
  14467. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  14468. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  14469. // Find the union of the frustum values of the cameras and scale
  14470. // the values so that the near plane's position does not change in world space,
  14471. // although must now be relative to the new union camera.
  14472. const near2 = near + zOffset;
  14473. const far2 = far + zOffset;
  14474. const left2 = left - xOffset;
  14475. const right2 = right + ( ipd - xOffset );
  14476. const top2 = topFov * far / far2 * near2;
  14477. const bottom2 = bottomFov * far / far2 * near2;
  14478. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  14479. }
  14480. function updateCamera( camera, parent ) {
  14481. if ( parent === null ) {
  14482. camera.matrixWorld.copy( camera.matrix );
  14483. } else {
  14484. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  14485. }
  14486. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  14487. }
  14488. this.updateCamera = function ( camera ) {
  14489. if ( session === null ) return;
  14490. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14491. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14492. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  14493. // Note that the new renderState won't apply until the next frame. See #18320
  14494. session.updateRenderState( {
  14495. depthNear: cameraVR.near,
  14496. depthFar: cameraVR.far
  14497. } );
  14498. _currentDepthNear = cameraVR.near;
  14499. _currentDepthFar = cameraVR.far;
  14500. }
  14501. const parent = camera.parent;
  14502. const cameras = cameraVR.cameras;
  14503. updateCamera( cameraVR, parent );
  14504. for ( let i = 0; i < cameras.length; i ++ ) {
  14505. updateCamera( cameras[ i ], parent );
  14506. }
  14507. cameraVR.matrixWorld.decompose( cameraVR.position, cameraVR.quaternion, cameraVR.scale );
  14508. // update user camera and its children
  14509. camera.position.copy( cameraVR.position );
  14510. camera.quaternion.copy( cameraVR.quaternion );
  14511. camera.scale.copy( cameraVR.scale );
  14512. camera.matrix.copy( cameraVR.matrix );
  14513. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14514. const children = camera.children;
  14515. for ( let i = 0, l = children.length; i < l; i ++ ) {
  14516. children[ i ].updateMatrixWorld( true );
  14517. }
  14518. // update projection matrix for proper view frustum culling
  14519. if ( cameras.length === 2 ) {
  14520. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14521. } else {
  14522. // assume single camera setup (AR)
  14523. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  14524. }
  14525. };
  14526. this.getCamera = function () {
  14527. return cameraVR;
  14528. };
  14529. this.getFoveation = function () {
  14530. if ( glProjLayer !== null ) {
  14531. return glProjLayer.fixedFoveation;
  14532. }
  14533. if ( glBaseLayer !== null ) {
  14534. return glBaseLayer.fixedFoveation;
  14535. }
  14536. return undefined;
  14537. };
  14538. this.setFoveation = function ( foveation ) {
  14539. // 0 = no foveation = full resolution
  14540. // 1 = maximum foveation = the edges render at lower resolution
  14541. if ( glProjLayer !== null ) {
  14542. glProjLayer.fixedFoveation = foveation;
  14543. }
  14544. if ( glBaseLayer !== null && glBaseLayer.fixedFoveation !== undefined ) {
  14545. glBaseLayer.fixedFoveation = foveation;
  14546. }
  14547. };
  14548. // Animation Loop
  14549. let onAnimationFrameCallback = null;
  14550. function onAnimationFrame( time, frame ) {
  14551. pose = frame.getViewerPose( referenceSpace );
  14552. xrFrame = frame;
  14553. if ( pose !== null ) {
  14554. const views = pose.views;
  14555. if ( glBaseLayer !== null ) {
  14556. state.bindXRFramebuffer( glBaseLayer.framebuffer );
  14557. }
  14558. let cameraVRNeedsUpdate = false;
  14559. // check if it's necessary to rebuild cameraVR's camera list
  14560. if ( views.length !== cameraVR.cameras.length ) {
  14561. cameraVR.cameras.length = 0;
  14562. cameraVRNeedsUpdate = true;
  14563. }
  14564. for ( let i = 0; i < views.length; i ++ ) {
  14565. const view = views[ i ];
  14566. let viewport = null;
  14567. if ( glBaseLayer !== null ) {
  14568. viewport = glBaseLayer.getViewport( view );
  14569. } else {
  14570. const glSubImage = glBinding.getViewSubImage( glProjLayer, view );
  14571. state.bindXRFramebuffer( glFramebuffer );
  14572. if ( glSubImage.depthStencilTexture !== undefined ) {
  14573. gl.framebufferTexture2D( 36160, depthStyle, 3553, glSubImage.depthStencilTexture, 0 );
  14574. }
  14575. gl.framebufferTexture2D( 36160, 36064, 3553, glSubImage.colorTexture, 0 );
  14576. viewport = glSubImage.viewport;
  14577. }
  14578. const camera = cameras[ i ];
  14579. camera.matrix.fromArray( view.transform.matrix );
  14580. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14581. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14582. if ( i === 0 ) {
  14583. cameraVR.matrix.copy( camera.matrix );
  14584. }
  14585. if ( cameraVRNeedsUpdate === true ) {
  14586. cameraVR.cameras.push( camera );
  14587. }
  14588. }
  14589. if ( isMultisample ) {
  14590. state.bindXRFramebuffer( glMultisampledFramebuffer );
  14591. if ( clearStyle !== null ) gl.clear( clearStyle );
  14592. }
  14593. }
  14594. //
  14595. const inputSources = session.inputSources;
  14596. for ( let i = 0; i < controllers.length; i ++ ) {
  14597. const controller = controllers[ i ];
  14598. const inputSource = inputSources[ i ];
  14599. controller.update( inputSource, frame, referenceSpace );
  14600. }
  14601. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  14602. if ( isMultisample ) {
  14603. const width = glProjLayer.textureWidth;
  14604. const height = glProjLayer.textureHeight;
  14605. state.bindFramebuffer( 36008, glMultisampledFramebuffer );
  14606. state.bindFramebuffer( 36009, glFramebuffer );
  14607. // Invalidate the depth here to avoid flush of the depth data to main memory.
  14608. gl.invalidateFramebuffer( 36008, [ depthStyle ] );
  14609. gl.invalidateFramebuffer( 36009, [ depthStyle ] );
  14610. gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, 16384, 9728 );
  14611. // Invalidate the MSAA buffer because it's not needed anymore.
  14612. gl.invalidateFramebuffer( 36008, [ 36064 ] );
  14613. state.bindFramebuffer( 36008, null );
  14614. state.bindFramebuffer( 36009, null );
  14615. state.bindFramebuffer( 36160, glMultisampledFramebuffer );
  14616. }
  14617. xrFrame = null;
  14618. }
  14619. const animation = new WebGLAnimation();
  14620. animation.setAnimationLoop( onAnimationFrame );
  14621. this.setAnimationLoop = function ( callback ) {
  14622. onAnimationFrameCallback = callback;
  14623. };
  14624. this.dispose = function () {};
  14625. }
  14626. }
  14627. function WebGLMaterials( properties ) {
  14628. function refreshFogUniforms( uniforms, fog ) {
  14629. uniforms.fogColor.value.copy( fog.color );
  14630. if ( fog.isFog ) {
  14631. uniforms.fogNear.value = fog.near;
  14632. uniforms.fogFar.value = fog.far;
  14633. } else if ( fog.isFogExp2 ) {
  14634. uniforms.fogDensity.value = fog.density;
  14635. }
  14636. }
  14637. function refreshMaterialUniforms( uniforms, material, pixelRatio, height, transmissionRenderTarget ) {
  14638. if ( material.isMeshBasicMaterial ) {
  14639. refreshUniformsCommon( uniforms, material );
  14640. } else if ( material.isMeshLambertMaterial ) {
  14641. refreshUniformsCommon( uniforms, material );
  14642. refreshUniformsLambert( uniforms, material );
  14643. } else if ( material.isMeshToonMaterial ) {
  14644. refreshUniformsCommon( uniforms, material );
  14645. refreshUniformsToon( uniforms, material );
  14646. } else if ( material.isMeshPhongMaterial ) {
  14647. refreshUniformsCommon( uniforms, material );
  14648. refreshUniformsPhong( uniforms, material );
  14649. } else if ( material.isMeshStandardMaterial ) {
  14650. refreshUniformsCommon( uniforms, material );
  14651. if ( material.isMeshPhysicalMaterial ) {
  14652. refreshUniformsPhysical( uniforms, material, transmissionRenderTarget );
  14653. } else {
  14654. refreshUniformsStandard( uniforms, material );
  14655. }
  14656. } else if ( material.isMeshMatcapMaterial ) {
  14657. refreshUniformsCommon( uniforms, material );
  14658. refreshUniformsMatcap( uniforms, material );
  14659. } else if ( material.isMeshDepthMaterial ) {
  14660. refreshUniformsCommon( uniforms, material );
  14661. refreshUniformsDepth( uniforms, material );
  14662. } else if ( material.isMeshDistanceMaterial ) {
  14663. refreshUniformsCommon( uniforms, material );
  14664. refreshUniformsDistance( uniforms, material );
  14665. } else if ( material.isMeshNormalMaterial ) {
  14666. refreshUniformsCommon( uniforms, material );
  14667. refreshUniformsNormal( uniforms, material );
  14668. } else if ( material.isLineBasicMaterial ) {
  14669. refreshUniformsLine( uniforms, material );
  14670. if ( material.isLineDashedMaterial ) {
  14671. refreshUniformsDash( uniforms, material );
  14672. }
  14673. } else if ( material.isPointsMaterial ) {
  14674. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  14675. } else if ( material.isSpriteMaterial ) {
  14676. refreshUniformsSprites( uniforms, material );
  14677. } else if ( material.isShadowMaterial ) {
  14678. uniforms.color.value.copy( material.color );
  14679. uniforms.opacity.value = material.opacity;
  14680. } else if ( material.isShaderMaterial ) {
  14681. material.uniformsNeedUpdate = false; // #15581
  14682. }
  14683. }
  14684. function refreshUniformsCommon( uniforms, material ) {
  14685. uniforms.opacity.value = material.opacity;
  14686. if ( material.color ) {
  14687. uniforms.diffuse.value.copy( material.color );
  14688. }
  14689. if ( material.emissive ) {
  14690. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14691. }
  14692. if ( material.map ) {
  14693. uniforms.map.value = material.map;
  14694. }
  14695. if ( material.alphaMap ) {
  14696. uniforms.alphaMap.value = material.alphaMap;
  14697. }
  14698. if ( material.specularMap ) {
  14699. uniforms.specularMap.value = material.specularMap;
  14700. }
  14701. if ( material.alphaTest > 0 ) {
  14702. uniforms.alphaTest.value = material.alphaTest;
  14703. }
  14704. const envMap = properties.get( material ).envMap;
  14705. if ( envMap ) {
  14706. uniforms.envMap.value = envMap;
  14707. uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1;
  14708. uniforms.reflectivity.value = material.reflectivity;
  14709. uniforms.ior.value = material.ior;
  14710. uniforms.refractionRatio.value = material.refractionRatio;
  14711. const maxMipLevel = properties.get( envMap ).__maxMipLevel;
  14712. if ( maxMipLevel !== undefined ) {
  14713. uniforms.maxMipLevel.value = maxMipLevel;
  14714. }
  14715. }
  14716. if ( material.lightMap ) {
  14717. uniforms.lightMap.value = material.lightMap;
  14718. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14719. }
  14720. if ( material.aoMap ) {
  14721. uniforms.aoMap.value = material.aoMap;
  14722. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14723. }
  14724. // uv repeat and offset setting priorities
  14725. // 1. color map
  14726. // 2. specular map
  14727. // 3. displacementMap map
  14728. // 4. normal map
  14729. // 5. bump map
  14730. // 6. roughnessMap map
  14731. // 7. metalnessMap map
  14732. // 8. alphaMap map
  14733. // 9. emissiveMap map
  14734. // 10. clearcoat map
  14735. // 11. clearcoat normal map
  14736. // 12. clearcoat roughnessMap map
  14737. // 13. specular intensity map
  14738. // 14. specular tint map
  14739. // 15. transmission map
  14740. // 16. thickness map
  14741. let uvScaleMap;
  14742. if ( material.map ) {
  14743. uvScaleMap = material.map;
  14744. } else if ( material.specularMap ) {
  14745. uvScaleMap = material.specularMap;
  14746. } else if ( material.displacementMap ) {
  14747. uvScaleMap = material.displacementMap;
  14748. } else if ( material.normalMap ) {
  14749. uvScaleMap = material.normalMap;
  14750. } else if ( material.bumpMap ) {
  14751. uvScaleMap = material.bumpMap;
  14752. } else if ( material.roughnessMap ) {
  14753. uvScaleMap = material.roughnessMap;
  14754. } else if ( material.metalnessMap ) {
  14755. uvScaleMap = material.metalnessMap;
  14756. } else if ( material.alphaMap ) {
  14757. uvScaleMap = material.alphaMap;
  14758. } else if ( material.emissiveMap ) {
  14759. uvScaleMap = material.emissiveMap;
  14760. } else if ( material.clearcoatMap ) {
  14761. uvScaleMap = material.clearcoatMap;
  14762. } else if ( material.clearcoatNormalMap ) {
  14763. uvScaleMap = material.clearcoatNormalMap;
  14764. } else if ( material.clearcoatRoughnessMap ) {
  14765. uvScaleMap = material.clearcoatRoughnessMap;
  14766. } else if ( material.specularIntensityMap ) {
  14767. uvScaleMap = material.specularIntensityMap;
  14768. } else if ( material.specularTintMap ) {
  14769. uvScaleMap = material.specularTintMap;
  14770. } else if ( material.transmissionMap ) {
  14771. uvScaleMap = material.transmissionMap;
  14772. } else if ( material.thicknessMap ) {
  14773. uvScaleMap = material.thicknessMap;
  14774. }
  14775. if ( uvScaleMap !== undefined ) {
  14776. // backwards compatibility
  14777. if ( uvScaleMap.isWebGLRenderTarget ) {
  14778. uvScaleMap = uvScaleMap.texture;
  14779. }
  14780. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14781. uvScaleMap.updateMatrix();
  14782. }
  14783. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14784. }
  14785. // uv repeat and offset setting priorities for uv2
  14786. // 1. ao map
  14787. // 2. light map
  14788. let uv2ScaleMap;
  14789. if ( material.aoMap ) {
  14790. uv2ScaleMap = material.aoMap;
  14791. } else if ( material.lightMap ) {
  14792. uv2ScaleMap = material.lightMap;
  14793. }
  14794. if ( uv2ScaleMap !== undefined ) {
  14795. // backwards compatibility
  14796. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  14797. uv2ScaleMap = uv2ScaleMap.texture;
  14798. }
  14799. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  14800. uv2ScaleMap.updateMatrix();
  14801. }
  14802. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  14803. }
  14804. }
  14805. function refreshUniformsLine( uniforms, material ) {
  14806. uniforms.diffuse.value.copy( material.color );
  14807. uniforms.opacity.value = material.opacity;
  14808. }
  14809. function refreshUniformsDash( uniforms, material ) {
  14810. uniforms.dashSize.value = material.dashSize;
  14811. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14812. uniforms.scale.value = material.scale;
  14813. }
  14814. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  14815. uniforms.diffuse.value.copy( material.color );
  14816. uniforms.opacity.value = material.opacity;
  14817. uniforms.size.value = material.size * pixelRatio;
  14818. uniforms.scale.value = height * 0.5;
  14819. if ( material.map ) {
  14820. uniforms.map.value = material.map;
  14821. }
  14822. if ( material.alphaMap ) {
  14823. uniforms.alphaMap.value = material.alphaMap;
  14824. }
  14825. if ( material.alphaTest > 0 ) {
  14826. uniforms.alphaTest.value = material.alphaTest;
  14827. }
  14828. // uv repeat and offset setting priorities
  14829. // 1. color map
  14830. // 2. alpha map
  14831. let uvScaleMap;
  14832. if ( material.map ) {
  14833. uvScaleMap = material.map;
  14834. } else if ( material.alphaMap ) {
  14835. uvScaleMap = material.alphaMap;
  14836. }
  14837. if ( uvScaleMap !== undefined ) {
  14838. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14839. uvScaleMap.updateMatrix();
  14840. }
  14841. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14842. }
  14843. }
  14844. function refreshUniformsSprites( uniforms, material ) {
  14845. uniforms.diffuse.value.copy( material.color );
  14846. uniforms.opacity.value = material.opacity;
  14847. uniforms.rotation.value = material.rotation;
  14848. if ( material.map ) {
  14849. uniforms.map.value = material.map;
  14850. }
  14851. if ( material.alphaMap ) {
  14852. uniforms.alphaMap.value = material.alphaMap;
  14853. }
  14854. if ( material.alphaTest > 0 ) {
  14855. uniforms.alphaTest.value = material.alphaTest;
  14856. }
  14857. // uv repeat and offset setting priorities
  14858. // 1. color map
  14859. // 2. alpha map
  14860. let uvScaleMap;
  14861. if ( material.map ) {
  14862. uvScaleMap = material.map;
  14863. } else if ( material.alphaMap ) {
  14864. uvScaleMap = material.alphaMap;
  14865. }
  14866. if ( uvScaleMap !== undefined ) {
  14867. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14868. uvScaleMap.updateMatrix();
  14869. }
  14870. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14871. }
  14872. }
  14873. function refreshUniformsLambert( uniforms, material ) {
  14874. if ( material.emissiveMap ) {
  14875. uniforms.emissiveMap.value = material.emissiveMap;
  14876. }
  14877. }
  14878. function refreshUniformsPhong( uniforms, material ) {
  14879. uniforms.specular.value.copy( material.specular );
  14880. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14881. if ( material.emissiveMap ) {
  14882. uniforms.emissiveMap.value = material.emissiveMap;
  14883. }
  14884. if ( material.bumpMap ) {
  14885. uniforms.bumpMap.value = material.bumpMap;
  14886. uniforms.bumpScale.value = material.bumpScale;
  14887. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14888. }
  14889. if ( material.normalMap ) {
  14890. uniforms.normalMap.value = material.normalMap;
  14891. uniforms.normalScale.value.copy( material.normalScale );
  14892. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14893. }
  14894. if ( material.displacementMap ) {
  14895. uniforms.displacementMap.value = material.displacementMap;
  14896. uniforms.displacementScale.value = material.displacementScale;
  14897. uniforms.displacementBias.value = material.displacementBias;
  14898. }
  14899. }
  14900. function refreshUniformsToon( uniforms, material ) {
  14901. if ( material.gradientMap ) {
  14902. uniforms.gradientMap.value = material.gradientMap;
  14903. }
  14904. if ( material.emissiveMap ) {
  14905. uniforms.emissiveMap.value = material.emissiveMap;
  14906. }
  14907. if ( material.bumpMap ) {
  14908. uniforms.bumpMap.value = material.bumpMap;
  14909. uniforms.bumpScale.value = material.bumpScale;
  14910. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14911. }
  14912. if ( material.normalMap ) {
  14913. uniforms.normalMap.value = material.normalMap;
  14914. uniforms.normalScale.value.copy( material.normalScale );
  14915. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14916. }
  14917. if ( material.displacementMap ) {
  14918. uniforms.displacementMap.value = material.displacementMap;
  14919. uniforms.displacementScale.value = material.displacementScale;
  14920. uniforms.displacementBias.value = material.displacementBias;
  14921. }
  14922. }
  14923. function refreshUniformsStandard( uniforms, material ) {
  14924. uniforms.roughness.value = material.roughness;
  14925. uniforms.metalness.value = material.metalness;
  14926. if ( material.roughnessMap ) {
  14927. uniforms.roughnessMap.value = material.roughnessMap;
  14928. }
  14929. if ( material.metalnessMap ) {
  14930. uniforms.metalnessMap.value = material.metalnessMap;
  14931. }
  14932. if ( material.emissiveMap ) {
  14933. uniforms.emissiveMap.value = material.emissiveMap;
  14934. }
  14935. if ( material.bumpMap ) {
  14936. uniforms.bumpMap.value = material.bumpMap;
  14937. uniforms.bumpScale.value = material.bumpScale;
  14938. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14939. }
  14940. if ( material.normalMap ) {
  14941. uniforms.normalMap.value = material.normalMap;
  14942. uniforms.normalScale.value.copy( material.normalScale );
  14943. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14944. }
  14945. if ( material.displacementMap ) {
  14946. uniforms.displacementMap.value = material.displacementMap;
  14947. uniforms.displacementScale.value = material.displacementScale;
  14948. uniforms.displacementBias.value = material.displacementBias;
  14949. }
  14950. const envMap = properties.get( material ).envMap;
  14951. if ( envMap ) {
  14952. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14953. uniforms.envMapIntensity.value = material.envMapIntensity;
  14954. }
  14955. }
  14956. function refreshUniformsPhysical( uniforms, material, transmissionRenderTarget ) {
  14957. refreshUniformsStandard( uniforms, material );
  14958. uniforms.ior.value = material.ior; // also part of uniforms common
  14959. if ( material.sheen > 0 ) {
  14960. uniforms.sheenTint.value.copy( material.sheenTint ).multiplyScalar( material.sheen );
  14961. uniforms.sheenRoughness.value = material.sheenRoughness;
  14962. }
  14963. if ( material.clearcoat > 0 ) {
  14964. uniforms.clearcoat.value = material.clearcoat;
  14965. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14966. if ( material.clearcoatMap ) {
  14967. uniforms.clearcoatMap.value = material.clearcoatMap;
  14968. }
  14969. if ( material.clearcoatRoughnessMap ) {
  14970. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14971. }
  14972. if ( material.clearcoatNormalMap ) {
  14973. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  14974. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14975. if ( material.side === BackSide ) {
  14976. uniforms.clearcoatNormalScale.value.negate();
  14977. }
  14978. }
  14979. }
  14980. if ( material.transmission > 0 ) {
  14981. uniforms.transmission.value = material.transmission;
  14982. uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture;
  14983. uniforms.transmissionSamplerSize.value.set( transmissionRenderTarget.width, transmissionRenderTarget.height );
  14984. if ( material.transmissionMap ) {
  14985. uniforms.transmissionMap.value = material.transmissionMap;
  14986. }
  14987. uniforms.thickness.value = material.thickness;
  14988. if ( material.thicknessMap ) {
  14989. uniforms.thicknessMap.value = material.thicknessMap;
  14990. }
  14991. uniforms.attenuationDistance.value = material.attenuationDistance;
  14992. uniforms.attenuationTint.value.copy( material.attenuationTint );
  14993. }
  14994. uniforms.specularIntensity.value = material.specularIntensity;
  14995. uniforms.specularTint.value.copy( material.specularTint );
  14996. if ( material.specularIntensityMap ) {
  14997. uniforms.specularIntensityMap.value = material.specularIntensityMap;
  14998. }
  14999. if ( material.specularTintMap ) {
  15000. uniforms.specularTintMap.value = material.specularTintMap;
  15001. }
  15002. }
  15003. function refreshUniformsMatcap( uniforms, material ) {
  15004. if ( material.matcap ) {
  15005. uniforms.matcap.value = material.matcap;
  15006. }
  15007. if ( material.bumpMap ) {
  15008. uniforms.bumpMap.value = material.bumpMap;
  15009. uniforms.bumpScale.value = material.bumpScale;
  15010. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15011. }
  15012. if ( material.normalMap ) {
  15013. uniforms.normalMap.value = material.normalMap;
  15014. uniforms.normalScale.value.copy( material.normalScale );
  15015. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15016. }
  15017. if ( material.displacementMap ) {
  15018. uniforms.displacementMap.value = material.displacementMap;
  15019. uniforms.displacementScale.value = material.displacementScale;
  15020. uniforms.displacementBias.value = material.displacementBias;
  15021. }
  15022. }
  15023. function refreshUniformsDepth( uniforms, material ) {
  15024. if ( material.displacementMap ) {
  15025. uniforms.displacementMap.value = material.displacementMap;
  15026. uniforms.displacementScale.value = material.displacementScale;
  15027. uniforms.displacementBias.value = material.displacementBias;
  15028. }
  15029. }
  15030. function refreshUniformsDistance( uniforms, material ) {
  15031. if ( material.displacementMap ) {
  15032. uniforms.displacementMap.value = material.displacementMap;
  15033. uniforms.displacementScale.value = material.displacementScale;
  15034. uniforms.displacementBias.value = material.displacementBias;
  15035. }
  15036. uniforms.referencePosition.value.copy( material.referencePosition );
  15037. uniforms.nearDistance.value = material.nearDistance;
  15038. uniforms.farDistance.value = material.farDistance;
  15039. }
  15040. function refreshUniformsNormal( uniforms, material ) {
  15041. if ( material.bumpMap ) {
  15042. uniforms.bumpMap.value = material.bumpMap;
  15043. uniforms.bumpScale.value = material.bumpScale;
  15044. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15045. }
  15046. if ( material.normalMap ) {
  15047. uniforms.normalMap.value = material.normalMap;
  15048. uniforms.normalScale.value.copy( material.normalScale );
  15049. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15050. }
  15051. if ( material.displacementMap ) {
  15052. uniforms.displacementMap.value = material.displacementMap;
  15053. uniforms.displacementScale.value = material.displacementScale;
  15054. uniforms.displacementBias.value = material.displacementBias;
  15055. }
  15056. }
  15057. return {
  15058. refreshFogUniforms: refreshFogUniforms,
  15059. refreshMaterialUniforms: refreshMaterialUniforms
  15060. };
  15061. }
  15062. function createCanvasElement() {
  15063. const canvas = createElementNS( 'canvas' );
  15064. canvas.style.display = 'block';
  15065. return canvas;
  15066. }
  15067. function WebGLRenderer( parameters = {} ) {
  15068. const _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  15069. _context = parameters.context !== undefined ? parameters.context : null,
  15070. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  15071. _depth = parameters.depth !== undefined ? parameters.depth : true,
  15072. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  15073. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  15074. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  15075. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  15076. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  15077. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  15078. let currentRenderList = null;
  15079. let currentRenderState = null;
  15080. // render() can be called from within a callback triggered by another render.
  15081. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  15082. const renderListStack = [];
  15083. const renderStateStack = [];
  15084. // public properties
  15085. this.domElement = _canvas;
  15086. // Debug configuration container
  15087. this.debug = {
  15088. /**
  15089. * Enables error checking and reporting when shader programs are being compiled
  15090. * @type {boolean}
  15091. */
  15092. checkShaderErrors: true
  15093. };
  15094. // clearing
  15095. this.autoClear = true;
  15096. this.autoClearColor = true;
  15097. this.autoClearDepth = true;
  15098. this.autoClearStencil = true;
  15099. // scene graph
  15100. this.sortObjects = true;
  15101. // user-defined clipping
  15102. this.clippingPlanes = [];
  15103. this.localClippingEnabled = false;
  15104. // physically based shading
  15105. this.gammaFactor = 2.0; // for backwards compatibility
  15106. this.outputEncoding = LinearEncoding;
  15107. // physical lights
  15108. this.physicallyCorrectLights = false;
  15109. // tone mapping
  15110. this.toneMapping = NoToneMapping;
  15111. this.toneMappingExposure = 1.0;
  15112. // internal properties
  15113. const _this = this;
  15114. let _isContextLost = false;
  15115. // internal state cache
  15116. let _currentActiveCubeFace = 0;
  15117. let _currentActiveMipmapLevel = 0;
  15118. let _currentRenderTarget = null;
  15119. let _currentMaterialId = - 1;
  15120. let _currentCamera = null;
  15121. const _currentViewport = new Vector4();
  15122. const _currentScissor = new Vector4();
  15123. let _currentScissorTest = null;
  15124. //
  15125. let _width = _canvas.width;
  15126. let _height = _canvas.height;
  15127. let _pixelRatio = 1;
  15128. let _opaqueSort = null;
  15129. let _transparentSort = null;
  15130. const _viewport = new Vector4( 0, 0, _width, _height );
  15131. const _scissor = new Vector4( 0, 0, _width, _height );
  15132. let _scissorTest = false;
  15133. //
  15134. const _currentDrawBuffers = [];
  15135. // frustum
  15136. const _frustum = new Frustum();
  15137. // clipping
  15138. let _clippingEnabled = false;
  15139. let _localClippingEnabled = false;
  15140. // transmission
  15141. let _transmissionRenderTarget = null;
  15142. // camera matrices cache
  15143. const _projScreenMatrix = new Matrix4();
  15144. const _vector3 = new Vector3();
  15145. const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  15146. function getTargetPixelRatio() {
  15147. return _currentRenderTarget === null ? _pixelRatio : 1;
  15148. }
  15149. // initialize
  15150. let _gl = _context;
  15151. function getContext( contextNames, contextAttributes ) {
  15152. for ( let i = 0; i < contextNames.length; i ++ ) {
  15153. const contextName = contextNames[ i ];
  15154. const context = _canvas.getContext( contextName, contextAttributes );
  15155. if ( context !== null ) return context;
  15156. }
  15157. return null;
  15158. }
  15159. try {
  15160. const contextAttributes = {
  15161. alpha: _alpha,
  15162. depth: _depth,
  15163. stencil: _stencil,
  15164. antialias: _antialias,
  15165. premultipliedAlpha: _premultipliedAlpha,
  15166. preserveDrawingBuffer: _preserveDrawingBuffer,
  15167. powerPreference: _powerPreference,
  15168. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  15169. };
  15170. // event listeners must be registered before WebGL context is created, see #12753
  15171. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  15172. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  15173. if ( _gl === null ) {
  15174. const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  15175. if ( _this.isWebGL1Renderer === true ) {
  15176. contextNames.shift();
  15177. }
  15178. _gl = getContext( contextNames, contextAttributes );
  15179. if ( _gl === null ) {
  15180. if ( getContext( contextNames ) ) {
  15181. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  15182. } else {
  15183. throw new Error( 'Error creating WebGL context.' );
  15184. }
  15185. }
  15186. }
  15187. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  15188. if ( _gl.getShaderPrecisionFormat === undefined ) {
  15189. _gl.getShaderPrecisionFormat = function () {
  15190. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  15191. };
  15192. }
  15193. } catch ( error ) {
  15194. console.error( 'THREE.WebGLRenderer: ' + error.message );
  15195. throw error;
  15196. }
  15197. let extensions, capabilities, state, info;
  15198. let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
  15199. let programCache, materials, renderLists, renderStates, clipping, shadowMap;
  15200. let background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15201. let utils, bindingStates;
  15202. function initGLContext() {
  15203. extensions = new WebGLExtensions( _gl );
  15204. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  15205. extensions.init( capabilities );
  15206. utils = new WebGLUtils( _gl, extensions, capabilities );
  15207. state = new WebGLState( _gl, extensions, capabilities );
  15208. _currentDrawBuffers[ 0 ] = 1029;
  15209. info = new WebGLInfo( _gl );
  15210. properties = new WebGLProperties();
  15211. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  15212. cubemaps = new WebGLCubeMaps( _this );
  15213. cubeuvmaps = new WebGLCubeUVMaps( _this );
  15214. attributes = new WebGLAttributes( _gl, capabilities );
  15215. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  15216. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  15217. objects = new WebGLObjects( _gl, geometries, attributes, info );
  15218. morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
  15219. clipping = new WebGLClipping( properties );
  15220. programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
  15221. materials = new WebGLMaterials( properties );
  15222. renderLists = new WebGLRenderLists( properties );
  15223. renderStates = new WebGLRenderStates( extensions, capabilities );
  15224. background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
  15225. shadowMap = new WebGLShadowMap( _this, objects, capabilities );
  15226. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  15227. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  15228. info.programs = programCache.programs;
  15229. _this.capabilities = capabilities;
  15230. _this.extensions = extensions;
  15231. _this.properties = properties;
  15232. _this.renderLists = renderLists;
  15233. _this.shadowMap = shadowMap;
  15234. _this.state = state;
  15235. _this.info = info;
  15236. }
  15237. initGLContext();
  15238. // xr
  15239. const xr = new WebXRManager( _this, _gl );
  15240. this.xr = xr;
  15241. // API
  15242. this.getContext = function () {
  15243. return _gl;
  15244. };
  15245. this.getContextAttributes = function () {
  15246. return _gl.getContextAttributes();
  15247. };
  15248. this.forceContextLoss = function () {
  15249. const extension = extensions.get( 'WEBGL_lose_context' );
  15250. if ( extension ) extension.loseContext();
  15251. };
  15252. this.forceContextRestore = function () {
  15253. const extension = extensions.get( 'WEBGL_lose_context' );
  15254. if ( extension ) extension.restoreContext();
  15255. };
  15256. this.getPixelRatio = function () {
  15257. return _pixelRatio;
  15258. };
  15259. this.setPixelRatio = function ( value ) {
  15260. if ( value === undefined ) return;
  15261. _pixelRatio = value;
  15262. this.setSize( _width, _height, false );
  15263. };
  15264. this.getSize = function ( target ) {
  15265. return target.set( _width, _height );
  15266. };
  15267. this.setSize = function ( width, height, updateStyle ) {
  15268. if ( xr.isPresenting ) {
  15269. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  15270. return;
  15271. }
  15272. _width = width;
  15273. _height = height;
  15274. _canvas.width = Math.floor( width * _pixelRatio );
  15275. _canvas.height = Math.floor( height * _pixelRatio );
  15276. if ( updateStyle !== false ) {
  15277. _canvas.style.width = width + 'px';
  15278. _canvas.style.height = height + 'px';
  15279. }
  15280. this.setViewport( 0, 0, width, height );
  15281. };
  15282. this.getDrawingBufferSize = function ( target ) {
  15283. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  15284. };
  15285. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  15286. _width = width;
  15287. _height = height;
  15288. _pixelRatio = pixelRatio;
  15289. _canvas.width = Math.floor( width * pixelRatio );
  15290. _canvas.height = Math.floor( height * pixelRatio );
  15291. this.setViewport( 0, 0, width, height );
  15292. };
  15293. this.getCurrentViewport = function ( target ) {
  15294. return target.copy( _currentViewport );
  15295. };
  15296. this.getViewport = function ( target ) {
  15297. return target.copy( _viewport );
  15298. };
  15299. this.setViewport = function ( x, y, width, height ) {
  15300. if ( x.isVector4 ) {
  15301. _viewport.set( x.x, x.y, x.z, x.w );
  15302. } else {
  15303. _viewport.set( x, y, width, height );
  15304. }
  15305. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  15306. };
  15307. this.getScissor = function ( target ) {
  15308. return target.copy( _scissor );
  15309. };
  15310. this.setScissor = function ( x, y, width, height ) {
  15311. if ( x.isVector4 ) {
  15312. _scissor.set( x.x, x.y, x.z, x.w );
  15313. } else {
  15314. _scissor.set( x, y, width, height );
  15315. }
  15316. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  15317. };
  15318. this.getScissorTest = function () {
  15319. return _scissorTest;
  15320. };
  15321. this.setScissorTest = function ( boolean ) {
  15322. state.setScissorTest( _scissorTest = boolean );
  15323. };
  15324. this.setOpaqueSort = function ( method ) {
  15325. _opaqueSort = method;
  15326. };
  15327. this.setTransparentSort = function ( method ) {
  15328. _transparentSort = method;
  15329. };
  15330. // Clearing
  15331. this.getClearColor = function ( target ) {
  15332. return target.copy( background.getClearColor() );
  15333. };
  15334. this.setClearColor = function () {
  15335. background.setClearColor.apply( background, arguments );
  15336. };
  15337. this.getClearAlpha = function () {
  15338. return background.getClearAlpha();
  15339. };
  15340. this.setClearAlpha = function () {
  15341. background.setClearAlpha.apply( background, arguments );
  15342. };
  15343. this.clear = function ( color, depth, stencil ) {
  15344. let bits = 0;
  15345. if ( color === undefined || color ) bits |= 16384;
  15346. if ( depth === undefined || depth ) bits |= 256;
  15347. if ( stencil === undefined || stencil ) bits |= 1024;
  15348. _gl.clear( bits );
  15349. };
  15350. this.clearColor = function () {
  15351. this.clear( true, false, false );
  15352. };
  15353. this.clearDepth = function () {
  15354. this.clear( false, true, false );
  15355. };
  15356. this.clearStencil = function () {
  15357. this.clear( false, false, true );
  15358. };
  15359. //
  15360. this.dispose = function () {
  15361. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15362. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  15363. renderLists.dispose();
  15364. renderStates.dispose();
  15365. properties.dispose();
  15366. cubemaps.dispose();
  15367. cubeuvmaps.dispose();
  15368. objects.dispose();
  15369. bindingStates.dispose();
  15370. xr.dispose();
  15371. xr.removeEventListener( 'sessionstart', onXRSessionStart );
  15372. xr.removeEventListener( 'sessionend', onXRSessionEnd );
  15373. if ( _transmissionRenderTarget ) {
  15374. _transmissionRenderTarget.dispose();
  15375. _transmissionRenderTarget = null;
  15376. }
  15377. animation.stop();
  15378. };
  15379. // Events
  15380. function onContextLost( event ) {
  15381. event.preventDefault();
  15382. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  15383. _isContextLost = true;
  15384. }
  15385. function onContextRestore( /* event */ ) {
  15386. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  15387. _isContextLost = false;
  15388. const infoAutoReset = info.autoReset;
  15389. const shadowMapEnabled = shadowMap.enabled;
  15390. const shadowMapAutoUpdate = shadowMap.autoUpdate;
  15391. const shadowMapNeedsUpdate = shadowMap.needsUpdate;
  15392. const shadowMapType = shadowMap.type;
  15393. initGLContext();
  15394. info.autoReset = infoAutoReset;
  15395. shadowMap.enabled = shadowMapEnabled;
  15396. shadowMap.autoUpdate = shadowMapAutoUpdate;
  15397. shadowMap.needsUpdate = shadowMapNeedsUpdate;
  15398. shadowMap.type = shadowMapType;
  15399. }
  15400. function onMaterialDispose( event ) {
  15401. const material = event.target;
  15402. material.removeEventListener( 'dispose', onMaterialDispose );
  15403. deallocateMaterial( material );
  15404. }
  15405. // Buffer deallocation
  15406. function deallocateMaterial( material ) {
  15407. releaseMaterialProgramReferences( material );
  15408. properties.remove( material );
  15409. }
  15410. function releaseMaterialProgramReferences( material ) {
  15411. const programs = properties.get( material ).programs;
  15412. if ( programs !== undefined ) {
  15413. programs.forEach( function ( program ) {
  15414. programCache.releaseProgram( program );
  15415. } );
  15416. }
  15417. }
  15418. // Buffer rendering
  15419. function renderObjectImmediate( object, program ) {
  15420. object.render( function ( object ) {
  15421. _this.renderBufferImmediate( object, program );
  15422. } );
  15423. }
  15424. this.renderBufferImmediate = function ( object, program ) {
  15425. bindingStates.initAttributes();
  15426. const buffers = properties.get( object );
  15427. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15428. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15429. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15430. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15431. const programAttributes = program.getAttributes();
  15432. if ( object.hasPositions ) {
  15433. _gl.bindBuffer( 34962, buffers.position );
  15434. _gl.bufferData( 34962, object.positionArray, 35048 );
  15435. bindingStates.enableAttribute( programAttributes.position.location );
  15436. _gl.vertexAttribPointer( programAttributes.position.location, 3, 5126, false, 0, 0 );
  15437. }
  15438. if ( object.hasNormals ) {
  15439. _gl.bindBuffer( 34962, buffers.normal );
  15440. _gl.bufferData( 34962, object.normalArray, 35048 );
  15441. bindingStates.enableAttribute( programAttributes.normal.location );
  15442. _gl.vertexAttribPointer( programAttributes.normal.location, 3, 5126, false, 0, 0 );
  15443. }
  15444. if ( object.hasUvs ) {
  15445. _gl.bindBuffer( 34962, buffers.uv );
  15446. _gl.bufferData( 34962, object.uvArray, 35048 );
  15447. bindingStates.enableAttribute( programAttributes.uv.location );
  15448. _gl.vertexAttribPointer( programAttributes.uv.location, 2, 5126, false, 0, 0 );
  15449. }
  15450. if ( object.hasColors ) {
  15451. _gl.bindBuffer( 34962, buffers.color );
  15452. _gl.bufferData( 34962, object.colorArray, 35048 );
  15453. bindingStates.enableAttribute( programAttributes.color.location );
  15454. _gl.vertexAttribPointer( programAttributes.color.location, 3, 5126, false, 0, 0 );
  15455. }
  15456. bindingStates.disableUnusedAttributes();
  15457. _gl.drawArrays( 4, 0, object.count );
  15458. object.count = 0;
  15459. };
  15460. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  15461. if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15462. const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  15463. const program = setProgram( camera, scene, material, object );
  15464. state.setMaterial( material, frontFaceCW );
  15465. //
  15466. let index = geometry.index;
  15467. const position = geometry.attributes.position;
  15468. //
  15469. if ( index === null ) {
  15470. if ( position === undefined || position.count === 0 ) return;
  15471. } else if ( index.count === 0 ) {
  15472. return;
  15473. }
  15474. //
  15475. let rangeFactor = 1;
  15476. if ( material.wireframe === true ) {
  15477. index = geometries.getWireframeAttribute( geometry );
  15478. rangeFactor = 2;
  15479. }
  15480. if ( geometry.morphAttributes.position !== undefined || geometry.morphAttributes.normal !== undefined ) {
  15481. morphtargets.update( object, geometry, material, program );
  15482. }
  15483. bindingStates.setup( object, material, program, geometry, index );
  15484. let attribute;
  15485. let renderer = bufferRenderer;
  15486. if ( index !== null ) {
  15487. attribute = attributes.get( index );
  15488. renderer = indexedBufferRenderer;
  15489. renderer.setIndex( attribute );
  15490. }
  15491. //
  15492. const dataCount = ( index !== null ) ? index.count : position.count;
  15493. const rangeStart = geometry.drawRange.start * rangeFactor;
  15494. const rangeCount = geometry.drawRange.count * rangeFactor;
  15495. const groupStart = group !== null ? group.start * rangeFactor : 0;
  15496. const groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15497. const drawStart = Math.max( rangeStart, groupStart );
  15498. const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15499. const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15500. if ( drawCount === 0 ) return;
  15501. //
  15502. if ( object.isMesh ) {
  15503. if ( material.wireframe === true ) {
  15504. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15505. renderer.setMode( 1 );
  15506. } else {
  15507. renderer.setMode( 4 );
  15508. }
  15509. } else if ( object.isLine ) {
  15510. let lineWidth = material.linewidth;
  15511. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15512. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15513. if ( object.isLineSegments ) {
  15514. renderer.setMode( 1 );
  15515. } else if ( object.isLineLoop ) {
  15516. renderer.setMode( 2 );
  15517. } else {
  15518. renderer.setMode( 3 );
  15519. }
  15520. } else if ( object.isPoints ) {
  15521. renderer.setMode( 0 );
  15522. } else if ( object.isSprite ) {
  15523. renderer.setMode( 4 );
  15524. }
  15525. if ( object.isInstancedMesh ) {
  15526. renderer.renderInstances( drawStart, drawCount, object.count );
  15527. } else if ( geometry.isInstancedBufferGeometry ) {
  15528. const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  15529. renderer.renderInstances( drawStart, drawCount, instanceCount );
  15530. } else {
  15531. renderer.render( drawStart, drawCount );
  15532. }
  15533. };
  15534. // Compile
  15535. this.compile = function ( scene, camera ) {
  15536. currentRenderState = renderStates.get( scene );
  15537. currentRenderState.init();
  15538. renderStateStack.push( currentRenderState );
  15539. scene.traverseVisible( function ( object ) {
  15540. if ( object.isLight && object.layers.test( camera.layers ) ) {
  15541. currentRenderState.pushLight( object );
  15542. if ( object.castShadow ) {
  15543. currentRenderState.pushShadow( object );
  15544. }
  15545. }
  15546. } );
  15547. currentRenderState.setupLights( _this.physicallyCorrectLights );
  15548. scene.traverse( function ( object ) {
  15549. const material = object.material;
  15550. if ( material ) {
  15551. if ( Array.isArray( material ) ) {
  15552. for ( let i = 0; i < material.length; i ++ ) {
  15553. const material2 = material[ i ];
  15554. getProgram( material2, scene, object );
  15555. }
  15556. } else {
  15557. getProgram( material, scene, object );
  15558. }
  15559. }
  15560. } );
  15561. renderStateStack.pop();
  15562. currentRenderState = null;
  15563. };
  15564. // Animation Loop
  15565. let onAnimationFrameCallback = null;
  15566. function onAnimationFrame( time ) {
  15567. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  15568. }
  15569. function onXRSessionStart() {
  15570. animation.stop();
  15571. }
  15572. function onXRSessionEnd() {
  15573. animation.start();
  15574. }
  15575. const animation = new WebGLAnimation();
  15576. animation.setAnimationLoop( onAnimationFrame );
  15577. if ( typeof window !== 'undefined' ) animation.setContext( window );
  15578. this.setAnimationLoop = function ( callback ) {
  15579. onAnimationFrameCallback = callback;
  15580. xr.setAnimationLoop( callback );
  15581. ( callback === null ) ? animation.stop() : animation.start();
  15582. };
  15583. xr.addEventListener( 'sessionstart', onXRSessionStart );
  15584. xr.addEventListener( 'sessionend', onXRSessionEnd );
  15585. // Rendering
  15586. this.render = function ( scene, camera ) {
  15587. if ( camera !== undefined && camera.isCamera !== true ) {
  15588. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15589. return;
  15590. }
  15591. if ( _isContextLost === true ) return;
  15592. // update scene graph
  15593. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15594. // update camera matrices and frustum
  15595. if ( camera.parent === null ) camera.updateMatrixWorld();
  15596. if ( xr.enabled === true && xr.isPresenting === true ) {
  15597. if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
  15598. camera = xr.getCamera(); // use XR camera for rendering
  15599. }
  15600. //
  15601. if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, _currentRenderTarget );
  15602. currentRenderState = renderStates.get( scene, renderStateStack.length );
  15603. currentRenderState.init();
  15604. renderStateStack.push( currentRenderState );
  15605. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15606. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  15607. _localClippingEnabled = this.localClippingEnabled;
  15608. _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15609. currentRenderList = renderLists.get( scene, renderListStack.length );
  15610. currentRenderList.init();
  15611. renderListStack.push( currentRenderList );
  15612. projectObject( scene, camera, 0, _this.sortObjects );
  15613. currentRenderList.finish();
  15614. if ( _this.sortObjects === true ) {
  15615. currentRenderList.sort( _opaqueSort, _transparentSort );
  15616. }
  15617. //
  15618. if ( _clippingEnabled === true ) clipping.beginShadows();
  15619. const shadowsArray = currentRenderState.state.shadowsArray;
  15620. shadowMap.render( shadowsArray, scene, camera );
  15621. if ( _clippingEnabled === true ) clipping.endShadows();
  15622. //
  15623. if ( this.info.autoReset === true ) this.info.reset();
  15624. //
  15625. background.render( currentRenderList, scene );
  15626. // render scene
  15627. currentRenderState.setupLights( _this.physicallyCorrectLights );
  15628. if ( camera.isArrayCamera ) {
  15629. const cameras = camera.cameras;
  15630. for ( let i = 0, l = cameras.length; i < l; i ++ ) {
  15631. const camera2 = cameras[ i ];
  15632. renderScene( currentRenderList, scene, camera2, camera2.viewport );
  15633. }
  15634. } else {
  15635. renderScene( currentRenderList, scene, camera );
  15636. }
  15637. //
  15638. if ( _currentRenderTarget !== null ) {
  15639. // resolve multisample renderbuffers to a single-sample texture if necessary
  15640. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  15641. // Generate mipmap if we're using any kind of mipmap filtering
  15642. textures.updateRenderTargetMipmap( _currentRenderTarget );
  15643. }
  15644. //
  15645. if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
  15646. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15647. state.buffers.depth.setTest( true );
  15648. state.buffers.depth.setMask( true );
  15649. state.buffers.color.setMask( true );
  15650. state.setPolygonOffset( false );
  15651. // _gl.finish();
  15652. bindingStates.resetDefaultState();
  15653. _currentMaterialId = - 1;
  15654. _currentCamera = null;
  15655. renderStateStack.pop();
  15656. if ( renderStateStack.length > 0 ) {
  15657. currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
  15658. } else {
  15659. currentRenderState = null;
  15660. }
  15661. renderListStack.pop();
  15662. if ( renderListStack.length > 0 ) {
  15663. currentRenderList = renderListStack[ renderListStack.length - 1 ];
  15664. } else {
  15665. currentRenderList = null;
  15666. }
  15667. };
  15668. function projectObject( object, camera, groupOrder, sortObjects ) {
  15669. if ( object.visible === false ) return;
  15670. const visible = object.layers.test( camera.layers );
  15671. if ( visible ) {
  15672. if ( object.isGroup ) {
  15673. groupOrder = object.renderOrder;
  15674. } else if ( object.isLOD ) {
  15675. if ( object.autoUpdate === true ) object.update( camera );
  15676. } else if ( object.isLight ) {
  15677. currentRenderState.pushLight( object );
  15678. if ( object.castShadow ) {
  15679. currentRenderState.pushShadow( object );
  15680. }
  15681. } else if ( object.isSprite ) {
  15682. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  15683. if ( sortObjects ) {
  15684. _vector3.setFromMatrixPosition( object.matrixWorld )
  15685. .applyMatrix4( _projScreenMatrix );
  15686. }
  15687. const geometry = objects.update( object );
  15688. const material = object.material;
  15689. if ( material.visible ) {
  15690. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15691. }
  15692. }
  15693. } else if ( object.isImmediateRenderObject ) {
  15694. if ( sortObjects ) {
  15695. _vector3.setFromMatrixPosition( object.matrixWorld )
  15696. .applyMatrix4( _projScreenMatrix );
  15697. }
  15698. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  15699. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  15700. if ( object.isSkinnedMesh ) {
  15701. // update skeleton only once in a frame
  15702. if ( object.skeleton.frame !== info.render.frame ) {
  15703. object.skeleton.update();
  15704. object.skeleton.frame = info.render.frame;
  15705. }
  15706. }
  15707. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  15708. if ( sortObjects ) {
  15709. _vector3.setFromMatrixPosition( object.matrixWorld )
  15710. .applyMatrix4( _projScreenMatrix );
  15711. }
  15712. const geometry = objects.update( object );
  15713. const material = object.material;
  15714. if ( Array.isArray( material ) ) {
  15715. const groups = geometry.groups;
  15716. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  15717. const group = groups[ i ];
  15718. const groupMaterial = material[ group.materialIndex ];
  15719. if ( groupMaterial && groupMaterial.visible ) {
  15720. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  15721. }
  15722. }
  15723. } else if ( material.visible ) {
  15724. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15725. }
  15726. }
  15727. }
  15728. }
  15729. const children = object.children;
  15730. for ( let i = 0, l = children.length; i < l; i ++ ) {
  15731. projectObject( children[ i ], camera, groupOrder, sortObjects );
  15732. }
  15733. }
  15734. function renderScene( currentRenderList, scene, camera, viewport ) {
  15735. const opaqueObjects = currentRenderList.opaque;
  15736. const transmissiveObjects = currentRenderList.transmissive;
  15737. const transparentObjects = currentRenderList.transparent;
  15738. currentRenderState.setupLightsView( camera );
  15739. if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, scene, camera );
  15740. if ( viewport ) state.viewport( _currentViewport.copy( viewport ) );
  15741. if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
  15742. if ( transmissiveObjects.length > 0 ) renderObjects( transmissiveObjects, scene, camera );
  15743. if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
  15744. }
  15745. function renderTransmissionPass( opaqueObjects, scene, camera ) {
  15746. if ( _transmissionRenderTarget === null ) {
  15747. const needsAntialias = _antialias === true && capabilities.isWebGL2 === true;
  15748. const renderTargetType = needsAntialias ? WebGLMultisampleRenderTarget : WebGLRenderTarget;
  15749. _transmissionRenderTarget = new renderTargetType( 1024, 1024, {
  15750. generateMipmaps: true,
  15751. type: utils.convert( HalfFloatType ) !== null ? HalfFloatType : UnsignedByteType,
  15752. minFilter: LinearMipmapLinearFilter,
  15753. magFilter: NearestFilter,
  15754. wrapS: ClampToEdgeWrapping,
  15755. wrapT: ClampToEdgeWrapping
  15756. } );
  15757. }
  15758. const currentRenderTarget = _this.getRenderTarget();
  15759. _this.setRenderTarget( _transmissionRenderTarget );
  15760. _this.clear();
  15761. // Turn off the features which can affect the frag color for opaque objects pass.
  15762. // Otherwise they are applied twice in opaque objects pass and transmission objects pass.
  15763. const currentToneMapping = _this.toneMapping;
  15764. _this.toneMapping = NoToneMapping;
  15765. renderObjects( opaqueObjects, scene, camera );
  15766. _this.toneMapping = currentToneMapping;
  15767. textures.updateMultisampleRenderTarget( _transmissionRenderTarget );
  15768. textures.updateRenderTargetMipmap( _transmissionRenderTarget );
  15769. _this.setRenderTarget( currentRenderTarget );
  15770. }
  15771. function renderObjects( renderList, scene, camera ) {
  15772. const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15773. for ( let i = 0, l = renderList.length; i < l; i ++ ) {
  15774. const renderItem = renderList[ i ];
  15775. const object = renderItem.object;
  15776. const geometry = renderItem.geometry;
  15777. const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15778. const group = renderItem.group;
  15779. if ( object.layers.test( camera.layers ) ) {
  15780. renderObject( object, scene, camera, geometry, material, group );
  15781. }
  15782. }
  15783. }
  15784. function renderObject( object, scene, camera, geometry, material, group ) {
  15785. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  15786. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15787. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15788. material.onBeforeRender( _this, scene, camera, geometry, object, group );
  15789. if ( object.isImmediateRenderObject ) {
  15790. const program = setProgram( camera, scene, material, object );
  15791. state.setMaterial( material );
  15792. bindingStates.reset();
  15793. renderObjectImmediate( object, program );
  15794. } else {
  15795. if ( material.transparent === true && material.side === DoubleSide ) {
  15796. material.side = BackSide;
  15797. material.needsUpdate = true;
  15798. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15799. material.side = FrontSide;
  15800. material.needsUpdate = true;
  15801. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15802. material.side = DoubleSide;
  15803. } else {
  15804. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15805. }
  15806. }
  15807. object.onAfterRender( _this, scene, camera, geometry, material, group );
  15808. }
  15809. function getProgram( material, scene, object ) {
  15810. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15811. const materialProperties = properties.get( material );
  15812. const lights = currentRenderState.state.lights;
  15813. const shadowsArray = currentRenderState.state.shadowsArray;
  15814. const lightsStateVersion = lights.state.version;
  15815. const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
  15816. const programCacheKey = programCache.getProgramCacheKey( parameters );
  15817. let programs = materialProperties.programs;
  15818. // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
  15819. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15820. materialProperties.fog = scene.fog;
  15821. materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
  15822. if ( programs === undefined ) {
  15823. // new material
  15824. material.addEventListener( 'dispose', onMaterialDispose );
  15825. programs = new Map();
  15826. materialProperties.programs = programs;
  15827. }
  15828. let program = programs.get( programCacheKey );
  15829. if ( program !== undefined ) {
  15830. // early out if program and light state is identical
  15831. if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) {
  15832. updateCommonMaterialProperties( material, parameters );
  15833. return program;
  15834. }
  15835. } else {
  15836. parameters.uniforms = programCache.getUniforms( material );
  15837. material.onBuild( parameters, _this );
  15838. material.onBeforeCompile( parameters, _this );
  15839. program = programCache.acquireProgram( parameters, programCacheKey );
  15840. programs.set( programCacheKey, program );
  15841. materialProperties.uniforms = parameters.uniforms;
  15842. }
  15843. const uniforms = materialProperties.uniforms;
  15844. if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) {
  15845. uniforms.clippingPlanes = clipping.uniform;
  15846. }
  15847. updateCommonMaterialProperties( material, parameters );
  15848. // store the light setup it was created for
  15849. materialProperties.needsLights = materialNeedsLights( material );
  15850. materialProperties.lightsStateVersion = lightsStateVersion;
  15851. if ( materialProperties.needsLights ) {
  15852. // wire up the material to this renderer's lighting state
  15853. uniforms.ambientLightColor.value = lights.state.ambient;
  15854. uniforms.lightProbe.value = lights.state.probe;
  15855. uniforms.directionalLights.value = lights.state.directional;
  15856. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15857. uniforms.spotLights.value = lights.state.spot;
  15858. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15859. uniforms.rectAreaLights.value = lights.state.rectArea;
  15860. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15861. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15862. uniforms.pointLights.value = lights.state.point;
  15863. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15864. uniforms.hemisphereLights.value = lights.state.hemi;
  15865. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15866. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15867. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15868. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15869. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15870. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  15871. // TODO (abelnation): add area lights shadow info to uniforms
  15872. }
  15873. const progUniforms = program.getUniforms();
  15874. const uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15875. materialProperties.currentProgram = program;
  15876. materialProperties.uniformsList = uniformsList;
  15877. return program;
  15878. }
  15879. function updateCommonMaterialProperties( material, parameters ) {
  15880. const materialProperties = properties.get( material );
  15881. materialProperties.outputEncoding = parameters.outputEncoding;
  15882. materialProperties.instancing = parameters.instancing;
  15883. materialProperties.skinning = parameters.skinning;
  15884. materialProperties.morphTargets = parameters.morphTargets;
  15885. materialProperties.morphNormals = parameters.morphNormals;
  15886. materialProperties.morphTargetsCount = parameters.morphTargetsCount;
  15887. materialProperties.numClippingPlanes = parameters.numClippingPlanes;
  15888. materialProperties.numIntersection = parameters.numClipIntersection;
  15889. materialProperties.vertexAlphas = parameters.vertexAlphas;
  15890. materialProperties.vertexTangents = parameters.vertexTangents;
  15891. }
  15892. function setProgram( camera, scene, material, object ) {
  15893. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15894. textures.resetTextureUnits();
  15895. const fog = scene.fog;
  15896. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  15897. const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15898. const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
  15899. const vertexAlphas = material.vertexColors === true && !! object.geometry && !! object.geometry.attributes.color && object.geometry.attributes.color.itemSize === 4;
  15900. const vertexTangents = !! object.geometry && !! object.geometry.attributes.tangent;
  15901. const morphTargets = !! object.geometry && !! object.geometry.morphAttributes.position;
  15902. const morphNormals = !! object.geometry && !! object.geometry.morphAttributes.normal;
  15903. const morphTargetsCount = ( !! object.geometry && !! object.geometry.morphAttributes.position ) ? object.geometry.morphAttributes.position.length : 0;
  15904. const materialProperties = properties.get( material );
  15905. const lights = currentRenderState.state.lights;
  15906. if ( _clippingEnabled === true ) {
  15907. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  15908. const useCache =
  15909. camera === _currentCamera &&
  15910. material.id === _currentMaterialId;
  15911. // we might want to call this function with some ClippingGroup
  15912. // object instead of the material, once it becomes feasible
  15913. // (#8465, #8379)
  15914. clipping.setState( material, camera, useCache );
  15915. }
  15916. }
  15917. //
  15918. let needsProgramChange = false;
  15919. if ( material.version === materialProperties.__version ) {
  15920. if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  15921. needsProgramChange = true;
  15922. } else if ( materialProperties.outputEncoding !== encoding ) {
  15923. needsProgramChange = true;
  15924. } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
  15925. needsProgramChange = true;
  15926. } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) {
  15927. needsProgramChange = true;
  15928. } else if ( object.isSkinnedMesh && materialProperties.skinning === false ) {
  15929. needsProgramChange = true;
  15930. } else if ( ! object.isSkinnedMesh && materialProperties.skinning === true ) {
  15931. needsProgramChange = true;
  15932. } else if ( materialProperties.envMap !== envMap ) {
  15933. needsProgramChange = true;
  15934. } else if ( material.fog && materialProperties.fog !== fog ) {
  15935. needsProgramChange = true;
  15936. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15937. ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
  15938. materialProperties.numIntersection !== clipping.numIntersection ) ) {
  15939. needsProgramChange = true;
  15940. } else if ( materialProperties.vertexAlphas !== vertexAlphas ) {
  15941. needsProgramChange = true;
  15942. } else if ( materialProperties.vertexTangents !== vertexTangents ) {
  15943. needsProgramChange = true;
  15944. } else if ( materialProperties.morphTargets !== morphTargets ) {
  15945. needsProgramChange = true;
  15946. } else if ( materialProperties.morphNormals !== morphNormals ) {
  15947. needsProgramChange = true;
  15948. } else if ( capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount ) {
  15949. needsProgramChange = true;
  15950. }
  15951. } else {
  15952. needsProgramChange = true;
  15953. materialProperties.__version = material.version;
  15954. }
  15955. //
  15956. let program = materialProperties.currentProgram;
  15957. if ( needsProgramChange === true ) {
  15958. program = getProgram( material, scene, object );
  15959. }
  15960. let refreshProgram = false;
  15961. let refreshMaterial = false;
  15962. let refreshLights = false;
  15963. const p_uniforms = program.getUniforms(),
  15964. m_uniforms = materialProperties.uniforms;
  15965. if ( state.useProgram( program.program ) ) {
  15966. refreshProgram = true;
  15967. refreshMaterial = true;
  15968. refreshLights = true;
  15969. }
  15970. if ( material.id !== _currentMaterialId ) {
  15971. _currentMaterialId = material.id;
  15972. refreshMaterial = true;
  15973. }
  15974. if ( refreshProgram || _currentCamera !== camera ) {
  15975. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15976. if ( capabilities.logarithmicDepthBuffer ) {
  15977. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15978. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15979. }
  15980. if ( _currentCamera !== camera ) {
  15981. _currentCamera = camera;
  15982. // lighting uniforms depend on the camera so enforce an update
  15983. // now, in case this material supports lights - or later, when
  15984. // the next material that does gets activated:
  15985. refreshMaterial = true; // set to true on material change
  15986. refreshLights = true; // remains set until update done
  15987. }
  15988. // load material specific uniforms
  15989. // (shader material also gets them for the sake of genericity)
  15990. if ( material.isShaderMaterial ||
  15991. material.isMeshPhongMaterial ||
  15992. material.isMeshToonMaterial ||
  15993. material.isMeshStandardMaterial ||
  15994. material.envMap ) {
  15995. const uCamPos = p_uniforms.map.cameraPosition;
  15996. if ( uCamPos !== undefined ) {
  15997. uCamPos.setValue( _gl,
  15998. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15999. }
  16000. }
  16001. if ( material.isMeshPhongMaterial ||
  16002. material.isMeshToonMaterial ||
  16003. material.isMeshLambertMaterial ||
  16004. material.isMeshBasicMaterial ||
  16005. material.isMeshStandardMaterial ||
  16006. material.isShaderMaterial ) {
  16007. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  16008. }
  16009. if ( material.isMeshPhongMaterial ||
  16010. material.isMeshToonMaterial ||
  16011. material.isMeshLambertMaterial ||
  16012. material.isMeshBasicMaterial ||
  16013. material.isMeshStandardMaterial ||
  16014. material.isShaderMaterial ||
  16015. material.isShadowMaterial ||
  16016. object.isSkinnedMesh ) {
  16017. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  16018. }
  16019. }
  16020. // skinning uniforms must be set even if material didn't change
  16021. // auto-setting of texture unit for bone texture must go before other textures
  16022. // otherwise textures used for skinning can take over texture units reserved for other material textures
  16023. if ( object.isSkinnedMesh ) {
  16024. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  16025. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  16026. const skeleton = object.skeleton;
  16027. if ( skeleton ) {
  16028. if ( capabilities.floatVertexTextures ) {
  16029. if ( skeleton.boneTexture === null ) skeleton.computeBoneTexture();
  16030. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  16031. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  16032. } else {
  16033. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  16034. }
  16035. }
  16036. }
  16037. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  16038. materialProperties.receiveShadow = object.receiveShadow;
  16039. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  16040. }
  16041. if ( refreshMaterial ) {
  16042. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  16043. if ( materialProperties.needsLights ) {
  16044. // the current material requires lighting info
  16045. // note: all lighting uniforms are always set correctly
  16046. // they simply reference the renderer's state for their
  16047. // values
  16048. //
  16049. // use the current material's .needsUpdate flags to set
  16050. // the GL state when required
  16051. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  16052. }
  16053. // refresh uniforms common to several materials
  16054. if ( fog && material.fog ) {
  16055. materials.refreshFogUniforms( m_uniforms, fog );
  16056. }
  16057. materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget );
  16058. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  16059. }
  16060. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  16061. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  16062. material.uniformsNeedUpdate = false;
  16063. }
  16064. if ( material.isSpriteMaterial ) {
  16065. p_uniforms.setValue( _gl, 'center', object.center );
  16066. }
  16067. // common matrices
  16068. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  16069. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  16070. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  16071. return program;
  16072. }
  16073. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  16074. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  16075. uniforms.ambientLightColor.needsUpdate = value;
  16076. uniforms.lightProbe.needsUpdate = value;
  16077. uniforms.directionalLights.needsUpdate = value;
  16078. uniforms.directionalLightShadows.needsUpdate = value;
  16079. uniforms.pointLights.needsUpdate = value;
  16080. uniforms.pointLightShadows.needsUpdate = value;
  16081. uniforms.spotLights.needsUpdate = value;
  16082. uniforms.spotLightShadows.needsUpdate = value;
  16083. uniforms.rectAreaLights.needsUpdate = value;
  16084. uniforms.hemisphereLights.needsUpdate = value;
  16085. }
  16086. function materialNeedsLights( material ) {
  16087. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  16088. material.isMeshStandardMaterial || material.isShadowMaterial ||
  16089. ( material.isShaderMaterial && material.lights === true );
  16090. }
  16091. this.getActiveCubeFace = function () {
  16092. return _currentActiveCubeFace;
  16093. };
  16094. this.getActiveMipmapLevel = function () {
  16095. return _currentActiveMipmapLevel;
  16096. };
  16097. this.getRenderTarget = function () {
  16098. return _currentRenderTarget;
  16099. };
  16100. this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  16101. _currentRenderTarget = renderTarget;
  16102. _currentActiveCubeFace = activeCubeFace;
  16103. _currentActiveMipmapLevel = activeMipmapLevel;
  16104. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16105. textures.setupRenderTarget( renderTarget );
  16106. }
  16107. let framebuffer = null;
  16108. let isCube = false;
  16109. let isRenderTarget3D = false;
  16110. if ( renderTarget ) {
  16111. const texture = renderTarget.texture;
  16112. if ( texture.isDataTexture3D || texture.isDataTexture2DArray ) {
  16113. isRenderTarget3D = true;
  16114. }
  16115. const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16116. if ( renderTarget.isWebGLCubeRenderTarget ) {
  16117. framebuffer = __webglFramebuffer[ activeCubeFace ];
  16118. isCube = true;
  16119. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  16120. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  16121. } else {
  16122. framebuffer = __webglFramebuffer;
  16123. }
  16124. _currentViewport.copy( renderTarget.viewport );
  16125. _currentScissor.copy( renderTarget.scissor );
  16126. _currentScissorTest = renderTarget.scissorTest;
  16127. } else {
  16128. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  16129. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  16130. _currentScissorTest = _scissorTest;
  16131. }
  16132. const framebufferBound = state.bindFramebuffer( 36160, framebuffer );
  16133. if ( framebufferBound && capabilities.drawBuffers ) {
  16134. let needsUpdate = false;
  16135. if ( renderTarget ) {
  16136. if ( renderTarget.isWebGLMultipleRenderTargets ) {
  16137. const textures = renderTarget.texture;
  16138. if ( _currentDrawBuffers.length !== textures.length || _currentDrawBuffers[ 0 ] !== 36064 ) {
  16139. for ( let i = 0, il = textures.length; i < il; i ++ ) {
  16140. _currentDrawBuffers[ i ] = 36064 + i;
  16141. }
  16142. _currentDrawBuffers.length = textures.length;
  16143. needsUpdate = true;
  16144. }
  16145. } else {
  16146. if ( _currentDrawBuffers.length !== 1 || _currentDrawBuffers[ 0 ] !== 36064 ) {
  16147. _currentDrawBuffers[ 0 ] = 36064;
  16148. _currentDrawBuffers.length = 1;
  16149. needsUpdate = true;
  16150. }
  16151. }
  16152. } else {
  16153. if ( _currentDrawBuffers.length !== 1 || _currentDrawBuffers[ 0 ] !== 1029 ) {
  16154. _currentDrawBuffers[ 0 ] = 1029;
  16155. _currentDrawBuffers.length = 1;
  16156. needsUpdate = true;
  16157. }
  16158. }
  16159. if ( needsUpdate ) {
  16160. if ( capabilities.isWebGL2 ) {
  16161. _gl.drawBuffers( _currentDrawBuffers );
  16162. } else {
  16163. extensions.get( 'WEBGL_draw_buffers' ).drawBuffersWEBGL( _currentDrawBuffers );
  16164. }
  16165. }
  16166. }
  16167. state.viewport( _currentViewport );
  16168. state.scissor( _currentScissor );
  16169. state.setScissorTest( _currentScissorTest );
  16170. if ( isCube ) {
  16171. const textureProperties = properties.get( renderTarget.texture );
  16172. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
  16173. } else if ( isRenderTarget3D ) {
  16174. const textureProperties = properties.get( renderTarget.texture );
  16175. const layer = activeCubeFace || 0;
  16176. _gl.framebufferTextureLayer( 36160, 36064, textureProperties.__webglTexture, activeMipmapLevel || 0, layer );
  16177. }
  16178. _currentMaterialId = - 1; // reset current material to ensure correct uniform bindings
  16179. };
  16180. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  16181. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  16182. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16183. return;
  16184. }
  16185. let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16186. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  16187. framebuffer = framebuffer[ activeCubeFaceIndex ];
  16188. }
  16189. if ( framebuffer ) {
  16190. state.bindFramebuffer( 36160, framebuffer );
  16191. try {
  16192. const texture = renderTarget.texture;
  16193. const textureFormat = texture.format;
  16194. const textureType = texture.type;
  16195. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  16196. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16197. return;
  16198. }
  16199. const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ) );
  16200. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // Edge and Chrome Mac < 52 (#9513)
  16201. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.has( 'OES_texture_float' ) || extensions.has( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  16202. ! halfFloatSupportedByExt ) {
  16203. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16204. return;
  16205. }
  16206. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  16207. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16208. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16209. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  16210. }
  16211. } else {
  16212. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16213. }
  16214. } finally {
  16215. // restore framebuffer of current render target if necessary
  16216. const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
  16217. state.bindFramebuffer( 36160, framebuffer );
  16218. }
  16219. }
  16220. };
  16221. this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
  16222. const levelScale = Math.pow( 2, - level );
  16223. const width = Math.floor( texture.image.width * levelScale );
  16224. const height = Math.floor( texture.image.height * levelScale );
  16225. let glFormat = utils.convert( texture.format );
  16226. if ( capabilities.isWebGL2 ) {
  16227. // Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1120100
  16228. // Not needed in Chrome 93+
  16229. if ( glFormat === 6407 ) glFormat = 32849;
  16230. if ( glFormat === 6408 ) glFormat = 32856;
  16231. }
  16232. textures.setTexture2D( texture, 0 );
  16233. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  16234. state.unbindTexture();
  16235. };
  16236. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
  16237. const width = srcTexture.image.width;
  16238. const height = srcTexture.image.height;
  16239. const glFormat = utils.convert( dstTexture.format );
  16240. const glType = utils.convert( dstTexture.type );
  16241. textures.setTexture2D( dstTexture, 0 );
  16242. // As another texture upload may have changed pixelStorei
  16243. // parameters, make sure they are correct for the dstTexture
  16244. _gl.pixelStorei( 37440, dstTexture.flipY );
  16245. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  16246. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  16247. if ( srcTexture.isDataTexture ) {
  16248. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  16249. } else {
  16250. if ( srcTexture.isCompressedTexture ) {
  16251. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  16252. } else {
  16253. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  16254. }
  16255. }
  16256. // Generate mipmaps only when copying level 0
  16257. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  16258. state.unbindTexture();
  16259. };
  16260. this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
  16261. if ( _this.isWebGL1Renderer ) {
  16262. console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.' );
  16263. return;
  16264. }
  16265. const width = sourceBox.max.x - sourceBox.min.x + 1;
  16266. const height = sourceBox.max.y - sourceBox.min.y + 1;
  16267. const depth = sourceBox.max.z - sourceBox.min.z + 1;
  16268. const glFormat = utils.convert( dstTexture.format );
  16269. const glType = utils.convert( dstTexture.type );
  16270. let glTarget;
  16271. if ( dstTexture.isDataTexture3D ) {
  16272. textures.setTexture3D( dstTexture, 0 );
  16273. glTarget = 32879;
  16274. } else if ( dstTexture.isDataTexture2DArray ) {
  16275. textures.setTexture2DArray( dstTexture, 0 );
  16276. glTarget = 35866;
  16277. } else {
  16278. console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
  16279. return;
  16280. }
  16281. _gl.pixelStorei( 37440, dstTexture.flipY );
  16282. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  16283. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  16284. const unpackRowLen = _gl.getParameter( 3314 );
  16285. const unpackImageHeight = _gl.getParameter( 32878 );
  16286. const unpackSkipPixels = _gl.getParameter( 3316 );
  16287. const unpackSkipRows = _gl.getParameter( 3315 );
  16288. const unpackSkipImages = _gl.getParameter( 32877 );
  16289. const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ 0 ] : srcTexture.image;
  16290. _gl.pixelStorei( 3314, image.width );
  16291. _gl.pixelStorei( 32878, image.height );
  16292. _gl.pixelStorei( 3316, sourceBox.min.x );
  16293. _gl.pixelStorei( 3315, sourceBox.min.y );
  16294. _gl.pixelStorei( 32877, sourceBox.min.z );
  16295. if ( srcTexture.isDataTexture || srcTexture.isDataTexture3D ) {
  16296. _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
  16297. } else {
  16298. if ( srcTexture.isCompressedTexture ) {
  16299. console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture.' );
  16300. _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
  16301. } else {
  16302. _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
  16303. }
  16304. }
  16305. _gl.pixelStorei( 3314, unpackRowLen );
  16306. _gl.pixelStorei( 32878, unpackImageHeight );
  16307. _gl.pixelStorei( 3316, unpackSkipPixels );
  16308. _gl.pixelStorei( 3315, unpackSkipRows );
  16309. _gl.pixelStorei( 32877, unpackSkipImages );
  16310. // Generate mipmaps only when copying level 0
  16311. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
  16312. state.unbindTexture();
  16313. };
  16314. this.initTexture = function ( texture ) {
  16315. textures.setTexture2D( texture, 0 );
  16316. state.unbindTexture();
  16317. };
  16318. this.resetState = function () {
  16319. _currentActiveCubeFace = 0;
  16320. _currentActiveMipmapLevel = 0;
  16321. _currentRenderTarget = null;
  16322. state.reset();
  16323. bindingStates.reset();
  16324. };
  16325. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  16326. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  16327. }
  16328. }
  16329. class WebGL1Renderer extends WebGLRenderer {}
  16330. WebGL1Renderer.prototype.isWebGL1Renderer = true;
  16331. class FogExp2 {
  16332. constructor( color, density = 0.00025 ) {
  16333. this.name = '';
  16334. this.color = new Color( color );
  16335. this.density = density;
  16336. }
  16337. clone() {
  16338. return new FogExp2( this.color, this.density );
  16339. }
  16340. toJSON( /* meta */ ) {
  16341. return {
  16342. type: 'FogExp2',
  16343. color: this.color.getHex(),
  16344. density: this.density
  16345. };
  16346. }
  16347. }
  16348. FogExp2.prototype.isFogExp2 = true;
  16349. class Fog {
  16350. constructor( color, near = 1, far = 1000 ) {
  16351. this.name = '';
  16352. this.color = new Color( color );
  16353. this.near = near;
  16354. this.far = far;
  16355. }
  16356. clone() {
  16357. return new Fog( this.color, this.near, this.far );
  16358. }
  16359. toJSON( /* meta */ ) {
  16360. return {
  16361. type: 'Fog',
  16362. color: this.color.getHex(),
  16363. near: this.near,
  16364. far: this.far
  16365. };
  16366. }
  16367. }
  16368. Fog.prototype.isFog = true;
  16369. class Scene extends Object3D {
  16370. constructor() {
  16371. super();
  16372. this.type = 'Scene';
  16373. this.background = null;
  16374. this.environment = null;
  16375. this.fog = null;
  16376. this.overrideMaterial = null;
  16377. this.autoUpdate = true; // checked by the renderer
  16378. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  16379. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  16380. }
  16381. }
  16382. copy( source, recursive ) {
  16383. super.copy( source, recursive );
  16384. if ( source.background !== null ) this.background = source.background.clone();
  16385. if ( source.environment !== null ) this.environment = source.environment.clone();
  16386. if ( source.fog !== null ) this.fog = source.fog.clone();
  16387. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  16388. this.autoUpdate = source.autoUpdate;
  16389. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16390. return this;
  16391. }
  16392. toJSON( meta ) {
  16393. const data = super.toJSON( meta );
  16394. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  16395. return data;
  16396. }
  16397. }
  16398. Scene.prototype.isScene = true;
  16399. class InterleavedBuffer {
  16400. constructor( array, stride ) {
  16401. this.array = array;
  16402. this.stride = stride;
  16403. this.count = array !== undefined ? array.length / stride : 0;
  16404. this.usage = StaticDrawUsage;
  16405. this.updateRange = { offset: 0, count: - 1 };
  16406. this.version = 0;
  16407. this.uuid = generateUUID();
  16408. }
  16409. onUploadCallback() {}
  16410. set needsUpdate( value ) {
  16411. if ( value === true ) this.version ++;
  16412. }
  16413. setUsage( value ) {
  16414. this.usage = value;
  16415. return this;
  16416. }
  16417. copy( source ) {
  16418. this.array = new source.array.constructor( source.array );
  16419. this.count = source.count;
  16420. this.stride = source.stride;
  16421. this.usage = source.usage;
  16422. return this;
  16423. }
  16424. copyAt( index1, attribute, index2 ) {
  16425. index1 *= this.stride;
  16426. index2 *= attribute.stride;
  16427. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  16428. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  16429. }
  16430. return this;
  16431. }
  16432. set( value, offset = 0 ) {
  16433. this.array.set( value, offset );
  16434. return this;
  16435. }
  16436. clone( data ) {
  16437. if ( data.arrayBuffers === undefined ) {
  16438. data.arrayBuffers = {};
  16439. }
  16440. if ( this.array.buffer._uuid === undefined ) {
  16441. this.array.buffer._uuid = generateUUID();
  16442. }
  16443. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16444. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  16445. }
  16446. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  16447. const ib = new this.constructor( array, this.stride );
  16448. ib.setUsage( this.usage );
  16449. return ib;
  16450. }
  16451. onUpload( callback ) {
  16452. this.onUploadCallback = callback;
  16453. return this;
  16454. }
  16455. toJSON( data ) {
  16456. if ( data.arrayBuffers === undefined ) {
  16457. data.arrayBuffers = {};
  16458. }
  16459. // generate UUID for array buffer if necessary
  16460. if ( this.array.buffer._uuid === undefined ) {
  16461. this.array.buffer._uuid = generateUUID();
  16462. }
  16463. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16464. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  16465. }
  16466. //
  16467. return {
  16468. uuid: this.uuid,
  16469. buffer: this.array.buffer._uuid,
  16470. type: this.array.constructor.name,
  16471. stride: this.stride
  16472. };
  16473. }
  16474. }
  16475. InterleavedBuffer.prototype.isInterleavedBuffer = true;
  16476. const _vector$6 = /*@__PURE__*/ new Vector3();
  16477. class InterleavedBufferAttribute {
  16478. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  16479. this.name = '';
  16480. this.data = interleavedBuffer;
  16481. this.itemSize = itemSize;
  16482. this.offset = offset;
  16483. this.normalized = normalized === true;
  16484. }
  16485. get count() {
  16486. return this.data.count;
  16487. }
  16488. get array() {
  16489. return this.data.array;
  16490. }
  16491. set needsUpdate( value ) {
  16492. this.data.needsUpdate = value;
  16493. }
  16494. applyMatrix4( m ) {
  16495. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  16496. _vector$6.x = this.getX( i );
  16497. _vector$6.y = this.getY( i );
  16498. _vector$6.z = this.getZ( i );
  16499. _vector$6.applyMatrix4( m );
  16500. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  16501. }
  16502. return this;
  16503. }
  16504. applyNormalMatrix( m ) {
  16505. for ( let i = 0, l = this.count; i < l; i ++ ) {
  16506. _vector$6.x = this.getX( i );
  16507. _vector$6.y = this.getY( i );
  16508. _vector$6.z = this.getZ( i );
  16509. _vector$6.applyNormalMatrix( m );
  16510. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  16511. }
  16512. return this;
  16513. }
  16514. transformDirection( m ) {
  16515. for ( let i = 0, l = this.count; i < l; i ++ ) {
  16516. _vector$6.x = this.getX( i );
  16517. _vector$6.y = this.getY( i );
  16518. _vector$6.z = this.getZ( i );
  16519. _vector$6.transformDirection( m );
  16520. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  16521. }
  16522. return this;
  16523. }
  16524. setX( index, x ) {
  16525. this.data.array[ index * this.data.stride + this.offset ] = x;
  16526. return this;
  16527. }
  16528. setY( index, y ) {
  16529. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16530. return this;
  16531. }
  16532. setZ( index, z ) {
  16533. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16534. return this;
  16535. }
  16536. setW( index, w ) {
  16537. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16538. return this;
  16539. }
  16540. getX( index ) {
  16541. return this.data.array[ index * this.data.stride + this.offset ];
  16542. }
  16543. getY( index ) {
  16544. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16545. }
  16546. getZ( index ) {
  16547. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16548. }
  16549. getW( index ) {
  16550. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16551. }
  16552. setXY( index, x, y ) {
  16553. index = index * this.data.stride + this.offset;
  16554. this.data.array[ index + 0 ] = x;
  16555. this.data.array[ index + 1 ] = y;
  16556. return this;
  16557. }
  16558. setXYZ( index, x, y, z ) {
  16559. index = index * this.data.stride + this.offset;
  16560. this.data.array[ index + 0 ] = x;
  16561. this.data.array[ index + 1 ] = y;
  16562. this.data.array[ index + 2 ] = z;
  16563. return this;
  16564. }
  16565. setXYZW( index, x, y, z, w ) {
  16566. index = index * this.data.stride + this.offset;
  16567. this.data.array[ index + 0 ] = x;
  16568. this.data.array[ index + 1 ] = y;
  16569. this.data.array[ index + 2 ] = z;
  16570. this.data.array[ index + 3 ] = w;
  16571. return this;
  16572. }
  16573. clone( data ) {
  16574. if ( data === undefined ) {
  16575. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  16576. const array = [];
  16577. for ( let i = 0; i < this.count; i ++ ) {
  16578. const index = i * this.data.stride + this.offset;
  16579. for ( let j = 0; j < this.itemSize; j ++ ) {
  16580. array.push( this.data.array[ index + j ] );
  16581. }
  16582. }
  16583. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  16584. } else {
  16585. if ( data.interleavedBuffers === undefined ) {
  16586. data.interleavedBuffers = {};
  16587. }
  16588. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16589. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  16590. }
  16591. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  16592. }
  16593. }
  16594. toJSON( data ) {
  16595. if ( data === undefined ) {
  16596. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  16597. const array = [];
  16598. for ( let i = 0; i < this.count; i ++ ) {
  16599. const index = i * this.data.stride + this.offset;
  16600. for ( let j = 0; j < this.itemSize; j ++ ) {
  16601. array.push( this.data.array[ index + j ] );
  16602. }
  16603. }
  16604. // deinterleave data and save it as an ordinary buffer attribute for now
  16605. return {
  16606. itemSize: this.itemSize,
  16607. type: this.array.constructor.name,
  16608. array: array,
  16609. normalized: this.normalized
  16610. };
  16611. } else {
  16612. // save as true interlaved attribtue
  16613. if ( data.interleavedBuffers === undefined ) {
  16614. data.interleavedBuffers = {};
  16615. }
  16616. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16617. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  16618. }
  16619. return {
  16620. isInterleavedBufferAttribute: true,
  16621. itemSize: this.itemSize,
  16622. data: this.data.uuid,
  16623. offset: this.offset,
  16624. normalized: this.normalized
  16625. };
  16626. }
  16627. }
  16628. }
  16629. InterleavedBufferAttribute.prototype.isInterleavedBufferAttribute = true;
  16630. /**
  16631. * parameters = {
  16632. * color: <hex>,
  16633. * map: new THREE.Texture( <Image> ),
  16634. * alphaMap: new THREE.Texture( <Image> ),
  16635. * rotation: <float>,
  16636. * sizeAttenuation: <bool>
  16637. * }
  16638. */
  16639. class SpriteMaterial extends Material {
  16640. constructor( parameters ) {
  16641. super();
  16642. this.type = 'SpriteMaterial';
  16643. this.color = new Color( 0xffffff );
  16644. this.map = null;
  16645. this.alphaMap = null;
  16646. this.rotation = 0;
  16647. this.sizeAttenuation = true;
  16648. this.transparent = true;
  16649. this.setValues( parameters );
  16650. }
  16651. copy( source ) {
  16652. super.copy( source );
  16653. this.color.copy( source.color );
  16654. this.map = source.map;
  16655. this.alphaMap = source.alphaMap;
  16656. this.rotation = source.rotation;
  16657. this.sizeAttenuation = source.sizeAttenuation;
  16658. return this;
  16659. }
  16660. }
  16661. SpriteMaterial.prototype.isSpriteMaterial = true;
  16662. let _geometry;
  16663. const _intersectPoint = /*@__PURE__*/ new Vector3();
  16664. const _worldScale = /*@__PURE__*/ new Vector3();
  16665. const _mvPosition = /*@__PURE__*/ new Vector3();
  16666. const _alignedPosition = /*@__PURE__*/ new Vector2();
  16667. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  16668. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  16669. const _vA = /*@__PURE__*/ new Vector3();
  16670. const _vB = /*@__PURE__*/ new Vector3();
  16671. const _vC = /*@__PURE__*/ new Vector3();
  16672. const _uvA = /*@__PURE__*/ new Vector2();
  16673. const _uvB = /*@__PURE__*/ new Vector2();
  16674. const _uvC = /*@__PURE__*/ new Vector2();
  16675. class Sprite extends Object3D {
  16676. constructor( material ) {
  16677. super();
  16678. this.type = 'Sprite';
  16679. if ( _geometry === undefined ) {
  16680. _geometry = new BufferGeometry();
  16681. const float32Array = new Float32Array( [
  16682. - 0.5, - 0.5, 0, 0, 0,
  16683. 0.5, - 0.5, 0, 1, 0,
  16684. 0.5, 0.5, 0, 1, 1,
  16685. - 0.5, 0.5, 0, 0, 1
  16686. ] );
  16687. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  16688. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  16689. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  16690. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  16691. }
  16692. this.geometry = _geometry;
  16693. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  16694. this.center = new Vector2( 0.5, 0.5 );
  16695. }
  16696. raycast( raycaster, intersects ) {
  16697. if ( raycaster.camera === null ) {
  16698. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  16699. }
  16700. _worldScale.setFromMatrixScale( this.matrixWorld );
  16701. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  16702. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  16703. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  16704. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  16705. _worldScale.multiplyScalar( - _mvPosition.z );
  16706. }
  16707. const rotation = this.material.rotation;
  16708. let sin, cos;
  16709. if ( rotation !== 0 ) {
  16710. cos = Math.cos( rotation );
  16711. sin = Math.sin( rotation );
  16712. }
  16713. const center = this.center;
  16714. transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16715. transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16716. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16717. _uvA.set( 0, 0 );
  16718. _uvB.set( 1, 0 );
  16719. _uvC.set( 1, 1 );
  16720. // check first triangle
  16721. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  16722. if ( intersect === null ) {
  16723. // check second triangle
  16724. transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16725. _uvB.set( 0, 1 );
  16726. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  16727. if ( intersect === null ) {
  16728. return;
  16729. }
  16730. }
  16731. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  16732. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16733. intersects.push( {
  16734. distance: distance,
  16735. point: _intersectPoint.clone(),
  16736. uv: Triangle.getUV( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  16737. face: null,
  16738. object: this
  16739. } );
  16740. }
  16741. copy( source ) {
  16742. super.copy( source );
  16743. if ( source.center !== undefined ) this.center.copy( source.center );
  16744. this.material = source.material;
  16745. return this;
  16746. }
  16747. }
  16748. Sprite.prototype.isSprite = true;
  16749. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  16750. // compute position in camera space
  16751. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  16752. // to check if rotation is not zero
  16753. if ( sin !== undefined ) {
  16754. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  16755. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  16756. } else {
  16757. _rotatedPosition.copy( _alignedPosition );
  16758. }
  16759. vertexPosition.copy( mvPosition );
  16760. vertexPosition.x += _rotatedPosition.x;
  16761. vertexPosition.y += _rotatedPosition.y;
  16762. // transform to world space
  16763. vertexPosition.applyMatrix4( _viewWorldMatrix );
  16764. }
  16765. const _v1$2 = /*@__PURE__*/ new Vector3();
  16766. const _v2$1 = /*@__PURE__*/ new Vector3();
  16767. class LOD extends Object3D {
  16768. constructor() {
  16769. super();
  16770. this._currentLevel = 0;
  16771. this.type = 'LOD';
  16772. Object.defineProperties( this, {
  16773. levels: {
  16774. enumerable: true,
  16775. value: []
  16776. },
  16777. isLOD: {
  16778. value: true,
  16779. }
  16780. } );
  16781. this.autoUpdate = true;
  16782. }
  16783. copy( source ) {
  16784. super.copy( source, false );
  16785. const levels = source.levels;
  16786. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  16787. const level = levels[ i ];
  16788. this.addLevel( level.object.clone(), level.distance );
  16789. }
  16790. this.autoUpdate = source.autoUpdate;
  16791. return this;
  16792. }
  16793. addLevel( object, distance = 0 ) {
  16794. distance = Math.abs( distance );
  16795. const levels = this.levels;
  16796. let l;
  16797. for ( l = 0; l < levels.length; l ++ ) {
  16798. if ( distance < levels[ l ].distance ) {
  16799. break;
  16800. }
  16801. }
  16802. levels.splice( l, 0, { distance: distance, object: object } );
  16803. this.add( object );
  16804. return this;
  16805. }
  16806. getCurrentLevel() {
  16807. return this._currentLevel;
  16808. }
  16809. getObjectForDistance( distance ) {
  16810. const levels = this.levels;
  16811. if ( levels.length > 0 ) {
  16812. let i, l;
  16813. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16814. if ( distance < levels[ i ].distance ) {
  16815. break;
  16816. }
  16817. }
  16818. return levels[ i - 1 ].object;
  16819. }
  16820. return null;
  16821. }
  16822. raycast( raycaster, intersects ) {
  16823. const levels = this.levels;
  16824. if ( levels.length > 0 ) {
  16825. _v1$2.setFromMatrixPosition( this.matrixWorld );
  16826. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  16827. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16828. }
  16829. }
  16830. update( camera ) {
  16831. const levels = this.levels;
  16832. if ( levels.length > 1 ) {
  16833. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  16834. _v2$1.setFromMatrixPosition( this.matrixWorld );
  16835. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  16836. levels[ 0 ].object.visible = true;
  16837. let i, l;
  16838. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16839. if ( distance >= levels[ i ].distance ) {
  16840. levels[ i - 1 ].object.visible = false;
  16841. levels[ i ].object.visible = true;
  16842. } else {
  16843. break;
  16844. }
  16845. }
  16846. this._currentLevel = i - 1;
  16847. for ( ; i < l; i ++ ) {
  16848. levels[ i ].object.visible = false;
  16849. }
  16850. }
  16851. }
  16852. toJSON( meta ) {
  16853. const data = super.toJSON( meta );
  16854. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  16855. data.object.levels = [];
  16856. const levels = this.levels;
  16857. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  16858. const level = levels[ i ];
  16859. data.object.levels.push( {
  16860. object: level.object.uuid,
  16861. distance: level.distance
  16862. } );
  16863. }
  16864. return data;
  16865. }
  16866. }
  16867. const _basePosition = /*@__PURE__*/ new Vector3();
  16868. const _skinIndex = /*@__PURE__*/ new Vector4();
  16869. const _skinWeight = /*@__PURE__*/ new Vector4();
  16870. const _vector$5 = /*@__PURE__*/ new Vector3();
  16871. const _matrix = /*@__PURE__*/ new Matrix4();
  16872. class SkinnedMesh extends Mesh {
  16873. constructor( geometry, material ) {
  16874. super( geometry, material );
  16875. this.type = 'SkinnedMesh';
  16876. this.bindMode = 'attached';
  16877. this.bindMatrix = new Matrix4();
  16878. this.bindMatrixInverse = new Matrix4();
  16879. }
  16880. copy( source ) {
  16881. super.copy( source );
  16882. this.bindMode = source.bindMode;
  16883. this.bindMatrix.copy( source.bindMatrix );
  16884. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  16885. this.skeleton = source.skeleton;
  16886. return this;
  16887. }
  16888. bind( skeleton, bindMatrix ) {
  16889. this.skeleton = skeleton;
  16890. if ( bindMatrix === undefined ) {
  16891. this.updateMatrixWorld( true );
  16892. this.skeleton.calculateInverses();
  16893. bindMatrix = this.matrixWorld;
  16894. }
  16895. this.bindMatrix.copy( bindMatrix );
  16896. this.bindMatrixInverse.copy( bindMatrix ).invert();
  16897. }
  16898. pose() {
  16899. this.skeleton.pose();
  16900. }
  16901. normalizeSkinWeights() {
  16902. const vector = new Vector4();
  16903. const skinWeight = this.geometry.attributes.skinWeight;
  16904. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  16905. vector.x = skinWeight.getX( i );
  16906. vector.y = skinWeight.getY( i );
  16907. vector.z = skinWeight.getZ( i );
  16908. vector.w = skinWeight.getW( i );
  16909. const scale = 1.0 / vector.manhattanLength();
  16910. if ( scale !== Infinity ) {
  16911. vector.multiplyScalar( scale );
  16912. } else {
  16913. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16914. }
  16915. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16916. }
  16917. }
  16918. updateMatrixWorld( force ) {
  16919. super.updateMatrixWorld( force );
  16920. if ( this.bindMode === 'attached' ) {
  16921. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  16922. } else if ( this.bindMode === 'detached' ) {
  16923. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  16924. } else {
  16925. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16926. }
  16927. }
  16928. boneTransform( index, target ) {
  16929. const skeleton = this.skeleton;
  16930. const geometry = this.geometry;
  16931. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  16932. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  16933. _basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  16934. target.set( 0, 0, 0 );
  16935. for ( let i = 0; i < 4; i ++ ) {
  16936. const weight = _skinWeight.getComponent( i );
  16937. if ( weight !== 0 ) {
  16938. const boneIndex = _skinIndex.getComponent( i );
  16939. _matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  16940. target.addScaledVector( _vector$5.copy( _basePosition ).applyMatrix4( _matrix ), weight );
  16941. }
  16942. }
  16943. return target.applyMatrix4( this.bindMatrixInverse );
  16944. }
  16945. }
  16946. SkinnedMesh.prototype.isSkinnedMesh = true;
  16947. class Bone extends Object3D {
  16948. constructor() {
  16949. super();
  16950. this.type = 'Bone';
  16951. }
  16952. }
  16953. Bone.prototype.isBone = true;
  16954. class DataTexture extends Texture {
  16955. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, encoding ) {
  16956. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16957. this.image = { data: data, width: width, height: height };
  16958. this.magFilter = magFilter;
  16959. this.minFilter = minFilter;
  16960. this.generateMipmaps = false;
  16961. this.flipY = false;
  16962. this.unpackAlignment = 1;
  16963. this.needsUpdate = true;
  16964. }
  16965. }
  16966. DataTexture.prototype.isDataTexture = true;
  16967. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  16968. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  16969. class Skeleton {
  16970. constructor( bones = [], boneInverses = [] ) {
  16971. this.uuid = generateUUID();
  16972. this.bones = bones.slice( 0 );
  16973. this.boneInverses = boneInverses;
  16974. this.boneMatrices = null;
  16975. this.boneTexture = null;
  16976. this.boneTextureSize = 0;
  16977. this.frame = - 1;
  16978. this.init();
  16979. }
  16980. init() {
  16981. const bones = this.bones;
  16982. const boneInverses = this.boneInverses;
  16983. this.boneMatrices = new Float32Array( bones.length * 16 );
  16984. // calculate inverse bone matrices if necessary
  16985. if ( boneInverses.length === 0 ) {
  16986. this.calculateInverses();
  16987. } else {
  16988. // handle special case
  16989. if ( bones.length !== boneInverses.length ) {
  16990. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  16991. this.boneInverses = [];
  16992. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16993. this.boneInverses.push( new Matrix4() );
  16994. }
  16995. }
  16996. }
  16997. }
  16998. calculateInverses() {
  16999. this.boneInverses.length = 0;
  17000. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  17001. const inverse = new Matrix4();
  17002. if ( this.bones[ i ] ) {
  17003. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  17004. }
  17005. this.boneInverses.push( inverse );
  17006. }
  17007. }
  17008. pose() {
  17009. // recover the bind-time world matrices
  17010. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  17011. const bone = this.bones[ i ];
  17012. if ( bone ) {
  17013. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  17014. }
  17015. }
  17016. // compute the local matrices, positions, rotations and scales
  17017. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  17018. const bone = this.bones[ i ];
  17019. if ( bone ) {
  17020. if ( bone.parent && bone.parent.isBone ) {
  17021. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  17022. bone.matrix.multiply( bone.matrixWorld );
  17023. } else {
  17024. bone.matrix.copy( bone.matrixWorld );
  17025. }
  17026. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  17027. }
  17028. }
  17029. }
  17030. update() {
  17031. const bones = this.bones;
  17032. const boneInverses = this.boneInverses;
  17033. const boneMatrices = this.boneMatrices;
  17034. const boneTexture = this.boneTexture;
  17035. // flatten bone matrices to array
  17036. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  17037. // compute the offset between the current and the original transform
  17038. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  17039. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  17040. _offsetMatrix.toArray( boneMatrices, i * 16 );
  17041. }
  17042. if ( boneTexture !== null ) {
  17043. boneTexture.needsUpdate = true;
  17044. }
  17045. }
  17046. clone() {
  17047. return new Skeleton( this.bones, this.boneInverses );
  17048. }
  17049. computeBoneTexture() {
  17050. // layout (1 matrix = 4 pixels)
  17051. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  17052. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  17053. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  17054. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  17055. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  17056. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  17057. size = ceilPowerOfTwo( size );
  17058. size = Math.max( size, 4 );
  17059. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  17060. boneMatrices.set( this.boneMatrices ); // copy current values
  17061. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  17062. this.boneMatrices = boneMatrices;
  17063. this.boneTexture = boneTexture;
  17064. this.boneTextureSize = size;
  17065. return this;
  17066. }
  17067. getBoneByName( name ) {
  17068. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  17069. const bone = this.bones[ i ];
  17070. if ( bone.name === name ) {
  17071. return bone;
  17072. }
  17073. }
  17074. return undefined;
  17075. }
  17076. dispose( ) {
  17077. if ( this.boneTexture !== null ) {
  17078. this.boneTexture.dispose();
  17079. this.boneTexture = null;
  17080. }
  17081. }
  17082. fromJSON( json, bones ) {
  17083. this.uuid = json.uuid;
  17084. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  17085. const uuid = json.bones[ i ];
  17086. let bone = bones[ uuid ];
  17087. if ( bone === undefined ) {
  17088. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  17089. bone = new Bone();
  17090. }
  17091. this.bones.push( bone );
  17092. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  17093. }
  17094. this.init();
  17095. return this;
  17096. }
  17097. toJSON() {
  17098. const data = {
  17099. metadata: {
  17100. version: 4.5,
  17101. type: 'Skeleton',
  17102. generator: 'Skeleton.toJSON'
  17103. },
  17104. bones: [],
  17105. boneInverses: []
  17106. };
  17107. data.uuid = this.uuid;
  17108. const bones = this.bones;
  17109. const boneInverses = this.boneInverses;
  17110. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  17111. const bone = bones[ i ];
  17112. data.bones.push( bone.uuid );
  17113. const boneInverse = boneInverses[ i ];
  17114. data.boneInverses.push( boneInverse.toArray() );
  17115. }
  17116. return data;
  17117. }
  17118. }
  17119. class InstancedBufferAttribute extends BufferAttribute {
  17120. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  17121. if ( typeof normalized === 'number' ) {
  17122. meshPerAttribute = normalized;
  17123. normalized = false;
  17124. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  17125. }
  17126. super( array, itemSize, normalized );
  17127. this.meshPerAttribute = meshPerAttribute;
  17128. }
  17129. copy( source ) {
  17130. super.copy( source );
  17131. this.meshPerAttribute = source.meshPerAttribute;
  17132. return this;
  17133. }
  17134. toJSON() {
  17135. const data = super.toJSON();
  17136. data.meshPerAttribute = this.meshPerAttribute;
  17137. data.isInstancedBufferAttribute = true;
  17138. return data;
  17139. }
  17140. }
  17141. InstancedBufferAttribute.prototype.isInstancedBufferAttribute = true;
  17142. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  17143. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  17144. const _instanceIntersects = [];
  17145. const _mesh = /*@__PURE__*/ new Mesh();
  17146. class InstancedMesh extends Mesh {
  17147. constructor( geometry, material, count ) {
  17148. super( geometry, material );
  17149. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  17150. this.instanceColor = null;
  17151. this.count = count;
  17152. this.frustumCulled = false;
  17153. }
  17154. copy( source ) {
  17155. super.copy( source );
  17156. this.instanceMatrix.copy( source.instanceMatrix );
  17157. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  17158. this.count = source.count;
  17159. return this;
  17160. }
  17161. getColorAt( index, color ) {
  17162. color.fromArray( this.instanceColor.array, index * 3 );
  17163. }
  17164. getMatrixAt( index, matrix ) {
  17165. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  17166. }
  17167. raycast( raycaster, intersects ) {
  17168. const matrixWorld = this.matrixWorld;
  17169. const raycastTimes = this.count;
  17170. _mesh.geometry = this.geometry;
  17171. _mesh.material = this.material;
  17172. if ( _mesh.material === undefined ) return;
  17173. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  17174. // calculate the world matrix for each instance
  17175. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  17176. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  17177. // the mesh represents this single instance
  17178. _mesh.matrixWorld = _instanceWorldMatrix;
  17179. _mesh.raycast( raycaster, _instanceIntersects );
  17180. // process the result of raycast
  17181. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  17182. const intersect = _instanceIntersects[ i ];
  17183. intersect.instanceId = instanceId;
  17184. intersect.object = this;
  17185. intersects.push( intersect );
  17186. }
  17187. _instanceIntersects.length = 0;
  17188. }
  17189. }
  17190. setColorAt( index, color ) {
  17191. if ( this.instanceColor === null ) {
  17192. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ), 3 );
  17193. }
  17194. color.toArray( this.instanceColor.array, index * 3 );
  17195. }
  17196. setMatrixAt( index, matrix ) {
  17197. matrix.toArray( this.instanceMatrix.array, index * 16 );
  17198. }
  17199. updateMorphTargets() {
  17200. }
  17201. dispose() {
  17202. this.dispatchEvent( { type: 'dispose' } );
  17203. }
  17204. }
  17205. InstancedMesh.prototype.isInstancedMesh = true;
  17206. /**
  17207. * parameters = {
  17208. * color: <hex>,
  17209. * opacity: <float>,
  17210. *
  17211. * linewidth: <float>,
  17212. * linecap: "round",
  17213. * linejoin: "round"
  17214. * }
  17215. */
  17216. class LineBasicMaterial extends Material {
  17217. constructor( parameters ) {
  17218. super();
  17219. this.type = 'LineBasicMaterial';
  17220. this.color = new Color( 0xffffff );
  17221. this.linewidth = 1;
  17222. this.linecap = 'round';
  17223. this.linejoin = 'round';
  17224. this.setValues( parameters );
  17225. }
  17226. copy( source ) {
  17227. super.copy( source );
  17228. this.color.copy( source.color );
  17229. this.linewidth = source.linewidth;
  17230. this.linecap = source.linecap;
  17231. this.linejoin = source.linejoin;
  17232. return this;
  17233. }
  17234. }
  17235. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  17236. const _start$1 = /*@__PURE__*/ new Vector3();
  17237. const _end$1 = /*@__PURE__*/ new Vector3();
  17238. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  17239. const _ray$1 = /*@__PURE__*/ new Ray();
  17240. const _sphere$1 = /*@__PURE__*/ new Sphere();
  17241. class Line extends Object3D {
  17242. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  17243. super();
  17244. this.type = 'Line';
  17245. this.geometry = geometry;
  17246. this.material = material;
  17247. this.updateMorphTargets();
  17248. }
  17249. copy( source ) {
  17250. super.copy( source );
  17251. this.material = source.material;
  17252. this.geometry = source.geometry;
  17253. return this;
  17254. }
  17255. computeLineDistances() {
  17256. const geometry = this.geometry;
  17257. if ( geometry.isBufferGeometry ) {
  17258. // we assume non-indexed geometry
  17259. if ( geometry.index === null ) {
  17260. const positionAttribute = geometry.attributes.position;
  17261. const lineDistances = [ 0 ];
  17262. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  17263. _start$1.fromBufferAttribute( positionAttribute, i - 1 );
  17264. _end$1.fromBufferAttribute( positionAttribute, i );
  17265. lineDistances[ i ] = lineDistances[ i - 1 ];
  17266. lineDistances[ i ] += _start$1.distanceTo( _end$1 );
  17267. }
  17268. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  17269. } else {
  17270. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  17271. }
  17272. } else if ( geometry.isGeometry ) {
  17273. console.error( 'THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17274. }
  17275. return this;
  17276. }
  17277. raycast( raycaster, intersects ) {
  17278. const geometry = this.geometry;
  17279. const matrixWorld = this.matrixWorld;
  17280. const threshold = raycaster.params.Line.threshold;
  17281. const drawRange = geometry.drawRange;
  17282. // Checking boundingSphere distance to ray
  17283. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  17284. _sphere$1.copy( geometry.boundingSphere );
  17285. _sphere$1.applyMatrix4( matrixWorld );
  17286. _sphere$1.radius += threshold;
  17287. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  17288. //
  17289. _inverseMatrix$1.copy( matrixWorld ).invert();
  17290. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  17291. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  17292. const localThresholdSq = localThreshold * localThreshold;
  17293. const vStart = new Vector3();
  17294. const vEnd = new Vector3();
  17295. const interSegment = new Vector3();
  17296. const interRay = new Vector3();
  17297. const step = this.isLineSegments ? 2 : 1;
  17298. if ( geometry.isBufferGeometry ) {
  17299. const index = geometry.index;
  17300. const attributes = geometry.attributes;
  17301. const positionAttribute = attributes.position;
  17302. if ( index !== null ) {
  17303. const start = Math.max( 0, drawRange.start );
  17304. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  17305. for ( let i = start, l = end - 1; i < l; i += step ) {
  17306. const a = index.getX( i );
  17307. const b = index.getX( i + 1 );
  17308. vStart.fromBufferAttribute( positionAttribute, a );
  17309. vEnd.fromBufferAttribute( positionAttribute, b );
  17310. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  17311. if ( distSq > localThresholdSq ) continue;
  17312. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  17313. const distance = raycaster.ray.origin.distanceTo( interRay );
  17314. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  17315. intersects.push( {
  17316. distance: distance,
  17317. // What do we want? intersection point on the ray or on the segment??
  17318. // point: raycaster.ray.at( distance ),
  17319. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  17320. index: i,
  17321. face: null,
  17322. faceIndex: null,
  17323. object: this
  17324. } );
  17325. }
  17326. } else {
  17327. const start = Math.max( 0, drawRange.start );
  17328. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  17329. for ( let i = start, l = end - 1; i < l; i += step ) {
  17330. vStart.fromBufferAttribute( positionAttribute, i );
  17331. vEnd.fromBufferAttribute( positionAttribute, i + 1 );
  17332. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  17333. if ( distSq > localThresholdSq ) continue;
  17334. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  17335. const distance = raycaster.ray.origin.distanceTo( interRay );
  17336. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  17337. intersects.push( {
  17338. distance: distance,
  17339. // What do we want? intersection point on the ray or on the segment??
  17340. // point: raycaster.ray.at( distance ),
  17341. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  17342. index: i,
  17343. face: null,
  17344. faceIndex: null,
  17345. object: this
  17346. } );
  17347. }
  17348. }
  17349. } else if ( geometry.isGeometry ) {
  17350. console.error( 'THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17351. }
  17352. }
  17353. updateMorphTargets() {
  17354. const geometry = this.geometry;
  17355. if ( geometry.isBufferGeometry ) {
  17356. const morphAttributes = geometry.morphAttributes;
  17357. const keys = Object.keys( morphAttributes );
  17358. if ( keys.length > 0 ) {
  17359. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  17360. if ( morphAttribute !== undefined ) {
  17361. this.morphTargetInfluences = [];
  17362. this.morphTargetDictionary = {};
  17363. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  17364. const name = morphAttribute[ m ].name || String( m );
  17365. this.morphTargetInfluences.push( 0 );
  17366. this.morphTargetDictionary[ name ] = m;
  17367. }
  17368. }
  17369. }
  17370. } else {
  17371. const morphTargets = geometry.morphTargets;
  17372. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  17373. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17374. }
  17375. }
  17376. }
  17377. }
  17378. Line.prototype.isLine = true;
  17379. const _start = /*@__PURE__*/ new Vector3();
  17380. const _end = /*@__PURE__*/ new Vector3();
  17381. class LineSegments extends Line {
  17382. constructor( geometry, material ) {
  17383. super( geometry, material );
  17384. this.type = 'LineSegments';
  17385. }
  17386. computeLineDistances() {
  17387. const geometry = this.geometry;
  17388. if ( geometry.isBufferGeometry ) {
  17389. // we assume non-indexed geometry
  17390. if ( geometry.index === null ) {
  17391. const positionAttribute = geometry.attributes.position;
  17392. const lineDistances = [];
  17393. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  17394. _start.fromBufferAttribute( positionAttribute, i );
  17395. _end.fromBufferAttribute( positionAttribute, i + 1 );
  17396. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  17397. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  17398. }
  17399. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  17400. } else {
  17401. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  17402. }
  17403. } else if ( geometry.isGeometry ) {
  17404. console.error( 'THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17405. }
  17406. return this;
  17407. }
  17408. }
  17409. LineSegments.prototype.isLineSegments = true;
  17410. class LineLoop extends Line {
  17411. constructor( geometry, material ) {
  17412. super( geometry, material );
  17413. this.type = 'LineLoop';
  17414. }
  17415. }
  17416. LineLoop.prototype.isLineLoop = true;
  17417. /**
  17418. * parameters = {
  17419. * color: <hex>,
  17420. * opacity: <float>,
  17421. * map: new THREE.Texture( <Image> ),
  17422. * alphaMap: new THREE.Texture( <Image> ),
  17423. *
  17424. * size: <float>,
  17425. * sizeAttenuation: <bool>
  17426. *
  17427. * }
  17428. */
  17429. class PointsMaterial extends Material {
  17430. constructor( parameters ) {
  17431. super();
  17432. this.type = 'PointsMaterial';
  17433. this.color = new Color( 0xffffff );
  17434. this.map = null;
  17435. this.alphaMap = null;
  17436. this.size = 1;
  17437. this.sizeAttenuation = true;
  17438. this.setValues( parameters );
  17439. }
  17440. copy( source ) {
  17441. super.copy( source );
  17442. this.color.copy( source.color );
  17443. this.map = source.map;
  17444. this.alphaMap = source.alphaMap;
  17445. this.size = source.size;
  17446. this.sizeAttenuation = source.sizeAttenuation;
  17447. return this;
  17448. }
  17449. }
  17450. PointsMaterial.prototype.isPointsMaterial = true;
  17451. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  17452. const _ray = /*@__PURE__*/ new Ray();
  17453. const _sphere = /*@__PURE__*/ new Sphere();
  17454. const _position$2 = /*@__PURE__*/ new Vector3();
  17455. class Points extends Object3D {
  17456. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  17457. super();
  17458. this.type = 'Points';
  17459. this.geometry = geometry;
  17460. this.material = material;
  17461. this.updateMorphTargets();
  17462. }
  17463. copy( source ) {
  17464. super.copy( source );
  17465. this.material = source.material;
  17466. this.geometry = source.geometry;
  17467. return this;
  17468. }
  17469. raycast( raycaster, intersects ) {
  17470. const geometry = this.geometry;
  17471. const matrixWorld = this.matrixWorld;
  17472. const threshold = raycaster.params.Points.threshold;
  17473. const drawRange = geometry.drawRange;
  17474. // Checking boundingSphere distance to ray
  17475. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  17476. _sphere.copy( geometry.boundingSphere );
  17477. _sphere.applyMatrix4( matrixWorld );
  17478. _sphere.radius += threshold;
  17479. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  17480. //
  17481. _inverseMatrix.copy( matrixWorld ).invert();
  17482. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  17483. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  17484. const localThresholdSq = localThreshold * localThreshold;
  17485. if ( geometry.isBufferGeometry ) {
  17486. const index = geometry.index;
  17487. const attributes = geometry.attributes;
  17488. const positionAttribute = attributes.position;
  17489. if ( index !== null ) {
  17490. const start = Math.max( 0, drawRange.start );
  17491. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  17492. for ( let i = start, il = end; i < il; i ++ ) {
  17493. const a = index.getX( i );
  17494. _position$2.fromBufferAttribute( positionAttribute, a );
  17495. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17496. }
  17497. } else {
  17498. const start = Math.max( 0, drawRange.start );
  17499. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  17500. for ( let i = start, l = end; i < l; i ++ ) {
  17501. _position$2.fromBufferAttribute( positionAttribute, i );
  17502. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17503. }
  17504. }
  17505. } else {
  17506. console.error( 'THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17507. }
  17508. }
  17509. updateMorphTargets() {
  17510. const geometry = this.geometry;
  17511. if ( geometry.isBufferGeometry ) {
  17512. const morphAttributes = geometry.morphAttributes;
  17513. const keys = Object.keys( morphAttributes );
  17514. if ( keys.length > 0 ) {
  17515. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  17516. if ( morphAttribute !== undefined ) {
  17517. this.morphTargetInfluences = [];
  17518. this.morphTargetDictionary = {};
  17519. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  17520. const name = morphAttribute[ m ].name || String( m );
  17521. this.morphTargetInfluences.push( 0 );
  17522. this.morphTargetDictionary[ name ] = m;
  17523. }
  17524. }
  17525. }
  17526. } else {
  17527. const morphTargets = geometry.morphTargets;
  17528. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  17529. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17530. }
  17531. }
  17532. }
  17533. }
  17534. Points.prototype.isPoints = true;
  17535. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  17536. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  17537. if ( rayPointDistanceSq < localThresholdSq ) {
  17538. const intersectPoint = new Vector3();
  17539. _ray.closestPointToPoint( point, intersectPoint );
  17540. intersectPoint.applyMatrix4( matrixWorld );
  17541. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  17542. if ( distance < raycaster.near || distance > raycaster.far ) return;
  17543. intersects.push( {
  17544. distance: distance,
  17545. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  17546. point: intersectPoint,
  17547. index: index,
  17548. face: null,
  17549. object: object
  17550. } );
  17551. }
  17552. }
  17553. class VideoTexture extends Texture {
  17554. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17555. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17556. this.format = format !== undefined ? format : RGBFormat;
  17557. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17558. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17559. this.generateMipmaps = false;
  17560. const scope = this;
  17561. function updateVideo() {
  17562. scope.needsUpdate = true;
  17563. video.requestVideoFrameCallback( updateVideo );
  17564. }
  17565. if ( 'requestVideoFrameCallback' in video ) {
  17566. video.requestVideoFrameCallback( updateVideo );
  17567. }
  17568. }
  17569. clone() {
  17570. return new this.constructor( this.image ).copy( this );
  17571. }
  17572. update() {
  17573. const video = this.image;
  17574. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  17575. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  17576. this.needsUpdate = true;
  17577. }
  17578. }
  17579. }
  17580. VideoTexture.prototype.isVideoTexture = true;
  17581. class CompressedTexture extends Texture {
  17582. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  17583. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  17584. this.image = { width: width, height: height };
  17585. this.mipmaps = mipmaps;
  17586. // no flipping for cube textures
  17587. // (also flipping doesn't work for compressed textures )
  17588. this.flipY = false;
  17589. // can't generate mipmaps for compressed textures
  17590. // mips must be embedded in DDS files
  17591. this.generateMipmaps = false;
  17592. }
  17593. }
  17594. CompressedTexture.prototype.isCompressedTexture = true;
  17595. class CanvasTexture extends Texture {
  17596. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17597. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17598. this.needsUpdate = true;
  17599. }
  17600. }
  17601. CanvasTexture.prototype.isCanvasTexture = true;
  17602. class DepthTexture extends Texture {
  17603. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  17604. format = format !== undefined ? format : DepthFormat;
  17605. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  17606. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  17607. }
  17608. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  17609. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  17610. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17611. this.image = { width: width, height: height };
  17612. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17613. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17614. this.flipY = false;
  17615. this.generateMipmaps = false;
  17616. }
  17617. }
  17618. DepthTexture.prototype.isDepthTexture = true;
  17619. class CircleGeometry extends BufferGeometry {
  17620. constructor( radius = 1, segments = 8, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17621. super();
  17622. this.type = 'CircleGeometry';
  17623. this.parameters = {
  17624. radius: radius,
  17625. segments: segments,
  17626. thetaStart: thetaStart,
  17627. thetaLength: thetaLength
  17628. };
  17629. segments = Math.max( 3, segments );
  17630. // buffers
  17631. const indices = [];
  17632. const vertices = [];
  17633. const normals = [];
  17634. const uvs = [];
  17635. // helper variables
  17636. const vertex = new Vector3();
  17637. const uv = new Vector2();
  17638. // center point
  17639. vertices.push( 0, 0, 0 );
  17640. normals.push( 0, 0, 1 );
  17641. uvs.push( 0.5, 0.5 );
  17642. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17643. const segment = thetaStart + s / segments * thetaLength;
  17644. // vertex
  17645. vertex.x = radius * Math.cos( segment );
  17646. vertex.y = radius * Math.sin( segment );
  17647. vertices.push( vertex.x, vertex.y, vertex.z );
  17648. // normal
  17649. normals.push( 0, 0, 1 );
  17650. // uvs
  17651. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17652. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17653. uvs.push( uv.x, uv.y );
  17654. }
  17655. // indices
  17656. for ( let i = 1; i <= segments; i ++ ) {
  17657. indices.push( i, i + 1, 0 );
  17658. }
  17659. // build geometry
  17660. this.setIndex( indices );
  17661. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17662. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17663. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17664. }
  17665. static fromJSON( data ) {
  17666. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  17667. }
  17668. }
  17669. class CylinderGeometry extends BufferGeometry {
  17670. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17671. super();
  17672. this.type = 'CylinderGeometry';
  17673. this.parameters = {
  17674. radiusTop: radiusTop,
  17675. radiusBottom: radiusBottom,
  17676. height: height,
  17677. radialSegments: radialSegments,
  17678. heightSegments: heightSegments,
  17679. openEnded: openEnded,
  17680. thetaStart: thetaStart,
  17681. thetaLength: thetaLength
  17682. };
  17683. const scope = this;
  17684. radialSegments = Math.floor( radialSegments );
  17685. heightSegments = Math.floor( heightSegments );
  17686. // buffers
  17687. const indices = [];
  17688. const vertices = [];
  17689. const normals = [];
  17690. const uvs = [];
  17691. // helper variables
  17692. let index = 0;
  17693. const indexArray = [];
  17694. const halfHeight = height / 2;
  17695. let groupStart = 0;
  17696. // generate geometry
  17697. generateTorso();
  17698. if ( openEnded === false ) {
  17699. if ( radiusTop > 0 ) generateCap( true );
  17700. if ( radiusBottom > 0 ) generateCap( false );
  17701. }
  17702. // build geometry
  17703. this.setIndex( indices );
  17704. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17705. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17706. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17707. function generateTorso() {
  17708. const normal = new Vector3();
  17709. const vertex = new Vector3();
  17710. let groupCount = 0;
  17711. // this will be used to calculate the normal
  17712. const slope = ( radiusBottom - radiusTop ) / height;
  17713. // generate vertices, normals and uvs
  17714. for ( let y = 0; y <= heightSegments; y ++ ) {
  17715. const indexRow = [];
  17716. const v = y / heightSegments;
  17717. // calculate the radius of the current row
  17718. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17719. for ( let x = 0; x <= radialSegments; x ++ ) {
  17720. const u = x / radialSegments;
  17721. const theta = u * thetaLength + thetaStart;
  17722. const sinTheta = Math.sin( theta );
  17723. const cosTheta = Math.cos( theta );
  17724. // vertex
  17725. vertex.x = radius * sinTheta;
  17726. vertex.y = - v * height + halfHeight;
  17727. vertex.z = radius * cosTheta;
  17728. vertices.push( vertex.x, vertex.y, vertex.z );
  17729. // normal
  17730. normal.set( sinTheta, slope, cosTheta ).normalize();
  17731. normals.push( normal.x, normal.y, normal.z );
  17732. // uv
  17733. uvs.push( u, 1 - v );
  17734. // save index of vertex in respective row
  17735. indexRow.push( index ++ );
  17736. }
  17737. // now save vertices of the row in our index array
  17738. indexArray.push( indexRow );
  17739. }
  17740. // generate indices
  17741. for ( let x = 0; x < radialSegments; x ++ ) {
  17742. for ( let y = 0; y < heightSegments; y ++ ) {
  17743. // we use the index array to access the correct indices
  17744. const a = indexArray[ y ][ x ];
  17745. const b = indexArray[ y + 1 ][ x ];
  17746. const c = indexArray[ y + 1 ][ x + 1 ];
  17747. const d = indexArray[ y ][ x + 1 ];
  17748. // faces
  17749. indices.push( a, b, d );
  17750. indices.push( b, c, d );
  17751. // update group counter
  17752. groupCount += 6;
  17753. }
  17754. }
  17755. // add a group to the geometry. this will ensure multi material support
  17756. scope.addGroup( groupStart, groupCount, 0 );
  17757. // calculate new start value for groups
  17758. groupStart += groupCount;
  17759. }
  17760. function generateCap( top ) {
  17761. // save the index of the first center vertex
  17762. const centerIndexStart = index;
  17763. const uv = new Vector2();
  17764. const vertex = new Vector3();
  17765. let groupCount = 0;
  17766. const radius = ( top === true ) ? radiusTop : radiusBottom;
  17767. const sign = ( top === true ) ? 1 : - 1;
  17768. // first we generate the center vertex data of the cap.
  17769. // because the geometry needs one set of uvs per face,
  17770. // we must generate a center vertex per face/segment
  17771. for ( let x = 1; x <= radialSegments; x ++ ) {
  17772. // vertex
  17773. vertices.push( 0, halfHeight * sign, 0 );
  17774. // normal
  17775. normals.push( 0, sign, 0 );
  17776. // uv
  17777. uvs.push( 0.5, 0.5 );
  17778. // increase index
  17779. index ++;
  17780. }
  17781. // save the index of the last center vertex
  17782. const centerIndexEnd = index;
  17783. // now we generate the surrounding vertices, normals and uvs
  17784. for ( let x = 0; x <= radialSegments; x ++ ) {
  17785. const u = x / radialSegments;
  17786. const theta = u * thetaLength + thetaStart;
  17787. const cosTheta = Math.cos( theta );
  17788. const sinTheta = Math.sin( theta );
  17789. // vertex
  17790. vertex.x = radius * sinTheta;
  17791. vertex.y = halfHeight * sign;
  17792. vertex.z = radius * cosTheta;
  17793. vertices.push( vertex.x, vertex.y, vertex.z );
  17794. // normal
  17795. normals.push( 0, sign, 0 );
  17796. // uv
  17797. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17798. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17799. uvs.push( uv.x, uv.y );
  17800. // increase index
  17801. index ++;
  17802. }
  17803. // generate indices
  17804. for ( let x = 0; x < radialSegments; x ++ ) {
  17805. const c = centerIndexStart + x;
  17806. const i = centerIndexEnd + x;
  17807. if ( top === true ) {
  17808. // face top
  17809. indices.push( i, i + 1, c );
  17810. } else {
  17811. // face bottom
  17812. indices.push( i + 1, i, c );
  17813. }
  17814. groupCount += 3;
  17815. }
  17816. // add a group to the geometry. this will ensure multi material support
  17817. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17818. // calculate new start value for groups
  17819. groupStart += groupCount;
  17820. }
  17821. }
  17822. static fromJSON( data ) {
  17823. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  17824. }
  17825. }
  17826. class ConeGeometry extends CylinderGeometry {
  17827. constructor( radius = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17828. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17829. this.type = 'ConeGeometry';
  17830. this.parameters = {
  17831. radius: radius,
  17832. height: height,
  17833. radialSegments: radialSegments,
  17834. heightSegments: heightSegments,
  17835. openEnded: openEnded,
  17836. thetaStart: thetaStart,
  17837. thetaLength: thetaLength
  17838. };
  17839. }
  17840. static fromJSON( data ) {
  17841. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  17842. }
  17843. }
  17844. class PolyhedronGeometry extends BufferGeometry {
  17845. constructor( vertices, indices, radius = 1, detail = 0 ) {
  17846. super();
  17847. this.type = 'PolyhedronGeometry';
  17848. this.parameters = {
  17849. vertices: vertices,
  17850. indices: indices,
  17851. radius: radius,
  17852. detail: detail
  17853. };
  17854. // default buffer data
  17855. const vertexBuffer = [];
  17856. const uvBuffer = [];
  17857. // the subdivision creates the vertex buffer data
  17858. subdivide( detail );
  17859. // all vertices should lie on a conceptual sphere with a given radius
  17860. applyRadius( radius );
  17861. // finally, create the uv data
  17862. generateUVs();
  17863. // build non-indexed geometry
  17864. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17865. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17866. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17867. if ( detail === 0 ) {
  17868. this.computeVertexNormals(); // flat normals
  17869. } else {
  17870. this.normalizeNormals(); // smooth normals
  17871. }
  17872. // helper functions
  17873. function subdivide( detail ) {
  17874. const a = new Vector3();
  17875. const b = new Vector3();
  17876. const c = new Vector3();
  17877. // iterate over all faces and apply a subdivison with the given detail value
  17878. for ( let i = 0; i < indices.length; i += 3 ) {
  17879. // get the vertices of the face
  17880. getVertexByIndex( indices[ i + 0 ], a );
  17881. getVertexByIndex( indices[ i + 1 ], b );
  17882. getVertexByIndex( indices[ i + 2 ], c );
  17883. // perform subdivision
  17884. subdivideFace( a, b, c, detail );
  17885. }
  17886. }
  17887. function subdivideFace( a, b, c, detail ) {
  17888. const cols = detail + 1;
  17889. // we use this multidimensional array as a data structure for creating the subdivision
  17890. const v = [];
  17891. // construct all of the vertices for this subdivision
  17892. for ( let i = 0; i <= cols; i ++ ) {
  17893. v[ i ] = [];
  17894. const aj = a.clone().lerp( c, i / cols );
  17895. const bj = b.clone().lerp( c, i / cols );
  17896. const rows = cols - i;
  17897. for ( let j = 0; j <= rows; j ++ ) {
  17898. if ( j === 0 && i === cols ) {
  17899. v[ i ][ j ] = aj;
  17900. } else {
  17901. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17902. }
  17903. }
  17904. }
  17905. // construct all of the faces
  17906. for ( let i = 0; i < cols; i ++ ) {
  17907. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  17908. const k = Math.floor( j / 2 );
  17909. if ( j % 2 === 0 ) {
  17910. pushVertex( v[ i ][ k + 1 ] );
  17911. pushVertex( v[ i + 1 ][ k ] );
  17912. pushVertex( v[ i ][ k ] );
  17913. } else {
  17914. pushVertex( v[ i ][ k + 1 ] );
  17915. pushVertex( v[ i + 1 ][ k + 1 ] );
  17916. pushVertex( v[ i + 1 ][ k ] );
  17917. }
  17918. }
  17919. }
  17920. }
  17921. function applyRadius( radius ) {
  17922. const vertex = new Vector3();
  17923. // iterate over the entire buffer and apply the radius to each vertex
  17924. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17925. vertex.x = vertexBuffer[ i + 0 ];
  17926. vertex.y = vertexBuffer[ i + 1 ];
  17927. vertex.z = vertexBuffer[ i + 2 ];
  17928. vertex.normalize().multiplyScalar( radius );
  17929. vertexBuffer[ i + 0 ] = vertex.x;
  17930. vertexBuffer[ i + 1 ] = vertex.y;
  17931. vertexBuffer[ i + 2 ] = vertex.z;
  17932. }
  17933. }
  17934. function generateUVs() {
  17935. const vertex = new Vector3();
  17936. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17937. vertex.x = vertexBuffer[ i + 0 ];
  17938. vertex.y = vertexBuffer[ i + 1 ];
  17939. vertex.z = vertexBuffer[ i + 2 ];
  17940. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17941. const v = inclination( vertex ) / Math.PI + 0.5;
  17942. uvBuffer.push( u, 1 - v );
  17943. }
  17944. correctUVs();
  17945. correctSeam();
  17946. }
  17947. function correctSeam() {
  17948. // handle case when face straddles the seam, see #3269
  17949. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  17950. // uv data of a single face
  17951. const x0 = uvBuffer[ i + 0 ];
  17952. const x1 = uvBuffer[ i + 2 ];
  17953. const x2 = uvBuffer[ i + 4 ];
  17954. const max = Math.max( x0, x1, x2 );
  17955. const min = Math.min( x0, x1, x2 );
  17956. // 0.9 is somewhat arbitrary
  17957. if ( max > 0.9 && min < 0.1 ) {
  17958. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17959. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17960. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17961. }
  17962. }
  17963. }
  17964. function pushVertex( vertex ) {
  17965. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17966. }
  17967. function getVertexByIndex( index, vertex ) {
  17968. const stride = index * 3;
  17969. vertex.x = vertices[ stride + 0 ];
  17970. vertex.y = vertices[ stride + 1 ];
  17971. vertex.z = vertices[ stride + 2 ];
  17972. }
  17973. function correctUVs() {
  17974. const a = new Vector3();
  17975. const b = new Vector3();
  17976. const c = new Vector3();
  17977. const centroid = new Vector3();
  17978. const uvA = new Vector2();
  17979. const uvB = new Vector2();
  17980. const uvC = new Vector2();
  17981. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17982. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17983. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17984. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17985. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17986. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17987. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17988. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17989. const azi = azimuth( centroid );
  17990. correctUV( uvA, j + 0, a, azi );
  17991. correctUV( uvB, j + 2, b, azi );
  17992. correctUV( uvC, j + 4, c, azi );
  17993. }
  17994. }
  17995. function correctUV( uv, stride, vector, azimuth ) {
  17996. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17997. uvBuffer[ stride ] = uv.x - 1;
  17998. }
  17999. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  18000. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  18001. }
  18002. }
  18003. // Angle around the Y axis, counter-clockwise when looking from above.
  18004. function azimuth( vector ) {
  18005. return Math.atan2( vector.z, - vector.x );
  18006. }
  18007. // Angle above the XZ plane.
  18008. function inclination( vector ) {
  18009. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  18010. }
  18011. }
  18012. static fromJSON( data ) {
  18013. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  18014. }
  18015. }
  18016. class DodecahedronGeometry extends PolyhedronGeometry {
  18017. constructor( radius = 1, detail = 0 ) {
  18018. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  18019. const r = 1 / t;
  18020. const vertices = [
  18021. // (±1, ±1, ±1)
  18022. - 1, - 1, - 1, - 1, - 1, 1,
  18023. - 1, 1, - 1, - 1, 1, 1,
  18024. 1, - 1, - 1, 1, - 1, 1,
  18025. 1, 1, - 1, 1, 1, 1,
  18026. // (0, ±1/φ, ±φ)
  18027. 0, - r, - t, 0, - r, t,
  18028. 0, r, - t, 0, r, t,
  18029. // (±1/φ, ±φ, 0)
  18030. - r, - t, 0, - r, t, 0,
  18031. r, - t, 0, r, t, 0,
  18032. // (±φ, 0, ±1/φ)
  18033. - t, 0, - r, t, 0, - r,
  18034. - t, 0, r, t, 0, r
  18035. ];
  18036. const indices = [
  18037. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  18038. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  18039. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  18040. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  18041. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  18042. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  18043. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  18044. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  18045. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  18046. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  18047. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  18048. 1, 12, 14, 1, 14, 5, 1, 5, 9
  18049. ];
  18050. super( vertices, indices, radius, detail );
  18051. this.type = 'DodecahedronGeometry';
  18052. this.parameters = {
  18053. radius: radius,
  18054. detail: detail
  18055. };
  18056. }
  18057. static fromJSON( data ) {
  18058. return new DodecahedronGeometry( data.radius, data.detail );
  18059. }
  18060. }
  18061. const _v0 = new Vector3();
  18062. const _v1$1 = new Vector3();
  18063. const _normal = new Vector3();
  18064. const _triangle = new Triangle();
  18065. class EdgesGeometry extends BufferGeometry {
  18066. constructor( geometry, thresholdAngle ) {
  18067. super();
  18068. this.type = 'EdgesGeometry';
  18069. this.parameters = {
  18070. thresholdAngle: thresholdAngle
  18071. };
  18072. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18073. if ( geometry.isGeometry === true ) {
  18074. console.error( 'THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  18075. return;
  18076. }
  18077. const precisionPoints = 4;
  18078. const precision = Math.pow( 10, precisionPoints );
  18079. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  18080. const indexAttr = geometry.getIndex();
  18081. const positionAttr = geometry.getAttribute( 'position' );
  18082. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  18083. const indexArr = [ 0, 0, 0 ];
  18084. const vertKeys = [ 'a', 'b', 'c' ];
  18085. const hashes = new Array( 3 );
  18086. const edgeData = {};
  18087. const vertices = [];
  18088. for ( let i = 0; i < indexCount; i += 3 ) {
  18089. if ( indexAttr ) {
  18090. indexArr[ 0 ] = indexAttr.getX( i );
  18091. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  18092. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  18093. } else {
  18094. indexArr[ 0 ] = i;
  18095. indexArr[ 1 ] = i + 1;
  18096. indexArr[ 2 ] = i + 2;
  18097. }
  18098. const { a, b, c } = _triangle;
  18099. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  18100. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  18101. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  18102. _triangle.getNormal( _normal );
  18103. // create hashes for the edge from the vertices
  18104. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  18105. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  18106. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  18107. // skip degenerate triangles
  18108. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  18109. continue;
  18110. }
  18111. // iterate over every edge
  18112. for ( let j = 0; j < 3; j ++ ) {
  18113. // get the first and next vertex making up the edge
  18114. const jNext = ( j + 1 ) % 3;
  18115. const vecHash0 = hashes[ j ];
  18116. const vecHash1 = hashes[ jNext ];
  18117. const v0 = _triangle[ vertKeys[ j ] ];
  18118. const v1 = _triangle[ vertKeys[ jNext ] ];
  18119. const hash = `${ vecHash0 }_${ vecHash1 }`;
  18120. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  18121. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  18122. // if we found a sibling edge add it into the vertex array if
  18123. // it meets the angle threshold and delete the edge from the map.
  18124. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  18125. vertices.push( v0.x, v0.y, v0.z );
  18126. vertices.push( v1.x, v1.y, v1.z );
  18127. }
  18128. edgeData[ reverseHash ] = null;
  18129. } else if ( ! ( hash in edgeData ) ) {
  18130. // if we've already got an edge here then skip adding a new one
  18131. edgeData[ hash ] = {
  18132. index0: indexArr[ j ],
  18133. index1: indexArr[ jNext ],
  18134. normal: _normal.clone(),
  18135. };
  18136. }
  18137. }
  18138. }
  18139. // iterate over all remaining, unmatched edges and add them to the vertex array
  18140. for ( const key in edgeData ) {
  18141. if ( edgeData[ key ] ) {
  18142. const { index0, index1 } = edgeData[ key ];
  18143. _v0.fromBufferAttribute( positionAttr, index0 );
  18144. _v1$1.fromBufferAttribute( positionAttr, index1 );
  18145. vertices.push( _v0.x, _v0.y, _v0.z );
  18146. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  18147. }
  18148. }
  18149. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18150. }
  18151. }
  18152. /**
  18153. * Extensible curve object.
  18154. *
  18155. * Some common of curve methods:
  18156. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  18157. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  18158. * .getPoints(), .getSpacedPoints()
  18159. * .getLength()
  18160. * .updateArcLengths()
  18161. *
  18162. * This following curves inherit from THREE.Curve:
  18163. *
  18164. * -- 2D curves --
  18165. * THREE.ArcCurve
  18166. * THREE.CubicBezierCurve
  18167. * THREE.EllipseCurve
  18168. * THREE.LineCurve
  18169. * THREE.QuadraticBezierCurve
  18170. * THREE.SplineCurve
  18171. *
  18172. * -- 3D curves --
  18173. * THREE.CatmullRomCurve3
  18174. * THREE.CubicBezierCurve3
  18175. * THREE.LineCurve3
  18176. * THREE.QuadraticBezierCurve3
  18177. *
  18178. * A series of curves can be represented as a THREE.CurvePath.
  18179. *
  18180. **/
  18181. class Curve {
  18182. constructor() {
  18183. this.type = 'Curve';
  18184. this.arcLengthDivisions = 200;
  18185. }
  18186. // Virtual base class method to overwrite and implement in subclasses
  18187. // - t [0 .. 1]
  18188. getPoint( /* t, optionalTarget */ ) {
  18189. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  18190. return null;
  18191. }
  18192. // Get point at relative position in curve according to arc length
  18193. // - u [0 .. 1]
  18194. getPointAt( u, optionalTarget ) {
  18195. const t = this.getUtoTmapping( u );
  18196. return this.getPoint( t, optionalTarget );
  18197. }
  18198. // Get sequence of points using getPoint( t )
  18199. getPoints( divisions = 5 ) {
  18200. const points = [];
  18201. for ( let d = 0; d <= divisions; d ++ ) {
  18202. points.push( this.getPoint( d / divisions ) );
  18203. }
  18204. return points;
  18205. }
  18206. // Get sequence of points using getPointAt( u )
  18207. getSpacedPoints( divisions = 5 ) {
  18208. const points = [];
  18209. for ( let d = 0; d <= divisions; d ++ ) {
  18210. points.push( this.getPointAt( d / divisions ) );
  18211. }
  18212. return points;
  18213. }
  18214. // Get total curve arc length
  18215. getLength() {
  18216. const lengths = this.getLengths();
  18217. return lengths[ lengths.length - 1 ];
  18218. }
  18219. // Get list of cumulative segment lengths
  18220. getLengths( divisions = this.arcLengthDivisions ) {
  18221. if ( this.cacheArcLengths &&
  18222. ( this.cacheArcLengths.length === divisions + 1 ) &&
  18223. ! this.needsUpdate ) {
  18224. return this.cacheArcLengths;
  18225. }
  18226. this.needsUpdate = false;
  18227. const cache = [];
  18228. let current, last = this.getPoint( 0 );
  18229. let sum = 0;
  18230. cache.push( 0 );
  18231. for ( let p = 1; p <= divisions; p ++ ) {
  18232. current = this.getPoint( p / divisions );
  18233. sum += current.distanceTo( last );
  18234. cache.push( sum );
  18235. last = current;
  18236. }
  18237. this.cacheArcLengths = cache;
  18238. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  18239. }
  18240. updateArcLengths() {
  18241. this.needsUpdate = true;
  18242. this.getLengths();
  18243. }
  18244. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  18245. getUtoTmapping( u, distance ) {
  18246. const arcLengths = this.getLengths();
  18247. let i = 0;
  18248. const il = arcLengths.length;
  18249. let targetArcLength; // The targeted u distance value to get
  18250. if ( distance ) {
  18251. targetArcLength = distance;
  18252. } else {
  18253. targetArcLength = u * arcLengths[ il - 1 ];
  18254. }
  18255. // binary search for the index with largest value smaller than target u distance
  18256. let low = 0, high = il - 1, comparison;
  18257. while ( low <= high ) {
  18258. 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
  18259. comparison = arcLengths[ i ] - targetArcLength;
  18260. if ( comparison < 0 ) {
  18261. low = i + 1;
  18262. } else if ( comparison > 0 ) {
  18263. high = i - 1;
  18264. } else {
  18265. high = i;
  18266. break;
  18267. // DONE
  18268. }
  18269. }
  18270. i = high;
  18271. if ( arcLengths[ i ] === targetArcLength ) {
  18272. return i / ( il - 1 );
  18273. }
  18274. // we could get finer grain at lengths, or use simple interpolation between two points
  18275. const lengthBefore = arcLengths[ i ];
  18276. const lengthAfter = arcLengths[ i + 1 ];
  18277. const segmentLength = lengthAfter - lengthBefore;
  18278. // determine where we are between the 'before' and 'after' points
  18279. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  18280. // add that fractional amount to t
  18281. const t = ( i + segmentFraction ) / ( il - 1 );
  18282. return t;
  18283. }
  18284. // Returns a unit vector tangent at t
  18285. // In case any sub curve does not implement its tangent derivation,
  18286. // 2 points a small delta apart will be used to find its gradient
  18287. // which seems to give a reasonable approximation
  18288. getTangent( t, optionalTarget ) {
  18289. const delta = 0.0001;
  18290. let t1 = t - delta;
  18291. let t2 = t + delta;
  18292. // Capping in case of danger
  18293. if ( t1 < 0 ) t1 = 0;
  18294. if ( t2 > 1 ) t2 = 1;
  18295. const pt1 = this.getPoint( t1 );
  18296. const pt2 = this.getPoint( t2 );
  18297. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  18298. tangent.copy( pt2 ).sub( pt1 ).normalize();
  18299. return tangent;
  18300. }
  18301. getTangentAt( u, optionalTarget ) {
  18302. const t = this.getUtoTmapping( u );
  18303. return this.getTangent( t, optionalTarget );
  18304. }
  18305. computeFrenetFrames( segments, closed ) {
  18306. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  18307. const normal = new Vector3();
  18308. const tangents = [];
  18309. const normals = [];
  18310. const binormals = [];
  18311. const vec = new Vector3();
  18312. const mat = new Matrix4();
  18313. // compute the tangent vectors for each segment on the curve
  18314. for ( let i = 0; i <= segments; i ++ ) {
  18315. const u = i / segments;
  18316. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  18317. }
  18318. // select an initial normal vector perpendicular to the first tangent vector,
  18319. // and in the direction of the minimum tangent xyz component
  18320. normals[ 0 ] = new Vector3();
  18321. binormals[ 0 ] = new Vector3();
  18322. let min = Number.MAX_VALUE;
  18323. const tx = Math.abs( tangents[ 0 ].x );
  18324. const ty = Math.abs( tangents[ 0 ].y );
  18325. const tz = Math.abs( tangents[ 0 ].z );
  18326. if ( tx <= min ) {
  18327. min = tx;
  18328. normal.set( 1, 0, 0 );
  18329. }
  18330. if ( ty <= min ) {
  18331. min = ty;
  18332. normal.set( 0, 1, 0 );
  18333. }
  18334. if ( tz <= min ) {
  18335. normal.set( 0, 0, 1 );
  18336. }
  18337. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  18338. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  18339. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  18340. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  18341. for ( let i = 1; i <= segments; i ++ ) {
  18342. normals[ i ] = normals[ i - 1 ].clone();
  18343. binormals[ i ] = binormals[ i - 1 ].clone();
  18344. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  18345. if ( vec.length() > Number.EPSILON ) {
  18346. vec.normalize();
  18347. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  18348. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  18349. }
  18350. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18351. }
  18352. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  18353. if ( closed === true ) {
  18354. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  18355. theta /= segments;
  18356. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  18357. theta = - theta;
  18358. }
  18359. for ( let i = 1; i <= segments; i ++ ) {
  18360. // twist a little...
  18361. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  18362. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  18363. }
  18364. }
  18365. return {
  18366. tangents: tangents,
  18367. normals: normals,
  18368. binormals: binormals
  18369. };
  18370. }
  18371. clone() {
  18372. return new this.constructor().copy( this );
  18373. }
  18374. copy( source ) {
  18375. this.arcLengthDivisions = source.arcLengthDivisions;
  18376. return this;
  18377. }
  18378. toJSON() {
  18379. const data = {
  18380. metadata: {
  18381. version: 4.5,
  18382. type: 'Curve',
  18383. generator: 'Curve.toJSON'
  18384. }
  18385. };
  18386. data.arcLengthDivisions = this.arcLengthDivisions;
  18387. data.type = this.type;
  18388. return data;
  18389. }
  18390. fromJSON( json ) {
  18391. this.arcLengthDivisions = json.arcLengthDivisions;
  18392. return this;
  18393. }
  18394. }
  18395. class EllipseCurve extends Curve {
  18396. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  18397. super();
  18398. this.type = 'EllipseCurve';
  18399. this.aX = aX;
  18400. this.aY = aY;
  18401. this.xRadius = xRadius;
  18402. this.yRadius = yRadius;
  18403. this.aStartAngle = aStartAngle;
  18404. this.aEndAngle = aEndAngle;
  18405. this.aClockwise = aClockwise;
  18406. this.aRotation = aRotation;
  18407. }
  18408. getPoint( t, optionalTarget ) {
  18409. const point = optionalTarget || new Vector2();
  18410. const twoPi = Math.PI * 2;
  18411. let deltaAngle = this.aEndAngle - this.aStartAngle;
  18412. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  18413. // ensures that deltaAngle is 0 .. 2 PI
  18414. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  18415. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  18416. if ( deltaAngle < Number.EPSILON ) {
  18417. if ( samePoints ) {
  18418. deltaAngle = 0;
  18419. } else {
  18420. deltaAngle = twoPi;
  18421. }
  18422. }
  18423. if ( this.aClockwise === true && ! samePoints ) {
  18424. if ( deltaAngle === twoPi ) {
  18425. deltaAngle = - twoPi;
  18426. } else {
  18427. deltaAngle = deltaAngle - twoPi;
  18428. }
  18429. }
  18430. const angle = this.aStartAngle + t * deltaAngle;
  18431. let x = this.aX + this.xRadius * Math.cos( angle );
  18432. let y = this.aY + this.yRadius * Math.sin( angle );
  18433. if ( this.aRotation !== 0 ) {
  18434. const cos = Math.cos( this.aRotation );
  18435. const sin = Math.sin( this.aRotation );
  18436. const tx = x - this.aX;
  18437. const ty = y - this.aY;
  18438. // Rotate the point about the center of the ellipse.
  18439. x = tx * cos - ty * sin + this.aX;
  18440. y = tx * sin + ty * cos + this.aY;
  18441. }
  18442. return point.set( x, y );
  18443. }
  18444. copy( source ) {
  18445. super.copy( source );
  18446. this.aX = source.aX;
  18447. this.aY = source.aY;
  18448. this.xRadius = source.xRadius;
  18449. this.yRadius = source.yRadius;
  18450. this.aStartAngle = source.aStartAngle;
  18451. this.aEndAngle = source.aEndAngle;
  18452. this.aClockwise = source.aClockwise;
  18453. this.aRotation = source.aRotation;
  18454. return this;
  18455. }
  18456. toJSON() {
  18457. const data = super.toJSON();
  18458. data.aX = this.aX;
  18459. data.aY = this.aY;
  18460. data.xRadius = this.xRadius;
  18461. data.yRadius = this.yRadius;
  18462. data.aStartAngle = this.aStartAngle;
  18463. data.aEndAngle = this.aEndAngle;
  18464. data.aClockwise = this.aClockwise;
  18465. data.aRotation = this.aRotation;
  18466. return data;
  18467. }
  18468. fromJSON( json ) {
  18469. super.fromJSON( json );
  18470. this.aX = json.aX;
  18471. this.aY = json.aY;
  18472. this.xRadius = json.xRadius;
  18473. this.yRadius = json.yRadius;
  18474. this.aStartAngle = json.aStartAngle;
  18475. this.aEndAngle = json.aEndAngle;
  18476. this.aClockwise = json.aClockwise;
  18477. this.aRotation = json.aRotation;
  18478. return this;
  18479. }
  18480. }
  18481. EllipseCurve.prototype.isEllipseCurve = true;
  18482. class ArcCurve extends EllipseCurve {
  18483. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18484. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18485. this.type = 'ArcCurve';
  18486. }
  18487. }
  18488. ArcCurve.prototype.isArcCurve = true;
  18489. /**
  18490. * Centripetal CatmullRom Curve - which is useful for avoiding
  18491. * cusps and self-intersections in non-uniform catmull rom curves.
  18492. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18493. *
  18494. * curve.type accepts centripetal(default), chordal and catmullrom
  18495. * curve.tension is used for catmullrom which defaults to 0.5
  18496. */
  18497. /*
  18498. Based on an optimized c++ solution in
  18499. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18500. - http://ideone.com/NoEbVM
  18501. This CubicPoly class could be used for reusing some variables and calculations,
  18502. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18503. which can be placed in CurveUtils.
  18504. */
  18505. function CubicPoly() {
  18506. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  18507. /*
  18508. * Compute coefficients for a cubic polynomial
  18509. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18510. * such that
  18511. * p(0) = x0, p(1) = x1
  18512. * and
  18513. * p'(0) = t0, p'(1) = t1.
  18514. */
  18515. function init( x0, x1, t0, t1 ) {
  18516. c0 = x0;
  18517. c1 = t0;
  18518. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18519. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18520. }
  18521. return {
  18522. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  18523. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18524. },
  18525. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18526. // compute tangents when parameterized in [t1,t2]
  18527. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18528. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18529. // rescale tangents for parametrization in [0,1]
  18530. t1 *= dt1;
  18531. t2 *= dt1;
  18532. init( x1, x2, t1, t2 );
  18533. },
  18534. calc: function ( t ) {
  18535. const t2 = t * t;
  18536. const t3 = t2 * t;
  18537. return c0 + c1 * t + c2 * t2 + c3 * t3;
  18538. }
  18539. };
  18540. }
  18541. //
  18542. const tmp = new Vector3();
  18543. const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  18544. class CatmullRomCurve3 extends Curve {
  18545. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  18546. super();
  18547. this.type = 'CatmullRomCurve3';
  18548. this.points = points;
  18549. this.closed = closed;
  18550. this.curveType = curveType;
  18551. this.tension = tension;
  18552. }
  18553. getPoint( t, optionalTarget = new Vector3() ) {
  18554. const point = optionalTarget;
  18555. const points = this.points;
  18556. const l = points.length;
  18557. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  18558. let intPoint = Math.floor( p );
  18559. let weight = p - intPoint;
  18560. if ( this.closed ) {
  18561. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  18562. } else if ( weight === 0 && intPoint === l - 1 ) {
  18563. intPoint = l - 2;
  18564. weight = 1;
  18565. }
  18566. let p0, p3; // 4 points (p1 & p2 defined below)
  18567. if ( this.closed || intPoint > 0 ) {
  18568. p0 = points[ ( intPoint - 1 ) % l ];
  18569. } else {
  18570. // extrapolate first point
  18571. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18572. p0 = tmp;
  18573. }
  18574. const p1 = points[ intPoint % l ];
  18575. const p2 = points[ ( intPoint + 1 ) % l ];
  18576. if ( this.closed || intPoint + 2 < l ) {
  18577. p3 = points[ ( intPoint + 2 ) % l ];
  18578. } else {
  18579. // extrapolate last point
  18580. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  18581. p3 = tmp;
  18582. }
  18583. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  18584. // init Centripetal / Chordal Catmull-Rom
  18585. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  18586. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18587. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18588. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18589. // safety check for repeated points
  18590. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18591. if ( dt0 < 1e-4 ) dt0 = dt1;
  18592. if ( dt2 < 1e-4 ) dt2 = dt1;
  18593. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18594. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18595. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18596. } else if ( this.curveType === 'catmullrom' ) {
  18597. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  18598. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  18599. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  18600. }
  18601. point.set(
  18602. px.calc( weight ),
  18603. py.calc( weight ),
  18604. pz.calc( weight )
  18605. );
  18606. return point;
  18607. }
  18608. copy( source ) {
  18609. super.copy( source );
  18610. this.points = [];
  18611. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  18612. const point = source.points[ i ];
  18613. this.points.push( point.clone() );
  18614. }
  18615. this.closed = source.closed;
  18616. this.curveType = source.curveType;
  18617. this.tension = source.tension;
  18618. return this;
  18619. }
  18620. toJSON() {
  18621. const data = super.toJSON();
  18622. data.points = [];
  18623. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  18624. const point = this.points[ i ];
  18625. data.points.push( point.toArray() );
  18626. }
  18627. data.closed = this.closed;
  18628. data.curveType = this.curveType;
  18629. data.tension = this.tension;
  18630. return data;
  18631. }
  18632. fromJSON( json ) {
  18633. super.fromJSON( json );
  18634. this.points = [];
  18635. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  18636. const point = json.points[ i ];
  18637. this.points.push( new Vector3().fromArray( point ) );
  18638. }
  18639. this.closed = json.closed;
  18640. this.curveType = json.curveType;
  18641. this.tension = json.tension;
  18642. return this;
  18643. }
  18644. }
  18645. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  18646. /**
  18647. * Bezier Curves formulas obtained from
  18648. * http://en.wikipedia.org/wiki/Bézier_curve
  18649. */
  18650. function CatmullRom( t, p0, p1, p2, p3 ) {
  18651. const v0 = ( p2 - p0 ) * 0.5;
  18652. const v1 = ( p3 - p1 ) * 0.5;
  18653. const t2 = t * t;
  18654. const t3 = t * t2;
  18655. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18656. }
  18657. //
  18658. function QuadraticBezierP0( t, p ) {
  18659. const k = 1 - t;
  18660. return k * k * p;
  18661. }
  18662. function QuadraticBezierP1( t, p ) {
  18663. return 2 * ( 1 - t ) * t * p;
  18664. }
  18665. function QuadraticBezierP2( t, p ) {
  18666. return t * t * p;
  18667. }
  18668. function QuadraticBezier( t, p0, p1, p2 ) {
  18669. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  18670. QuadraticBezierP2( t, p2 );
  18671. }
  18672. //
  18673. function CubicBezierP0( t, p ) {
  18674. const k = 1 - t;
  18675. return k * k * k * p;
  18676. }
  18677. function CubicBezierP1( t, p ) {
  18678. const k = 1 - t;
  18679. return 3 * k * k * t * p;
  18680. }
  18681. function CubicBezierP2( t, p ) {
  18682. return 3 * ( 1 - t ) * t * t * p;
  18683. }
  18684. function CubicBezierP3( t, p ) {
  18685. return t * t * t * p;
  18686. }
  18687. function CubicBezier( t, p0, p1, p2, p3 ) {
  18688. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  18689. CubicBezierP3( t, p3 );
  18690. }
  18691. class CubicBezierCurve extends Curve {
  18692. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  18693. super();
  18694. this.type = 'CubicBezierCurve';
  18695. this.v0 = v0;
  18696. this.v1 = v1;
  18697. this.v2 = v2;
  18698. this.v3 = v3;
  18699. }
  18700. getPoint( t, optionalTarget = new Vector2() ) {
  18701. const point = optionalTarget;
  18702. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18703. point.set(
  18704. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  18705. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  18706. );
  18707. return point;
  18708. }
  18709. copy( source ) {
  18710. super.copy( source );
  18711. this.v0.copy( source.v0 );
  18712. this.v1.copy( source.v1 );
  18713. this.v2.copy( source.v2 );
  18714. this.v3.copy( source.v3 );
  18715. return this;
  18716. }
  18717. toJSON() {
  18718. const data = super.toJSON();
  18719. data.v0 = this.v0.toArray();
  18720. data.v1 = this.v1.toArray();
  18721. data.v2 = this.v2.toArray();
  18722. data.v3 = this.v3.toArray();
  18723. return data;
  18724. }
  18725. fromJSON( json ) {
  18726. super.fromJSON( json );
  18727. this.v0.fromArray( json.v0 );
  18728. this.v1.fromArray( json.v1 );
  18729. this.v2.fromArray( json.v2 );
  18730. this.v3.fromArray( json.v3 );
  18731. return this;
  18732. }
  18733. }
  18734. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  18735. class CubicBezierCurve3 extends Curve {
  18736. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  18737. super();
  18738. this.type = 'CubicBezierCurve3';
  18739. this.v0 = v0;
  18740. this.v1 = v1;
  18741. this.v2 = v2;
  18742. this.v3 = v3;
  18743. }
  18744. getPoint( t, optionalTarget = new Vector3() ) {
  18745. const point = optionalTarget;
  18746. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18747. point.set(
  18748. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  18749. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  18750. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  18751. );
  18752. return point;
  18753. }
  18754. copy( source ) {
  18755. super.copy( source );
  18756. this.v0.copy( source.v0 );
  18757. this.v1.copy( source.v1 );
  18758. this.v2.copy( source.v2 );
  18759. this.v3.copy( source.v3 );
  18760. return this;
  18761. }
  18762. toJSON() {
  18763. const data = super.toJSON();
  18764. data.v0 = this.v0.toArray();
  18765. data.v1 = this.v1.toArray();
  18766. data.v2 = this.v2.toArray();
  18767. data.v3 = this.v3.toArray();
  18768. return data;
  18769. }
  18770. fromJSON( json ) {
  18771. super.fromJSON( json );
  18772. this.v0.fromArray( json.v0 );
  18773. this.v1.fromArray( json.v1 );
  18774. this.v2.fromArray( json.v2 );
  18775. this.v3.fromArray( json.v3 );
  18776. return this;
  18777. }
  18778. }
  18779. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  18780. class LineCurve extends Curve {
  18781. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  18782. super();
  18783. this.type = 'LineCurve';
  18784. this.v1 = v1;
  18785. this.v2 = v2;
  18786. }
  18787. getPoint( t, optionalTarget = new Vector2() ) {
  18788. const point = optionalTarget;
  18789. if ( t === 1 ) {
  18790. point.copy( this.v2 );
  18791. } else {
  18792. point.copy( this.v2 ).sub( this.v1 );
  18793. point.multiplyScalar( t ).add( this.v1 );
  18794. }
  18795. return point;
  18796. }
  18797. // Line curve is linear, so we can overwrite default getPointAt
  18798. getPointAt( u, optionalTarget ) {
  18799. return this.getPoint( u, optionalTarget );
  18800. }
  18801. getTangent( t, optionalTarget ) {
  18802. const tangent = optionalTarget || new Vector2();
  18803. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  18804. return tangent;
  18805. }
  18806. copy( source ) {
  18807. super.copy( source );
  18808. this.v1.copy( source.v1 );
  18809. this.v2.copy( source.v2 );
  18810. return this;
  18811. }
  18812. toJSON() {
  18813. const data = super.toJSON();
  18814. data.v1 = this.v1.toArray();
  18815. data.v2 = this.v2.toArray();
  18816. return data;
  18817. }
  18818. fromJSON( json ) {
  18819. super.fromJSON( json );
  18820. this.v1.fromArray( json.v1 );
  18821. this.v2.fromArray( json.v2 );
  18822. return this;
  18823. }
  18824. }
  18825. LineCurve.prototype.isLineCurve = true;
  18826. class LineCurve3 extends Curve {
  18827. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  18828. super();
  18829. this.type = 'LineCurve3';
  18830. this.isLineCurve3 = true;
  18831. this.v1 = v1;
  18832. this.v2 = v2;
  18833. }
  18834. getPoint( t, optionalTarget = new Vector3() ) {
  18835. const point = optionalTarget;
  18836. if ( t === 1 ) {
  18837. point.copy( this.v2 );
  18838. } else {
  18839. point.copy( this.v2 ).sub( this.v1 );
  18840. point.multiplyScalar( t ).add( this.v1 );
  18841. }
  18842. return point;
  18843. }
  18844. // Line curve is linear, so we can overwrite default getPointAt
  18845. getPointAt( u, optionalTarget ) {
  18846. return this.getPoint( u, optionalTarget );
  18847. }
  18848. copy( source ) {
  18849. super.copy( source );
  18850. this.v1.copy( source.v1 );
  18851. this.v2.copy( source.v2 );
  18852. return this;
  18853. }
  18854. toJSON() {
  18855. const data = super.toJSON();
  18856. data.v1 = this.v1.toArray();
  18857. data.v2 = this.v2.toArray();
  18858. return data;
  18859. }
  18860. fromJSON( json ) {
  18861. super.fromJSON( json );
  18862. this.v1.fromArray( json.v1 );
  18863. this.v2.fromArray( json.v2 );
  18864. return this;
  18865. }
  18866. }
  18867. class QuadraticBezierCurve extends Curve {
  18868. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  18869. super();
  18870. this.type = 'QuadraticBezierCurve';
  18871. this.v0 = v0;
  18872. this.v1 = v1;
  18873. this.v2 = v2;
  18874. }
  18875. getPoint( t, optionalTarget = new Vector2() ) {
  18876. const point = optionalTarget;
  18877. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  18878. point.set(
  18879. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  18880. QuadraticBezier( t, v0.y, v1.y, v2.y )
  18881. );
  18882. return point;
  18883. }
  18884. copy( source ) {
  18885. super.copy( source );
  18886. this.v0.copy( source.v0 );
  18887. this.v1.copy( source.v1 );
  18888. this.v2.copy( source.v2 );
  18889. return this;
  18890. }
  18891. toJSON() {
  18892. const data = super.toJSON();
  18893. data.v0 = this.v0.toArray();
  18894. data.v1 = this.v1.toArray();
  18895. data.v2 = this.v2.toArray();
  18896. return data;
  18897. }
  18898. fromJSON( json ) {
  18899. super.fromJSON( json );
  18900. this.v0.fromArray( json.v0 );
  18901. this.v1.fromArray( json.v1 );
  18902. this.v2.fromArray( json.v2 );
  18903. return this;
  18904. }
  18905. }
  18906. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  18907. class QuadraticBezierCurve3 extends Curve {
  18908. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  18909. super();
  18910. this.type = 'QuadraticBezierCurve3';
  18911. this.v0 = v0;
  18912. this.v1 = v1;
  18913. this.v2 = v2;
  18914. }
  18915. getPoint( t, optionalTarget = new Vector3() ) {
  18916. const point = optionalTarget;
  18917. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  18918. point.set(
  18919. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  18920. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  18921. QuadraticBezier( t, v0.z, v1.z, v2.z )
  18922. );
  18923. return point;
  18924. }
  18925. copy( source ) {
  18926. super.copy( source );
  18927. this.v0.copy( source.v0 );
  18928. this.v1.copy( source.v1 );
  18929. this.v2.copy( source.v2 );
  18930. return this;
  18931. }
  18932. toJSON() {
  18933. const data = super.toJSON();
  18934. data.v0 = this.v0.toArray();
  18935. data.v1 = this.v1.toArray();
  18936. data.v2 = this.v2.toArray();
  18937. return data;
  18938. }
  18939. fromJSON( json ) {
  18940. super.fromJSON( json );
  18941. this.v0.fromArray( json.v0 );
  18942. this.v1.fromArray( json.v1 );
  18943. this.v2.fromArray( json.v2 );
  18944. return this;
  18945. }
  18946. }
  18947. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  18948. class SplineCurve extends Curve {
  18949. constructor( points = [] ) {
  18950. super();
  18951. this.type = 'SplineCurve';
  18952. this.points = points;
  18953. }
  18954. getPoint( t, optionalTarget = new Vector2() ) {
  18955. const point = optionalTarget;
  18956. const points = this.points;
  18957. const p = ( points.length - 1 ) * t;
  18958. const intPoint = Math.floor( p );
  18959. const weight = p - intPoint;
  18960. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18961. const p1 = points[ intPoint ];
  18962. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18963. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18964. point.set(
  18965. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  18966. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  18967. );
  18968. return point;
  18969. }
  18970. copy( source ) {
  18971. super.copy( source );
  18972. this.points = [];
  18973. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  18974. const point = source.points[ i ];
  18975. this.points.push( point.clone() );
  18976. }
  18977. return this;
  18978. }
  18979. toJSON() {
  18980. const data = super.toJSON();
  18981. data.points = [];
  18982. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  18983. const point = this.points[ i ];
  18984. data.points.push( point.toArray() );
  18985. }
  18986. return data;
  18987. }
  18988. fromJSON( json ) {
  18989. super.fromJSON( json );
  18990. this.points = [];
  18991. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  18992. const point = json.points[ i ];
  18993. this.points.push( new Vector2().fromArray( point ) );
  18994. }
  18995. return this;
  18996. }
  18997. }
  18998. SplineCurve.prototype.isSplineCurve = true;
  18999. var Curves = /*#__PURE__*/Object.freeze({
  19000. __proto__: null,
  19001. ArcCurve: ArcCurve,
  19002. CatmullRomCurve3: CatmullRomCurve3,
  19003. CubicBezierCurve: CubicBezierCurve,
  19004. CubicBezierCurve3: CubicBezierCurve3,
  19005. EllipseCurve: EllipseCurve,
  19006. LineCurve: LineCurve,
  19007. LineCurve3: LineCurve3,
  19008. QuadraticBezierCurve: QuadraticBezierCurve,
  19009. QuadraticBezierCurve3: QuadraticBezierCurve3,
  19010. SplineCurve: SplineCurve
  19011. });
  19012. /**
  19013. * Port from https://github.com/mapbox/earcut (v2.2.2)
  19014. */
  19015. const Earcut = {
  19016. triangulate: function ( data, holeIndices, dim = 2 ) {
  19017. const hasHoles = holeIndices && holeIndices.length;
  19018. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  19019. let outerNode = linkedList( data, 0, outerLen, dim, true );
  19020. const triangles = [];
  19021. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  19022. let minX, minY, maxX, maxY, x, y, invSize;
  19023. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  19024. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  19025. if ( data.length > 80 * dim ) {
  19026. minX = maxX = data[ 0 ];
  19027. minY = maxY = data[ 1 ];
  19028. for ( let i = dim; i < outerLen; i += dim ) {
  19029. x = data[ i ];
  19030. y = data[ i + 1 ];
  19031. if ( x < minX ) minX = x;
  19032. if ( y < minY ) minY = y;
  19033. if ( x > maxX ) maxX = x;
  19034. if ( y > maxY ) maxY = y;
  19035. }
  19036. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  19037. invSize = Math.max( maxX - minX, maxY - minY );
  19038. invSize = invSize !== 0 ? 1 / invSize : 0;
  19039. }
  19040. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  19041. return triangles;
  19042. }
  19043. };
  19044. // create a circular doubly linked list from polygon points in the specified winding order
  19045. function linkedList( data, start, end, dim, clockwise ) {
  19046. let i, last;
  19047. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  19048. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  19049. } else {
  19050. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  19051. }
  19052. if ( last && equals( last, last.next ) ) {
  19053. removeNode( last );
  19054. last = last.next;
  19055. }
  19056. return last;
  19057. }
  19058. // eliminate colinear or duplicate points
  19059. function filterPoints( start, end ) {
  19060. if ( ! start ) return start;
  19061. if ( ! end ) end = start;
  19062. let p = start,
  19063. again;
  19064. do {
  19065. again = false;
  19066. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  19067. removeNode( p );
  19068. p = end = p.prev;
  19069. if ( p === p.next ) break;
  19070. again = true;
  19071. } else {
  19072. p = p.next;
  19073. }
  19074. } while ( again || p !== end );
  19075. return end;
  19076. }
  19077. // main ear slicing loop which triangulates a polygon (given as a linked list)
  19078. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  19079. if ( ! ear ) return;
  19080. // interlink polygon nodes in z-order
  19081. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  19082. let stop = ear,
  19083. prev, next;
  19084. // iterate through ears, slicing them one by one
  19085. while ( ear.prev !== ear.next ) {
  19086. prev = ear.prev;
  19087. next = ear.next;
  19088. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  19089. // cut off the triangle
  19090. triangles.push( prev.i / dim );
  19091. triangles.push( ear.i / dim );
  19092. triangles.push( next.i / dim );
  19093. removeNode( ear );
  19094. // skipping the next vertex leads to less sliver triangles
  19095. ear = next.next;
  19096. stop = next.next;
  19097. continue;
  19098. }
  19099. ear = next;
  19100. // if we looped through the whole remaining polygon and can't find any more ears
  19101. if ( ear === stop ) {
  19102. // try filtering points and slicing again
  19103. if ( ! pass ) {
  19104. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  19105. // if this didn't work, try curing all small self-intersections locally
  19106. } else if ( pass === 1 ) {
  19107. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  19108. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  19109. // as a last resort, try splitting the remaining polygon into two
  19110. } else if ( pass === 2 ) {
  19111. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  19112. }
  19113. break;
  19114. }
  19115. }
  19116. }
  19117. // check whether a polygon node forms a valid ear with adjacent nodes
  19118. function isEar( ear ) {
  19119. const a = ear.prev,
  19120. b = ear,
  19121. c = ear.next;
  19122. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  19123. // now make sure we don't have other points inside the potential ear
  19124. let p = ear.next.next;
  19125. while ( p !== ear.prev ) {
  19126. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  19127. area( p.prev, p, p.next ) >= 0 ) return false;
  19128. p = p.next;
  19129. }
  19130. return true;
  19131. }
  19132. function isEarHashed( ear, minX, minY, invSize ) {
  19133. const a = ear.prev,
  19134. b = ear,
  19135. c = ear.next;
  19136. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  19137. // triangle bbox; min & max are calculated like this for speed
  19138. const minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  19139. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  19140. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  19141. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  19142. // z-order range for the current triangle bbox;
  19143. const minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  19144. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  19145. let p = ear.prevZ,
  19146. n = ear.nextZ;
  19147. // look for points inside the triangle in both directions
  19148. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  19149. if ( p !== ear.prev && p !== ear.next &&
  19150. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  19151. area( p.prev, p, p.next ) >= 0 ) return false;
  19152. p = p.prevZ;
  19153. if ( n !== ear.prev && n !== ear.next &&
  19154. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  19155. area( n.prev, n, n.next ) >= 0 ) return false;
  19156. n = n.nextZ;
  19157. }
  19158. // look for remaining points in decreasing z-order
  19159. while ( p && p.z >= minZ ) {
  19160. if ( p !== ear.prev && p !== ear.next &&
  19161. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  19162. area( p.prev, p, p.next ) >= 0 ) return false;
  19163. p = p.prevZ;
  19164. }
  19165. // look for remaining points in increasing z-order
  19166. while ( n && n.z <= maxZ ) {
  19167. if ( n !== ear.prev && n !== ear.next &&
  19168. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  19169. area( n.prev, n, n.next ) >= 0 ) return false;
  19170. n = n.nextZ;
  19171. }
  19172. return true;
  19173. }
  19174. // go through all polygon nodes and cure small local self-intersections
  19175. function cureLocalIntersections( start, triangles, dim ) {
  19176. let p = start;
  19177. do {
  19178. const a = p.prev,
  19179. b = p.next.next;
  19180. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  19181. triangles.push( a.i / dim );
  19182. triangles.push( p.i / dim );
  19183. triangles.push( b.i / dim );
  19184. // remove two nodes involved
  19185. removeNode( p );
  19186. removeNode( p.next );
  19187. p = start = b;
  19188. }
  19189. p = p.next;
  19190. } while ( p !== start );
  19191. return filterPoints( p );
  19192. }
  19193. // try splitting polygon into two and triangulate them independently
  19194. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  19195. // look for a valid diagonal that divides the polygon into two
  19196. let a = start;
  19197. do {
  19198. let b = a.next.next;
  19199. while ( b !== a.prev ) {
  19200. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  19201. // split the polygon in two by the diagonal
  19202. let c = splitPolygon( a, b );
  19203. // filter colinear points around the cuts
  19204. a = filterPoints( a, a.next );
  19205. c = filterPoints( c, c.next );
  19206. // run earcut on each half
  19207. earcutLinked( a, triangles, dim, minX, minY, invSize );
  19208. earcutLinked( c, triangles, dim, minX, minY, invSize );
  19209. return;
  19210. }
  19211. b = b.next;
  19212. }
  19213. a = a.next;
  19214. } while ( a !== start );
  19215. }
  19216. // link every hole into the outer loop, producing a single-ring polygon without holes
  19217. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  19218. const queue = [];
  19219. let i, len, start, end, list;
  19220. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  19221. start = holeIndices[ i ] * dim;
  19222. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  19223. list = linkedList( data, start, end, dim, false );
  19224. if ( list === list.next ) list.steiner = true;
  19225. queue.push( getLeftmost( list ) );
  19226. }
  19227. queue.sort( compareX );
  19228. // process holes from left to right
  19229. for ( i = 0; i < queue.length; i ++ ) {
  19230. eliminateHole( queue[ i ], outerNode );
  19231. outerNode = filterPoints( outerNode, outerNode.next );
  19232. }
  19233. return outerNode;
  19234. }
  19235. function compareX( a, b ) {
  19236. return a.x - b.x;
  19237. }
  19238. // find a bridge between vertices that connects hole with an outer ring and and link it
  19239. function eliminateHole( hole, outerNode ) {
  19240. outerNode = findHoleBridge( hole, outerNode );
  19241. if ( outerNode ) {
  19242. const b = splitPolygon( outerNode, hole );
  19243. // filter collinear points around the cuts
  19244. filterPoints( outerNode, outerNode.next );
  19245. filterPoints( b, b.next );
  19246. }
  19247. }
  19248. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  19249. function findHoleBridge( hole, outerNode ) {
  19250. let p = outerNode;
  19251. const hx = hole.x;
  19252. const hy = hole.y;
  19253. let qx = - Infinity, m;
  19254. // find a segment intersected by a ray from the hole's leftmost point to the left;
  19255. // segment's endpoint with lesser x will be potential connection point
  19256. do {
  19257. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  19258. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  19259. if ( x <= hx && x > qx ) {
  19260. qx = x;
  19261. if ( x === hx ) {
  19262. if ( hy === p.y ) return p;
  19263. if ( hy === p.next.y ) return p.next;
  19264. }
  19265. m = p.x < p.next.x ? p : p.next;
  19266. }
  19267. }
  19268. p = p.next;
  19269. } while ( p !== outerNode );
  19270. if ( ! m ) return null;
  19271. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  19272. // look for points inside the triangle of hole point, segment intersection and endpoint;
  19273. // if there are no points found, we have a valid connection;
  19274. // otherwise choose the point of the minimum angle with the ray as connection point
  19275. const stop = m,
  19276. mx = m.x,
  19277. my = m.y;
  19278. let tanMin = Infinity, tan;
  19279. p = m;
  19280. do {
  19281. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  19282. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  19283. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  19284. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  19285. m = p;
  19286. tanMin = tan;
  19287. }
  19288. }
  19289. p = p.next;
  19290. } while ( p !== stop );
  19291. return m;
  19292. }
  19293. // whether sector in vertex m contains sector in vertex p in the same coordinates
  19294. function sectorContainsSector( m, p ) {
  19295. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  19296. }
  19297. // interlink polygon nodes in z-order
  19298. function indexCurve( start, minX, minY, invSize ) {
  19299. let p = start;
  19300. do {
  19301. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  19302. p.prevZ = p.prev;
  19303. p.nextZ = p.next;
  19304. p = p.next;
  19305. } while ( p !== start );
  19306. p.prevZ.nextZ = null;
  19307. p.prevZ = null;
  19308. sortLinked( p );
  19309. }
  19310. // Simon Tatham's linked list merge sort algorithm
  19311. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  19312. function sortLinked( list ) {
  19313. let i, p, q, e, tail, numMerges, pSize, qSize,
  19314. inSize = 1;
  19315. do {
  19316. p = list;
  19317. list = null;
  19318. tail = null;
  19319. numMerges = 0;
  19320. while ( p ) {
  19321. numMerges ++;
  19322. q = p;
  19323. pSize = 0;
  19324. for ( i = 0; i < inSize; i ++ ) {
  19325. pSize ++;
  19326. q = q.nextZ;
  19327. if ( ! q ) break;
  19328. }
  19329. qSize = inSize;
  19330. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  19331. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  19332. e = p;
  19333. p = p.nextZ;
  19334. pSize --;
  19335. } else {
  19336. e = q;
  19337. q = q.nextZ;
  19338. qSize --;
  19339. }
  19340. if ( tail ) tail.nextZ = e;
  19341. else list = e;
  19342. e.prevZ = tail;
  19343. tail = e;
  19344. }
  19345. p = q;
  19346. }
  19347. tail.nextZ = null;
  19348. inSize *= 2;
  19349. } while ( numMerges > 1 );
  19350. return list;
  19351. }
  19352. // z-order of a point given coords and inverse of the longer side of data bbox
  19353. function zOrder( x, y, minX, minY, invSize ) {
  19354. // coords are transformed into non-negative 15-bit integer range
  19355. x = 32767 * ( x - minX ) * invSize;
  19356. y = 32767 * ( y - minY ) * invSize;
  19357. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  19358. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  19359. x = ( x | ( x << 2 ) ) & 0x33333333;
  19360. x = ( x | ( x << 1 ) ) & 0x55555555;
  19361. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  19362. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  19363. y = ( y | ( y << 2 ) ) & 0x33333333;
  19364. y = ( y | ( y << 1 ) ) & 0x55555555;
  19365. return x | ( y << 1 );
  19366. }
  19367. // find the leftmost node of a polygon ring
  19368. function getLeftmost( start ) {
  19369. let p = start,
  19370. leftmost = start;
  19371. do {
  19372. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  19373. p = p.next;
  19374. } while ( p !== start );
  19375. return leftmost;
  19376. }
  19377. // check if a point lies within a convex triangle
  19378. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  19379. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  19380. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  19381. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  19382. }
  19383. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  19384. function isValidDiagonal( a, b ) {
  19385. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  19386. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  19387. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  19388. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  19389. }
  19390. // signed area of a triangle
  19391. function area( p, q, r ) {
  19392. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  19393. }
  19394. // check if two points are equal
  19395. function equals( p1, p2 ) {
  19396. return p1.x === p2.x && p1.y === p2.y;
  19397. }
  19398. // check if two segments intersect
  19399. function intersects( p1, q1, p2, q2 ) {
  19400. const o1 = sign( area( p1, q1, p2 ) );
  19401. const o2 = sign( area( p1, q1, q2 ) );
  19402. const o3 = sign( area( p2, q2, p1 ) );
  19403. const o4 = sign( area( p2, q2, q1 ) );
  19404. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  19405. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  19406. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  19407. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  19408. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  19409. return false;
  19410. }
  19411. // for collinear points p, q, r, check if point q lies on segment pr
  19412. function onSegment( p, q, r ) {
  19413. 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 );
  19414. }
  19415. function sign( num ) {
  19416. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  19417. }
  19418. // check if a polygon diagonal intersects any polygon segments
  19419. function intersectsPolygon( a, b ) {
  19420. let p = a;
  19421. do {
  19422. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  19423. intersects( p, p.next, a, b ) ) return true;
  19424. p = p.next;
  19425. } while ( p !== a );
  19426. return false;
  19427. }
  19428. // check if a polygon diagonal is locally inside the polygon
  19429. function locallyInside( a, b ) {
  19430. return area( a.prev, a, a.next ) < 0 ?
  19431. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  19432. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  19433. }
  19434. // check if the middle point of a polygon diagonal is inside the polygon
  19435. function middleInside( a, b ) {
  19436. let p = a,
  19437. inside = false;
  19438. const px = ( a.x + b.x ) / 2,
  19439. py = ( a.y + b.y ) / 2;
  19440. do {
  19441. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  19442. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  19443. inside = ! inside;
  19444. p = p.next;
  19445. } while ( p !== a );
  19446. return inside;
  19447. }
  19448. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  19449. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  19450. function splitPolygon( a, b ) {
  19451. const a2 = new Node( a.i, a.x, a.y ),
  19452. b2 = new Node( b.i, b.x, b.y ),
  19453. an = a.next,
  19454. bp = b.prev;
  19455. a.next = b;
  19456. b.prev = a;
  19457. a2.next = an;
  19458. an.prev = a2;
  19459. b2.next = a2;
  19460. a2.prev = b2;
  19461. bp.next = b2;
  19462. b2.prev = bp;
  19463. return b2;
  19464. }
  19465. // create a node and optionally link it with previous one (in a circular doubly linked list)
  19466. function insertNode( i, x, y, last ) {
  19467. const p = new Node( i, x, y );
  19468. if ( ! last ) {
  19469. p.prev = p;
  19470. p.next = p;
  19471. } else {
  19472. p.next = last.next;
  19473. p.prev = last;
  19474. last.next.prev = p;
  19475. last.next = p;
  19476. }
  19477. return p;
  19478. }
  19479. function removeNode( p ) {
  19480. p.next.prev = p.prev;
  19481. p.prev.next = p.next;
  19482. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  19483. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  19484. }
  19485. function Node( i, x, y ) {
  19486. // vertex index in coordinates array
  19487. this.i = i;
  19488. // vertex coordinates
  19489. this.x = x;
  19490. this.y = y;
  19491. // previous and next vertex nodes in a polygon ring
  19492. this.prev = null;
  19493. this.next = null;
  19494. // z-order curve value
  19495. this.z = null;
  19496. // previous and next nodes in z-order
  19497. this.prevZ = null;
  19498. this.nextZ = null;
  19499. // indicates whether this is a steiner point
  19500. this.steiner = false;
  19501. }
  19502. function signedArea( data, start, end, dim ) {
  19503. let sum = 0;
  19504. for ( let i = start, j = end - dim; i < end; i += dim ) {
  19505. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  19506. j = i;
  19507. }
  19508. return sum;
  19509. }
  19510. class ShapeUtils {
  19511. // calculate area of the contour polygon
  19512. static area( contour ) {
  19513. const n = contour.length;
  19514. let a = 0.0;
  19515. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  19516. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19517. }
  19518. return a * 0.5;
  19519. }
  19520. static isClockWise( pts ) {
  19521. return ShapeUtils.area( pts ) < 0;
  19522. }
  19523. static triangulateShape( contour, holes ) {
  19524. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  19525. const holeIndices = []; // array of hole indices
  19526. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  19527. removeDupEndPts( contour );
  19528. addContour( vertices, contour );
  19529. //
  19530. let holeIndex = contour.length;
  19531. holes.forEach( removeDupEndPts );
  19532. for ( let i = 0; i < holes.length; i ++ ) {
  19533. holeIndices.push( holeIndex );
  19534. holeIndex += holes[ i ].length;
  19535. addContour( vertices, holes[ i ] );
  19536. }
  19537. //
  19538. const triangles = Earcut.triangulate( vertices, holeIndices );
  19539. //
  19540. for ( let i = 0; i < triangles.length; i += 3 ) {
  19541. faces.push( triangles.slice( i, i + 3 ) );
  19542. }
  19543. return faces;
  19544. }
  19545. }
  19546. function removeDupEndPts( points ) {
  19547. const l = points.length;
  19548. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  19549. points.pop();
  19550. }
  19551. }
  19552. function addContour( vertices, contour ) {
  19553. for ( let i = 0; i < contour.length; i ++ ) {
  19554. vertices.push( contour[ i ].x );
  19555. vertices.push( contour[ i ].y );
  19556. }
  19557. }
  19558. /**
  19559. * Creates extruded geometry from a path shape.
  19560. *
  19561. * parameters = {
  19562. *
  19563. * curveSegments: <int>, // number of points on the curves
  19564. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19565. * depth: <float>, // Depth to extrude the shape
  19566. *
  19567. * bevelEnabled: <bool>, // turn on bevel
  19568. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19569. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  19570. * bevelOffset: <float>, // how far from shape outline does bevel start
  19571. * bevelSegments: <int>, // number of bevel layers
  19572. *
  19573. * extrudePath: <THREE.Curve> // curve to extrude shape along
  19574. *
  19575. * UVGenerator: <Object> // object that provides UV generator functions
  19576. *
  19577. * }
  19578. */
  19579. class ExtrudeGeometry extends BufferGeometry {
  19580. constructor( shapes, options ) {
  19581. super();
  19582. this.type = 'ExtrudeGeometry';
  19583. this.parameters = {
  19584. shapes: shapes,
  19585. options: options
  19586. };
  19587. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19588. const scope = this;
  19589. const verticesArray = [];
  19590. const uvArray = [];
  19591. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  19592. const shape = shapes[ i ];
  19593. addShape( shape );
  19594. }
  19595. // build geometry
  19596. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  19597. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  19598. this.computeVertexNormals();
  19599. // functions
  19600. function addShape( shape ) {
  19601. const placeholder = [];
  19602. // options
  19603. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19604. const steps = options.steps !== undefined ? options.steps : 1;
  19605. let depth = options.depth !== undefined ? options.depth : 100;
  19606. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  19607. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  19608. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  19609. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  19610. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19611. const extrudePath = options.extrudePath;
  19612. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  19613. // deprecated options
  19614. if ( options.amount !== undefined ) {
  19615. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  19616. depth = options.amount;
  19617. }
  19618. //
  19619. let extrudePts, extrudeByPath = false;
  19620. let splineTube, binormal, normal, position2;
  19621. if ( extrudePath ) {
  19622. extrudePts = extrudePath.getSpacedPoints( steps );
  19623. extrudeByPath = true;
  19624. bevelEnabled = false; // bevels not supported for path extrusion
  19625. // SETUP TNB variables
  19626. // TODO1 - have a .isClosed in spline?
  19627. splineTube = extrudePath.computeFrenetFrames( steps, false );
  19628. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19629. binormal = new Vector3();
  19630. normal = new Vector3();
  19631. position2 = new Vector3();
  19632. }
  19633. // Safeguards if bevels are not enabled
  19634. if ( ! bevelEnabled ) {
  19635. bevelSegments = 0;
  19636. bevelThickness = 0;
  19637. bevelSize = 0;
  19638. bevelOffset = 0;
  19639. }
  19640. // Variables initialization
  19641. const shapePoints = shape.extractPoints( curveSegments );
  19642. let vertices = shapePoints.shape;
  19643. const holes = shapePoints.holes;
  19644. const reverse = ! ShapeUtils.isClockWise( vertices );
  19645. if ( reverse ) {
  19646. vertices = vertices.reverse();
  19647. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19648. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19649. const ahole = holes[ h ];
  19650. if ( ShapeUtils.isClockWise( ahole ) ) {
  19651. holes[ h ] = ahole.reverse();
  19652. }
  19653. }
  19654. }
  19655. const faces = ShapeUtils.triangulateShape( vertices, holes );
  19656. /* Vertices */
  19657. const contour = vertices; // vertices has all points but contour has only points of circumference
  19658. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19659. const ahole = holes[ h ];
  19660. vertices = vertices.concat( ahole );
  19661. }
  19662. function scalePt2( pt, vec, size ) {
  19663. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  19664. return vec.clone().multiplyScalar( size ).add( pt );
  19665. }
  19666. const vlen = vertices.length, flen = faces.length;
  19667. // Find directions for point movement
  19668. function getBevelVec( inPt, inPrev, inNext ) {
  19669. // computes for inPt the corresponding point inPt' on a new contour
  19670. // shifted by 1 unit (length of normalized vector) to the left
  19671. // if we walk along contour clockwise, this new contour is outside the old one
  19672. //
  19673. // inPt' is the intersection of the two lines parallel to the two
  19674. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19675. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  19676. // good reading for geometry algorithms (here: line-line intersection)
  19677. // http://geomalgorithms.com/a05-_intersect-1.html
  19678. const v_prev_x = inPt.x - inPrev.x,
  19679. v_prev_y = inPt.y - inPrev.y;
  19680. const v_next_x = inNext.x - inPt.x,
  19681. v_next_y = inNext.y - inPt.y;
  19682. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19683. // check for collinear edges
  19684. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19685. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  19686. // not collinear
  19687. // length of vectors for normalizing
  19688. const v_prev_len = Math.sqrt( v_prev_lensq );
  19689. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19690. // shift adjacent points by unit vectors to the left
  19691. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19692. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19693. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19694. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19695. // scaling factor for v_prev to intersection point
  19696. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19697. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19698. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19699. // vector from inPt to intersection point
  19700. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19701. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19702. // Don't normalize!, otherwise sharp corners become ugly
  19703. // but prevent crazy spikes
  19704. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19705. if ( v_trans_lensq <= 2 ) {
  19706. return new Vector2( v_trans_x, v_trans_y );
  19707. } else {
  19708. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19709. }
  19710. } else {
  19711. // handle special case of collinear edges
  19712. let direction_eq = false; // assumes: opposite
  19713. if ( v_prev_x > Number.EPSILON ) {
  19714. if ( v_next_x > Number.EPSILON ) {
  19715. direction_eq = true;
  19716. }
  19717. } else {
  19718. if ( v_prev_x < - Number.EPSILON ) {
  19719. if ( v_next_x < - Number.EPSILON ) {
  19720. direction_eq = true;
  19721. }
  19722. } else {
  19723. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19724. direction_eq = true;
  19725. }
  19726. }
  19727. }
  19728. if ( direction_eq ) {
  19729. // console.log("Warning: lines are a straight sequence");
  19730. v_trans_x = - v_prev_y;
  19731. v_trans_y = v_prev_x;
  19732. shrink_by = Math.sqrt( v_prev_lensq );
  19733. } else {
  19734. // console.log("Warning: lines are a straight spike");
  19735. v_trans_x = v_prev_x;
  19736. v_trans_y = v_prev_y;
  19737. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19738. }
  19739. }
  19740. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19741. }
  19742. const contourMovements = [];
  19743. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19744. if ( j === il ) j = 0;
  19745. if ( k === il ) k = 0;
  19746. // (j)---(i)---(k)
  19747. // console.log('i,j,k', i, j , k)
  19748. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19749. }
  19750. const holesMovements = [];
  19751. let oneHoleMovements, verticesMovements = contourMovements.concat();
  19752. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19753. const ahole = holes[ h ];
  19754. oneHoleMovements = [];
  19755. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19756. if ( j === il ) j = 0;
  19757. if ( k === il ) k = 0;
  19758. // (j)---(i)---(k)
  19759. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19760. }
  19761. holesMovements.push( oneHoleMovements );
  19762. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19763. }
  19764. // Loop bevelSegments, 1 for the front, 1 for the back
  19765. for ( let b = 0; b < bevelSegments; b ++ ) {
  19766. //for ( b = bevelSegments; b > 0; b -- ) {
  19767. const t = b / bevelSegments;
  19768. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  19769. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  19770. // contract shape
  19771. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  19772. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19773. v( vert.x, vert.y, - z );
  19774. }
  19775. // expand holes
  19776. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19777. const ahole = holes[ h ];
  19778. oneHoleMovements = holesMovements[ h ];
  19779. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  19780. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19781. v( vert.x, vert.y, - z );
  19782. }
  19783. }
  19784. }
  19785. const bs = bevelSize + bevelOffset;
  19786. // Back facing vertices
  19787. for ( let i = 0; i < vlen; i ++ ) {
  19788. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19789. if ( ! extrudeByPath ) {
  19790. v( vert.x, vert.y, 0 );
  19791. } else {
  19792. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19793. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19794. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19795. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19796. v( position2.x, position2.y, position2.z );
  19797. }
  19798. }
  19799. // Add stepped vertices...
  19800. // Including front facing vertices
  19801. for ( let s = 1; s <= steps; s ++ ) {
  19802. for ( let i = 0; i < vlen; i ++ ) {
  19803. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19804. if ( ! extrudeByPath ) {
  19805. v( vert.x, vert.y, depth / steps * s );
  19806. } else {
  19807. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19808. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19809. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19810. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19811. v( position2.x, position2.y, position2.z );
  19812. }
  19813. }
  19814. }
  19815. // Add bevel segments planes
  19816. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19817. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  19818. const t = b / bevelSegments;
  19819. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  19820. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  19821. // contract shape
  19822. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  19823. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19824. v( vert.x, vert.y, depth + z );
  19825. }
  19826. // expand holes
  19827. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19828. const ahole = holes[ h ];
  19829. oneHoleMovements = holesMovements[ h ];
  19830. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  19831. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19832. if ( ! extrudeByPath ) {
  19833. v( vert.x, vert.y, depth + z );
  19834. } else {
  19835. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19836. }
  19837. }
  19838. }
  19839. }
  19840. /* Faces */
  19841. // Top and bottom faces
  19842. buildLidFaces();
  19843. // Sides faces
  19844. buildSideFaces();
  19845. ///// Internal functions
  19846. function buildLidFaces() {
  19847. const start = verticesArray.length / 3;
  19848. if ( bevelEnabled ) {
  19849. let layer = 0; // steps + 1
  19850. let offset = vlen * layer;
  19851. // Bottom faces
  19852. for ( let i = 0; i < flen; i ++ ) {
  19853. const face = faces[ i ];
  19854. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19855. }
  19856. layer = steps + bevelSegments * 2;
  19857. offset = vlen * layer;
  19858. // Top faces
  19859. for ( let i = 0; i < flen; i ++ ) {
  19860. const face = faces[ i ];
  19861. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19862. }
  19863. } else {
  19864. // Bottom faces
  19865. for ( let i = 0; i < flen; i ++ ) {
  19866. const face = faces[ i ];
  19867. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19868. }
  19869. // Top faces
  19870. for ( let i = 0; i < flen; i ++ ) {
  19871. const face = faces[ i ];
  19872. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19873. }
  19874. }
  19875. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  19876. }
  19877. // Create faces for the z-sides of the shape
  19878. function buildSideFaces() {
  19879. const start = verticesArray.length / 3;
  19880. let layeroffset = 0;
  19881. sidewalls( contour, layeroffset );
  19882. layeroffset += contour.length;
  19883. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  19884. const ahole = holes[ h ];
  19885. sidewalls( ahole, layeroffset );
  19886. //, true
  19887. layeroffset += ahole.length;
  19888. }
  19889. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  19890. }
  19891. function sidewalls( contour, layeroffset ) {
  19892. let i = contour.length;
  19893. while ( -- i >= 0 ) {
  19894. const j = i;
  19895. let k = i - 1;
  19896. if ( k < 0 ) k = contour.length - 1;
  19897. //console.log('b', i,j, i-1, k,vertices.length);
  19898. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  19899. const slen1 = vlen * s;
  19900. const slen2 = vlen * ( s + 1 );
  19901. const a = layeroffset + j + slen1,
  19902. b = layeroffset + k + slen1,
  19903. c = layeroffset + k + slen2,
  19904. d = layeroffset + j + slen2;
  19905. f4( a, b, c, d );
  19906. }
  19907. }
  19908. }
  19909. function v( x, y, z ) {
  19910. placeholder.push( x );
  19911. placeholder.push( y );
  19912. placeholder.push( z );
  19913. }
  19914. function f3( a, b, c ) {
  19915. addVertex( a );
  19916. addVertex( b );
  19917. addVertex( c );
  19918. const nextIndex = verticesArray.length / 3;
  19919. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  19920. addUV( uvs[ 0 ] );
  19921. addUV( uvs[ 1 ] );
  19922. addUV( uvs[ 2 ] );
  19923. }
  19924. function f4( a, b, c, d ) {
  19925. addVertex( a );
  19926. addVertex( b );
  19927. addVertex( d );
  19928. addVertex( b );
  19929. addVertex( c );
  19930. addVertex( d );
  19931. const nextIndex = verticesArray.length / 3;
  19932. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  19933. addUV( uvs[ 0 ] );
  19934. addUV( uvs[ 1 ] );
  19935. addUV( uvs[ 3 ] );
  19936. addUV( uvs[ 1 ] );
  19937. addUV( uvs[ 2 ] );
  19938. addUV( uvs[ 3 ] );
  19939. }
  19940. function addVertex( index ) {
  19941. verticesArray.push( placeholder[ index * 3 + 0 ] );
  19942. verticesArray.push( placeholder[ index * 3 + 1 ] );
  19943. verticesArray.push( placeholder[ index * 3 + 2 ] );
  19944. }
  19945. function addUV( vector2 ) {
  19946. uvArray.push( vector2.x );
  19947. uvArray.push( vector2.y );
  19948. }
  19949. }
  19950. }
  19951. toJSON() {
  19952. const data = super.toJSON();
  19953. const shapes = this.parameters.shapes;
  19954. const options = this.parameters.options;
  19955. return toJSON$1( shapes, options, data );
  19956. }
  19957. static fromJSON( data, shapes ) {
  19958. const geometryShapes = [];
  19959. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  19960. const shape = shapes[ data.shapes[ j ] ];
  19961. geometryShapes.push( shape );
  19962. }
  19963. const extrudePath = data.options.extrudePath;
  19964. if ( extrudePath !== undefined ) {
  19965. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  19966. }
  19967. return new ExtrudeGeometry( geometryShapes, data.options );
  19968. }
  19969. }
  19970. const WorldUVGenerator = {
  19971. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  19972. const a_x = vertices[ indexA * 3 ];
  19973. const a_y = vertices[ indexA * 3 + 1 ];
  19974. const b_x = vertices[ indexB * 3 ];
  19975. const b_y = vertices[ indexB * 3 + 1 ];
  19976. const c_x = vertices[ indexC * 3 ];
  19977. const c_y = vertices[ indexC * 3 + 1 ];
  19978. return [
  19979. new Vector2( a_x, a_y ),
  19980. new Vector2( b_x, b_y ),
  19981. new Vector2( c_x, c_y )
  19982. ];
  19983. },
  19984. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  19985. const a_x = vertices[ indexA * 3 ];
  19986. const a_y = vertices[ indexA * 3 + 1 ];
  19987. const a_z = vertices[ indexA * 3 + 2 ];
  19988. const b_x = vertices[ indexB * 3 ];
  19989. const b_y = vertices[ indexB * 3 + 1 ];
  19990. const b_z = vertices[ indexB * 3 + 2 ];
  19991. const c_x = vertices[ indexC * 3 ];
  19992. const c_y = vertices[ indexC * 3 + 1 ];
  19993. const c_z = vertices[ indexC * 3 + 2 ];
  19994. const d_x = vertices[ indexD * 3 ];
  19995. const d_y = vertices[ indexD * 3 + 1 ];
  19996. const d_z = vertices[ indexD * 3 + 2 ];
  19997. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  19998. return [
  19999. new Vector2( a_x, 1 - a_z ),
  20000. new Vector2( b_x, 1 - b_z ),
  20001. new Vector2( c_x, 1 - c_z ),
  20002. new Vector2( d_x, 1 - d_z )
  20003. ];
  20004. } else {
  20005. return [
  20006. new Vector2( a_y, 1 - a_z ),
  20007. new Vector2( b_y, 1 - b_z ),
  20008. new Vector2( c_y, 1 - c_z ),
  20009. new Vector2( d_y, 1 - d_z )
  20010. ];
  20011. }
  20012. }
  20013. };
  20014. function toJSON$1( shapes, options, data ) {
  20015. data.shapes = [];
  20016. if ( Array.isArray( shapes ) ) {
  20017. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  20018. const shape = shapes[ i ];
  20019. data.shapes.push( shape.uuid );
  20020. }
  20021. } else {
  20022. data.shapes.push( shapes.uuid );
  20023. }
  20024. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  20025. return data;
  20026. }
  20027. class IcosahedronGeometry extends PolyhedronGeometry {
  20028. constructor( radius = 1, detail = 0 ) {
  20029. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20030. const vertices = [
  20031. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20032. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20033. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20034. ];
  20035. const indices = [
  20036. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20037. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20038. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20039. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20040. ];
  20041. super( vertices, indices, radius, detail );
  20042. this.type = 'IcosahedronGeometry';
  20043. this.parameters = {
  20044. radius: radius,
  20045. detail: detail
  20046. };
  20047. }
  20048. static fromJSON( data ) {
  20049. return new IcosahedronGeometry( data.radius, data.detail );
  20050. }
  20051. }
  20052. class LatheGeometry extends BufferGeometry {
  20053. 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 ) {
  20054. super();
  20055. this.type = 'LatheGeometry';
  20056. this.parameters = {
  20057. points: points,
  20058. segments: segments,
  20059. phiStart: phiStart,
  20060. phiLength: phiLength
  20061. };
  20062. segments = Math.floor( segments );
  20063. // clamp phiLength so it's in range of [ 0, 2PI ]
  20064. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  20065. // buffers
  20066. const indices = [];
  20067. const vertices = [];
  20068. const uvs = [];
  20069. // helper variables
  20070. const inverseSegments = 1.0 / segments;
  20071. const vertex = new Vector3();
  20072. const uv = new Vector2();
  20073. // generate vertices and uvs
  20074. for ( let i = 0; i <= segments; i ++ ) {
  20075. const phi = phiStart + i * inverseSegments * phiLength;
  20076. const sin = Math.sin( phi );
  20077. const cos = Math.cos( phi );
  20078. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  20079. // vertex
  20080. vertex.x = points[ j ].x * sin;
  20081. vertex.y = points[ j ].y;
  20082. vertex.z = points[ j ].x * cos;
  20083. vertices.push( vertex.x, vertex.y, vertex.z );
  20084. // uv
  20085. uv.x = i / segments;
  20086. uv.y = j / ( points.length - 1 );
  20087. uvs.push( uv.x, uv.y );
  20088. }
  20089. }
  20090. // indices
  20091. for ( let i = 0; i < segments; i ++ ) {
  20092. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  20093. const base = j + i * points.length;
  20094. const a = base;
  20095. const b = base + points.length;
  20096. const c = base + points.length + 1;
  20097. const d = base + 1;
  20098. // faces
  20099. indices.push( a, b, d );
  20100. indices.push( b, c, d );
  20101. }
  20102. }
  20103. // build geometry
  20104. this.setIndex( indices );
  20105. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20106. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20107. // generate normals
  20108. this.computeVertexNormals();
  20109. // if the geometry is closed, we need to average the normals along the seam.
  20110. // because the corresponding vertices are identical (but still have different UVs).
  20111. if ( phiLength === Math.PI * 2 ) {
  20112. const normals = this.attributes.normal.array;
  20113. const n1 = new Vector3();
  20114. const n2 = new Vector3();
  20115. const n = new Vector3();
  20116. // this is the buffer offset for the last line of vertices
  20117. const base = segments * points.length * 3;
  20118. for ( let i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  20119. // select the normal of the vertex in the first line
  20120. n1.x = normals[ j + 0 ];
  20121. n1.y = normals[ j + 1 ];
  20122. n1.z = normals[ j + 2 ];
  20123. // select the normal of the vertex in the last line
  20124. n2.x = normals[ base + j + 0 ];
  20125. n2.y = normals[ base + j + 1 ];
  20126. n2.z = normals[ base + j + 2 ];
  20127. // average normals
  20128. n.addVectors( n1, n2 ).normalize();
  20129. // assign the new values to both normals
  20130. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  20131. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  20132. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  20133. }
  20134. }
  20135. }
  20136. static fromJSON( data ) {
  20137. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  20138. }
  20139. }
  20140. class OctahedronGeometry extends PolyhedronGeometry {
  20141. constructor( radius = 1, detail = 0 ) {
  20142. const vertices = [
  20143. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  20144. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20145. ];
  20146. const indices = [
  20147. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  20148. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  20149. 1, 3, 4, 1, 4, 2
  20150. ];
  20151. super( vertices, indices, radius, detail );
  20152. this.type = 'OctahedronGeometry';
  20153. this.parameters = {
  20154. radius: radius,
  20155. detail: detail
  20156. };
  20157. }
  20158. static fromJSON( data ) {
  20159. return new OctahedronGeometry( data.radius, data.detail );
  20160. }
  20161. }
  20162. /**
  20163. * Parametric Surfaces Geometry
  20164. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  20165. */
  20166. class ParametricGeometry extends BufferGeometry {
  20167. constructor( func, slices, stacks ) {
  20168. super();
  20169. this.type = 'ParametricGeometry';
  20170. this.parameters = {
  20171. func: func,
  20172. slices: slices,
  20173. stacks: stacks
  20174. };
  20175. // buffers
  20176. const indices = [];
  20177. const vertices = [];
  20178. const normals = [];
  20179. const uvs = [];
  20180. const EPS = 0.00001;
  20181. const normal = new Vector3();
  20182. const p0 = new Vector3(), p1 = new Vector3();
  20183. const pu = new Vector3(), pv = new Vector3();
  20184. if ( func.length < 3 ) {
  20185. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  20186. }
  20187. // generate vertices, normals and uvs
  20188. const sliceCount = slices + 1;
  20189. for ( let i = 0; i <= stacks; i ++ ) {
  20190. const v = i / stacks;
  20191. for ( let j = 0; j <= slices; j ++ ) {
  20192. const u = j / slices;
  20193. // vertex
  20194. func( u, v, p0 );
  20195. vertices.push( p0.x, p0.y, p0.z );
  20196. // normal
  20197. // approximate tangent vectors via finite differences
  20198. if ( u - EPS >= 0 ) {
  20199. func( u - EPS, v, p1 );
  20200. pu.subVectors( p0, p1 );
  20201. } else {
  20202. func( u + EPS, v, p1 );
  20203. pu.subVectors( p1, p0 );
  20204. }
  20205. if ( v - EPS >= 0 ) {
  20206. func( u, v - EPS, p1 );
  20207. pv.subVectors( p0, p1 );
  20208. } else {
  20209. func( u, v + EPS, p1 );
  20210. pv.subVectors( p1, p0 );
  20211. }
  20212. // cross product of tangent vectors returns surface normal
  20213. normal.crossVectors( pu, pv ).normalize();
  20214. normals.push( normal.x, normal.y, normal.z );
  20215. // uv
  20216. uvs.push( u, v );
  20217. }
  20218. }
  20219. // generate indices
  20220. for ( let i = 0; i < stacks; i ++ ) {
  20221. for ( let j = 0; j < slices; j ++ ) {
  20222. const a = i * sliceCount + j;
  20223. const b = i * sliceCount + j + 1;
  20224. const c = ( i + 1 ) * sliceCount + j + 1;
  20225. const d = ( i + 1 ) * sliceCount + j;
  20226. // faces one and two
  20227. indices.push( a, b, d );
  20228. indices.push( b, c, d );
  20229. }
  20230. }
  20231. // build geometry
  20232. this.setIndex( indices );
  20233. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20234. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20235. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20236. }
  20237. }
  20238. class RingGeometry extends BufferGeometry {
  20239. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 8, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  20240. super();
  20241. this.type = 'RingGeometry';
  20242. this.parameters = {
  20243. innerRadius: innerRadius,
  20244. outerRadius: outerRadius,
  20245. thetaSegments: thetaSegments,
  20246. phiSegments: phiSegments,
  20247. thetaStart: thetaStart,
  20248. thetaLength: thetaLength
  20249. };
  20250. thetaSegments = Math.max( 3, thetaSegments );
  20251. phiSegments = Math.max( 1, phiSegments );
  20252. // buffers
  20253. const indices = [];
  20254. const vertices = [];
  20255. const normals = [];
  20256. const uvs = [];
  20257. // some helper variables
  20258. let radius = innerRadius;
  20259. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  20260. const vertex = new Vector3();
  20261. const uv = new Vector2();
  20262. // generate vertices, normals and uvs
  20263. for ( let j = 0; j <= phiSegments; j ++ ) {
  20264. for ( let i = 0; i <= thetaSegments; i ++ ) {
  20265. // values are generate from the inside of the ring to the outside
  20266. const segment = thetaStart + i / thetaSegments * thetaLength;
  20267. // vertex
  20268. vertex.x = radius * Math.cos( segment );
  20269. vertex.y = radius * Math.sin( segment );
  20270. vertices.push( vertex.x, vertex.y, vertex.z );
  20271. // normal
  20272. normals.push( 0, 0, 1 );
  20273. // uv
  20274. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  20275. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  20276. uvs.push( uv.x, uv.y );
  20277. }
  20278. // increase the radius for next row of vertices
  20279. radius += radiusStep;
  20280. }
  20281. // indices
  20282. for ( let j = 0; j < phiSegments; j ++ ) {
  20283. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  20284. for ( let i = 0; i < thetaSegments; i ++ ) {
  20285. const segment = i + thetaSegmentLevel;
  20286. const a = segment;
  20287. const b = segment + thetaSegments + 1;
  20288. const c = segment + thetaSegments + 2;
  20289. const d = segment + 1;
  20290. // faces
  20291. indices.push( a, b, d );
  20292. indices.push( b, c, d );
  20293. }
  20294. }
  20295. // build geometry
  20296. this.setIndex( indices );
  20297. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20298. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20299. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20300. }
  20301. static fromJSON( data ) {
  20302. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  20303. }
  20304. }
  20305. /**************************************************************
  20306. * Curved Path - a curve path is simply a array of connected
  20307. * curves, but retains the api of a curve
  20308. **************************************************************/
  20309. class CurvePath extends Curve {
  20310. constructor() {
  20311. super();
  20312. this.type = 'CurvePath';
  20313. this.curves = [];
  20314. this.autoClose = false; // Automatically closes the path
  20315. }
  20316. add( curve ) {
  20317. this.curves.push( curve );
  20318. }
  20319. closePath() {
  20320. // Add a line curve if start and end of lines are not connected
  20321. const startPoint = this.curves[ 0 ].getPoint( 0 );
  20322. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20323. if ( ! startPoint.equals( endPoint ) ) {
  20324. this.curves.push( new LineCurve( endPoint, startPoint ) );
  20325. }
  20326. }
  20327. // To get accurate point with reference to
  20328. // entire path distance at time t,
  20329. // following has to be done:
  20330. // 1. Length of each sub path have to be known
  20331. // 2. Locate and identify type of curve
  20332. // 3. Get t for the curve
  20333. // 4. Return curve.getPointAt(t')
  20334. getPoint( t, optionalTarget ) {
  20335. const d = t * this.getLength();
  20336. const curveLengths = this.getCurveLengths();
  20337. let i = 0;
  20338. // To think about boundaries points.
  20339. while ( i < curveLengths.length ) {
  20340. if ( curveLengths[ i ] >= d ) {
  20341. const diff = curveLengths[ i ] - d;
  20342. const curve = this.curves[ i ];
  20343. const segmentLength = curve.getLength();
  20344. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  20345. return curve.getPointAt( u, optionalTarget );
  20346. }
  20347. i ++;
  20348. }
  20349. return null;
  20350. // loop where sum != 0, sum > d , sum+1 <d
  20351. }
  20352. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20353. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20354. // getPoint() depends on getLength
  20355. getLength() {
  20356. const lens = this.getCurveLengths();
  20357. return lens[ lens.length - 1 ];
  20358. }
  20359. // cacheLengths must be recalculated.
  20360. updateArcLengths() {
  20361. this.needsUpdate = true;
  20362. this.cacheLengths = null;
  20363. this.getCurveLengths();
  20364. }
  20365. // Compute lengths and cache them
  20366. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20367. getCurveLengths() {
  20368. // We use cache values if curves and cache array are same length
  20369. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20370. return this.cacheLengths;
  20371. }
  20372. // Get length of sub-curve
  20373. // Push sums into cached array
  20374. const lengths = [];
  20375. let sums = 0;
  20376. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  20377. sums += this.curves[ i ].getLength();
  20378. lengths.push( sums );
  20379. }
  20380. this.cacheLengths = lengths;
  20381. return lengths;
  20382. }
  20383. getSpacedPoints( divisions = 40 ) {
  20384. const points = [];
  20385. for ( let i = 0; i <= divisions; i ++ ) {
  20386. points.push( this.getPoint( i / divisions ) );
  20387. }
  20388. if ( this.autoClose ) {
  20389. points.push( points[ 0 ] );
  20390. }
  20391. return points;
  20392. }
  20393. getPoints( divisions = 12 ) {
  20394. const points = [];
  20395. let last;
  20396. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  20397. const curve = curves[ i ];
  20398. const resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  20399. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  20400. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  20401. : divisions;
  20402. const pts = curve.getPoints( resolution );
  20403. for ( let j = 0; j < pts.length; j ++ ) {
  20404. const point = pts[ j ];
  20405. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  20406. points.push( point );
  20407. last = point;
  20408. }
  20409. }
  20410. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  20411. points.push( points[ 0 ] );
  20412. }
  20413. return points;
  20414. }
  20415. copy( source ) {
  20416. super.copy( source );
  20417. this.curves = [];
  20418. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  20419. const curve = source.curves[ i ];
  20420. this.curves.push( curve.clone() );
  20421. }
  20422. this.autoClose = source.autoClose;
  20423. return this;
  20424. }
  20425. toJSON() {
  20426. const data = super.toJSON();
  20427. data.autoClose = this.autoClose;
  20428. data.curves = [];
  20429. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  20430. const curve = this.curves[ i ];
  20431. data.curves.push( curve.toJSON() );
  20432. }
  20433. return data;
  20434. }
  20435. fromJSON( json ) {
  20436. super.fromJSON( json );
  20437. this.autoClose = json.autoClose;
  20438. this.curves = [];
  20439. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  20440. const curve = json.curves[ i ];
  20441. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  20442. }
  20443. return this;
  20444. }
  20445. }
  20446. class Path extends CurvePath {
  20447. constructor( points ) {
  20448. super();
  20449. this.type = 'Path';
  20450. this.currentPoint = new Vector2();
  20451. if ( points ) {
  20452. this.setFromPoints( points );
  20453. }
  20454. }
  20455. setFromPoints( points ) {
  20456. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  20457. for ( let i = 1, l = points.length; i < l; i ++ ) {
  20458. this.lineTo( points[ i ].x, points[ i ].y );
  20459. }
  20460. return this;
  20461. }
  20462. moveTo( x, y ) {
  20463. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  20464. return this;
  20465. }
  20466. lineTo( x, y ) {
  20467. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  20468. this.curves.push( curve );
  20469. this.currentPoint.set( x, y );
  20470. return this;
  20471. }
  20472. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  20473. const curve = new QuadraticBezierCurve(
  20474. this.currentPoint.clone(),
  20475. new Vector2( aCPx, aCPy ),
  20476. new Vector2( aX, aY )
  20477. );
  20478. this.curves.push( curve );
  20479. this.currentPoint.set( aX, aY );
  20480. return this;
  20481. }
  20482. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20483. const curve = new CubicBezierCurve(
  20484. this.currentPoint.clone(),
  20485. new Vector2( aCP1x, aCP1y ),
  20486. new Vector2( aCP2x, aCP2y ),
  20487. new Vector2( aX, aY )
  20488. );
  20489. this.curves.push( curve );
  20490. this.currentPoint.set( aX, aY );
  20491. return this;
  20492. }
  20493. splineThru( pts /*Array of Vector*/ ) {
  20494. const npts = [ this.currentPoint.clone() ].concat( pts );
  20495. const curve = new SplineCurve( npts );
  20496. this.curves.push( curve );
  20497. this.currentPoint.copy( pts[ pts.length - 1 ] );
  20498. return this;
  20499. }
  20500. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20501. const x0 = this.currentPoint.x;
  20502. const y0 = this.currentPoint.y;
  20503. this.absarc( aX + x0, aY + y0, aRadius,
  20504. aStartAngle, aEndAngle, aClockwise );
  20505. return this;
  20506. }
  20507. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20508. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20509. return this;
  20510. }
  20511. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20512. const x0 = this.currentPoint.x;
  20513. const y0 = this.currentPoint.y;
  20514. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20515. return this;
  20516. }
  20517. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20518. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20519. if ( this.curves.length > 0 ) {
  20520. // if a previous curve is present, attempt to join
  20521. const firstPoint = curve.getPoint( 0 );
  20522. if ( ! firstPoint.equals( this.currentPoint ) ) {
  20523. this.lineTo( firstPoint.x, firstPoint.y );
  20524. }
  20525. }
  20526. this.curves.push( curve );
  20527. const lastPoint = curve.getPoint( 1 );
  20528. this.currentPoint.copy( lastPoint );
  20529. return this;
  20530. }
  20531. copy( source ) {
  20532. super.copy( source );
  20533. this.currentPoint.copy( source.currentPoint );
  20534. return this;
  20535. }
  20536. toJSON() {
  20537. const data = super.toJSON();
  20538. data.currentPoint = this.currentPoint.toArray();
  20539. return data;
  20540. }
  20541. fromJSON( json ) {
  20542. super.fromJSON( json );
  20543. this.currentPoint.fromArray( json.currentPoint );
  20544. return this;
  20545. }
  20546. }
  20547. class Shape extends Path {
  20548. constructor( points ) {
  20549. super( points );
  20550. this.uuid = generateUUID();
  20551. this.type = 'Shape';
  20552. this.holes = [];
  20553. }
  20554. getPointsHoles( divisions ) {
  20555. const holesPts = [];
  20556. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  20557. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20558. }
  20559. return holesPts;
  20560. }
  20561. // get points of shape and holes (keypoints based on segments parameter)
  20562. extractPoints( divisions ) {
  20563. return {
  20564. shape: this.getPoints( divisions ),
  20565. holes: this.getPointsHoles( divisions )
  20566. };
  20567. }
  20568. copy( source ) {
  20569. super.copy( source );
  20570. this.holes = [];
  20571. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  20572. const hole = source.holes[ i ];
  20573. this.holes.push( hole.clone() );
  20574. }
  20575. return this;
  20576. }
  20577. toJSON() {
  20578. const data = super.toJSON();
  20579. data.uuid = this.uuid;
  20580. data.holes = [];
  20581. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  20582. const hole = this.holes[ i ];
  20583. data.holes.push( hole.toJSON() );
  20584. }
  20585. return data;
  20586. }
  20587. fromJSON( json ) {
  20588. super.fromJSON( json );
  20589. this.uuid = json.uuid;
  20590. this.holes = [];
  20591. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  20592. const hole = json.holes[ i ];
  20593. this.holes.push( new Path().fromJSON( hole ) );
  20594. }
  20595. return this;
  20596. }
  20597. }
  20598. class ShapeGeometry extends BufferGeometry {
  20599. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
  20600. super();
  20601. this.type = 'ShapeGeometry';
  20602. this.parameters = {
  20603. shapes: shapes,
  20604. curveSegments: curveSegments
  20605. };
  20606. // buffers
  20607. const indices = [];
  20608. const vertices = [];
  20609. const normals = [];
  20610. const uvs = [];
  20611. // helper variables
  20612. let groupStart = 0;
  20613. let groupCount = 0;
  20614. // allow single and array values for "shapes" parameter
  20615. if ( Array.isArray( shapes ) === false ) {
  20616. addShape( shapes );
  20617. } else {
  20618. for ( let i = 0; i < shapes.length; i ++ ) {
  20619. addShape( shapes[ i ] );
  20620. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  20621. groupStart += groupCount;
  20622. groupCount = 0;
  20623. }
  20624. }
  20625. // build geometry
  20626. this.setIndex( indices );
  20627. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20628. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20629. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20630. // helper functions
  20631. function addShape( shape ) {
  20632. const indexOffset = vertices.length / 3;
  20633. const points = shape.extractPoints( curveSegments );
  20634. let shapeVertices = points.shape;
  20635. const shapeHoles = points.holes;
  20636. // check direction of vertices
  20637. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  20638. shapeVertices = shapeVertices.reverse();
  20639. }
  20640. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  20641. const shapeHole = shapeHoles[ i ];
  20642. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  20643. shapeHoles[ i ] = shapeHole.reverse();
  20644. }
  20645. }
  20646. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  20647. // join vertices of inner and outer paths to a single array
  20648. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  20649. const shapeHole = shapeHoles[ i ];
  20650. shapeVertices = shapeVertices.concat( shapeHole );
  20651. }
  20652. // vertices, normals, uvs
  20653. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  20654. const vertex = shapeVertices[ i ];
  20655. vertices.push( vertex.x, vertex.y, 0 );
  20656. normals.push( 0, 0, 1 );
  20657. uvs.push( vertex.x, vertex.y ); // world uvs
  20658. }
  20659. // incides
  20660. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  20661. const face = faces[ i ];
  20662. const a = face[ 0 ] + indexOffset;
  20663. const b = face[ 1 ] + indexOffset;
  20664. const c = face[ 2 ] + indexOffset;
  20665. indices.push( a, b, c );
  20666. groupCount += 3;
  20667. }
  20668. }
  20669. }
  20670. toJSON() {
  20671. const data = super.toJSON();
  20672. const shapes = this.parameters.shapes;
  20673. return toJSON( shapes, data );
  20674. }
  20675. static fromJSON( data, shapes ) {
  20676. const geometryShapes = [];
  20677. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  20678. const shape = shapes[ data.shapes[ j ] ];
  20679. geometryShapes.push( shape );
  20680. }
  20681. return new ShapeGeometry( geometryShapes, data.curveSegments );
  20682. }
  20683. }
  20684. function toJSON( shapes, data ) {
  20685. data.shapes = [];
  20686. if ( Array.isArray( shapes ) ) {
  20687. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  20688. const shape = shapes[ i ];
  20689. data.shapes.push( shape.uuid );
  20690. }
  20691. } else {
  20692. data.shapes.push( shapes.uuid );
  20693. }
  20694. return data;
  20695. }
  20696. class SphereGeometry extends BufferGeometry {
  20697. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  20698. super();
  20699. this.type = 'SphereGeometry';
  20700. this.parameters = {
  20701. radius: radius,
  20702. widthSegments: widthSegments,
  20703. heightSegments: heightSegments,
  20704. phiStart: phiStart,
  20705. phiLength: phiLength,
  20706. thetaStart: thetaStart,
  20707. thetaLength: thetaLength
  20708. };
  20709. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  20710. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  20711. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  20712. let index = 0;
  20713. const grid = [];
  20714. const vertex = new Vector3();
  20715. const normal = new Vector3();
  20716. // buffers
  20717. const indices = [];
  20718. const vertices = [];
  20719. const normals = [];
  20720. const uvs = [];
  20721. // generate vertices, normals and uvs
  20722. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  20723. const verticesRow = [];
  20724. const v = iy / heightSegments;
  20725. // special case for the poles
  20726. let uOffset = 0;
  20727. if ( iy == 0 && thetaStart == 0 ) {
  20728. uOffset = 0.5 / widthSegments;
  20729. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  20730. uOffset = - 0.5 / widthSegments;
  20731. }
  20732. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  20733. const u = ix / widthSegments;
  20734. // vertex
  20735. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20736. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  20737. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20738. vertices.push( vertex.x, vertex.y, vertex.z );
  20739. // normal
  20740. normal.copy( vertex ).normalize();
  20741. normals.push( normal.x, normal.y, normal.z );
  20742. // uv
  20743. uvs.push( u + uOffset, 1 - v );
  20744. verticesRow.push( index ++ );
  20745. }
  20746. grid.push( verticesRow );
  20747. }
  20748. // indices
  20749. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  20750. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  20751. const a = grid[ iy ][ ix + 1 ];
  20752. const b = grid[ iy ][ ix ];
  20753. const c = grid[ iy + 1 ][ ix ];
  20754. const d = grid[ iy + 1 ][ ix + 1 ];
  20755. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  20756. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  20757. }
  20758. }
  20759. // build geometry
  20760. this.setIndex( indices );
  20761. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20762. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20763. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20764. }
  20765. static fromJSON( data ) {
  20766. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  20767. }
  20768. }
  20769. class TetrahedronGeometry extends PolyhedronGeometry {
  20770. constructor( radius = 1, detail = 0 ) {
  20771. const vertices = [
  20772. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20773. ];
  20774. const indices = [
  20775. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20776. ];
  20777. super( vertices, indices, radius, detail );
  20778. this.type = 'TetrahedronGeometry';
  20779. this.parameters = {
  20780. radius: radius,
  20781. detail: detail
  20782. };
  20783. }
  20784. static fromJSON( data ) {
  20785. return new TetrahedronGeometry( data.radius, data.detail );
  20786. }
  20787. }
  20788. /**
  20789. * Text = 3D Text
  20790. *
  20791. * parameters = {
  20792. * font: <THREE.Font>, // font
  20793. *
  20794. * size: <float>, // size of the text
  20795. * height: <float>, // thickness to extrude text
  20796. * curveSegments: <int>, // number of points on the curves
  20797. *
  20798. * bevelEnabled: <bool>, // turn on bevel
  20799. * bevelThickness: <float>, // how deep into text bevel goes
  20800. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  20801. * bevelOffset: <float> // how far from text outline does bevel start
  20802. * }
  20803. */
  20804. class TextGeometry extends ExtrudeGeometry {
  20805. constructor( text, parameters = {} ) {
  20806. const font = parameters.font;
  20807. if ( ! ( font && font.isFont ) ) {
  20808. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  20809. return new BufferGeometry();
  20810. }
  20811. const shapes = font.generateShapes( text, parameters.size );
  20812. // translate parameters to ExtrudeGeometry API
  20813. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  20814. // defaults
  20815. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  20816. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  20817. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  20818. super( shapes, parameters );
  20819. this.type = 'TextGeometry';
  20820. }
  20821. }
  20822. class TorusGeometry extends BufferGeometry {
  20823. constructor( radius = 1, tube = 0.4, radialSegments = 8, tubularSegments = 6, arc = Math.PI * 2 ) {
  20824. super();
  20825. this.type = 'TorusGeometry';
  20826. this.parameters = {
  20827. radius: radius,
  20828. tube: tube,
  20829. radialSegments: radialSegments,
  20830. tubularSegments: tubularSegments,
  20831. arc: arc
  20832. };
  20833. radialSegments = Math.floor( radialSegments );
  20834. tubularSegments = Math.floor( tubularSegments );
  20835. // buffers
  20836. const indices = [];
  20837. const vertices = [];
  20838. const normals = [];
  20839. const uvs = [];
  20840. // helper variables
  20841. const center = new Vector3();
  20842. const vertex = new Vector3();
  20843. const normal = new Vector3();
  20844. // generate vertices, normals and uvs
  20845. for ( let j = 0; j <= radialSegments; j ++ ) {
  20846. for ( let i = 0; i <= tubularSegments; i ++ ) {
  20847. const u = i / tubularSegments * arc;
  20848. const v = j / radialSegments * Math.PI * 2;
  20849. // vertex
  20850. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  20851. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  20852. vertex.z = tube * Math.sin( v );
  20853. vertices.push( vertex.x, vertex.y, vertex.z );
  20854. // normal
  20855. center.x = radius * Math.cos( u );
  20856. center.y = radius * Math.sin( u );
  20857. normal.subVectors( vertex, center ).normalize();
  20858. normals.push( normal.x, normal.y, normal.z );
  20859. // uv
  20860. uvs.push( i / tubularSegments );
  20861. uvs.push( j / radialSegments );
  20862. }
  20863. }
  20864. // generate indices
  20865. for ( let j = 1; j <= radialSegments; j ++ ) {
  20866. for ( let i = 1; i <= tubularSegments; i ++ ) {
  20867. // indices
  20868. const a = ( tubularSegments + 1 ) * j + i - 1;
  20869. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  20870. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  20871. const d = ( tubularSegments + 1 ) * j + i;
  20872. // faces
  20873. indices.push( a, b, d );
  20874. indices.push( b, c, d );
  20875. }
  20876. }
  20877. // build geometry
  20878. this.setIndex( indices );
  20879. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20880. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20881. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20882. }
  20883. static fromJSON( data ) {
  20884. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  20885. }
  20886. }
  20887. class TorusKnotGeometry extends BufferGeometry {
  20888. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  20889. super();
  20890. this.type = 'TorusKnotGeometry';
  20891. this.parameters = {
  20892. radius: radius,
  20893. tube: tube,
  20894. tubularSegments: tubularSegments,
  20895. radialSegments: radialSegments,
  20896. p: p,
  20897. q: q
  20898. };
  20899. tubularSegments = Math.floor( tubularSegments );
  20900. radialSegments = Math.floor( radialSegments );
  20901. // buffers
  20902. const indices = [];
  20903. const vertices = [];
  20904. const normals = [];
  20905. const uvs = [];
  20906. // helper variables
  20907. const vertex = new Vector3();
  20908. const normal = new Vector3();
  20909. const P1 = new Vector3();
  20910. const P2 = new Vector3();
  20911. const B = new Vector3();
  20912. const T = new Vector3();
  20913. const N = new Vector3();
  20914. // generate vertices, normals and uvs
  20915. for ( let i = 0; i <= tubularSegments; ++ i ) {
  20916. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  20917. const u = i / tubularSegments * p * Math.PI * 2;
  20918. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  20919. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  20920. calculatePositionOnCurve( u, p, q, radius, P1 );
  20921. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  20922. // calculate orthonormal basis
  20923. T.subVectors( P2, P1 );
  20924. N.addVectors( P2, P1 );
  20925. B.crossVectors( T, N );
  20926. N.crossVectors( B, T );
  20927. // normalize B, N. T can be ignored, we don't use it
  20928. B.normalize();
  20929. N.normalize();
  20930. for ( let j = 0; j <= radialSegments; ++ j ) {
  20931. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  20932. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  20933. const v = j / radialSegments * Math.PI * 2;
  20934. const cx = - tube * Math.cos( v );
  20935. const cy = tube * Math.sin( v );
  20936. // now calculate the final vertex position.
  20937. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  20938. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  20939. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  20940. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  20941. vertices.push( vertex.x, vertex.y, vertex.z );
  20942. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  20943. normal.subVectors( vertex, P1 ).normalize();
  20944. normals.push( normal.x, normal.y, normal.z );
  20945. // uv
  20946. uvs.push( i / tubularSegments );
  20947. uvs.push( j / radialSegments );
  20948. }
  20949. }
  20950. // generate indices
  20951. for ( let j = 1; j <= tubularSegments; j ++ ) {
  20952. for ( let i = 1; i <= radialSegments; i ++ ) {
  20953. // indices
  20954. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  20955. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  20956. const c = ( radialSegments + 1 ) * j + i;
  20957. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  20958. // faces
  20959. indices.push( a, b, d );
  20960. indices.push( b, c, d );
  20961. }
  20962. }
  20963. // build geometry
  20964. this.setIndex( indices );
  20965. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20966. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20967. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20968. // this function calculates the current position on the torus curve
  20969. function calculatePositionOnCurve( u, p, q, radius, position ) {
  20970. const cu = Math.cos( u );
  20971. const su = Math.sin( u );
  20972. const quOverP = q / p * u;
  20973. const cs = Math.cos( quOverP );
  20974. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  20975. position.y = radius * ( 2 + cs ) * su * 0.5;
  20976. position.z = radius * Math.sin( quOverP ) * 0.5;
  20977. }
  20978. }
  20979. static fromJSON( data ) {
  20980. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  20981. }
  20982. }
  20983. class TubeGeometry extends BufferGeometry {
  20984. constructor( path, tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  20985. super();
  20986. this.type = 'TubeGeometry';
  20987. this.parameters = {
  20988. path: path,
  20989. tubularSegments: tubularSegments,
  20990. radius: radius,
  20991. radialSegments: radialSegments,
  20992. closed: closed
  20993. };
  20994. const frames = path.computeFrenetFrames( tubularSegments, closed );
  20995. // expose internals
  20996. this.tangents = frames.tangents;
  20997. this.normals = frames.normals;
  20998. this.binormals = frames.binormals;
  20999. // helper variables
  21000. const vertex = new Vector3();
  21001. const normal = new Vector3();
  21002. const uv = new Vector2();
  21003. let P = new Vector3();
  21004. // buffer
  21005. const vertices = [];
  21006. const normals = [];
  21007. const uvs = [];
  21008. const indices = [];
  21009. // create buffer data
  21010. generateBufferData();
  21011. // build geometry
  21012. this.setIndex( indices );
  21013. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21014. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  21015. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  21016. // functions
  21017. function generateBufferData() {
  21018. for ( let i = 0; i < tubularSegments; i ++ ) {
  21019. generateSegment( i );
  21020. }
  21021. // if the geometry is not closed, generate the last row of vertices and normals
  21022. // at the regular position on the given path
  21023. //
  21024. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  21025. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  21026. // uvs are generated in a separate function.
  21027. // this makes it easy compute correct values for closed geometries
  21028. generateUVs();
  21029. // finally create faces
  21030. generateIndices();
  21031. }
  21032. function generateSegment( i ) {
  21033. // we use getPointAt to sample evenly distributed points from the given path
  21034. P = path.getPointAt( i / tubularSegments, P );
  21035. // retrieve corresponding normal and binormal
  21036. const N = frames.normals[ i ];
  21037. const B = frames.binormals[ i ];
  21038. // generate normals and vertices for the current segment
  21039. for ( let j = 0; j <= radialSegments; j ++ ) {
  21040. const v = j / radialSegments * Math.PI * 2;
  21041. const sin = Math.sin( v );
  21042. const cos = - Math.cos( v );
  21043. // normal
  21044. normal.x = ( cos * N.x + sin * B.x );
  21045. normal.y = ( cos * N.y + sin * B.y );
  21046. normal.z = ( cos * N.z + sin * B.z );
  21047. normal.normalize();
  21048. normals.push( normal.x, normal.y, normal.z );
  21049. // vertex
  21050. vertex.x = P.x + radius * normal.x;
  21051. vertex.y = P.y + radius * normal.y;
  21052. vertex.z = P.z + radius * normal.z;
  21053. vertices.push( vertex.x, vertex.y, vertex.z );
  21054. }
  21055. }
  21056. function generateIndices() {
  21057. for ( let j = 1; j <= tubularSegments; j ++ ) {
  21058. for ( let i = 1; i <= radialSegments; i ++ ) {
  21059. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  21060. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  21061. const c = ( radialSegments + 1 ) * j + i;
  21062. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  21063. // faces
  21064. indices.push( a, b, d );
  21065. indices.push( b, c, d );
  21066. }
  21067. }
  21068. }
  21069. function generateUVs() {
  21070. for ( let i = 0; i <= tubularSegments; i ++ ) {
  21071. for ( let j = 0; j <= radialSegments; j ++ ) {
  21072. uv.x = i / tubularSegments;
  21073. uv.y = j / radialSegments;
  21074. uvs.push( uv.x, uv.y );
  21075. }
  21076. }
  21077. }
  21078. }
  21079. toJSON() {
  21080. const data = super.toJSON();
  21081. data.path = this.parameters.path.toJSON();
  21082. return data;
  21083. }
  21084. static fromJSON( data ) {
  21085. // This only works for built-in curves (e.g. CatmullRomCurve3).
  21086. // User defined curves or instances of CurvePath will not be deserialized.
  21087. return new TubeGeometry(
  21088. new Curves[ data.path.type ]().fromJSON( data.path ),
  21089. data.tubularSegments,
  21090. data.radius,
  21091. data.radialSegments,
  21092. data.closed
  21093. );
  21094. }
  21095. }
  21096. class WireframeGeometry extends BufferGeometry {
  21097. constructor( geometry ) {
  21098. super();
  21099. this.type = 'WireframeGeometry';
  21100. if ( geometry.isGeometry === true ) {
  21101. console.error( 'THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  21102. return;
  21103. }
  21104. // buffer
  21105. const vertices = [];
  21106. const edges = new Set();
  21107. // helper variables
  21108. const start = new Vector3();
  21109. const end = new Vector3();
  21110. if ( geometry.index !== null ) {
  21111. // indexed BufferGeometry
  21112. const position = geometry.attributes.position;
  21113. const indices = geometry.index;
  21114. let groups = geometry.groups;
  21115. if ( groups.length === 0 ) {
  21116. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  21117. }
  21118. // create a data structure that contains all eges without duplicates
  21119. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  21120. const group = groups[ o ];
  21121. const groupStart = group.start;
  21122. const groupCount = group.count;
  21123. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  21124. for ( let j = 0; j < 3; j ++ ) {
  21125. const index1 = indices.getX( i + j );
  21126. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  21127. start.fromBufferAttribute( position, index1 );
  21128. end.fromBufferAttribute( position, index2 );
  21129. if ( isUniqueEdge( start, end, edges ) === true ) {
  21130. vertices.push( start.x, start.y, start.z );
  21131. vertices.push( end.x, end.y, end.z );
  21132. }
  21133. }
  21134. }
  21135. }
  21136. } else {
  21137. // non-indexed BufferGeometry
  21138. const position = geometry.attributes.position;
  21139. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  21140. for ( let j = 0; j < 3; j ++ ) {
  21141. // three edges per triangle, an edge is represented as (index1, index2)
  21142. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  21143. const index1 = 3 * i + j;
  21144. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  21145. start.fromBufferAttribute( position, index1 );
  21146. end.fromBufferAttribute( position, index2 );
  21147. if ( isUniqueEdge( start, end, edges ) === true ) {
  21148. vertices.push( start.x, start.y, start.z );
  21149. vertices.push( end.x, end.y, end.z );
  21150. }
  21151. }
  21152. }
  21153. }
  21154. // build geometry
  21155. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21156. }
  21157. }
  21158. function isUniqueEdge( start, end, edges ) {
  21159. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  21160. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  21161. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  21162. return false;
  21163. } else {
  21164. edges.add( hash1, hash2 );
  21165. return true;
  21166. }
  21167. }
  21168. var Geometries = /*#__PURE__*/Object.freeze({
  21169. __proto__: null,
  21170. BoxGeometry: BoxGeometry,
  21171. BoxBufferGeometry: BoxGeometry,
  21172. CircleGeometry: CircleGeometry,
  21173. CircleBufferGeometry: CircleGeometry,
  21174. ConeGeometry: ConeGeometry,
  21175. ConeBufferGeometry: ConeGeometry,
  21176. CylinderGeometry: CylinderGeometry,
  21177. CylinderBufferGeometry: CylinderGeometry,
  21178. DodecahedronGeometry: DodecahedronGeometry,
  21179. DodecahedronBufferGeometry: DodecahedronGeometry,
  21180. EdgesGeometry: EdgesGeometry,
  21181. ExtrudeGeometry: ExtrudeGeometry,
  21182. ExtrudeBufferGeometry: ExtrudeGeometry,
  21183. IcosahedronGeometry: IcosahedronGeometry,
  21184. IcosahedronBufferGeometry: IcosahedronGeometry,
  21185. LatheGeometry: LatheGeometry,
  21186. LatheBufferGeometry: LatheGeometry,
  21187. OctahedronGeometry: OctahedronGeometry,
  21188. OctahedronBufferGeometry: OctahedronGeometry,
  21189. ParametricGeometry: ParametricGeometry,
  21190. ParametricBufferGeometry: ParametricGeometry,
  21191. PlaneGeometry: PlaneGeometry,
  21192. PlaneBufferGeometry: PlaneGeometry,
  21193. PolyhedronGeometry: PolyhedronGeometry,
  21194. PolyhedronBufferGeometry: PolyhedronGeometry,
  21195. RingGeometry: RingGeometry,
  21196. RingBufferGeometry: RingGeometry,
  21197. ShapeGeometry: ShapeGeometry,
  21198. ShapeBufferGeometry: ShapeGeometry,
  21199. SphereGeometry: SphereGeometry,
  21200. SphereBufferGeometry: SphereGeometry,
  21201. TetrahedronGeometry: TetrahedronGeometry,
  21202. TetrahedronBufferGeometry: TetrahedronGeometry,
  21203. TextGeometry: TextGeometry,
  21204. TextBufferGeometry: TextGeometry,
  21205. TorusGeometry: TorusGeometry,
  21206. TorusBufferGeometry: TorusGeometry,
  21207. TorusKnotGeometry: TorusKnotGeometry,
  21208. TorusKnotBufferGeometry: TorusKnotGeometry,
  21209. TubeGeometry: TubeGeometry,
  21210. TubeBufferGeometry: TubeGeometry,
  21211. WireframeGeometry: WireframeGeometry
  21212. });
  21213. /**
  21214. * parameters = {
  21215. * color: <THREE.Color>
  21216. * }
  21217. */
  21218. class ShadowMaterial extends Material {
  21219. constructor( parameters ) {
  21220. super();
  21221. this.type = 'ShadowMaterial';
  21222. this.color = new Color( 0x000000 );
  21223. this.transparent = true;
  21224. this.setValues( parameters );
  21225. }
  21226. copy( source ) {
  21227. super.copy( source );
  21228. this.color.copy( source.color );
  21229. return this;
  21230. }
  21231. }
  21232. ShadowMaterial.prototype.isShadowMaterial = true;
  21233. /**
  21234. * parameters = {
  21235. * color: <hex>,
  21236. * roughness: <float>,
  21237. * metalness: <float>,
  21238. * opacity: <float>,
  21239. *
  21240. * map: new THREE.Texture( <Image> ),
  21241. *
  21242. * lightMap: new THREE.Texture( <Image> ),
  21243. * lightMapIntensity: <float>
  21244. *
  21245. * aoMap: new THREE.Texture( <Image> ),
  21246. * aoMapIntensity: <float>
  21247. *
  21248. * emissive: <hex>,
  21249. * emissiveIntensity: <float>
  21250. * emissiveMap: new THREE.Texture( <Image> ),
  21251. *
  21252. * bumpMap: new THREE.Texture( <Image> ),
  21253. * bumpScale: <float>,
  21254. *
  21255. * normalMap: new THREE.Texture( <Image> ),
  21256. * normalMapType: THREE.TangentSpaceNormalMap,
  21257. * normalScale: <Vector2>,
  21258. *
  21259. * displacementMap: new THREE.Texture( <Image> ),
  21260. * displacementScale: <float>,
  21261. * displacementBias: <float>,
  21262. *
  21263. * roughnessMap: new THREE.Texture( <Image> ),
  21264. *
  21265. * metalnessMap: new THREE.Texture( <Image> ),
  21266. *
  21267. * alphaMap: new THREE.Texture( <Image> ),
  21268. *
  21269. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  21270. * envMapIntensity: <float>
  21271. *
  21272. * refractionRatio: <float>,
  21273. *
  21274. * wireframe: <boolean>,
  21275. * wireframeLinewidth: <float>,
  21276. *
  21277. * flatShading: <bool>
  21278. * }
  21279. */
  21280. class MeshStandardMaterial extends Material {
  21281. constructor( parameters ) {
  21282. super();
  21283. this.defines = { 'STANDARD': '' };
  21284. this.type = 'MeshStandardMaterial';
  21285. this.color = new Color( 0xffffff ); // diffuse
  21286. this.roughness = 1.0;
  21287. this.metalness = 0.0;
  21288. this.map = null;
  21289. this.lightMap = null;
  21290. this.lightMapIntensity = 1.0;
  21291. this.aoMap = null;
  21292. this.aoMapIntensity = 1.0;
  21293. this.emissive = new Color( 0x000000 );
  21294. this.emissiveIntensity = 1.0;
  21295. this.emissiveMap = null;
  21296. this.bumpMap = null;
  21297. this.bumpScale = 1;
  21298. this.normalMap = null;
  21299. this.normalMapType = TangentSpaceNormalMap;
  21300. this.normalScale = new Vector2( 1, 1 );
  21301. this.displacementMap = null;
  21302. this.displacementScale = 1;
  21303. this.displacementBias = 0;
  21304. this.roughnessMap = null;
  21305. this.metalnessMap = null;
  21306. this.alphaMap = null;
  21307. this.envMap = null;
  21308. this.envMapIntensity = 1.0;
  21309. this.refractionRatio = 0.98;
  21310. this.wireframe = false;
  21311. this.wireframeLinewidth = 1;
  21312. this.wireframeLinecap = 'round';
  21313. this.wireframeLinejoin = 'round';
  21314. this.flatShading = false;
  21315. this.setValues( parameters );
  21316. }
  21317. copy( source ) {
  21318. super.copy( source );
  21319. this.defines = { 'STANDARD': '' };
  21320. this.color.copy( source.color );
  21321. this.roughness = source.roughness;
  21322. this.metalness = source.metalness;
  21323. this.map = source.map;
  21324. this.lightMap = source.lightMap;
  21325. this.lightMapIntensity = source.lightMapIntensity;
  21326. this.aoMap = source.aoMap;
  21327. this.aoMapIntensity = source.aoMapIntensity;
  21328. this.emissive.copy( source.emissive );
  21329. this.emissiveMap = source.emissiveMap;
  21330. this.emissiveIntensity = source.emissiveIntensity;
  21331. this.bumpMap = source.bumpMap;
  21332. this.bumpScale = source.bumpScale;
  21333. this.normalMap = source.normalMap;
  21334. this.normalMapType = source.normalMapType;
  21335. this.normalScale.copy( source.normalScale );
  21336. this.displacementMap = source.displacementMap;
  21337. this.displacementScale = source.displacementScale;
  21338. this.displacementBias = source.displacementBias;
  21339. this.roughnessMap = source.roughnessMap;
  21340. this.metalnessMap = source.metalnessMap;
  21341. this.alphaMap = source.alphaMap;
  21342. this.envMap = source.envMap;
  21343. this.envMapIntensity = source.envMapIntensity;
  21344. this.refractionRatio = source.refractionRatio;
  21345. this.wireframe = source.wireframe;
  21346. this.wireframeLinewidth = source.wireframeLinewidth;
  21347. this.wireframeLinecap = source.wireframeLinecap;
  21348. this.wireframeLinejoin = source.wireframeLinejoin;
  21349. this.flatShading = source.flatShading;
  21350. return this;
  21351. }
  21352. }
  21353. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  21354. /**
  21355. * parameters = {
  21356. * clearcoat: <float>,
  21357. * clearcoatMap: new THREE.Texture( <Image> ),
  21358. * clearcoatRoughness: <float>,
  21359. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  21360. * clearcoatNormalScale: <Vector2>,
  21361. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  21362. *
  21363. * ior: <float>,
  21364. * reflectivity: <float>,
  21365. *
  21366. * sheen: <float>,
  21367. * sheenTint: <Color>,
  21368. * sheenRoughness: <float>,
  21369. *
  21370. * transmission: <float>,
  21371. * transmissionMap: new THREE.Texture( <Image> ),
  21372. *
  21373. * thickness: <float>,
  21374. * thicknessMap: new THREE.Texture( <Image> ),
  21375. * attenuationDistance: <float>,
  21376. * attenuationTint: <Color>,
  21377. *
  21378. * specularIntensity: <float>,
  21379. * specularIntensityhMap: new THREE.Texture( <Image> ),
  21380. * specularTint: <Color>,
  21381. * specularTintMap: new THREE.Texture( <Image> )
  21382. * }
  21383. */
  21384. class MeshPhysicalMaterial extends MeshStandardMaterial {
  21385. constructor( parameters ) {
  21386. super();
  21387. this.defines = {
  21388. 'STANDARD': '',
  21389. 'PHYSICAL': ''
  21390. };
  21391. this.type = 'MeshPhysicalMaterial';
  21392. this.clearcoatMap = null;
  21393. this.clearcoatRoughness = 0.0;
  21394. this.clearcoatRoughnessMap = null;
  21395. this.clearcoatNormalScale = new Vector2( 1, 1 );
  21396. this.clearcoatNormalMap = null;
  21397. this.ior = 1.5;
  21398. Object.defineProperty( this, 'reflectivity', {
  21399. get: function () {
  21400. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  21401. },
  21402. set: function ( reflectivity ) {
  21403. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  21404. }
  21405. } );
  21406. this.sheenTint = new Color( 0x000000 );
  21407. this.sheenRoughness = 1.0;
  21408. this.transmissionMap = null;
  21409. this.thickness = 0.01;
  21410. this.thicknessMap = null;
  21411. this.attenuationDistance = 0.0;
  21412. this.attenuationTint = new Color( 1, 1, 1 );
  21413. this.specularIntensity = 1.0;
  21414. this.specularIntensityMap = null;
  21415. this.specularTint = new Color( 1, 1, 1 );
  21416. this.specularTintMap = null;
  21417. this._sheen = 0.0;
  21418. this._clearcoat = 0;
  21419. this._transmission = 0;
  21420. this.setValues( parameters );
  21421. }
  21422. get sheen() {
  21423. return this._sheen;
  21424. }
  21425. set sheen( value ) {
  21426. if ( this._sheen > 0 !== value > 0 ) {
  21427. this.version ++;
  21428. }
  21429. this._sheen = value;
  21430. }
  21431. get clearcoat() {
  21432. return this._clearcoat;
  21433. }
  21434. set clearcoat( value ) {
  21435. if ( this._clearcoat > 0 !== value > 0 ) {
  21436. this.version ++;
  21437. }
  21438. this._clearcoat = value;
  21439. }
  21440. get transmission() {
  21441. return this._transmission;
  21442. }
  21443. set transmission( value ) {
  21444. if ( this._transmission > 0 !== value > 0 ) {
  21445. this.version ++;
  21446. }
  21447. this._transmission = value;
  21448. }
  21449. copy( source ) {
  21450. super.copy( source );
  21451. this.defines = {
  21452. 'STANDARD': '',
  21453. 'PHYSICAL': ''
  21454. };
  21455. this.clearcoat = source.clearcoat;
  21456. this.clearcoatMap = source.clearcoatMap;
  21457. this.clearcoatRoughness = source.clearcoatRoughness;
  21458. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  21459. this.clearcoatNormalMap = source.clearcoatNormalMap;
  21460. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  21461. this.ior = source.ior;
  21462. this.sheen = source.sheen;
  21463. this.sheenTint.copy( source.sheenTint );
  21464. this.sheenRoughness = source.sheenRoughness;
  21465. this.transmission = source.transmission;
  21466. this.transmissionMap = source.transmissionMap;
  21467. this.thickness = source.thickness;
  21468. this.thicknessMap = source.thicknessMap;
  21469. this.attenuationDistance = source.attenuationDistance;
  21470. this.attenuationTint.copy( source.attenuationTint );
  21471. this.specularIntensity = source.specularIntensity;
  21472. this.specularIntensityMap = source.specularIntensityMap;
  21473. this.specularTint.copy( source.specularTint );
  21474. this.specularTintMap = source.specularTintMap;
  21475. return this;
  21476. }
  21477. }
  21478. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  21479. /**
  21480. * parameters = {
  21481. * color: <hex>,
  21482. * specular: <hex>,
  21483. * shininess: <float>,
  21484. * opacity: <float>,
  21485. *
  21486. * map: new THREE.Texture( <Image> ),
  21487. *
  21488. * lightMap: new THREE.Texture( <Image> ),
  21489. * lightMapIntensity: <float>
  21490. *
  21491. * aoMap: new THREE.Texture( <Image> ),
  21492. * aoMapIntensity: <float>
  21493. *
  21494. * emissive: <hex>,
  21495. * emissiveIntensity: <float>
  21496. * emissiveMap: new THREE.Texture( <Image> ),
  21497. *
  21498. * bumpMap: new THREE.Texture( <Image> ),
  21499. * bumpScale: <float>,
  21500. *
  21501. * normalMap: new THREE.Texture( <Image> ),
  21502. * normalMapType: THREE.TangentSpaceNormalMap,
  21503. * normalScale: <Vector2>,
  21504. *
  21505. * displacementMap: new THREE.Texture( <Image> ),
  21506. * displacementScale: <float>,
  21507. * displacementBias: <float>,
  21508. *
  21509. * specularMap: new THREE.Texture( <Image> ),
  21510. *
  21511. * alphaMap: new THREE.Texture( <Image> ),
  21512. *
  21513. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  21514. * combine: THREE.MultiplyOperation,
  21515. * reflectivity: <float>,
  21516. * refractionRatio: <float>,
  21517. *
  21518. * wireframe: <boolean>,
  21519. * wireframeLinewidth: <float>,
  21520. *
  21521. * flatShading: <bool>
  21522. * }
  21523. */
  21524. class MeshPhongMaterial extends Material {
  21525. constructor( parameters ) {
  21526. super();
  21527. this.type = 'MeshPhongMaterial';
  21528. this.color = new Color( 0xffffff ); // diffuse
  21529. this.specular = new Color( 0x111111 );
  21530. this.shininess = 30;
  21531. this.map = null;
  21532. this.lightMap = null;
  21533. this.lightMapIntensity = 1.0;
  21534. this.aoMap = null;
  21535. this.aoMapIntensity = 1.0;
  21536. this.emissive = new Color( 0x000000 );
  21537. this.emissiveIntensity = 1.0;
  21538. this.emissiveMap = null;
  21539. this.bumpMap = null;
  21540. this.bumpScale = 1;
  21541. this.normalMap = null;
  21542. this.normalMapType = TangentSpaceNormalMap;
  21543. this.normalScale = new Vector2( 1, 1 );
  21544. this.displacementMap = null;
  21545. this.displacementScale = 1;
  21546. this.displacementBias = 0;
  21547. this.specularMap = null;
  21548. this.alphaMap = null;
  21549. this.envMap = null;
  21550. this.combine = MultiplyOperation;
  21551. this.reflectivity = 1;
  21552. this.refractionRatio = 0.98;
  21553. this.wireframe = false;
  21554. this.wireframeLinewidth = 1;
  21555. this.wireframeLinecap = 'round';
  21556. this.wireframeLinejoin = 'round';
  21557. this.flatShading = false;
  21558. this.setValues( parameters );
  21559. }
  21560. copy( source ) {
  21561. super.copy( source );
  21562. this.color.copy( source.color );
  21563. this.specular.copy( source.specular );
  21564. this.shininess = source.shininess;
  21565. this.map = source.map;
  21566. this.lightMap = source.lightMap;
  21567. this.lightMapIntensity = source.lightMapIntensity;
  21568. this.aoMap = source.aoMap;
  21569. this.aoMapIntensity = source.aoMapIntensity;
  21570. this.emissive.copy( source.emissive );
  21571. this.emissiveMap = source.emissiveMap;
  21572. this.emissiveIntensity = source.emissiveIntensity;
  21573. this.bumpMap = source.bumpMap;
  21574. this.bumpScale = source.bumpScale;
  21575. this.normalMap = source.normalMap;
  21576. this.normalMapType = source.normalMapType;
  21577. this.normalScale.copy( source.normalScale );
  21578. this.displacementMap = source.displacementMap;
  21579. this.displacementScale = source.displacementScale;
  21580. this.displacementBias = source.displacementBias;
  21581. this.specularMap = source.specularMap;
  21582. this.alphaMap = source.alphaMap;
  21583. this.envMap = source.envMap;
  21584. this.combine = source.combine;
  21585. this.reflectivity = source.reflectivity;
  21586. this.refractionRatio = source.refractionRatio;
  21587. this.wireframe = source.wireframe;
  21588. this.wireframeLinewidth = source.wireframeLinewidth;
  21589. this.wireframeLinecap = source.wireframeLinecap;
  21590. this.wireframeLinejoin = source.wireframeLinejoin;
  21591. this.flatShading = source.flatShading;
  21592. return this;
  21593. }
  21594. }
  21595. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  21596. /**
  21597. * parameters = {
  21598. * color: <hex>,
  21599. *
  21600. * map: new THREE.Texture( <Image> ),
  21601. * gradientMap: new THREE.Texture( <Image> ),
  21602. *
  21603. * lightMap: new THREE.Texture( <Image> ),
  21604. * lightMapIntensity: <float>
  21605. *
  21606. * aoMap: new THREE.Texture( <Image> ),
  21607. * aoMapIntensity: <float>
  21608. *
  21609. * emissive: <hex>,
  21610. * emissiveIntensity: <float>
  21611. * emissiveMap: new THREE.Texture( <Image> ),
  21612. *
  21613. * bumpMap: new THREE.Texture( <Image> ),
  21614. * bumpScale: <float>,
  21615. *
  21616. * normalMap: new THREE.Texture( <Image> ),
  21617. * normalMapType: THREE.TangentSpaceNormalMap,
  21618. * normalScale: <Vector2>,
  21619. *
  21620. * displacementMap: new THREE.Texture( <Image> ),
  21621. * displacementScale: <float>,
  21622. * displacementBias: <float>,
  21623. *
  21624. * alphaMap: new THREE.Texture( <Image> ),
  21625. *
  21626. * wireframe: <boolean>,
  21627. * wireframeLinewidth: <float>,
  21628. *
  21629. * }
  21630. */
  21631. class MeshToonMaterial extends Material {
  21632. constructor( parameters ) {
  21633. super();
  21634. this.defines = { 'TOON': '' };
  21635. this.type = 'MeshToonMaterial';
  21636. this.color = new Color( 0xffffff );
  21637. this.map = null;
  21638. this.gradientMap = null;
  21639. this.lightMap = null;
  21640. this.lightMapIntensity = 1.0;
  21641. this.aoMap = null;
  21642. this.aoMapIntensity = 1.0;
  21643. this.emissive = new Color( 0x000000 );
  21644. this.emissiveIntensity = 1.0;
  21645. this.emissiveMap = null;
  21646. this.bumpMap = null;
  21647. this.bumpScale = 1;
  21648. this.normalMap = null;
  21649. this.normalMapType = TangentSpaceNormalMap;
  21650. this.normalScale = new Vector2( 1, 1 );
  21651. this.displacementMap = null;
  21652. this.displacementScale = 1;
  21653. this.displacementBias = 0;
  21654. this.alphaMap = null;
  21655. this.wireframe = false;
  21656. this.wireframeLinewidth = 1;
  21657. this.wireframeLinecap = 'round';
  21658. this.wireframeLinejoin = 'round';
  21659. this.setValues( parameters );
  21660. }
  21661. copy( source ) {
  21662. super.copy( source );
  21663. this.color.copy( source.color );
  21664. this.map = source.map;
  21665. this.gradientMap = source.gradientMap;
  21666. this.lightMap = source.lightMap;
  21667. this.lightMapIntensity = source.lightMapIntensity;
  21668. this.aoMap = source.aoMap;
  21669. this.aoMapIntensity = source.aoMapIntensity;
  21670. this.emissive.copy( source.emissive );
  21671. this.emissiveMap = source.emissiveMap;
  21672. this.emissiveIntensity = source.emissiveIntensity;
  21673. this.bumpMap = source.bumpMap;
  21674. this.bumpScale = source.bumpScale;
  21675. this.normalMap = source.normalMap;
  21676. this.normalMapType = source.normalMapType;
  21677. this.normalScale.copy( source.normalScale );
  21678. this.displacementMap = source.displacementMap;
  21679. this.displacementScale = source.displacementScale;
  21680. this.displacementBias = source.displacementBias;
  21681. this.alphaMap = source.alphaMap;
  21682. this.wireframe = source.wireframe;
  21683. this.wireframeLinewidth = source.wireframeLinewidth;
  21684. this.wireframeLinecap = source.wireframeLinecap;
  21685. this.wireframeLinejoin = source.wireframeLinejoin;
  21686. return this;
  21687. }
  21688. }
  21689. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  21690. /**
  21691. * parameters = {
  21692. * opacity: <float>,
  21693. *
  21694. * bumpMap: new THREE.Texture( <Image> ),
  21695. * bumpScale: <float>,
  21696. *
  21697. * normalMap: new THREE.Texture( <Image> ),
  21698. * normalMapType: THREE.TangentSpaceNormalMap,
  21699. * normalScale: <Vector2>,
  21700. *
  21701. * displacementMap: new THREE.Texture( <Image> ),
  21702. * displacementScale: <float>,
  21703. * displacementBias: <float>,
  21704. *
  21705. * wireframe: <boolean>,
  21706. * wireframeLinewidth: <float>
  21707. *
  21708. * flatShading: <bool>
  21709. * }
  21710. */
  21711. class MeshNormalMaterial extends Material {
  21712. constructor( parameters ) {
  21713. super();
  21714. this.type = 'MeshNormalMaterial';
  21715. this.bumpMap = null;
  21716. this.bumpScale = 1;
  21717. this.normalMap = null;
  21718. this.normalMapType = TangentSpaceNormalMap;
  21719. this.normalScale = new Vector2( 1, 1 );
  21720. this.displacementMap = null;
  21721. this.displacementScale = 1;
  21722. this.displacementBias = 0;
  21723. this.wireframe = false;
  21724. this.wireframeLinewidth = 1;
  21725. this.fog = false;
  21726. this.flatShading = false;
  21727. this.setValues( parameters );
  21728. }
  21729. copy( source ) {
  21730. super.copy( source );
  21731. this.bumpMap = source.bumpMap;
  21732. this.bumpScale = source.bumpScale;
  21733. this.normalMap = source.normalMap;
  21734. this.normalMapType = source.normalMapType;
  21735. this.normalScale.copy( source.normalScale );
  21736. this.displacementMap = source.displacementMap;
  21737. this.displacementScale = source.displacementScale;
  21738. this.displacementBias = source.displacementBias;
  21739. this.wireframe = source.wireframe;
  21740. this.wireframeLinewidth = source.wireframeLinewidth;
  21741. this.flatShading = source.flatShading;
  21742. return this;
  21743. }
  21744. }
  21745. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  21746. /**
  21747. * parameters = {
  21748. * color: <hex>,
  21749. * opacity: <float>,
  21750. *
  21751. * map: new THREE.Texture( <Image> ),
  21752. *
  21753. * lightMap: new THREE.Texture( <Image> ),
  21754. * lightMapIntensity: <float>
  21755. *
  21756. * aoMap: new THREE.Texture( <Image> ),
  21757. * aoMapIntensity: <float>
  21758. *
  21759. * emissive: <hex>,
  21760. * emissiveIntensity: <float>
  21761. * emissiveMap: new THREE.Texture( <Image> ),
  21762. *
  21763. * specularMap: new THREE.Texture( <Image> ),
  21764. *
  21765. * alphaMap: new THREE.Texture( <Image> ),
  21766. *
  21767. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  21768. * combine: THREE.Multiply,
  21769. * reflectivity: <float>,
  21770. * refractionRatio: <float>,
  21771. *
  21772. * wireframe: <boolean>,
  21773. * wireframeLinewidth: <float>,
  21774. *
  21775. * }
  21776. */
  21777. class MeshLambertMaterial extends Material {
  21778. constructor( parameters ) {
  21779. super();
  21780. this.type = 'MeshLambertMaterial';
  21781. this.color = new Color( 0xffffff ); // diffuse
  21782. this.map = null;
  21783. this.lightMap = null;
  21784. this.lightMapIntensity = 1.0;
  21785. this.aoMap = null;
  21786. this.aoMapIntensity = 1.0;
  21787. this.emissive = new Color( 0x000000 );
  21788. this.emissiveIntensity = 1.0;
  21789. this.emissiveMap = null;
  21790. this.specularMap = null;
  21791. this.alphaMap = null;
  21792. this.envMap = null;
  21793. this.combine = MultiplyOperation;
  21794. this.reflectivity = 1;
  21795. this.refractionRatio = 0.98;
  21796. this.wireframe = false;
  21797. this.wireframeLinewidth = 1;
  21798. this.wireframeLinecap = 'round';
  21799. this.wireframeLinejoin = 'round';
  21800. this.setValues( parameters );
  21801. }
  21802. copy( source ) {
  21803. super.copy( source );
  21804. this.color.copy( source.color );
  21805. this.map = source.map;
  21806. this.lightMap = source.lightMap;
  21807. this.lightMapIntensity = source.lightMapIntensity;
  21808. this.aoMap = source.aoMap;
  21809. this.aoMapIntensity = source.aoMapIntensity;
  21810. this.emissive.copy( source.emissive );
  21811. this.emissiveMap = source.emissiveMap;
  21812. this.emissiveIntensity = source.emissiveIntensity;
  21813. this.specularMap = source.specularMap;
  21814. this.alphaMap = source.alphaMap;
  21815. this.envMap = source.envMap;
  21816. this.combine = source.combine;
  21817. this.reflectivity = source.reflectivity;
  21818. this.refractionRatio = source.refractionRatio;
  21819. this.wireframe = source.wireframe;
  21820. this.wireframeLinewidth = source.wireframeLinewidth;
  21821. this.wireframeLinecap = source.wireframeLinecap;
  21822. this.wireframeLinejoin = source.wireframeLinejoin;
  21823. return this;
  21824. }
  21825. }
  21826. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  21827. /**
  21828. * parameters = {
  21829. * color: <hex>,
  21830. * opacity: <float>,
  21831. *
  21832. * matcap: new THREE.Texture( <Image> ),
  21833. *
  21834. * map: new THREE.Texture( <Image> ),
  21835. *
  21836. * bumpMap: new THREE.Texture( <Image> ),
  21837. * bumpScale: <float>,
  21838. *
  21839. * normalMap: new THREE.Texture( <Image> ),
  21840. * normalMapType: THREE.TangentSpaceNormalMap,
  21841. * normalScale: <Vector2>,
  21842. *
  21843. * displacementMap: new THREE.Texture( <Image> ),
  21844. * displacementScale: <float>,
  21845. * displacementBias: <float>,
  21846. *
  21847. * alphaMap: new THREE.Texture( <Image> ),
  21848. *
  21849. * flatShading: <bool>
  21850. * }
  21851. */
  21852. class MeshMatcapMaterial extends Material {
  21853. constructor( parameters ) {
  21854. super();
  21855. this.defines = { 'MATCAP': '' };
  21856. this.type = 'MeshMatcapMaterial';
  21857. this.color = new Color( 0xffffff ); // diffuse
  21858. this.matcap = null;
  21859. this.map = null;
  21860. this.bumpMap = null;
  21861. this.bumpScale = 1;
  21862. this.normalMap = null;
  21863. this.normalMapType = TangentSpaceNormalMap;
  21864. this.normalScale = new Vector2( 1, 1 );
  21865. this.displacementMap = null;
  21866. this.displacementScale = 1;
  21867. this.displacementBias = 0;
  21868. this.alphaMap = null;
  21869. this.flatShading = false;
  21870. this.setValues( parameters );
  21871. }
  21872. copy( source ) {
  21873. super.copy( source );
  21874. this.defines = { 'MATCAP': '' };
  21875. this.color.copy( source.color );
  21876. this.matcap = source.matcap;
  21877. this.map = source.map;
  21878. this.bumpMap = source.bumpMap;
  21879. this.bumpScale = source.bumpScale;
  21880. this.normalMap = source.normalMap;
  21881. this.normalMapType = source.normalMapType;
  21882. this.normalScale.copy( source.normalScale );
  21883. this.displacementMap = source.displacementMap;
  21884. this.displacementScale = source.displacementScale;
  21885. this.displacementBias = source.displacementBias;
  21886. this.alphaMap = source.alphaMap;
  21887. this.flatShading = source.flatShading;
  21888. return this;
  21889. }
  21890. }
  21891. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  21892. /**
  21893. * parameters = {
  21894. * color: <hex>,
  21895. * opacity: <float>,
  21896. *
  21897. * linewidth: <float>,
  21898. *
  21899. * scale: <float>,
  21900. * dashSize: <float>,
  21901. * gapSize: <float>
  21902. * }
  21903. */
  21904. class LineDashedMaterial extends LineBasicMaterial {
  21905. constructor( parameters ) {
  21906. super();
  21907. this.type = 'LineDashedMaterial';
  21908. this.scale = 1;
  21909. this.dashSize = 3;
  21910. this.gapSize = 1;
  21911. this.setValues( parameters );
  21912. }
  21913. copy( source ) {
  21914. super.copy( source );
  21915. this.scale = source.scale;
  21916. this.dashSize = source.dashSize;
  21917. this.gapSize = source.gapSize;
  21918. return this;
  21919. }
  21920. }
  21921. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  21922. var Materials = /*#__PURE__*/Object.freeze({
  21923. __proto__: null,
  21924. ShadowMaterial: ShadowMaterial,
  21925. SpriteMaterial: SpriteMaterial,
  21926. RawShaderMaterial: RawShaderMaterial,
  21927. ShaderMaterial: ShaderMaterial,
  21928. PointsMaterial: PointsMaterial,
  21929. MeshPhysicalMaterial: MeshPhysicalMaterial,
  21930. MeshStandardMaterial: MeshStandardMaterial,
  21931. MeshPhongMaterial: MeshPhongMaterial,
  21932. MeshToonMaterial: MeshToonMaterial,
  21933. MeshNormalMaterial: MeshNormalMaterial,
  21934. MeshLambertMaterial: MeshLambertMaterial,
  21935. MeshDepthMaterial: MeshDepthMaterial,
  21936. MeshDistanceMaterial: MeshDistanceMaterial,
  21937. MeshBasicMaterial: MeshBasicMaterial,
  21938. MeshMatcapMaterial: MeshMatcapMaterial,
  21939. LineDashedMaterial: LineDashedMaterial,
  21940. LineBasicMaterial: LineBasicMaterial,
  21941. Material: Material
  21942. });
  21943. const AnimationUtils = {
  21944. // same as Array.prototype.slice, but also works on typed arrays
  21945. arraySlice: function ( array, from, to ) {
  21946. if ( AnimationUtils.isTypedArray( array ) ) {
  21947. // in ios9 array.subarray(from, undefined) will return empty array
  21948. // but array.subarray(from) or array.subarray(from, len) is correct
  21949. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  21950. }
  21951. return array.slice( from, to );
  21952. },
  21953. // converts an array to a specific type
  21954. convertArray: function ( array, type, forceClone ) {
  21955. if ( ! array || // let 'undefined' and 'null' pass
  21956. ! forceClone && array.constructor === type ) return array;
  21957. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  21958. return new type( array ); // create typed array
  21959. }
  21960. return Array.prototype.slice.call( array ); // create Array
  21961. },
  21962. isTypedArray: function ( object ) {
  21963. return ArrayBuffer.isView( object ) &&
  21964. ! ( object instanceof DataView );
  21965. },
  21966. // returns an array by which times and values can be sorted
  21967. getKeyframeOrder: function ( times ) {
  21968. function compareTime( i, j ) {
  21969. return times[ i ] - times[ j ];
  21970. }
  21971. const n = times.length;
  21972. const result = new Array( n );
  21973. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  21974. result.sort( compareTime );
  21975. return result;
  21976. },
  21977. // uses the array previously returned by 'getKeyframeOrder' to sort data
  21978. sortedArray: function ( values, stride, order ) {
  21979. const nValues = values.length;
  21980. const result = new values.constructor( nValues );
  21981. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  21982. const srcOffset = order[ i ] * stride;
  21983. for ( let j = 0; j !== stride; ++ j ) {
  21984. result[ dstOffset ++ ] = values[ srcOffset + j ];
  21985. }
  21986. }
  21987. return result;
  21988. },
  21989. // function for parsing AOS keyframe formats
  21990. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  21991. let i = 1, key = jsonKeys[ 0 ];
  21992. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  21993. key = jsonKeys[ i ++ ];
  21994. }
  21995. if ( key === undefined ) return; // no data
  21996. let value = key[ valuePropertyName ];
  21997. if ( value === undefined ) return; // no data
  21998. if ( Array.isArray( value ) ) {
  21999. do {
  22000. value = key[ valuePropertyName ];
  22001. if ( value !== undefined ) {
  22002. times.push( key.time );
  22003. values.push.apply( values, value ); // push all elements
  22004. }
  22005. key = jsonKeys[ i ++ ];
  22006. } while ( key !== undefined );
  22007. } else if ( value.toArray !== undefined ) {
  22008. // ...assume THREE.Math-ish
  22009. do {
  22010. value = key[ valuePropertyName ];
  22011. if ( value !== undefined ) {
  22012. times.push( key.time );
  22013. value.toArray( values, values.length );
  22014. }
  22015. key = jsonKeys[ i ++ ];
  22016. } while ( key !== undefined );
  22017. } else {
  22018. // otherwise push as-is
  22019. do {
  22020. value = key[ valuePropertyName ];
  22021. if ( value !== undefined ) {
  22022. times.push( key.time );
  22023. values.push( value );
  22024. }
  22025. key = jsonKeys[ i ++ ];
  22026. } while ( key !== undefined );
  22027. }
  22028. },
  22029. subclip: function ( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  22030. const clip = sourceClip.clone();
  22031. clip.name = name;
  22032. const tracks = [];
  22033. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  22034. const track = clip.tracks[ i ];
  22035. const valueSize = track.getValueSize();
  22036. const times = [];
  22037. const values = [];
  22038. for ( let j = 0; j < track.times.length; ++ j ) {
  22039. const frame = track.times[ j ] * fps;
  22040. if ( frame < startFrame || frame >= endFrame ) continue;
  22041. times.push( track.times[ j ] );
  22042. for ( let k = 0; k < valueSize; ++ k ) {
  22043. values.push( track.values[ j * valueSize + k ] );
  22044. }
  22045. }
  22046. if ( times.length === 0 ) continue;
  22047. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  22048. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  22049. tracks.push( track );
  22050. }
  22051. clip.tracks = tracks;
  22052. // find minimum .times value across all tracks in the trimmed clip
  22053. let minStartTime = Infinity;
  22054. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  22055. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  22056. minStartTime = clip.tracks[ i ].times[ 0 ];
  22057. }
  22058. }
  22059. // shift all tracks such that clip begins at t=0
  22060. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  22061. clip.tracks[ i ].shift( - 1 * minStartTime );
  22062. }
  22063. clip.resetDuration();
  22064. return clip;
  22065. },
  22066. makeClipAdditive: function ( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  22067. if ( fps <= 0 ) fps = 30;
  22068. const numTracks = referenceClip.tracks.length;
  22069. const referenceTime = referenceFrame / fps;
  22070. // Make each track's values relative to the values at the reference frame
  22071. for ( let i = 0; i < numTracks; ++ i ) {
  22072. const referenceTrack = referenceClip.tracks[ i ];
  22073. const referenceTrackType = referenceTrack.ValueTypeName;
  22074. // Skip this track if it's non-numeric
  22075. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  22076. // Find the track in the target clip whose name and type matches the reference track
  22077. const targetTrack = targetClip.tracks.find( function ( track ) {
  22078. return track.name === referenceTrack.name
  22079. && track.ValueTypeName === referenceTrackType;
  22080. } );
  22081. if ( targetTrack === undefined ) continue;
  22082. let referenceOffset = 0;
  22083. const referenceValueSize = referenceTrack.getValueSize();
  22084. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  22085. referenceOffset = referenceValueSize / 3;
  22086. }
  22087. let targetOffset = 0;
  22088. const targetValueSize = targetTrack.getValueSize();
  22089. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  22090. targetOffset = targetValueSize / 3;
  22091. }
  22092. const lastIndex = referenceTrack.times.length - 1;
  22093. let referenceValue;
  22094. // Find the value to subtract out of the track
  22095. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  22096. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  22097. const startIndex = referenceOffset;
  22098. const endIndex = referenceValueSize - referenceOffset;
  22099. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  22100. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  22101. // Reference frame is after the last keyframe, so just use the last keyframe
  22102. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  22103. const endIndex = startIndex + referenceValueSize - referenceOffset;
  22104. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  22105. } else {
  22106. // Interpolate to the reference value
  22107. const interpolant = referenceTrack.createInterpolant();
  22108. const startIndex = referenceOffset;
  22109. const endIndex = referenceValueSize - referenceOffset;
  22110. interpolant.evaluate( referenceTime );
  22111. referenceValue = AnimationUtils.arraySlice( interpolant.resultBuffer, startIndex, endIndex );
  22112. }
  22113. // Conjugate the quaternion
  22114. if ( referenceTrackType === 'quaternion' ) {
  22115. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  22116. referenceQuat.toArray( referenceValue );
  22117. }
  22118. // Subtract the reference value from all of the track values
  22119. const numTimes = targetTrack.times.length;
  22120. for ( let j = 0; j < numTimes; ++ j ) {
  22121. const valueStart = j * targetValueSize + targetOffset;
  22122. if ( referenceTrackType === 'quaternion' ) {
  22123. // Multiply the conjugate for quaternion track types
  22124. Quaternion.multiplyQuaternionsFlat(
  22125. targetTrack.values,
  22126. valueStart,
  22127. referenceValue,
  22128. 0,
  22129. targetTrack.values,
  22130. valueStart
  22131. );
  22132. } else {
  22133. const valueEnd = targetValueSize - targetOffset * 2;
  22134. // Subtract each value for all other numeric track types
  22135. for ( let k = 0; k < valueEnd; ++ k ) {
  22136. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  22137. }
  22138. }
  22139. }
  22140. }
  22141. targetClip.blendMode = AdditiveAnimationBlendMode;
  22142. return targetClip;
  22143. }
  22144. };
  22145. /**
  22146. * Abstract base class of interpolants over parametric samples.
  22147. *
  22148. * The parameter domain is one dimensional, typically the time or a path
  22149. * along a curve defined by the data.
  22150. *
  22151. * The sample values can have any dimensionality and derived classes may
  22152. * apply special interpretations to the data.
  22153. *
  22154. * This class provides the interval seek in a Template Method, deferring
  22155. * the actual interpolation to derived classes.
  22156. *
  22157. * Time complexity is O(1) for linear access crossing at most two points
  22158. * and O(log N) for random access, where N is the number of positions.
  22159. *
  22160. * References:
  22161. *
  22162. * http://www.oodesign.com/template-method-pattern.html
  22163. *
  22164. */
  22165. class Interpolant {
  22166. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  22167. this.parameterPositions = parameterPositions;
  22168. this._cachedIndex = 0;
  22169. this.resultBuffer = resultBuffer !== undefined ?
  22170. resultBuffer : new sampleValues.constructor( sampleSize );
  22171. this.sampleValues = sampleValues;
  22172. this.valueSize = sampleSize;
  22173. this.settings = null;
  22174. this.DefaultSettings_ = {};
  22175. }
  22176. evaluate( t ) {
  22177. const pp = this.parameterPositions;
  22178. let i1 = this._cachedIndex,
  22179. t1 = pp[ i1 ],
  22180. t0 = pp[ i1 - 1 ];
  22181. validate_interval: {
  22182. seek: {
  22183. let right;
  22184. linear_scan: {
  22185. //- See http://jsperf.com/comparison-to-undefined/3
  22186. //- slower code:
  22187. //-
  22188. //- if ( t >= t1 || t1 === undefined ) {
  22189. forward_scan: if ( ! ( t < t1 ) ) {
  22190. for ( let giveUpAt = i1 + 2; ; ) {
  22191. if ( t1 === undefined ) {
  22192. if ( t < t0 ) break forward_scan;
  22193. // after end
  22194. i1 = pp.length;
  22195. this._cachedIndex = i1;
  22196. return this.afterEnd_( i1 - 1, t, t0 );
  22197. }
  22198. if ( i1 === giveUpAt ) break; // this loop
  22199. t0 = t1;
  22200. t1 = pp[ ++ i1 ];
  22201. if ( t < t1 ) {
  22202. // we have arrived at the sought interval
  22203. break seek;
  22204. }
  22205. }
  22206. // prepare binary search on the right side of the index
  22207. right = pp.length;
  22208. break linear_scan;
  22209. }
  22210. //- slower code:
  22211. //- if ( t < t0 || t0 === undefined ) {
  22212. if ( ! ( t >= t0 ) ) {
  22213. // looping?
  22214. const t1global = pp[ 1 ];
  22215. if ( t < t1global ) {
  22216. i1 = 2; // + 1, using the scan for the details
  22217. t0 = t1global;
  22218. }
  22219. // linear reverse scan
  22220. for ( let giveUpAt = i1 - 2; ; ) {
  22221. if ( t0 === undefined ) {
  22222. // before start
  22223. this._cachedIndex = 0;
  22224. return this.beforeStart_( 0, t, t1 );
  22225. }
  22226. if ( i1 === giveUpAt ) break; // this loop
  22227. t1 = t0;
  22228. t0 = pp[ -- i1 - 1 ];
  22229. if ( t >= t0 ) {
  22230. // we have arrived at the sought interval
  22231. break seek;
  22232. }
  22233. }
  22234. // prepare binary search on the left side of the index
  22235. right = i1;
  22236. i1 = 0;
  22237. break linear_scan;
  22238. }
  22239. // the interval is valid
  22240. break validate_interval;
  22241. } // linear scan
  22242. // binary search
  22243. while ( i1 < right ) {
  22244. const mid = ( i1 + right ) >>> 1;
  22245. if ( t < pp[ mid ] ) {
  22246. right = mid;
  22247. } else {
  22248. i1 = mid + 1;
  22249. }
  22250. }
  22251. t1 = pp[ i1 ];
  22252. t0 = pp[ i1 - 1 ];
  22253. // check boundary cases, again
  22254. if ( t0 === undefined ) {
  22255. this._cachedIndex = 0;
  22256. return this.beforeStart_( 0, t, t1 );
  22257. }
  22258. if ( t1 === undefined ) {
  22259. i1 = pp.length;
  22260. this._cachedIndex = i1;
  22261. return this.afterEnd_( i1 - 1, t0, t );
  22262. }
  22263. } // seek
  22264. this._cachedIndex = i1;
  22265. this.intervalChanged_( i1, t0, t1 );
  22266. } // validate_interval
  22267. return this.interpolate_( i1, t0, t, t1 );
  22268. }
  22269. getSettings_() {
  22270. return this.settings || this.DefaultSettings_;
  22271. }
  22272. copySampleValue_( index ) {
  22273. // copies a sample value to the result buffer
  22274. const result = this.resultBuffer,
  22275. values = this.sampleValues,
  22276. stride = this.valueSize,
  22277. offset = index * stride;
  22278. for ( let i = 0; i !== stride; ++ i ) {
  22279. result[ i ] = values[ offset + i ];
  22280. }
  22281. return result;
  22282. }
  22283. // Template methods for derived classes:
  22284. interpolate_( /* i1, t0, t, t1 */ ) {
  22285. throw new Error( 'call to abstract method' );
  22286. // implementations shall return this.resultBuffer
  22287. }
  22288. intervalChanged_( /* i1, t0, t1 */ ) {
  22289. // empty
  22290. }
  22291. }
  22292. // ALIAS DEFINITIONS
  22293. Interpolant.prototype.beforeStart_ = Interpolant.prototype.copySampleValue_;
  22294. Interpolant.prototype.afterEnd_ = Interpolant.prototype.copySampleValue_;
  22295. /**
  22296. * Fast and simple cubic spline interpolant.
  22297. *
  22298. * It was derived from a Hermitian construction setting the first derivative
  22299. * at each sample position to the linear slope between neighboring positions
  22300. * over their parameter interval.
  22301. */
  22302. class CubicInterpolant extends Interpolant {
  22303. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  22304. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  22305. this._weightPrev = - 0;
  22306. this._offsetPrev = - 0;
  22307. this._weightNext = - 0;
  22308. this._offsetNext = - 0;
  22309. this.DefaultSettings_ = {
  22310. endingStart: ZeroCurvatureEnding,
  22311. endingEnd: ZeroCurvatureEnding
  22312. };
  22313. }
  22314. intervalChanged_( i1, t0, t1 ) {
  22315. const pp = this.parameterPositions;
  22316. let iPrev = i1 - 2,
  22317. iNext = i1 + 1,
  22318. tPrev = pp[ iPrev ],
  22319. tNext = pp[ iNext ];
  22320. if ( tPrev === undefined ) {
  22321. switch ( this.getSettings_().endingStart ) {
  22322. case ZeroSlopeEnding:
  22323. // f'(t0) = 0
  22324. iPrev = i1;
  22325. tPrev = 2 * t0 - t1;
  22326. break;
  22327. case WrapAroundEnding:
  22328. // use the other end of the curve
  22329. iPrev = pp.length - 2;
  22330. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  22331. break;
  22332. default: // ZeroCurvatureEnding
  22333. // f''(t0) = 0 a.k.a. Natural Spline
  22334. iPrev = i1;
  22335. tPrev = t1;
  22336. }
  22337. }
  22338. if ( tNext === undefined ) {
  22339. switch ( this.getSettings_().endingEnd ) {
  22340. case ZeroSlopeEnding:
  22341. // f'(tN) = 0
  22342. iNext = i1;
  22343. tNext = 2 * t1 - t0;
  22344. break;
  22345. case WrapAroundEnding:
  22346. // use the other end of the curve
  22347. iNext = 1;
  22348. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  22349. break;
  22350. default: // ZeroCurvatureEnding
  22351. // f''(tN) = 0, a.k.a. Natural Spline
  22352. iNext = i1 - 1;
  22353. tNext = t0;
  22354. }
  22355. }
  22356. const halfDt = ( t1 - t0 ) * 0.5,
  22357. stride = this.valueSize;
  22358. this._weightPrev = halfDt / ( t0 - tPrev );
  22359. this._weightNext = halfDt / ( tNext - t1 );
  22360. this._offsetPrev = iPrev * stride;
  22361. this._offsetNext = iNext * stride;
  22362. }
  22363. interpolate_( i1, t0, t, t1 ) {
  22364. const result = this.resultBuffer,
  22365. values = this.sampleValues,
  22366. stride = this.valueSize,
  22367. o1 = i1 * stride, o0 = o1 - stride,
  22368. oP = this._offsetPrev, oN = this._offsetNext,
  22369. wP = this._weightPrev, wN = this._weightNext,
  22370. p = ( t - t0 ) / ( t1 - t0 ),
  22371. pp = p * p,
  22372. ppp = pp * p;
  22373. // evaluate polynomials
  22374. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  22375. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  22376. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  22377. const sN = wN * ppp - wN * pp;
  22378. // combine data linearly
  22379. for ( let i = 0; i !== stride; ++ i ) {
  22380. result[ i ] =
  22381. sP * values[ oP + i ] +
  22382. s0 * values[ o0 + i ] +
  22383. s1 * values[ o1 + i ] +
  22384. sN * values[ oN + i ];
  22385. }
  22386. return result;
  22387. }
  22388. }
  22389. class LinearInterpolant extends Interpolant {
  22390. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  22391. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  22392. }
  22393. interpolate_( i1, t0, t, t1 ) {
  22394. const result = this.resultBuffer,
  22395. values = this.sampleValues,
  22396. stride = this.valueSize,
  22397. offset1 = i1 * stride,
  22398. offset0 = offset1 - stride,
  22399. weight1 = ( t - t0 ) / ( t1 - t0 ),
  22400. weight0 = 1 - weight1;
  22401. for ( let i = 0; i !== stride; ++ i ) {
  22402. result[ i ] =
  22403. values[ offset0 + i ] * weight0 +
  22404. values[ offset1 + i ] * weight1;
  22405. }
  22406. return result;
  22407. }
  22408. }
  22409. /**
  22410. *
  22411. * Interpolant that evaluates to the sample value at the position preceeding
  22412. * the parameter.
  22413. */
  22414. class DiscreteInterpolant extends Interpolant {
  22415. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  22416. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  22417. }
  22418. interpolate_( i1 /*, t0, t, t1 */ ) {
  22419. return this.copySampleValue_( i1 - 1 );
  22420. }
  22421. }
  22422. class KeyframeTrack {
  22423. constructor( name, times, values, interpolation ) {
  22424. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  22425. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  22426. this.name = name;
  22427. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  22428. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  22429. this.setInterpolation( interpolation || this.DefaultInterpolation );
  22430. }
  22431. // Serialization (in static context, because of constructor invocation
  22432. // and automatic invocation of .toJSON):
  22433. static toJSON( track ) {
  22434. const trackType = track.constructor;
  22435. let json;
  22436. // derived classes can define a static toJSON method
  22437. if ( trackType.toJSON !== this.toJSON ) {
  22438. json = trackType.toJSON( track );
  22439. } else {
  22440. // by default, we assume the data can be serialized as-is
  22441. json = {
  22442. 'name': track.name,
  22443. 'times': AnimationUtils.convertArray( track.times, Array ),
  22444. 'values': AnimationUtils.convertArray( track.values, Array )
  22445. };
  22446. const interpolation = track.getInterpolation();
  22447. if ( interpolation !== track.DefaultInterpolation ) {
  22448. json.interpolation = interpolation;
  22449. }
  22450. }
  22451. json.type = track.ValueTypeName; // mandatory
  22452. return json;
  22453. }
  22454. InterpolantFactoryMethodDiscrete( result ) {
  22455. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  22456. }
  22457. InterpolantFactoryMethodLinear( result ) {
  22458. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  22459. }
  22460. InterpolantFactoryMethodSmooth( result ) {
  22461. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  22462. }
  22463. setInterpolation( interpolation ) {
  22464. let factoryMethod;
  22465. switch ( interpolation ) {
  22466. case InterpolateDiscrete:
  22467. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  22468. break;
  22469. case InterpolateLinear:
  22470. factoryMethod = this.InterpolantFactoryMethodLinear;
  22471. break;
  22472. case InterpolateSmooth:
  22473. factoryMethod = this.InterpolantFactoryMethodSmooth;
  22474. break;
  22475. }
  22476. if ( factoryMethod === undefined ) {
  22477. const message = 'unsupported interpolation for ' +
  22478. this.ValueTypeName + ' keyframe track named ' + this.name;
  22479. if ( this.createInterpolant === undefined ) {
  22480. // fall back to default, unless the default itself is messed up
  22481. if ( interpolation !== this.DefaultInterpolation ) {
  22482. this.setInterpolation( this.DefaultInterpolation );
  22483. } else {
  22484. throw new Error( message ); // fatal, in this case
  22485. }
  22486. }
  22487. console.warn( 'THREE.KeyframeTrack:', message );
  22488. return this;
  22489. }
  22490. this.createInterpolant = factoryMethod;
  22491. return this;
  22492. }
  22493. getInterpolation() {
  22494. switch ( this.createInterpolant ) {
  22495. case this.InterpolantFactoryMethodDiscrete:
  22496. return InterpolateDiscrete;
  22497. case this.InterpolantFactoryMethodLinear:
  22498. return InterpolateLinear;
  22499. case this.InterpolantFactoryMethodSmooth:
  22500. return InterpolateSmooth;
  22501. }
  22502. }
  22503. getValueSize() {
  22504. return this.values.length / this.times.length;
  22505. }
  22506. // move all keyframes either forwards or backwards in time
  22507. shift( timeOffset ) {
  22508. if ( timeOffset !== 0.0 ) {
  22509. const times = this.times;
  22510. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  22511. times[ i ] += timeOffset;
  22512. }
  22513. }
  22514. return this;
  22515. }
  22516. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  22517. scale( timeScale ) {
  22518. if ( timeScale !== 1.0 ) {
  22519. const times = this.times;
  22520. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  22521. times[ i ] *= timeScale;
  22522. }
  22523. }
  22524. return this;
  22525. }
  22526. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  22527. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  22528. trim( startTime, endTime ) {
  22529. const times = this.times,
  22530. nKeys = times.length;
  22531. let from = 0,
  22532. to = nKeys - 1;
  22533. while ( from !== nKeys && times[ from ] < startTime ) {
  22534. ++ from;
  22535. }
  22536. while ( to !== - 1 && times[ to ] > endTime ) {
  22537. -- to;
  22538. }
  22539. ++ to; // inclusive -> exclusive bound
  22540. if ( from !== 0 || to !== nKeys ) {
  22541. // empty tracks are forbidden, so keep at least one keyframe
  22542. if ( from >= to ) {
  22543. to = Math.max( to, 1 );
  22544. from = to - 1;
  22545. }
  22546. const stride = this.getValueSize();
  22547. this.times = AnimationUtils.arraySlice( times, from, to );
  22548. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  22549. }
  22550. return this;
  22551. }
  22552. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  22553. validate() {
  22554. let valid = true;
  22555. const valueSize = this.getValueSize();
  22556. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  22557. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  22558. valid = false;
  22559. }
  22560. const times = this.times,
  22561. values = this.values,
  22562. nKeys = times.length;
  22563. if ( nKeys === 0 ) {
  22564. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  22565. valid = false;
  22566. }
  22567. let prevTime = null;
  22568. for ( let i = 0; i !== nKeys; i ++ ) {
  22569. const currTime = times[ i ];
  22570. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  22571. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  22572. valid = false;
  22573. break;
  22574. }
  22575. if ( prevTime !== null && prevTime > currTime ) {
  22576. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  22577. valid = false;
  22578. break;
  22579. }
  22580. prevTime = currTime;
  22581. }
  22582. if ( values !== undefined ) {
  22583. if ( AnimationUtils.isTypedArray( values ) ) {
  22584. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  22585. const value = values[ i ];
  22586. if ( isNaN( value ) ) {
  22587. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  22588. valid = false;
  22589. break;
  22590. }
  22591. }
  22592. }
  22593. }
  22594. return valid;
  22595. }
  22596. // removes equivalent sequential keys as common in morph target sequences
  22597. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  22598. optimize() {
  22599. // times or values may be shared with other tracks, so overwriting is unsafe
  22600. const times = AnimationUtils.arraySlice( this.times ),
  22601. values = AnimationUtils.arraySlice( this.values ),
  22602. stride = this.getValueSize(),
  22603. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  22604. lastIndex = times.length - 1;
  22605. let writeIndex = 1;
  22606. for ( let i = 1; i < lastIndex; ++ i ) {
  22607. let keep = false;
  22608. const time = times[ i ];
  22609. const timeNext = times[ i + 1 ];
  22610. // remove adjacent keyframes scheduled at the same time
  22611. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  22612. if ( ! smoothInterpolation ) {
  22613. // remove unnecessary keyframes same as their neighbors
  22614. const offset = i * stride,
  22615. offsetP = offset - stride,
  22616. offsetN = offset + stride;
  22617. for ( let j = 0; j !== stride; ++ j ) {
  22618. const value = values[ offset + j ];
  22619. if ( value !== values[ offsetP + j ] ||
  22620. value !== values[ offsetN + j ] ) {
  22621. keep = true;
  22622. break;
  22623. }
  22624. }
  22625. } else {
  22626. keep = true;
  22627. }
  22628. }
  22629. // in-place compaction
  22630. if ( keep ) {
  22631. if ( i !== writeIndex ) {
  22632. times[ writeIndex ] = times[ i ];
  22633. const readOffset = i * stride,
  22634. writeOffset = writeIndex * stride;
  22635. for ( let j = 0; j !== stride; ++ j ) {
  22636. values[ writeOffset + j ] = values[ readOffset + j ];
  22637. }
  22638. }
  22639. ++ writeIndex;
  22640. }
  22641. }
  22642. // flush last keyframe (compaction looks ahead)
  22643. if ( lastIndex > 0 ) {
  22644. times[ writeIndex ] = times[ lastIndex ];
  22645. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  22646. values[ writeOffset + j ] = values[ readOffset + j ];
  22647. }
  22648. ++ writeIndex;
  22649. }
  22650. if ( writeIndex !== times.length ) {
  22651. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  22652. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  22653. } else {
  22654. this.times = times;
  22655. this.values = values;
  22656. }
  22657. return this;
  22658. }
  22659. clone() {
  22660. const times = AnimationUtils.arraySlice( this.times, 0 );
  22661. const values = AnimationUtils.arraySlice( this.values, 0 );
  22662. const TypedKeyframeTrack = this.constructor;
  22663. const track = new TypedKeyframeTrack( this.name, times, values );
  22664. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  22665. track.createInterpolant = this.createInterpolant;
  22666. return track;
  22667. }
  22668. }
  22669. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  22670. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  22671. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  22672. /**
  22673. * A Track of Boolean keyframe values.
  22674. */
  22675. class BooleanKeyframeTrack extends KeyframeTrack {}
  22676. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  22677. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  22678. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  22679. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  22680. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  22681. /**
  22682. * A Track of keyframe values that represent color.
  22683. */
  22684. class ColorKeyframeTrack extends KeyframeTrack {}
  22685. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  22686. /**
  22687. * A Track of numeric keyframe values.
  22688. */
  22689. class NumberKeyframeTrack extends KeyframeTrack {}
  22690. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  22691. /**
  22692. * Spherical linear unit quaternion interpolant.
  22693. */
  22694. class QuaternionLinearInterpolant extends Interpolant {
  22695. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  22696. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  22697. }
  22698. interpolate_( i1, t0, t, t1 ) {
  22699. const result = this.resultBuffer,
  22700. values = this.sampleValues,
  22701. stride = this.valueSize,
  22702. alpha = ( t - t0 ) / ( t1 - t0 );
  22703. let offset = i1 * stride;
  22704. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  22705. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  22706. }
  22707. return result;
  22708. }
  22709. }
  22710. /**
  22711. * A Track of quaternion keyframe values.
  22712. */
  22713. class QuaternionKeyframeTrack extends KeyframeTrack {
  22714. InterpolantFactoryMethodLinear( result ) {
  22715. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  22716. }
  22717. }
  22718. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  22719. // ValueBufferType is inherited
  22720. QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  22721. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  22722. /**
  22723. * A Track that interpolates Strings
  22724. */
  22725. class StringKeyframeTrack extends KeyframeTrack {}
  22726. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  22727. StringKeyframeTrack.prototype.ValueBufferType = Array;
  22728. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  22729. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  22730. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  22731. /**
  22732. * A Track of vectored keyframe values.
  22733. */
  22734. class VectorKeyframeTrack extends KeyframeTrack {}
  22735. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  22736. class AnimationClip {
  22737. constructor( name, duration = - 1, tracks, blendMode = NormalAnimationBlendMode ) {
  22738. this.name = name;
  22739. this.tracks = tracks;
  22740. this.duration = duration;
  22741. this.blendMode = blendMode;
  22742. this.uuid = generateUUID();
  22743. // this means it should figure out its duration by scanning the tracks
  22744. if ( this.duration < 0 ) {
  22745. this.resetDuration();
  22746. }
  22747. }
  22748. static parse( json ) {
  22749. const tracks = [],
  22750. jsonTracks = json.tracks,
  22751. frameTime = 1.0 / ( json.fps || 1.0 );
  22752. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  22753. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  22754. }
  22755. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  22756. clip.uuid = json.uuid;
  22757. return clip;
  22758. }
  22759. static toJSON( clip ) {
  22760. const tracks = [],
  22761. clipTracks = clip.tracks;
  22762. const json = {
  22763. 'name': clip.name,
  22764. 'duration': clip.duration,
  22765. 'tracks': tracks,
  22766. 'uuid': clip.uuid,
  22767. 'blendMode': clip.blendMode
  22768. };
  22769. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  22770. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  22771. }
  22772. return json;
  22773. }
  22774. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  22775. const numMorphTargets = morphTargetSequence.length;
  22776. const tracks = [];
  22777. for ( let i = 0; i < numMorphTargets; i ++ ) {
  22778. let times = [];
  22779. let values = [];
  22780. times.push(
  22781. ( i + numMorphTargets - 1 ) % numMorphTargets,
  22782. i,
  22783. ( i + 1 ) % numMorphTargets );
  22784. values.push( 0, 1, 0 );
  22785. const order = AnimationUtils.getKeyframeOrder( times );
  22786. times = AnimationUtils.sortedArray( times, 1, order );
  22787. values = AnimationUtils.sortedArray( values, 1, order );
  22788. // if there is a key at the first frame, duplicate it as the
  22789. // last frame as well for perfect loop.
  22790. if ( ! noLoop && times[ 0 ] === 0 ) {
  22791. times.push( numMorphTargets );
  22792. values.push( values[ 0 ] );
  22793. }
  22794. tracks.push(
  22795. new NumberKeyframeTrack(
  22796. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  22797. times, values
  22798. ).scale( 1.0 / fps ) );
  22799. }
  22800. return new this( name, - 1, tracks );
  22801. }
  22802. static findByName( objectOrClipArray, name ) {
  22803. let clipArray = objectOrClipArray;
  22804. if ( ! Array.isArray( objectOrClipArray ) ) {
  22805. const o = objectOrClipArray;
  22806. clipArray = o.geometry && o.geometry.animations || o.animations;
  22807. }
  22808. for ( let i = 0; i < clipArray.length; i ++ ) {
  22809. if ( clipArray[ i ].name === name ) {
  22810. return clipArray[ i ];
  22811. }
  22812. }
  22813. return null;
  22814. }
  22815. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  22816. const animationToMorphTargets = {};
  22817. // tested with https://regex101.com/ on trick sequences
  22818. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  22819. const pattern = /^([\w-]*?)([\d]+)$/;
  22820. // sort morph target names into animation groups based
  22821. // patterns like Walk_001, Walk_002, Run_001, Run_002
  22822. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  22823. const morphTarget = morphTargets[ i ];
  22824. const parts = morphTarget.name.match( pattern );
  22825. if ( parts && parts.length > 1 ) {
  22826. const name = parts[ 1 ];
  22827. let animationMorphTargets = animationToMorphTargets[ name ];
  22828. if ( ! animationMorphTargets ) {
  22829. animationToMorphTargets[ name ] = animationMorphTargets = [];
  22830. }
  22831. animationMorphTargets.push( morphTarget );
  22832. }
  22833. }
  22834. const clips = [];
  22835. for ( const name in animationToMorphTargets ) {
  22836. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  22837. }
  22838. return clips;
  22839. }
  22840. // parse the animation.hierarchy format
  22841. static parseAnimation( animation, bones ) {
  22842. if ( ! animation ) {
  22843. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  22844. return null;
  22845. }
  22846. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  22847. // only return track if there are actually keys.
  22848. if ( animationKeys.length !== 0 ) {
  22849. const times = [];
  22850. const values = [];
  22851. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  22852. // empty keys are filtered out, so check again
  22853. if ( times.length !== 0 ) {
  22854. destTracks.push( new trackType( trackName, times, values ) );
  22855. }
  22856. }
  22857. };
  22858. const tracks = [];
  22859. const clipName = animation.name || 'default';
  22860. const fps = animation.fps || 30;
  22861. const blendMode = animation.blendMode;
  22862. // automatic length determination in AnimationClip.
  22863. let duration = animation.length || - 1;
  22864. const hierarchyTracks = animation.hierarchy || [];
  22865. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  22866. const animationKeys = hierarchyTracks[ h ].keys;
  22867. // skip empty tracks
  22868. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  22869. // process morph targets
  22870. if ( animationKeys[ 0 ].morphTargets ) {
  22871. // figure out all morph targets used in this track
  22872. const morphTargetNames = {};
  22873. let k;
  22874. for ( k = 0; k < animationKeys.length; k ++ ) {
  22875. if ( animationKeys[ k ].morphTargets ) {
  22876. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  22877. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  22878. }
  22879. }
  22880. }
  22881. // create a track for each morph target with all zero
  22882. // morphTargetInfluences except for the keys in which
  22883. // the morphTarget is named.
  22884. for ( const morphTargetName in morphTargetNames ) {
  22885. const times = [];
  22886. const values = [];
  22887. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  22888. const animationKey = animationKeys[ k ];
  22889. times.push( animationKey.time );
  22890. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  22891. }
  22892. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  22893. }
  22894. duration = morphTargetNames.length * ( fps || 1.0 );
  22895. } else {
  22896. // ...assume skeletal animation
  22897. const boneName = '.bones[' + bones[ h ].name + ']';
  22898. addNonemptyTrack(
  22899. VectorKeyframeTrack, boneName + '.position',
  22900. animationKeys, 'pos', tracks );
  22901. addNonemptyTrack(
  22902. QuaternionKeyframeTrack, boneName + '.quaternion',
  22903. animationKeys, 'rot', tracks );
  22904. addNonemptyTrack(
  22905. VectorKeyframeTrack, boneName + '.scale',
  22906. animationKeys, 'scl', tracks );
  22907. }
  22908. }
  22909. if ( tracks.length === 0 ) {
  22910. return null;
  22911. }
  22912. const clip = new this( clipName, duration, tracks, blendMode );
  22913. return clip;
  22914. }
  22915. resetDuration() {
  22916. const tracks = this.tracks;
  22917. let duration = 0;
  22918. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  22919. const track = this.tracks[ i ];
  22920. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  22921. }
  22922. this.duration = duration;
  22923. return this;
  22924. }
  22925. trim() {
  22926. for ( let i = 0; i < this.tracks.length; i ++ ) {
  22927. this.tracks[ i ].trim( 0, this.duration );
  22928. }
  22929. return this;
  22930. }
  22931. validate() {
  22932. let valid = true;
  22933. for ( let i = 0; i < this.tracks.length; i ++ ) {
  22934. valid = valid && this.tracks[ i ].validate();
  22935. }
  22936. return valid;
  22937. }
  22938. optimize() {
  22939. for ( let i = 0; i < this.tracks.length; i ++ ) {
  22940. this.tracks[ i ].optimize();
  22941. }
  22942. return this;
  22943. }
  22944. clone() {
  22945. const tracks = [];
  22946. for ( let i = 0; i < this.tracks.length; i ++ ) {
  22947. tracks.push( this.tracks[ i ].clone() );
  22948. }
  22949. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  22950. }
  22951. toJSON() {
  22952. return this.constructor.toJSON( this );
  22953. }
  22954. }
  22955. function getTrackTypeForValueTypeName( typeName ) {
  22956. switch ( typeName.toLowerCase() ) {
  22957. case 'scalar':
  22958. case 'double':
  22959. case 'float':
  22960. case 'number':
  22961. case 'integer':
  22962. return NumberKeyframeTrack;
  22963. case 'vector':
  22964. case 'vector2':
  22965. case 'vector3':
  22966. case 'vector4':
  22967. return VectorKeyframeTrack;
  22968. case 'color':
  22969. return ColorKeyframeTrack;
  22970. case 'quaternion':
  22971. return QuaternionKeyframeTrack;
  22972. case 'bool':
  22973. case 'boolean':
  22974. return BooleanKeyframeTrack;
  22975. case 'string':
  22976. return StringKeyframeTrack;
  22977. }
  22978. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  22979. }
  22980. function parseKeyframeTrack( json ) {
  22981. if ( json.type === undefined ) {
  22982. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  22983. }
  22984. const trackType = getTrackTypeForValueTypeName( json.type );
  22985. if ( json.times === undefined ) {
  22986. const times = [], values = [];
  22987. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  22988. json.times = times;
  22989. json.values = values;
  22990. }
  22991. // derived classes can define a static parse method
  22992. if ( trackType.parse !== undefined ) {
  22993. return trackType.parse( json );
  22994. } else {
  22995. // by default, we assume a constructor compatible with the base
  22996. return new trackType( json.name, json.times, json.values, json.interpolation );
  22997. }
  22998. }
  22999. const Cache = {
  23000. enabled: false,
  23001. files: {},
  23002. add: function ( key, file ) {
  23003. if ( this.enabled === false ) return;
  23004. // console.log( 'THREE.Cache', 'Adding key:', key );
  23005. this.files[ key ] = file;
  23006. },
  23007. get: function ( key ) {
  23008. if ( this.enabled === false ) return;
  23009. // console.log( 'THREE.Cache', 'Checking key:', key );
  23010. return this.files[ key ];
  23011. },
  23012. remove: function ( key ) {
  23013. delete this.files[ key ];
  23014. },
  23015. clear: function () {
  23016. this.files = {};
  23017. }
  23018. };
  23019. class LoadingManager {
  23020. constructor( onLoad, onProgress, onError ) {
  23021. const scope = this;
  23022. let isLoading = false;
  23023. let itemsLoaded = 0;
  23024. let itemsTotal = 0;
  23025. let urlModifier = undefined;
  23026. const handlers = [];
  23027. // Refer to #5689 for the reason why we don't set .onStart
  23028. // in the constructor
  23029. this.onStart = undefined;
  23030. this.onLoad = onLoad;
  23031. this.onProgress = onProgress;
  23032. this.onError = onError;
  23033. this.itemStart = function ( url ) {
  23034. itemsTotal ++;
  23035. if ( isLoading === false ) {
  23036. if ( scope.onStart !== undefined ) {
  23037. scope.onStart( url, itemsLoaded, itemsTotal );
  23038. }
  23039. }
  23040. isLoading = true;
  23041. };
  23042. this.itemEnd = function ( url ) {
  23043. itemsLoaded ++;
  23044. if ( scope.onProgress !== undefined ) {
  23045. scope.onProgress( url, itemsLoaded, itemsTotal );
  23046. }
  23047. if ( itemsLoaded === itemsTotal ) {
  23048. isLoading = false;
  23049. if ( scope.onLoad !== undefined ) {
  23050. scope.onLoad();
  23051. }
  23052. }
  23053. };
  23054. this.itemError = function ( url ) {
  23055. if ( scope.onError !== undefined ) {
  23056. scope.onError( url );
  23057. }
  23058. };
  23059. this.resolveURL = function ( url ) {
  23060. if ( urlModifier ) {
  23061. return urlModifier( url );
  23062. }
  23063. return url;
  23064. };
  23065. this.setURLModifier = function ( transform ) {
  23066. urlModifier = transform;
  23067. return this;
  23068. };
  23069. this.addHandler = function ( regex, loader ) {
  23070. handlers.push( regex, loader );
  23071. return this;
  23072. };
  23073. this.removeHandler = function ( regex ) {
  23074. const index = handlers.indexOf( regex );
  23075. if ( index !== - 1 ) {
  23076. handlers.splice( index, 2 );
  23077. }
  23078. return this;
  23079. };
  23080. this.getHandler = function ( file ) {
  23081. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  23082. const regex = handlers[ i ];
  23083. const loader = handlers[ i + 1 ];
  23084. if ( regex.global ) regex.lastIndex = 0; // see #17920
  23085. if ( regex.test( file ) ) {
  23086. return loader;
  23087. }
  23088. }
  23089. return null;
  23090. };
  23091. }
  23092. }
  23093. const DefaultLoadingManager = new LoadingManager();
  23094. class Loader {
  23095. constructor( manager ) {
  23096. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23097. this.crossOrigin = 'anonymous';
  23098. this.withCredentials = false;
  23099. this.path = '';
  23100. this.resourcePath = '';
  23101. this.requestHeader = {};
  23102. }
  23103. load( /* url, onLoad, onProgress, onError */ ) {}
  23104. loadAsync( url, onProgress ) {
  23105. const scope = this;
  23106. return new Promise( function ( resolve, reject ) {
  23107. scope.load( url, resolve, onProgress, reject );
  23108. } );
  23109. }
  23110. parse( /* data */ ) {}
  23111. setCrossOrigin( crossOrigin ) {
  23112. this.crossOrigin = crossOrigin;
  23113. return this;
  23114. }
  23115. setWithCredentials( value ) {
  23116. this.withCredentials = value;
  23117. return this;
  23118. }
  23119. setPath( path ) {
  23120. this.path = path;
  23121. return this;
  23122. }
  23123. setResourcePath( resourcePath ) {
  23124. this.resourcePath = resourcePath;
  23125. return this;
  23126. }
  23127. setRequestHeader( requestHeader ) {
  23128. this.requestHeader = requestHeader;
  23129. return this;
  23130. }
  23131. }
  23132. const loading = {};
  23133. class FileLoader extends Loader {
  23134. constructor( manager ) {
  23135. super( manager );
  23136. }
  23137. load( url, onLoad, onProgress, onError ) {
  23138. if ( url === undefined ) url = '';
  23139. if ( this.path !== undefined ) url = this.path + url;
  23140. url = this.manager.resolveURL( url );
  23141. const scope = this;
  23142. const cached = Cache.get( url );
  23143. if ( cached !== undefined ) {
  23144. scope.manager.itemStart( url );
  23145. setTimeout( function () {
  23146. if ( onLoad ) onLoad( cached );
  23147. scope.manager.itemEnd( url );
  23148. }, 0 );
  23149. return cached;
  23150. }
  23151. // Check if request is duplicate
  23152. if ( loading[ url ] !== undefined ) {
  23153. loading[ url ].push( {
  23154. onLoad: onLoad,
  23155. onProgress: onProgress,
  23156. onError: onError
  23157. } );
  23158. return;
  23159. }
  23160. // Check for data: URI
  23161. const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  23162. const dataUriRegexResult = url.match( dataUriRegex );
  23163. let request;
  23164. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  23165. if ( dataUriRegexResult ) {
  23166. const mimeType = dataUriRegexResult[ 1 ];
  23167. const isBase64 = !! dataUriRegexResult[ 2 ];
  23168. let data = dataUriRegexResult[ 3 ];
  23169. data = decodeURIComponent( data );
  23170. if ( isBase64 ) data = atob( data );
  23171. try {
  23172. let response;
  23173. const responseType = ( this.responseType || '' ).toLowerCase();
  23174. switch ( responseType ) {
  23175. case 'arraybuffer':
  23176. case 'blob':
  23177. const view = new Uint8Array( data.length );
  23178. for ( let i = 0; i < data.length; i ++ ) {
  23179. view[ i ] = data.charCodeAt( i );
  23180. }
  23181. if ( responseType === 'blob' ) {
  23182. response = new Blob( [ view.buffer ], { type: mimeType } );
  23183. } else {
  23184. response = view.buffer;
  23185. }
  23186. break;
  23187. case 'document':
  23188. const parser = new DOMParser();
  23189. response = parser.parseFromString( data, mimeType );
  23190. break;
  23191. case 'json':
  23192. response = JSON.parse( data );
  23193. break;
  23194. default: // 'text' or other
  23195. response = data;
  23196. break;
  23197. }
  23198. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  23199. setTimeout( function () {
  23200. if ( onLoad ) onLoad( response );
  23201. scope.manager.itemEnd( url );
  23202. }, 0 );
  23203. } catch ( error ) {
  23204. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  23205. setTimeout( function () {
  23206. if ( onError ) onError( error );
  23207. scope.manager.itemError( url );
  23208. scope.manager.itemEnd( url );
  23209. }, 0 );
  23210. }
  23211. } else {
  23212. // Initialise array for duplicate requests
  23213. loading[ url ] = [];
  23214. loading[ url ].push( {
  23215. onLoad: onLoad,
  23216. onProgress: onProgress,
  23217. onError: onError
  23218. } );
  23219. request = new XMLHttpRequest();
  23220. request.open( 'GET', url, true );
  23221. request.addEventListener( 'load', function ( event ) {
  23222. const response = this.response;
  23223. const callbacks = loading[ url ];
  23224. delete loading[ url ];
  23225. if ( this.status === 200 || this.status === 0 ) {
  23226. // Some browsers return HTTP Status 0 when using non-http protocol
  23227. // e.g. 'file://' or 'data://'. Handle as success.
  23228. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  23229. // Add to cache only on HTTP success, so that we do not cache
  23230. // error response bodies as proper responses to requests.
  23231. Cache.add( url, response );
  23232. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  23233. const callback = callbacks[ i ];
  23234. if ( callback.onLoad ) callback.onLoad( response );
  23235. }
  23236. scope.manager.itemEnd( url );
  23237. } else {
  23238. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  23239. const callback = callbacks[ i ];
  23240. if ( callback.onError ) callback.onError( event );
  23241. }
  23242. scope.manager.itemError( url );
  23243. scope.manager.itemEnd( url );
  23244. }
  23245. }, false );
  23246. request.addEventListener( 'progress', function ( event ) {
  23247. const callbacks = loading[ url ];
  23248. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  23249. const callback = callbacks[ i ];
  23250. if ( callback.onProgress ) callback.onProgress( event );
  23251. }
  23252. }, false );
  23253. request.addEventListener( 'error', function ( event ) {
  23254. const callbacks = loading[ url ];
  23255. delete loading[ url ];
  23256. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  23257. const callback = callbacks[ i ];
  23258. if ( callback.onError ) callback.onError( event );
  23259. }
  23260. scope.manager.itemError( url );
  23261. scope.manager.itemEnd( url );
  23262. }, false );
  23263. request.addEventListener( 'abort', function ( event ) {
  23264. const callbacks = loading[ url ];
  23265. delete loading[ url ];
  23266. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  23267. const callback = callbacks[ i ];
  23268. if ( callback.onError ) callback.onError( event );
  23269. }
  23270. scope.manager.itemError( url );
  23271. scope.manager.itemEnd( url );
  23272. }, false );
  23273. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  23274. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  23275. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  23276. for ( const header in this.requestHeader ) {
  23277. request.setRequestHeader( header, this.requestHeader[ header ] );
  23278. }
  23279. request.send( null );
  23280. }
  23281. scope.manager.itemStart( url );
  23282. return request;
  23283. }
  23284. setResponseType( value ) {
  23285. this.responseType = value;
  23286. return this;
  23287. }
  23288. setMimeType( value ) {
  23289. this.mimeType = value;
  23290. return this;
  23291. }
  23292. }
  23293. class AnimationLoader extends Loader {
  23294. constructor( manager ) {
  23295. super( manager );
  23296. }
  23297. load( url, onLoad, onProgress, onError ) {
  23298. const scope = this;
  23299. const loader = new FileLoader( this.manager );
  23300. loader.setPath( this.path );
  23301. loader.setRequestHeader( this.requestHeader );
  23302. loader.setWithCredentials( this.withCredentials );
  23303. loader.load( url, function ( text ) {
  23304. try {
  23305. onLoad( scope.parse( JSON.parse( text ) ) );
  23306. } catch ( e ) {
  23307. if ( onError ) {
  23308. onError( e );
  23309. } else {
  23310. console.error( e );
  23311. }
  23312. scope.manager.itemError( url );
  23313. }
  23314. }, onProgress, onError );
  23315. }
  23316. parse( json ) {
  23317. const animations = [];
  23318. for ( let i = 0; i < json.length; i ++ ) {
  23319. const clip = AnimationClip.parse( json[ i ] );
  23320. animations.push( clip );
  23321. }
  23322. return animations;
  23323. }
  23324. }
  23325. /**
  23326. * Abstract Base class to block based textures loader (dds, pvr, ...)
  23327. *
  23328. * Sub classes have to implement the parse() method which will be used in load().
  23329. */
  23330. class CompressedTextureLoader extends Loader {
  23331. constructor( manager ) {
  23332. super( manager );
  23333. }
  23334. load( url, onLoad, onProgress, onError ) {
  23335. const scope = this;
  23336. const images = [];
  23337. const texture = new CompressedTexture();
  23338. const loader = new FileLoader( this.manager );
  23339. loader.setPath( this.path );
  23340. loader.setResponseType( 'arraybuffer' );
  23341. loader.setRequestHeader( this.requestHeader );
  23342. loader.setWithCredentials( scope.withCredentials );
  23343. let loaded = 0;
  23344. function loadTexture( i ) {
  23345. loader.load( url[ i ], function ( buffer ) {
  23346. const texDatas = scope.parse( buffer, true );
  23347. images[ i ] = {
  23348. width: texDatas.width,
  23349. height: texDatas.height,
  23350. format: texDatas.format,
  23351. mipmaps: texDatas.mipmaps
  23352. };
  23353. loaded += 1;
  23354. if ( loaded === 6 ) {
  23355. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  23356. texture.image = images;
  23357. texture.format = texDatas.format;
  23358. texture.needsUpdate = true;
  23359. if ( onLoad ) onLoad( texture );
  23360. }
  23361. }, onProgress, onError );
  23362. }
  23363. if ( Array.isArray( url ) ) {
  23364. for ( let i = 0, il = url.length; i < il; ++ i ) {
  23365. loadTexture( i );
  23366. }
  23367. } else {
  23368. // compressed cubemap texture stored in a single DDS file
  23369. loader.load( url, function ( buffer ) {
  23370. const texDatas = scope.parse( buffer, true );
  23371. if ( texDatas.isCubemap ) {
  23372. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  23373. for ( let f = 0; f < faces; f ++ ) {
  23374. images[ f ] = { mipmaps: [] };
  23375. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  23376. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  23377. images[ f ].format = texDatas.format;
  23378. images[ f ].width = texDatas.width;
  23379. images[ f ].height = texDatas.height;
  23380. }
  23381. }
  23382. texture.image = images;
  23383. } else {
  23384. texture.image.width = texDatas.width;
  23385. texture.image.height = texDatas.height;
  23386. texture.mipmaps = texDatas.mipmaps;
  23387. }
  23388. if ( texDatas.mipmapCount === 1 ) {
  23389. texture.minFilter = LinearFilter;
  23390. }
  23391. texture.format = texDatas.format;
  23392. texture.needsUpdate = true;
  23393. if ( onLoad ) onLoad( texture );
  23394. }, onProgress, onError );
  23395. }
  23396. return texture;
  23397. }
  23398. }
  23399. class ImageLoader extends Loader {
  23400. constructor( manager ) {
  23401. super( manager );
  23402. }
  23403. load( url, onLoad, onProgress, onError ) {
  23404. if ( this.path !== undefined ) url = this.path + url;
  23405. url = this.manager.resolveURL( url );
  23406. const scope = this;
  23407. const cached = Cache.get( url );
  23408. if ( cached !== undefined ) {
  23409. scope.manager.itemStart( url );
  23410. setTimeout( function () {
  23411. if ( onLoad ) onLoad( cached );
  23412. scope.manager.itemEnd( url );
  23413. }, 0 );
  23414. return cached;
  23415. }
  23416. const image = createElementNS( 'img' );
  23417. function onImageLoad() {
  23418. image.removeEventListener( 'load', onImageLoad, false );
  23419. image.removeEventListener( 'error', onImageError, false );
  23420. Cache.add( url, this );
  23421. if ( onLoad ) onLoad( this );
  23422. scope.manager.itemEnd( url );
  23423. }
  23424. function onImageError( event ) {
  23425. image.removeEventListener( 'load', onImageLoad, false );
  23426. image.removeEventListener( 'error', onImageError, false );
  23427. if ( onError ) onError( event );
  23428. scope.manager.itemError( url );
  23429. scope.manager.itemEnd( url );
  23430. }
  23431. image.addEventListener( 'load', onImageLoad, false );
  23432. image.addEventListener( 'error', onImageError, false );
  23433. if ( url.substr( 0, 5 ) !== 'data:' ) {
  23434. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  23435. }
  23436. scope.manager.itemStart( url );
  23437. image.src = url;
  23438. return image;
  23439. }
  23440. }
  23441. class CubeTextureLoader extends Loader {
  23442. constructor( manager ) {
  23443. super( manager );
  23444. }
  23445. load( urls, onLoad, onProgress, onError ) {
  23446. const texture = new CubeTexture();
  23447. const loader = new ImageLoader( this.manager );
  23448. loader.setCrossOrigin( this.crossOrigin );
  23449. loader.setPath( this.path );
  23450. let loaded = 0;
  23451. function loadTexture( i ) {
  23452. loader.load( urls[ i ], function ( image ) {
  23453. texture.images[ i ] = image;
  23454. loaded ++;
  23455. if ( loaded === 6 ) {
  23456. texture.needsUpdate = true;
  23457. if ( onLoad ) onLoad( texture );
  23458. }
  23459. }, undefined, onError );
  23460. }
  23461. for ( let i = 0; i < urls.length; ++ i ) {
  23462. loadTexture( i );
  23463. }
  23464. return texture;
  23465. }
  23466. }
  23467. /**
  23468. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  23469. *
  23470. * Sub classes have to implement the parse() method which will be used in load().
  23471. */
  23472. class DataTextureLoader extends Loader {
  23473. constructor( manager ) {
  23474. super( manager );
  23475. }
  23476. load( url, onLoad, onProgress, onError ) {
  23477. const scope = this;
  23478. const texture = new DataTexture();
  23479. const loader = new FileLoader( this.manager );
  23480. loader.setResponseType( 'arraybuffer' );
  23481. loader.setRequestHeader( this.requestHeader );
  23482. loader.setPath( this.path );
  23483. loader.setWithCredentials( scope.withCredentials );
  23484. loader.load( url, function ( buffer ) {
  23485. const texData = scope.parse( buffer );
  23486. if ( ! texData ) return;
  23487. if ( texData.image !== undefined ) {
  23488. texture.image = texData.image;
  23489. } else if ( texData.data !== undefined ) {
  23490. texture.image.width = texData.width;
  23491. texture.image.height = texData.height;
  23492. texture.image.data = texData.data;
  23493. }
  23494. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  23495. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  23496. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  23497. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  23498. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  23499. if ( texData.encoding !== undefined ) {
  23500. texture.encoding = texData.encoding;
  23501. }
  23502. if ( texData.flipY !== undefined ) {
  23503. texture.flipY = texData.flipY;
  23504. }
  23505. if ( texData.format !== undefined ) {
  23506. texture.format = texData.format;
  23507. }
  23508. if ( texData.type !== undefined ) {
  23509. texture.type = texData.type;
  23510. }
  23511. if ( texData.mipmaps !== undefined ) {
  23512. texture.mipmaps = texData.mipmaps;
  23513. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  23514. }
  23515. if ( texData.mipmapCount === 1 ) {
  23516. texture.minFilter = LinearFilter;
  23517. }
  23518. if ( texData.generateMipmaps !== undefined ) {
  23519. texture.generateMipmaps = texData.generateMipmaps;
  23520. }
  23521. texture.needsUpdate = true;
  23522. if ( onLoad ) onLoad( texture, texData );
  23523. }, onProgress, onError );
  23524. return texture;
  23525. }
  23526. }
  23527. class TextureLoader extends Loader {
  23528. constructor( manager ) {
  23529. super( manager );
  23530. }
  23531. load( url, onLoad, onProgress, onError ) {
  23532. const texture = new Texture();
  23533. const loader = new ImageLoader( this.manager );
  23534. loader.setCrossOrigin( this.crossOrigin );
  23535. loader.setPath( this.path );
  23536. loader.load( url, function ( image ) {
  23537. texture.image = image;
  23538. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  23539. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  23540. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  23541. texture.needsUpdate = true;
  23542. if ( onLoad !== undefined ) {
  23543. onLoad( texture );
  23544. }
  23545. }, onProgress, onError );
  23546. return texture;
  23547. }
  23548. }
  23549. class Light extends Object3D {
  23550. constructor( color, intensity = 1 ) {
  23551. super();
  23552. this.type = 'Light';
  23553. this.color = new Color( color );
  23554. this.intensity = intensity;
  23555. }
  23556. dispose() {
  23557. // Empty here in base class; some subclasses override.
  23558. }
  23559. copy( source ) {
  23560. super.copy( source );
  23561. this.color.copy( source.color );
  23562. this.intensity = source.intensity;
  23563. return this;
  23564. }
  23565. toJSON( meta ) {
  23566. const data = super.toJSON( meta );
  23567. data.object.color = this.color.getHex();
  23568. data.object.intensity = this.intensity;
  23569. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  23570. if ( this.distance !== undefined ) data.object.distance = this.distance;
  23571. if ( this.angle !== undefined ) data.object.angle = this.angle;
  23572. if ( this.decay !== undefined ) data.object.decay = this.decay;
  23573. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  23574. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  23575. return data;
  23576. }
  23577. }
  23578. Light.prototype.isLight = true;
  23579. class HemisphereLight extends Light {
  23580. constructor( skyColor, groundColor, intensity ) {
  23581. super( skyColor, intensity );
  23582. this.type = 'HemisphereLight';
  23583. this.position.copy( Object3D.DefaultUp );
  23584. this.updateMatrix();
  23585. this.groundColor = new Color( groundColor );
  23586. }
  23587. copy( source ) {
  23588. Light.prototype.copy.call( this, source );
  23589. this.groundColor.copy( source.groundColor );
  23590. return this;
  23591. }
  23592. }
  23593. HemisphereLight.prototype.isHemisphereLight = true;
  23594. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  23595. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  23596. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  23597. class LightShadow {
  23598. constructor( camera ) {
  23599. this.camera = camera;
  23600. this.bias = 0;
  23601. this.normalBias = 0;
  23602. this.radius = 1;
  23603. this.blurSamples = 8;
  23604. this.mapSize = new Vector2( 512, 512 );
  23605. this.map = null;
  23606. this.mapPass = null;
  23607. this.matrix = new Matrix4();
  23608. this.autoUpdate = true;
  23609. this.needsUpdate = false;
  23610. this._frustum = new Frustum();
  23611. this._frameExtents = new Vector2( 1, 1 );
  23612. this._viewportCount = 1;
  23613. this._viewports = [
  23614. new Vector4( 0, 0, 1, 1 )
  23615. ];
  23616. }
  23617. getViewportCount() {
  23618. return this._viewportCount;
  23619. }
  23620. getFrustum() {
  23621. return this._frustum;
  23622. }
  23623. updateMatrices( light ) {
  23624. const shadowCamera = this.camera;
  23625. const shadowMatrix = this.matrix;
  23626. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  23627. shadowCamera.position.copy( _lightPositionWorld$1 );
  23628. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  23629. shadowCamera.lookAt( _lookTarget$1 );
  23630. shadowCamera.updateMatrixWorld();
  23631. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23632. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  23633. shadowMatrix.set(
  23634. 0.5, 0.0, 0.0, 0.5,
  23635. 0.0, 0.5, 0.0, 0.5,
  23636. 0.0, 0.0, 0.5, 0.5,
  23637. 0.0, 0.0, 0.0, 1.0
  23638. );
  23639. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23640. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23641. }
  23642. getViewport( viewportIndex ) {
  23643. return this._viewports[ viewportIndex ];
  23644. }
  23645. getFrameExtents() {
  23646. return this._frameExtents;
  23647. }
  23648. dispose() {
  23649. if ( this.map ) {
  23650. this.map.dispose();
  23651. }
  23652. if ( this.mapPass ) {
  23653. this.mapPass.dispose();
  23654. }
  23655. }
  23656. copy( source ) {
  23657. this.camera = source.camera.clone();
  23658. this.bias = source.bias;
  23659. this.radius = source.radius;
  23660. this.mapSize.copy( source.mapSize );
  23661. return this;
  23662. }
  23663. clone() {
  23664. return new this.constructor().copy( this );
  23665. }
  23666. toJSON() {
  23667. const object = {};
  23668. if ( this.bias !== 0 ) object.bias = this.bias;
  23669. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  23670. if ( this.radius !== 1 ) object.radius = this.radius;
  23671. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23672. object.camera = this.camera.toJSON( false ).object;
  23673. delete object.camera.matrix;
  23674. return object;
  23675. }
  23676. }
  23677. class SpotLightShadow extends LightShadow {
  23678. constructor() {
  23679. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23680. this.focus = 1;
  23681. }
  23682. updateMatrices( light ) {
  23683. const camera = this.camera;
  23684. const fov = RAD2DEG * 2 * light.angle * this.focus;
  23685. const aspect = this.mapSize.width / this.mapSize.height;
  23686. const far = light.distance || camera.far;
  23687. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23688. camera.fov = fov;
  23689. camera.aspect = aspect;
  23690. camera.far = far;
  23691. camera.updateProjectionMatrix();
  23692. }
  23693. super.updateMatrices( light );
  23694. }
  23695. copy( source ) {
  23696. super.copy( source );
  23697. this.focus = source.focus;
  23698. return this;
  23699. }
  23700. }
  23701. SpotLightShadow.prototype.isSpotLightShadow = true;
  23702. class SpotLight extends Light {
  23703. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 1 ) {
  23704. super( color, intensity );
  23705. this.type = 'SpotLight';
  23706. this.position.copy( Object3D.DefaultUp );
  23707. this.updateMatrix();
  23708. this.target = new Object3D();
  23709. this.distance = distance;
  23710. this.angle = angle;
  23711. this.penumbra = penumbra;
  23712. this.decay = decay; // for physically correct lights, should be 2.
  23713. this.shadow = new SpotLightShadow();
  23714. }
  23715. get power() {
  23716. // compute the light's luminous power (in lumens) from its intensity (in candela)
  23717. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  23718. return this.intensity * Math.PI;
  23719. }
  23720. set power( power ) {
  23721. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  23722. this.intensity = power / Math.PI;
  23723. }
  23724. dispose() {
  23725. this.shadow.dispose();
  23726. }
  23727. copy( source ) {
  23728. super.copy( source );
  23729. this.distance = source.distance;
  23730. this.angle = source.angle;
  23731. this.penumbra = source.penumbra;
  23732. this.decay = source.decay;
  23733. this.target = source.target.clone();
  23734. this.shadow = source.shadow.clone();
  23735. return this;
  23736. }
  23737. }
  23738. SpotLight.prototype.isSpotLight = true;
  23739. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  23740. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  23741. const _lookTarget = /*@__PURE__*/ new Vector3();
  23742. class PointLightShadow extends LightShadow {
  23743. constructor() {
  23744. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23745. this._frameExtents = new Vector2( 4, 2 );
  23746. this._viewportCount = 6;
  23747. this._viewports = [
  23748. // These viewports map a cube-map onto a 2D texture with the
  23749. // following orientation:
  23750. //
  23751. // xzXZ
  23752. // y Y
  23753. //
  23754. // X - Positive x direction
  23755. // x - Negative x direction
  23756. // Y - Positive y direction
  23757. // y - Negative y direction
  23758. // Z - Positive z direction
  23759. // z - Negative z direction
  23760. // positive X
  23761. new Vector4( 2, 1, 1, 1 ),
  23762. // negative X
  23763. new Vector4( 0, 1, 1, 1 ),
  23764. // positive Z
  23765. new Vector4( 3, 1, 1, 1 ),
  23766. // negative Z
  23767. new Vector4( 1, 1, 1, 1 ),
  23768. // positive Y
  23769. new Vector4( 3, 0, 1, 1 ),
  23770. // negative Y
  23771. new Vector4( 1, 0, 1, 1 )
  23772. ];
  23773. this._cubeDirections = [
  23774. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23775. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23776. ];
  23777. this._cubeUps = [
  23778. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23779. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23780. ];
  23781. }
  23782. updateMatrices( light, viewportIndex = 0 ) {
  23783. const camera = this.camera;
  23784. const shadowMatrix = this.matrix;
  23785. const far = light.distance || camera.far;
  23786. if ( far !== camera.far ) {
  23787. camera.far = far;
  23788. camera.updateProjectionMatrix();
  23789. }
  23790. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23791. camera.position.copy( _lightPositionWorld );
  23792. _lookTarget.copy( camera.position );
  23793. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23794. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23795. camera.lookAt( _lookTarget );
  23796. camera.updateMatrixWorld();
  23797. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  23798. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23799. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  23800. }
  23801. }
  23802. PointLightShadow.prototype.isPointLightShadow = true;
  23803. class PointLight extends Light {
  23804. constructor( color, intensity, distance = 0, decay = 1 ) {
  23805. super( color, intensity );
  23806. this.type = 'PointLight';
  23807. this.distance = distance;
  23808. this.decay = decay; // for physically correct lights, should be 2.
  23809. this.shadow = new PointLightShadow();
  23810. }
  23811. get power() {
  23812. // compute the light's luminous power (in lumens) from its intensity (in candela)
  23813. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  23814. return this.intensity * 4 * Math.PI;
  23815. }
  23816. set power( power ) {
  23817. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  23818. this.intensity = power / ( 4 * Math.PI );
  23819. }
  23820. dispose() {
  23821. this.shadow.dispose();
  23822. }
  23823. copy( source ) {
  23824. super.copy( source );
  23825. this.distance = source.distance;
  23826. this.decay = source.decay;
  23827. this.shadow = source.shadow.clone();
  23828. return this;
  23829. }
  23830. }
  23831. PointLight.prototype.isPointLight = true;
  23832. class DirectionalLightShadow extends LightShadow {
  23833. constructor() {
  23834. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  23835. }
  23836. }
  23837. DirectionalLightShadow.prototype.isDirectionalLightShadow = true;
  23838. class DirectionalLight extends Light {
  23839. constructor( color, intensity ) {
  23840. super( color, intensity );
  23841. this.type = 'DirectionalLight';
  23842. this.position.copy( Object3D.DefaultUp );
  23843. this.updateMatrix();
  23844. this.target = new Object3D();
  23845. this.shadow = new DirectionalLightShadow();
  23846. }
  23847. dispose() {
  23848. this.shadow.dispose();
  23849. }
  23850. copy( source ) {
  23851. super.copy( source );
  23852. this.target = source.target.clone();
  23853. this.shadow = source.shadow.clone();
  23854. return this;
  23855. }
  23856. }
  23857. DirectionalLight.prototype.isDirectionalLight = true;
  23858. class AmbientLight extends Light {
  23859. constructor( color, intensity ) {
  23860. super( color, intensity );
  23861. this.type = 'AmbientLight';
  23862. }
  23863. }
  23864. AmbientLight.prototype.isAmbientLight = true;
  23865. class RectAreaLight extends Light {
  23866. constructor( color, intensity, width = 10, height = 10 ) {
  23867. super( color, intensity );
  23868. this.type = 'RectAreaLight';
  23869. this.width = width;
  23870. this.height = height;
  23871. }
  23872. get power() {
  23873. // compute the light's luminous power (in lumens) from its intensity (in nits)
  23874. return this.intensity * this.width * this.height * Math.PI;
  23875. }
  23876. set power( power ) {
  23877. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  23878. this.intensity = power / ( this.width * this.height * Math.PI );
  23879. }
  23880. copy( source ) {
  23881. super.copy( source );
  23882. this.width = source.width;
  23883. this.height = source.height;
  23884. return this;
  23885. }
  23886. toJSON( meta ) {
  23887. const data = super.toJSON( meta );
  23888. data.object.width = this.width;
  23889. data.object.height = this.height;
  23890. return data;
  23891. }
  23892. }
  23893. RectAreaLight.prototype.isRectAreaLight = true;
  23894. /**
  23895. * Primary reference:
  23896. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23897. *
  23898. * Secondary reference:
  23899. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23900. */
  23901. // 3-band SH defined by 9 coefficients
  23902. class SphericalHarmonics3 {
  23903. constructor() {
  23904. this.coefficients = [];
  23905. for ( let i = 0; i < 9; i ++ ) {
  23906. this.coefficients.push( new Vector3() );
  23907. }
  23908. }
  23909. set( coefficients ) {
  23910. for ( let i = 0; i < 9; i ++ ) {
  23911. this.coefficients[ i ].copy( coefficients[ i ] );
  23912. }
  23913. return this;
  23914. }
  23915. zero() {
  23916. for ( let i = 0; i < 9; i ++ ) {
  23917. this.coefficients[ i ].set( 0, 0, 0 );
  23918. }
  23919. return this;
  23920. }
  23921. // get the radiance in the direction of the normal
  23922. // target is a Vector3
  23923. getAt( normal, target ) {
  23924. // normal is assumed to be unit length
  23925. const x = normal.x, y = normal.y, z = normal.z;
  23926. const coeff = this.coefficients;
  23927. // band 0
  23928. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  23929. // band 1
  23930. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  23931. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  23932. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  23933. // band 2
  23934. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  23935. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  23936. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  23937. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  23938. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  23939. return target;
  23940. }
  23941. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23942. // target is a Vector3
  23943. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23944. getIrradianceAt( normal, target ) {
  23945. // normal is assumed to be unit length
  23946. const x = normal.x, y = normal.y, z = normal.z;
  23947. const coeff = this.coefficients;
  23948. // band 0
  23949. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  23950. // band 1
  23951. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  23952. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  23953. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  23954. // band 2
  23955. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  23956. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  23957. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  23958. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  23959. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  23960. return target;
  23961. }
  23962. add( sh ) {
  23963. for ( let i = 0; i < 9; i ++ ) {
  23964. this.coefficients[ i ].add( sh.coefficients[ i ] );
  23965. }
  23966. return this;
  23967. }
  23968. addScaledSH( sh, s ) {
  23969. for ( let i = 0; i < 9; i ++ ) {
  23970. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  23971. }
  23972. return this;
  23973. }
  23974. scale( s ) {
  23975. for ( let i = 0; i < 9; i ++ ) {
  23976. this.coefficients[ i ].multiplyScalar( s );
  23977. }
  23978. return this;
  23979. }
  23980. lerp( sh, alpha ) {
  23981. for ( let i = 0; i < 9; i ++ ) {
  23982. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  23983. }
  23984. return this;
  23985. }
  23986. equals( sh ) {
  23987. for ( let i = 0; i < 9; i ++ ) {
  23988. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  23989. return false;
  23990. }
  23991. }
  23992. return true;
  23993. }
  23994. copy( sh ) {
  23995. return this.set( sh.coefficients );
  23996. }
  23997. clone() {
  23998. return new this.constructor().copy( this );
  23999. }
  24000. fromArray( array, offset = 0 ) {
  24001. const coefficients = this.coefficients;
  24002. for ( let i = 0; i < 9; i ++ ) {
  24003. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  24004. }
  24005. return this;
  24006. }
  24007. toArray( array = [], offset = 0 ) {
  24008. const coefficients = this.coefficients;
  24009. for ( let i = 0; i < 9; i ++ ) {
  24010. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  24011. }
  24012. return array;
  24013. }
  24014. // evaluate the basis functions
  24015. // shBasis is an Array[ 9 ]
  24016. static getBasisAt( normal, shBasis ) {
  24017. // normal is assumed to be unit length
  24018. const x = normal.x, y = normal.y, z = normal.z;
  24019. // band 0
  24020. shBasis[ 0 ] = 0.282095;
  24021. // band 1
  24022. shBasis[ 1 ] = 0.488603 * y;
  24023. shBasis[ 2 ] = 0.488603 * z;
  24024. shBasis[ 3 ] = 0.488603 * x;
  24025. // band 2
  24026. shBasis[ 4 ] = 1.092548 * x * y;
  24027. shBasis[ 5 ] = 1.092548 * y * z;
  24028. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24029. shBasis[ 7 ] = 1.092548 * x * z;
  24030. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24031. }
  24032. }
  24033. SphericalHarmonics3.prototype.isSphericalHarmonics3 = true;
  24034. class LightProbe extends Light {
  24035. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  24036. super( undefined, intensity );
  24037. this.sh = sh;
  24038. }
  24039. copy( source ) {
  24040. super.copy( source );
  24041. this.sh.copy( source.sh );
  24042. return this;
  24043. }
  24044. fromJSON( json ) {
  24045. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24046. this.sh.fromArray( json.sh );
  24047. return this;
  24048. }
  24049. toJSON( meta ) {
  24050. const data = super.toJSON( meta );
  24051. data.object.sh = this.sh.toArray();
  24052. return data;
  24053. }
  24054. }
  24055. LightProbe.prototype.isLightProbe = true;
  24056. class MaterialLoader extends Loader {
  24057. constructor( manager ) {
  24058. super( manager );
  24059. this.textures = {};
  24060. }
  24061. load( url, onLoad, onProgress, onError ) {
  24062. const scope = this;
  24063. const loader = new FileLoader( scope.manager );
  24064. loader.setPath( scope.path );
  24065. loader.setRequestHeader( scope.requestHeader );
  24066. loader.setWithCredentials( scope.withCredentials );
  24067. loader.load( url, function ( text ) {
  24068. try {
  24069. onLoad( scope.parse( JSON.parse( text ) ) );
  24070. } catch ( e ) {
  24071. if ( onError ) {
  24072. onError( e );
  24073. } else {
  24074. console.error( e );
  24075. }
  24076. scope.manager.itemError( url );
  24077. }
  24078. }, onProgress, onError );
  24079. }
  24080. parse( json ) {
  24081. const textures = this.textures;
  24082. function getTexture( name ) {
  24083. if ( textures[ name ] === undefined ) {
  24084. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  24085. }
  24086. return textures[ name ];
  24087. }
  24088. const material = new Materials[ json.type ]();
  24089. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  24090. if ( json.name !== undefined ) material.name = json.name;
  24091. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  24092. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  24093. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  24094. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  24095. if ( json.sheenTint !== undefined ) material.sheenTint = new Color().setHex( json.sheenTint );
  24096. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  24097. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  24098. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  24099. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  24100. if ( json.specularTint !== undefined && material.specularTint !== undefined ) material.specularTint.setHex( json.specularTint );
  24101. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  24102. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  24103. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  24104. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  24105. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  24106. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  24107. if ( json.attenuationTint !== undefined && material.attenuationTint !== undefined ) material.attenuationTint.setHex( json.attenuationTint );
  24108. if ( json.fog !== undefined ) material.fog = json.fog;
  24109. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  24110. if ( json.blending !== undefined ) material.blending = json.blending;
  24111. if ( json.combine !== undefined ) material.combine = json.combine;
  24112. if ( json.side !== undefined ) material.side = json.side;
  24113. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  24114. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  24115. if ( json.format !== undefined ) material.format = json.format;
  24116. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  24117. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  24118. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  24119. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  24120. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  24121. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  24122. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  24123. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  24124. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  24125. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  24126. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  24127. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  24128. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  24129. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  24130. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  24131. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  24132. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  24133. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  24134. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  24135. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  24136. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  24137. if ( json.scale !== undefined ) material.scale = json.scale;
  24138. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  24139. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24140. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24141. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  24142. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  24143. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  24144. if ( json.visible !== undefined ) material.visible = json.visible;
  24145. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  24146. if ( json.userData !== undefined ) material.userData = json.userData;
  24147. if ( json.vertexColors !== undefined ) {
  24148. if ( typeof json.vertexColors === 'number' ) {
  24149. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  24150. } else {
  24151. material.vertexColors = json.vertexColors;
  24152. }
  24153. }
  24154. // Shader Material
  24155. if ( json.uniforms !== undefined ) {
  24156. for ( const name in json.uniforms ) {
  24157. const uniform = json.uniforms[ name ];
  24158. material.uniforms[ name ] = {};
  24159. switch ( uniform.type ) {
  24160. case 't':
  24161. material.uniforms[ name ].value = getTexture( uniform.value );
  24162. break;
  24163. case 'c':
  24164. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  24165. break;
  24166. case 'v2':
  24167. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  24168. break;
  24169. case 'v3':
  24170. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  24171. break;
  24172. case 'v4':
  24173. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  24174. break;
  24175. case 'm3':
  24176. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  24177. break;
  24178. case 'm4':
  24179. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  24180. break;
  24181. default:
  24182. material.uniforms[ name ].value = uniform.value;
  24183. }
  24184. }
  24185. }
  24186. if ( json.defines !== undefined ) material.defines = json.defines;
  24187. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  24188. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  24189. if ( json.extensions !== undefined ) {
  24190. for ( const key in json.extensions ) {
  24191. material.extensions[ key ] = json.extensions[ key ];
  24192. }
  24193. }
  24194. // Deprecated
  24195. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  24196. // for PointsMaterial
  24197. if ( json.size !== undefined ) material.size = json.size;
  24198. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  24199. // maps
  24200. if ( json.map !== undefined ) material.map = getTexture( json.map );
  24201. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  24202. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  24203. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  24204. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  24205. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  24206. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  24207. if ( json.normalScale !== undefined ) {
  24208. let normalScale = json.normalScale;
  24209. if ( Array.isArray( normalScale ) === false ) {
  24210. // Blender exporter used to export a scalar. See #7459
  24211. normalScale = [ normalScale, normalScale ];
  24212. }
  24213. material.normalScale = new Vector2().fromArray( normalScale );
  24214. }
  24215. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  24216. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  24217. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  24218. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  24219. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  24220. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  24221. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  24222. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  24223. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  24224. if ( json.specularTintMap !== undefined ) material.specularTintMap = getTexture( json.specularTintMap );
  24225. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  24226. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  24227. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  24228. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  24229. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  24230. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  24231. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  24232. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  24233. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  24234. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  24235. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  24236. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  24237. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  24238. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  24239. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  24240. return material;
  24241. }
  24242. setTextures( value ) {
  24243. this.textures = value;
  24244. return this;
  24245. }
  24246. }
  24247. class LoaderUtils {
  24248. static decodeText( array ) {
  24249. if ( typeof TextDecoder !== 'undefined' ) {
  24250. return new TextDecoder().decode( array );
  24251. }
  24252. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24253. // throws a "maximum call stack size exceeded" error for large arrays.
  24254. let s = '';
  24255. for ( let i = 0, il = array.length; i < il; i ++ ) {
  24256. // Implicitly assumes little-endian.
  24257. s += String.fromCharCode( array[ i ] );
  24258. }
  24259. try {
  24260. // merges multi-byte utf-8 characters.
  24261. return decodeURIComponent( escape( s ) );
  24262. } catch ( e ) { // see #16358
  24263. return s;
  24264. }
  24265. }
  24266. static extractUrlBase( url ) {
  24267. const index = url.lastIndexOf( '/' );
  24268. if ( index === - 1 ) return './';
  24269. return url.substr( 0, index + 1 );
  24270. }
  24271. }
  24272. class InstancedBufferGeometry extends BufferGeometry {
  24273. constructor() {
  24274. super();
  24275. this.type = 'InstancedBufferGeometry';
  24276. this.instanceCount = Infinity;
  24277. }
  24278. copy( source ) {
  24279. super.copy( source );
  24280. this.instanceCount = source.instanceCount;
  24281. return this;
  24282. }
  24283. clone() {
  24284. return new this.constructor().copy( this );
  24285. }
  24286. toJSON() {
  24287. const data = super.toJSON( this );
  24288. data.instanceCount = this.instanceCount;
  24289. data.isInstancedBufferGeometry = true;
  24290. return data;
  24291. }
  24292. }
  24293. InstancedBufferGeometry.prototype.isInstancedBufferGeometry = true;
  24294. class BufferGeometryLoader extends Loader {
  24295. constructor( manager ) {
  24296. super( manager );
  24297. }
  24298. load( url, onLoad, onProgress, onError ) {
  24299. const scope = this;
  24300. const loader = new FileLoader( scope.manager );
  24301. loader.setPath( scope.path );
  24302. loader.setRequestHeader( scope.requestHeader );
  24303. loader.setWithCredentials( scope.withCredentials );
  24304. loader.load( url, function ( text ) {
  24305. try {
  24306. onLoad( scope.parse( JSON.parse( text ) ) );
  24307. } catch ( e ) {
  24308. if ( onError ) {
  24309. onError( e );
  24310. } else {
  24311. console.error( e );
  24312. }
  24313. scope.manager.itemError( url );
  24314. }
  24315. }, onProgress, onError );
  24316. }
  24317. parse( json ) {
  24318. const interleavedBufferMap = {};
  24319. const arrayBufferMap = {};
  24320. function getInterleavedBuffer( json, uuid ) {
  24321. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  24322. const interleavedBuffers = json.interleavedBuffers;
  24323. const interleavedBuffer = interleavedBuffers[ uuid ];
  24324. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  24325. const array = getTypedArray( interleavedBuffer.type, buffer );
  24326. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  24327. ib.uuid = interleavedBuffer.uuid;
  24328. interleavedBufferMap[ uuid ] = ib;
  24329. return ib;
  24330. }
  24331. function getArrayBuffer( json, uuid ) {
  24332. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  24333. const arrayBuffers = json.arrayBuffers;
  24334. const arrayBuffer = arrayBuffers[ uuid ];
  24335. const ab = new Uint32Array( arrayBuffer ).buffer;
  24336. arrayBufferMap[ uuid ] = ab;
  24337. return ab;
  24338. }
  24339. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24340. const index = json.data.index;
  24341. if ( index !== undefined ) {
  24342. const typedArray = getTypedArray( index.type, index.array );
  24343. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  24344. }
  24345. const attributes = json.data.attributes;
  24346. for ( const key in attributes ) {
  24347. const attribute = attributes[ key ];
  24348. let bufferAttribute;
  24349. if ( attribute.isInterleavedBufferAttribute ) {
  24350. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24351. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24352. } else {
  24353. const typedArray = getTypedArray( attribute.type, attribute.array );
  24354. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24355. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  24356. }
  24357. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24358. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  24359. if ( attribute.updateRange !== undefined ) {
  24360. bufferAttribute.updateRange.offset = attribute.updateRange.offset;
  24361. bufferAttribute.updateRange.count = attribute.updateRange.count;
  24362. }
  24363. geometry.setAttribute( key, bufferAttribute );
  24364. }
  24365. const morphAttributes = json.data.morphAttributes;
  24366. if ( morphAttributes ) {
  24367. for ( const key in morphAttributes ) {
  24368. const attributeArray = morphAttributes[ key ];
  24369. const array = [];
  24370. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  24371. const attribute = attributeArray[ i ];
  24372. let bufferAttribute;
  24373. if ( attribute.isInterleavedBufferAttribute ) {
  24374. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24375. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24376. } else {
  24377. const typedArray = getTypedArray( attribute.type, attribute.array );
  24378. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  24379. }
  24380. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24381. array.push( bufferAttribute );
  24382. }
  24383. geometry.morphAttributes[ key ] = array;
  24384. }
  24385. }
  24386. const morphTargetsRelative = json.data.morphTargetsRelative;
  24387. if ( morphTargetsRelative ) {
  24388. geometry.morphTargetsRelative = true;
  24389. }
  24390. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24391. if ( groups !== undefined ) {
  24392. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  24393. const group = groups[ i ];
  24394. geometry.addGroup( group.start, group.count, group.materialIndex );
  24395. }
  24396. }
  24397. const boundingSphere = json.data.boundingSphere;
  24398. if ( boundingSphere !== undefined ) {
  24399. const center = new Vector3();
  24400. if ( boundingSphere.center !== undefined ) {
  24401. center.fromArray( boundingSphere.center );
  24402. }
  24403. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  24404. }
  24405. if ( json.name ) geometry.name = json.name;
  24406. if ( json.userData ) geometry.userData = json.userData;
  24407. return geometry;
  24408. }
  24409. }
  24410. class ObjectLoader extends Loader {
  24411. constructor( manager ) {
  24412. super( manager );
  24413. }
  24414. load( url, onLoad, onProgress, onError ) {
  24415. const scope = this;
  24416. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24417. this.resourcePath = this.resourcePath || path;
  24418. const loader = new FileLoader( this.manager );
  24419. loader.setPath( this.path );
  24420. loader.setRequestHeader( this.requestHeader );
  24421. loader.setWithCredentials( this.withCredentials );
  24422. loader.load( url, function ( text ) {
  24423. let json = null;
  24424. try {
  24425. json = JSON.parse( text );
  24426. } catch ( error ) {
  24427. if ( onError !== undefined ) onError( error );
  24428. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  24429. return;
  24430. }
  24431. const metadata = json.metadata;
  24432. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24433. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24434. return;
  24435. }
  24436. scope.parse( json, onLoad );
  24437. }, onProgress, onError );
  24438. }
  24439. async loadAsync( url, onProgress ) {
  24440. const scope = this;
  24441. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24442. this.resourcePath = this.resourcePath || path;
  24443. const loader = new FileLoader( this.manager );
  24444. loader.setPath( this.path );
  24445. loader.setRequestHeader( this.requestHeader );
  24446. loader.setWithCredentials( this.withCredentials );
  24447. const text = await loader.loadAsync( url, onProgress );
  24448. const json = JSON.parse( text );
  24449. const metadata = json.metadata;
  24450. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24451. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24452. }
  24453. return await scope.parseAsync( json );
  24454. }
  24455. parse( json, onLoad ) {
  24456. const animations = this.parseAnimations( json.animations );
  24457. const shapes = this.parseShapes( json.shapes );
  24458. const geometries = this.parseGeometries( json.geometries, shapes );
  24459. const images = this.parseImages( json.images, function () {
  24460. if ( onLoad !== undefined ) onLoad( object );
  24461. } );
  24462. const textures = this.parseTextures( json.textures, images );
  24463. const materials = this.parseMaterials( json.materials, textures );
  24464. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  24465. const skeletons = this.parseSkeletons( json.skeletons, object );
  24466. this.bindSkeletons( object, skeletons );
  24467. //
  24468. if ( onLoad !== undefined ) {
  24469. let hasImages = false;
  24470. for ( const uuid in images ) {
  24471. if ( images[ uuid ] instanceof HTMLImageElement ) {
  24472. hasImages = true;
  24473. break;
  24474. }
  24475. }
  24476. if ( hasImages === false ) onLoad( object );
  24477. }
  24478. return object;
  24479. }
  24480. async parseAsync( json ) {
  24481. const animations = this.parseAnimations( json.animations );
  24482. const shapes = this.parseShapes( json.shapes );
  24483. const geometries = this.parseGeometries( json.geometries, shapes );
  24484. const images = await this.parseImagesAsync( json.images );
  24485. const textures = this.parseTextures( json.textures, images );
  24486. const materials = this.parseMaterials( json.materials, textures );
  24487. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  24488. const skeletons = this.parseSkeletons( json.skeletons, object );
  24489. this.bindSkeletons( object, skeletons );
  24490. return object;
  24491. }
  24492. parseShapes( json ) {
  24493. const shapes = {};
  24494. if ( json !== undefined ) {
  24495. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24496. const shape = new Shape().fromJSON( json[ i ] );
  24497. shapes[ shape.uuid ] = shape;
  24498. }
  24499. }
  24500. return shapes;
  24501. }
  24502. parseSkeletons( json, object ) {
  24503. const skeletons = {};
  24504. const bones = {};
  24505. // generate bone lookup table
  24506. object.traverse( function ( child ) {
  24507. if ( child.isBone ) bones[ child.uuid ] = child;
  24508. } );
  24509. // create skeletons
  24510. if ( json !== undefined ) {
  24511. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24512. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  24513. skeletons[ skeleton.uuid ] = skeleton;
  24514. }
  24515. }
  24516. return skeletons;
  24517. }
  24518. parseGeometries( json, shapes ) {
  24519. const geometries = {};
  24520. if ( json !== undefined ) {
  24521. const bufferGeometryLoader = new BufferGeometryLoader();
  24522. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24523. let geometry;
  24524. const data = json[ i ];
  24525. switch ( data.type ) {
  24526. case 'BufferGeometry':
  24527. case 'InstancedBufferGeometry':
  24528. geometry = bufferGeometryLoader.parse( data );
  24529. break;
  24530. case 'Geometry':
  24531. console.error( 'THREE.ObjectLoader: The legacy Geometry type is no longer supported.' );
  24532. break;
  24533. default:
  24534. if ( data.type in Geometries ) {
  24535. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  24536. } else {
  24537. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  24538. }
  24539. }
  24540. geometry.uuid = data.uuid;
  24541. if ( data.name !== undefined ) geometry.name = data.name;
  24542. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  24543. geometries[ data.uuid ] = geometry;
  24544. }
  24545. }
  24546. return geometries;
  24547. }
  24548. parseMaterials( json, textures ) {
  24549. const cache = {}; // MultiMaterial
  24550. const materials = {};
  24551. if ( json !== undefined ) {
  24552. const loader = new MaterialLoader();
  24553. loader.setTextures( textures );
  24554. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24555. const data = json[ i ];
  24556. if ( data.type === 'MultiMaterial' ) {
  24557. // Deprecated
  24558. const array = [];
  24559. for ( let j = 0; j < data.materials.length; j ++ ) {
  24560. const material = data.materials[ j ];
  24561. if ( cache[ material.uuid ] === undefined ) {
  24562. cache[ material.uuid ] = loader.parse( material );
  24563. }
  24564. array.push( cache[ material.uuid ] );
  24565. }
  24566. materials[ data.uuid ] = array;
  24567. } else {
  24568. if ( cache[ data.uuid ] === undefined ) {
  24569. cache[ data.uuid ] = loader.parse( data );
  24570. }
  24571. materials[ data.uuid ] = cache[ data.uuid ];
  24572. }
  24573. }
  24574. }
  24575. return materials;
  24576. }
  24577. parseAnimations( json ) {
  24578. const animations = {};
  24579. if ( json !== undefined ) {
  24580. for ( let i = 0; i < json.length; i ++ ) {
  24581. const data = json[ i ];
  24582. const clip = AnimationClip.parse( data );
  24583. animations[ clip.uuid ] = clip;
  24584. }
  24585. }
  24586. return animations;
  24587. }
  24588. parseImages( json, onLoad ) {
  24589. const scope = this;
  24590. const images = {};
  24591. let loader;
  24592. function loadImage( url ) {
  24593. scope.manager.itemStart( url );
  24594. return loader.load( url, function () {
  24595. scope.manager.itemEnd( url );
  24596. }, undefined, function () {
  24597. scope.manager.itemError( url );
  24598. scope.manager.itemEnd( url );
  24599. } );
  24600. }
  24601. function deserializeImage( image ) {
  24602. if ( typeof image === 'string' ) {
  24603. const url = image;
  24604. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  24605. return loadImage( path );
  24606. } else {
  24607. if ( image.data ) {
  24608. return {
  24609. data: getTypedArray( image.type, image.data ),
  24610. width: image.width,
  24611. height: image.height
  24612. };
  24613. } else {
  24614. return null;
  24615. }
  24616. }
  24617. }
  24618. if ( json !== undefined && json.length > 0 ) {
  24619. const manager = new LoadingManager( onLoad );
  24620. loader = new ImageLoader( manager );
  24621. loader.setCrossOrigin( this.crossOrigin );
  24622. for ( let i = 0, il = json.length; i < il; i ++ ) {
  24623. const image = json[ i ];
  24624. const url = image.url;
  24625. if ( Array.isArray( url ) ) {
  24626. // load array of images e.g CubeTexture
  24627. images[ image.uuid ] = [];
  24628. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  24629. const currentUrl = url[ j ];
  24630. const deserializedImage = deserializeImage( currentUrl );
  24631. if ( deserializedImage !== null ) {
  24632. if ( deserializedImage instanceof HTMLImageElement ) {
  24633. images[ image.uuid ].push( deserializedImage );
  24634. } else {
  24635. // special case: handle array of data textures for cube textures
  24636. images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  24637. }
  24638. }
  24639. }
  24640. } else {
  24641. // load single image
  24642. const deserializedImage = deserializeImage( image.url );
  24643. if ( deserializedImage !== null ) {
  24644. images[ image.uuid ] = deserializedImage;
  24645. }
  24646. }
  24647. }
  24648. }
  24649. return images;
  24650. }
  24651. async parseImagesAsync( json ) {
  24652. const scope = this;
  24653. const images = {};
  24654. let loader;
  24655. async function deserializeImage( image ) {
  24656. if ( typeof image === 'string' ) {
  24657. const url = image;
  24658. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  24659. return await loader.loadAsync( path );
  24660. } else {
  24661. if ( image.data ) {
  24662. return {
  24663. data: getTypedArray( image.type, image.data ),
  24664. width: image.width,
  24665. height: image.height
  24666. };
  24667. } else {
  24668. return null;
  24669. }
  24670. }
  24671. }
  24672. if ( json !== undefined && json.length > 0 ) {
  24673. loader = new ImageLoader( this.manager );
  24674. loader.setCrossOrigin( this.crossOrigin );
  24675. for ( let i = 0, il = json.length; i < il; i ++ ) {
  24676. const image = json[ i ];
  24677. const url = image.url;
  24678. if ( Array.isArray( url ) ) {
  24679. // load array of images e.g CubeTexture
  24680. images[ image.uuid ] = [];
  24681. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  24682. const currentUrl = url[ j ];
  24683. const deserializedImage = await deserializeImage( currentUrl );
  24684. if ( deserializedImage !== null ) {
  24685. if ( deserializedImage instanceof HTMLImageElement ) {
  24686. images[ image.uuid ].push( deserializedImage );
  24687. } else {
  24688. // special case: handle array of data textures for cube textures
  24689. images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  24690. }
  24691. }
  24692. }
  24693. } else {
  24694. // load single image
  24695. const deserializedImage = await deserializeImage( image.url );
  24696. if ( deserializedImage !== null ) {
  24697. images[ image.uuid ] = deserializedImage;
  24698. }
  24699. }
  24700. }
  24701. }
  24702. return images;
  24703. }
  24704. parseTextures( json, images ) {
  24705. function parseConstant( value, type ) {
  24706. if ( typeof value === 'number' ) return value;
  24707. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24708. return type[ value ];
  24709. }
  24710. const textures = {};
  24711. if ( json !== undefined ) {
  24712. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24713. const data = json[ i ];
  24714. if ( data.image === undefined ) {
  24715. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24716. }
  24717. if ( images[ data.image ] === undefined ) {
  24718. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24719. }
  24720. let texture;
  24721. const image = images[ data.image ];
  24722. if ( Array.isArray( image ) ) {
  24723. texture = new CubeTexture( image );
  24724. if ( image.length === 6 ) texture.needsUpdate = true;
  24725. } else {
  24726. if ( image && image.data ) {
  24727. texture = new DataTexture( image.data, image.width, image.height );
  24728. } else {
  24729. texture = new Texture( image );
  24730. }
  24731. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  24732. }
  24733. texture.uuid = data.uuid;
  24734. if ( data.name !== undefined ) texture.name = data.name;
  24735. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24736. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24737. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24738. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24739. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24740. if ( data.wrap !== undefined ) {
  24741. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  24742. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  24743. }
  24744. if ( data.format !== undefined ) texture.format = data.format;
  24745. if ( data.type !== undefined ) texture.type = data.type;
  24746. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  24747. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  24748. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  24749. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  24750. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  24751. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  24752. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  24753. textures[ data.uuid ] = texture;
  24754. }
  24755. }
  24756. return textures;
  24757. }
  24758. parseObject( data, geometries, materials, textures, animations ) {
  24759. let object;
  24760. function getGeometry( name ) {
  24761. if ( geometries[ name ] === undefined ) {
  24762. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  24763. }
  24764. return geometries[ name ];
  24765. }
  24766. function getMaterial( name ) {
  24767. if ( name === undefined ) return undefined;
  24768. if ( Array.isArray( name ) ) {
  24769. const array = [];
  24770. for ( let i = 0, l = name.length; i < l; i ++ ) {
  24771. const uuid = name[ i ];
  24772. if ( materials[ uuid ] === undefined ) {
  24773. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  24774. }
  24775. array.push( materials[ uuid ] );
  24776. }
  24777. return array;
  24778. }
  24779. if ( materials[ name ] === undefined ) {
  24780. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  24781. }
  24782. return materials[ name ];
  24783. }
  24784. function getTexture( uuid ) {
  24785. if ( textures[ uuid ] === undefined ) {
  24786. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  24787. }
  24788. return textures[ uuid ];
  24789. }
  24790. let geometry, material;
  24791. switch ( data.type ) {
  24792. case 'Scene':
  24793. object = new Scene();
  24794. if ( data.background !== undefined ) {
  24795. if ( Number.isInteger( data.background ) ) {
  24796. object.background = new Color( data.background );
  24797. } else {
  24798. object.background = getTexture( data.background );
  24799. }
  24800. }
  24801. if ( data.environment !== undefined ) {
  24802. object.environment = getTexture( data.environment );
  24803. }
  24804. if ( data.fog !== undefined ) {
  24805. if ( data.fog.type === 'Fog' ) {
  24806. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  24807. } else if ( data.fog.type === 'FogExp2' ) {
  24808. object.fog = new FogExp2( data.fog.color, data.fog.density );
  24809. }
  24810. }
  24811. break;
  24812. case 'PerspectiveCamera':
  24813. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  24814. if ( data.focus !== undefined ) object.focus = data.focus;
  24815. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24816. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  24817. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  24818. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24819. break;
  24820. case 'OrthographicCamera':
  24821. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  24822. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24823. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24824. break;
  24825. case 'AmbientLight':
  24826. object = new AmbientLight( data.color, data.intensity );
  24827. break;
  24828. case 'DirectionalLight':
  24829. object = new DirectionalLight( data.color, data.intensity );
  24830. break;
  24831. case 'PointLight':
  24832. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  24833. break;
  24834. case 'RectAreaLight':
  24835. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  24836. break;
  24837. case 'SpotLight':
  24838. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  24839. break;
  24840. case 'HemisphereLight':
  24841. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  24842. break;
  24843. case 'LightProbe':
  24844. object = new LightProbe().fromJSON( data );
  24845. break;
  24846. case 'SkinnedMesh':
  24847. geometry = getGeometry( data.geometry );
  24848. material = getMaterial( data.material );
  24849. object = new SkinnedMesh( geometry, material );
  24850. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  24851. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  24852. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  24853. break;
  24854. case 'Mesh':
  24855. geometry = getGeometry( data.geometry );
  24856. material = getMaterial( data.material );
  24857. object = new Mesh( geometry, material );
  24858. break;
  24859. case 'InstancedMesh':
  24860. geometry = getGeometry( data.geometry );
  24861. material = getMaterial( data.material );
  24862. const count = data.count;
  24863. const instanceMatrix = data.instanceMatrix;
  24864. const instanceColor = data.instanceColor;
  24865. object = new InstancedMesh( geometry, material, count );
  24866. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  24867. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  24868. break;
  24869. case 'LOD':
  24870. object = new LOD();
  24871. break;
  24872. case 'Line':
  24873. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  24874. break;
  24875. case 'LineLoop':
  24876. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  24877. break;
  24878. case 'LineSegments':
  24879. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  24880. break;
  24881. case 'PointCloud':
  24882. case 'Points':
  24883. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  24884. break;
  24885. case 'Sprite':
  24886. object = new Sprite( getMaterial( data.material ) );
  24887. break;
  24888. case 'Group':
  24889. object = new Group();
  24890. break;
  24891. case 'Bone':
  24892. object = new Bone();
  24893. break;
  24894. default:
  24895. object = new Object3D();
  24896. }
  24897. object.uuid = data.uuid;
  24898. if ( data.name !== undefined ) object.name = data.name;
  24899. if ( data.matrix !== undefined ) {
  24900. object.matrix.fromArray( data.matrix );
  24901. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24902. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  24903. } else {
  24904. if ( data.position !== undefined ) object.position.fromArray( data.position );
  24905. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  24906. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  24907. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  24908. }
  24909. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  24910. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  24911. if ( data.shadow ) {
  24912. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  24913. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  24914. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  24915. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  24916. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  24917. }
  24918. if ( data.visible !== undefined ) object.visible = data.visible;
  24919. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  24920. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  24921. if ( data.userData !== undefined ) object.userData = data.userData;
  24922. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  24923. if ( data.children !== undefined ) {
  24924. const children = data.children;
  24925. for ( let i = 0; i < children.length; i ++ ) {
  24926. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  24927. }
  24928. }
  24929. if ( data.animations !== undefined ) {
  24930. const objectAnimations = data.animations;
  24931. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  24932. const uuid = objectAnimations[ i ];
  24933. object.animations.push( animations[ uuid ] );
  24934. }
  24935. }
  24936. if ( data.type === 'LOD' ) {
  24937. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  24938. const levels = data.levels;
  24939. for ( let l = 0; l < levels.length; l ++ ) {
  24940. const level = levels[ l ];
  24941. const child = object.getObjectByProperty( 'uuid', level.object );
  24942. if ( child !== undefined ) {
  24943. object.addLevel( child, level.distance );
  24944. }
  24945. }
  24946. }
  24947. return object;
  24948. }
  24949. bindSkeletons( object, skeletons ) {
  24950. if ( Object.keys( skeletons ).length === 0 ) return;
  24951. object.traverse( function ( child ) {
  24952. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  24953. const skeleton = skeletons[ child.skeleton ];
  24954. if ( skeleton === undefined ) {
  24955. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  24956. } else {
  24957. child.bind( skeleton, child.bindMatrix );
  24958. }
  24959. }
  24960. } );
  24961. }
  24962. /* DEPRECATED */
  24963. setTexturePath( value ) {
  24964. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  24965. return this.setResourcePath( value );
  24966. }
  24967. }
  24968. const TEXTURE_MAPPING = {
  24969. UVMapping: UVMapping,
  24970. CubeReflectionMapping: CubeReflectionMapping,
  24971. CubeRefractionMapping: CubeRefractionMapping,
  24972. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24973. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24974. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24975. CubeUVRefractionMapping: CubeUVRefractionMapping
  24976. };
  24977. const TEXTURE_WRAPPING = {
  24978. RepeatWrapping: RepeatWrapping,
  24979. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24980. MirroredRepeatWrapping: MirroredRepeatWrapping
  24981. };
  24982. const TEXTURE_FILTER = {
  24983. NearestFilter: NearestFilter,
  24984. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24985. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24986. LinearFilter: LinearFilter,
  24987. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24988. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24989. };
  24990. class ImageBitmapLoader extends Loader {
  24991. constructor( manager ) {
  24992. super( manager );
  24993. if ( typeof createImageBitmap === 'undefined' ) {
  24994. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  24995. }
  24996. if ( typeof fetch === 'undefined' ) {
  24997. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  24998. }
  24999. this.options = { premultiplyAlpha: 'none' };
  25000. }
  25001. setOptions( options ) {
  25002. this.options = options;
  25003. return this;
  25004. }
  25005. load( url, onLoad, onProgress, onError ) {
  25006. if ( url === undefined ) url = '';
  25007. if ( this.path !== undefined ) url = this.path + url;
  25008. url = this.manager.resolveURL( url );
  25009. const scope = this;
  25010. const cached = Cache.get( url );
  25011. if ( cached !== undefined ) {
  25012. scope.manager.itemStart( url );
  25013. setTimeout( function () {
  25014. if ( onLoad ) onLoad( cached );
  25015. scope.manager.itemEnd( url );
  25016. }, 0 );
  25017. return cached;
  25018. }
  25019. const fetchOptions = {};
  25020. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  25021. fetchOptions.headers = this.requestHeader;
  25022. fetch( url, fetchOptions ).then( function ( res ) {
  25023. return res.blob();
  25024. } ).then( function ( blob ) {
  25025. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  25026. } ).then( function ( imageBitmap ) {
  25027. Cache.add( url, imageBitmap );
  25028. if ( onLoad ) onLoad( imageBitmap );
  25029. scope.manager.itemEnd( url );
  25030. } ).catch( function ( e ) {
  25031. if ( onError ) onError( e );
  25032. scope.manager.itemError( url );
  25033. scope.manager.itemEnd( url );
  25034. } );
  25035. scope.manager.itemStart( url );
  25036. }
  25037. }
  25038. ImageBitmapLoader.prototype.isImageBitmapLoader = true;
  25039. class ShapePath {
  25040. constructor() {
  25041. this.type = 'ShapePath';
  25042. this.color = new Color();
  25043. this.subPaths = [];
  25044. this.currentPath = null;
  25045. }
  25046. moveTo( x, y ) {
  25047. this.currentPath = new Path();
  25048. this.subPaths.push( this.currentPath );
  25049. this.currentPath.moveTo( x, y );
  25050. return this;
  25051. }
  25052. lineTo( x, y ) {
  25053. this.currentPath.lineTo( x, y );
  25054. return this;
  25055. }
  25056. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  25057. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  25058. return this;
  25059. }
  25060. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  25061. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  25062. return this;
  25063. }
  25064. splineThru( pts ) {
  25065. this.currentPath.splineThru( pts );
  25066. return this;
  25067. }
  25068. toShapes( isCCW, noHoles ) {
  25069. function toShapesNoHoles( inSubpaths ) {
  25070. const shapes = [];
  25071. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  25072. const tmpPath = inSubpaths[ i ];
  25073. const tmpShape = new Shape();
  25074. tmpShape.curves = tmpPath.curves;
  25075. shapes.push( tmpShape );
  25076. }
  25077. return shapes;
  25078. }
  25079. function isPointInsidePolygon( inPt, inPolygon ) {
  25080. const polyLen = inPolygon.length;
  25081. // inPt on polygon contour => immediate success or
  25082. // toggling of inside/outside at every single! intersection point of an edge
  25083. // with the horizontal line through inPt, left of inPt
  25084. // not counting lowerY endpoints of edges and whole edges on that line
  25085. let inside = false;
  25086. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  25087. let edgeLowPt = inPolygon[ p ];
  25088. let edgeHighPt = inPolygon[ q ];
  25089. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  25090. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  25091. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  25092. // not parallel
  25093. if ( edgeDy < 0 ) {
  25094. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  25095. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  25096. }
  25097. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  25098. if ( inPt.y === edgeLowPt.y ) {
  25099. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  25100. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25101. } else {
  25102. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  25103. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  25104. if ( perpEdge < 0 ) continue;
  25105. inside = ! inside; // true intersection left of inPt
  25106. }
  25107. } else {
  25108. // parallel or collinear
  25109. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  25110. // edge lies on the same horizontal line as inPt
  25111. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  25112. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  25113. // continue;
  25114. }
  25115. }
  25116. return inside;
  25117. }
  25118. const isClockWise = ShapeUtils.isClockWise;
  25119. const subPaths = this.subPaths;
  25120. if ( subPaths.length === 0 ) return [];
  25121. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  25122. let solid, tmpPath, tmpShape;
  25123. const shapes = [];
  25124. if ( subPaths.length === 1 ) {
  25125. tmpPath = subPaths[ 0 ];
  25126. tmpShape = new Shape();
  25127. tmpShape.curves = tmpPath.curves;
  25128. shapes.push( tmpShape );
  25129. return shapes;
  25130. }
  25131. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  25132. holesFirst = isCCW ? ! holesFirst : holesFirst;
  25133. // console.log("Holes first", holesFirst);
  25134. const betterShapeHoles = [];
  25135. const newShapes = [];
  25136. let newShapeHoles = [];
  25137. let mainIdx = 0;
  25138. let tmpPoints;
  25139. newShapes[ mainIdx ] = undefined;
  25140. newShapeHoles[ mainIdx ] = [];
  25141. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  25142. tmpPath = subPaths[ i ];
  25143. tmpPoints = tmpPath.getPoints();
  25144. solid = isClockWise( tmpPoints );
  25145. solid = isCCW ? ! solid : solid;
  25146. if ( solid ) {
  25147. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  25148. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  25149. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  25150. if ( holesFirst ) mainIdx ++;
  25151. newShapeHoles[ mainIdx ] = [];
  25152. //console.log('cw', i);
  25153. } else {
  25154. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  25155. //console.log('ccw', i);
  25156. }
  25157. }
  25158. // only Holes? -> probably all Shapes with wrong orientation
  25159. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  25160. if ( newShapes.length > 1 ) {
  25161. let ambiguous = false;
  25162. const toChange = [];
  25163. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25164. betterShapeHoles[ sIdx ] = [];
  25165. }
  25166. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25167. const sho = newShapeHoles[ sIdx ];
  25168. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  25169. const ho = sho[ hIdx ];
  25170. let hole_unassigned = true;
  25171. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  25172. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  25173. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  25174. if ( hole_unassigned ) {
  25175. hole_unassigned = false;
  25176. betterShapeHoles[ s2Idx ].push( ho );
  25177. } else {
  25178. ambiguous = true;
  25179. }
  25180. }
  25181. }
  25182. if ( hole_unassigned ) {
  25183. betterShapeHoles[ sIdx ].push( ho );
  25184. }
  25185. }
  25186. }
  25187. // console.log("ambiguous: ", ambiguous);
  25188. if ( toChange.length > 0 ) {
  25189. // console.log("to change: ", toChange);
  25190. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  25191. }
  25192. }
  25193. let tmpHoles;
  25194. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  25195. tmpShape = newShapes[ i ].s;
  25196. shapes.push( tmpShape );
  25197. tmpHoles = newShapeHoles[ i ];
  25198. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  25199. tmpShape.holes.push( tmpHoles[ j ].h );
  25200. }
  25201. }
  25202. //console.log("shape", shapes);
  25203. return shapes;
  25204. }
  25205. }
  25206. class Font {
  25207. constructor( data ) {
  25208. this.type = 'Font';
  25209. this.data = data;
  25210. }
  25211. generateShapes( text, size = 100 ) {
  25212. const shapes = [];
  25213. const paths = createPaths( text, size, this.data );
  25214. for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
  25215. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  25216. }
  25217. return shapes;
  25218. }
  25219. }
  25220. function createPaths( text, size, data ) {
  25221. const chars = Array.from( text );
  25222. const scale = size / data.resolution;
  25223. const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  25224. const paths = [];
  25225. let offsetX = 0, offsetY = 0;
  25226. for ( let i = 0; i < chars.length; i ++ ) {
  25227. const char = chars[ i ];
  25228. if ( char === '\n' ) {
  25229. offsetX = 0;
  25230. offsetY -= line_height;
  25231. } else {
  25232. const ret = createPath( char, scale, offsetX, offsetY, data );
  25233. offsetX += ret.offsetX;
  25234. paths.push( ret.path );
  25235. }
  25236. }
  25237. return paths;
  25238. }
  25239. function createPath( char, scale, offsetX, offsetY, data ) {
  25240. const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  25241. if ( ! glyph ) {
  25242. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  25243. return;
  25244. }
  25245. const path = new ShapePath();
  25246. let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25247. if ( glyph.o ) {
  25248. const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  25249. for ( let i = 0, l = outline.length; i < l; ) {
  25250. const action = outline[ i ++ ];
  25251. switch ( action ) {
  25252. case 'm': // moveTo
  25253. x = outline[ i ++ ] * scale + offsetX;
  25254. y = outline[ i ++ ] * scale + offsetY;
  25255. path.moveTo( x, y );
  25256. break;
  25257. case 'l': // lineTo
  25258. x = outline[ i ++ ] * scale + offsetX;
  25259. y = outline[ i ++ ] * scale + offsetY;
  25260. path.lineTo( x, y );
  25261. break;
  25262. case 'q': // quadraticCurveTo
  25263. cpx = outline[ i ++ ] * scale + offsetX;
  25264. cpy = outline[ i ++ ] * scale + offsetY;
  25265. cpx1 = outline[ i ++ ] * scale + offsetX;
  25266. cpy1 = outline[ i ++ ] * scale + offsetY;
  25267. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  25268. break;
  25269. case 'b': // bezierCurveTo
  25270. cpx = outline[ i ++ ] * scale + offsetX;
  25271. cpy = outline[ i ++ ] * scale + offsetY;
  25272. cpx1 = outline[ i ++ ] * scale + offsetX;
  25273. cpy1 = outline[ i ++ ] * scale + offsetY;
  25274. cpx2 = outline[ i ++ ] * scale + offsetX;
  25275. cpy2 = outline[ i ++ ] * scale + offsetY;
  25276. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  25277. break;
  25278. }
  25279. }
  25280. }
  25281. return { offsetX: glyph.ha * scale, path: path };
  25282. }
  25283. Font.prototype.isFont = true;
  25284. class FontLoader extends Loader {
  25285. constructor( manager ) {
  25286. super( manager );
  25287. }
  25288. load( url, onLoad, onProgress, onError ) {
  25289. const scope = this;
  25290. const loader = new FileLoader( this.manager );
  25291. loader.setPath( this.path );
  25292. loader.setRequestHeader( this.requestHeader );
  25293. loader.setWithCredentials( scope.withCredentials );
  25294. loader.load( url, function ( text ) {
  25295. let json;
  25296. try {
  25297. json = JSON.parse( text );
  25298. } catch ( e ) {
  25299. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  25300. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  25301. }
  25302. const font = scope.parse( json );
  25303. if ( onLoad ) onLoad( font );
  25304. }, onProgress, onError );
  25305. }
  25306. parse( json ) {
  25307. return new Font( json );
  25308. }
  25309. }
  25310. let _context;
  25311. const AudioContext = {
  25312. getContext: function () {
  25313. if ( _context === undefined ) {
  25314. _context = new ( window.AudioContext || window.webkitAudioContext )();
  25315. }
  25316. return _context;
  25317. },
  25318. setContext: function ( value ) {
  25319. _context = value;
  25320. }
  25321. };
  25322. class AudioLoader extends Loader {
  25323. constructor( manager ) {
  25324. super( manager );
  25325. }
  25326. load( url, onLoad, onProgress, onError ) {
  25327. const scope = this;
  25328. const loader = new FileLoader( this.manager );
  25329. loader.setResponseType( 'arraybuffer' );
  25330. loader.setPath( this.path );
  25331. loader.setRequestHeader( this.requestHeader );
  25332. loader.setWithCredentials( this.withCredentials );
  25333. loader.load( url, function ( buffer ) {
  25334. try {
  25335. // Create a copy of the buffer. The `decodeAudioData` method
  25336. // detaches the buffer when complete, preventing reuse.
  25337. const bufferCopy = buffer.slice( 0 );
  25338. const context = AudioContext.getContext();
  25339. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25340. onLoad( audioBuffer );
  25341. } );
  25342. } catch ( e ) {
  25343. if ( onError ) {
  25344. onError( e );
  25345. } else {
  25346. console.error( e );
  25347. }
  25348. scope.manager.itemError( url );
  25349. }
  25350. }, onProgress, onError );
  25351. }
  25352. }
  25353. class HemisphereLightProbe extends LightProbe {
  25354. constructor( skyColor, groundColor, intensity = 1 ) {
  25355. super( undefined, intensity );
  25356. const color1 = new Color().set( skyColor );
  25357. const color2 = new Color().set( groundColor );
  25358. const sky = new Vector3( color1.r, color1.g, color1.b );
  25359. const ground = new Vector3( color2.r, color2.g, color2.b );
  25360. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25361. const c0 = Math.sqrt( Math.PI );
  25362. const c1 = c0 * Math.sqrt( 0.75 );
  25363. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25364. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25365. }
  25366. }
  25367. HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
  25368. class AmbientLightProbe extends LightProbe {
  25369. constructor( color, intensity = 1 ) {
  25370. super( undefined, intensity );
  25371. const color1 = new Color().set( color );
  25372. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25373. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25374. }
  25375. }
  25376. AmbientLightProbe.prototype.isAmbientLightProbe = true;
  25377. const _eyeRight = /*@__PURE__*/ new Matrix4();
  25378. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  25379. class StereoCamera {
  25380. constructor() {
  25381. this.type = 'StereoCamera';
  25382. this.aspect = 1;
  25383. this.eyeSep = 0.064;
  25384. this.cameraL = new PerspectiveCamera();
  25385. this.cameraL.layers.enable( 1 );
  25386. this.cameraL.matrixAutoUpdate = false;
  25387. this.cameraR = new PerspectiveCamera();
  25388. this.cameraR.layers.enable( 2 );
  25389. this.cameraR.matrixAutoUpdate = false;
  25390. this._cache = {
  25391. focus: null,
  25392. fov: null,
  25393. aspect: null,
  25394. near: null,
  25395. far: null,
  25396. zoom: null,
  25397. eyeSep: null
  25398. };
  25399. }
  25400. update( camera ) {
  25401. const cache = this._cache;
  25402. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  25403. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  25404. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25405. if ( needsUpdate ) {
  25406. cache.focus = camera.focus;
  25407. cache.fov = camera.fov;
  25408. cache.aspect = camera.aspect * this.aspect;
  25409. cache.near = camera.near;
  25410. cache.far = camera.far;
  25411. cache.zoom = camera.zoom;
  25412. cache.eyeSep = this.eyeSep;
  25413. // Off-axis stereoscopic effect based on
  25414. // http://paulbourke.net/stereographics/stereorender/
  25415. const projectionMatrix = camera.projectionMatrix.clone();
  25416. const eyeSepHalf = cache.eyeSep / 2;
  25417. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25418. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  25419. let xmin, xmax;
  25420. // translate xOffset
  25421. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  25422. _eyeRight.elements[ 12 ] = eyeSepHalf;
  25423. // for left eye
  25424. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  25425. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25426. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25427. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25428. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25429. // for right eye
  25430. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  25431. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25432. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25433. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25434. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25435. }
  25436. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  25437. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  25438. }
  25439. }
  25440. class Clock {
  25441. constructor( autoStart = true ) {
  25442. this.autoStart = autoStart;
  25443. this.startTime = 0;
  25444. this.oldTime = 0;
  25445. this.elapsedTime = 0;
  25446. this.running = false;
  25447. }
  25448. start() {
  25449. this.startTime = now();
  25450. this.oldTime = this.startTime;
  25451. this.elapsedTime = 0;
  25452. this.running = true;
  25453. }
  25454. stop() {
  25455. this.getElapsedTime();
  25456. this.running = false;
  25457. this.autoStart = false;
  25458. }
  25459. getElapsedTime() {
  25460. this.getDelta();
  25461. return this.elapsedTime;
  25462. }
  25463. getDelta() {
  25464. let diff = 0;
  25465. if ( this.autoStart && ! this.running ) {
  25466. this.start();
  25467. return 0;
  25468. }
  25469. if ( this.running ) {
  25470. const newTime = now();
  25471. diff = ( newTime - this.oldTime ) / 1000;
  25472. this.oldTime = newTime;
  25473. this.elapsedTime += diff;
  25474. }
  25475. return diff;
  25476. }
  25477. }
  25478. function now() {
  25479. return ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25480. }
  25481. const _position$1 = /*@__PURE__*/ new Vector3();
  25482. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  25483. const _scale$1 = /*@__PURE__*/ new Vector3();
  25484. const _orientation$1 = /*@__PURE__*/ new Vector3();
  25485. class AudioListener extends Object3D {
  25486. constructor() {
  25487. super();
  25488. this.type = 'AudioListener';
  25489. this.context = AudioContext.getContext();
  25490. this.gain = this.context.createGain();
  25491. this.gain.connect( this.context.destination );
  25492. this.filter = null;
  25493. this.timeDelta = 0;
  25494. // private
  25495. this._clock = new Clock();
  25496. }
  25497. getInput() {
  25498. return this.gain;
  25499. }
  25500. removeFilter() {
  25501. if ( this.filter !== null ) {
  25502. this.gain.disconnect( this.filter );
  25503. this.filter.disconnect( this.context.destination );
  25504. this.gain.connect( this.context.destination );
  25505. this.filter = null;
  25506. }
  25507. return this;
  25508. }
  25509. getFilter() {
  25510. return this.filter;
  25511. }
  25512. setFilter( value ) {
  25513. if ( this.filter !== null ) {
  25514. this.gain.disconnect( this.filter );
  25515. this.filter.disconnect( this.context.destination );
  25516. } else {
  25517. this.gain.disconnect( this.context.destination );
  25518. }
  25519. this.filter = value;
  25520. this.gain.connect( this.filter );
  25521. this.filter.connect( this.context.destination );
  25522. return this;
  25523. }
  25524. getMasterVolume() {
  25525. return this.gain.gain.value;
  25526. }
  25527. setMasterVolume( value ) {
  25528. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25529. return this;
  25530. }
  25531. updateMatrixWorld( force ) {
  25532. super.updateMatrixWorld( force );
  25533. const listener = this.context.listener;
  25534. const up = this.up;
  25535. this.timeDelta = this._clock.getDelta();
  25536. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  25537. _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 );
  25538. if ( listener.positionX ) {
  25539. // code path for Chrome (see #14393)
  25540. const endTime = this.context.currentTime + this.timeDelta;
  25541. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  25542. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  25543. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  25544. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  25545. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  25546. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  25547. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25548. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25549. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25550. } else {
  25551. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  25552. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  25553. }
  25554. }
  25555. }
  25556. class Audio extends Object3D {
  25557. constructor( listener ) {
  25558. super();
  25559. this.type = 'Audio';
  25560. this.listener = listener;
  25561. this.context = listener.context;
  25562. this.gain = this.context.createGain();
  25563. this.gain.connect( listener.getInput() );
  25564. this.autoplay = false;
  25565. this.buffer = null;
  25566. this.detune = 0;
  25567. this.loop = false;
  25568. this.loopStart = 0;
  25569. this.loopEnd = 0;
  25570. this.offset = 0;
  25571. this.duration = undefined;
  25572. this.playbackRate = 1;
  25573. this.isPlaying = false;
  25574. this.hasPlaybackControl = true;
  25575. this.source = null;
  25576. this.sourceType = 'empty';
  25577. this._startedAt = 0;
  25578. this._progress = 0;
  25579. this._connected = false;
  25580. this.filters = [];
  25581. }
  25582. getOutput() {
  25583. return this.gain;
  25584. }
  25585. setNodeSource( audioNode ) {
  25586. this.hasPlaybackControl = false;
  25587. this.sourceType = 'audioNode';
  25588. this.source = audioNode;
  25589. this.connect();
  25590. return this;
  25591. }
  25592. setMediaElementSource( mediaElement ) {
  25593. this.hasPlaybackControl = false;
  25594. this.sourceType = 'mediaNode';
  25595. this.source = this.context.createMediaElementSource( mediaElement );
  25596. this.connect();
  25597. return this;
  25598. }
  25599. setMediaStreamSource( mediaStream ) {
  25600. this.hasPlaybackControl = false;
  25601. this.sourceType = 'mediaStreamNode';
  25602. this.source = this.context.createMediaStreamSource( mediaStream );
  25603. this.connect();
  25604. return this;
  25605. }
  25606. setBuffer( audioBuffer ) {
  25607. this.buffer = audioBuffer;
  25608. this.sourceType = 'buffer';
  25609. if ( this.autoplay ) this.play();
  25610. return this;
  25611. }
  25612. play( delay = 0 ) {
  25613. if ( this.isPlaying === true ) {
  25614. console.warn( 'THREE.Audio: Audio is already playing.' );
  25615. return;
  25616. }
  25617. if ( this.hasPlaybackControl === false ) {
  25618. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25619. return;
  25620. }
  25621. this._startedAt = this.context.currentTime + delay;
  25622. const source = this.context.createBufferSource();
  25623. source.buffer = this.buffer;
  25624. source.loop = this.loop;
  25625. source.loopStart = this.loopStart;
  25626. source.loopEnd = this.loopEnd;
  25627. source.onended = this.onEnded.bind( this );
  25628. source.start( this._startedAt, this._progress + this.offset, this.duration );
  25629. this.isPlaying = true;
  25630. this.source = source;
  25631. this.setDetune( this.detune );
  25632. this.setPlaybackRate( this.playbackRate );
  25633. return this.connect();
  25634. }
  25635. pause() {
  25636. if ( this.hasPlaybackControl === false ) {
  25637. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25638. return;
  25639. }
  25640. if ( this.isPlaying === true ) {
  25641. // update current progress
  25642. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  25643. if ( this.loop === true ) {
  25644. // ensure _progress does not exceed duration with looped audios
  25645. this._progress = this._progress % ( this.duration || this.buffer.duration );
  25646. }
  25647. this.source.stop();
  25648. this.source.onended = null;
  25649. this.isPlaying = false;
  25650. }
  25651. return this;
  25652. }
  25653. stop() {
  25654. if ( this.hasPlaybackControl === false ) {
  25655. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25656. return;
  25657. }
  25658. this._progress = 0;
  25659. this.source.stop();
  25660. this.source.onended = null;
  25661. this.isPlaying = false;
  25662. return this;
  25663. }
  25664. connect() {
  25665. if ( this.filters.length > 0 ) {
  25666. this.source.connect( this.filters[ 0 ] );
  25667. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25668. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25669. }
  25670. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25671. } else {
  25672. this.source.connect( this.getOutput() );
  25673. }
  25674. this._connected = true;
  25675. return this;
  25676. }
  25677. disconnect() {
  25678. if ( this.filters.length > 0 ) {
  25679. this.source.disconnect( this.filters[ 0 ] );
  25680. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25681. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25682. }
  25683. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25684. } else {
  25685. this.source.disconnect( this.getOutput() );
  25686. }
  25687. this._connected = false;
  25688. return this;
  25689. }
  25690. getFilters() {
  25691. return this.filters;
  25692. }
  25693. setFilters( value ) {
  25694. if ( ! value ) value = [];
  25695. if ( this._connected === true ) {
  25696. this.disconnect();
  25697. this.filters = value.slice();
  25698. this.connect();
  25699. } else {
  25700. this.filters = value.slice();
  25701. }
  25702. return this;
  25703. }
  25704. setDetune( value ) {
  25705. this.detune = value;
  25706. if ( this.source.detune === undefined ) return; // only set detune when available
  25707. if ( this.isPlaying === true ) {
  25708. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25709. }
  25710. return this;
  25711. }
  25712. getDetune() {
  25713. return this.detune;
  25714. }
  25715. getFilter() {
  25716. return this.getFilters()[ 0 ];
  25717. }
  25718. setFilter( filter ) {
  25719. return this.setFilters( filter ? [ filter ] : [] );
  25720. }
  25721. setPlaybackRate( value ) {
  25722. if ( this.hasPlaybackControl === false ) {
  25723. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25724. return;
  25725. }
  25726. this.playbackRate = value;
  25727. if ( this.isPlaying === true ) {
  25728. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25729. }
  25730. return this;
  25731. }
  25732. getPlaybackRate() {
  25733. return this.playbackRate;
  25734. }
  25735. onEnded() {
  25736. this.isPlaying = false;
  25737. }
  25738. getLoop() {
  25739. if ( this.hasPlaybackControl === false ) {
  25740. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25741. return false;
  25742. }
  25743. return this.loop;
  25744. }
  25745. setLoop( value ) {
  25746. if ( this.hasPlaybackControl === false ) {
  25747. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25748. return;
  25749. }
  25750. this.loop = value;
  25751. if ( this.isPlaying === true ) {
  25752. this.source.loop = this.loop;
  25753. }
  25754. return this;
  25755. }
  25756. setLoopStart( value ) {
  25757. this.loopStart = value;
  25758. return this;
  25759. }
  25760. setLoopEnd( value ) {
  25761. this.loopEnd = value;
  25762. return this;
  25763. }
  25764. getVolume() {
  25765. return this.gain.gain.value;
  25766. }
  25767. setVolume( value ) {
  25768. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25769. return this;
  25770. }
  25771. }
  25772. const _position = /*@__PURE__*/ new Vector3();
  25773. const _quaternion = /*@__PURE__*/ new Quaternion();
  25774. const _scale = /*@__PURE__*/ new Vector3();
  25775. const _orientation = /*@__PURE__*/ new Vector3();
  25776. class PositionalAudio extends Audio {
  25777. constructor( listener ) {
  25778. super( listener );
  25779. this.panner = this.context.createPanner();
  25780. this.panner.panningModel = 'HRTF';
  25781. this.panner.connect( this.gain );
  25782. }
  25783. getOutput() {
  25784. return this.panner;
  25785. }
  25786. getRefDistance() {
  25787. return this.panner.refDistance;
  25788. }
  25789. setRefDistance( value ) {
  25790. this.panner.refDistance = value;
  25791. return this;
  25792. }
  25793. getRolloffFactor() {
  25794. return this.panner.rolloffFactor;
  25795. }
  25796. setRolloffFactor( value ) {
  25797. this.panner.rolloffFactor = value;
  25798. return this;
  25799. }
  25800. getDistanceModel() {
  25801. return this.panner.distanceModel;
  25802. }
  25803. setDistanceModel( value ) {
  25804. this.panner.distanceModel = value;
  25805. return this;
  25806. }
  25807. getMaxDistance() {
  25808. return this.panner.maxDistance;
  25809. }
  25810. setMaxDistance( value ) {
  25811. this.panner.maxDistance = value;
  25812. return this;
  25813. }
  25814. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  25815. this.panner.coneInnerAngle = coneInnerAngle;
  25816. this.panner.coneOuterAngle = coneOuterAngle;
  25817. this.panner.coneOuterGain = coneOuterGain;
  25818. return this;
  25819. }
  25820. updateMatrixWorld( force ) {
  25821. super.updateMatrixWorld( force );
  25822. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  25823. this.matrixWorld.decompose( _position, _quaternion, _scale );
  25824. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  25825. const panner = this.panner;
  25826. if ( panner.positionX ) {
  25827. // code path for Chrome and Firefox (see #14393)
  25828. const endTime = this.context.currentTime + this.listener.timeDelta;
  25829. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  25830. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  25831. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  25832. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  25833. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  25834. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  25835. } else {
  25836. panner.setPosition( _position.x, _position.y, _position.z );
  25837. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  25838. }
  25839. }
  25840. }
  25841. class AudioAnalyser {
  25842. constructor( audio, fftSize = 2048 ) {
  25843. this.analyser = audio.context.createAnalyser();
  25844. this.analyser.fftSize = fftSize;
  25845. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25846. audio.getOutput().connect( this.analyser );
  25847. }
  25848. getFrequencyData() {
  25849. this.analyser.getByteFrequencyData( this.data );
  25850. return this.data;
  25851. }
  25852. getAverageFrequency() {
  25853. let value = 0;
  25854. const data = this.getFrequencyData();
  25855. for ( let i = 0; i < data.length; i ++ ) {
  25856. value += data[ i ];
  25857. }
  25858. return value / data.length;
  25859. }
  25860. }
  25861. class PropertyMixer {
  25862. constructor( binding, typeName, valueSize ) {
  25863. this.binding = binding;
  25864. this.valueSize = valueSize;
  25865. let mixFunction,
  25866. mixFunctionAdditive,
  25867. setIdentity;
  25868. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25869. //
  25870. // interpolators can use .buffer as their .result
  25871. // the data then goes to 'incoming'
  25872. //
  25873. // 'accu0' and 'accu1' are used frame-interleaved for
  25874. // the cumulative result and are compared to detect
  25875. // changes
  25876. //
  25877. // 'orig' stores the original state of the property
  25878. //
  25879. // 'add' is used for additive cumulative results
  25880. //
  25881. // 'work' is optional and is only present for quaternion types. It is used
  25882. // to store intermediate quaternion multiplication results
  25883. switch ( typeName ) {
  25884. case 'quaternion':
  25885. mixFunction = this._slerp;
  25886. mixFunctionAdditive = this._slerpAdditive;
  25887. setIdentity = this._setAdditiveIdentityQuaternion;
  25888. this.buffer = new Float64Array( valueSize * 6 );
  25889. this._workIndex = 5;
  25890. break;
  25891. case 'string':
  25892. case 'bool':
  25893. mixFunction = this._select;
  25894. // Use the regular mix function and for additive on these types,
  25895. // additive is not relevant for non-numeric types
  25896. mixFunctionAdditive = this._select;
  25897. setIdentity = this._setAdditiveIdentityOther;
  25898. this.buffer = new Array( valueSize * 5 );
  25899. break;
  25900. default:
  25901. mixFunction = this._lerp;
  25902. mixFunctionAdditive = this._lerpAdditive;
  25903. setIdentity = this._setAdditiveIdentityNumeric;
  25904. this.buffer = new Float64Array( valueSize * 5 );
  25905. }
  25906. this._mixBufferRegion = mixFunction;
  25907. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25908. this._setIdentity = setIdentity;
  25909. this._origIndex = 3;
  25910. this._addIndex = 4;
  25911. this.cumulativeWeight = 0;
  25912. this.cumulativeWeightAdditive = 0;
  25913. this.useCount = 0;
  25914. this.referenceCount = 0;
  25915. }
  25916. // accumulate data in the 'incoming' region into 'accu<i>'
  25917. accumulate( accuIndex, weight ) {
  25918. // note: happily accumulating nothing when weight = 0, the caller knows
  25919. // the weight and shouldn't have made the call in the first place
  25920. const buffer = this.buffer,
  25921. stride = this.valueSize,
  25922. offset = accuIndex * stride + stride;
  25923. let currentWeight = this.cumulativeWeight;
  25924. if ( currentWeight === 0 ) {
  25925. // accuN := incoming * weight
  25926. for ( let i = 0; i !== stride; ++ i ) {
  25927. buffer[ offset + i ] = buffer[ i ];
  25928. }
  25929. currentWeight = weight;
  25930. } else {
  25931. // accuN := accuN + incoming * weight
  25932. currentWeight += weight;
  25933. const mix = weight / currentWeight;
  25934. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25935. }
  25936. this.cumulativeWeight = currentWeight;
  25937. }
  25938. // accumulate data in the 'incoming' region into 'add'
  25939. accumulateAdditive( weight ) {
  25940. const buffer = this.buffer,
  25941. stride = this.valueSize,
  25942. offset = stride * this._addIndex;
  25943. if ( this.cumulativeWeightAdditive === 0 ) {
  25944. // add = identity
  25945. this._setIdentity();
  25946. }
  25947. // add := add + incoming * weight
  25948. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  25949. this.cumulativeWeightAdditive += weight;
  25950. }
  25951. // apply the state of 'accu<i>' to the binding when accus differ
  25952. apply( accuIndex ) {
  25953. const stride = this.valueSize,
  25954. buffer = this.buffer,
  25955. offset = accuIndex * stride + stride,
  25956. weight = this.cumulativeWeight,
  25957. weightAdditive = this.cumulativeWeightAdditive,
  25958. binding = this.binding;
  25959. this.cumulativeWeight = 0;
  25960. this.cumulativeWeightAdditive = 0;
  25961. if ( weight < 1 ) {
  25962. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25963. const originalValueOffset = stride * this._origIndex;
  25964. this._mixBufferRegion(
  25965. buffer, offset, originalValueOffset, 1 - weight, stride );
  25966. }
  25967. if ( weightAdditive > 0 ) {
  25968. // accuN := accuN + additive accuN
  25969. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  25970. }
  25971. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  25972. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25973. // value has changed -> update scene graph
  25974. binding.setValue( buffer, offset );
  25975. break;
  25976. }
  25977. }
  25978. }
  25979. // remember the state of the bound property and copy it to both accus
  25980. saveOriginalState() {
  25981. const binding = this.binding;
  25982. const buffer = this.buffer,
  25983. stride = this.valueSize,
  25984. originalValueOffset = stride * this._origIndex;
  25985. binding.getValue( buffer, originalValueOffset );
  25986. // accu[0..1] := orig -- initially detect changes against the original
  25987. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25988. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25989. }
  25990. // Add to identity for additive
  25991. this._setIdentity();
  25992. this.cumulativeWeight = 0;
  25993. this.cumulativeWeightAdditive = 0;
  25994. }
  25995. // apply the state previously taken via 'saveOriginalState' to the binding
  25996. restoreOriginalState() {
  25997. const originalValueOffset = this.valueSize * 3;
  25998. this.binding.setValue( this.buffer, originalValueOffset );
  25999. }
  26000. _setAdditiveIdentityNumeric() {
  26001. const startIndex = this._addIndex * this.valueSize;
  26002. const endIndex = startIndex + this.valueSize;
  26003. for ( let i = startIndex; i < endIndex; i ++ ) {
  26004. this.buffer[ i ] = 0;
  26005. }
  26006. }
  26007. _setAdditiveIdentityQuaternion() {
  26008. this._setAdditiveIdentityNumeric();
  26009. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  26010. }
  26011. _setAdditiveIdentityOther() {
  26012. const startIndex = this._origIndex * this.valueSize;
  26013. const targetIndex = this._addIndex * this.valueSize;
  26014. for ( let i = 0; i < this.valueSize; i ++ ) {
  26015. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  26016. }
  26017. }
  26018. // mix functions
  26019. _select( buffer, dstOffset, srcOffset, t, stride ) {
  26020. if ( t >= 0.5 ) {
  26021. for ( let i = 0; i !== stride; ++ i ) {
  26022. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  26023. }
  26024. }
  26025. }
  26026. _slerp( buffer, dstOffset, srcOffset, t ) {
  26027. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  26028. }
  26029. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  26030. const workOffset = this._workIndex * stride;
  26031. // Store result in intermediate buffer offset
  26032. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  26033. // Slerp to the intermediate result
  26034. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  26035. }
  26036. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  26037. const s = 1 - t;
  26038. for ( let i = 0; i !== stride; ++ i ) {
  26039. const j = dstOffset + i;
  26040. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  26041. }
  26042. }
  26043. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  26044. for ( let i = 0; i !== stride; ++ i ) {
  26045. const j = dstOffset + i;
  26046. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  26047. }
  26048. }
  26049. }
  26050. // Characters [].:/ are reserved for track binding syntax.
  26051. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26052. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  26053. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26054. // only latin characters, and the unicode \p{L} is not yet supported. So
  26055. // instead, we exclude reserved characters and match everything else.
  26056. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26057. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26058. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26059. // be matched to parse the rest of the track name.
  26060. const _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  26061. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26062. const _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  26063. // Object on target node, and accessor. May not contain reserved
  26064. // characters. Accessor may contain any character except closing bracket.
  26065. const _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  26066. // Property and accessor. May not contain reserved characters. Accessor may
  26067. // contain any non-bracket characters.
  26068. const _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  26069. const _trackRe = new RegExp( ''
  26070. + '^'
  26071. + _directoryRe
  26072. + _nodeRe
  26073. + _objectRe
  26074. + _propertyRe
  26075. + '$'
  26076. );
  26077. const _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26078. class Composite {
  26079. constructor( targetGroup, path, optionalParsedPath ) {
  26080. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  26081. this._targetGroup = targetGroup;
  26082. this._bindings = targetGroup.subscribe_( path, parsedPath );
  26083. }
  26084. getValue( array, offset ) {
  26085. this.bind(); // bind all binding
  26086. const firstValidIndex = this._targetGroup.nCachedObjects_,
  26087. binding = this._bindings[ firstValidIndex ];
  26088. // and only call .getValue on the first
  26089. if ( binding !== undefined ) binding.getValue( array, offset );
  26090. }
  26091. setValue( array, offset ) {
  26092. const bindings = this._bindings;
  26093. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26094. bindings[ i ].setValue( array, offset );
  26095. }
  26096. }
  26097. bind() {
  26098. const bindings = this._bindings;
  26099. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26100. bindings[ i ].bind();
  26101. }
  26102. }
  26103. unbind() {
  26104. const bindings = this._bindings;
  26105. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26106. bindings[ i ].unbind();
  26107. }
  26108. }
  26109. }
  26110. // Note: This class uses a State pattern on a per-method basis:
  26111. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26112. // prototype version of these methods with one that represents
  26113. // the bound state. When the property is not found, the methods
  26114. // become no-ops.
  26115. class PropertyBinding {
  26116. constructor( rootNode, path, parsedPath ) {
  26117. this.path = path;
  26118. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26119. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26120. this.rootNode = rootNode;
  26121. // initial state of these methods that calls 'bind'
  26122. this.getValue = this._getValue_unbound;
  26123. this.setValue = this._setValue_unbound;
  26124. }
  26125. static create( root, path, parsedPath ) {
  26126. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26127. return new PropertyBinding( root, path, parsedPath );
  26128. } else {
  26129. return new PropertyBinding.Composite( root, path, parsedPath );
  26130. }
  26131. }
  26132. /**
  26133. * Replaces spaces with underscores and removes unsupported characters from
  26134. * node names, to ensure compatibility with parseTrackName().
  26135. *
  26136. * @param {string} name Node name to be sanitized.
  26137. * @return {string}
  26138. */
  26139. static sanitizeNodeName( name ) {
  26140. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  26141. }
  26142. static parseTrackName( trackName ) {
  26143. const matches = _trackRe.exec( trackName );
  26144. if ( ! matches ) {
  26145. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26146. }
  26147. const results = {
  26148. // directoryName: matches[ 1 ], // (tschw) currently unused
  26149. nodeName: matches[ 2 ],
  26150. objectName: matches[ 3 ],
  26151. objectIndex: matches[ 4 ],
  26152. propertyName: matches[ 5 ], // required
  26153. propertyIndex: matches[ 6 ]
  26154. };
  26155. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26156. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26157. const objectName = results.nodeName.substring( lastDot + 1 );
  26158. // Object names must be checked against an allowlist. Otherwise, there
  26159. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26160. // 'bar' could be the objectName, or part of a nodeName (which can
  26161. // include '.' characters).
  26162. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26163. results.nodeName = results.nodeName.substring( 0, lastDot );
  26164. results.objectName = objectName;
  26165. }
  26166. }
  26167. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26168. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26169. }
  26170. return results;
  26171. }
  26172. static findNode( root, nodeName ) {
  26173. if ( ! nodeName || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26174. return root;
  26175. }
  26176. // search into skeleton bones.
  26177. if ( root.skeleton ) {
  26178. const bone = root.skeleton.getBoneByName( nodeName );
  26179. if ( bone !== undefined ) {
  26180. return bone;
  26181. }
  26182. }
  26183. // search into node subtree.
  26184. if ( root.children ) {
  26185. const searchNodeSubtree = function ( children ) {
  26186. for ( let i = 0; i < children.length; i ++ ) {
  26187. const childNode = children[ i ];
  26188. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26189. return childNode;
  26190. }
  26191. const result = searchNodeSubtree( childNode.children );
  26192. if ( result ) return result;
  26193. }
  26194. return null;
  26195. };
  26196. const subTreeNode = searchNodeSubtree( root.children );
  26197. if ( subTreeNode ) {
  26198. return subTreeNode;
  26199. }
  26200. }
  26201. return null;
  26202. }
  26203. // these are used to "bind" a nonexistent property
  26204. _getValue_unavailable() {}
  26205. _setValue_unavailable() {}
  26206. // Getters
  26207. _getValue_direct( buffer, offset ) {
  26208. buffer[ offset ] = this.targetObject[ this.propertyName ];
  26209. }
  26210. _getValue_array( buffer, offset ) {
  26211. const source = this.resolvedProperty;
  26212. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  26213. buffer[ offset ++ ] = source[ i ];
  26214. }
  26215. }
  26216. _getValue_arrayElement( buffer, offset ) {
  26217. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26218. }
  26219. _getValue_toArray( buffer, offset ) {
  26220. this.resolvedProperty.toArray( buffer, offset );
  26221. }
  26222. // Direct
  26223. _setValue_direct( buffer, offset ) {
  26224. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26225. }
  26226. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  26227. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26228. this.targetObject.needsUpdate = true;
  26229. }
  26230. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26231. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26232. this.targetObject.matrixWorldNeedsUpdate = true;
  26233. }
  26234. // EntireArray
  26235. _setValue_array( buffer, offset ) {
  26236. const dest = this.resolvedProperty;
  26237. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26238. dest[ i ] = buffer[ offset ++ ];
  26239. }
  26240. }
  26241. _setValue_array_setNeedsUpdate( buffer, offset ) {
  26242. const dest = this.resolvedProperty;
  26243. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26244. dest[ i ] = buffer[ offset ++ ];
  26245. }
  26246. this.targetObject.needsUpdate = true;
  26247. }
  26248. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26249. const dest = this.resolvedProperty;
  26250. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26251. dest[ i ] = buffer[ offset ++ ];
  26252. }
  26253. this.targetObject.matrixWorldNeedsUpdate = true;
  26254. }
  26255. // ArrayElement
  26256. _setValue_arrayElement( buffer, offset ) {
  26257. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26258. }
  26259. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26260. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26261. this.targetObject.needsUpdate = true;
  26262. }
  26263. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26264. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26265. this.targetObject.matrixWorldNeedsUpdate = true;
  26266. }
  26267. // HasToFromArray
  26268. _setValue_fromArray( buffer, offset ) {
  26269. this.resolvedProperty.fromArray( buffer, offset );
  26270. }
  26271. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26272. this.resolvedProperty.fromArray( buffer, offset );
  26273. this.targetObject.needsUpdate = true;
  26274. }
  26275. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26276. this.resolvedProperty.fromArray( buffer, offset );
  26277. this.targetObject.matrixWorldNeedsUpdate = true;
  26278. }
  26279. _getValue_unbound( targetArray, offset ) {
  26280. this.bind();
  26281. this.getValue( targetArray, offset );
  26282. }
  26283. _setValue_unbound( sourceArray, offset ) {
  26284. this.bind();
  26285. this.setValue( sourceArray, offset );
  26286. }
  26287. // create getter / setter pair for a property in the scene graph
  26288. bind() {
  26289. let targetObject = this.node;
  26290. const parsedPath = this.parsedPath;
  26291. const objectName = parsedPath.objectName;
  26292. const propertyName = parsedPath.propertyName;
  26293. let propertyIndex = parsedPath.propertyIndex;
  26294. if ( ! targetObject ) {
  26295. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26296. this.node = targetObject;
  26297. }
  26298. // set fail state so we can just 'return' on error
  26299. this.getValue = this._getValue_unavailable;
  26300. this.setValue = this._setValue_unavailable;
  26301. // ensure there is a value node
  26302. if ( ! targetObject ) {
  26303. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26304. return;
  26305. }
  26306. if ( objectName ) {
  26307. let objectIndex = parsedPath.objectIndex;
  26308. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26309. switch ( objectName ) {
  26310. case 'materials':
  26311. if ( ! targetObject.material ) {
  26312. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26313. return;
  26314. }
  26315. if ( ! targetObject.material.materials ) {
  26316. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26317. return;
  26318. }
  26319. targetObject = targetObject.material.materials;
  26320. break;
  26321. case 'bones':
  26322. if ( ! targetObject.skeleton ) {
  26323. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26324. return;
  26325. }
  26326. // potential future optimization: skip this if propertyIndex is already an integer
  26327. // and convert the integer string to a true integer.
  26328. targetObject = targetObject.skeleton.bones;
  26329. // support resolving morphTarget names into indices.
  26330. for ( let i = 0; i < targetObject.length; i ++ ) {
  26331. if ( targetObject[ i ].name === objectIndex ) {
  26332. objectIndex = i;
  26333. break;
  26334. }
  26335. }
  26336. break;
  26337. default:
  26338. if ( targetObject[ objectName ] === undefined ) {
  26339. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26340. return;
  26341. }
  26342. targetObject = targetObject[ objectName ];
  26343. }
  26344. if ( objectIndex !== undefined ) {
  26345. if ( targetObject[ objectIndex ] === undefined ) {
  26346. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26347. return;
  26348. }
  26349. targetObject = targetObject[ objectIndex ];
  26350. }
  26351. }
  26352. // resolve property
  26353. const nodeProperty = targetObject[ propertyName ];
  26354. if ( nodeProperty === undefined ) {
  26355. const nodeName = parsedPath.nodeName;
  26356. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26357. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26358. return;
  26359. }
  26360. // determine versioning scheme
  26361. let versioning = this.Versioning.None;
  26362. this.targetObject = targetObject;
  26363. if ( targetObject.needsUpdate !== undefined ) { // material
  26364. versioning = this.Versioning.NeedsUpdate;
  26365. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26366. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26367. }
  26368. // determine how the property gets bound
  26369. let bindingType = this.BindingType.Direct;
  26370. if ( propertyIndex !== undefined ) {
  26371. // access a sub element of the property array (only primitives are supported right now)
  26372. if ( propertyName === 'morphTargetInfluences' ) {
  26373. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26374. // support resolving morphTarget names into indices.
  26375. if ( ! targetObject.geometry ) {
  26376. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26377. return;
  26378. }
  26379. if ( targetObject.geometry.isBufferGeometry ) {
  26380. if ( ! targetObject.geometry.morphAttributes ) {
  26381. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26382. return;
  26383. }
  26384. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  26385. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  26386. }
  26387. } else {
  26388. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  26389. return;
  26390. }
  26391. }
  26392. bindingType = this.BindingType.ArrayElement;
  26393. this.resolvedProperty = nodeProperty;
  26394. this.propertyIndex = propertyIndex;
  26395. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26396. // must use copy for Object3D.Euler/Quaternion
  26397. bindingType = this.BindingType.HasFromToArray;
  26398. this.resolvedProperty = nodeProperty;
  26399. } else if ( Array.isArray( nodeProperty ) ) {
  26400. bindingType = this.BindingType.EntireArray;
  26401. this.resolvedProperty = nodeProperty;
  26402. } else {
  26403. this.propertyName = propertyName;
  26404. }
  26405. // select getter / setter
  26406. this.getValue = this.GetterByBindingType[ bindingType ];
  26407. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26408. }
  26409. unbind() {
  26410. this.node = null;
  26411. // back to the prototype version of getValue / setValue
  26412. // note: avoiding to mutate the shape of 'this' via 'delete'
  26413. this.getValue = this._getValue_unbound;
  26414. this.setValue = this._setValue_unbound;
  26415. }
  26416. }
  26417. PropertyBinding.Composite = Composite;
  26418. PropertyBinding.prototype.BindingType = {
  26419. Direct: 0,
  26420. EntireArray: 1,
  26421. ArrayElement: 2,
  26422. HasFromToArray: 3
  26423. };
  26424. PropertyBinding.prototype.Versioning = {
  26425. None: 0,
  26426. NeedsUpdate: 1,
  26427. MatrixWorldNeedsUpdate: 2
  26428. };
  26429. PropertyBinding.prototype.GetterByBindingType = [
  26430. PropertyBinding.prototype._getValue_direct,
  26431. PropertyBinding.prototype._getValue_array,
  26432. PropertyBinding.prototype._getValue_arrayElement,
  26433. PropertyBinding.prototype._getValue_toArray,
  26434. ];
  26435. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  26436. [
  26437. // Direct
  26438. PropertyBinding.prototype._setValue_direct,
  26439. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  26440. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  26441. ], [
  26442. // EntireArray
  26443. PropertyBinding.prototype._setValue_array,
  26444. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  26445. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  26446. ], [
  26447. // ArrayElement
  26448. PropertyBinding.prototype._setValue_arrayElement,
  26449. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  26450. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  26451. ], [
  26452. // HasToFromArray
  26453. PropertyBinding.prototype._setValue_fromArray,
  26454. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  26455. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  26456. ]
  26457. ];
  26458. /**
  26459. *
  26460. * A group of objects that receives a shared animation state.
  26461. *
  26462. * Usage:
  26463. *
  26464. * - Add objects you would otherwise pass as 'root' to the
  26465. * constructor or the .clipAction method of AnimationMixer.
  26466. *
  26467. * - Instead pass this object as 'root'.
  26468. *
  26469. * - You can also add and remove objects later when the mixer
  26470. * is running.
  26471. *
  26472. * Note:
  26473. *
  26474. * Objects of this class appear as one object to the mixer,
  26475. * so cache control of the individual objects must be done
  26476. * on the group.
  26477. *
  26478. * Limitation:
  26479. *
  26480. * - The animated properties must be compatible among the
  26481. * all objects in the group.
  26482. *
  26483. * - A single property can either be controlled through a
  26484. * target group or directly, but not both.
  26485. */
  26486. class AnimationObjectGroup {
  26487. constructor() {
  26488. this.uuid = generateUUID();
  26489. // cached objects followed by the active ones
  26490. this._objects = Array.prototype.slice.call( arguments );
  26491. this.nCachedObjects_ = 0; // threshold
  26492. // note: read by PropertyBinding.Composite
  26493. const indices = {};
  26494. this._indicesByUUID = indices; // for bookkeeping
  26495. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26496. indices[ arguments[ i ].uuid ] = i;
  26497. }
  26498. this._paths = []; // inside: string
  26499. this._parsedPaths = []; // inside: { we don't care, here }
  26500. this._bindings = []; // inside: Array< PropertyBinding >
  26501. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26502. const scope = this;
  26503. this.stats = {
  26504. objects: {
  26505. get total() {
  26506. return scope._objects.length;
  26507. },
  26508. get inUse() {
  26509. return this.total - scope.nCachedObjects_;
  26510. }
  26511. },
  26512. get bindingsPerObject() {
  26513. return scope._bindings.length;
  26514. }
  26515. };
  26516. }
  26517. add() {
  26518. const objects = this._objects,
  26519. indicesByUUID = this._indicesByUUID,
  26520. paths = this._paths,
  26521. parsedPaths = this._parsedPaths,
  26522. bindings = this._bindings,
  26523. nBindings = bindings.length;
  26524. let knownObject = undefined,
  26525. nObjects = objects.length,
  26526. nCachedObjects = this.nCachedObjects_;
  26527. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26528. const object = arguments[ i ],
  26529. uuid = object.uuid;
  26530. let index = indicesByUUID[ uuid ];
  26531. if ( index === undefined ) {
  26532. // unknown object -> add it to the ACTIVE region
  26533. index = nObjects ++;
  26534. indicesByUUID[ uuid ] = index;
  26535. objects.push( object );
  26536. // accounting is done, now do the same for all bindings
  26537. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26538. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26539. }
  26540. } else if ( index < nCachedObjects ) {
  26541. knownObject = objects[ index ];
  26542. // move existing object to the ACTIVE region
  26543. const firstActiveIndex = -- nCachedObjects,
  26544. lastCachedObject = objects[ firstActiveIndex ];
  26545. indicesByUUID[ lastCachedObject.uuid ] = index;
  26546. objects[ index ] = lastCachedObject;
  26547. indicesByUUID[ uuid ] = firstActiveIndex;
  26548. objects[ firstActiveIndex ] = object;
  26549. // accounting is done, now do the same for all bindings
  26550. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26551. const bindingsForPath = bindings[ j ],
  26552. lastCached = bindingsForPath[ firstActiveIndex ];
  26553. let binding = bindingsForPath[ index ];
  26554. bindingsForPath[ index ] = lastCached;
  26555. if ( binding === undefined ) {
  26556. // since we do not bother to create new bindings
  26557. // for objects that are cached, the binding may
  26558. // or may not exist
  26559. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26560. }
  26561. bindingsForPath[ firstActiveIndex ] = binding;
  26562. }
  26563. } else if ( objects[ index ] !== knownObject ) {
  26564. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26565. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26566. } // else the object is already where we want it to be
  26567. } // for arguments
  26568. this.nCachedObjects_ = nCachedObjects;
  26569. }
  26570. remove() {
  26571. const objects = this._objects,
  26572. indicesByUUID = this._indicesByUUID,
  26573. bindings = this._bindings,
  26574. nBindings = bindings.length;
  26575. let nCachedObjects = this.nCachedObjects_;
  26576. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26577. const object = arguments[ i ],
  26578. uuid = object.uuid,
  26579. index = indicesByUUID[ uuid ];
  26580. if ( index !== undefined && index >= nCachedObjects ) {
  26581. // move existing object into the CACHED region
  26582. const lastCachedIndex = nCachedObjects ++,
  26583. firstActiveObject = objects[ lastCachedIndex ];
  26584. indicesByUUID[ firstActiveObject.uuid ] = index;
  26585. objects[ index ] = firstActiveObject;
  26586. indicesByUUID[ uuid ] = lastCachedIndex;
  26587. objects[ lastCachedIndex ] = object;
  26588. // accounting is done, now do the same for all bindings
  26589. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26590. const bindingsForPath = bindings[ j ],
  26591. firstActive = bindingsForPath[ lastCachedIndex ],
  26592. binding = bindingsForPath[ index ];
  26593. bindingsForPath[ index ] = firstActive;
  26594. bindingsForPath[ lastCachedIndex ] = binding;
  26595. }
  26596. }
  26597. } // for arguments
  26598. this.nCachedObjects_ = nCachedObjects;
  26599. }
  26600. // remove & forget
  26601. uncache() {
  26602. const objects = this._objects,
  26603. indicesByUUID = this._indicesByUUID,
  26604. bindings = this._bindings,
  26605. nBindings = bindings.length;
  26606. let nCachedObjects = this.nCachedObjects_,
  26607. nObjects = objects.length;
  26608. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26609. const object = arguments[ i ],
  26610. uuid = object.uuid,
  26611. index = indicesByUUID[ uuid ];
  26612. if ( index !== undefined ) {
  26613. delete indicesByUUID[ uuid ];
  26614. if ( index < nCachedObjects ) {
  26615. // object is cached, shrink the CACHED region
  26616. const firstActiveIndex = -- nCachedObjects,
  26617. lastCachedObject = objects[ firstActiveIndex ],
  26618. lastIndex = -- nObjects,
  26619. lastObject = objects[ lastIndex ];
  26620. // last cached object takes this object's place
  26621. indicesByUUID[ lastCachedObject.uuid ] = index;
  26622. objects[ index ] = lastCachedObject;
  26623. // last object goes to the activated slot and pop
  26624. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26625. objects[ firstActiveIndex ] = lastObject;
  26626. objects.pop();
  26627. // accounting is done, now do the same for all bindings
  26628. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26629. const bindingsForPath = bindings[ j ],
  26630. lastCached = bindingsForPath[ firstActiveIndex ],
  26631. last = bindingsForPath[ lastIndex ];
  26632. bindingsForPath[ index ] = lastCached;
  26633. bindingsForPath[ firstActiveIndex ] = last;
  26634. bindingsForPath.pop();
  26635. }
  26636. } else {
  26637. // object is active, just swap with the last and pop
  26638. const lastIndex = -- nObjects,
  26639. lastObject = objects[ lastIndex ];
  26640. if ( lastIndex > 0 ) {
  26641. indicesByUUID[ lastObject.uuid ] = index;
  26642. }
  26643. objects[ index ] = lastObject;
  26644. objects.pop();
  26645. // accounting is done, now do the same for all bindings
  26646. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26647. const bindingsForPath = bindings[ j ];
  26648. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26649. bindingsForPath.pop();
  26650. }
  26651. } // cached or active
  26652. } // if object is known
  26653. } // for arguments
  26654. this.nCachedObjects_ = nCachedObjects;
  26655. }
  26656. // Internal interface used by befriended PropertyBinding.Composite:
  26657. subscribe_( path, parsedPath ) {
  26658. // returns an array of bindings for the given path that is changed
  26659. // according to the contained objects in the group
  26660. const indicesByPath = this._bindingsIndicesByPath;
  26661. let index = indicesByPath[ path ];
  26662. const bindings = this._bindings;
  26663. if ( index !== undefined ) return bindings[ index ];
  26664. const paths = this._paths,
  26665. parsedPaths = this._parsedPaths,
  26666. objects = this._objects,
  26667. nObjects = objects.length,
  26668. nCachedObjects = this.nCachedObjects_,
  26669. bindingsForPath = new Array( nObjects );
  26670. index = bindings.length;
  26671. indicesByPath[ path ] = index;
  26672. paths.push( path );
  26673. parsedPaths.push( parsedPath );
  26674. bindings.push( bindingsForPath );
  26675. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26676. const object = objects[ i ];
  26677. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26678. }
  26679. return bindingsForPath;
  26680. }
  26681. unsubscribe_( path ) {
  26682. // tells the group to forget about a property path and no longer
  26683. // update the array previously obtained with 'subscribe_'
  26684. const indicesByPath = this._bindingsIndicesByPath,
  26685. index = indicesByPath[ path ];
  26686. if ( index !== undefined ) {
  26687. const paths = this._paths,
  26688. parsedPaths = this._parsedPaths,
  26689. bindings = this._bindings,
  26690. lastBindingsIndex = bindings.length - 1,
  26691. lastBindings = bindings[ lastBindingsIndex ],
  26692. lastBindingsPath = path[ lastBindingsIndex ];
  26693. indicesByPath[ lastBindingsPath ] = index;
  26694. bindings[ index ] = lastBindings;
  26695. bindings.pop();
  26696. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26697. parsedPaths.pop();
  26698. paths[ index ] = paths[ lastBindingsIndex ];
  26699. paths.pop();
  26700. }
  26701. }
  26702. }
  26703. AnimationObjectGroup.prototype.isAnimationObjectGroup = true;
  26704. class AnimationAction {
  26705. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  26706. this._mixer = mixer;
  26707. this._clip = clip;
  26708. this._localRoot = localRoot;
  26709. this.blendMode = blendMode;
  26710. const tracks = clip.tracks,
  26711. nTracks = tracks.length,
  26712. interpolants = new Array( nTracks );
  26713. const interpolantSettings = {
  26714. endingStart: ZeroCurvatureEnding,
  26715. endingEnd: ZeroCurvatureEnding
  26716. };
  26717. for ( let i = 0; i !== nTracks; ++ i ) {
  26718. const interpolant = tracks[ i ].createInterpolant( null );
  26719. interpolants[ i ] = interpolant;
  26720. interpolant.settings = interpolantSettings;
  26721. }
  26722. this._interpolantSettings = interpolantSettings;
  26723. this._interpolants = interpolants; // bound by the mixer
  26724. // inside: PropertyMixer (managed by the mixer)
  26725. this._propertyBindings = new Array( nTracks );
  26726. this._cacheIndex = null; // for the memory manager
  26727. this._byClipCacheIndex = null; // for the memory manager
  26728. this._timeScaleInterpolant = null;
  26729. this._weightInterpolant = null;
  26730. this.loop = LoopRepeat;
  26731. this._loopCount = - 1;
  26732. // global mixer time when the action is to be started
  26733. // it's set back to 'null' upon start of the action
  26734. this._startTime = null;
  26735. // scaled local time of the action
  26736. // gets clamped or wrapped to 0..clip.duration according to loop
  26737. this.time = 0;
  26738. this.timeScale = 1;
  26739. this._effectiveTimeScale = 1;
  26740. this.weight = 1;
  26741. this._effectiveWeight = 1;
  26742. this.repetitions = Infinity; // no. of repetitions when looping
  26743. this.paused = false; // true -> zero effective time scale
  26744. this.enabled = true; // false -> zero effective weight
  26745. this.clampWhenFinished = false;// keep feeding the last frame?
  26746. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  26747. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  26748. }
  26749. // State & Scheduling
  26750. play() {
  26751. this._mixer._activateAction( this );
  26752. return this;
  26753. }
  26754. stop() {
  26755. this._mixer._deactivateAction( this );
  26756. return this.reset();
  26757. }
  26758. reset() {
  26759. this.paused = false;
  26760. this.enabled = true;
  26761. this.time = 0; // restart clip
  26762. this._loopCount = - 1;// forget previous loops
  26763. this._startTime = null;// forget scheduling
  26764. return this.stopFading().stopWarping();
  26765. }
  26766. isRunning() {
  26767. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  26768. this._startTime === null && this._mixer._isActiveAction( this );
  26769. }
  26770. // return true when play has been called
  26771. isScheduled() {
  26772. return this._mixer._isActiveAction( this );
  26773. }
  26774. startAt( time ) {
  26775. this._startTime = time;
  26776. return this;
  26777. }
  26778. setLoop( mode, repetitions ) {
  26779. this.loop = mode;
  26780. this.repetitions = repetitions;
  26781. return this;
  26782. }
  26783. // Weight
  26784. // set the weight stopping any scheduled fading
  26785. // although .enabled = false yields an effective weight of zero, this
  26786. // method does *not* change .enabled, because it would be confusing
  26787. setEffectiveWeight( weight ) {
  26788. this.weight = weight;
  26789. // note: same logic as when updated at runtime
  26790. this._effectiveWeight = this.enabled ? weight : 0;
  26791. return this.stopFading();
  26792. }
  26793. // return the weight considering fading and .enabled
  26794. getEffectiveWeight() {
  26795. return this._effectiveWeight;
  26796. }
  26797. fadeIn( duration ) {
  26798. return this._scheduleFading( duration, 0, 1 );
  26799. }
  26800. fadeOut( duration ) {
  26801. return this._scheduleFading( duration, 1, 0 );
  26802. }
  26803. crossFadeFrom( fadeOutAction, duration, warp ) {
  26804. fadeOutAction.fadeOut( duration );
  26805. this.fadeIn( duration );
  26806. if ( warp ) {
  26807. const fadeInDuration = this._clip.duration,
  26808. fadeOutDuration = fadeOutAction._clip.duration,
  26809. startEndRatio = fadeOutDuration / fadeInDuration,
  26810. endStartRatio = fadeInDuration / fadeOutDuration;
  26811. fadeOutAction.warp( 1.0, startEndRatio, duration );
  26812. this.warp( endStartRatio, 1.0, duration );
  26813. }
  26814. return this;
  26815. }
  26816. crossFadeTo( fadeInAction, duration, warp ) {
  26817. return fadeInAction.crossFadeFrom( this, duration, warp );
  26818. }
  26819. stopFading() {
  26820. const weightInterpolant = this._weightInterpolant;
  26821. if ( weightInterpolant !== null ) {
  26822. this._weightInterpolant = null;
  26823. this._mixer._takeBackControlInterpolant( weightInterpolant );
  26824. }
  26825. return this;
  26826. }
  26827. // Time Scale Control
  26828. // set the time scale stopping any scheduled warping
  26829. // although .paused = true yields an effective time scale of zero, this
  26830. // method does *not* change .paused, because it would be confusing
  26831. setEffectiveTimeScale( timeScale ) {
  26832. this.timeScale = timeScale;
  26833. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26834. return this.stopWarping();
  26835. }
  26836. // return the time scale considering warping and .paused
  26837. getEffectiveTimeScale() {
  26838. return this._effectiveTimeScale;
  26839. }
  26840. setDuration( duration ) {
  26841. this.timeScale = this._clip.duration / duration;
  26842. return this.stopWarping();
  26843. }
  26844. syncWith( action ) {
  26845. this.time = action.time;
  26846. this.timeScale = action.timeScale;
  26847. return this.stopWarping();
  26848. }
  26849. halt( duration ) {
  26850. return this.warp( this._effectiveTimeScale, 0, duration );
  26851. }
  26852. warp( startTimeScale, endTimeScale, duration ) {
  26853. const mixer = this._mixer,
  26854. now = mixer.time,
  26855. timeScale = this.timeScale;
  26856. let interpolant = this._timeScaleInterpolant;
  26857. if ( interpolant === null ) {
  26858. interpolant = mixer._lendControlInterpolant();
  26859. this._timeScaleInterpolant = interpolant;
  26860. }
  26861. const times = interpolant.parameterPositions,
  26862. values = interpolant.sampleValues;
  26863. times[ 0 ] = now;
  26864. times[ 1 ] = now + duration;
  26865. values[ 0 ] = startTimeScale / timeScale;
  26866. values[ 1 ] = endTimeScale / timeScale;
  26867. return this;
  26868. }
  26869. stopWarping() {
  26870. const timeScaleInterpolant = this._timeScaleInterpolant;
  26871. if ( timeScaleInterpolant !== null ) {
  26872. this._timeScaleInterpolant = null;
  26873. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  26874. }
  26875. return this;
  26876. }
  26877. // Object Accessors
  26878. getMixer() {
  26879. return this._mixer;
  26880. }
  26881. getClip() {
  26882. return this._clip;
  26883. }
  26884. getRoot() {
  26885. return this._localRoot || this._mixer._root;
  26886. }
  26887. // Interna
  26888. _update( time, deltaTime, timeDirection, accuIndex ) {
  26889. // called by the mixer
  26890. if ( ! this.enabled ) {
  26891. // call ._updateWeight() to update ._effectiveWeight
  26892. this._updateWeight( time );
  26893. return;
  26894. }
  26895. const startTime = this._startTime;
  26896. if ( startTime !== null ) {
  26897. // check for scheduled start of action
  26898. const timeRunning = ( time - startTime ) * timeDirection;
  26899. if ( timeRunning < 0 || timeDirection === 0 ) {
  26900. return; // yet to come / don't decide when delta = 0
  26901. }
  26902. // start
  26903. this._startTime = null; // unschedule
  26904. deltaTime = timeDirection * timeRunning;
  26905. }
  26906. // apply time scale and advance time
  26907. deltaTime *= this._updateTimeScale( time );
  26908. const clipTime = this._updateTime( deltaTime );
  26909. // note: _updateTime may disable the action resulting in
  26910. // an effective weight of 0
  26911. const weight = this._updateWeight( time );
  26912. if ( weight > 0 ) {
  26913. const interpolants = this._interpolants;
  26914. const propertyMixers = this._propertyBindings;
  26915. switch ( this.blendMode ) {
  26916. case AdditiveAnimationBlendMode:
  26917. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  26918. interpolants[ j ].evaluate( clipTime );
  26919. propertyMixers[ j ].accumulateAdditive( weight );
  26920. }
  26921. break;
  26922. case NormalAnimationBlendMode:
  26923. default:
  26924. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  26925. interpolants[ j ].evaluate( clipTime );
  26926. propertyMixers[ j ].accumulate( accuIndex, weight );
  26927. }
  26928. }
  26929. }
  26930. }
  26931. _updateWeight( time ) {
  26932. let weight = 0;
  26933. if ( this.enabled ) {
  26934. weight = this.weight;
  26935. const interpolant = this._weightInterpolant;
  26936. if ( interpolant !== null ) {
  26937. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  26938. weight *= interpolantValue;
  26939. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26940. this.stopFading();
  26941. if ( interpolantValue === 0 ) {
  26942. // faded out, disable
  26943. this.enabled = false;
  26944. }
  26945. }
  26946. }
  26947. }
  26948. this._effectiveWeight = weight;
  26949. return weight;
  26950. }
  26951. _updateTimeScale( time ) {
  26952. let timeScale = 0;
  26953. if ( ! this.paused ) {
  26954. timeScale = this.timeScale;
  26955. const interpolant = this._timeScaleInterpolant;
  26956. if ( interpolant !== null ) {
  26957. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  26958. timeScale *= interpolantValue;
  26959. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26960. this.stopWarping();
  26961. if ( timeScale === 0 ) {
  26962. // motion has halted, pause
  26963. this.paused = true;
  26964. } else {
  26965. // warp done - apply final time scale
  26966. this.timeScale = timeScale;
  26967. }
  26968. }
  26969. }
  26970. }
  26971. this._effectiveTimeScale = timeScale;
  26972. return timeScale;
  26973. }
  26974. _updateTime( deltaTime ) {
  26975. const duration = this._clip.duration;
  26976. const loop = this.loop;
  26977. let time = this.time + deltaTime;
  26978. let loopCount = this._loopCount;
  26979. const pingPong = ( loop === LoopPingPong );
  26980. if ( deltaTime === 0 ) {
  26981. if ( loopCount === - 1 ) return time;
  26982. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26983. }
  26984. if ( loop === LoopOnce ) {
  26985. if ( loopCount === - 1 ) {
  26986. // just started
  26987. this._loopCount = 0;
  26988. this._setEndings( true, true, false );
  26989. }
  26990. handle_stop: {
  26991. if ( time >= duration ) {
  26992. time = duration;
  26993. } else if ( time < 0 ) {
  26994. time = 0;
  26995. } else {
  26996. this.time = time;
  26997. break handle_stop;
  26998. }
  26999. if ( this.clampWhenFinished ) this.paused = true;
  27000. else this.enabled = false;
  27001. this.time = time;
  27002. this._mixer.dispatchEvent( {
  27003. type: 'finished', action: this,
  27004. direction: deltaTime < 0 ? - 1 : 1
  27005. } );
  27006. }
  27007. } else { // repetitive Repeat or PingPong
  27008. if ( loopCount === - 1 ) {
  27009. // just started
  27010. if ( deltaTime >= 0 ) {
  27011. loopCount = 0;
  27012. this._setEndings( true, this.repetitions === 0, pingPong );
  27013. } else {
  27014. // when looping in reverse direction, the initial
  27015. // transition through zero counts as a repetition,
  27016. // so leave loopCount at -1
  27017. this._setEndings( this.repetitions === 0, true, pingPong );
  27018. }
  27019. }
  27020. if ( time >= duration || time < 0 ) {
  27021. // wrap around
  27022. const loopDelta = Math.floor( time / duration ); // signed
  27023. time -= duration * loopDelta;
  27024. loopCount += Math.abs( loopDelta );
  27025. const pending = this.repetitions - loopCount;
  27026. if ( pending <= 0 ) {
  27027. // have to stop (switch state, clamp time, fire event)
  27028. if ( this.clampWhenFinished ) this.paused = true;
  27029. else this.enabled = false;
  27030. time = deltaTime > 0 ? duration : 0;
  27031. this.time = time;
  27032. this._mixer.dispatchEvent( {
  27033. type: 'finished', action: this,
  27034. direction: deltaTime > 0 ? 1 : - 1
  27035. } );
  27036. } else {
  27037. // keep running
  27038. if ( pending === 1 ) {
  27039. // entering the last round
  27040. const atStart = deltaTime < 0;
  27041. this._setEndings( atStart, ! atStart, pingPong );
  27042. } else {
  27043. this._setEndings( false, false, pingPong );
  27044. }
  27045. this._loopCount = loopCount;
  27046. this.time = time;
  27047. this._mixer.dispatchEvent( {
  27048. type: 'loop', action: this, loopDelta: loopDelta
  27049. } );
  27050. }
  27051. } else {
  27052. this.time = time;
  27053. }
  27054. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  27055. // invert time for the "pong round"
  27056. return duration - time;
  27057. }
  27058. }
  27059. return time;
  27060. }
  27061. _setEndings( atStart, atEnd, pingPong ) {
  27062. const settings = this._interpolantSettings;
  27063. if ( pingPong ) {
  27064. settings.endingStart = ZeroSlopeEnding;
  27065. settings.endingEnd = ZeroSlopeEnding;
  27066. } else {
  27067. // assuming for LoopOnce atStart == atEnd == true
  27068. if ( atStart ) {
  27069. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27070. } else {
  27071. settings.endingStart = WrapAroundEnding;
  27072. }
  27073. if ( atEnd ) {
  27074. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27075. } else {
  27076. settings.endingEnd = WrapAroundEnding;
  27077. }
  27078. }
  27079. }
  27080. _scheduleFading( duration, weightNow, weightThen ) {
  27081. const mixer = this._mixer, now = mixer.time;
  27082. let interpolant = this._weightInterpolant;
  27083. if ( interpolant === null ) {
  27084. interpolant = mixer._lendControlInterpolant();
  27085. this._weightInterpolant = interpolant;
  27086. }
  27087. const times = interpolant.parameterPositions,
  27088. values = interpolant.sampleValues;
  27089. times[ 0 ] = now;
  27090. values[ 0 ] = weightNow;
  27091. times[ 1 ] = now + duration;
  27092. values[ 1 ] = weightThen;
  27093. return this;
  27094. }
  27095. }
  27096. class AnimationMixer extends EventDispatcher {
  27097. constructor( root ) {
  27098. super();
  27099. this._root = root;
  27100. this._initMemoryManager();
  27101. this._accuIndex = 0;
  27102. this.time = 0;
  27103. this.timeScale = 1.0;
  27104. }
  27105. _bindAction( action, prototypeAction ) {
  27106. const root = action._localRoot || this._root,
  27107. tracks = action._clip.tracks,
  27108. nTracks = tracks.length,
  27109. bindings = action._propertyBindings,
  27110. interpolants = action._interpolants,
  27111. rootUuid = root.uuid,
  27112. bindingsByRoot = this._bindingsByRootAndName;
  27113. let bindingsByName = bindingsByRoot[ rootUuid ];
  27114. if ( bindingsByName === undefined ) {
  27115. bindingsByName = {};
  27116. bindingsByRoot[ rootUuid ] = bindingsByName;
  27117. }
  27118. for ( let i = 0; i !== nTracks; ++ i ) {
  27119. const track = tracks[ i ],
  27120. trackName = track.name;
  27121. let binding = bindingsByName[ trackName ];
  27122. if ( binding !== undefined ) {
  27123. bindings[ i ] = binding;
  27124. } else {
  27125. binding = bindings[ i ];
  27126. if ( binding !== undefined ) {
  27127. // existing binding, make sure the cache knows
  27128. if ( binding._cacheIndex === null ) {
  27129. ++ binding.referenceCount;
  27130. this._addInactiveBinding( binding, rootUuid, trackName );
  27131. }
  27132. continue;
  27133. }
  27134. const path = prototypeAction && prototypeAction.
  27135. _propertyBindings[ i ].binding.parsedPath;
  27136. binding = new PropertyMixer(
  27137. PropertyBinding.create( root, trackName, path ),
  27138. track.ValueTypeName, track.getValueSize() );
  27139. ++ binding.referenceCount;
  27140. this._addInactiveBinding( binding, rootUuid, trackName );
  27141. bindings[ i ] = binding;
  27142. }
  27143. interpolants[ i ].resultBuffer = binding.buffer;
  27144. }
  27145. }
  27146. _activateAction( action ) {
  27147. if ( ! this._isActiveAction( action ) ) {
  27148. if ( action._cacheIndex === null ) {
  27149. // this action has been forgotten by the cache, but the user
  27150. // appears to be still using it -> rebind
  27151. const rootUuid = ( action._localRoot || this._root ).uuid,
  27152. clipUuid = action._clip.uuid,
  27153. actionsForClip = this._actionsByClip[ clipUuid ];
  27154. this._bindAction( action,
  27155. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27156. this._addInactiveAction( action, clipUuid, rootUuid );
  27157. }
  27158. const bindings = action._propertyBindings;
  27159. // increment reference counts / sort out state
  27160. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27161. const binding = bindings[ i ];
  27162. if ( binding.useCount ++ === 0 ) {
  27163. this._lendBinding( binding );
  27164. binding.saveOriginalState();
  27165. }
  27166. }
  27167. this._lendAction( action );
  27168. }
  27169. }
  27170. _deactivateAction( action ) {
  27171. if ( this._isActiveAction( action ) ) {
  27172. const bindings = action._propertyBindings;
  27173. // decrement reference counts / sort out state
  27174. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27175. const binding = bindings[ i ];
  27176. if ( -- binding.useCount === 0 ) {
  27177. binding.restoreOriginalState();
  27178. this._takeBackBinding( binding );
  27179. }
  27180. }
  27181. this._takeBackAction( action );
  27182. }
  27183. }
  27184. // Memory manager
  27185. _initMemoryManager() {
  27186. this._actions = []; // 'nActiveActions' followed by inactive ones
  27187. this._nActiveActions = 0;
  27188. this._actionsByClip = {};
  27189. // inside:
  27190. // {
  27191. // knownActions: Array< AnimationAction > - used as prototypes
  27192. // actionByRoot: AnimationAction - lookup
  27193. // }
  27194. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27195. this._nActiveBindings = 0;
  27196. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27197. this._controlInterpolants = []; // same game as above
  27198. this._nActiveControlInterpolants = 0;
  27199. const scope = this;
  27200. this.stats = {
  27201. actions: {
  27202. get total() {
  27203. return scope._actions.length;
  27204. },
  27205. get inUse() {
  27206. return scope._nActiveActions;
  27207. }
  27208. },
  27209. bindings: {
  27210. get total() {
  27211. return scope._bindings.length;
  27212. },
  27213. get inUse() {
  27214. return scope._nActiveBindings;
  27215. }
  27216. },
  27217. controlInterpolants: {
  27218. get total() {
  27219. return scope._controlInterpolants.length;
  27220. },
  27221. get inUse() {
  27222. return scope._nActiveControlInterpolants;
  27223. }
  27224. }
  27225. };
  27226. }
  27227. // Memory management for AnimationAction objects
  27228. _isActiveAction( action ) {
  27229. const index = action._cacheIndex;
  27230. return index !== null && index < this._nActiveActions;
  27231. }
  27232. _addInactiveAction( action, clipUuid, rootUuid ) {
  27233. const actions = this._actions,
  27234. actionsByClip = this._actionsByClip;
  27235. let actionsForClip = actionsByClip[ clipUuid ];
  27236. if ( actionsForClip === undefined ) {
  27237. actionsForClip = {
  27238. knownActions: [ action ],
  27239. actionByRoot: {}
  27240. };
  27241. action._byClipCacheIndex = 0;
  27242. actionsByClip[ clipUuid ] = actionsForClip;
  27243. } else {
  27244. const knownActions = actionsForClip.knownActions;
  27245. action._byClipCacheIndex = knownActions.length;
  27246. knownActions.push( action );
  27247. }
  27248. action._cacheIndex = actions.length;
  27249. actions.push( action );
  27250. actionsForClip.actionByRoot[ rootUuid ] = action;
  27251. }
  27252. _removeInactiveAction( action ) {
  27253. const actions = this._actions,
  27254. lastInactiveAction = actions[ actions.length - 1 ],
  27255. cacheIndex = action._cacheIndex;
  27256. lastInactiveAction._cacheIndex = cacheIndex;
  27257. actions[ cacheIndex ] = lastInactiveAction;
  27258. actions.pop();
  27259. action._cacheIndex = null;
  27260. const clipUuid = action._clip.uuid,
  27261. actionsByClip = this._actionsByClip,
  27262. actionsForClip = actionsByClip[ clipUuid ],
  27263. knownActionsForClip = actionsForClip.knownActions,
  27264. lastKnownAction =
  27265. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27266. byClipCacheIndex = action._byClipCacheIndex;
  27267. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27268. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27269. knownActionsForClip.pop();
  27270. action._byClipCacheIndex = null;
  27271. const actionByRoot = actionsForClip.actionByRoot,
  27272. rootUuid = ( action._localRoot || this._root ).uuid;
  27273. delete actionByRoot[ rootUuid ];
  27274. if ( knownActionsForClip.length === 0 ) {
  27275. delete actionsByClip[ clipUuid ];
  27276. }
  27277. this._removeInactiveBindingsForAction( action );
  27278. }
  27279. _removeInactiveBindingsForAction( action ) {
  27280. const bindings = action._propertyBindings;
  27281. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27282. const binding = bindings[ i ];
  27283. if ( -- binding.referenceCount === 0 ) {
  27284. this._removeInactiveBinding( binding );
  27285. }
  27286. }
  27287. }
  27288. _lendAction( action ) {
  27289. // [ active actions | inactive actions ]
  27290. // [ active actions >| inactive actions ]
  27291. // s a
  27292. // <-swap->
  27293. // a s
  27294. const actions = this._actions,
  27295. prevIndex = action._cacheIndex,
  27296. lastActiveIndex = this._nActiveActions ++,
  27297. firstInactiveAction = actions[ lastActiveIndex ];
  27298. action._cacheIndex = lastActiveIndex;
  27299. actions[ lastActiveIndex ] = action;
  27300. firstInactiveAction._cacheIndex = prevIndex;
  27301. actions[ prevIndex ] = firstInactiveAction;
  27302. }
  27303. _takeBackAction( action ) {
  27304. // [ active actions | inactive actions ]
  27305. // [ active actions |< inactive actions ]
  27306. // a s
  27307. // <-swap->
  27308. // s a
  27309. const actions = this._actions,
  27310. prevIndex = action._cacheIndex,
  27311. firstInactiveIndex = -- this._nActiveActions,
  27312. lastActiveAction = actions[ firstInactiveIndex ];
  27313. action._cacheIndex = firstInactiveIndex;
  27314. actions[ firstInactiveIndex ] = action;
  27315. lastActiveAction._cacheIndex = prevIndex;
  27316. actions[ prevIndex ] = lastActiveAction;
  27317. }
  27318. // Memory management for PropertyMixer objects
  27319. _addInactiveBinding( binding, rootUuid, trackName ) {
  27320. const bindingsByRoot = this._bindingsByRootAndName,
  27321. bindings = this._bindings;
  27322. let bindingByName = bindingsByRoot[ rootUuid ];
  27323. if ( bindingByName === undefined ) {
  27324. bindingByName = {};
  27325. bindingsByRoot[ rootUuid ] = bindingByName;
  27326. }
  27327. bindingByName[ trackName ] = binding;
  27328. binding._cacheIndex = bindings.length;
  27329. bindings.push( binding );
  27330. }
  27331. _removeInactiveBinding( binding ) {
  27332. const bindings = this._bindings,
  27333. propBinding = binding.binding,
  27334. rootUuid = propBinding.rootNode.uuid,
  27335. trackName = propBinding.path,
  27336. bindingsByRoot = this._bindingsByRootAndName,
  27337. bindingByName = bindingsByRoot[ rootUuid ],
  27338. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27339. cacheIndex = binding._cacheIndex;
  27340. lastInactiveBinding._cacheIndex = cacheIndex;
  27341. bindings[ cacheIndex ] = lastInactiveBinding;
  27342. bindings.pop();
  27343. delete bindingByName[ trackName ];
  27344. if ( Object.keys( bindingByName ).length === 0 ) {
  27345. delete bindingsByRoot[ rootUuid ];
  27346. }
  27347. }
  27348. _lendBinding( binding ) {
  27349. const bindings = this._bindings,
  27350. prevIndex = binding._cacheIndex,
  27351. lastActiveIndex = this._nActiveBindings ++,
  27352. firstInactiveBinding = bindings[ lastActiveIndex ];
  27353. binding._cacheIndex = lastActiveIndex;
  27354. bindings[ lastActiveIndex ] = binding;
  27355. firstInactiveBinding._cacheIndex = prevIndex;
  27356. bindings[ prevIndex ] = firstInactiveBinding;
  27357. }
  27358. _takeBackBinding( binding ) {
  27359. const bindings = this._bindings,
  27360. prevIndex = binding._cacheIndex,
  27361. firstInactiveIndex = -- this._nActiveBindings,
  27362. lastActiveBinding = bindings[ firstInactiveIndex ];
  27363. binding._cacheIndex = firstInactiveIndex;
  27364. bindings[ firstInactiveIndex ] = binding;
  27365. lastActiveBinding._cacheIndex = prevIndex;
  27366. bindings[ prevIndex ] = lastActiveBinding;
  27367. }
  27368. // Memory management of Interpolants for weight and time scale
  27369. _lendControlInterpolant() {
  27370. const interpolants = this._controlInterpolants,
  27371. lastActiveIndex = this._nActiveControlInterpolants ++;
  27372. let interpolant = interpolants[ lastActiveIndex ];
  27373. if ( interpolant === undefined ) {
  27374. interpolant = new LinearInterpolant(
  27375. new Float32Array( 2 ), new Float32Array( 2 ),
  27376. 1, this._controlInterpolantsResultBuffer );
  27377. interpolant.__cacheIndex = lastActiveIndex;
  27378. interpolants[ lastActiveIndex ] = interpolant;
  27379. }
  27380. return interpolant;
  27381. }
  27382. _takeBackControlInterpolant( interpolant ) {
  27383. const interpolants = this._controlInterpolants,
  27384. prevIndex = interpolant.__cacheIndex,
  27385. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27386. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27387. interpolant.__cacheIndex = firstInactiveIndex;
  27388. interpolants[ firstInactiveIndex ] = interpolant;
  27389. lastActiveInterpolant.__cacheIndex = prevIndex;
  27390. interpolants[ prevIndex ] = lastActiveInterpolant;
  27391. }
  27392. // return an action for a clip optionally using a custom root target
  27393. // object (this method allocates a lot of dynamic memory in case a
  27394. // previously unknown clip/root combination is specified)
  27395. clipAction( clip, optionalRoot, blendMode ) {
  27396. const root = optionalRoot || this._root,
  27397. rootUuid = root.uuid;
  27398. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  27399. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27400. const actionsForClip = this._actionsByClip[ clipUuid ];
  27401. let prototypeAction = null;
  27402. if ( blendMode === undefined ) {
  27403. if ( clipObject !== null ) {
  27404. blendMode = clipObject.blendMode;
  27405. } else {
  27406. blendMode = NormalAnimationBlendMode;
  27407. }
  27408. }
  27409. if ( actionsForClip !== undefined ) {
  27410. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  27411. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  27412. return existingAction;
  27413. }
  27414. // we know the clip, so we don't have to parse all
  27415. // the bindings again but can just copy
  27416. prototypeAction = actionsForClip.knownActions[ 0 ];
  27417. // also, take the clip from the prototype action
  27418. if ( clipObject === null )
  27419. clipObject = prototypeAction._clip;
  27420. }
  27421. // clip must be known when specified via string
  27422. if ( clipObject === null ) return null;
  27423. // allocate all resources required to run it
  27424. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  27425. this._bindAction( newAction, prototypeAction );
  27426. // and make the action known to the memory manager
  27427. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27428. return newAction;
  27429. }
  27430. // get an existing action
  27431. existingAction( clip, optionalRoot ) {
  27432. const root = optionalRoot || this._root,
  27433. rootUuid = root.uuid,
  27434. clipObject = typeof clip === 'string' ?
  27435. AnimationClip.findByName( root, clip ) : clip,
  27436. clipUuid = clipObject ? clipObject.uuid : clip,
  27437. actionsForClip = this._actionsByClip[ clipUuid ];
  27438. if ( actionsForClip !== undefined ) {
  27439. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27440. }
  27441. return null;
  27442. }
  27443. // deactivates all previously scheduled actions
  27444. stopAllAction() {
  27445. const actions = this._actions,
  27446. nActions = this._nActiveActions;
  27447. for ( let i = nActions - 1; i >= 0; -- i ) {
  27448. actions[ i ].stop();
  27449. }
  27450. return this;
  27451. }
  27452. // advance the time and update apply the animation
  27453. update( deltaTime ) {
  27454. deltaTime *= this.timeScale;
  27455. const actions = this._actions,
  27456. nActions = this._nActiveActions,
  27457. time = this.time += deltaTime,
  27458. timeDirection = Math.sign( deltaTime ),
  27459. accuIndex = this._accuIndex ^= 1;
  27460. // run active actions
  27461. for ( let i = 0; i !== nActions; ++ i ) {
  27462. const action = actions[ i ];
  27463. action._update( time, deltaTime, timeDirection, accuIndex );
  27464. }
  27465. // update scene graph
  27466. const bindings = this._bindings,
  27467. nBindings = this._nActiveBindings;
  27468. for ( let i = 0; i !== nBindings; ++ i ) {
  27469. bindings[ i ].apply( accuIndex );
  27470. }
  27471. return this;
  27472. }
  27473. // Allows you to seek to a specific time in an animation.
  27474. setTime( timeInSeconds ) {
  27475. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27476. for ( let i = 0; i < this._actions.length; i ++ ) {
  27477. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27478. }
  27479. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  27480. }
  27481. // return this mixer's root target object
  27482. getRoot() {
  27483. return this._root;
  27484. }
  27485. // free all resources specific to a particular clip
  27486. uncacheClip( clip ) {
  27487. const actions = this._actions,
  27488. clipUuid = clip.uuid,
  27489. actionsByClip = this._actionsByClip,
  27490. actionsForClip = actionsByClip[ clipUuid ];
  27491. if ( actionsForClip !== undefined ) {
  27492. // note: just calling _removeInactiveAction would mess up the
  27493. // iteration state and also require updating the state we can
  27494. // just throw away
  27495. const actionsToRemove = actionsForClip.knownActions;
  27496. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27497. const action = actionsToRemove[ i ];
  27498. this._deactivateAction( action );
  27499. const cacheIndex = action._cacheIndex,
  27500. lastInactiveAction = actions[ actions.length - 1 ];
  27501. action._cacheIndex = null;
  27502. action._byClipCacheIndex = null;
  27503. lastInactiveAction._cacheIndex = cacheIndex;
  27504. actions[ cacheIndex ] = lastInactiveAction;
  27505. actions.pop();
  27506. this._removeInactiveBindingsForAction( action );
  27507. }
  27508. delete actionsByClip[ clipUuid ];
  27509. }
  27510. }
  27511. // free all resources specific to a particular root target object
  27512. uncacheRoot( root ) {
  27513. const rootUuid = root.uuid,
  27514. actionsByClip = this._actionsByClip;
  27515. for ( const clipUuid in actionsByClip ) {
  27516. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27517. action = actionByRoot[ rootUuid ];
  27518. if ( action !== undefined ) {
  27519. this._deactivateAction( action );
  27520. this._removeInactiveAction( action );
  27521. }
  27522. }
  27523. const bindingsByRoot = this._bindingsByRootAndName,
  27524. bindingByName = bindingsByRoot[ rootUuid ];
  27525. if ( bindingByName !== undefined ) {
  27526. for ( const trackName in bindingByName ) {
  27527. const binding = bindingByName[ trackName ];
  27528. binding.restoreOriginalState();
  27529. this._removeInactiveBinding( binding );
  27530. }
  27531. }
  27532. }
  27533. // remove a targeted clip from the cache
  27534. uncacheAction( clip, optionalRoot ) {
  27535. const action = this.existingAction( clip, optionalRoot );
  27536. if ( action !== null ) {
  27537. this._deactivateAction( action );
  27538. this._removeInactiveAction( action );
  27539. }
  27540. }
  27541. }
  27542. AnimationMixer.prototype._controlInterpolantsResultBuffer = new Float32Array( 1 );
  27543. class Uniform {
  27544. constructor( value ) {
  27545. if ( typeof value === 'string' ) {
  27546. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27547. value = arguments[ 1 ];
  27548. }
  27549. this.value = value;
  27550. }
  27551. clone() {
  27552. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27553. }
  27554. }
  27555. class InstancedInterleavedBuffer extends InterleavedBuffer {
  27556. constructor( array, stride, meshPerAttribute = 1 ) {
  27557. super( array, stride );
  27558. this.meshPerAttribute = meshPerAttribute;
  27559. }
  27560. copy( source ) {
  27561. super.copy( source );
  27562. this.meshPerAttribute = source.meshPerAttribute;
  27563. return this;
  27564. }
  27565. clone( data ) {
  27566. const ib = super.clone( data );
  27567. ib.meshPerAttribute = this.meshPerAttribute;
  27568. return ib;
  27569. }
  27570. toJSON( data ) {
  27571. const json = super.toJSON( data );
  27572. json.isInstancedInterleavedBuffer = true;
  27573. json.meshPerAttribute = this.meshPerAttribute;
  27574. return json;
  27575. }
  27576. }
  27577. InstancedInterleavedBuffer.prototype.isInstancedInterleavedBuffer = true;
  27578. class GLBufferAttribute {
  27579. constructor( buffer, type, itemSize, elementSize, count ) {
  27580. this.buffer = buffer;
  27581. this.type = type;
  27582. this.itemSize = itemSize;
  27583. this.elementSize = elementSize;
  27584. this.count = count;
  27585. this.version = 0;
  27586. }
  27587. set needsUpdate( value ) {
  27588. if ( value === true ) this.version ++;
  27589. }
  27590. setBuffer( buffer ) {
  27591. this.buffer = buffer;
  27592. return this;
  27593. }
  27594. setType( type, elementSize ) {
  27595. this.type = type;
  27596. this.elementSize = elementSize;
  27597. return this;
  27598. }
  27599. setItemSize( itemSize ) {
  27600. this.itemSize = itemSize;
  27601. return this;
  27602. }
  27603. setCount( count ) {
  27604. this.count = count;
  27605. return this;
  27606. }
  27607. }
  27608. GLBufferAttribute.prototype.isGLBufferAttribute = true;
  27609. class Raycaster {
  27610. constructor( origin, direction, near = 0, far = Infinity ) {
  27611. this.ray = new Ray( origin, direction );
  27612. // direction is assumed to be normalized (for accurate distance calculations)
  27613. this.near = near;
  27614. this.far = far;
  27615. this.camera = null;
  27616. this.layers = new Layers();
  27617. this.params = {
  27618. Mesh: {},
  27619. Line: { threshold: 1 },
  27620. LOD: {},
  27621. Points: { threshold: 1 },
  27622. Sprite: {}
  27623. };
  27624. }
  27625. set( origin, direction ) {
  27626. // direction is assumed to be normalized (for accurate distance calculations)
  27627. this.ray.set( origin, direction );
  27628. }
  27629. setFromCamera( coords, camera ) {
  27630. if ( camera && camera.isPerspectiveCamera ) {
  27631. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27632. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27633. this.camera = camera;
  27634. } else if ( camera && camera.isOrthographicCamera ) {
  27635. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27636. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27637. this.camera = camera;
  27638. } else {
  27639. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  27640. }
  27641. }
  27642. intersectObject( object, recursive = true, intersects = [] ) {
  27643. intersectObject( object, this, intersects, recursive );
  27644. intersects.sort( ascSort );
  27645. return intersects;
  27646. }
  27647. intersectObjects( objects, recursive = true, intersects = [] ) {
  27648. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  27649. intersectObject( objects[ i ], this, intersects, recursive );
  27650. }
  27651. intersects.sort( ascSort );
  27652. return intersects;
  27653. }
  27654. }
  27655. function ascSort( a, b ) {
  27656. return a.distance - b.distance;
  27657. }
  27658. function intersectObject( object, raycaster, intersects, recursive ) {
  27659. if ( object.layers.test( raycaster.layers ) ) {
  27660. object.raycast( raycaster, intersects );
  27661. }
  27662. if ( recursive === true ) {
  27663. const children = object.children;
  27664. for ( let i = 0, l = children.length; i < l; i ++ ) {
  27665. intersectObject( children[ i ], raycaster, intersects, true );
  27666. }
  27667. }
  27668. }
  27669. /**
  27670. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27671. *
  27672. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27673. * The azimuthal angle (theta) is measured from the positive z-axis.
  27674. */
  27675. class Spherical {
  27676. constructor( radius = 1, phi = 0, theta = 0 ) {
  27677. this.radius = radius;
  27678. this.phi = phi; // polar angle
  27679. this.theta = theta; // azimuthal angle
  27680. return this;
  27681. }
  27682. set( radius, phi, theta ) {
  27683. this.radius = radius;
  27684. this.phi = phi;
  27685. this.theta = theta;
  27686. return this;
  27687. }
  27688. copy( other ) {
  27689. this.radius = other.radius;
  27690. this.phi = other.phi;
  27691. this.theta = other.theta;
  27692. return this;
  27693. }
  27694. // restrict phi to be betwee EPS and PI-EPS
  27695. makeSafe() {
  27696. const EPS = 0.000001;
  27697. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27698. return this;
  27699. }
  27700. setFromVector3( v ) {
  27701. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27702. }
  27703. setFromCartesianCoords( x, y, z ) {
  27704. this.radius = Math.sqrt( x * x + y * y + z * z );
  27705. if ( this.radius === 0 ) {
  27706. this.theta = 0;
  27707. this.phi = 0;
  27708. } else {
  27709. this.theta = Math.atan2( x, z );
  27710. this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );
  27711. }
  27712. return this;
  27713. }
  27714. clone() {
  27715. return new this.constructor().copy( this );
  27716. }
  27717. }
  27718. /**
  27719. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27720. */
  27721. class Cylindrical {
  27722. constructor( radius = 1, theta = 0, y = 0 ) {
  27723. this.radius = radius; // distance from the origin to a point in the x-z plane
  27724. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27725. this.y = y; // height above the x-z plane
  27726. return this;
  27727. }
  27728. set( radius, theta, y ) {
  27729. this.radius = radius;
  27730. this.theta = theta;
  27731. this.y = y;
  27732. return this;
  27733. }
  27734. copy( other ) {
  27735. this.radius = other.radius;
  27736. this.theta = other.theta;
  27737. this.y = other.y;
  27738. return this;
  27739. }
  27740. setFromVector3( v ) {
  27741. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27742. }
  27743. setFromCartesianCoords( x, y, z ) {
  27744. this.radius = Math.sqrt( x * x + z * z );
  27745. this.theta = Math.atan2( x, z );
  27746. this.y = y;
  27747. return this;
  27748. }
  27749. clone() {
  27750. return new this.constructor().copy( this );
  27751. }
  27752. }
  27753. const _vector$4 = /*@__PURE__*/ new Vector2();
  27754. class Box2 {
  27755. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  27756. this.min = min;
  27757. this.max = max;
  27758. }
  27759. set( min, max ) {
  27760. this.min.copy( min );
  27761. this.max.copy( max );
  27762. return this;
  27763. }
  27764. setFromPoints( points ) {
  27765. this.makeEmpty();
  27766. for ( let i = 0, il = points.length; i < il; i ++ ) {
  27767. this.expandByPoint( points[ i ] );
  27768. }
  27769. return this;
  27770. }
  27771. setFromCenterAndSize( center, size ) {
  27772. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  27773. this.min.copy( center ).sub( halfSize );
  27774. this.max.copy( center ).add( halfSize );
  27775. return this;
  27776. }
  27777. clone() {
  27778. return new this.constructor().copy( this );
  27779. }
  27780. copy( box ) {
  27781. this.min.copy( box.min );
  27782. this.max.copy( box.max );
  27783. return this;
  27784. }
  27785. makeEmpty() {
  27786. this.min.x = this.min.y = + Infinity;
  27787. this.max.x = this.max.y = - Infinity;
  27788. return this;
  27789. }
  27790. isEmpty() {
  27791. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27792. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27793. }
  27794. getCenter( target ) {
  27795. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27796. }
  27797. getSize( target ) {
  27798. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27799. }
  27800. expandByPoint( point ) {
  27801. this.min.min( point );
  27802. this.max.max( point );
  27803. return this;
  27804. }
  27805. expandByVector( vector ) {
  27806. this.min.sub( vector );
  27807. this.max.add( vector );
  27808. return this;
  27809. }
  27810. expandByScalar( scalar ) {
  27811. this.min.addScalar( - scalar );
  27812. this.max.addScalar( scalar );
  27813. return this;
  27814. }
  27815. containsPoint( point ) {
  27816. return point.x < this.min.x || point.x > this.max.x ||
  27817. point.y < this.min.y || point.y > this.max.y ? false : true;
  27818. }
  27819. containsBox( box ) {
  27820. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27821. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27822. }
  27823. getParameter( point, target ) {
  27824. // This can potentially have a divide by zero if the box
  27825. // has a size dimension of 0.
  27826. return target.set(
  27827. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27828. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27829. );
  27830. }
  27831. intersectsBox( box ) {
  27832. // using 4 splitting planes to rule out intersections
  27833. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27834. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27835. }
  27836. clampPoint( point, target ) {
  27837. return target.copy( point ).clamp( this.min, this.max );
  27838. }
  27839. distanceToPoint( point ) {
  27840. const clampedPoint = _vector$4.copy( point ).clamp( this.min, this.max );
  27841. return clampedPoint.sub( point ).length();
  27842. }
  27843. intersect( box ) {
  27844. this.min.max( box.min );
  27845. this.max.min( box.max );
  27846. return this;
  27847. }
  27848. union( box ) {
  27849. this.min.min( box.min );
  27850. this.max.max( box.max );
  27851. return this;
  27852. }
  27853. translate( offset ) {
  27854. this.min.add( offset );
  27855. this.max.add( offset );
  27856. return this;
  27857. }
  27858. equals( box ) {
  27859. return box.min.equals( this.min ) && box.max.equals( this.max );
  27860. }
  27861. }
  27862. Box2.prototype.isBox2 = true;
  27863. const _startP = /*@__PURE__*/ new Vector3();
  27864. const _startEnd = /*@__PURE__*/ new Vector3();
  27865. class Line3 {
  27866. constructor( start = new Vector3(), end = new Vector3() ) {
  27867. this.start = start;
  27868. this.end = end;
  27869. }
  27870. set( start, end ) {
  27871. this.start.copy( start );
  27872. this.end.copy( end );
  27873. return this;
  27874. }
  27875. copy( line ) {
  27876. this.start.copy( line.start );
  27877. this.end.copy( line.end );
  27878. return this;
  27879. }
  27880. getCenter( target ) {
  27881. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27882. }
  27883. delta( target ) {
  27884. return target.subVectors( this.end, this.start );
  27885. }
  27886. distanceSq() {
  27887. return this.start.distanceToSquared( this.end );
  27888. }
  27889. distance() {
  27890. return this.start.distanceTo( this.end );
  27891. }
  27892. at( t, target ) {
  27893. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27894. }
  27895. closestPointToPointParameter( point, clampToLine ) {
  27896. _startP.subVectors( point, this.start );
  27897. _startEnd.subVectors( this.end, this.start );
  27898. const startEnd2 = _startEnd.dot( _startEnd );
  27899. const startEnd_startP = _startEnd.dot( _startP );
  27900. let t = startEnd_startP / startEnd2;
  27901. if ( clampToLine ) {
  27902. t = clamp( t, 0, 1 );
  27903. }
  27904. return t;
  27905. }
  27906. closestPointToPoint( point, clampToLine, target ) {
  27907. const t = this.closestPointToPointParameter( point, clampToLine );
  27908. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27909. }
  27910. applyMatrix4( matrix ) {
  27911. this.start.applyMatrix4( matrix );
  27912. this.end.applyMatrix4( matrix );
  27913. return this;
  27914. }
  27915. equals( line ) {
  27916. return line.start.equals( this.start ) && line.end.equals( this.end );
  27917. }
  27918. clone() {
  27919. return new this.constructor().copy( this );
  27920. }
  27921. }
  27922. class ImmediateRenderObject extends Object3D {
  27923. constructor( material ) {
  27924. super();
  27925. this.material = material;
  27926. this.render = function ( /* renderCallback */ ) {};
  27927. this.hasPositions = false;
  27928. this.hasNormals = false;
  27929. this.hasColors = false;
  27930. this.hasUvs = false;
  27931. this.positionArray = null;
  27932. this.normalArray = null;
  27933. this.colorArray = null;
  27934. this.uvArray = null;
  27935. this.count = 0;
  27936. }
  27937. }
  27938. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27939. const _vector$3 = /*@__PURE__*/ new Vector3();
  27940. class SpotLightHelper extends Object3D {
  27941. constructor( light, color ) {
  27942. super();
  27943. this.light = light;
  27944. this.light.updateMatrixWorld();
  27945. this.matrix = light.matrixWorld;
  27946. this.matrixAutoUpdate = false;
  27947. this.color = color;
  27948. const geometry = new BufferGeometry();
  27949. const positions = [
  27950. 0, 0, 0, 0, 0, 1,
  27951. 0, 0, 0, 1, 0, 1,
  27952. 0, 0, 0, - 1, 0, 1,
  27953. 0, 0, 0, 0, 1, 1,
  27954. 0, 0, 0, 0, - 1, 1
  27955. ];
  27956. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27957. const p1 = ( i / l ) * Math.PI * 2;
  27958. const p2 = ( j / l ) * Math.PI * 2;
  27959. positions.push(
  27960. Math.cos( p1 ), Math.sin( p1 ), 1,
  27961. Math.cos( p2 ), Math.sin( p2 ), 1
  27962. );
  27963. }
  27964. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27965. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  27966. this.cone = new LineSegments( geometry, material );
  27967. this.add( this.cone );
  27968. this.update();
  27969. }
  27970. dispose() {
  27971. this.cone.geometry.dispose();
  27972. this.cone.material.dispose();
  27973. }
  27974. update() {
  27975. this.light.updateMatrixWorld();
  27976. const coneLength = this.light.distance ? this.light.distance : 1000;
  27977. const coneWidth = coneLength * Math.tan( this.light.angle );
  27978. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27979. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  27980. this.cone.lookAt( _vector$3 );
  27981. if ( this.color !== undefined ) {
  27982. this.cone.material.color.set( this.color );
  27983. } else {
  27984. this.cone.material.color.copy( this.light.color );
  27985. }
  27986. }
  27987. }
  27988. const _vector$2 = /*@__PURE__*/ new Vector3();
  27989. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  27990. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  27991. class SkeletonHelper extends LineSegments {
  27992. constructor( object ) {
  27993. const bones = getBoneList( object );
  27994. const geometry = new BufferGeometry();
  27995. const vertices = [];
  27996. const colors = [];
  27997. const color1 = new Color( 0, 0, 1 );
  27998. const color2 = new Color( 0, 1, 0 );
  27999. for ( let i = 0; i < bones.length; i ++ ) {
  28000. const bone = bones[ i ];
  28001. if ( bone.parent && bone.parent.isBone ) {
  28002. vertices.push( 0, 0, 0 );
  28003. vertices.push( 0, 0, 0 );
  28004. colors.push( color1.r, color1.g, color1.b );
  28005. colors.push( color2.r, color2.g, color2.b );
  28006. }
  28007. }
  28008. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28009. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28010. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  28011. super( geometry, material );
  28012. this.type = 'SkeletonHelper';
  28013. this.isSkeletonHelper = true;
  28014. this.root = object;
  28015. this.bones = bones;
  28016. this.matrix = object.matrixWorld;
  28017. this.matrixAutoUpdate = false;
  28018. }
  28019. updateMatrixWorld( force ) {
  28020. const bones = this.bones;
  28021. const geometry = this.geometry;
  28022. const position = geometry.getAttribute( 'position' );
  28023. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  28024. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  28025. const bone = bones[ i ];
  28026. if ( bone.parent && bone.parent.isBone ) {
  28027. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  28028. _vector$2.setFromMatrixPosition( _boneMatrix );
  28029. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  28030. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  28031. _vector$2.setFromMatrixPosition( _boneMatrix );
  28032. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  28033. j += 2;
  28034. }
  28035. }
  28036. geometry.getAttribute( 'position' ).needsUpdate = true;
  28037. super.updateMatrixWorld( force );
  28038. }
  28039. }
  28040. function getBoneList( object ) {
  28041. const boneList = [];
  28042. if ( object && object.isBone ) {
  28043. boneList.push( object );
  28044. }
  28045. for ( let i = 0; i < object.children.length; i ++ ) {
  28046. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28047. }
  28048. return boneList;
  28049. }
  28050. class PointLightHelper extends Mesh {
  28051. constructor( light, sphereSize, color ) {
  28052. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  28053. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28054. super( geometry, material );
  28055. this.light = light;
  28056. this.light.updateMatrixWorld();
  28057. this.color = color;
  28058. this.type = 'PointLightHelper';
  28059. this.matrix = this.light.matrixWorld;
  28060. this.matrixAutoUpdate = false;
  28061. this.update();
  28062. /*
  28063. // TODO: delete this comment?
  28064. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28065. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28066. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28067. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28068. const d = light.distance;
  28069. if ( d === 0.0 ) {
  28070. this.lightDistance.visible = false;
  28071. } else {
  28072. this.lightDistance.scale.set( d, d, d );
  28073. }
  28074. this.add( this.lightDistance );
  28075. */
  28076. }
  28077. dispose() {
  28078. this.geometry.dispose();
  28079. this.material.dispose();
  28080. }
  28081. update() {
  28082. if ( this.color !== undefined ) {
  28083. this.material.color.set( this.color );
  28084. } else {
  28085. this.material.color.copy( this.light.color );
  28086. }
  28087. /*
  28088. const d = this.light.distance;
  28089. if ( d === 0.0 ) {
  28090. this.lightDistance.visible = false;
  28091. } else {
  28092. this.lightDistance.visible = true;
  28093. this.lightDistance.scale.set( d, d, d );
  28094. }
  28095. */
  28096. }
  28097. }
  28098. const _vector$1 = /*@__PURE__*/ new Vector3();
  28099. const _color1 = /*@__PURE__*/ new Color();
  28100. const _color2 = /*@__PURE__*/ new Color();
  28101. class HemisphereLightHelper extends Object3D {
  28102. constructor( light, size, color ) {
  28103. super();
  28104. this.light = light;
  28105. this.light.updateMatrixWorld();
  28106. this.matrix = light.matrixWorld;
  28107. this.matrixAutoUpdate = false;
  28108. this.color = color;
  28109. const geometry = new OctahedronGeometry( size );
  28110. geometry.rotateY( Math.PI * 0.5 );
  28111. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28112. if ( this.color === undefined ) this.material.vertexColors = true;
  28113. const position = geometry.getAttribute( 'position' );
  28114. const colors = new Float32Array( position.count * 3 );
  28115. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28116. this.add( new Mesh( geometry, this.material ) );
  28117. this.update();
  28118. }
  28119. dispose() {
  28120. this.children[ 0 ].geometry.dispose();
  28121. this.children[ 0 ].material.dispose();
  28122. }
  28123. update() {
  28124. const mesh = this.children[ 0 ];
  28125. if ( this.color !== undefined ) {
  28126. this.material.color.set( this.color );
  28127. } else {
  28128. const colors = mesh.geometry.getAttribute( 'color' );
  28129. _color1.copy( this.light.color );
  28130. _color2.copy( this.light.groundColor );
  28131. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  28132. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  28133. colors.setXYZ( i, color.r, color.g, color.b );
  28134. }
  28135. colors.needsUpdate = true;
  28136. }
  28137. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28138. }
  28139. }
  28140. class GridHelper extends LineSegments {
  28141. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  28142. color1 = new Color( color1 );
  28143. color2 = new Color( color2 );
  28144. const center = divisions / 2;
  28145. const step = size / divisions;
  28146. const halfSize = size / 2;
  28147. const vertices = [], colors = [];
  28148. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28149. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28150. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28151. const color = i === center ? color1 : color2;
  28152. color.toArray( colors, j ); j += 3;
  28153. color.toArray( colors, j ); j += 3;
  28154. color.toArray( colors, j ); j += 3;
  28155. color.toArray( colors, j ); j += 3;
  28156. }
  28157. const geometry = new BufferGeometry();
  28158. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28159. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28160. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28161. super( geometry, material );
  28162. this.type = 'GridHelper';
  28163. }
  28164. }
  28165. class PolarGridHelper extends LineSegments {
  28166. constructor( radius = 10, radials = 16, circles = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  28167. color1 = new Color( color1 );
  28168. color2 = new Color( color2 );
  28169. const vertices = [];
  28170. const colors = [];
  28171. // create the radials
  28172. for ( let i = 0; i <= radials; i ++ ) {
  28173. const v = ( i / radials ) * ( Math.PI * 2 );
  28174. const x = Math.sin( v ) * radius;
  28175. const z = Math.cos( v ) * radius;
  28176. vertices.push( 0, 0, 0 );
  28177. vertices.push( x, 0, z );
  28178. const color = ( i & 1 ) ? color1 : color2;
  28179. colors.push( color.r, color.g, color.b );
  28180. colors.push( color.r, color.g, color.b );
  28181. }
  28182. // create the circles
  28183. for ( let i = 0; i <= circles; i ++ ) {
  28184. const color = ( i & 1 ) ? color1 : color2;
  28185. const r = radius - ( radius / circles * i );
  28186. for ( let j = 0; j < divisions; j ++ ) {
  28187. // first vertex
  28188. let v = ( j / divisions ) * ( Math.PI * 2 );
  28189. let x = Math.sin( v ) * r;
  28190. let z = Math.cos( v ) * r;
  28191. vertices.push( x, 0, z );
  28192. colors.push( color.r, color.g, color.b );
  28193. // second vertex
  28194. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28195. x = Math.sin( v ) * r;
  28196. z = Math.cos( v ) * r;
  28197. vertices.push( x, 0, z );
  28198. colors.push( color.r, color.g, color.b );
  28199. }
  28200. }
  28201. const geometry = new BufferGeometry();
  28202. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28203. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28204. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28205. super( geometry, material );
  28206. this.type = 'PolarGridHelper';
  28207. }
  28208. }
  28209. const _v1 = /*@__PURE__*/ new Vector3();
  28210. const _v2 = /*@__PURE__*/ new Vector3();
  28211. const _v3 = /*@__PURE__*/ new Vector3();
  28212. class DirectionalLightHelper extends Object3D {
  28213. constructor( light, size, color ) {
  28214. super();
  28215. this.light = light;
  28216. this.light.updateMatrixWorld();
  28217. this.matrix = light.matrixWorld;
  28218. this.matrixAutoUpdate = false;
  28219. this.color = color;
  28220. if ( size === undefined ) size = 1;
  28221. let geometry = new BufferGeometry();
  28222. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28223. - size, size, 0,
  28224. size, size, 0,
  28225. size, - size, 0,
  28226. - size, - size, 0,
  28227. - size, size, 0
  28228. ], 3 ) );
  28229. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28230. this.lightPlane = new Line( geometry, material );
  28231. this.add( this.lightPlane );
  28232. geometry = new BufferGeometry();
  28233. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28234. this.targetLine = new Line( geometry, material );
  28235. this.add( this.targetLine );
  28236. this.update();
  28237. }
  28238. dispose() {
  28239. this.lightPlane.geometry.dispose();
  28240. this.lightPlane.material.dispose();
  28241. this.targetLine.geometry.dispose();
  28242. this.targetLine.material.dispose();
  28243. }
  28244. update() {
  28245. _v1.setFromMatrixPosition( this.light.matrixWorld );
  28246. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  28247. _v3.subVectors( _v2, _v1 );
  28248. this.lightPlane.lookAt( _v2 );
  28249. if ( this.color !== undefined ) {
  28250. this.lightPlane.material.color.set( this.color );
  28251. this.targetLine.material.color.set( this.color );
  28252. } else {
  28253. this.lightPlane.material.color.copy( this.light.color );
  28254. this.targetLine.material.color.copy( this.light.color );
  28255. }
  28256. this.targetLine.lookAt( _v2 );
  28257. this.targetLine.scale.z = _v3.length();
  28258. }
  28259. }
  28260. const _vector = /*@__PURE__*/ new Vector3();
  28261. const _camera = /*@__PURE__*/ new Camera();
  28262. /**
  28263. * - shows frustum, line of sight and up of the camera
  28264. * - suitable for fast updates
  28265. * - based on frustum visualization in lightgl.js shadowmap example
  28266. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28267. */
  28268. class CameraHelper extends LineSegments {
  28269. constructor( camera ) {
  28270. const geometry = new BufferGeometry();
  28271. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  28272. const vertices = [];
  28273. const colors = [];
  28274. const pointMap = {};
  28275. // colors
  28276. const colorFrustum = new Color( 0xffaa00 );
  28277. const colorCone = new Color( 0xff0000 );
  28278. const colorUp = new Color( 0x00aaff );
  28279. const colorTarget = new Color( 0xffffff );
  28280. const colorCross = new Color( 0x333333 );
  28281. // near
  28282. addLine( 'n1', 'n2', colorFrustum );
  28283. addLine( 'n2', 'n4', colorFrustum );
  28284. addLine( 'n4', 'n3', colorFrustum );
  28285. addLine( 'n3', 'n1', colorFrustum );
  28286. // far
  28287. addLine( 'f1', 'f2', colorFrustum );
  28288. addLine( 'f2', 'f4', colorFrustum );
  28289. addLine( 'f4', 'f3', colorFrustum );
  28290. addLine( 'f3', 'f1', colorFrustum );
  28291. // sides
  28292. addLine( 'n1', 'f1', colorFrustum );
  28293. addLine( 'n2', 'f2', colorFrustum );
  28294. addLine( 'n3', 'f3', colorFrustum );
  28295. addLine( 'n4', 'f4', colorFrustum );
  28296. // cone
  28297. addLine( 'p', 'n1', colorCone );
  28298. addLine( 'p', 'n2', colorCone );
  28299. addLine( 'p', 'n3', colorCone );
  28300. addLine( 'p', 'n4', colorCone );
  28301. // up
  28302. addLine( 'u1', 'u2', colorUp );
  28303. addLine( 'u2', 'u3', colorUp );
  28304. addLine( 'u3', 'u1', colorUp );
  28305. // target
  28306. addLine( 'c', 't', colorTarget );
  28307. addLine( 'p', 'c', colorCross );
  28308. // cross
  28309. addLine( 'cn1', 'cn2', colorCross );
  28310. addLine( 'cn3', 'cn4', colorCross );
  28311. addLine( 'cf1', 'cf2', colorCross );
  28312. addLine( 'cf3', 'cf4', colorCross );
  28313. function addLine( a, b, color ) {
  28314. addPoint( a, color );
  28315. addPoint( b, color );
  28316. }
  28317. function addPoint( id, color ) {
  28318. vertices.push( 0, 0, 0 );
  28319. colors.push( color.r, color.g, color.b );
  28320. if ( pointMap[ id ] === undefined ) {
  28321. pointMap[ id ] = [];
  28322. }
  28323. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28324. }
  28325. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28326. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28327. super( geometry, material );
  28328. this.type = 'CameraHelper';
  28329. this.camera = camera;
  28330. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28331. this.matrix = camera.matrixWorld;
  28332. this.matrixAutoUpdate = false;
  28333. this.pointMap = pointMap;
  28334. this.update();
  28335. }
  28336. update() {
  28337. const geometry = this.geometry;
  28338. const pointMap = this.pointMap;
  28339. const w = 1, h = 1;
  28340. // we need just camera projection matrix inverse
  28341. // world matrix must be identity
  28342. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28343. // center / target
  28344. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28345. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28346. // near
  28347. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28348. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28349. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28350. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28351. // far
  28352. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28353. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28354. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28355. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28356. // up
  28357. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28358. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28359. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28360. // cross
  28361. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28362. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28363. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28364. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28365. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28366. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28367. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28368. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28369. geometry.getAttribute( 'position' ).needsUpdate = true;
  28370. }
  28371. dispose() {
  28372. this.geometry.dispose();
  28373. this.material.dispose();
  28374. }
  28375. }
  28376. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28377. _vector.set( x, y, z ).unproject( camera );
  28378. const points = pointMap[ point ];
  28379. if ( points !== undefined ) {
  28380. const position = geometry.getAttribute( 'position' );
  28381. for ( let i = 0, l = points.length; i < l; i ++ ) {
  28382. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  28383. }
  28384. }
  28385. }
  28386. const _box = /*@__PURE__*/ new Box3();
  28387. class BoxHelper extends LineSegments {
  28388. constructor( object, color = 0xffff00 ) {
  28389. 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 ] );
  28390. const positions = new Float32Array( 8 * 3 );
  28391. const geometry = new BufferGeometry();
  28392. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28393. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28394. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28395. this.object = object;
  28396. this.type = 'BoxHelper';
  28397. this.matrixAutoUpdate = false;
  28398. this.update();
  28399. }
  28400. update( object ) {
  28401. if ( object !== undefined ) {
  28402. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28403. }
  28404. if ( this.object !== undefined ) {
  28405. _box.setFromObject( this.object );
  28406. }
  28407. if ( _box.isEmpty() ) return;
  28408. const min = _box.min;
  28409. const max = _box.max;
  28410. /*
  28411. 5____4
  28412. 1/___0/|
  28413. | 6__|_7
  28414. 2/___3/
  28415. 0: max.x, max.y, max.z
  28416. 1: min.x, max.y, max.z
  28417. 2: min.x, min.y, max.z
  28418. 3: max.x, min.y, max.z
  28419. 4: max.x, max.y, min.z
  28420. 5: min.x, max.y, min.z
  28421. 6: min.x, min.y, min.z
  28422. 7: max.x, min.y, min.z
  28423. */
  28424. const position = this.geometry.attributes.position;
  28425. const array = position.array;
  28426. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28427. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28428. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28429. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28430. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28431. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28432. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28433. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28434. position.needsUpdate = true;
  28435. this.geometry.computeBoundingSphere();
  28436. }
  28437. setFromObject( object ) {
  28438. this.object = object;
  28439. this.update();
  28440. return this;
  28441. }
  28442. copy( source ) {
  28443. LineSegments.prototype.copy.call( this, source );
  28444. this.object = source.object;
  28445. return this;
  28446. }
  28447. }
  28448. class Box3Helper extends LineSegments {
  28449. constructor( box, color = 0xffff00 ) {
  28450. 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 ] );
  28451. 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 ];
  28452. const geometry = new BufferGeometry();
  28453. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28454. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28455. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28456. this.box = box;
  28457. this.type = 'Box3Helper';
  28458. this.geometry.computeBoundingSphere();
  28459. }
  28460. updateMatrixWorld( force ) {
  28461. const box = this.box;
  28462. if ( box.isEmpty() ) return;
  28463. box.getCenter( this.position );
  28464. box.getSize( this.scale );
  28465. this.scale.multiplyScalar( 0.5 );
  28466. super.updateMatrixWorld( force );
  28467. }
  28468. }
  28469. class PlaneHelper extends Line {
  28470. constructor( plane, size = 1, hex = 0xffff00 ) {
  28471. const color = hex;
  28472. 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, 0, 0, 1, 0, 0, 0 ];
  28473. const geometry = new BufferGeometry();
  28474. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28475. geometry.computeBoundingSphere();
  28476. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28477. this.type = 'PlaneHelper';
  28478. this.plane = plane;
  28479. this.size = size;
  28480. const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28481. const geometry2 = new BufferGeometry();
  28482. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28483. geometry2.computeBoundingSphere();
  28484. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28485. }
  28486. updateMatrixWorld( force ) {
  28487. let scale = - this.plane.constant;
  28488. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28489. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28490. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28491. this.lookAt( this.plane.normal );
  28492. super.updateMatrixWorld( force );
  28493. }
  28494. }
  28495. const _axis = /*@__PURE__*/ new Vector3();
  28496. let _lineGeometry, _coneGeometry;
  28497. class ArrowHelper extends Object3D {
  28498. // dir is assumed to be normalized
  28499. 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 ) {
  28500. super();
  28501. this.type = 'ArrowHelper';
  28502. if ( _lineGeometry === undefined ) {
  28503. _lineGeometry = new BufferGeometry();
  28504. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28505. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  28506. _coneGeometry.translate( 0, - 0.5, 0 );
  28507. }
  28508. this.position.copy( origin );
  28509. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28510. this.line.matrixAutoUpdate = false;
  28511. this.add( this.line );
  28512. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28513. this.cone.matrixAutoUpdate = false;
  28514. this.add( this.cone );
  28515. this.setDirection( dir );
  28516. this.setLength( length, headLength, headWidth );
  28517. }
  28518. setDirection( dir ) {
  28519. // dir is assumed to be normalized
  28520. if ( dir.y > 0.99999 ) {
  28521. this.quaternion.set( 0, 0, 0, 1 );
  28522. } else if ( dir.y < - 0.99999 ) {
  28523. this.quaternion.set( 1, 0, 0, 0 );
  28524. } else {
  28525. _axis.set( dir.z, 0, - dir.x ).normalize();
  28526. const radians = Math.acos( dir.y );
  28527. this.quaternion.setFromAxisAngle( _axis, radians );
  28528. }
  28529. }
  28530. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  28531. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28532. this.line.updateMatrix();
  28533. this.cone.scale.set( headWidth, headLength, headWidth );
  28534. this.cone.position.y = length;
  28535. this.cone.updateMatrix();
  28536. }
  28537. setColor( color ) {
  28538. this.line.material.color.set( color );
  28539. this.cone.material.color.set( color );
  28540. }
  28541. copy( source ) {
  28542. super.copy( source, false );
  28543. this.line.copy( source.line );
  28544. this.cone.copy( source.cone );
  28545. return this;
  28546. }
  28547. }
  28548. class AxesHelper extends LineSegments {
  28549. constructor( size = 1 ) {
  28550. const vertices = [
  28551. 0, 0, 0, size, 0, 0,
  28552. 0, 0, 0, 0, size, 0,
  28553. 0, 0, 0, 0, 0, size
  28554. ];
  28555. const colors = [
  28556. 1, 0, 0, 1, 0.6, 0,
  28557. 0, 1, 0, 0.6, 1, 0,
  28558. 0, 0, 1, 0, 0.6, 1
  28559. ];
  28560. const geometry = new BufferGeometry();
  28561. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28562. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28563. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28564. super( geometry, material );
  28565. this.type = 'AxesHelper';
  28566. }
  28567. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  28568. const color = new Color();
  28569. const array = this.geometry.attributes.color.array;
  28570. color.set( xAxisColor );
  28571. color.toArray( array, 0 );
  28572. color.toArray( array, 3 );
  28573. color.set( yAxisColor );
  28574. color.toArray( array, 6 );
  28575. color.toArray( array, 9 );
  28576. color.set( zAxisColor );
  28577. color.toArray( array, 12 );
  28578. color.toArray( array, 15 );
  28579. this.geometry.attributes.color.needsUpdate = true;
  28580. return this;
  28581. }
  28582. dispose() {
  28583. this.geometry.dispose();
  28584. this.material.dispose();
  28585. }
  28586. }
  28587. const _floatView = new Float32Array( 1 );
  28588. const _int32View = new Int32Array( _floatView.buffer );
  28589. class DataUtils {
  28590. // Converts float32 to float16 (stored as uint16 value).
  28591. static toHalfFloat( val ) {
  28592. if ( val > 65504 ) {
  28593. console.warn( 'THREE.DataUtils.toHalfFloat(): value exceeds 65504.' );
  28594. val = 65504; // maximum representable value in float16
  28595. }
  28596. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28597. /* This method is faster than the OpenEXR implementation (very often
  28598. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28599. * by James Tursa?s half-precision code. */
  28600. _floatView[ 0 ] = val;
  28601. const x = _int32View[ 0 ];
  28602. let bits = ( x >> 16 ) & 0x8000; /* Get the sign */
  28603. let m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
  28604. const e = ( x >> 23 ) & 0xff; /* Using int is faster here */
  28605. /* If zero, or denormal, or exponent underflows too much for a denormal
  28606. * half, return signed zero. */
  28607. if ( e < 103 ) return bits;
  28608. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28609. if ( e > 142 ) {
  28610. bits |= 0x7c00;
  28611. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28612. * not Inf, so make sure we set one mantissa bit too. */
  28613. bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
  28614. return bits;
  28615. }
  28616. /* If exponent underflows but not too much, return a denormal */
  28617. if ( e < 113 ) {
  28618. m |= 0x0800;
  28619. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28620. * to 1, which is OK. */
  28621. bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
  28622. return bits;
  28623. }
  28624. bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
  28625. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28626. * the exponent, which is OK. */
  28627. bits += m & 1;
  28628. return bits;
  28629. }
  28630. }
  28631. const LineStrip = 0;
  28632. const LinePieces = 1;
  28633. const NoColors = 0;
  28634. const FaceColors = 1;
  28635. const VertexColors = 2;
  28636. function MeshFaceMaterial( materials ) {
  28637. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28638. return materials;
  28639. }
  28640. function MultiMaterial( materials = [] ) {
  28641. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28642. materials.isMultiMaterial = true;
  28643. materials.materials = materials;
  28644. materials.clone = function () {
  28645. return materials.slice();
  28646. };
  28647. return materials;
  28648. }
  28649. function PointCloud( geometry, material ) {
  28650. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28651. return new Points( geometry, material );
  28652. }
  28653. function Particle( material ) {
  28654. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28655. return new Sprite( material );
  28656. }
  28657. function ParticleSystem( geometry, material ) {
  28658. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28659. return new Points( geometry, material );
  28660. }
  28661. function PointCloudMaterial( parameters ) {
  28662. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28663. return new PointsMaterial( parameters );
  28664. }
  28665. function ParticleBasicMaterial( parameters ) {
  28666. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28667. return new PointsMaterial( parameters );
  28668. }
  28669. function ParticleSystemMaterial( parameters ) {
  28670. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28671. return new PointsMaterial( parameters );
  28672. }
  28673. function Vertex( x, y, z ) {
  28674. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28675. return new Vector3( x, y, z );
  28676. }
  28677. //
  28678. function DynamicBufferAttribute( array, itemSize ) {
  28679. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  28680. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  28681. }
  28682. function Int8Attribute( array, itemSize ) {
  28683. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28684. return new Int8BufferAttribute( array, itemSize );
  28685. }
  28686. function Uint8Attribute( array, itemSize ) {
  28687. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28688. return new Uint8BufferAttribute( array, itemSize );
  28689. }
  28690. function Uint8ClampedAttribute( array, itemSize ) {
  28691. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28692. return new Uint8ClampedBufferAttribute( array, itemSize );
  28693. }
  28694. function Int16Attribute( array, itemSize ) {
  28695. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28696. return new Int16BufferAttribute( array, itemSize );
  28697. }
  28698. function Uint16Attribute( array, itemSize ) {
  28699. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28700. return new Uint16BufferAttribute( array, itemSize );
  28701. }
  28702. function Int32Attribute( array, itemSize ) {
  28703. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28704. return new Int32BufferAttribute( array, itemSize );
  28705. }
  28706. function Uint32Attribute( array, itemSize ) {
  28707. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28708. return new Uint32BufferAttribute( array, itemSize );
  28709. }
  28710. function Float32Attribute( array, itemSize ) {
  28711. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28712. return new Float32BufferAttribute( array, itemSize );
  28713. }
  28714. function Float64Attribute( array, itemSize ) {
  28715. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28716. return new Float64BufferAttribute( array, itemSize );
  28717. }
  28718. //
  28719. Curve.create = function ( construct, getPoint ) {
  28720. console.log( 'THREE.Curve.create() has been deprecated' );
  28721. construct.prototype = Object.create( Curve.prototype );
  28722. construct.prototype.constructor = construct;
  28723. construct.prototype.getPoint = getPoint;
  28724. return construct;
  28725. };
  28726. //
  28727. Path.prototype.fromPoints = function ( points ) {
  28728. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28729. return this.setFromPoints( points );
  28730. };
  28731. //
  28732. function AxisHelper( size ) {
  28733. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28734. return new AxesHelper( size );
  28735. }
  28736. function BoundingBoxHelper( object, color ) {
  28737. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28738. return new BoxHelper( object, color );
  28739. }
  28740. function EdgesHelper( object, hex ) {
  28741. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28742. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28743. }
  28744. GridHelper.prototype.setColors = function () {
  28745. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28746. };
  28747. SkeletonHelper.prototype.update = function () {
  28748. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28749. };
  28750. function WireframeHelper( object, hex ) {
  28751. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28752. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28753. }
  28754. //
  28755. Loader.prototype.extractUrlBase = function ( url ) {
  28756. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28757. return LoaderUtils.extractUrlBase( url );
  28758. };
  28759. Loader.Handlers = {
  28760. add: function ( /* regex, loader */ ) {
  28761. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  28762. },
  28763. get: function ( /* file */ ) {
  28764. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  28765. }
  28766. };
  28767. function XHRLoader( manager ) {
  28768. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28769. return new FileLoader( manager );
  28770. }
  28771. function BinaryTextureLoader( manager ) {
  28772. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28773. return new DataTextureLoader( manager );
  28774. }
  28775. //
  28776. Box2.prototype.center = function ( optionalTarget ) {
  28777. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28778. return this.getCenter( optionalTarget );
  28779. };
  28780. Box2.prototype.empty = function () {
  28781. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28782. return this.isEmpty();
  28783. };
  28784. Box2.prototype.isIntersectionBox = function ( box ) {
  28785. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28786. return this.intersectsBox( box );
  28787. };
  28788. Box2.prototype.size = function ( optionalTarget ) {
  28789. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28790. return this.getSize( optionalTarget );
  28791. };
  28792. //
  28793. Box3.prototype.center = function ( optionalTarget ) {
  28794. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28795. return this.getCenter( optionalTarget );
  28796. };
  28797. Box3.prototype.empty = function () {
  28798. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28799. return this.isEmpty();
  28800. };
  28801. Box3.prototype.isIntersectionBox = function ( box ) {
  28802. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28803. return this.intersectsBox( box );
  28804. };
  28805. Box3.prototype.isIntersectionSphere = function ( sphere ) {
  28806. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28807. return this.intersectsSphere( sphere );
  28808. };
  28809. Box3.prototype.size = function ( optionalTarget ) {
  28810. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28811. return this.getSize( optionalTarget );
  28812. };
  28813. //
  28814. Sphere.prototype.empty = function () {
  28815. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  28816. return this.isEmpty();
  28817. };
  28818. //
  28819. Frustum.prototype.setFromMatrix = function ( m ) {
  28820. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  28821. return this.setFromProjectionMatrix( m );
  28822. };
  28823. //
  28824. Line3.prototype.center = function ( optionalTarget ) {
  28825. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28826. return this.getCenter( optionalTarget );
  28827. };
  28828. //
  28829. Matrix3.prototype.flattenToArrayOffset = function ( array, offset ) {
  28830. console.warn( 'THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  28831. return this.toArray( array, offset );
  28832. };
  28833. Matrix3.prototype.multiplyVector3 = function ( vector ) {
  28834. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28835. return vector.applyMatrix3( this );
  28836. };
  28837. Matrix3.prototype.multiplyVector3Array = function ( /* a */ ) {
  28838. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28839. };
  28840. Matrix3.prototype.applyToBufferAttribute = function ( attribute ) {
  28841. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  28842. return attribute.applyMatrix3( this );
  28843. };
  28844. Matrix3.prototype.applyToVector3Array = function ( /* array, offset, length */ ) {
  28845. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28846. };
  28847. Matrix3.prototype.getInverse = function ( matrix ) {
  28848. console.warn( 'THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  28849. return this.copy( matrix ).invert();
  28850. };
  28851. //
  28852. Matrix4.prototype.extractPosition = function ( m ) {
  28853. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28854. return this.copyPosition( m );
  28855. };
  28856. Matrix4.prototype.flattenToArrayOffset = function ( array, offset ) {
  28857. console.warn( 'THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  28858. return this.toArray( array, offset );
  28859. };
  28860. Matrix4.prototype.getPosition = function () {
  28861. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28862. return new Vector3().setFromMatrixColumn( this, 3 );
  28863. };
  28864. Matrix4.prototype.setRotationFromQuaternion = function ( q ) {
  28865. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28866. return this.makeRotationFromQuaternion( q );
  28867. };
  28868. Matrix4.prototype.multiplyToArray = function () {
  28869. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28870. };
  28871. Matrix4.prototype.multiplyVector3 = function ( vector ) {
  28872. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28873. return vector.applyMatrix4( this );
  28874. };
  28875. Matrix4.prototype.multiplyVector4 = function ( vector ) {
  28876. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28877. return vector.applyMatrix4( this );
  28878. };
  28879. Matrix4.prototype.multiplyVector3Array = function ( /* a */ ) {
  28880. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28881. };
  28882. Matrix4.prototype.rotateAxis = function ( v ) {
  28883. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28884. v.transformDirection( this );
  28885. };
  28886. Matrix4.prototype.crossVector = function ( vector ) {
  28887. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28888. return vector.applyMatrix4( this );
  28889. };
  28890. Matrix4.prototype.translate = function () {
  28891. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28892. };
  28893. Matrix4.prototype.rotateX = function () {
  28894. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28895. };
  28896. Matrix4.prototype.rotateY = function () {
  28897. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28898. };
  28899. Matrix4.prototype.rotateZ = function () {
  28900. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28901. };
  28902. Matrix4.prototype.rotateByAxis = function () {
  28903. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28904. };
  28905. Matrix4.prototype.applyToBufferAttribute = function ( attribute ) {
  28906. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  28907. return attribute.applyMatrix4( this );
  28908. };
  28909. Matrix4.prototype.applyToVector3Array = function ( /* array, offset, length */ ) {
  28910. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28911. };
  28912. Matrix4.prototype.makeFrustum = function ( left, right, bottom, top, near, far ) {
  28913. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28914. return this.makePerspective( left, right, top, bottom, near, far );
  28915. };
  28916. Matrix4.prototype.getInverse = function ( matrix ) {
  28917. console.warn( 'THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  28918. return this.copy( matrix ).invert();
  28919. };
  28920. //
  28921. Plane.prototype.isIntersectionLine = function ( line ) {
  28922. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28923. return this.intersectsLine( line );
  28924. };
  28925. //
  28926. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28927. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28928. return vector.applyQuaternion( this );
  28929. };
  28930. Quaternion.prototype.inverse = function ( ) {
  28931. console.warn( 'THREE.Quaternion: .inverse() has been renamed to invert().' );
  28932. return this.invert();
  28933. };
  28934. //
  28935. Ray.prototype.isIntersectionBox = function ( box ) {
  28936. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28937. return this.intersectsBox( box );
  28938. };
  28939. Ray.prototype.isIntersectionPlane = function ( plane ) {
  28940. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28941. return this.intersectsPlane( plane );
  28942. };
  28943. Ray.prototype.isIntersectionSphere = function ( sphere ) {
  28944. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28945. return this.intersectsSphere( sphere );
  28946. };
  28947. //
  28948. Triangle.prototype.area = function () {
  28949. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28950. return this.getArea();
  28951. };
  28952. Triangle.prototype.barycoordFromPoint = function ( point, target ) {
  28953. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28954. return this.getBarycoord( point, target );
  28955. };
  28956. Triangle.prototype.midpoint = function ( target ) {
  28957. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28958. return this.getMidpoint( target );
  28959. };
  28960. Triangle.prototypenormal = function ( target ) {
  28961. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28962. return this.getNormal( target );
  28963. };
  28964. Triangle.prototype.plane = function ( target ) {
  28965. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28966. return this.getPlane( target );
  28967. };
  28968. Triangle.barycoordFromPoint = function ( point, a, b, c, target ) {
  28969. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28970. return Triangle.getBarycoord( point, a, b, c, target );
  28971. };
  28972. Triangle.normal = function ( a, b, c, target ) {
  28973. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28974. return Triangle.getNormal( a, b, c, target );
  28975. };
  28976. //
  28977. Shape.prototype.extractAllPoints = function ( divisions ) {
  28978. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28979. return this.extractPoints( divisions );
  28980. };
  28981. Shape.prototype.extrude = function ( options ) {
  28982. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28983. return new ExtrudeGeometry( this, options );
  28984. };
  28985. Shape.prototype.makeGeometry = function ( options ) {
  28986. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28987. return new ShapeGeometry( this, options );
  28988. };
  28989. //
  28990. Vector2.prototype.fromAttribute = function ( attribute, index, offset ) {
  28991. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28992. return this.fromBufferAttribute( attribute, index, offset );
  28993. };
  28994. Vector2.prototype.distanceToManhattan = function ( v ) {
  28995. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28996. return this.manhattanDistanceTo( v );
  28997. };
  28998. Vector2.prototype.lengthManhattan = function () {
  28999. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29000. return this.manhattanLength();
  29001. };
  29002. //
  29003. Vector3.prototype.setEulerFromRotationMatrix = function () {
  29004. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29005. };
  29006. Vector3.prototype.setEulerFromQuaternion = function () {
  29007. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29008. };
  29009. Vector3.prototype.getPositionFromMatrix = function ( m ) {
  29010. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29011. return this.setFromMatrixPosition( m );
  29012. };
  29013. Vector3.prototype.getScaleFromMatrix = function ( m ) {
  29014. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29015. return this.setFromMatrixScale( m );
  29016. };
  29017. Vector3.prototype.getColumnFromMatrix = function ( index, matrix ) {
  29018. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29019. return this.setFromMatrixColumn( matrix, index );
  29020. };
  29021. Vector3.prototype.applyProjection = function ( m ) {
  29022. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29023. return this.applyMatrix4( m );
  29024. };
  29025. Vector3.prototype.fromAttribute = function ( attribute, index, offset ) {
  29026. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29027. return this.fromBufferAttribute( attribute, index, offset );
  29028. };
  29029. Vector3.prototype.distanceToManhattan = function ( v ) {
  29030. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29031. return this.manhattanDistanceTo( v );
  29032. };
  29033. Vector3.prototype.lengthManhattan = function () {
  29034. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29035. return this.manhattanLength();
  29036. };
  29037. //
  29038. Vector4.prototype.fromAttribute = function ( attribute, index, offset ) {
  29039. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29040. return this.fromBufferAttribute( attribute, index, offset );
  29041. };
  29042. Vector4.prototype.lengthManhattan = function () {
  29043. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29044. return this.manhattanLength();
  29045. };
  29046. //
  29047. Object3D.prototype.getChildByName = function ( name ) {
  29048. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  29049. return this.getObjectByName( name );
  29050. };
  29051. Object3D.prototype.renderDepth = function () {
  29052. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  29053. };
  29054. Object3D.prototype.translate = function ( distance, axis ) {
  29055. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  29056. return this.translateOnAxis( axis, distance );
  29057. };
  29058. Object3D.prototype.getWorldRotation = function () {
  29059. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  29060. };
  29061. Object3D.prototype.applyMatrix = function ( matrix ) {
  29062. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  29063. return this.applyMatrix4( matrix );
  29064. };
  29065. Object.defineProperties( Object3D.prototype, {
  29066. eulerOrder: {
  29067. get: function () {
  29068. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29069. return this.rotation.order;
  29070. },
  29071. set: function ( value ) {
  29072. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29073. this.rotation.order = value;
  29074. }
  29075. },
  29076. useQuaternion: {
  29077. get: function () {
  29078. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29079. },
  29080. set: function () {
  29081. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29082. }
  29083. }
  29084. } );
  29085. Mesh.prototype.setDrawMode = function () {
  29086. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29087. };
  29088. Object.defineProperties( Mesh.prototype, {
  29089. drawMode: {
  29090. get: function () {
  29091. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  29092. return TrianglesDrawMode;
  29093. },
  29094. set: function () {
  29095. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29096. }
  29097. }
  29098. } );
  29099. SkinnedMesh.prototype.initBones = function () {
  29100. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29101. };
  29102. //
  29103. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29104. console.warn( 'THREE.PerspectiveCamera.setLens is deprecated. ' +
  29105. 'Use .setFocalLength and .filmGauge for a photographic setup.' );
  29106. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29107. this.setFocalLength( focalLength );
  29108. };
  29109. //
  29110. Object.defineProperties( Light.prototype, {
  29111. onlyShadow: {
  29112. set: function () {
  29113. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29114. }
  29115. },
  29116. shadowCameraFov: {
  29117. set: function ( value ) {
  29118. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29119. this.shadow.camera.fov = value;
  29120. }
  29121. },
  29122. shadowCameraLeft: {
  29123. set: function ( value ) {
  29124. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29125. this.shadow.camera.left = value;
  29126. }
  29127. },
  29128. shadowCameraRight: {
  29129. set: function ( value ) {
  29130. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29131. this.shadow.camera.right = value;
  29132. }
  29133. },
  29134. shadowCameraTop: {
  29135. set: function ( value ) {
  29136. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29137. this.shadow.camera.top = value;
  29138. }
  29139. },
  29140. shadowCameraBottom: {
  29141. set: function ( value ) {
  29142. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29143. this.shadow.camera.bottom = value;
  29144. }
  29145. },
  29146. shadowCameraNear: {
  29147. set: function ( value ) {
  29148. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29149. this.shadow.camera.near = value;
  29150. }
  29151. },
  29152. shadowCameraFar: {
  29153. set: function ( value ) {
  29154. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29155. this.shadow.camera.far = value;
  29156. }
  29157. },
  29158. shadowCameraVisible: {
  29159. set: function () {
  29160. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29161. }
  29162. },
  29163. shadowBias: {
  29164. set: function ( value ) {
  29165. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29166. this.shadow.bias = value;
  29167. }
  29168. },
  29169. shadowDarkness: {
  29170. set: function () {
  29171. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29172. }
  29173. },
  29174. shadowMapWidth: {
  29175. set: function ( value ) {
  29176. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29177. this.shadow.mapSize.width = value;
  29178. }
  29179. },
  29180. shadowMapHeight: {
  29181. set: function ( value ) {
  29182. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29183. this.shadow.mapSize.height = value;
  29184. }
  29185. }
  29186. } );
  29187. //
  29188. Object.defineProperties( BufferAttribute.prototype, {
  29189. length: {
  29190. get: function () {
  29191. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29192. return this.array.length;
  29193. }
  29194. },
  29195. dynamic: {
  29196. get: function () {
  29197. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29198. return this.usage === DynamicDrawUsage;
  29199. },
  29200. set: function ( /* value */ ) {
  29201. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29202. this.setUsage( DynamicDrawUsage );
  29203. }
  29204. }
  29205. } );
  29206. BufferAttribute.prototype.setDynamic = function ( value ) {
  29207. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29208. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29209. return this;
  29210. };
  29211. BufferAttribute.prototype.copyIndicesArray = function ( /* indices */ ) {
  29212. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  29213. },
  29214. BufferAttribute.prototype.setArray = function ( /* array */ ) {
  29215. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29216. };
  29217. //
  29218. BufferGeometry.prototype.addIndex = function ( index ) {
  29219. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  29220. this.setIndex( index );
  29221. };
  29222. BufferGeometry.prototype.addAttribute = function ( name, attribute ) {
  29223. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  29224. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  29225. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  29226. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  29227. }
  29228. if ( name === 'index' ) {
  29229. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  29230. this.setIndex( attribute );
  29231. return this;
  29232. }
  29233. return this.setAttribute( name, attribute );
  29234. };
  29235. BufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset ) {
  29236. if ( indexOffset !== undefined ) {
  29237. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  29238. }
  29239. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  29240. this.addGroup( start, count );
  29241. };
  29242. BufferGeometry.prototype.clearDrawCalls = function () {
  29243. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  29244. this.clearGroups();
  29245. };
  29246. BufferGeometry.prototype.computeOffsets = function () {
  29247. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  29248. };
  29249. BufferGeometry.prototype.removeAttribute = function ( name ) {
  29250. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  29251. return this.deleteAttribute( name );
  29252. };
  29253. BufferGeometry.prototype.applyMatrix = function ( matrix ) {
  29254. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29255. return this.applyMatrix4( matrix );
  29256. };
  29257. Object.defineProperties( BufferGeometry.prototype, {
  29258. drawcalls: {
  29259. get: function () {
  29260. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  29261. return this.groups;
  29262. }
  29263. },
  29264. offsets: {
  29265. get: function () {
  29266. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  29267. return this.groups;
  29268. }
  29269. }
  29270. } );
  29271. InterleavedBuffer.prototype.setDynamic = function ( value ) {
  29272. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29273. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29274. return this;
  29275. };
  29276. InterleavedBuffer.prototype.setArray = function ( /* array */ ) {
  29277. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29278. };
  29279. //
  29280. ExtrudeGeometry.prototype.getArrays = function () {
  29281. console.error( 'THREE.ExtrudeGeometry: .getArrays() has been removed.' );
  29282. };
  29283. ExtrudeGeometry.prototype.addShapeList = function () {
  29284. console.error( 'THREE.ExtrudeGeometry: .addShapeList() has been removed.' );
  29285. };
  29286. ExtrudeGeometry.prototype.addShape = function () {
  29287. console.error( 'THREE.ExtrudeGeometry: .addShape() has been removed.' );
  29288. };
  29289. //
  29290. Scene.prototype.dispose = function () {
  29291. console.error( 'THREE.Scene: .dispose() has been removed.' );
  29292. };
  29293. //
  29294. Uniform.prototype.onUpdate = function () {
  29295. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  29296. return this;
  29297. };
  29298. //
  29299. Object.defineProperties( Material.prototype, {
  29300. wrapAround: {
  29301. get: function () {
  29302. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29303. },
  29304. set: function () {
  29305. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29306. }
  29307. },
  29308. overdraw: {
  29309. get: function () {
  29310. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29311. },
  29312. set: function () {
  29313. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29314. }
  29315. },
  29316. wrapRGB: {
  29317. get: function () {
  29318. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  29319. return new Color();
  29320. }
  29321. },
  29322. shading: {
  29323. get: function () {
  29324. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29325. },
  29326. set: function ( value ) {
  29327. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29328. this.flatShading = ( value === FlatShading );
  29329. }
  29330. },
  29331. stencilMask: {
  29332. get: function () {
  29333. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29334. return this.stencilFuncMask;
  29335. },
  29336. set: function ( value ) {
  29337. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29338. this.stencilFuncMask = value;
  29339. }
  29340. },
  29341. vertexTangents: {
  29342. get: function () {
  29343. console.warn( 'THREE.' + this.type + ': .vertexTangents has been removed.' );
  29344. },
  29345. set: function () {
  29346. console.warn( 'THREE.' + this.type + ': .vertexTangents has been removed.' );
  29347. }
  29348. },
  29349. } );
  29350. Object.defineProperties( ShaderMaterial.prototype, {
  29351. derivatives: {
  29352. get: function () {
  29353. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29354. return this.extensions.derivatives;
  29355. },
  29356. set: function ( value ) {
  29357. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29358. this.extensions.derivatives = value;
  29359. }
  29360. }
  29361. } );
  29362. //
  29363. WebGLRenderer.prototype.clearTarget = function ( renderTarget, color, depth, stencil ) {
  29364. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  29365. this.setRenderTarget( renderTarget );
  29366. this.clear( color, depth, stencil );
  29367. };
  29368. WebGLRenderer.prototype.animate = function ( callback ) {
  29369. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  29370. this.setAnimationLoop( callback );
  29371. };
  29372. WebGLRenderer.prototype.getCurrentRenderTarget = function () {
  29373. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  29374. return this.getRenderTarget();
  29375. };
  29376. WebGLRenderer.prototype.getMaxAnisotropy = function () {
  29377. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  29378. return this.capabilities.getMaxAnisotropy();
  29379. };
  29380. WebGLRenderer.prototype.getPrecision = function () {
  29381. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  29382. return this.capabilities.precision;
  29383. };
  29384. WebGLRenderer.prototype.resetGLState = function () {
  29385. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  29386. return this.state.reset();
  29387. };
  29388. WebGLRenderer.prototype.supportsFloatTextures = function () {
  29389. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  29390. return this.extensions.get( 'OES_texture_float' );
  29391. };
  29392. WebGLRenderer.prototype.supportsHalfFloatTextures = function () {
  29393. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  29394. return this.extensions.get( 'OES_texture_half_float' );
  29395. };
  29396. WebGLRenderer.prototype.supportsStandardDerivatives = function () {
  29397. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  29398. return this.extensions.get( 'OES_standard_derivatives' );
  29399. };
  29400. WebGLRenderer.prototype.supportsCompressedTextureS3TC = function () {
  29401. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  29402. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  29403. };
  29404. WebGLRenderer.prototype.supportsCompressedTexturePVRTC = function () {
  29405. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  29406. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  29407. };
  29408. WebGLRenderer.prototype.supportsBlendMinMax = function () {
  29409. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  29410. return this.extensions.get( 'EXT_blend_minmax' );
  29411. };
  29412. WebGLRenderer.prototype.supportsVertexTextures = function () {
  29413. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  29414. return this.capabilities.vertexTextures;
  29415. };
  29416. WebGLRenderer.prototype.supportsInstancedArrays = function () {
  29417. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  29418. return this.extensions.get( 'ANGLE_instanced_arrays' );
  29419. };
  29420. WebGLRenderer.prototype.enableScissorTest = function ( boolean ) {
  29421. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  29422. this.setScissorTest( boolean );
  29423. };
  29424. WebGLRenderer.prototype.initMaterial = function () {
  29425. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  29426. };
  29427. WebGLRenderer.prototype.addPrePlugin = function () {
  29428. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  29429. };
  29430. WebGLRenderer.prototype.addPostPlugin = function () {
  29431. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  29432. };
  29433. WebGLRenderer.prototype.updateShadowMap = function () {
  29434. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  29435. };
  29436. WebGLRenderer.prototype.setFaceCulling = function () {
  29437. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  29438. };
  29439. WebGLRenderer.prototype.allocTextureUnit = function () {
  29440. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  29441. };
  29442. WebGLRenderer.prototype.setTexture = function () {
  29443. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  29444. };
  29445. WebGLRenderer.prototype.setTexture2D = function () {
  29446. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  29447. };
  29448. WebGLRenderer.prototype.setTextureCube = function () {
  29449. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  29450. };
  29451. WebGLRenderer.prototype.getActiveMipMapLevel = function () {
  29452. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  29453. return this.getActiveMipmapLevel();
  29454. };
  29455. Object.defineProperties( WebGLRenderer.prototype, {
  29456. shadowMapEnabled: {
  29457. get: function () {
  29458. return this.shadowMap.enabled;
  29459. },
  29460. set: function ( value ) {
  29461. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  29462. this.shadowMap.enabled = value;
  29463. }
  29464. },
  29465. shadowMapType: {
  29466. get: function () {
  29467. return this.shadowMap.type;
  29468. },
  29469. set: function ( value ) {
  29470. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  29471. this.shadowMap.type = value;
  29472. }
  29473. },
  29474. shadowMapCullFace: {
  29475. get: function () {
  29476. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29477. return undefined;
  29478. },
  29479. set: function ( /* value */ ) {
  29480. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29481. }
  29482. },
  29483. context: {
  29484. get: function () {
  29485. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29486. return this.getContext();
  29487. }
  29488. },
  29489. vr: {
  29490. get: function () {
  29491. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  29492. return this.xr;
  29493. }
  29494. },
  29495. gammaInput: {
  29496. get: function () {
  29497. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  29498. return false;
  29499. },
  29500. set: function () {
  29501. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  29502. }
  29503. },
  29504. gammaOutput: {
  29505. get: function () {
  29506. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  29507. return false;
  29508. },
  29509. set: function ( value ) {
  29510. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  29511. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  29512. }
  29513. },
  29514. toneMappingWhitePoint: {
  29515. get: function () {
  29516. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  29517. return 1.0;
  29518. },
  29519. set: function () {
  29520. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  29521. }
  29522. },
  29523. } );
  29524. Object.defineProperties( WebGLShadowMap.prototype, {
  29525. cullFace: {
  29526. get: function () {
  29527. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29528. return undefined;
  29529. },
  29530. set: function ( /* cullFace */ ) {
  29531. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29532. }
  29533. },
  29534. renderReverseSided: {
  29535. get: function () {
  29536. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29537. return undefined;
  29538. },
  29539. set: function () {
  29540. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29541. }
  29542. },
  29543. renderSingleSided: {
  29544. get: function () {
  29545. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29546. return undefined;
  29547. },
  29548. set: function () {
  29549. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29550. }
  29551. }
  29552. } );
  29553. function WebGLRenderTargetCube( width, height, options ) {
  29554. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  29555. return new WebGLCubeRenderTarget( width, options );
  29556. }
  29557. //
  29558. Object.defineProperties( WebGLRenderTarget.prototype, {
  29559. wrapS: {
  29560. get: function () {
  29561. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29562. return this.texture.wrapS;
  29563. },
  29564. set: function ( value ) {
  29565. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29566. this.texture.wrapS = value;
  29567. }
  29568. },
  29569. wrapT: {
  29570. get: function () {
  29571. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29572. return this.texture.wrapT;
  29573. },
  29574. set: function ( value ) {
  29575. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29576. this.texture.wrapT = value;
  29577. }
  29578. },
  29579. magFilter: {
  29580. get: function () {
  29581. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29582. return this.texture.magFilter;
  29583. },
  29584. set: function ( value ) {
  29585. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29586. this.texture.magFilter = value;
  29587. }
  29588. },
  29589. minFilter: {
  29590. get: function () {
  29591. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29592. return this.texture.minFilter;
  29593. },
  29594. set: function ( value ) {
  29595. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29596. this.texture.minFilter = value;
  29597. }
  29598. },
  29599. anisotropy: {
  29600. get: function () {
  29601. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29602. return this.texture.anisotropy;
  29603. },
  29604. set: function ( value ) {
  29605. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29606. this.texture.anisotropy = value;
  29607. }
  29608. },
  29609. offset: {
  29610. get: function () {
  29611. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29612. return this.texture.offset;
  29613. },
  29614. set: function ( value ) {
  29615. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29616. this.texture.offset = value;
  29617. }
  29618. },
  29619. repeat: {
  29620. get: function () {
  29621. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29622. return this.texture.repeat;
  29623. },
  29624. set: function ( value ) {
  29625. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29626. this.texture.repeat = value;
  29627. }
  29628. },
  29629. format: {
  29630. get: function () {
  29631. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29632. return this.texture.format;
  29633. },
  29634. set: function ( value ) {
  29635. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29636. this.texture.format = value;
  29637. }
  29638. },
  29639. type: {
  29640. get: function () {
  29641. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29642. return this.texture.type;
  29643. },
  29644. set: function ( value ) {
  29645. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29646. this.texture.type = value;
  29647. }
  29648. },
  29649. generateMipmaps: {
  29650. get: function () {
  29651. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29652. return this.texture.generateMipmaps;
  29653. },
  29654. set: function ( value ) {
  29655. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29656. this.texture.generateMipmaps = value;
  29657. }
  29658. }
  29659. } );
  29660. //
  29661. Audio.prototype.load = function ( file ) {
  29662. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29663. const scope = this;
  29664. const audioLoader = new AudioLoader();
  29665. audioLoader.load( file, function ( buffer ) {
  29666. scope.setBuffer( buffer );
  29667. } );
  29668. return this;
  29669. };
  29670. AudioAnalyser.prototype.getData = function () {
  29671. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29672. return this.getFrequencyData();
  29673. };
  29674. //
  29675. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29676. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29677. return this.update( renderer, scene );
  29678. };
  29679. CubeCamera.prototype.clear = function ( renderer, color, depth, stencil ) {
  29680. console.warn( 'THREE.CubeCamera: .clear() is now .renderTarget.clear().' );
  29681. return this.renderTarget.clear( renderer, color, depth, stencil );
  29682. };
  29683. ImageUtils.crossOrigin = undefined;
  29684. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29685. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29686. const loader = new TextureLoader();
  29687. loader.setCrossOrigin( this.crossOrigin );
  29688. const texture = loader.load( url, onLoad, undefined, onError );
  29689. if ( mapping ) texture.mapping = mapping;
  29690. return texture;
  29691. };
  29692. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29693. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29694. const loader = new CubeTextureLoader();
  29695. loader.setCrossOrigin( this.crossOrigin );
  29696. const texture = loader.load( urls, onLoad, undefined, onError );
  29697. if ( mapping ) texture.mapping = mapping;
  29698. return texture;
  29699. };
  29700. ImageUtils.loadCompressedTexture = function () {
  29701. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29702. };
  29703. ImageUtils.loadCompressedTextureCube = function () {
  29704. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29705. };
  29706. //
  29707. function CanvasRenderer() {
  29708. console.error( 'THREE.CanvasRenderer has been removed' );
  29709. }
  29710. //
  29711. function JSONLoader() {
  29712. console.error( 'THREE.JSONLoader has been removed.' );
  29713. }
  29714. //
  29715. const SceneUtils = {
  29716. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29717. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29718. },
  29719. detach: function ( /* child, parent, scene */ ) {
  29720. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29721. },
  29722. attach: function ( /* child, scene, parent */ ) {
  29723. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29724. }
  29725. };
  29726. //
  29727. function LensFlare() {
  29728. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  29729. }
  29730. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  29731. /* eslint-disable no-undef */
  29732. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  29733. revision: REVISION,
  29734. } } ) );
  29735. /* eslint-enable no-undef */
  29736. }
  29737. if ( typeof window !== 'undefined' ) {
  29738. if ( window.__THREE__ ) {
  29739. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  29740. } else {
  29741. window.__THREE__ = REVISION;
  29742. }
  29743. }
  29744. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AlphaFormat, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightProbe, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, AxisHelper, BackSide, BasicDepthPacking, BasicShadowMap, BinaryTextureLoader, Bone, BooleanKeyframeTrack, BoundingBoxHelper, Box2, Box3, Box3Helper, BoxGeometry as BoxBufferGeometry, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasRenderer, CanvasTexture, CatmullRomCurve3, CineonToneMapping, CircleGeometry as CircleBufferGeometry, CircleGeometry, ClampToEdgeWrapping, Clock, Color, ColorKeyframeTrack, CompressedTexture, CompressedTextureLoader, ConeGeometry as ConeBufferGeometry, ConeGeometry, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubeUVRefractionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry as CylinderBufferGeometry, CylinderGeometry, Cylindrical, DataTexture, DataTexture2DArray, DataTexture3D, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry as DodecahedronBufferGeometry, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicBufferAttribute, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EdgesHelper, EllipseCurve, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeGeometry as ExtrudeBufferGeometry, ExtrudeGeometry, FaceColors, FileLoader, FlatShading, Float16BufferAttribute, Float32Attribute, Float32BufferAttribute, Float64Attribute, Float64BufferAttribute, FloatType, Fog, FogExp2, Font, FontLoader, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GammaEncoding, GreaterDepth, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, HemisphereLightProbe, IcosahedronGeometry as IcosahedronBufferGeometry, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, ImmediateRenderObject, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16Attribute, Int16BufferAttribute, Int32Attribute, Int32BufferAttribute, Int8Attribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, JSONLoader, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry as LatheBufferGeometry, LatheGeometry, Layers, LensFlare, LessDepth, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LinePieces, LineSegments, LineStrip, LinearEncoding, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearToneMapping, Loader, LoaderUtils, LoadingManager, LogLuvEncoding, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, MathUtils as Math, MathUtils, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshFaceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiMaterial, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeverDepth, NeverStencilFunc, NoBlending, NoColors, NoToneMapping, NormalAnimationBlendMode, NormalBlending, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry as OctahedronBufferGeometry, OctahedronGeometry, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, ParametricGeometry as ParametricBufferGeometry, ParametricGeometry, Particle, ParticleBasicMaterial, ParticleSystem, ParticleSystemMaterial, Path, PerspectiveCamera, Plane, PlaneGeometry as PlaneBufferGeometry, PlaneGeometry, PlaneHelper, PointCloud, PointCloudMaterial, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry as PolyhedronBufferGeometry, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, 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, RGBDEncoding, RGBEEncoding, RGBEFormat, RGBFormat, RGBIntegerFormat, RGBM16Encoding, RGBM7Encoding, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RedFormat, RedIntegerFormat, ReinhardToneMapping, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingGeometry as RingBufferGeometry, RingGeometry, SRGB8_ALPHA8_ASTC_10x10_Format, SRGB8_ALPHA8_ASTC_10x5_Format, SRGB8_ALPHA8_ASTC_10x6_Format, SRGB8_ALPHA8_ASTC_10x8_Format, SRGB8_ALPHA8_ASTC_12x10_Format, SRGB8_ALPHA8_ASTC_12x12_Format, SRGB8_ALPHA8_ASTC_4x4_Format, SRGB8_ALPHA8_ASTC_5x4_Format, SRGB8_ALPHA8_ASTC_5x5_Format, SRGB8_ALPHA8_ASTC_6x5_Format, SRGB8_ALPHA8_ASTC_6x6_Format, SRGB8_ALPHA8_ASTC_8x5_Format, SRGB8_ALPHA8_ASTC_8x6_Format, SRGB8_ALPHA8_ASTC_8x8_Format, Scene, SceneUtils, ShaderChunk, ShaderLib, ShaderMaterial, ShadowMaterial, Shape, ShapeGeometry as ShapeBufferGeometry, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SmoothShading, Sphere, SphereGeometry as SphereBufferGeometry, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronGeometry as TetrahedronBufferGeometry, TetrahedronGeometry, TextGeometry as TextBufferGeometry, TextGeometry, Texture, TextureLoader, TorusGeometry as TorusBufferGeometry, TorusGeometry, TorusKnotGeometry as TorusKnotBufferGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry as TubeBufferGeometry, TubeGeometry, UVMapping, Uint16Attribute, Uint16BufferAttribute, Uint32Attribute, Uint32BufferAttribute, Uint8Attribute, Uint8BufferAttribute, Uint8ClampedAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShort565Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, Vertex, VertexColors, VideoTexture, WebGL1Renderer, WebGLCubeRenderTarget, WebGLMultipleRenderTargets, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };