three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965
  1. /**
  2. * @license
  3. * Copyright 2010-2021 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '127dev';
  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. function EventDispatcher() {}
  204. Object.assign( EventDispatcher.prototype, {
  205. addEventListener: function ( type, listener ) {
  206. if ( this._listeners === undefined ) this._listeners = {};
  207. const listeners = this._listeners;
  208. if ( listeners[ type ] === undefined ) {
  209. listeners[ type ] = [];
  210. }
  211. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  212. listeners[ type ].push( listener );
  213. }
  214. },
  215. hasEventListener: function ( type, listener ) {
  216. if ( this._listeners === undefined ) return false;
  217. const listeners = this._listeners;
  218. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  219. },
  220. removeEventListener: function ( type, listener ) {
  221. if ( this._listeners === undefined ) return;
  222. const listeners = this._listeners;
  223. const listenerArray = listeners[ type ];
  224. if ( listenerArray !== undefined ) {
  225. const index = listenerArray.indexOf( listener );
  226. if ( index !== - 1 ) {
  227. listenerArray.splice( index, 1 );
  228. }
  229. }
  230. },
  231. dispatchEvent: function ( event ) {
  232. if ( this._listeners === undefined ) return;
  233. const listeners = this._listeners;
  234. const listenerArray = listeners[ event.type ];
  235. if ( listenerArray !== undefined ) {
  236. event.target = this;
  237. // Make a copy, in case listeners are removed while iterating.
  238. const array = listenerArray.slice( 0 );
  239. for ( let i = 0, l = array.length; i < l; i ++ ) {
  240. array[ i ].call( this, event );
  241. }
  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 MathUtils = {
  251. DEG2RAD: Math.PI / 180,
  252. RAD2DEG: 180 / Math.PI,
  253. generateUUID: function () {
  254. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  255. const d0 = Math.random() * 0xffffffff | 0;
  256. const d1 = Math.random() * 0xffffffff | 0;
  257. const d2 = Math.random() * 0xffffffff | 0;
  258. const d3 = Math.random() * 0xffffffff | 0;
  259. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  260. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  261. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  262. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  263. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  264. return uuid.toUpperCase();
  265. },
  266. clamp: function ( value, min, max ) {
  267. return Math.max( min, Math.min( max, value ) );
  268. },
  269. // compute euclidian modulo of m % n
  270. // https://en.wikipedia.org/wiki/Modulo_operation
  271. euclideanModulo: function ( n, m ) {
  272. return ( ( n % m ) + m ) % m;
  273. },
  274. // Linear mapping from range <a1, a2> to range <b1, b2>
  275. mapLinear: function ( x, a1, a2, b1, b2 ) {
  276. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  277. },
  278. // https://en.wikipedia.org/wiki/Linear_interpolation
  279. lerp: function ( x, y, t ) {
  280. return ( 1 - t ) * x + t * y;
  281. },
  282. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  283. damp: function ( x, y, lambda, dt ) {
  284. return MathUtils.lerp( x, y, 1 - Math.exp( - lambda * dt ) );
  285. },
  286. // https://www.desmos.com/calculator/vcsjnyz7x4
  287. pingpong: function ( x, length = 1 ) {
  288. return length - Math.abs( MathUtils.euclideanModulo( x, length * 2 ) - length );
  289. },
  290. // http://en.wikipedia.org/wiki/Smoothstep
  291. smoothstep: function ( x, min, max ) {
  292. if ( x <= min ) return 0;
  293. if ( x >= max ) return 1;
  294. x = ( x - min ) / ( max - min );
  295. return x * x * ( 3 - 2 * x );
  296. },
  297. smootherstep: function ( x, min, max ) {
  298. if ( x <= min ) return 0;
  299. if ( x >= max ) return 1;
  300. x = ( x - min ) / ( max - min );
  301. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  302. },
  303. // Random integer from <low, high> interval
  304. randInt: function ( low, high ) {
  305. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  306. },
  307. // Random float from <low, high> interval
  308. randFloat: function ( low, high ) {
  309. return low + Math.random() * ( high - low );
  310. },
  311. // Random float from <-range/2, range/2> interval
  312. randFloatSpread: function ( range ) {
  313. return range * ( 0.5 - Math.random() );
  314. },
  315. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  316. seededRandom: function ( s ) {
  317. if ( s !== undefined ) _seed = s % 2147483647;
  318. // Park-Miller algorithm
  319. _seed = _seed * 16807 % 2147483647;
  320. return ( _seed - 1 ) / 2147483646;
  321. },
  322. degToRad: function ( degrees ) {
  323. return degrees * MathUtils.DEG2RAD;
  324. },
  325. radToDeg: function ( radians ) {
  326. return radians * MathUtils.RAD2DEG;
  327. },
  328. isPowerOfTwo: function ( value ) {
  329. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  330. },
  331. ceilPowerOfTwo: function ( value ) {
  332. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  333. },
  334. floorPowerOfTwo: function ( value ) {
  335. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  336. },
  337. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  338. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  339. // rotations are applied to the axes in the order specified by 'order'
  340. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  341. // angles are in radians
  342. const cos = Math.cos;
  343. const sin = Math.sin;
  344. const c2 = cos( b / 2 );
  345. const s2 = sin( b / 2 );
  346. const c13 = cos( ( a + c ) / 2 );
  347. const s13 = sin( ( a + c ) / 2 );
  348. const c1_3 = cos( ( a - c ) / 2 );
  349. const s1_3 = sin( ( a - c ) / 2 );
  350. const c3_1 = cos( ( c - a ) / 2 );
  351. const s3_1 = sin( ( c - a ) / 2 );
  352. switch ( order ) {
  353. case 'XYX':
  354. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  355. break;
  356. case 'YZY':
  357. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  358. break;
  359. case 'ZXZ':
  360. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  361. break;
  362. case 'XZX':
  363. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  364. break;
  365. case 'YXY':
  366. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  367. break;
  368. case 'ZYZ':
  369. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  370. break;
  371. default:
  372. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  373. }
  374. }
  375. };
  376. class Vector2 {
  377. constructor( x = 0, y = 0 ) {
  378. this.x = x;
  379. this.y = y;
  380. }
  381. get width() {
  382. return this.x;
  383. }
  384. set width( value ) {
  385. this.x = value;
  386. }
  387. get height() {
  388. return this.y;
  389. }
  390. set height( value ) {
  391. this.y = value;
  392. }
  393. set( x, y ) {
  394. this.x = x;
  395. this.y = y;
  396. return this;
  397. }
  398. setScalar( scalar ) {
  399. this.x = scalar;
  400. this.y = scalar;
  401. return this;
  402. }
  403. setX( x ) {
  404. this.x = x;
  405. return this;
  406. }
  407. setY( y ) {
  408. this.y = y;
  409. return this;
  410. }
  411. setComponent( index, value ) {
  412. switch ( index ) {
  413. case 0: this.x = value; break;
  414. case 1: this.y = value; break;
  415. default: throw new Error( 'index is out of range: ' + index );
  416. }
  417. return this;
  418. }
  419. getComponent( index ) {
  420. switch ( index ) {
  421. case 0: return this.x;
  422. case 1: return this.y;
  423. default: throw new Error( 'index is out of range: ' + index );
  424. }
  425. }
  426. clone() {
  427. return new this.constructor( this.x, this.y );
  428. }
  429. copy( v ) {
  430. this.x = v.x;
  431. this.y = v.y;
  432. return this;
  433. }
  434. add( v, w ) {
  435. if ( w !== undefined ) {
  436. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  437. return this.addVectors( v, w );
  438. }
  439. this.x += v.x;
  440. this.y += v.y;
  441. return this;
  442. }
  443. addScalar( s ) {
  444. this.x += s;
  445. this.y += s;
  446. return this;
  447. }
  448. addVectors( a, b ) {
  449. this.x = a.x + b.x;
  450. this.y = a.y + b.y;
  451. return this;
  452. }
  453. addScaledVector( v, s ) {
  454. this.x += v.x * s;
  455. this.y += v.y * s;
  456. return this;
  457. }
  458. sub( v, w ) {
  459. if ( w !== undefined ) {
  460. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  461. return this.subVectors( v, w );
  462. }
  463. this.x -= v.x;
  464. this.y -= v.y;
  465. return this;
  466. }
  467. subScalar( s ) {
  468. this.x -= s;
  469. this.y -= s;
  470. return this;
  471. }
  472. subVectors( a, b ) {
  473. this.x = a.x - b.x;
  474. this.y = a.y - b.y;
  475. return this;
  476. }
  477. multiply( v ) {
  478. this.x *= v.x;
  479. this.y *= v.y;
  480. return this;
  481. }
  482. multiplyScalar( scalar ) {
  483. this.x *= scalar;
  484. this.y *= scalar;
  485. return this;
  486. }
  487. divide( v ) {
  488. this.x /= v.x;
  489. this.y /= v.y;
  490. return this;
  491. }
  492. divideScalar( scalar ) {
  493. return this.multiplyScalar( 1 / scalar );
  494. }
  495. applyMatrix3( m ) {
  496. const x = this.x, y = this.y;
  497. const e = m.elements;
  498. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  499. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  500. return this;
  501. }
  502. min( v ) {
  503. this.x = Math.min( this.x, v.x );
  504. this.y = Math.min( this.y, v.y );
  505. return this;
  506. }
  507. max( v ) {
  508. this.x = Math.max( this.x, v.x );
  509. this.y = Math.max( this.y, v.y );
  510. return this;
  511. }
  512. clamp( min, max ) {
  513. // assumes min < max, componentwise
  514. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  515. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  516. return this;
  517. }
  518. clampScalar( minVal, maxVal ) {
  519. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  520. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  521. return this;
  522. }
  523. clampLength( min, max ) {
  524. const length = this.length();
  525. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  526. }
  527. floor() {
  528. this.x = Math.floor( this.x );
  529. this.y = Math.floor( this.y );
  530. return this;
  531. }
  532. ceil() {
  533. this.x = Math.ceil( this.x );
  534. this.y = Math.ceil( this.y );
  535. return this;
  536. }
  537. round() {
  538. this.x = Math.round( this.x );
  539. this.y = Math.round( this.y );
  540. return this;
  541. }
  542. roundToZero() {
  543. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  544. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  545. return this;
  546. }
  547. negate() {
  548. this.x = - this.x;
  549. this.y = - this.y;
  550. return this;
  551. }
  552. dot( v ) {
  553. return this.x * v.x + this.y * v.y;
  554. }
  555. cross( v ) {
  556. return this.x * v.y - this.y * v.x;
  557. }
  558. lengthSq() {
  559. return this.x * this.x + this.y * this.y;
  560. }
  561. length() {
  562. return Math.sqrt( this.x * this.x + this.y * this.y );
  563. }
  564. manhattanLength() {
  565. return Math.abs( this.x ) + Math.abs( this.y );
  566. }
  567. normalize() {
  568. return this.divideScalar( this.length() || 1 );
  569. }
  570. angle() {
  571. // computes the angle in radians with respect to the positive x-axis
  572. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  573. return angle;
  574. }
  575. distanceTo( v ) {
  576. return Math.sqrt( this.distanceToSquared( v ) );
  577. }
  578. distanceToSquared( v ) {
  579. const dx = this.x - v.x, dy = this.y - v.y;
  580. return dx * dx + dy * dy;
  581. }
  582. manhattanDistanceTo( v ) {
  583. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  584. }
  585. setLength( length ) {
  586. return this.normalize().multiplyScalar( length );
  587. }
  588. lerp( v, alpha ) {
  589. this.x += ( v.x - this.x ) * alpha;
  590. this.y += ( v.y - this.y ) * alpha;
  591. return this;
  592. }
  593. lerpVectors( v1, v2, alpha ) {
  594. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  595. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  596. return this;
  597. }
  598. equals( v ) {
  599. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  600. }
  601. fromArray( array, offset = 0 ) {
  602. this.x = array[ offset ];
  603. this.y = array[ offset + 1 ];
  604. return this;
  605. }
  606. toArray( array = [], offset = 0 ) {
  607. array[ offset ] = this.x;
  608. array[ offset + 1 ] = this.y;
  609. return array;
  610. }
  611. fromBufferAttribute( attribute, index, offset ) {
  612. if ( offset !== undefined ) {
  613. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  614. }
  615. this.x = attribute.getX( index );
  616. this.y = attribute.getY( index );
  617. return this;
  618. }
  619. rotateAround( center, angle ) {
  620. const c = Math.cos( angle ), s = Math.sin( angle );
  621. const x = this.x - center.x;
  622. const y = this.y - center.y;
  623. this.x = x * c - y * s + center.x;
  624. this.y = x * s + y * c + center.y;
  625. return this;
  626. }
  627. random() {
  628. this.x = Math.random();
  629. this.y = Math.random();
  630. return this;
  631. }
  632. }
  633. Vector2.prototype.isVector2 = true;
  634. class Matrix3 {
  635. constructor() {
  636. this.elements = [
  637. 1, 0, 0,
  638. 0, 1, 0,
  639. 0, 0, 1
  640. ];
  641. if ( arguments.length > 0 ) {
  642. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  643. }
  644. }
  645. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  646. const te = this.elements;
  647. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  648. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  649. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  650. return this;
  651. }
  652. identity() {
  653. this.set(
  654. 1, 0, 0,
  655. 0, 1, 0,
  656. 0, 0, 1
  657. );
  658. return this;
  659. }
  660. copy( m ) {
  661. const te = this.elements;
  662. const me = m.elements;
  663. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  664. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  665. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  666. return this;
  667. }
  668. extractBasis( xAxis, yAxis, zAxis ) {
  669. xAxis.setFromMatrix3Column( this, 0 );
  670. yAxis.setFromMatrix3Column( this, 1 );
  671. zAxis.setFromMatrix3Column( this, 2 );
  672. return this;
  673. }
  674. setFromMatrix4( m ) {
  675. const me = m.elements;
  676. this.set(
  677. me[ 0 ], me[ 4 ], me[ 8 ],
  678. me[ 1 ], me[ 5 ], me[ 9 ],
  679. me[ 2 ], me[ 6 ], me[ 10 ]
  680. );
  681. return this;
  682. }
  683. multiply( m ) {
  684. return this.multiplyMatrices( this, m );
  685. }
  686. premultiply( m ) {
  687. return this.multiplyMatrices( m, this );
  688. }
  689. multiplyMatrices( a, b ) {
  690. const ae = a.elements;
  691. const be = b.elements;
  692. const te = this.elements;
  693. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  694. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  695. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  696. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  697. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  698. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  699. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  700. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  701. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  702. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  703. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  704. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  705. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  706. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  707. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  708. return this;
  709. }
  710. multiplyScalar( s ) {
  711. const te = this.elements;
  712. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  713. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  714. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  715. return this;
  716. }
  717. determinant() {
  718. const te = this.elements;
  719. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  720. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  721. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  722. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  723. }
  724. invert() {
  725. const te = this.elements,
  726. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  727. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  728. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  729. t11 = n33 * n22 - n32 * n23,
  730. t12 = n32 * n13 - n33 * n12,
  731. t13 = n23 * n12 - n22 * n13,
  732. det = n11 * t11 + n21 * t12 + n31 * t13;
  733. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  734. const detInv = 1 / det;
  735. te[ 0 ] = t11 * detInv;
  736. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  737. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  738. te[ 3 ] = t12 * detInv;
  739. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  740. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  741. te[ 6 ] = t13 * detInv;
  742. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  743. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  744. return this;
  745. }
  746. transpose() {
  747. let tmp;
  748. const m = this.elements;
  749. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  750. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  751. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  752. return this;
  753. }
  754. getNormalMatrix( matrix4 ) {
  755. return this.setFromMatrix4( matrix4 ).invert().transpose();
  756. }
  757. transposeIntoArray( r ) {
  758. const m = this.elements;
  759. r[ 0 ] = m[ 0 ];
  760. r[ 1 ] = m[ 3 ];
  761. r[ 2 ] = m[ 6 ];
  762. r[ 3 ] = m[ 1 ];
  763. r[ 4 ] = m[ 4 ];
  764. r[ 5 ] = m[ 7 ];
  765. r[ 6 ] = m[ 2 ];
  766. r[ 7 ] = m[ 5 ];
  767. r[ 8 ] = m[ 8 ];
  768. return this;
  769. }
  770. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  771. const c = Math.cos( rotation );
  772. const s = Math.sin( rotation );
  773. this.set(
  774. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  775. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  776. 0, 0, 1
  777. );
  778. return this;
  779. }
  780. scale( sx, sy ) {
  781. const te = this.elements;
  782. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  783. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  784. return this;
  785. }
  786. rotate( theta ) {
  787. const c = Math.cos( theta );
  788. const s = Math.sin( theta );
  789. const te = this.elements;
  790. const a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  791. const a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  792. te[ 0 ] = c * a11 + s * a21;
  793. te[ 3 ] = c * a12 + s * a22;
  794. te[ 6 ] = c * a13 + s * a23;
  795. te[ 1 ] = - s * a11 + c * a21;
  796. te[ 4 ] = - s * a12 + c * a22;
  797. te[ 7 ] = - s * a13 + c * a23;
  798. return this;
  799. }
  800. translate( tx, ty ) {
  801. const te = this.elements;
  802. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  803. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  804. return this;
  805. }
  806. equals( matrix ) {
  807. const te = this.elements;
  808. const me = matrix.elements;
  809. for ( let i = 0; i < 9; i ++ ) {
  810. if ( te[ i ] !== me[ i ] ) return false;
  811. }
  812. return true;
  813. }
  814. fromArray( array, offset = 0 ) {
  815. for ( let i = 0; i < 9; i ++ ) {
  816. this.elements[ i ] = array[ i + offset ];
  817. }
  818. return this;
  819. }
  820. toArray( array = [], offset = 0 ) {
  821. const te = this.elements;
  822. array[ offset ] = te[ 0 ];
  823. array[ offset + 1 ] = te[ 1 ];
  824. array[ offset + 2 ] = te[ 2 ];
  825. array[ offset + 3 ] = te[ 3 ];
  826. array[ offset + 4 ] = te[ 4 ];
  827. array[ offset + 5 ] = te[ 5 ];
  828. array[ offset + 6 ] = te[ 6 ];
  829. array[ offset + 7 ] = te[ 7 ];
  830. array[ offset + 8 ] = te[ 8 ];
  831. return array;
  832. }
  833. clone() {
  834. return new this.constructor().fromArray( this.elements );
  835. }
  836. }
  837. Matrix3.prototype.isMatrix3 = true;
  838. let _canvas;
  839. const ImageUtils = {
  840. getDataURL: function ( image ) {
  841. if ( /^data:/i.test( image.src ) ) {
  842. return image.src;
  843. }
  844. if ( typeof HTMLCanvasElement == 'undefined' ) {
  845. return image.src;
  846. }
  847. let canvas;
  848. if ( image instanceof HTMLCanvasElement ) {
  849. canvas = image;
  850. } else {
  851. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  852. _canvas.width = image.width;
  853. _canvas.height = image.height;
  854. const context = _canvas.getContext( '2d' );
  855. if ( image instanceof ImageData ) {
  856. context.putImageData( image, 0, 0 );
  857. } else {
  858. context.drawImage( image, 0, 0, image.width, image.height );
  859. }
  860. canvas = _canvas;
  861. }
  862. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  863. console.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image );
  864. return canvas.toDataURL( 'image/jpeg', 0.6 );
  865. } else {
  866. return canvas.toDataURL( 'image/png' );
  867. }
  868. }
  869. };
  870. let textureId = 0;
  871. class Texture extends EventDispatcher {
  872. 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 ) {
  873. super();
  874. Object.defineProperty( this, 'id', { value: textureId ++ } );
  875. this.uuid = MathUtils.generateUUID();
  876. this.name = '';
  877. this.image = image;
  878. this.mipmaps = [];
  879. this.mapping = mapping;
  880. this.wrapS = wrapS;
  881. this.wrapT = wrapT;
  882. this.magFilter = magFilter;
  883. this.minFilter = minFilter;
  884. this.anisotropy = anisotropy;
  885. this.format = format;
  886. this.internalFormat = null;
  887. this.type = type;
  888. this.offset = new Vector2( 0, 0 );
  889. this.repeat = new Vector2( 1, 1 );
  890. this.center = new Vector2( 0, 0 );
  891. this.rotation = 0;
  892. this.matrixAutoUpdate = true;
  893. this.matrix = new Matrix3();
  894. this.generateMipmaps = true;
  895. this.premultiplyAlpha = false;
  896. this.flipY = true;
  897. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  898. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  899. //
  900. // Also changing the encoding after already used by a Material will not automatically make the Material
  901. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  902. this.encoding = encoding;
  903. this.version = 0;
  904. this.onUpdate = null;
  905. }
  906. updateMatrix() {
  907. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  908. }
  909. clone() {
  910. return new this.constructor().copy( this );
  911. }
  912. copy( source ) {
  913. this.name = source.name;
  914. this.image = source.image;
  915. this.mipmaps = source.mipmaps.slice( 0 );
  916. this.mapping = source.mapping;
  917. this.wrapS = source.wrapS;
  918. this.wrapT = source.wrapT;
  919. this.magFilter = source.magFilter;
  920. this.minFilter = source.minFilter;
  921. this.anisotropy = source.anisotropy;
  922. this.format = source.format;
  923. this.internalFormat = source.internalFormat;
  924. this.type = source.type;
  925. this.offset.copy( source.offset );
  926. this.repeat.copy( source.repeat );
  927. this.center.copy( source.center );
  928. this.rotation = source.rotation;
  929. this.matrixAutoUpdate = source.matrixAutoUpdate;
  930. this.matrix.copy( source.matrix );
  931. this.generateMipmaps = source.generateMipmaps;
  932. this.premultiplyAlpha = source.premultiplyAlpha;
  933. this.flipY = source.flipY;
  934. this.unpackAlignment = source.unpackAlignment;
  935. this.encoding = source.encoding;
  936. return this;
  937. }
  938. toJSON( meta ) {
  939. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  940. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  941. return meta.textures[ this.uuid ];
  942. }
  943. const output = {
  944. metadata: {
  945. version: 4.5,
  946. type: 'Texture',
  947. generator: 'Texture.toJSON'
  948. },
  949. uuid: this.uuid,
  950. name: this.name,
  951. mapping: this.mapping,
  952. repeat: [ this.repeat.x, this.repeat.y ],
  953. offset: [ this.offset.x, this.offset.y ],
  954. center: [ this.center.x, this.center.y ],
  955. rotation: this.rotation,
  956. wrap: [ this.wrapS, this.wrapT ],
  957. format: this.format,
  958. type: this.type,
  959. encoding: this.encoding,
  960. minFilter: this.minFilter,
  961. magFilter: this.magFilter,
  962. anisotropy: this.anisotropy,
  963. flipY: this.flipY,
  964. premultiplyAlpha: this.premultiplyAlpha,
  965. unpackAlignment: this.unpackAlignment
  966. };
  967. if ( this.image !== undefined ) {
  968. // TODO: Move to THREE.Image
  969. const image = this.image;
  970. if ( image.uuid === undefined ) {
  971. image.uuid = MathUtils.generateUUID(); // UGH
  972. }
  973. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  974. let url;
  975. if ( Array.isArray( image ) ) {
  976. // process array of images e.g. CubeTexture
  977. url = [];
  978. for ( let i = 0, l = image.length; i < l; i ++ ) {
  979. // check cube texture with data textures
  980. if ( image[ i ].isDataTexture ) {
  981. url.push( serializeImage( image[ i ].image ) );
  982. } else {
  983. url.push( serializeImage( image[ i ] ) );
  984. }
  985. }
  986. } else {
  987. // process single image
  988. url = serializeImage( image );
  989. }
  990. meta.images[ image.uuid ] = {
  991. uuid: image.uuid,
  992. url: url
  993. };
  994. }
  995. output.image = image.uuid;
  996. }
  997. if ( ! isRootObject ) {
  998. meta.textures[ this.uuid ] = output;
  999. }
  1000. return output;
  1001. }
  1002. dispose() {
  1003. this.dispatchEvent( { type: 'dispose' } );
  1004. }
  1005. transformUv( uv ) {
  1006. if ( this.mapping !== UVMapping ) return uv;
  1007. uv.applyMatrix3( this.matrix );
  1008. if ( uv.x < 0 || uv.x > 1 ) {
  1009. switch ( this.wrapS ) {
  1010. case RepeatWrapping:
  1011. uv.x = uv.x - Math.floor( uv.x );
  1012. break;
  1013. case ClampToEdgeWrapping:
  1014. uv.x = uv.x < 0 ? 0 : 1;
  1015. break;
  1016. case MirroredRepeatWrapping:
  1017. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1018. uv.x = Math.ceil( uv.x ) - uv.x;
  1019. } else {
  1020. uv.x = uv.x - Math.floor( uv.x );
  1021. }
  1022. break;
  1023. }
  1024. }
  1025. if ( uv.y < 0 || uv.y > 1 ) {
  1026. switch ( this.wrapT ) {
  1027. case RepeatWrapping:
  1028. uv.y = uv.y - Math.floor( uv.y );
  1029. break;
  1030. case ClampToEdgeWrapping:
  1031. uv.y = uv.y < 0 ? 0 : 1;
  1032. break;
  1033. case MirroredRepeatWrapping:
  1034. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1035. uv.y = Math.ceil( uv.y ) - uv.y;
  1036. } else {
  1037. uv.y = uv.y - Math.floor( uv.y );
  1038. }
  1039. break;
  1040. }
  1041. }
  1042. if ( this.flipY ) {
  1043. uv.y = 1 - uv.y;
  1044. }
  1045. return uv;
  1046. }
  1047. set needsUpdate( value ) {
  1048. if ( value === true ) this.version ++;
  1049. }
  1050. }
  1051. Texture.DEFAULT_IMAGE = undefined;
  1052. Texture.DEFAULT_MAPPING = UVMapping;
  1053. Texture.prototype.isTexture = true;
  1054. function serializeImage( image ) {
  1055. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1056. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1057. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1058. // default images
  1059. return ImageUtils.getDataURL( image );
  1060. } else {
  1061. if ( image.data ) {
  1062. // images of DataTexture
  1063. return {
  1064. data: Array.prototype.slice.call( image.data ),
  1065. width: image.width,
  1066. height: image.height,
  1067. type: image.data.constructor.name
  1068. };
  1069. } else {
  1070. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1071. return {};
  1072. }
  1073. }
  1074. }
  1075. class Vector4 {
  1076. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1077. this.x = x;
  1078. this.y = y;
  1079. this.z = z;
  1080. this.w = w;
  1081. }
  1082. get width() {
  1083. return this.z;
  1084. }
  1085. set width( value ) {
  1086. this.z = value;
  1087. }
  1088. get height() {
  1089. return this.w;
  1090. }
  1091. set height( value ) {
  1092. this.w = value;
  1093. }
  1094. set( x, y, z, w ) {
  1095. this.x = x;
  1096. this.y = y;
  1097. this.z = z;
  1098. this.w = w;
  1099. return this;
  1100. }
  1101. setScalar( scalar ) {
  1102. this.x = scalar;
  1103. this.y = scalar;
  1104. this.z = scalar;
  1105. this.w = scalar;
  1106. return this;
  1107. }
  1108. setX( x ) {
  1109. this.x = x;
  1110. return this;
  1111. }
  1112. setY( y ) {
  1113. this.y = y;
  1114. return this;
  1115. }
  1116. setZ( z ) {
  1117. this.z = z;
  1118. return this;
  1119. }
  1120. setW( w ) {
  1121. this.w = w;
  1122. return this;
  1123. }
  1124. setComponent( index, value ) {
  1125. switch ( index ) {
  1126. case 0: this.x = value; break;
  1127. case 1: this.y = value; break;
  1128. case 2: this.z = value; break;
  1129. case 3: this.w = value; break;
  1130. default: throw new Error( 'index is out of range: ' + index );
  1131. }
  1132. return this;
  1133. }
  1134. getComponent( index ) {
  1135. switch ( index ) {
  1136. case 0: return this.x;
  1137. case 1: return this.y;
  1138. case 2: return this.z;
  1139. case 3: return this.w;
  1140. default: throw new Error( 'index is out of range: ' + index );
  1141. }
  1142. }
  1143. clone() {
  1144. return new this.constructor( this.x, this.y, this.z, this.w );
  1145. }
  1146. copy( v ) {
  1147. this.x = v.x;
  1148. this.y = v.y;
  1149. this.z = v.z;
  1150. this.w = ( v.w !== undefined ) ? v.w : 1;
  1151. return this;
  1152. }
  1153. add( v, w ) {
  1154. if ( w !== undefined ) {
  1155. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1156. return this.addVectors( v, w );
  1157. }
  1158. this.x += v.x;
  1159. this.y += v.y;
  1160. this.z += v.z;
  1161. this.w += v.w;
  1162. return this;
  1163. }
  1164. addScalar( s ) {
  1165. this.x += s;
  1166. this.y += s;
  1167. this.z += s;
  1168. this.w += s;
  1169. return this;
  1170. }
  1171. addVectors( a, b ) {
  1172. this.x = a.x + b.x;
  1173. this.y = a.y + b.y;
  1174. this.z = a.z + b.z;
  1175. this.w = a.w + b.w;
  1176. return this;
  1177. }
  1178. addScaledVector( v, s ) {
  1179. this.x += v.x * s;
  1180. this.y += v.y * s;
  1181. this.z += v.z * s;
  1182. this.w += v.w * s;
  1183. return this;
  1184. }
  1185. sub( v, w ) {
  1186. if ( w !== undefined ) {
  1187. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1188. return this.subVectors( v, w );
  1189. }
  1190. this.x -= v.x;
  1191. this.y -= v.y;
  1192. this.z -= v.z;
  1193. this.w -= v.w;
  1194. return this;
  1195. }
  1196. subScalar( s ) {
  1197. this.x -= s;
  1198. this.y -= s;
  1199. this.z -= s;
  1200. this.w -= s;
  1201. return this;
  1202. }
  1203. subVectors( a, b ) {
  1204. this.x = a.x - b.x;
  1205. this.y = a.y - b.y;
  1206. this.z = a.z - b.z;
  1207. this.w = a.w - b.w;
  1208. return this;
  1209. }
  1210. multiply( v ) {
  1211. this.x *= v.x;
  1212. this.y *= v.y;
  1213. this.z *= v.z;
  1214. this.w *= v.w;
  1215. return this;
  1216. }
  1217. multiplyScalar( scalar ) {
  1218. this.x *= scalar;
  1219. this.y *= scalar;
  1220. this.z *= scalar;
  1221. this.w *= scalar;
  1222. return this;
  1223. }
  1224. applyMatrix4( m ) {
  1225. const x = this.x, y = this.y, z = this.z, w = this.w;
  1226. const e = m.elements;
  1227. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1228. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1229. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1230. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1231. return this;
  1232. }
  1233. divideScalar( scalar ) {
  1234. return this.multiplyScalar( 1 / scalar );
  1235. }
  1236. setAxisAngleFromQuaternion( q ) {
  1237. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1238. // q is assumed to be normalized
  1239. this.w = 2 * Math.acos( q.w );
  1240. const s = Math.sqrt( 1 - q.w * q.w );
  1241. if ( s < 0.0001 ) {
  1242. this.x = 1;
  1243. this.y = 0;
  1244. this.z = 0;
  1245. } else {
  1246. this.x = q.x / s;
  1247. this.y = q.y / s;
  1248. this.z = q.z / s;
  1249. }
  1250. return this;
  1251. }
  1252. setAxisAngleFromRotationMatrix( m ) {
  1253. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1254. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1255. let angle, x, y, z; // variables for result
  1256. const epsilon = 0.01, // margin to allow for rounding errors
  1257. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1258. te = m.elements,
  1259. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1260. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1261. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1262. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1263. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1264. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1265. // singularity found
  1266. // first check for identity matrix which must have +1 for all terms
  1267. // in leading diagonal and zero in other terms
  1268. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1269. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1270. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1271. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1272. // this singularity is identity matrix so angle = 0
  1273. this.set( 1, 0, 0, 0 );
  1274. return this; // zero angle, arbitrary axis
  1275. }
  1276. // otherwise this singularity is angle = 180
  1277. angle = Math.PI;
  1278. const xx = ( m11 + 1 ) / 2;
  1279. const yy = ( m22 + 1 ) / 2;
  1280. const zz = ( m33 + 1 ) / 2;
  1281. const xy = ( m12 + m21 ) / 4;
  1282. const xz = ( m13 + m31 ) / 4;
  1283. const yz = ( m23 + m32 ) / 4;
  1284. if ( ( xx > yy ) && ( xx > zz ) ) {
  1285. // m11 is the largest diagonal term
  1286. if ( xx < epsilon ) {
  1287. x = 0;
  1288. y = 0.707106781;
  1289. z = 0.707106781;
  1290. } else {
  1291. x = Math.sqrt( xx );
  1292. y = xy / x;
  1293. z = xz / x;
  1294. }
  1295. } else if ( yy > zz ) {
  1296. // m22 is the largest diagonal term
  1297. if ( yy < epsilon ) {
  1298. x = 0.707106781;
  1299. y = 0;
  1300. z = 0.707106781;
  1301. } else {
  1302. y = Math.sqrt( yy );
  1303. x = xy / y;
  1304. z = yz / y;
  1305. }
  1306. } else {
  1307. // m33 is the largest diagonal term so base result on this
  1308. if ( zz < epsilon ) {
  1309. x = 0.707106781;
  1310. y = 0.707106781;
  1311. z = 0;
  1312. } else {
  1313. z = Math.sqrt( zz );
  1314. x = xz / z;
  1315. y = yz / z;
  1316. }
  1317. }
  1318. this.set( x, y, z, angle );
  1319. return this; // return 180 deg rotation
  1320. }
  1321. // as we have reached here there are no singularities so we can handle normally
  1322. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1323. ( m13 - m31 ) * ( m13 - m31 ) +
  1324. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1325. if ( Math.abs( s ) < 0.001 ) s = 1;
  1326. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1327. // caught by singularity test above, but I've left it in just in case
  1328. this.x = ( m32 - m23 ) / s;
  1329. this.y = ( m13 - m31 ) / s;
  1330. this.z = ( m21 - m12 ) / s;
  1331. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1332. return this;
  1333. }
  1334. min( v ) {
  1335. this.x = Math.min( this.x, v.x );
  1336. this.y = Math.min( this.y, v.y );
  1337. this.z = Math.min( this.z, v.z );
  1338. this.w = Math.min( this.w, v.w );
  1339. return this;
  1340. }
  1341. max( v ) {
  1342. this.x = Math.max( this.x, v.x );
  1343. this.y = Math.max( this.y, v.y );
  1344. this.z = Math.max( this.z, v.z );
  1345. this.w = Math.max( this.w, v.w );
  1346. return this;
  1347. }
  1348. clamp( min, max ) {
  1349. // assumes min < max, componentwise
  1350. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1351. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1352. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1353. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1354. return this;
  1355. }
  1356. clampScalar( minVal, maxVal ) {
  1357. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1358. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1359. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1360. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1361. return this;
  1362. }
  1363. clampLength( min, max ) {
  1364. const length = this.length();
  1365. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1366. }
  1367. floor() {
  1368. this.x = Math.floor( this.x );
  1369. this.y = Math.floor( this.y );
  1370. this.z = Math.floor( this.z );
  1371. this.w = Math.floor( this.w );
  1372. return this;
  1373. }
  1374. ceil() {
  1375. this.x = Math.ceil( this.x );
  1376. this.y = Math.ceil( this.y );
  1377. this.z = Math.ceil( this.z );
  1378. this.w = Math.ceil( this.w );
  1379. return this;
  1380. }
  1381. round() {
  1382. this.x = Math.round( this.x );
  1383. this.y = Math.round( this.y );
  1384. this.z = Math.round( this.z );
  1385. this.w = Math.round( this.w );
  1386. return this;
  1387. }
  1388. roundToZero() {
  1389. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1390. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1391. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1392. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1393. return this;
  1394. }
  1395. negate() {
  1396. this.x = - this.x;
  1397. this.y = - this.y;
  1398. this.z = - this.z;
  1399. this.w = - this.w;
  1400. return this;
  1401. }
  1402. dot( v ) {
  1403. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1404. }
  1405. lengthSq() {
  1406. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1407. }
  1408. length() {
  1409. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1410. }
  1411. manhattanLength() {
  1412. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1413. }
  1414. normalize() {
  1415. return this.divideScalar( this.length() || 1 );
  1416. }
  1417. setLength( length ) {
  1418. return this.normalize().multiplyScalar( length );
  1419. }
  1420. lerp( v, alpha ) {
  1421. this.x += ( v.x - this.x ) * alpha;
  1422. this.y += ( v.y - this.y ) * alpha;
  1423. this.z += ( v.z - this.z ) * alpha;
  1424. this.w += ( v.w - this.w ) * alpha;
  1425. return this;
  1426. }
  1427. lerpVectors( v1, v2, alpha ) {
  1428. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1429. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1430. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1431. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1432. return this;
  1433. }
  1434. equals( v ) {
  1435. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1436. }
  1437. fromArray( array, offset = 0 ) {
  1438. this.x = array[ offset ];
  1439. this.y = array[ offset + 1 ];
  1440. this.z = array[ offset + 2 ];
  1441. this.w = array[ offset + 3 ];
  1442. return this;
  1443. }
  1444. toArray( array = [], offset = 0 ) {
  1445. array[ offset ] = this.x;
  1446. array[ offset + 1 ] = this.y;
  1447. array[ offset + 2 ] = this.z;
  1448. array[ offset + 3 ] = this.w;
  1449. return array;
  1450. }
  1451. fromBufferAttribute( attribute, index, offset ) {
  1452. if ( offset !== undefined ) {
  1453. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1454. }
  1455. this.x = attribute.getX( index );
  1456. this.y = attribute.getY( index );
  1457. this.z = attribute.getZ( index );
  1458. this.w = attribute.getW( index );
  1459. return this;
  1460. }
  1461. random() {
  1462. this.x = Math.random();
  1463. this.y = Math.random();
  1464. this.z = Math.random();
  1465. this.w = Math.random();
  1466. return this;
  1467. }
  1468. }
  1469. Vector4.prototype.isVector4 = true;
  1470. /*
  1471. In options, we can specify:
  1472. * Texture parameters for an auto-generated target texture
  1473. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1474. */
  1475. class WebGLRenderTarget extends EventDispatcher {
  1476. constructor( width, height, options ) {
  1477. super();
  1478. this.width = width;
  1479. this.height = height;
  1480. this.depth = 1;
  1481. this.scissor = new Vector4( 0, 0, width, height );
  1482. this.scissorTest = false;
  1483. this.viewport = new Vector4( 0, 0, width, height );
  1484. options = options || {};
  1485. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1486. this.texture.image = {};
  1487. this.texture.image.width = width;
  1488. this.texture.image.height = height;
  1489. this.texture.image.depth = 1;
  1490. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1491. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1492. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1493. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1494. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1495. }
  1496. setTexture( texture ) {
  1497. texture.image = {
  1498. width: this.width,
  1499. height: this.height,
  1500. depth: this.depth
  1501. };
  1502. this.texture = texture;
  1503. }
  1504. setSize( width, height, depth = 1 ) {
  1505. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1506. this.width = width;
  1507. this.height = height;
  1508. this.depth = depth;
  1509. this.texture.image.width = width;
  1510. this.texture.image.height = height;
  1511. this.texture.image.depth = depth;
  1512. this.dispose();
  1513. }
  1514. this.viewport.set( 0, 0, width, height );
  1515. this.scissor.set( 0, 0, width, height );
  1516. }
  1517. clone() {
  1518. return new this.constructor().copy( this );
  1519. }
  1520. copy( source ) {
  1521. this.width = source.width;
  1522. this.height = source.height;
  1523. this.depth = source.depth;
  1524. this.viewport.copy( source.viewport );
  1525. this.texture = source.texture.clone();
  1526. this.depthBuffer = source.depthBuffer;
  1527. this.stencilBuffer = source.stencilBuffer;
  1528. this.depthTexture = source.depthTexture;
  1529. return this;
  1530. }
  1531. dispose() {
  1532. this.dispatchEvent( { type: 'dispose' } );
  1533. }
  1534. }
  1535. WebGLRenderTarget.prototype.isWebGLRenderTarget = true;
  1536. class WebGLMultisampleRenderTarget extends WebGLRenderTarget {
  1537. constructor( width, height, options ) {
  1538. super( width, height, options );
  1539. this.samples = 4;
  1540. }
  1541. copy( source ) {
  1542. super.copy.call( this, source );
  1543. this.samples = source.samples;
  1544. return this;
  1545. }
  1546. }
  1547. WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
  1548. class Quaternion {
  1549. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1550. this._x = x;
  1551. this._y = y;
  1552. this._z = z;
  1553. this._w = w;
  1554. }
  1555. static slerp( qa, qb, qm, t ) {
  1556. return qm.copy( qa ).slerp( qb, t );
  1557. }
  1558. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1559. // fuzz-free, array-based Quaternion SLERP operation
  1560. let x0 = src0[ srcOffset0 + 0 ],
  1561. y0 = src0[ srcOffset0 + 1 ],
  1562. z0 = src0[ srcOffset0 + 2 ],
  1563. w0 = src0[ srcOffset0 + 3 ];
  1564. const x1 = src1[ srcOffset1 + 0 ],
  1565. y1 = src1[ srcOffset1 + 1 ],
  1566. z1 = src1[ srcOffset1 + 2 ],
  1567. w1 = src1[ srcOffset1 + 3 ];
  1568. if ( t === 0 ) {
  1569. dst[ dstOffset + 0 ] = x0;
  1570. dst[ dstOffset + 1 ] = y0;
  1571. dst[ dstOffset + 2 ] = z0;
  1572. dst[ dstOffset + 3 ] = w0;
  1573. return;
  1574. }
  1575. if ( t === 1 ) {
  1576. dst[ dstOffset + 0 ] = x1;
  1577. dst[ dstOffset + 1 ] = y1;
  1578. dst[ dstOffset + 2 ] = z1;
  1579. dst[ dstOffset + 3 ] = w1;
  1580. return;
  1581. }
  1582. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1583. let s = 1 - t;
  1584. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1585. dir = ( cos >= 0 ? 1 : - 1 ),
  1586. sqrSin = 1 - cos * cos;
  1587. // Skip the Slerp for tiny steps to avoid numeric problems:
  1588. if ( sqrSin > Number.EPSILON ) {
  1589. const sin = Math.sqrt( sqrSin ),
  1590. len = Math.atan2( sin, cos * dir );
  1591. s = Math.sin( s * len ) / sin;
  1592. t = Math.sin( t * len ) / sin;
  1593. }
  1594. const tDir = t * dir;
  1595. x0 = x0 * s + x1 * tDir;
  1596. y0 = y0 * s + y1 * tDir;
  1597. z0 = z0 * s + z1 * tDir;
  1598. w0 = w0 * s + w1 * tDir;
  1599. // Normalize in case we just did a lerp:
  1600. if ( s === 1 - t ) {
  1601. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1602. x0 *= f;
  1603. y0 *= f;
  1604. z0 *= f;
  1605. w0 *= f;
  1606. }
  1607. }
  1608. dst[ dstOffset ] = x0;
  1609. dst[ dstOffset + 1 ] = y0;
  1610. dst[ dstOffset + 2 ] = z0;
  1611. dst[ dstOffset + 3 ] = w0;
  1612. }
  1613. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1614. const x0 = src0[ srcOffset0 ];
  1615. const y0 = src0[ srcOffset0 + 1 ];
  1616. const z0 = src0[ srcOffset0 + 2 ];
  1617. const w0 = src0[ srcOffset0 + 3 ];
  1618. const x1 = src1[ srcOffset1 ];
  1619. const y1 = src1[ srcOffset1 + 1 ];
  1620. const z1 = src1[ srcOffset1 + 2 ];
  1621. const w1 = src1[ srcOffset1 + 3 ];
  1622. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1623. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1624. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1625. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1626. return dst;
  1627. }
  1628. get x() {
  1629. return this._x;
  1630. }
  1631. set x( value ) {
  1632. this._x = value;
  1633. this._onChangeCallback();
  1634. }
  1635. get y() {
  1636. return this._y;
  1637. }
  1638. set y( value ) {
  1639. this._y = value;
  1640. this._onChangeCallback();
  1641. }
  1642. get z() {
  1643. return this._z;
  1644. }
  1645. set z( value ) {
  1646. this._z = value;
  1647. this._onChangeCallback();
  1648. }
  1649. get w() {
  1650. return this._w;
  1651. }
  1652. set w( value ) {
  1653. this._w = value;
  1654. this._onChangeCallback();
  1655. }
  1656. set( x, y, z, w ) {
  1657. this._x = x;
  1658. this._y = y;
  1659. this._z = z;
  1660. this._w = w;
  1661. this._onChangeCallback();
  1662. return this;
  1663. }
  1664. clone() {
  1665. return new this.constructor( this._x, this._y, this._z, this._w );
  1666. }
  1667. copy( quaternion ) {
  1668. this._x = quaternion.x;
  1669. this._y = quaternion.y;
  1670. this._z = quaternion.z;
  1671. this._w = quaternion.w;
  1672. this._onChangeCallback();
  1673. return this;
  1674. }
  1675. setFromEuler( euler, update ) {
  1676. if ( ! ( euler && euler.isEuler ) ) {
  1677. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1678. }
  1679. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  1680. // http://www.mathworks.com/matlabcentral/fileexchange/
  1681. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1682. // content/SpinCalc.m
  1683. const cos = Math.cos;
  1684. const sin = Math.sin;
  1685. const c1 = cos( x / 2 );
  1686. const c2 = cos( y / 2 );
  1687. const c3 = cos( z / 2 );
  1688. const s1 = sin( x / 2 );
  1689. const s2 = sin( y / 2 );
  1690. const s3 = sin( z / 2 );
  1691. switch ( order ) {
  1692. case 'XYZ':
  1693. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1694. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1695. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1696. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1697. break;
  1698. case 'YXZ':
  1699. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1700. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1701. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1702. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1703. break;
  1704. case 'ZXY':
  1705. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1706. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1707. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1708. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1709. break;
  1710. case 'ZYX':
  1711. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1712. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1713. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1714. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1715. break;
  1716. case 'YZX':
  1717. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1718. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1719. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1720. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1721. break;
  1722. case 'XZY':
  1723. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1724. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1725. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1726. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1727. break;
  1728. default:
  1729. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1730. }
  1731. if ( update !== false ) this._onChangeCallback();
  1732. return this;
  1733. }
  1734. setFromAxisAngle( axis, angle ) {
  1735. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1736. // assumes axis is normalized
  1737. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  1738. this._x = axis.x * s;
  1739. this._y = axis.y * s;
  1740. this._z = axis.z * s;
  1741. this._w = Math.cos( halfAngle );
  1742. this._onChangeCallback();
  1743. return this;
  1744. }
  1745. setFromRotationMatrix( m ) {
  1746. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1747. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1748. const te = m.elements,
  1749. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1750. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1751. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1752. trace = m11 + m22 + m33;
  1753. if ( trace > 0 ) {
  1754. const s = 0.5 / Math.sqrt( trace + 1.0 );
  1755. this._w = 0.25 / s;
  1756. this._x = ( m32 - m23 ) * s;
  1757. this._y = ( m13 - m31 ) * s;
  1758. this._z = ( m21 - m12 ) * s;
  1759. } else if ( m11 > m22 && m11 > m33 ) {
  1760. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1761. this._w = ( m32 - m23 ) / s;
  1762. this._x = 0.25 * s;
  1763. this._y = ( m12 + m21 ) / s;
  1764. this._z = ( m13 + m31 ) / s;
  1765. } else if ( m22 > m33 ) {
  1766. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1767. this._w = ( m13 - m31 ) / s;
  1768. this._x = ( m12 + m21 ) / s;
  1769. this._y = 0.25 * s;
  1770. this._z = ( m23 + m32 ) / s;
  1771. } else {
  1772. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1773. this._w = ( m21 - m12 ) / s;
  1774. this._x = ( m13 + m31 ) / s;
  1775. this._y = ( m23 + m32 ) / s;
  1776. this._z = 0.25 * s;
  1777. }
  1778. this._onChangeCallback();
  1779. return this;
  1780. }
  1781. setFromUnitVectors( vFrom, vTo ) {
  1782. // assumes direction vectors vFrom and vTo are normalized
  1783. const EPS = 0.000001;
  1784. let r = vFrom.dot( vTo ) + 1;
  1785. if ( r < EPS ) {
  1786. r = 0;
  1787. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1788. this._x = - vFrom.y;
  1789. this._y = vFrom.x;
  1790. this._z = 0;
  1791. this._w = r;
  1792. } else {
  1793. this._x = 0;
  1794. this._y = - vFrom.z;
  1795. this._z = vFrom.y;
  1796. this._w = r;
  1797. }
  1798. } else {
  1799. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1800. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1801. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1802. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1803. this._w = r;
  1804. }
  1805. return this.normalize();
  1806. }
  1807. angleTo( q ) {
  1808. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1809. }
  1810. rotateTowards( q, step ) {
  1811. const angle = this.angleTo( q );
  1812. if ( angle === 0 ) return this;
  1813. const t = Math.min( 1, step / angle );
  1814. this.slerp( q, t );
  1815. return this;
  1816. }
  1817. identity() {
  1818. return this.set( 0, 0, 0, 1 );
  1819. }
  1820. invert() {
  1821. // quaternion is assumed to have unit length
  1822. return this.conjugate();
  1823. }
  1824. conjugate() {
  1825. this._x *= - 1;
  1826. this._y *= - 1;
  1827. this._z *= - 1;
  1828. this._onChangeCallback();
  1829. return this;
  1830. }
  1831. dot( v ) {
  1832. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1833. }
  1834. lengthSq() {
  1835. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1836. }
  1837. length() {
  1838. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1839. }
  1840. normalize() {
  1841. let l = this.length();
  1842. if ( l === 0 ) {
  1843. this._x = 0;
  1844. this._y = 0;
  1845. this._z = 0;
  1846. this._w = 1;
  1847. } else {
  1848. l = 1 / l;
  1849. this._x = this._x * l;
  1850. this._y = this._y * l;
  1851. this._z = this._z * l;
  1852. this._w = this._w * l;
  1853. }
  1854. this._onChangeCallback();
  1855. return this;
  1856. }
  1857. multiply( q, p ) {
  1858. if ( p !== undefined ) {
  1859. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1860. return this.multiplyQuaternions( q, p );
  1861. }
  1862. return this.multiplyQuaternions( this, q );
  1863. }
  1864. premultiply( q ) {
  1865. return this.multiplyQuaternions( q, this );
  1866. }
  1867. multiplyQuaternions( a, b ) {
  1868. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1869. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1870. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1871. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1872. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1873. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1874. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1875. this._onChangeCallback();
  1876. return this;
  1877. }
  1878. slerp( qb, t ) {
  1879. if ( t === 0 ) return this;
  1880. if ( t === 1 ) return this.copy( qb );
  1881. const x = this._x, y = this._y, z = this._z, w = this._w;
  1882. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1883. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1884. if ( cosHalfTheta < 0 ) {
  1885. this._w = - qb._w;
  1886. this._x = - qb._x;
  1887. this._y = - qb._y;
  1888. this._z = - qb._z;
  1889. cosHalfTheta = - cosHalfTheta;
  1890. } else {
  1891. this.copy( qb );
  1892. }
  1893. if ( cosHalfTheta >= 1.0 ) {
  1894. this._w = w;
  1895. this._x = x;
  1896. this._y = y;
  1897. this._z = z;
  1898. return this;
  1899. }
  1900. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1901. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1902. const s = 1 - t;
  1903. this._w = s * w + t * this._w;
  1904. this._x = s * x + t * this._x;
  1905. this._y = s * y + t * this._y;
  1906. this._z = s * z + t * this._z;
  1907. this.normalize();
  1908. this._onChangeCallback();
  1909. return this;
  1910. }
  1911. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1912. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1913. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1914. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1915. this._w = ( w * ratioA + this._w * ratioB );
  1916. this._x = ( x * ratioA + this._x * ratioB );
  1917. this._y = ( y * ratioA + this._y * ratioB );
  1918. this._z = ( z * ratioA + this._z * ratioB );
  1919. this._onChangeCallback();
  1920. return this;
  1921. }
  1922. equals( quaternion ) {
  1923. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1924. }
  1925. fromArray( array, offset = 0 ) {
  1926. this._x = array[ offset ];
  1927. this._y = array[ offset + 1 ];
  1928. this._z = array[ offset + 2 ];
  1929. this._w = array[ offset + 3 ];
  1930. this._onChangeCallback();
  1931. return this;
  1932. }
  1933. toArray( array = [], offset = 0 ) {
  1934. array[ offset ] = this._x;
  1935. array[ offset + 1 ] = this._y;
  1936. array[ offset + 2 ] = this._z;
  1937. array[ offset + 3 ] = this._w;
  1938. return array;
  1939. }
  1940. fromBufferAttribute( attribute, index ) {
  1941. this._x = attribute.getX( index );
  1942. this._y = attribute.getY( index );
  1943. this._z = attribute.getZ( index );
  1944. this._w = attribute.getW( index );
  1945. return this;
  1946. }
  1947. _onChange( callback ) {
  1948. this._onChangeCallback = callback;
  1949. return this;
  1950. }
  1951. _onChangeCallback() {}
  1952. }
  1953. Quaternion.prototype.isQuaternion = true;
  1954. class Vector3 {
  1955. constructor( x = 0, y = 0, z = 0 ) {
  1956. this.x = x;
  1957. this.y = y;
  1958. this.z = z;
  1959. }
  1960. set( x, y, z ) {
  1961. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  1962. this.x = x;
  1963. this.y = y;
  1964. this.z = z;
  1965. return this;
  1966. }
  1967. setScalar( scalar ) {
  1968. this.x = scalar;
  1969. this.y = scalar;
  1970. this.z = scalar;
  1971. return this;
  1972. }
  1973. setX( x ) {
  1974. this.x = x;
  1975. return this;
  1976. }
  1977. setY( y ) {
  1978. this.y = y;
  1979. return this;
  1980. }
  1981. setZ( z ) {
  1982. this.z = z;
  1983. return this;
  1984. }
  1985. setComponent( index, value ) {
  1986. switch ( index ) {
  1987. case 0: this.x = value; break;
  1988. case 1: this.y = value; break;
  1989. case 2: this.z = value; break;
  1990. default: throw new Error( 'index is out of range: ' + index );
  1991. }
  1992. return this;
  1993. }
  1994. getComponent( index ) {
  1995. switch ( index ) {
  1996. case 0: return this.x;
  1997. case 1: return this.y;
  1998. case 2: return this.z;
  1999. default: throw new Error( 'index is out of range: ' + index );
  2000. }
  2001. }
  2002. clone() {
  2003. return new this.constructor( this.x, this.y, this.z );
  2004. }
  2005. copy( v ) {
  2006. this.x = v.x;
  2007. this.y = v.y;
  2008. this.z = v.z;
  2009. return this;
  2010. }
  2011. add( v, w ) {
  2012. if ( w !== undefined ) {
  2013. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2014. return this.addVectors( v, w );
  2015. }
  2016. this.x += v.x;
  2017. this.y += v.y;
  2018. this.z += v.z;
  2019. return this;
  2020. }
  2021. addScalar( s ) {
  2022. this.x += s;
  2023. this.y += s;
  2024. this.z += s;
  2025. return this;
  2026. }
  2027. addVectors( a, b ) {
  2028. this.x = a.x + b.x;
  2029. this.y = a.y + b.y;
  2030. this.z = a.z + b.z;
  2031. return this;
  2032. }
  2033. addScaledVector( v, s ) {
  2034. this.x += v.x * s;
  2035. this.y += v.y * s;
  2036. this.z += v.z * s;
  2037. return this;
  2038. }
  2039. sub( v, w ) {
  2040. if ( w !== undefined ) {
  2041. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2042. return this.subVectors( v, w );
  2043. }
  2044. this.x -= v.x;
  2045. this.y -= v.y;
  2046. this.z -= v.z;
  2047. return this;
  2048. }
  2049. subScalar( s ) {
  2050. this.x -= s;
  2051. this.y -= s;
  2052. this.z -= s;
  2053. return this;
  2054. }
  2055. subVectors( a, b ) {
  2056. this.x = a.x - b.x;
  2057. this.y = a.y - b.y;
  2058. this.z = a.z - b.z;
  2059. return this;
  2060. }
  2061. multiply( v, w ) {
  2062. if ( w !== undefined ) {
  2063. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2064. return this.multiplyVectors( v, w );
  2065. }
  2066. this.x *= v.x;
  2067. this.y *= v.y;
  2068. this.z *= v.z;
  2069. return this;
  2070. }
  2071. multiplyScalar( scalar ) {
  2072. this.x *= scalar;
  2073. this.y *= scalar;
  2074. this.z *= scalar;
  2075. return this;
  2076. }
  2077. multiplyVectors( a, b ) {
  2078. this.x = a.x * b.x;
  2079. this.y = a.y * b.y;
  2080. this.z = a.z * b.z;
  2081. return this;
  2082. }
  2083. applyEuler( euler ) {
  2084. if ( ! ( euler && euler.isEuler ) ) {
  2085. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2086. }
  2087. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2088. }
  2089. applyAxisAngle( axis, angle ) {
  2090. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2091. }
  2092. applyMatrix3( m ) {
  2093. const x = this.x, y = this.y, z = this.z;
  2094. const e = m.elements;
  2095. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2096. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2097. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2098. return this;
  2099. }
  2100. applyNormalMatrix( m ) {
  2101. return this.applyMatrix3( m ).normalize();
  2102. }
  2103. applyMatrix4( m ) {
  2104. const x = this.x, y = this.y, z = this.z;
  2105. const e = m.elements;
  2106. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2107. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2108. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2109. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2110. return this;
  2111. }
  2112. applyQuaternion( q ) {
  2113. const x = this.x, y = this.y, z = this.z;
  2114. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2115. // calculate quat * vector
  2116. const ix = qw * x + qy * z - qz * y;
  2117. const iy = qw * y + qz * x - qx * z;
  2118. const iz = qw * z + qx * y - qy * x;
  2119. const iw = - qx * x - qy * y - qz * z;
  2120. // calculate result * inverse quat
  2121. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2122. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2123. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2124. return this;
  2125. }
  2126. project( camera ) {
  2127. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2128. }
  2129. unproject( camera ) {
  2130. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2131. }
  2132. transformDirection( m ) {
  2133. // input: THREE.Matrix4 affine matrix
  2134. // vector interpreted as a direction
  2135. const x = this.x, y = this.y, z = this.z;
  2136. const e = m.elements;
  2137. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2138. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2139. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2140. return this.normalize();
  2141. }
  2142. divide( v ) {
  2143. this.x /= v.x;
  2144. this.y /= v.y;
  2145. this.z /= v.z;
  2146. return this;
  2147. }
  2148. divideScalar( scalar ) {
  2149. return this.multiplyScalar( 1 / scalar );
  2150. }
  2151. min( v ) {
  2152. this.x = Math.min( this.x, v.x );
  2153. this.y = Math.min( this.y, v.y );
  2154. this.z = Math.min( this.z, v.z );
  2155. return this;
  2156. }
  2157. max( v ) {
  2158. this.x = Math.max( this.x, v.x );
  2159. this.y = Math.max( this.y, v.y );
  2160. this.z = Math.max( this.z, v.z );
  2161. return this;
  2162. }
  2163. clamp( min, max ) {
  2164. // assumes min < max, componentwise
  2165. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2166. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2167. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2168. return this;
  2169. }
  2170. clampScalar( minVal, maxVal ) {
  2171. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2172. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2173. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2174. return this;
  2175. }
  2176. clampLength( min, max ) {
  2177. const length = this.length();
  2178. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2179. }
  2180. floor() {
  2181. this.x = Math.floor( this.x );
  2182. this.y = Math.floor( this.y );
  2183. this.z = Math.floor( this.z );
  2184. return this;
  2185. }
  2186. ceil() {
  2187. this.x = Math.ceil( this.x );
  2188. this.y = Math.ceil( this.y );
  2189. this.z = Math.ceil( this.z );
  2190. return this;
  2191. }
  2192. round() {
  2193. this.x = Math.round( this.x );
  2194. this.y = Math.round( this.y );
  2195. this.z = Math.round( this.z );
  2196. return this;
  2197. }
  2198. roundToZero() {
  2199. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2200. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2201. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2202. return this;
  2203. }
  2204. negate() {
  2205. this.x = - this.x;
  2206. this.y = - this.y;
  2207. this.z = - this.z;
  2208. return this;
  2209. }
  2210. dot( v ) {
  2211. return this.x * v.x + this.y * v.y + this.z * v.z;
  2212. }
  2213. // TODO lengthSquared?
  2214. lengthSq() {
  2215. return this.x * this.x + this.y * this.y + this.z * this.z;
  2216. }
  2217. length() {
  2218. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2219. }
  2220. manhattanLength() {
  2221. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2222. }
  2223. normalize() {
  2224. return this.divideScalar( this.length() || 1 );
  2225. }
  2226. setLength( length ) {
  2227. return this.normalize().multiplyScalar( length );
  2228. }
  2229. lerp( v, alpha ) {
  2230. this.x += ( v.x - this.x ) * alpha;
  2231. this.y += ( v.y - this.y ) * alpha;
  2232. this.z += ( v.z - this.z ) * alpha;
  2233. return this;
  2234. }
  2235. lerpVectors( v1, v2, alpha ) {
  2236. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2237. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2238. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2239. return this;
  2240. }
  2241. cross( v, w ) {
  2242. if ( w !== undefined ) {
  2243. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2244. return this.crossVectors( v, w );
  2245. }
  2246. return this.crossVectors( this, v );
  2247. }
  2248. crossVectors( a, b ) {
  2249. const ax = a.x, ay = a.y, az = a.z;
  2250. const bx = b.x, by = b.y, bz = b.z;
  2251. this.x = ay * bz - az * by;
  2252. this.y = az * bx - ax * bz;
  2253. this.z = ax * by - ay * bx;
  2254. return this;
  2255. }
  2256. projectOnVector( v ) {
  2257. const denominator = v.lengthSq();
  2258. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2259. const scalar = v.dot( this ) / denominator;
  2260. return this.copy( v ).multiplyScalar( scalar );
  2261. }
  2262. projectOnPlane( planeNormal ) {
  2263. _vector.copy( this ).projectOnVector( planeNormal );
  2264. return this.sub( _vector );
  2265. }
  2266. reflect( normal ) {
  2267. // reflect incident vector off plane orthogonal to normal
  2268. // normal is assumed to have unit length
  2269. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2270. }
  2271. angleTo( v ) {
  2272. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2273. if ( denominator === 0 ) return Math.PI / 2;
  2274. const theta = this.dot( v ) / denominator;
  2275. // clamp, to handle numerical problems
  2276. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2277. }
  2278. distanceTo( v ) {
  2279. return Math.sqrt( this.distanceToSquared( v ) );
  2280. }
  2281. distanceToSquared( v ) {
  2282. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2283. return dx * dx + dy * dy + dz * dz;
  2284. }
  2285. manhattanDistanceTo( v ) {
  2286. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2287. }
  2288. setFromSpherical( s ) {
  2289. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2290. }
  2291. setFromSphericalCoords( radius, phi, theta ) {
  2292. const sinPhiRadius = Math.sin( phi ) * radius;
  2293. this.x = sinPhiRadius * Math.sin( theta );
  2294. this.y = Math.cos( phi ) * radius;
  2295. this.z = sinPhiRadius * Math.cos( theta );
  2296. return this;
  2297. }
  2298. setFromCylindrical( c ) {
  2299. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2300. }
  2301. setFromCylindricalCoords( radius, theta, y ) {
  2302. this.x = radius * Math.sin( theta );
  2303. this.y = y;
  2304. this.z = radius * Math.cos( theta );
  2305. return this;
  2306. }
  2307. setFromMatrixPosition( m ) {
  2308. const e = m.elements;
  2309. this.x = e[ 12 ];
  2310. this.y = e[ 13 ];
  2311. this.z = e[ 14 ];
  2312. return this;
  2313. }
  2314. setFromMatrixScale( m ) {
  2315. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2316. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2317. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2318. this.x = sx;
  2319. this.y = sy;
  2320. this.z = sz;
  2321. return this;
  2322. }
  2323. setFromMatrixColumn( m, index ) {
  2324. return this.fromArray( m.elements, index * 4 );
  2325. }
  2326. setFromMatrix3Column( m, index ) {
  2327. return this.fromArray( m.elements, index * 3 );
  2328. }
  2329. equals( v ) {
  2330. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2331. }
  2332. fromArray( array, offset = 0 ) {
  2333. this.x = array[ offset ];
  2334. this.y = array[ offset + 1 ];
  2335. this.z = array[ offset + 2 ];
  2336. return this;
  2337. }
  2338. toArray( array = [], offset = 0 ) {
  2339. array[ offset ] = this.x;
  2340. array[ offset + 1 ] = this.y;
  2341. array[ offset + 2 ] = this.z;
  2342. return array;
  2343. }
  2344. fromBufferAttribute( attribute, index, offset ) {
  2345. if ( offset !== undefined ) {
  2346. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2347. }
  2348. this.x = attribute.getX( index );
  2349. this.y = attribute.getY( index );
  2350. this.z = attribute.getZ( index );
  2351. return this;
  2352. }
  2353. random() {
  2354. this.x = Math.random();
  2355. this.y = Math.random();
  2356. this.z = Math.random();
  2357. return this;
  2358. }
  2359. }
  2360. Vector3.prototype.isVector3 = true;
  2361. const _vector = /*@__PURE__*/ new Vector3();
  2362. const _quaternion = /*@__PURE__*/ new Quaternion();
  2363. class Box3 {
  2364. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2365. this.min = min;
  2366. this.max = max;
  2367. }
  2368. set( min, max ) {
  2369. this.min.copy( min );
  2370. this.max.copy( max );
  2371. return this;
  2372. }
  2373. setFromArray( array ) {
  2374. let minX = + Infinity;
  2375. let minY = + Infinity;
  2376. let minZ = + Infinity;
  2377. let maxX = - Infinity;
  2378. let maxY = - Infinity;
  2379. let maxZ = - Infinity;
  2380. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  2381. const x = array[ i ];
  2382. const y = array[ i + 1 ];
  2383. const z = array[ i + 2 ];
  2384. if ( x < minX ) minX = x;
  2385. if ( y < minY ) minY = y;
  2386. if ( z < minZ ) minZ = z;
  2387. if ( x > maxX ) maxX = x;
  2388. if ( y > maxY ) maxY = y;
  2389. if ( z > maxZ ) maxZ = z;
  2390. }
  2391. this.min.set( minX, minY, minZ );
  2392. this.max.set( maxX, maxY, maxZ );
  2393. return this;
  2394. }
  2395. setFromBufferAttribute( attribute ) {
  2396. let minX = + Infinity;
  2397. let minY = + Infinity;
  2398. let minZ = + Infinity;
  2399. let maxX = - Infinity;
  2400. let maxY = - Infinity;
  2401. let maxZ = - Infinity;
  2402. for ( let i = 0, l = attribute.count; i < l; i ++ ) {
  2403. const x = attribute.getX( i );
  2404. const y = attribute.getY( i );
  2405. const z = attribute.getZ( i );
  2406. if ( x < minX ) minX = x;
  2407. if ( y < minY ) minY = y;
  2408. if ( z < minZ ) minZ = z;
  2409. if ( x > maxX ) maxX = x;
  2410. if ( y > maxY ) maxY = y;
  2411. if ( z > maxZ ) maxZ = z;
  2412. }
  2413. this.min.set( minX, minY, minZ );
  2414. this.max.set( maxX, maxY, maxZ );
  2415. return this;
  2416. }
  2417. setFromPoints( points ) {
  2418. this.makeEmpty();
  2419. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2420. this.expandByPoint( points[ i ] );
  2421. }
  2422. return this;
  2423. }
  2424. setFromCenterAndSize( center, size ) {
  2425. const halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  2426. this.min.copy( center ).sub( halfSize );
  2427. this.max.copy( center ).add( halfSize );
  2428. return this;
  2429. }
  2430. setFromObject( object ) {
  2431. this.makeEmpty();
  2432. return this.expandByObject( object );
  2433. }
  2434. clone() {
  2435. return new this.constructor().copy( this );
  2436. }
  2437. copy( box ) {
  2438. this.min.copy( box.min );
  2439. this.max.copy( box.max );
  2440. return this;
  2441. }
  2442. makeEmpty() {
  2443. this.min.x = this.min.y = this.min.z = + Infinity;
  2444. this.max.x = this.max.y = this.max.z = - Infinity;
  2445. return this;
  2446. }
  2447. isEmpty() {
  2448. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2449. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2450. }
  2451. getCenter( target ) {
  2452. if ( target === undefined ) {
  2453. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2454. target = new Vector3();
  2455. }
  2456. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2457. }
  2458. getSize( target ) {
  2459. if ( target === undefined ) {
  2460. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2461. target = new Vector3();
  2462. }
  2463. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2464. }
  2465. expandByPoint( point ) {
  2466. this.min.min( point );
  2467. this.max.max( point );
  2468. return this;
  2469. }
  2470. expandByVector( vector ) {
  2471. this.min.sub( vector );
  2472. this.max.add( vector );
  2473. return this;
  2474. }
  2475. expandByScalar( scalar ) {
  2476. this.min.addScalar( - scalar );
  2477. this.max.addScalar( scalar );
  2478. return this;
  2479. }
  2480. expandByObject( object ) {
  2481. // Computes the world-axis-aligned bounding box of an object (including its children),
  2482. // accounting for both the object's, and children's, world transforms
  2483. object.updateWorldMatrix( false, false );
  2484. const geometry = object.geometry;
  2485. if ( geometry !== undefined ) {
  2486. if ( geometry.boundingBox === null ) {
  2487. geometry.computeBoundingBox();
  2488. }
  2489. _box.copy( geometry.boundingBox );
  2490. _box.applyMatrix4( object.matrixWorld );
  2491. this.union( _box );
  2492. }
  2493. const children = object.children;
  2494. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2495. this.expandByObject( children[ i ] );
  2496. }
  2497. return this;
  2498. }
  2499. containsPoint( point ) {
  2500. return point.x < this.min.x || point.x > this.max.x ||
  2501. point.y < this.min.y || point.y > this.max.y ||
  2502. point.z < this.min.z || point.z > this.max.z ? false : true;
  2503. }
  2504. containsBox( box ) {
  2505. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2506. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2507. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2508. }
  2509. getParameter( point, target ) {
  2510. // This can potentially have a divide by zero if the box
  2511. // has a size dimension of 0.
  2512. if ( target === undefined ) {
  2513. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2514. target = new Vector3();
  2515. }
  2516. return target.set(
  2517. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2518. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2519. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2520. );
  2521. }
  2522. intersectsBox( box ) {
  2523. // using 6 splitting planes to rule out intersections.
  2524. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2525. box.max.y < this.min.y || box.min.y > this.max.y ||
  2526. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2527. }
  2528. intersectsSphere( sphere ) {
  2529. // Find the point on the AABB closest to the sphere center.
  2530. this.clampPoint( sphere.center, _vector$1 );
  2531. // If that point is inside the sphere, the AABB and sphere intersect.
  2532. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2533. }
  2534. intersectsPlane( plane ) {
  2535. // We compute the minimum and maximum dot product values. If those values
  2536. // are on the same side (back or front) of the plane, then there is no intersection.
  2537. let min, max;
  2538. if ( plane.normal.x > 0 ) {
  2539. min = plane.normal.x * this.min.x;
  2540. max = plane.normal.x * this.max.x;
  2541. } else {
  2542. min = plane.normal.x * this.max.x;
  2543. max = plane.normal.x * this.min.x;
  2544. }
  2545. if ( plane.normal.y > 0 ) {
  2546. min += plane.normal.y * this.min.y;
  2547. max += plane.normal.y * this.max.y;
  2548. } else {
  2549. min += plane.normal.y * this.max.y;
  2550. max += plane.normal.y * this.min.y;
  2551. }
  2552. if ( plane.normal.z > 0 ) {
  2553. min += plane.normal.z * this.min.z;
  2554. max += plane.normal.z * this.max.z;
  2555. } else {
  2556. min += plane.normal.z * this.max.z;
  2557. max += plane.normal.z * this.min.z;
  2558. }
  2559. return ( min <= - plane.constant && max >= - plane.constant );
  2560. }
  2561. intersectsTriangle( triangle ) {
  2562. if ( this.isEmpty() ) {
  2563. return false;
  2564. }
  2565. // compute box center and extents
  2566. this.getCenter( _center );
  2567. _extents.subVectors( this.max, _center );
  2568. // translate triangle to aabb origin
  2569. _v0.subVectors( triangle.a, _center );
  2570. _v1.subVectors( triangle.b, _center );
  2571. _v2.subVectors( triangle.c, _center );
  2572. // compute edge vectors for triangle
  2573. _f0.subVectors( _v1, _v0 );
  2574. _f1.subVectors( _v2, _v1 );
  2575. _f2.subVectors( _v0, _v2 );
  2576. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2577. // 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
  2578. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2579. let axes = [
  2580. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  2581. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  2582. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  2583. ];
  2584. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2585. return false;
  2586. }
  2587. // test 3 face normals from the aabb
  2588. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2589. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2590. return false;
  2591. }
  2592. // finally testing the face normal of the triangle
  2593. // use already existing triangle edge vectors here
  2594. _triangleNormal.crossVectors( _f0, _f1 );
  2595. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  2596. return satForAxes( axes, _v0, _v1, _v2, _extents );
  2597. }
  2598. clampPoint( point, target ) {
  2599. if ( target === undefined ) {
  2600. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2601. target = new Vector3();
  2602. }
  2603. return target.copy( point ).clamp( this.min, this.max );
  2604. }
  2605. distanceToPoint( point ) {
  2606. const clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  2607. return clampedPoint.sub( point ).length();
  2608. }
  2609. getBoundingSphere( target ) {
  2610. if ( target === undefined ) {
  2611. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2612. //target = new Sphere(); // removed to avoid cyclic dependency
  2613. }
  2614. this.getCenter( target.center );
  2615. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  2616. return target;
  2617. }
  2618. intersect( box ) {
  2619. this.min.max( box.min );
  2620. this.max.min( box.max );
  2621. // 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.
  2622. if ( this.isEmpty() ) this.makeEmpty();
  2623. return this;
  2624. }
  2625. union( box ) {
  2626. this.min.min( box.min );
  2627. this.max.max( box.max );
  2628. return this;
  2629. }
  2630. applyMatrix4( matrix ) {
  2631. // transform of empty box is an empty box.
  2632. if ( this.isEmpty() ) return this;
  2633. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2634. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2635. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2636. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2637. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2638. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2639. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2640. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2641. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2642. this.setFromPoints( _points );
  2643. return this;
  2644. }
  2645. translate( offset ) {
  2646. this.min.add( offset );
  2647. this.max.add( offset );
  2648. return this;
  2649. }
  2650. equals( box ) {
  2651. return box.min.equals( this.min ) && box.max.equals( this.max );
  2652. }
  2653. }
  2654. Box3.prototype.isBox3 = true;
  2655. const _points = [
  2656. /*@__PURE__*/ new Vector3(),
  2657. /*@__PURE__*/ new Vector3(),
  2658. /*@__PURE__*/ new Vector3(),
  2659. /*@__PURE__*/ new Vector3(),
  2660. /*@__PURE__*/ new Vector3(),
  2661. /*@__PURE__*/ new Vector3(),
  2662. /*@__PURE__*/ new Vector3(),
  2663. /*@__PURE__*/ new Vector3()
  2664. ];
  2665. const _vector$1 = /*@__PURE__*/ new Vector3();
  2666. const _box = /*@__PURE__*/ new Box3();
  2667. // triangle centered vertices
  2668. const _v0 = /*@__PURE__*/ new Vector3();
  2669. const _v1 = /*@__PURE__*/ new Vector3();
  2670. const _v2 = /*@__PURE__*/ new Vector3();
  2671. // triangle edge vectors
  2672. const _f0 = /*@__PURE__*/ new Vector3();
  2673. const _f1 = /*@__PURE__*/ new Vector3();
  2674. const _f2 = /*@__PURE__*/ new Vector3();
  2675. const _center = /*@__PURE__*/ new Vector3();
  2676. const _extents = /*@__PURE__*/ new Vector3();
  2677. const _triangleNormal = /*@__PURE__*/ new Vector3();
  2678. const _testAxis = /*@__PURE__*/ new Vector3();
  2679. function satForAxes( axes, v0, v1, v2, extents ) {
  2680. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2681. _testAxis.fromArray( axes, i );
  2682. // project the aabb onto the seperating axis
  2683. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  2684. // project all 3 vertices of the triangle onto the seperating axis
  2685. const p0 = v0.dot( _testAxis );
  2686. const p1 = v1.dot( _testAxis );
  2687. const p2 = v2.dot( _testAxis );
  2688. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2689. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2690. // points of the projected triangle are outside the projected half-length of the aabb
  2691. // the axis is seperating and we can exit
  2692. return false;
  2693. }
  2694. }
  2695. return true;
  2696. }
  2697. const _box$1 = /*@__PURE__*/ new Box3();
  2698. class Sphere {
  2699. constructor( center = new Vector3(), radius = - 1 ) {
  2700. this.center = center;
  2701. this.radius = radius;
  2702. }
  2703. set( center, radius ) {
  2704. this.center.copy( center );
  2705. this.radius = radius;
  2706. return this;
  2707. }
  2708. setFromPoints( points, optionalCenter ) {
  2709. const center = this.center;
  2710. if ( optionalCenter !== undefined ) {
  2711. center.copy( optionalCenter );
  2712. } else {
  2713. _box$1.setFromPoints( points ).getCenter( center );
  2714. }
  2715. let maxRadiusSq = 0;
  2716. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2717. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2718. }
  2719. this.radius = Math.sqrt( maxRadiusSq );
  2720. return this;
  2721. }
  2722. copy( sphere ) {
  2723. this.center.copy( sphere.center );
  2724. this.radius = sphere.radius;
  2725. return this;
  2726. }
  2727. isEmpty() {
  2728. return ( this.radius < 0 );
  2729. }
  2730. makeEmpty() {
  2731. this.center.set( 0, 0, 0 );
  2732. this.radius = - 1;
  2733. return this;
  2734. }
  2735. containsPoint( point ) {
  2736. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2737. }
  2738. distanceToPoint( point ) {
  2739. return ( point.distanceTo( this.center ) - this.radius );
  2740. }
  2741. intersectsSphere( sphere ) {
  2742. const radiusSum = this.radius + sphere.radius;
  2743. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2744. }
  2745. intersectsBox( box ) {
  2746. return box.intersectsSphere( this );
  2747. }
  2748. intersectsPlane( plane ) {
  2749. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2750. }
  2751. clampPoint( point, target ) {
  2752. const deltaLengthSq = this.center.distanceToSquared( point );
  2753. if ( target === undefined ) {
  2754. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2755. target = new Vector3();
  2756. }
  2757. target.copy( point );
  2758. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2759. target.sub( this.center ).normalize();
  2760. target.multiplyScalar( this.radius ).add( this.center );
  2761. }
  2762. return target;
  2763. }
  2764. getBoundingBox( target ) {
  2765. if ( target === undefined ) {
  2766. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2767. target = new Box3();
  2768. }
  2769. if ( this.isEmpty() ) {
  2770. // Empty sphere produces empty bounding box
  2771. target.makeEmpty();
  2772. return target;
  2773. }
  2774. target.set( this.center, this.center );
  2775. target.expandByScalar( this.radius );
  2776. return target;
  2777. }
  2778. applyMatrix4( matrix ) {
  2779. this.center.applyMatrix4( matrix );
  2780. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2781. return this;
  2782. }
  2783. translate( offset ) {
  2784. this.center.add( offset );
  2785. return this;
  2786. }
  2787. equals( sphere ) {
  2788. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2789. }
  2790. clone() {
  2791. return new this.constructor().copy( this );
  2792. }
  2793. }
  2794. const _vector$2 = /*@__PURE__*/ new Vector3();
  2795. const _segCenter = /*@__PURE__*/ new Vector3();
  2796. const _segDir = /*@__PURE__*/ new Vector3();
  2797. const _diff = /*@__PURE__*/ new Vector3();
  2798. const _edge1 = /*@__PURE__*/ new Vector3();
  2799. const _edge2 = /*@__PURE__*/ new Vector3();
  2800. const _normal = /*@__PURE__*/ new Vector3();
  2801. class Ray {
  2802. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
  2803. this.origin = origin;
  2804. this.direction = direction;
  2805. }
  2806. set( origin, direction ) {
  2807. this.origin.copy( origin );
  2808. this.direction.copy( direction );
  2809. return this;
  2810. }
  2811. copy( ray ) {
  2812. this.origin.copy( ray.origin );
  2813. this.direction.copy( ray.direction );
  2814. return this;
  2815. }
  2816. at( t, target ) {
  2817. if ( target === undefined ) {
  2818. console.warn( 'THREE.Ray: .at() target is now required' );
  2819. target = new Vector3();
  2820. }
  2821. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  2822. }
  2823. lookAt( v ) {
  2824. this.direction.copy( v ).sub( this.origin ).normalize();
  2825. return this;
  2826. }
  2827. recast( t ) {
  2828. this.origin.copy( this.at( t, _vector$2 ) );
  2829. return this;
  2830. }
  2831. closestPointToPoint( point, target ) {
  2832. if ( target === undefined ) {
  2833. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  2834. target = new Vector3();
  2835. }
  2836. target.subVectors( point, this.origin );
  2837. const directionDistance = target.dot( this.direction );
  2838. if ( directionDistance < 0 ) {
  2839. return target.copy( this.origin );
  2840. }
  2841. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2842. }
  2843. distanceToPoint( point ) {
  2844. return Math.sqrt( this.distanceSqToPoint( point ) );
  2845. }
  2846. distanceSqToPoint( point ) {
  2847. const directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  2848. // point behind the ray
  2849. if ( directionDistance < 0 ) {
  2850. return this.origin.distanceToSquared( point );
  2851. }
  2852. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2853. return _vector$2.distanceToSquared( point );
  2854. }
  2855. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  2856. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  2857. // It returns the min distance between the ray and the segment
  2858. // defined by v0 and v1
  2859. // It can also set two optional targets :
  2860. // - The closest point on the ray
  2861. // - The closest point on the segment
  2862. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  2863. _segDir.copy( v1 ).sub( v0 ).normalize();
  2864. _diff.copy( this.origin ).sub( _segCenter );
  2865. const segExtent = v0.distanceTo( v1 ) * 0.5;
  2866. const a01 = - this.direction.dot( _segDir );
  2867. const b0 = _diff.dot( this.direction );
  2868. const b1 = - _diff.dot( _segDir );
  2869. const c = _diff.lengthSq();
  2870. const det = Math.abs( 1 - a01 * a01 );
  2871. let s0, s1, sqrDist, extDet;
  2872. if ( det > 0 ) {
  2873. // The ray and segment are not parallel.
  2874. s0 = a01 * b1 - b0;
  2875. s1 = a01 * b0 - b1;
  2876. extDet = segExtent * det;
  2877. if ( s0 >= 0 ) {
  2878. if ( s1 >= - extDet ) {
  2879. if ( s1 <= extDet ) {
  2880. // region 0
  2881. // Minimum at interior points of ray and segment.
  2882. const invDet = 1 / det;
  2883. s0 *= invDet;
  2884. s1 *= invDet;
  2885. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  2886. } else {
  2887. // region 1
  2888. s1 = segExtent;
  2889. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2890. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2891. }
  2892. } else {
  2893. // region 5
  2894. s1 = - segExtent;
  2895. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2896. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2897. }
  2898. } else {
  2899. if ( s1 <= - extDet ) {
  2900. // region 4
  2901. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  2902. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2903. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2904. } else if ( s1 <= extDet ) {
  2905. // region 3
  2906. s0 = 0;
  2907. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2908. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  2909. } else {
  2910. // region 2
  2911. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  2912. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2913. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2914. }
  2915. }
  2916. } else {
  2917. // Ray and segment are parallel.
  2918. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  2919. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2920. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2921. }
  2922. if ( optionalPointOnRay ) {
  2923. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  2924. }
  2925. if ( optionalPointOnSegment ) {
  2926. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  2927. }
  2928. return sqrDist;
  2929. }
  2930. intersectSphere( sphere, target ) {
  2931. _vector$2.subVectors( sphere.center, this.origin );
  2932. const tca = _vector$2.dot( this.direction );
  2933. const d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  2934. const radius2 = sphere.radius * sphere.radius;
  2935. if ( d2 > radius2 ) return null;
  2936. const thc = Math.sqrt( radius2 - d2 );
  2937. // t0 = first intersect point - entrance on front of sphere
  2938. const t0 = tca - thc;
  2939. // t1 = second intersect point - exit point on back of sphere
  2940. const t1 = tca + thc;
  2941. // test to see if both t0 and t1 are behind the ray - if so, return null
  2942. if ( t0 < 0 && t1 < 0 ) return null;
  2943. // test to see if t0 is behind the ray:
  2944. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  2945. // in order to always return an intersect point that is in front of the ray.
  2946. if ( t0 < 0 ) return this.at( t1, target );
  2947. // else t0 is in front of the ray, so return the first collision point scaled by t0
  2948. return this.at( t0, target );
  2949. }
  2950. intersectsSphere( sphere ) {
  2951. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  2952. }
  2953. distanceToPlane( plane ) {
  2954. const denominator = plane.normal.dot( this.direction );
  2955. if ( denominator === 0 ) {
  2956. // line is coplanar, return origin
  2957. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  2958. return 0;
  2959. }
  2960. // Null is preferable to undefined since undefined means.... it is undefined
  2961. return null;
  2962. }
  2963. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  2964. // Return if the ray never intersects the plane
  2965. return t >= 0 ? t : null;
  2966. }
  2967. intersectPlane( plane, target ) {
  2968. const t = this.distanceToPlane( plane );
  2969. if ( t === null ) {
  2970. return null;
  2971. }
  2972. return this.at( t, target );
  2973. }
  2974. intersectsPlane( plane ) {
  2975. // check if the ray lies on the plane first
  2976. const distToPoint = plane.distanceToPoint( this.origin );
  2977. if ( distToPoint === 0 ) {
  2978. return true;
  2979. }
  2980. const denominator = plane.normal.dot( this.direction );
  2981. if ( denominator * distToPoint < 0 ) {
  2982. return true;
  2983. }
  2984. // ray origin is behind the plane (and is pointing behind it)
  2985. return false;
  2986. }
  2987. intersectBox( box, target ) {
  2988. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  2989. const invdirx = 1 / this.direction.x,
  2990. invdiry = 1 / this.direction.y,
  2991. invdirz = 1 / this.direction.z;
  2992. const origin = this.origin;
  2993. if ( invdirx >= 0 ) {
  2994. tmin = ( box.min.x - origin.x ) * invdirx;
  2995. tmax = ( box.max.x - origin.x ) * invdirx;
  2996. } else {
  2997. tmin = ( box.max.x - origin.x ) * invdirx;
  2998. tmax = ( box.min.x - origin.x ) * invdirx;
  2999. }
  3000. if ( invdiry >= 0 ) {
  3001. tymin = ( box.min.y - origin.y ) * invdiry;
  3002. tymax = ( box.max.y - origin.y ) * invdiry;
  3003. } else {
  3004. tymin = ( box.max.y - origin.y ) * invdiry;
  3005. tymax = ( box.min.y - origin.y ) * invdiry;
  3006. }
  3007. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3008. // These lines also handle the case where tmin or tmax is NaN
  3009. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3010. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3011. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3012. if ( invdirz >= 0 ) {
  3013. tzmin = ( box.min.z - origin.z ) * invdirz;
  3014. tzmax = ( box.max.z - origin.z ) * invdirz;
  3015. } else {
  3016. tzmin = ( box.max.z - origin.z ) * invdirz;
  3017. tzmax = ( box.min.z - origin.z ) * invdirz;
  3018. }
  3019. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3020. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3021. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3022. //return point closest to the ray (positive side)
  3023. if ( tmax < 0 ) return null;
  3024. return this.at( tmin >= 0 ? tmin : tmax, target );
  3025. }
  3026. intersectsBox( box ) {
  3027. return this.intersectBox( box, _vector$2 ) !== null;
  3028. }
  3029. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3030. // Compute the offset origin, edges, and normal.
  3031. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3032. _edge1.subVectors( b, a );
  3033. _edge2.subVectors( c, a );
  3034. _normal.crossVectors( _edge1, _edge2 );
  3035. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3036. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3037. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3038. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3039. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3040. let DdN = this.direction.dot( _normal );
  3041. let sign;
  3042. if ( DdN > 0 ) {
  3043. if ( backfaceCulling ) return null;
  3044. sign = 1;
  3045. } else if ( DdN < 0 ) {
  3046. sign = - 1;
  3047. DdN = - DdN;
  3048. } else {
  3049. return null;
  3050. }
  3051. _diff.subVectors( this.origin, a );
  3052. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3053. // b1 < 0, no intersection
  3054. if ( DdQxE2 < 0 ) {
  3055. return null;
  3056. }
  3057. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3058. // b2 < 0, no intersection
  3059. if ( DdE1xQ < 0 ) {
  3060. return null;
  3061. }
  3062. // b1+b2 > 1, no intersection
  3063. if ( DdQxE2 + DdE1xQ > DdN ) {
  3064. return null;
  3065. }
  3066. // Line intersects triangle, check if ray does.
  3067. const QdN = - sign * _diff.dot( _normal );
  3068. // t < 0, no intersection
  3069. if ( QdN < 0 ) {
  3070. return null;
  3071. }
  3072. // Ray intersects triangle.
  3073. return this.at( QdN / DdN, target );
  3074. }
  3075. applyMatrix4( matrix4 ) {
  3076. this.origin.applyMatrix4( matrix4 );
  3077. this.direction.transformDirection( matrix4 );
  3078. return this;
  3079. }
  3080. equals( ray ) {
  3081. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3082. }
  3083. clone() {
  3084. return new this.constructor().copy( this );
  3085. }
  3086. }
  3087. class Matrix4 {
  3088. constructor() {
  3089. this.elements = [
  3090. 1, 0, 0, 0,
  3091. 0, 1, 0, 0,
  3092. 0, 0, 1, 0,
  3093. 0, 0, 0, 1
  3094. ];
  3095. if ( arguments.length > 0 ) {
  3096. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3097. }
  3098. }
  3099. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3100. const te = this.elements;
  3101. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3102. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3103. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3104. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3105. return this;
  3106. }
  3107. identity() {
  3108. this.set(
  3109. 1, 0, 0, 0,
  3110. 0, 1, 0, 0,
  3111. 0, 0, 1, 0,
  3112. 0, 0, 0, 1
  3113. );
  3114. return this;
  3115. }
  3116. clone() {
  3117. return new Matrix4().fromArray( this.elements );
  3118. }
  3119. copy( m ) {
  3120. const te = this.elements;
  3121. const me = m.elements;
  3122. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3123. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3124. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3125. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3126. return this;
  3127. }
  3128. copyPosition( m ) {
  3129. const te = this.elements, me = m.elements;
  3130. te[ 12 ] = me[ 12 ];
  3131. te[ 13 ] = me[ 13 ];
  3132. te[ 14 ] = me[ 14 ];
  3133. return this;
  3134. }
  3135. setFromMatrix3( m ) {
  3136. const me = m.elements;
  3137. this.set(
  3138. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3139. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3140. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3141. 0, 0, 0, 1
  3142. );
  3143. return this;
  3144. }
  3145. extractBasis( xAxis, yAxis, zAxis ) {
  3146. xAxis.setFromMatrixColumn( this, 0 );
  3147. yAxis.setFromMatrixColumn( this, 1 );
  3148. zAxis.setFromMatrixColumn( this, 2 );
  3149. return this;
  3150. }
  3151. makeBasis( xAxis, yAxis, zAxis ) {
  3152. this.set(
  3153. xAxis.x, yAxis.x, zAxis.x, 0,
  3154. xAxis.y, yAxis.y, zAxis.y, 0,
  3155. xAxis.z, yAxis.z, zAxis.z, 0,
  3156. 0, 0, 0, 1
  3157. );
  3158. return this;
  3159. }
  3160. extractRotation( m ) {
  3161. // this method does not support reflection matrices
  3162. const te = this.elements;
  3163. const me = m.elements;
  3164. const scaleX = 1 / _v1$1.setFromMatrixColumn( m, 0 ).length();
  3165. const scaleY = 1 / _v1$1.setFromMatrixColumn( m, 1 ).length();
  3166. const scaleZ = 1 / _v1$1.setFromMatrixColumn( m, 2 ).length();
  3167. te[ 0 ] = me[ 0 ] * scaleX;
  3168. te[ 1 ] = me[ 1 ] * scaleX;
  3169. te[ 2 ] = me[ 2 ] * scaleX;
  3170. te[ 3 ] = 0;
  3171. te[ 4 ] = me[ 4 ] * scaleY;
  3172. te[ 5 ] = me[ 5 ] * scaleY;
  3173. te[ 6 ] = me[ 6 ] * scaleY;
  3174. te[ 7 ] = 0;
  3175. te[ 8 ] = me[ 8 ] * scaleZ;
  3176. te[ 9 ] = me[ 9 ] * scaleZ;
  3177. te[ 10 ] = me[ 10 ] * scaleZ;
  3178. te[ 11 ] = 0;
  3179. te[ 12 ] = 0;
  3180. te[ 13 ] = 0;
  3181. te[ 14 ] = 0;
  3182. te[ 15 ] = 1;
  3183. return this;
  3184. }
  3185. makeRotationFromEuler( euler ) {
  3186. if ( ! ( euler && euler.isEuler ) ) {
  3187. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3188. }
  3189. const te = this.elements;
  3190. const x = euler.x, y = euler.y, z = euler.z;
  3191. const a = Math.cos( x ), b = Math.sin( x );
  3192. const c = Math.cos( y ), d = Math.sin( y );
  3193. const e = Math.cos( z ), f = Math.sin( z );
  3194. if ( euler.order === 'XYZ' ) {
  3195. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3196. te[ 0 ] = c * e;
  3197. te[ 4 ] = - c * f;
  3198. te[ 8 ] = d;
  3199. te[ 1 ] = af + be * d;
  3200. te[ 5 ] = ae - bf * d;
  3201. te[ 9 ] = - b * c;
  3202. te[ 2 ] = bf - ae * d;
  3203. te[ 6 ] = be + af * d;
  3204. te[ 10 ] = a * c;
  3205. } else if ( euler.order === 'YXZ' ) {
  3206. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3207. te[ 0 ] = ce + df * b;
  3208. te[ 4 ] = de * b - cf;
  3209. te[ 8 ] = a * d;
  3210. te[ 1 ] = a * f;
  3211. te[ 5 ] = a * e;
  3212. te[ 9 ] = - b;
  3213. te[ 2 ] = cf * b - de;
  3214. te[ 6 ] = df + ce * b;
  3215. te[ 10 ] = a * c;
  3216. } else if ( euler.order === 'ZXY' ) {
  3217. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3218. te[ 0 ] = ce - df * b;
  3219. te[ 4 ] = - a * f;
  3220. te[ 8 ] = de + cf * b;
  3221. te[ 1 ] = cf + de * b;
  3222. te[ 5 ] = a * e;
  3223. te[ 9 ] = df - ce * b;
  3224. te[ 2 ] = - a * d;
  3225. te[ 6 ] = b;
  3226. te[ 10 ] = a * c;
  3227. } else if ( euler.order === 'ZYX' ) {
  3228. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3229. te[ 0 ] = c * e;
  3230. te[ 4 ] = be * d - af;
  3231. te[ 8 ] = ae * d + bf;
  3232. te[ 1 ] = c * f;
  3233. te[ 5 ] = bf * d + ae;
  3234. te[ 9 ] = af * d - be;
  3235. te[ 2 ] = - d;
  3236. te[ 6 ] = b * c;
  3237. te[ 10 ] = a * c;
  3238. } else if ( euler.order === 'YZX' ) {
  3239. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3240. te[ 0 ] = c * e;
  3241. te[ 4 ] = bd - ac * f;
  3242. te[ 8 ] = bc * f + ad;
  3243. te[ 1 ] = f;
  3244. te[ 5 ] = a * e;
  3245. te[ 9 ] = - b * e;
  3246. te[ 2 ] = - d * e;
  3247. te[ 6 ] = ad * f + bc;
  3248. te[ 10 ] = ac - bd * f;
  3249. } else if ( euler.order === 'XZY' ) {
  3250. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3251. te[ 0 ] = c * e;
  3252. te[ 4 ] = - f;
  3253. te[ 8 ] = d * e;
  3254. te[ 1 ] = ac * f + bd;
  3255. te[ 5 ] = a * e;
  3256. te[ 9 ] = ad * f - bc;
  3257. te[ 2 ] = bc * f - ad;
  3258. te[ 6 ] = b * e;
  3259. te[ 10 ] = bd * f + ac;
  3260. }
  3261. // bottom row
  3262. te[ 3 ] = 0;
  3263. te[ 7 ] = 0;
  3264. te[ 11 ] = 0;
  3265. // last column
  3266. te[ 12 ] = 0;
  3267. te[ 13 ] = 0;
  3268. te[ 14 ] = 0;
  3269. te[ 15 ] = 1;
  3270. return this;
  3271. }
  3272. makeRotationFromQuaternion( q ) {
  3273. return this.compose( _zero, q, _one );
  3274. }
  3275. lookAt( eye, target, up ) {
  3276. const te = this.elements;
  3277. _z.subVectors( eye, target );
  3278. if ( _z.lengthSq() === 0 ) {
  3279. // eye and target are in the same position
  3280. _z.z = 1;
  3281. }
  3282. _z.normalize();
  3283. _x.crossVectors( up, _z );
  3284. if ( _x.lengthSq() === 0 ) {
  3285. // up and z are parallel
  3286. if ( Math.abs( up.z ) === 1 ) {
  3287. _z.x += 0.0001;
  3288. } else {
  3289. _z.z += 0.0001;
  3290. }
  3291. _z.normalize();
  3292. _x.crossVectors( up, _z );
  3293. }
  3294. _x.normalize();
  3295. _y.crossVectors( _z, _x );
  3296. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3297. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3298. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3299. return this;
  3300. }
  3301. multiply( m, n ) {
  3302. if ( n !== undefined ) {
  3303. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3304. return this.multiplyMatrices( m, n );
  3305. }
  3306. return this.multiplyMatrices( this, m );
  3307. }
  3308. premultiply( m ) {
  3309. return this.multiplyMatrices( m, this );
  3310. }
  3311. multiplyMatrices( a, b ) {
  3312. const ae = a.elements;
  3313. const be = b.elements;
  3314. const te = this.elements;
  3315. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3316. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3317. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3318. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3319. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3320. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3321. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3322. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3323. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3324. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3325. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3326. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3327. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3328. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3329. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3330. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3331. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3332. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3333. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3334. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3335. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3336. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3337. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3338. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3339. return this;
  3340. }
  3341. multiplyScalar( s ) {
  3342. const te = this.elements;
  3343. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3344. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3345. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3346. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3347. return this;
  3348. }
  3349. determinant() {
  3350. const te = this.elements;
  3351. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3352. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3353. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3354. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3355. //TODO: make this more efficient
  3356. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3357. return (
  3358. n41 * (
  3359. + n14 * n23 * n32
  3360. - n13 * n24 * n32
  3361. - n14 * n22 * n33
  3362. + n12 * n24 * n33
  3363. + n13 * n22 * n34
  3364. - n12 * n23 * n34
  3365. ) +
  3366. n42 * (
  3367. + n11 * n23 * n34
  3368. - n11 * n24 * n33
  3369. + n14 * n21 * n33
  3370. - n13 * n21 * n34
  3371. + n13 * n24 * n31
  3372. - n14 * n23 * n31
  3373. ) +
  3374. n43 * (
  3375. + n11 * n24 * n32
  3376. - n11 * n22 * n34
  3377. - n14 * n21 * n32
  3378. + n12 * n21 * n34
  3379. + n14 * n22 * n31
  3380. - n12 * n24 * n31
  3381. ) +
  3382. n44 * (
  3383. - n13 * n22 * n31
  3384. - n11 * n23 * n32
  3385. + n11 * n22 * n33
  3386. + n13 * n21 * n32
  3387. - n12 * n21 * n33
  3388. + n12 * n23 * n31
  3389. )
  3390. );
  3391. }
  3392. transpose() {
  3393. const te = this.elements;
  3394. let tmp;
  3395. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3396. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3397. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3398. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3399. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3400. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3401. return this;
  3402. }
  3403. setPosition( x, y, z ) {
  3404. const te = this.elements;
  3405. if ( x.isVector3 ) {
  3406. te[ 12 ] = x.x;
  3407. te[ 13 ] = x.y;
  3408. te[ 14 ] = x.z;
  3409. } else {
  3410. te[ 12 ] = x;
  3411. te[ 13 ] = y;
  3412. te[ 14 ] = z;
  3413. }
  3414. return this;
  3415. }
  3416. invert() {
  3417. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3418. const te = this.elements,
  3419. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3420. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3421. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3422. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3423. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3424. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3425. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3426. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3427. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3428. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3429. const detInv = 1 / det;
  3430. te[ 0 ] = t11 * detInv;
  3431. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3432. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3433. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3434. te[ 4 ] = t12 * detInv;
  3435. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3436. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3437. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3438. te[ 8 ] = t13 * detInv;
  3439. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3440. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3441. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3442. te[ 12 ] = t14 * detInv;
  3443. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3444. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3445. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3446. return this;
  3447. }
  3448. scale( v ) {
  3449. const te = this.elements;
  3450. const x = v.x, y = v.y, z = v.z;
  3451. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3452. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3453. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3454. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3455. return this;
  3456. }
  3457. getMaxScaleOnAxis() {
  3458. const te = this.elements;
  3459. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3460. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3461. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3462. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3463. }
  3464. makeTranslation( x, y, z ) {
  3465. this.set(
  3466. 1, 0, 0, x,
  3467. 0, 1, 0, y,
  3468. 0, 0, 1, z,
  3469. 0, 0, 0, 1
  3470. );
  3471. return this;
  3472. }
  3473. makeRotationX( theta ) {
  3474. const c = Math.cos( theta ), s = Math.sin( theta );
  3475. this.set(
  3476. 1, 0, 0, 0,
  3477. 0, c, - s, 0,
  3478. 0, s, c, 0,
  3479. 0, 0, 0, 1
  3480. );
  3481. return this;
  3482. }
  3483. makeRotationY( theta ) {
  3484. const c = Math.cos( theta ), s = Math.sin( theta );
  3485. this.set(
  3486. c, 0, s, 0,
  3487. 0, 1, 0, 0,
  3488. - s, 0, c, 0,
  3489. 0, 0, 0, 1
  3490. );
  3491. return this;
  3492. }
  3493. makeRotationZ( theta ) {
  3494. const c = Math.cos( theta ), s = Math.sin( theta );
  3495. this.set(
  3496. c, - s, 0, 0,
  3497. s, c, 0, 0,
  3498. 0, 0, 1, 0,
  3499. 0, 0, 0, 1
  3500. );
  3501. return this;
  3502. }
  3503. makeRotationAxis( axis, angle ) {
  3504. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3505. const c = Math.cos( angle );
  3506. const s = Math.sin( angle );
  3507. const t = 1 - c;
  3508. const x = axis.x, y = axis.y, z = axis.z;
  3509. const tx = t * x, ty = t * y;
  3510. this.set(
  3511. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3512. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3513. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3514. 0, 0, 0, 1
  3515. );
  3516. return this;
  3517. }
  3518. makeScale( x, y, z ) {
  3519. this.set(
  3520. x, 0, 0, 0,
  3521. 0, y, 0, 0,
  3522. 0, 0, z, 0,
  3523. 0, 0, 0, 1
  3524. );
  3525. return this;
  3526. }
  3527. makeShear( x, y, z ) {
  3528. this.set(
  3529. 1, y, z, 0,
  3530. x, 1, z, 0,
  3531. x, y, 1, 0,
  3532. 0, 0, 0, 1
  3533. );
  3534. return this;
  3535. }
  3536. compose( position, quaternion, scale ) {
  3537. const te = this.elements;
  3538. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3539. const x2 = x + x, y2 = y + y, z2 = z + z;
  3540. const xx = x * x2, xy = x * y2, xz = x * z2;
  3541. const yy = y * y2, yz = y * z2, zz = z * z2;
  3542. const wx = w * x2, wy = w * y2, wz = w * z2;
  3543. const sx = scale.x, sy = scale.y, sz = scale.z;
  3544. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3545. te[ 1 ] = ( xy + wz ) * sx;
  3546. te[ 2 ] = ( xz - wy ) * sx;
  3547. te[ 3 ] = 0;
  3548. te[ 4 ] = ( xy - wz ) * sy;
  3549. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3550. te[ 6 ] = ( yz + wx ) * sy;
  3551. te[ 7 ] = 0;
  3552. te[ 8 ] = ( xz + wy ) * sz;
  3553. te[ 9 ] = ( yz - wx ) * sz;
  3554. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3555. te[ 11 ] = 0;
  3556. te[ 12 ] = position.x;
  3557. te[ 13 ] = position.y;
  3558. te[ 14 ] = position.z;
  3559. te[ 15 ] = 1;
  3560. return this;
  3561. }
  3562. decompose( position, quaternion, scale ) {
  3563. const te = this.elements;
  3564. let sx = _v1$1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3565. const sy = _v1$1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3566. const sz = _v1$1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3567. // if determine is negative, we need to invert one scale
  3568. const det = this.determinant();
  3569. if ( det < 0 ) sx = - sx;
  3570. position.x = te[ 12 ];
  3571. position.y = te[ 13 ];
  3572. position.z = te[ 14 ];
  3573. // scale the rotation part
  3574. _m1.copy( this );
  3575. const invSX = 1 / sx;
  3576. const invSY = 1 / sy;
  3577. const invSZ = 1 / sz;
  3578. _m1.elements[ 0 ] *= invSX;
  3579. _m1.elements[ 1 ] *= invSX;
  3580. _m1.elements[ 2 ] *= invSX;
  3581. _m1.elements[ 4 ] *= invSY;
  3582. _m1.elements[ 5 ] *= invSY;
  3583. _m1.elements[ 6 ] *= invSY;
  3584. _m1.elements[ 8 ] *= invSZ;
  3585. _m1.elements[ 9 ] *= invSZ;
  3586. _m1.elements[ 10 ] *= invSZ;
  3587. quaternion.setFromRotationMatrix( _m1 );
  3588. scale.x = sx;
  3589. scale.y = sy;
  3590. scale.z = sz;
  3591. return this;
  3592. }
  3593. makePerspective( left, right, top, bottom, near, far ) {
  3594. if ( far === undefined ) {
  3595. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3596. }
  3597. const te = this.elements;
  3598. const x = 2 * near / ( right - left );
  3599. const y = 2 * near / ( top - bottom );
  3600. const a = ( right + left ) / ( right - left );
  3601. const b = ( top + bottom ) / ( top - bottom );
  3602. const c = - ( far + near ) / ( far - near );
  3603. const d = - 2 * far * near / ( far - near );
  3604. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3605. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3606. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3607. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3608. return this;
  3609. }
  3610. makeOrthographic( left, right, top, bottom, near, far ) {
  3611. const te = this.elements;
  3612. const w = 1.0 / ( right - left );
  3613. const h = 1.0 / ( top - bottom );
  3614. const p = 1.0 / ( far - near );
  3615. const x = ( right + left ) * w;
  3616. const y = ( top + bottom ) * h;
  3617. const z = ( far + near ) * p;
  3618. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3619. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3620. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3621. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3622. return this;
  3623. }
  3624. equals( matrix ) {
  3625. const te = this.elements;
  3626. const me = matrix.elements;
  3627. for ( let i = 0; i < 16; i ++ ) {
  3628. if ( te[ i ] !== me[ i ] ) return false;
  3629. }
  3630. return true;
  3631. }
  3632. fromArray( array, offset = 0 ) {
  3633. for ( let i = 0; i < 16; i ++ ) {
  3634. this.elements[ i ] = array[ i + offset ];
  3635. }
  3636. return this;
  3637. }
  3638. toArray( array = [], offset = 0 ) {
  3639. const te = this.elements;
  3640. array[ offset ] = te[ 0 ];
  3641. array[ offset + 1 ] = te[ 1 ];
  3642. array[ offset + 2 ] = te[ 2 ];
  3643. array[ offset + 3 ] = te[ 3 ];
  3644. array[ offset + 4 ] = te[ 4 ];
  3645. array[ offset + 5 ] = te[ 5 ];
  3646. array[ offset + 6 ] = te[ 6 ];
  3647. array[ offset + 7 ] = te[ 7 ];
  3648. array[ offset + 8 ] = te[ 8 ];
  3649. array[ offset + 9 ] = te[ 9 ];
  3650. array[ offset + 10 ] = te[ 10 ];
  3651. array[ offset + 11 ] = te[ 11 ];
  3652. array[ offset + 12 ] = te[ 12 ];
  3653. array[ offset + 13 ] = te[ 13 ];
  3654. array[ offset + 14 ] = te[ 14 ];
  3655. array[ offset + 15 ] = te[ 15 ];
  3656. return array;
  3657. }
  3658. }
  3659. Matrix4.prototype.isMatrix4 = true;
  3660. const _v1$1 = /*@__PURE__*/ new Vector3();
  3661. const _m1 = /*@__PURE__*/ new Matrix4();
  3662. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  3663. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  3664. const _x = /*@__PURE__*/ new Vector3();
  3665. const _y = /*@__PURE__*/ new Vector3();
  3666. const _z = /*@__PURE__*/ new Vector3();
  3667. const _matrix = /*@__PURE__*/ new Matrix4();
  3668. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  3669. class Euler {
  3670. constructor( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
  3671. this._x = x;
  3672. this._y = y;
  3673. this._z = z;
  3674. this._order = order;
  3675. }
  3676. get x() {
  3677. return this._x;
  3678. }
  3679. set x( value ) {
  3680. this._x = value;
  3681. this._onChangeCallback();
  3682. }
  3683. get y() {
  3684. return this._y;
  3685. }
  3686. set y( value ) {
  3687. this._y = value;
  3688. this._onChangeCallback();
  3689. }
  3690. get z() {
  3691. return this._z;
  3692. }
  3693. set z( value ) {
  3694. this._z = value;
  3695. this._onChangeCallback();
  3696. }
  3697. get order() {
  3698. return this._order;
  3699. }
  3700. set order( value ) {
  3701. this._order = value;
  3702. this._onChangeCallback();
  3703. }
  3704. set( x, y, z, order ) {
  3705. this._x = x;
  3706. this._y = y;
  3707. this._z = z;
  3708. this._order = order || this._order;
  3709. this._onChangeCallback();
  3710. return this;
  3711. }
  3712. clone() {
  3713. return new this.constructor( this._x, this._y, this._z, this._order );
  3714. }
  3715. copy( euler ) {
  3716. this._x = euler._x;
  3717. this._y = euler._y;
  3718. this._z = euler._z;
  3719. this._order = euler._order;
  3720. this._onChangeCallback();
  3721. return this;
  3722. }
  3723. setFromRotationMatrix( m, order, update ) {
  3724. const clamp = MathUtils.clamp;
  3725. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3726. const te = m.elements;
  3727. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3728. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3729. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3730. order = order || this._order;
  3731. switch ( order ) {
  3732. case 'XYZ':
  3733. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3734. if ( Math.abs( m13 ) < 0.9999999 ) {
  3735. this._x = Math.atan2( - m23, m33 );
  3736. this._z = Math.atan2( - m12, m11 );
  3737. } else {
  3738. this._x = Math.atan2( m32, m22 );
  3739. this._z = 0;
  3740. }
  3741. break;
  3742. case 'YXZ':
  3743. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3744. if ( Math.abs( m23 ) < 0.9999999 ) {
  3745. this._y = Math.atan2( m13, m33 );
  3746. this._z = Math.atan2( m21, m22 );
  3747. } else {
  3748. this._y = Math.atan2( - m31, m11 );
  3749. this._z = 0;
  3750. }
  3751. break;
  3752. case 'ZXY':
  3753. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3754. if ( Math.abs( m32 ) < 0.9999999 ) {
  3755. this._y = Math.atan2( - m31, m33 );
  3756. this._z = Math.atan2( - m12, m22 );
  3757. } else {
  3758. this._y = 0;
  3759. this._z = Math.atan2( m21, m11 );
  3760. }
  3761. break;
  3762. case 'ZYX':
  3763. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3764. if ( Math.abs( m31 ) < 0.9999999 ) {
  3765. this._x = Math.atan2( m32, m33 );
  3766. this._z = Math.atan2( m21, m11 );
  3767. } else {
  3768. this._x = 0;
  3769. this._z = Math.atan2( - m12, m22 );
  3770. }
  3771. break;
  3772. case 'YZX':
  3773. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3774. if ( Math.abs( m21 ) < 0.9999999 ) {
  3775. this._x = Math.atan2( - m23, m22 );
  3776. this._y = Math.atan2( - m31, m11 );
  3777. } else {
  3778. this._x = 0;
  3779. this._y = Math.atan2( m13, m33 );
  3780. }
  3781. break;
  3782. case 'XZY':
  3783. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3784. if ( Math.abs( m12 ) < 0.9999999 ) {
  3785. this._x = Math.atan2( m32, m22 );
  3786. this._y = Math.atan2( m13, m11 );
  3787. } else {
  3788. this._x = Math.atan2( - m23, m33 );
  3789. this._y = 0;
  3790. }
  3791. break;
  3792. default:
  3793. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3794. }
  3795. this._order = order;
  3796. if ( update !== false ) this._onChangeCallback();
  3797. return this;
  3798. }
  3799. setFromQuaternion( q, order, update ) {
  3800. _matrix.makeRotationFromQuaternion( q );
  3801. return this.setFromRotationMatrix( _matrix, order, update );
  3802. }
  3803. setFromVector3( v, order ) {
  3804. return this.set( v.x, v.y, v.z, order || this._order );
  3805. }
  3806. reorder( newOrder ) {
  3807. // WARNING: this discards revolution information -bhouston
  3808. _quaternion$1.setFromEuler( this );
  3809. return this.setFromQuaternion( _quaternion$1, newOrder );
  3810. }
  3811. equals( euler ) {
  3812. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3813. }
  3814. fromArray( array ) {
  3815. this._x = array[ 0 ];
  3816. this._y = array[ 1 ];
  3817. this._z = array[ 2 ];
  3818. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3819. this._onChangeCallback();
  3820. return this;
  3821. }
  3822. toArray( array = [], offset = 0 ) {
  3823. array[ offset ] = this._x;
  3824. array[ offset + 1 ] = this._y;
  3825. array[ offset + 2 ] = this._z;
  3826. array[ offset + 3 ] = this._order;
  3827. return array;
  3828. }
  3829. toVector3( optionalResult ) {
  3830. if ( optionalResult ) {
  3831. return optionalResult.set( this._x, this._y, this._z );
  3832. } else {
  3833. return new Vector3( this._x, this._y, this._z );
  3834. }
  3835. }
  3836. _onChange( callback ) {
  3837. this._onChangeCallback = callback;
  3838. return this;
  3839. }
  3840. _onChangeCallback() {}
  3841. }
  3842. Euler.prototype.isEuler = true;
  3843. Euler.DefaultOrder = 'XYZ';
  3844. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3845. class Layers {
  3846. constructor() {
  3847. this.mask = 1 | 0;
  3848. }
  3849. set( channel ) {
  3850. this.mask = 1 << channel | 0;
  3851. }
  3852. enable( channel ) {
  3853. this.mask |= 1 << channel | 0;
  3854. }
  3855. enableAll() {
  3856. this.mask = 0xffffffff | 0;
  3857. }
  3858. toggle( channel ) {
  3859. this.mask ^= 1 << channel | 0;
  3860. }
  3861. disable( channel ) {
  3862. this.mask &= ~ ( 1 << channel | 0 );
  3863. }
  3864. disableAll() {
  3865. this.mask = 0;
  3866. }
  3867. test( layers ) {
  3868. return ( this.mask & layers.mask ) !== 0;
  3869. }
  3870. }
  3871. let _object3DId = 0;
  3872. const _v1$2 = new Vector3();
  3873. const _q1 = new Quaternion();
  3874. const _m1$1 = new Matrix4();
  3875. const _target = new Vector3();
  3876. const _position = new Vector3();
  3877. const _scale = new Vector3();
  3878. const _quaternion$2 = new Quaternion();
  3879. const _xAxis = new Vector3( 1, 0, 0 );
  3880. const _yAxis = new Vector3( 0, 1, 0 );
  3881. const _zAxis = new Vector3( 0, 0, 1 );
  3882. const _addedEvent = { type: 'added' };
  3883. const _removedEvent = { type: 'removed' };
  3884. function Object3D() {
  3885. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3886. this.uuid = MathUtils.generateUUID();
  3887. this.name = '';
  3888. this.type = 'Object3D';
  3889. this.parent = null;
  3890. this.children = [];
  3891. this.up = Object3D.DefaultUp.clone();
  3892. const position = new Vector3();
  3893. const rotation = new Euler();
  3894. const quaternion = new Quaternion();
  3895. const scale = new Vector3( 1, 1, 1 );
  3896. function onRotationChange() {
  3897. quaternion.setFromEuler( rotation, false );
  3898. }
  3899. function onQuaternionChange() {
  3900. rotation.setFromQuaternion( quaternion, undefined, false );
  3901. }
  3902. rotation._onChange( onRotationChange );
  3903. quaternion._onChange( onQuaternionChange );
  3904. Object.defineProperties( this, {
  3905. position: {
  3906. configurable: true,
  3907. enumerable: true,
  3908. value: position
  3909. },
  3910. rotation: {
  3911. configurable: true,
  3912. enumerable: true,
  3913. value: rotation
  3914. },
  3915. quaternion: {
  3916. configurable: true,
  3917. enumerable: true,
  3918. value: quaternion
  3919. },
  3920. scale: {
  3921. configurable: true,
  3922. enumerable: true,
  3923. value: scale
  3924. },
  3925. modelViewMatrix: {
  3926. value: new Matrix4()
  3927. },
  3928. normalMatrix: {
  3929. value: new Matrix3()
  3930. }
  3931. } );
  3932. this.matrix = new Matrix4();
  3933. this.matrixWorld = new Matrix4();
  3934. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3935. this.matrixWorldNeedsUpdate = false;
  3936. this.layers = new Layers();
  3937. this.visible = true;
  3938. this.castShadow = false;
  3939. this.receiveShadow = false;
  3940. this.frustumCulled = true;
  3941. this.renderOrder = 0;
  3942. this.animations = [];
  3943. this.userData = {};
  3944. }
  3945. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3946. Object3D.DefaultMatrixAutoUpdate = true;
  3947. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3948. constructor: Object3D,
  3949. isObject3D: true,
  3950. onBeforeRender: function () {},
  3951. onAfterRender: function () {},
  3952. applyMatrix4: function ( matrix ) {
  3953. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3954. this.matrix.premultiply( matrix );
  3955. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3956. },
  3957. applyQuaternion: function ( q ) {
  3958. this.quaternion.premultiply( q );
  3959. return this;
  3960. },
  3961. setRotationFromAxisAngle: function ( axis, angle ) {
  3962. // assumes axis is normalized
  3963. this.quaternion.setFromAxisAngle( axis, angle );
  3964. },
  3965. setRotationFromEuler: function ( euler ) {
  3966. this.quaternion.setFromEuler( euler, true );
  3967. },
  3968. setRotationFromMatrix: function ( m ) {
  3969. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3970. this.quaternion.setFromRotationMatrix( m );
  3971. },
  3972. setRotationFromQuaternion: function ( q ) {
  3973. // assumes q is normalized
  3974. this.quaternion.copy( q );
  3975. },
  3976. rotateOnAxis: function ( axis, angle ) {
  3977. // rotate object on axis in object space
  3978. // axis is assumed to be normalized
  3979. _q1.setFromAxisAngle( axis, angle );
  3980. this.quaternion.multiply( _q1 );
  3981. return this;
  3982. },
  3983. rotateOnWorldAxis: function ( axis, angle ) {
  3984. // rotate object on axis in world space
  3985. // axis is assumed to be normalized
  3986. // method assumes no rotated parent
  3987. _q1.setFromAxisAngle( axis, angle );
  3988. this.quaternion.premultiply( _q1 );
  3989. return this;
  3990. },
  3991. rotateX: function ( angle ) {
  3992. return this.rotateOnAxis( _xAxis, angle );
  3993. },
  3994. rotateY: function ( angle ) {
  3995. return this.rotateOnAxis( _yAxis, angle );
  3996. },
  3997. rotateZ: function ( angle ) {
  3998. return this.rotateOnAxis( _zAxis, angle );
  3999. },
  4000. translateOnAxis: function ( axis, distance ) {
  4001. // translate object by distance along axis in object space
  4002. // axis is assumed to be normalized
  4003. _v1$2.copy( axis ).applyQuaternion( this.quaternion );
  4004. this.position.add( _v1$2.multiplyScalar( distance ) );
  4005. return this;
  4006. },
  4007. translateX: function ( distance ) {
  4008. return this.translateOnAxis( _xAxis, distance );
  4009. },
  4010. translateY: function ( distance ) {
  4011. return this.translateOnAxis( _yAxis, distance );
  4012. },
  4013. translateZ: function ( distance ) {
  4014. return this.translateOnAxis( _zAxis, distance );
  4015. },
  4016. localToWorld: function ( vector ) {
  4017. return vector.applyMatrix4( this.matrixWorld );
  4018. },
  4019. worldToLocal: function ( vector ) {
  4020. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4021. },
  4022. lookAt: function ( x, y, z ) {
  4023. // This method does not support objects having non-uniformly-scaled parent(s)
  4024. if ( x.isVector3 ) {
  4025. _target.copy( x );
  4026. } else {
  4027. _target.set( x, y, z );
  4028. }
  4029. const parent = this.parent;
  4030. this.updateWorldMatrix( true, false );
  4031. _position.setFromMatrixPosition( this.matrixWorld );
  4032. if ( this.isCamera || this.isLight ) {
  4033. _m1$1.lookAt( _position, _target, this.up );
  4034. } else {
  4035. _m1$1.lookAt( _target, _position, this.up );
  4036. }
  4037. this.quaternion.setFromRotationMatrix( _m1$1 );
  4038. if ( parent ) {
  4039. _m1$1.extractRotation( parent.matrixWorld );
  4040. _q1.setFromRotationMatrix( _m1$1 );
  4041. this.quaternion.premultiply( _q1.invert() );
  4042. }
  4043. },
  4044. add: function ( object ) {
  4045. if ( arguments.length > 1 ) {
  4046. for ( let i = 0; i < arguments.length; i ++ ) {
  4047. this.add( arguments[ i ] );
  4048. }
  4049. return this;
  4050. }
  4051. if ( object === this ) {
  4052. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4053. return this;
  4054. }
  4055. if ( object && object.isObject3D ) {
  4056. if ( object.parent !== null ) {
  4057. object.parent.remove( object );
  4058. }
  4059. object.parent = this;
  4060. this.children.push( object );
  4061. object.dispatchEvent( _addedEvent );
  4062. } else {
  4063. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4064. }
  4065. return this;
  4066. },
  4067. remove: function ( object ) {
  4068. if ( arguments.length > 1 ) {
  4069. for ( let i = 0; i < arguments.length; i ++ ) {
  4070. this.remove( arguments[ i ] );
  4071. }
  4072. return this;
  4073. }
  4074. const index = this.children.indexOf( object );
  4075. if ( index !== - 1 ) {
  4076. object.parent = null;
  4077. this.children.splice( index, 1 );
  4078. object.dispatchEvent( _removedEvent );
  4079. }
  4080. return this;
  4081. },
  4082. clear: function () {
  4083. for ( let i = 0; i < this.children.length; i ++ ) {
  4084. const object = this.children[ i ];
  4085. object.parent = null;
  4086. object.dispatchEvent( _removedEvent );
  4087. }
  4088. this.children.length = 0;
  4089. return this;
  4090. },
  4091. attach: function ( object ) {
  4092. // adds object as a child of this, while maintaining the object's world transform
  4093. this.updateWorldMatrix( true, false );
  4094. _m1$1.copy( this.matrixWorld ).invert();
  4095. if ( object.parent !== null ) {
  4096. object.parent.updateWorldMatrix( true, false );
  4097. _m1$1.multiply( object.parent.matrixWorld );
  4098. }
  4099. object.applyMatrix4( _m1$1 );
  4100. this.add( object );
  4101. object.updateWorldMatrix( false, true );
  4102. return this;
  4103. },
  4104. getObjectById: function ( id ) {
  4105. return this.getObjectByProperty( 'id', id );
  4106. },
  4107. getObjectByName: function ( name ) {
  4108. return this.getObjectByProperty( 'name', name );
  4109. },
  4110. getObjectByProperty: function ( name, value ) {
  4111. if ( this[ name ] === value ) return this;
  4112. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4113. const child = this.children[ i ];
  4114. const object = child.getObjectByProperty( name, value );
  4115. if ( object !== undefined ) {
  4116. return object;
  4117. }
  4118. }
  4119. return undefined;
  4120. },
  4121. getWorldPosition: function ( target ) {
  4122. if ( target === undefined ) {
  4123. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4124. target = new Vector3();
  4125. }
  4126. this.updateWorldMatrix( true, false );
  4127. return target.setFromMatrixPosition( this.matrixWorld );
  4128. },
  4129. getWorldQuaternion: function ( target ) {
  4130. if ( target === undefined ) {
  4131. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  4132. target = new Quaternion();
  4133. }
  4134. this.updateWorldMatrix( true, false );
  4135. this.matrixWorld.decompose( _position, target, _scale );
  4136. return target;
  4137. },
  4138. getWorldScale: function ( target ) {
  4139. if ( target === undefined ) {
  4140. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  4141. target = new Vector3();
  4142. }
  4143. this.updateWorldMatrix( true, false );
  4144. this.matrixWorld.decompose( _position, _quaternion$2, target );
  4145. return target;
  4146. },
  4147. getWorldDirection: function ( target ) {
  4148. if ( target === undefined ) {
  4149. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  4150. target = new Vector3();
  4151. }
  4152. this.updateWorldMatrix( true, false );
  4153. const e = this.matrixWorld.elements;
  4154. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4155. },
  4156. raycast: function () {},
  4157. traverse: function ( callback ) {
  4158. callback( this );
  4159. const children = this.children;
  4160. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4161. children[ i ].traverse( callback );
  4162. }
  4163. },
  4164. traverseVisible: function ( callback ) {
  4165. if ( this.visible === false ) return;
  4166. callback( this );
  4167. const children = this.children;
  4168. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4169. children[ i ].traverseVisible( callback );
  4170. }
  4171. },
  4172. traverseAncestors: function ( callback ) {
  4173. const parent = this.parent;
  4174. if ( parent !== null ) {
  4175. callback( parent );
  4176. parent.traverseAncestors( callback );
  4177. }
  4178. },
  4179. updateMatrix: function () {
  4180. this.matrix.compose( this.position, this.quaternion, this.scale );
  4181. this.matrixWorldNeedsUpdate = true;
  4182. },
  4183. updateMatrixWorld: function ( force ) {
  4184. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4185. if ( this.matrixWorldNeedsUpdate || force ) {
  4186. if ( this.parent === null ) {
  4187. this.matrixWorld.copy( this.matrix );
  4188. } else {
  4189. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4190. }
  4191. this.matrixWorldNeedsUpdate = false;
  4192. force = true;
  4193. }
  4194. // update children
  4195. const children = this.children;
  4196. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4197. children[ i ].updateMatrixWorld( force );
  4198. }
  4199. },
  4200. updateWorldMatrix: function ( updateParents, updateChildren ) {
  4201. const parent = this.parent;
  4202. if ( updateParents === true && parent !== null ) {
  4203. parent.updateWorldMatrix( true, false );
  4204. }
  4205. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4206. if ( this.parent === null ) {
  4207. this.matrixWorld.copy( this.matrix );
  4208. } else {
  4209. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4210. }
  4211. // update children
  4212. if ( updateChildren === true ) {
  4213. const children = this.children;
  4214. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4215. children[ i ].updateWorldMatrix( false, true );
  4216. }
  4217. }
  4218. },
  4219. toJSON: function ( meta ) {
  4220. // meta is a string when called from JSON.stringify
  4221. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4222. const output = {};
  4223. // meta is a hash used to collect geometries, materials.
  4224. // not providing it implies that this is the root object
  4225. // being serialized.
  4226. if ( isRootObject ) {
  4227. // initialize meta obj
  4228. meta = {
  4229. geometries: {},
  4230. materials: {},
  4231. textures: {},
  4232. images: {},
  4233. shapes: {},
  4234. skeletons: {},
  4235. animations: {}
  4236. };
  4237. output.metadata = {
  4238. version: 4.5,
  4239. type: 'Object',
  4240. generator: 'Object3D.toJSON'
  4241. };
  4242. }
  4243. // standard Object3D serialization
  4244. const object = {};
  4245. object.uuid = this.uuid;
  4246. object.type = this.type;
  4247. if ( this.name !== '' ) object.name = this.name;
  4248. if ( this.castShadow === true ) object.castShadow = true;
  4249. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4250. if ( this.visible === false ) object.visible = false;
  4251. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4252. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4253. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4254. object.layers = this.layers.mask;
  4255. object.matrix = this.matrix.toArray();
  4256. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4257. // object specific properties
  4258. if ( this.isInstancedMesh ) {
  4259. object.type = 'InstancedMesh';
  4260. object.count = this.count;
  4261. object.instanceMatrix = this.instanceMatrix.toJSON();
  4262. }
  4263. //
  4264. function serialize( library, element ) {
  4265. if ( library[ element.uuid ] === undefined ) {
  4266. library[ element.uuid ] = element.toJSON( meta );
  4267. }
  4268. return element.uuid;
  4269. }
  4270. if ( this.isMesh || this.isLine || this.isPoints ) {
  4271. object.geometry = serialize( meta.geometries, this.geometry );
  4272. const parameters = this.geometry.parameters;
  4273. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4274. const shapes = parameters.shapes;
  4275. if ( Array.isArray( shapes ) ) {
  4276. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4277. const shape = shapes[ i ];
  4278. serialize( meta.shapes, shape );
  4279. }
  4280. } else {
  4281. serialize( meta.shapes, shapes );
  4282. }
  4283. }
  4284. }
  4285. if ( this.isSkinnedMesh ) {
  4286. object.bindMode = this.bindMode;
  4287. object.bindMatrix = this.bindMatrix.toArray();
  4288. if ( this.skeleton !== undefined ) {
  4289. serialize( meta.skeletons, this.skeleton );
  4290. object.skeleton = this.skeleton.uuid;
  4291. }
  4292. }
  4293. if ( this.material !== undefined ) {
  4294. if ( Array.isArray( this.material ) ) {
  4295. const uuids = [];
  4296. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4297. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4298. }
  4299. object.material = uuids;
  4300. } else {
  4301. object.material = serialize( meta.materials, this.material );
  4302. }
  4303. }
  4304. //
  4305. if ( this.children.length > 0 ) {
  4306. object.children = [];
  4307. for ( let i = 0; i < this.children.length; i ++ ) {
  4308. object.children.push( this.children[ i ].toJSON( meta ).object );
  4309. }
  4310. }
  4311. //
  4312. if ( this.animations.length > 0 ) {
  4313. object.animations = [];
  4314. for ( let i = 0; i < this.animations.length; i ++ ) {
  4315. const animation = this.animations[ i ];
  4316. object.animations.push( serialize( meta.animations, animation ) );
  4317. }
  4318. }
  4319. if ( isRootObject ) {
  4320. const geometries = extractFromCache( meta.geometries );
  4321. const materials = extractFromCache( meta.materials );
  4322. const textures = extractFromCache( meta.textures );
  4323. const images = extractFromCache( meta.images );
  4324. const shapes = extractFromCache( meta.shapes );
  4325. const skeletons = extractFromCache( meta.skeletons );
  4326. const animations = extractFromCache( meta.animations );
  4327. if ( geometries.length > 0 ) output.geometries = geometries;
  4328. if ( materials.length > 0 ) output.materials = materials;
  4329. if ( textures.length > 0 ) output.textures = textures;
  4330. if ( images.length > 0 ) output.images = images;
  4331. if ( shapes.length > 0 ) output.shapes = shapes;
  4332. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4333. if ( animations.length > 0 ) output.animations = animations;
  4334. }
  4335. output.object = object;
  4336. return output;
  4337. // extract data from the cache hash
  4338. // remove metadata on each item
  4339. // and return as array
  4340. function extractFromCache( cache ) {
  4341. const values = [];
  4342. for ( const key in cache ) {
  4343. const data = cache[ key ];
  4344. delete data.metadata;
  4345. values.push( data );
  4346. }
  4347. return values;
  4348. }
  4349. },
  4350. clone: function ( recursive ) {
  4351. return new this.constructor().copy( this, recursive );
  4352. },
  4353. copy: function ( source, recursive = true ) {
  4354. this.name = source.name;
  4355. this.up.copy( source.up );
  4356. this.position.copy( source.position );
  4357. this.rotation.order = source.rotation.order;
  4358. this.quaternion.copy( source.quaternion );
  4359. this.scale.copy( source.scale );
  4360. this.matrix.copy( source.matrix );
  4361. this.matrixWorld.copy( source.matrixWorld );
  4362. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4363. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4364. this.layers.mask = source.layers.mask;
  4365. this.visible = source.visible;
  4366. this.castShadow = source.castShadow;
  4367. this.receiveShadow = source.receiveShadow;
  4368. this.frustumCulled = source.frustumCulled;
  4369. this.renderOrder = source.renderOrder;
  4370. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4371. if ( recursive === true ) {
  4372. for ( let i = 0; i < source.children.length; i ++ ) {
  4373. const child = source.children[ i ];
  4374. this.add( child.clone() );
  4375. }
  4376. }
  4377. return this;
  4378. }
  4379. } );
  4380. const _vector1 = /*@__PURE__*/ new Vector3();
  4381. const _vector2 = /*@__PURE__*/ new Vector3();
  4382. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  4383. class Plane {
  4384. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  4385. // normal is assumed to be normalized
  4386. this.normal = normal;
  4387. this.constant = constant;
  4388. }
  4389. set( normal, constant ) {
  4390. this.normal.copy( normal );
  4391. this.constant = constant;
  4392. return this;
  4393. }
  4394. setComponents( x, y, z, w ) {
  4395. this.normal.set( x, y, z );
  4396. this.constant = w;
  4397. return this;
  4398. }
  4399. setFromNormalAndCoplanarPoint( normal, point ) {
  4400. this.normal.copy( normal );
  4401. this.constant = - point.dot( this.normal );
  4402. return this;
  4403. }
  4404. setFromCoplanarPoints( a, b, c ) {
  4405. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4406. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4407. this.setFromNormalAndCoplanarPoint( normal, a );
  4408. return this;
  4409. }
  4410. copy( plane ) {
  4411. this.normal.copy( plane.normal );
  4412. this.constant = plane.constant;
  4413. return this;
  4414. }
  4415. normalize() {
  4416. // Note: will lead to a divide by zero if the plane is invalid.
  4417. const inverseNormalLength = 1.0 / this.normal.length();
  4418. this.normal.multiplyScalar( inverseNormalLength );
  4419. this.constant *= inverseNormalLength;
  4420. return this;
  4421. }
  4422. negate() {
  4423. this.constant *= - 1;
  4424. this.normal.negate();
  4425. return this;
  4426. }
  4427. distanceToPoint( point ) {
  4428. return this.normal.dot( point ) + this.constant;
  4429. }
  4430. distanceToSphere( sphere ) {
  4431. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4432. }
  4433. projectPoint( point, target ) {
  4434. if ( target === undefined ) {
  4435. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4436. target = new Vector3();
  4437. }
  4438. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4439. }
  4440. intersectLine( line, target ) {
  4441. if ( target === undefined ) {
  4442. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4443. target = new Vector3();
  4444. }
  4445. const direction = line.delta( _vector1 );
  4446. const denominator = this.normal.dot( direction );
  4447. if ( denominator === 0 ) {
  4448. // line is coplanar, return origin
  4449. if ( this.distanceToPoint( line.start ) === 0 ) {
  4450. return target.copy( line.start );
  4451. }
  4452. // Unsure if this is the correct method to handle this case.
  4453. return undefined;
  4454. }
  4455. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4456. if ( t < 0 || t > 1 ) {
  4457. return undefined;
  4458. }
  4459. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4460. }
  4461. intersectsLine( line ) {
  4462. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4463. const startSign = this.distanceToPoint( line.start );
  4464. const endSign = this.distanceToPoint( line.end );
  4465. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4466. }
  4467. intersectsBox( box ) {
  4468. return box.intersectsPlane( this );
  4469. }
  4470. intersectsSphere( sphere ) {
  4471. return sphere.intersectsPlane( this );
  4472. }
  4473. coplanarPoint( target ) {
  4474. if ( target === undefined ) {
  4475. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4476. target = new Vector3();
  4477. }
  4478. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4479. }
  4480. applyMatrix4( matrix, optionalNormalMatrix ) {
  4481. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4482. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4483. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4484. this.constant = - referencePoint.dot( normal );
  4485. return this;
  4486. }
  4487. translate( offset ) {
  4488. this.constant -= offset.dot( this.normal );
  4489. return this;
  4490. }
  4491. equals( plane ) {
  4492. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4493. }
  4494. clone() {
  4495. return new this.constructor().copy( this );
  4496. }
  4497. }
  4498. Plane.prototype.isPlane = true;
  4499. const _v0$1 = /*@__PURE__*/ new Vector3();
  4500. const _v1$3 = /*@__PURE__*/ new Vector3();
  4501. const _v2$1 = /*@__PURE__*/ new Vector3();
  4502. const _v3 = /*@__PURE__*/ new Vector3();
  4503. const _vab = /*@__PURE__*/ new Vector3();
  4504. const _vac = /*@__PURE__*/ new Vector3();
  4505. const _vbc = /*@__PURE__*/ new Vector3();
  4506. const _vap = /*@__PURE__*/ new Vector3();
  4507. const _vbp = /*@__PURE__*/ new Vector3();
  4508. const _vcp = /*@__PURE__*/ new Vector3();
  4509. class Triangle {
  4510. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4511. this.a = a;
  4512. this.b = b;
  4513. this.c = c;
  4514. }
  4515. static getNormal( a, b, c, target ) {
  4516. if ( target === undefined ) {
  4517. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4518. target = new Vector3();
  4519. }
  4520. target.subVectors( c, b );
  4521. _v0$1.subVectors( a, b );
  4522. target.cross( _v0$1 );
  4523. const targetLengthSq = target.lengthSq();
  4524. if ( targetLengthSq > 0 ) {
  4525. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4526. }
  4527. return target.set( 0, 0, 0 );
  4528. }
  4529. // static/instance method to calculate barycentric coordinates
  4530. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4531. static getBarycoord( point, a, b, c, target ) {
  4532. _v0$1.subVectors( c, a );
  4533. _v1$3.subVectors( b, a );
  4534. _v2$1.subVectors( point, a );
  4535. const dot00 = _v0$1.dot( _v0$1 );
  4536. const dot01 = _v0$1.dot( _v1$3 );
  4537. const dot02 = _v0$1.dot( _v2$1 );
  4538. const dot11 = _v1$3.dot( _v1$3 );
  4539. const dot12 = _v1$3.dot( _v2$1 );
  4540. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4541. if ( target === undefined ) {
  4542. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4543. target = new Vector3();
  4544. }
  4545. // collinear or singular triangle
  4546. if ( denom === 0 ) {
  4547. // arbitrary location outside of triangle?
  4548. // not sure if this is the best idea, maybe should be returning undefined
  4549. return target.set( - 2, - 1, - 1 );
  4550. }
  4551. const invDenom = 1 / denom;
  4552. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4553. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4554. // barycentric coordinates must always sum to 1
  4555. return target.set( 1 - u - v, v, u );
  4556. }
  4557. static containsPoint( point, a, b, c ) {
  4558. this.getBarycoord( point, a, b, c, _v3 );
  4559. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4560. }
  4561. static getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4562. this.getBarycoord( point, p1, p2, p3, _v3 );
  4563. target.set( 0, 0 );
  4564. target.addScaledVector( uv1, _v3.x );
  4565. target.addScaledVector( uv2, _v3.y );
  4566. target.addScaledVector( uv3, _v3.z );
  4567. return target;
  4568. }
  4569. static isFrontFacing( a, b, c, direction ) {
  4570. _v0$1.subVectors( c, b );
  4571. _v1$3.subVectors( a, b );
  4572. // strictly front facing
  4573. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4574. }
  4575. set( a, b, c ) {
  4576. this.a.copy( a );
  4577. this.b.copy( b );
  4578. this.c.copy( c );
  4579. return this;
  4580. }
  4581. setFromPointsAndIndices( points, i0, i1, i2 ) {
  4582. this.a.copy( points[ i0 ] );
  4583. this.b.copy( points[ i1 ] );
  4584. this.c.copy( points[ i2 ] );
  4585. return this;
  4586. }
  4587. clone() {
  4588. return new this.constructor().copy( this );
  4589. }
  4590. copy( triangle ) {
  4591. this.a.copy( triangle.a );
  4592. this.b.copy( triangle.b );
  4593. this.c.copy( triangle.c );
  4594. return this;
  4595. }
  4596. getArea() {
  4597. _v0$1.subVectors( this.c, this.b );
  4598. _v1$3.subVectors( this.a, this.b );
  4599. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4600. }
  4601. getMidpoint( target ) {
  4602. if ( target === undefined ) {
  4603. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4604. target = new Vector3();
  4605. }
  4606. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4607. }
  4608. getNormal( target ) {
  4609. return Triangle.getNormal( this.a, this.b, this.c, target );
  4610. }
  4611. getPlane( target ) {
  4612. if ( target === undefined ) {
  4613. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4614. target = new Plane();
  4615. }
  4616. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4617. }
  4618. getBarycoord( point, target ) {
  4619. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4620. }
  4621. getUV( point, uv1, uv2, uv3, target ) {
  4622. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4623. }
  4624. containsPoint( point ) {
  4625. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4626. }
  4627. isFrontFacing( direction ) {
  4628. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4629. }
  4630. intersectsBox( box ) {
  4631. return box.intersectsTriangle( this );
  4632. }
  4633. closestPointToPoint( p, target ) {
  4634. if ( target === undefined ) {
  4635. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4636. target = new Vector3();
  4637. }
  4638. const a = this.a, b = this.b, c = this.c;
  4639. let v, w;
  4640. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4641. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4642. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4643. // basically, we're distinguishing which of the voronoi regions of the triangle
  4644. // the point lies in with the minimum amount of redundant computation.
  4645. _vab.subVectors( b, a );
  4646. _vac.subVectors( c, a );
  4647. _vap.subVectors( p, a );
  4648. const d1 = _vab.dot( _vap );
  4649. const d2 = _vac.dot( _vap );
  4650. if ( d1 <= 0 && d2 <= 0 ) {
  4651. // vertex region of A; barycentric coords (1, 0, 0)
  4652. return target.copy( a );
  4653. }
  4654. _vbp.subVectors( p, b );
  4655. const d3 = _vab.dot( _vbp );
  4656. const d4 = _vac.dot( _vbp );
  4657. if ( d3 >= 0 && d4 <= d3 ) {
  4658. // vertex region of B; barycentric coords (0, 1, 0)
  4659. return target.copy( b );
  4660. }
  4661. const vc = d1 * d4 - d3 * d2;
  4662. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4663. v = d1 / ( d1 - d3 );
  4664. // edge region of AB; barycentric coords (1-v, v, 0)
  4665. return target.copy( a ).addScaledVector( _vab, v );
  4666. }
  4667. _vcp.subVectors( p, c );
  4668. const d5 = _vab.dot( _vcp );
  4669. const d6 = _vac.dot( _vcp );
  4670. if ( d6 >= 0 && d5 <= d6 ) {
  4671. // vertex region of C; barycentric coords (0, 0, 1)
  4672. return target.copy( c );
  4673. }
  4674. const vb = d5 * d2 - d1 * d6;
  4675. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4676. w = d2 / ( d2 - d6 );
  4677. // edge region of AC; barycentric coords (1-w, 0, w)
  4678. return target.copy( a ).addScaledVector( _vac, w );
  4679. }
  4680. const va = d3 * d6 - d5 * d4;
  4681. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4682. _vbc.subVectors( c, b );
  4683. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4684. // edge region of BC; barycentric coords (0, 1-w, w)
  4685. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4686. }
  4687. // face region
  4688. const denom = 1 / ( va + vb + vc );
  4689. // u = va * denom
  4690. v = vb * denom;
  4691. w = vc * denom;
  4692. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4693. }
  4694. equals( triangle ) {
  4695. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4696. }
  4697. }
  4698. let materialId = 0;
  4699. function Material() {
  4700. Object.defineProperty( this, 'id', { value: materialId ++ } );
  4701. this.uuid = MathUtils.generateUUID();
  4702. this.name = '';
  4703. this.type = 'Material';
  4704. this.fog = true;
  4705. this.blending = NormalBlending;
  4706. this.side = FrontSide;
  4707. this.vertexColors = false;
  4708. this.opacity = 1;
  4709. this.transparent = false;
  4710. this.blendSrc = SrcAlphaFactor;
  4711. this.blendDst = OneMinusSrcAlphaFactor;
  4712. this.blendEquation = AddEquation;
  4713. this.blendSrcAlpha = null;
  4714. this.blendDstAlpha = null;
  4715. this.blendEquationAlpha = null;
  4716. this.depthFunc = LessEqualDepth;
  4717. this.depthTest = true;
  4718. this.depthWrite = true;
  4719. this.stencilWriteMask = 0xff;
  4720. this.stencilFunc = AlwaysStencilFunc;
  4721. this.stencilRef = 0;
  4722. this.stencilFuncMask = 0xff;
  4723. this.stencilFail = KeepStencilOp;
  4724. this.stencilZFail = KeepStencilOp;
  4725. this.stencilZPass = KeepStencilOp;
  4726. this.stencilWrite = false;
  4727. this.clippingPlanes = null;
  4728. this.clipIntersection = false;
  4729. this.clipShadows = false;
  4730. this.shadowSide = null;
  4731. this.colorWrite = true;
  4732. this.precision = null; // override the renderer's default precision for this material
  4733. this.polygonOffset = false;
  4734. this.polygonOffsetFactor = 0;
  4735. this.polygonOffsetUnits = 0;
  4736. this.dithering = false;
  4737. this.alphaTest = 0;
  4738. this.alphaToCoverage = false;
  4739. this.premultipliedAlpha = false;
  4740. this.visible = true;
  4741. this.toneMapped = true;
  4742. this.userData = {};
  4743. this.version = 0;
  4744. }
  4745. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  4746. constructor: Material,
  4747. isMaterial: true,
  4748. onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
  4749. customProgramCacheKey: function () {
  4750. return this.onBeforeCompile.toString();
  4751. },
  4752. setValues: function ( 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: function ( 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 && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  4803. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  4804. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  4805. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  4806. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  4807. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  4808. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  4809. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  4810. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  4811. }
  4812. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  4813. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  4814. }
  4815. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  4816. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  4817. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  4818. }
  4819. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  4820. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  4821. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  4822. if ( this.lightMap && this.lightMap.isTexture ) {
  4823. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  4824. data.lightMapIntensity = this.lightMapIntensity;
  4825. }
  4826. if ( this.aoMap && this.aoMap.isTexture ) {
  4827. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  4828. data.aoMapIntensity = this.aoMapIntensity;
  4829. }
  4830. if ( this.bumpMap && this.bumpMap.isTexture ) {
  4831. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  4832. data.bumpScale = this.bumpScale;
  4833. }
  4834. if ( this.normalMap && this.normalMap.isTexture ) {
  4835. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  4836. data.normalMapType = this.normalMapType;
  4837. data.normalScale = this.normalScale.toArray();
  4838. }
  4839. if ( this.displacementMap && this.displacementMap.isTexture ) {
  4840. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  4841. data.displacementScale = this.displacementScale;
  4842. data.displacementBias = this.displacementBias;
  4843. }
  4844. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  4845. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  4846. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  4847. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  4848. if ( this.envMap && this.envMap.isTexture ) {
  4849. data.envMap = this.envMap.toJSON( meta ).uuid;
  4850. data.reflectivity = this.reflectivity; // Scale behind envMap
  4851. data.refractionRatio = this.refractionRatio;
  4852. if ( this.combine !== undefined ) data.combine = this.combine;
  4853. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  4854. }
  4855. if ( this.gradientMap && this.gradientMap.isTexture ) {
  4856. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  4857. }
  4858. if ( this.size !== undefined ) data.size = this.size;
  4859. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  4860. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  4861. if ( this.side !== FrontSide ) data.side = this.side;
  4862. if ( this.vertexColors ) data.vertexColors = true;
  4863. if ( this.opacity < 1 ) data.opacity = this.opacity;
  4864. if ( this.transparent === true ) data.transparent = this.transparent;
  4865. data.depthFunc = this.depthFunc;
  4866. data.depthTest = this.depthTest;
  4867. data.depthWrite = this.depthWrite;
  4868. data.stencilWrite = this.stencilWrite;
  4869. data.stencilWriteMask = this.stencilWriteMask;
  4870. data.stencilFunc = this.stencilFunc;
  4871. data.stencilRef = this.stencilRef;
  4872. data.stencilFuncMask = this.stencilFuncMask;
  4873. data.stencilFail = this.stencilFail;
  4874. data.stencilZFail = this.stencilZFail;
  4875. data.stencilZPass = this.stencilZPass;
  4876. // rotation (SpriteMaterial)
  4877. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  4878. if ( this.polygonOffset === true ) data.polygonOffset = true;
  4879. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  4880. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  4881. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  4882. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  4883. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  4884. if ( this.scale !== undefined ) data.scale = this.scale;
  4885. if ( this.dithering === true ) data.dithering = true;
  4886. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  4887. if ( this.alphaToCoverage === true ) data.alphaToCoverage = this.alphaToCoverage;
  4888. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  4889. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  4890. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  4891. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  4892. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  4893. if ( this.morphTargets === true ) data.morphTargets = true;
  4894. if ( this.morphNormals === true ) data.morphNormals = true;
  4895. if ( this.skinning === true ) data.skinning = true;
  4896. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  4897. if ( this.visible === false ) data.visible = false;
  4898. if ( this.toneMapped === false ) data.toneMapped = false;
  4899. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4900. // TODO: Copied from Object3D.toJSON
  4901. function extractFromCache( cache ) {
  4902. const values = [];
  4903. for ( const key in cache ) {
  4904. const data = cache[ key ];
  4905. delete data.metadata;
  4906. values.push( data );
  4907. }
  4908. return values;
  4909. }
  4910. if ( isRoot ) {
  4911. const textures = extractFromCache( meta.textures );
  4912. const images = extractFromCache( meta.images );
  4913. if ( textures.length > 0 ) data.textures = textures;
  4914. if ( images.length > 0 ) data.images = images;
  4915. }
  4916. return data;
  4917. },
  4918. clone: function () {
  4919. return new this.constructor().copy( this );
  4920. },
  4921. copy: function ( source ) {
  4922. this.name = source.name;
  4923. this.fog = source.fog;
  4924. this.blending = source.blending;
  4925. this.side = source.side;
  4926. this.vertexColors = source.vertexColors;
  4927. this.opacity = source.opacity;
  4928. this.transparent = source.transparent;
  4929. this.blendSrc = source.blendSrc;
  4930. this.blendDst = source.blendDst;
  4931. this.blendEquation = source.blendEquation;
  4932. this.blendSrcAlpha = source.blendSrcAlpha;
  4933. this.blendDstAlpha = source.blendDstAlpha;
  4934. this.blendEquationAlpha = source.blendEquationAlpha;
  4935. this.depthFunc = source.depthFunc;
  4936. this.depthTest = source.depthTest;
  4937. this.depthWrite = source.depthWrite;
  4938. this.stencilWriteMask = source.stencilWriteMask;
  4939. this.stencilFunc = source.stencilFunc;
  4940. this.stencilRef = source.stencilRef;
  4941. this.stencilFuncMask = source.stencilFuncMask;
  4942. this.stencilFail = source.stencilFail;
  4943. this.stencilZFail = source.stencilZFail;
  4944. this.stencilZPass = source.stencilZPass;
  4945. this.stencilWrite = source.stencilWrite;
  4946. const srcPlanes = source.clippingPlanes;
  4947. let dstPlanes = null;
  4948. if ( srcPlanes !== null ) {
  4949. const n = srcPlanes.length;
  4950. dstPlanes = new Array( n );
  4951. for ( let i = 0; i !== n; ++ i ) {
  4952. dstPlanes[ i ] = srcPlanes[ i ].clone();
  4953. }
  4954. }
  4955. this.clippingPlanes = dstPlanes;
  4956. this.clipIntersection = source.clipIntersection;
  4957. this.clipShadows = source.clipShadows;
  4958. this.shadowSide = source.shadowSide;
  4959. this.colorWrite = source.colorWrite;
  4960. this.precision = source.precision;
  4961. this.polygonOffset = source.polygonOffset;
  4962. this.polygonOffsetFactor = source.polygonOffsetFactor;
  4963. this.polygonOffsetUnits = source.polygonOffsetUnits;
  4964. this.dithering = source.dithering;
  4965. this.alphaTest = source.alphaTest;
  4966. this.alphaToCoverage = source.alphaToCoverage;
  4967. this.premultipliedAlpha = source.premultipliedAlpha;
  4968. this.visible = source.visible;
  4969. this.toneMapped = source.toneMapped;
  4970. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4971. return this;
  4972. },
  4973. dispose: function () {
  4974. this.dispatchEvent( { type: 'dispose' } );
  4975. }
  4976. } );
  4977. Object.defineProperty( Material.prototype, 'needsUpdate', {
  4978. set: function ( value ) {
  4979. if ( value === true ) this.version ++;
  4980. }
  4981. } );
  4982. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4983. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4984. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4985. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4986. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4987. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4988. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4989. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4990. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4991. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4992. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4993. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4994. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4995. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4996. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4997. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4998. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4999. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5000. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5001. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5002. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5003. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5004. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5005. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5006. const _hslA = { h: 0, s: 0, l: 0 };
  5007. const _hslB = { h: 0, s: 0, l: 0 };
  5008. function hue2rgb( p, q, t ) {
  5009. if ( t < 0 ) t += 1;
  5010. if ( t > 1 ) t -= 1;
  5011. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5012. if ( t < 1 / 2 ) return q;
  5013. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5014. return p;
  5015. }
  5016. function SRGBToLinear( c ) {
  5017. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  5018. }
  5019. function LinearToSRGB( c ) {
  5020. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  5021. }
  5022. class Color {
  5023. constructor( r, g, b ) {
  5024. if ( g === undefined && b === undefined ) {
  5025. // r is THREE.Color, hex or string
  5026. return this.set( r );
  5027. }
  5028. return this.setRGB( r, g, b );
  5029. }
  5030. set( value ) {
  5031. if ( value && value.isColor ) {
  5032. this.copy( value );
  5033. } else if ( typeof value === 'number' ) {
  5034. this.setHex( value );
  5035. } else if ( typeof value === 'string' ) {
  5036. this.setStyle( value );
  5037. }
  5038. return this;
  5039. }
  5040. setScalar( scalar ) {
  5041. this.r = scalar;
  5042. this.g = scalar;
  5043. this.b = scalar;
  5044. return this;
  5045. }
  5046. setHex( hex ) {
  5047. hex = Math.floor( hex );
  5048. this.r = ( hex >> 16 & 255 ) / 255;
  5049. this.g = ( hex >> 8 & 255 ) / 255;
  5050. this.b = ( hex & 255 ) / 255;
  5051. return this;
  5052. }
  5053. setRGB( r, g, b ) {
  5054. this.r = r;
  5055. this.g = g;
  5056. this.b = b;
  5057. return this;
  5058. }
  5059. setHSL( h, s, l ) {
  5060. // h,s,l ranges are in 0.0 - 1.0
  5061. h = MathUtils.euclideanModulo( h, 1 );
  5062. s = MathUtils.clamp( s, 0, 1 );
  5063. l = MathUtils.clamp( l, 0, 1 );
  5064. if ( s === 0 ) {
  5065. this.r = this.g = this.b = l;
  5066. } else {
  5067. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5068. const q = ( 2 * l ) - p;
  5069. this.r = hue2rgb( q, p, h + 1 / 3 );
  5070. this.g = hue2rgb( q, p, h );
  5071. this.b = hue2rgb( q, p, h - 1 / 3 );
  5072. }
  5073. return this;
  5074. }
  5075. setStyle( style ) {
  5076. function handleAlpha( string ) {
  5077. if ( string === undefined ) return;
  5078. if ( parseFloat( string ) < 1 ) {
  5079. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5080. }
  5081. }
  5082. let m;
  5083. if ( m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec( style ) ) {
  5084. // rgb / hsl
  5085. let color;
  5086. const name = m[ 1 ];
  5087. const components = m[ 2 ];
  5088. switch ( name ) {
  5089. case 'rgb':
  5090. case 'rgba':
  5091. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5092. // rgb(255,0,0) rgba(255,0,0,0.5)
  5093. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  5094. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  5095. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  5096. handleAlpha( color[ 4 ] );
  5097. return this;
  5098. }
  5099. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5100. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5101. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  5102. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  5103. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  5104. handleAlpha( color[ 4 ] );
  5105. return this;
  5106. }
  5107. break;
  5108. case 'hsl':
  5109. case 'hsla':
  5110. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5111. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5112. const h = parseFloat( color[ 1 ] ) / 360;
  5113. const s = parseInt( color[ 2 ], 10 ) / 100;
  5114. const l = parseInt( color[ 3 ], 10 ) / 100;
  5115. handleAlpha( color[ 4 ] );
  5116. return this.setHSL( h, s, l );
  5117. }
  5118. break;
  5119. }
  5120. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5121. // hex color
  5122. const hex = m[ 1 ];
  5123. const size = hex.length;
  5124. if ( size === 3 ) {
  5125. // #ff0
  5126. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  5127. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  5128. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  5129. return this;
  5130. } else if ( size === 6 ) {
  5131. // #ff0000
  5132. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  5133. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  5134. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  5135. return this;
  5136. }
  5137. }
  5138. if ( style && style.length > 0 ) {
  5139. return this.setColorName( style );
  5140. }
  5141. return this;
  5142. }
  5143. setColorName( style ) {
  5144. // color keywords
  5145. const hex = _colorKeywords[ style ];
  5146. if ( hex !== undefined ) {
  5147. // red
  5148. this.setHex( hex );
  5149. } else {
  5150. // unknown color
  5151. console.warn( 'THREE.Color: Unknown color ' + style );
  5152. }
  5153. return this;
  5154. }
  5155. clone() {
  5156. return new this.constructor( this.r, this.g, this.b );
  5157. }
  5158. copy( color ) {
  5159. this.r = color.r;
  5160. this.g = color.g;
  5161. this.b = color.b;
  5162. return this;
  5163. }
  5164. copyGammaToLinear( color, gammaFactor = 2.0 ) {
  5165. this.r = Math.pow( color.r, gammaFactor );
  5166. this.g = Math.pow( color.g, gammaFactor );
  5167. this.b = Math.pow( color.b, gammaFactor );
  5168. return this;
  5169. }
  5170. copyLinearToGamma( color, gammaFactor = 2.0 ) {
  5171. const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5172. this.r = Math.pow( color.r, safeInverse );
  5173. this.g = Math.pow( color.g, safeInverse );
  5174. this.b = Math.pow( color.b, safeInverse );
  5175. return this;
  5176. }
  5177. convertGammaToLinear( gammaFactor ) {
  5178. this.copyGammaToLinear( this, gammaFactor );
  5179. return this;
  5180. }
  5181. convertLinearToGamma( gammaFactor ) {
  5182. this.copyLinearToGamma( this, gammaFactor );
  5183. return this;
  5184. }
  5185. copySRGBToLinear( color ) {
  5186. this.r = SRGBToLinear( color.r );
  5187. this.g = SRGBToLinear( color.g );
  5188. this.b = SRGBToLinear( color.b );
  5189. return this;
  5190. }
  5191. copyLinearToSRGB( color ) {
  5192. this.r = LinearToSRGB( color.r );
  5193. this.g = LinearToSRGB( color.g );
  5194. this.b = LinearToSRGB( color.b );
  5195. return this;
  5196. }
  5197. convertSRGBToLinear() {
  5198. this.copySRGBToLinear( this );
  5199. return this;
  5200. }
  5201. convertLinearToSRGB() {
  5202. this.copyLinearToSRGB( this );
  5203. return this;
  5204. }
  5205. getHex() {
  5206. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5207. }
  5208. getHexString() {
  5209. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5210. }
  5211. getHSL( target ) {
  5212. // h,s,l ranges are in 0.0 - 1.0
  5213. if ( target === undefined ) {
  5214. console.warn( 'THREE.Color: .getHSL() target is now required' );
  5215. target = { h: 0, s: 0, l: 0 };
  5216. }
  5217. const r = this.r, g = this.g, b = this.b;
  5218. const max = Math.max( r, g, b );
  5219. const min = Math.min( r, g, b );
  5220. let hue, saturation;
  5221. const lightness = ( min + max ) / 2.0;
  5222. if ( min === max ) {
  5223. hue = 0;
  5224. saturation = 0;
  5225. } else {
  5226. const delta = max - min;
  5227. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5228. switch ( max ) {
  5229. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5230. case g: hue = ( b - r ) / delta + 2; break;
  5231. case b: hue = ( r - g ) / delta + 4; break;
  5232. }
  5233. hue /= 6;
  5234. }
  5235. target.h = hue;
  5236. target.s = saturation;
  5237. target.l = lightness;
  5238. return target;
  5239. }
  5240. getStyle() {
  5241. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5242. }
  5243. offsetHSL( h, s, l ) {
  5244. this.getHSL( _hslA );
  5245. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  5246. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  5247. return this;
  5248. }
  5249. add( color ) {
  5250. this.r += color.r;
  5251. this.g += color.g;
  5252. this.b += color.b;
  5253. return this;
  5254. }
  5255. addColors( color1, color2 ) {
  5256. this.r = color1.r + color2.r;
  5257. this.g = color1.g + color2.g;
  5258. this.b = color1.b + color2.b;
  5259. return this;
  5260. }
  5261. addScalar( s ) {
  5262. this.r += s;
  5263. this.g += s;
  5264. this.b += s;
  5265. return this;
  5266. }
  5267. sub( color ) {
  5268. this.r = Math.max( 0, this.r - color.r );
  5269. this.g = Math.max( 0, this.g - color.g );
  5270. this.b = Math.max( 0, this.b - color.b );
  5271. return this;
  5272. }
  5273. multiply( color ) {
  5274. this.r *= color.r;
  5275. this.g *= color.g;
  5276. this.b *= color.b;
  5277. return this;
  5278. }
  5279. multiplyScalar( s ) {
  5280. this.r *= s;
  5281. this.g *= s;
  5282. this.b *= s;
  5283. return this;
  5284. }
  5285. lerp( color, alpha ) {
  5286. this.r += ( color.r - this.r ) * alpha;
  5287. this.g += ( color.g - this.g ) * alpha;
  5288. this.b += ( color.b - this.b ) * alpha;
  5289. return this;
  5290. }
  5291. lerpColors( color1, color2, alpha ) {
  5292. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5293. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5294. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5295. return this;
  5296. }
  5297. lerpHSL( color, alpha ) {
  5298. this.getHSL( _hslA );
  5299. color.getHSL( _hslB );
  5300. const h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  5301. const s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  5302. const l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  5303. this.setHSL( h, s, l );
  5304. return this;
  5305. }
  5306. equals( c ) {
  5307. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5308. }
  5309. fromArray( array, offset = 0 ) {
  5310. this.r = array[ offset ];
  5311. this.g = array[ offset + 1 ];
  5312. this.b = array[ offset + 2 ];
  5313. return this;
  5314. }
  5315. toArray( array = [], offset = 0 ) {
  5316. array[ offset ] = this.r;
  5317. array[ offset + 1 ] = this.g;
  5318. array[ offset + 2 ] = this.b;
  5319. return array;
  5320. }
  5321. fromBufferAttribute( attribute, index ) {
  5322. this.r = attribute.getX( index );
  5323. this.g = attribute.getY( index );
  5324. this.b = attribute.getZ( index );
  5325. if ( attribute.normalized === true ) {
  5326. // assuming Uint8Array
  5327. this.r /= 255;
  5328. this.g /= 255;
  5329. this.b /= 255;
  5330. }
  5331. return this;
  5332. }
  5333. toJSON() {
  5334. return this.getHex();
  5335. }
  5336. }
  5337. Color.NAMES = _colorKeywords;
  5338. Color.prototype.isColor = true;
  5339. Color.prototype.r = 1;
  5340. Color.prototype.g = 1;
  5341. Color.prototype.b = 1;
  5342. /**
  5343. * parameters = {
  5344. * color: <hex>,
  5345. * opacity: <float>,
  5346. * map: new THREE.Texture( <Image> ),
  5347. *
  5348. * lightMap: new THREE.Texture( <Image> ),
  5349. * lightMapIntensity: <float>
  5350. *
  5351. * aoMap: new THREE.Texture( <Image> ),
  5352. * aoMapIntensity: <float>
  5353. *
  5354. * specularMap: new THREE.Texture( <Image> ),
  5355. *
  5356. * alphaMap: new THREE.Texture( <Image> ),
  5357. *
  5358. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5359. * combine: THREE.Multiply,
  5360. * reflectivity: <float>,
  5361. * refractionRatio: <float>,
  5362. *
  5363. * depthTest: <bool>,
  5364. * depthWrite: <bool>,
  5365. *
  5366. * wireframe: <boolean>,
  5367. * wireframeLinewidth: <float>,
  5368. *
  5369. * skinning: <bool>,
  5370. * morphTargets: <bool>
  5371. * }
  5372. */
  5373. class MeshBasicMaterial extends Material {
  5374. constructor( parameters ) {
  5375. super();
  5376. this.type = 'MeshBasicMaterial';
  5377. this.color = new Color( 0xffffff ); // emissive
  5378. this.map = null;
  5379. this.lightMap = null;
  5380. this.lightMapIntensity = 1.0;
  5381. this.aoMap = null;
  5382. this.aoMapIntensity = 1.0;
  5383. this.specularMap = null;
  5384. this.alphaMap = null;
  5385. this.envMap = null;
  5386. this.combine = MultiplyOperation;
  5387. this.reflectivity = 1;
  5388. this.refractionRatio = 0.98;
  5389. this.wireframe = false;
  5390. this.wireframeLinewidth = 1;
  5391. this.wireframeLinecap = 'round';
  5392. this.wireframeLinejoin = 'round';
  5393. this.skinning = false;
  5394. this.morphTargets = false;
  5395. this.setValues( parameters );
  5396. }
  5397. copy( source ) {
  5398. super.copy( source );
  5399. this.color.copy( source.color );
  5400. this.map = source.map;
  5401. this.lightMap = source.lightMap;
  5402. this.lightMapIntensity = source.lightMapIntensity;
  5403. this.aoMap = source.aoMap;
  5404. this.aoMapIntensity = source.aoMapIntensity;
  5405. this.specularMap = source.specularMap;
  5406. this.alphaMap = source.alphaMap;
  5407. this.envMap = source.envMap;
  5408. this.combine = source.combine;
  5409. this.reflectivity = source.reflectivity;
  5410. this.refractionRatio = source.refractionRatio;
  5411. this.wireframe = source.wireframe;
  5412. this.wireframeLinewidth = source.wireframeLinewidth;
  5413. this.wireframeLinecap = source.wireframeLinecap;
  5414. this.wireframeLinejoin = source.wireframeLinejoin;
  5415. this.skinning = source.skinning;
  5416. this.morphTargets = source.morphTargets;
  5417. return this;
  5418. }
  5419. }
  5420. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5421. const _vector$3 = new Vector3();
  5422. const _vector2$1 = new Vector2();
  5423. function BufferAttribute( array, itemSize, normalized ) {
  5424. if ( Array.isArray( array ) ) {
  5425. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5426. }
  5427. this.name = '';
  5428. this.array = array;
  5429. this.itemSize = itemSize;
  5430. this.count = array !== undefined ? array.length / itemSize : 0;
  5431. this.normalized = normalized === true;
  5432. this.usage = StaticDrawUsage;
  5433. this.updateRange = { offset: 0, count: - 1 };
  5434. this.version = 0;
  5435. }
  5436. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5437. set: function ( value ) {
  5438. if ( value === true ) this.version ++;
  5439. }
  5440. } );
  5441. Object.assign( BufferAttribute.prototype, {
  5442. isBufferAttribute: true,
  5443. onUploadCallback: function () {},
  5444. setUsage: function ( value ) {
  5445. this.usage = value;
  5446. return this;
  5447. },
  5448. copy: function ( source ) {
  5449. this.name = source.name;
  5450. this.array = new source.array.constructor( source.array );
  5451. this.itemSize = source.itemSize;
  5452. this.count = source.count;
  5453. this.normalized = source.normalized;
  5454. this.usage = source.usage;
  5455. return this;
  5456. },
  5457. copyAt: function ( index1, attribute, index2 ) {
  5458. index1 *= this.itemSize;
  5459. index2 *= attribute.itemSize;
  5460. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  5461. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5462. }
  5463. return this;
  5464. },
  5465. copyArray: function ( array ) {
  5466. this.array.set( array );
  5467. return this;
  5468. },
  5469. copyColorsArray: function ( colors ) {
  5470. const array = this.array;
  5471. let offset = 0;
  5472. for ( let i = 0, l = colors.length; i < l; i ++ ) {
  5473. let color = colors[ i ];
  5474. if ( color === undefined ) {
  5475. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5476. color = new Color();
  5477. }
  5478. array[ offset ++ ] = color.r;
  5479. array[ offset ++ ] = color.g;
  5480. array[ offset ++ ] = color.b;
  5481. }
  5482. return this;
  5483. },
  5484. copyVector2sArray: function ( vectors ) {
  5485. const array = this.array;
  5486. let offset = 0;
  5487. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5488. let vector = vectors[ i ];
  5489. if ( vector === undefined ) {
  5490. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5491. vector = new Vector2();
  5492. }
  5493. array[ offset ++ ] = vector.x;
  5494. array[ offset ++ ] = vector.y;
  5495. }
  5496. return this;
  5497. },
  5498. copyVector3sArray: function ( vectors ) {
  5499. const array = this.array;
  5500. let offset = 0;
  5501. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5502. let vector = vectors[ i ];
  5503. if ( vector === undefined ) {
  5504. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5505. vector = new Vector3();
  5506. }
  5507. array[ offset ++ ] = vector.x;
  5508. array[ offset ++ ] = vector.y;
  5509. array[ offset ++ ] = vector.z;
  5510. }
  5511. return this;
  5512. },
  5513. copyVector4sArray: function ( vectors ) {
  5514. const array = this.array;
  5515. let offset = 0;
  5516. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5517. let vector = vectors[ i ];
  5518. if ( vector === undefined ) {
  5519. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5520. vector = new Vector4();
  5521. }
  5522. array[ offset ++ ] = vector.x;
  5523. array[ offset ++ ] = vector.y;
  5524. array[ offset ++ ] = vector.z;
  5525. array[ offset ++ ] = vector.w;
  5526. }
  5527. return this;
  5528. },
  5529. applyMatrix3: function ( m ) {
  5530. if ( this.itemSize === 2 ) {
  5531. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5532. _vector2$1.fromBufferAttribute( this, i );
  5533. _vector2$1.applyMatrix3( m );
  5534. this.setXY( i, _vector2$1.x, _vector2$1.y );
  5535. }
  5536. } else if ( this.itemSize === 3 ) {
  5537. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5538. _vector$3.fromBufferAttribute( this, i );
  5539. _vector$3.applyMatrix3( m );
  5540. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5541. }
  5542. }
  5543. return this;
  5544. },
  5545. applyMatrix4: function ( m ) {
  5546. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5547. _vector$3.x = this.getX( i );
  5548. _vector$3.y = this.getY( i );
  5549. _vector$3.z = this.getZ( i );
  5550. _vector$3.applyMatrix4( m );
  5551. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5552. }
  5553. return this;
  5554. },
  5555. applyNormalMatrix: function ( m ) {
  5556. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5557. _vector$3.x = this.getX( i );
  5558. _vector$3.y = this.getY( i );
  5559. _vector$3.z = this.getZ( i );
  5560. _vector$3.applyNormalMatrix( m );
  5561. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5562. }
  5563. return this;
  5564. },
  5565. transformDirection: function ( m ) {
  5566. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5567. _vector$3.x = this.getX( i );
  5568. _vector$3.y = this.getY( i );
  5569. _vector$3.z = this.getZ( i );
  5570. _vector$3.transformDirection( m );
  5571. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5572. }
  5573. return this;
  5574. },
  5575. set: function ( value, offset = 0 ) {
  5576. this.array.set( value, offset );
  5577. return this;
  5578. },
  5579. getX: function ( index ) {
  5580. return this.array[ index * this.itemSize ];
  5581. },
  5582. setX: function ( index, x ) {
  5583. this.array[ index * this.itemSize ] = x;
  5584. return this;
  5585. },
  5586. getY: function ( index ) {
  5587. return this.array[ index * this.itemSize + 1 ];
  5588. },
  5589. setY: function ( index, y ) {
  5590. this.array[ index * this.itemSize + 1 ] = y;
  5591. return this;
  5592. },
  5593. getZ: function ( index ) {
  5594. return this.array[ index * this.itemSize + 2 ];
  5595. },
  5596. setZ: function ( index, z ) {
  5597. this.array[ index * this.itemSize + 2 ] = z;
  5598. return this;
  5599. },
  5600. getW: function ( index ) {
  5601. return this.array[ index * this.itemSize + 3 ];
  5602. },
  5603. setW: function ( index, w ) {
  5604. this.array[ index * this.itemSize + 3 ] = w;
  5605. return this;
  5606. },
  5607. setXY: function ( index, x, y ) {
  5608. index *= this.itemSize;
  5609. this.array[ index + 0 ] = x;
  5610. this.array[ index + 1 ] = y;
  5611. return this;
  5612. },
  5613. setXYZ: function ( index, x, y, z ) {
  5614. index *= this.itemSize;
  5615. this.array[ index + 0 ] = x;
  5616. this.array[ index + 1 ] = y;
  5617. this.array[ index + 2 ] = z;
  5618. return this;
  5619. },
  5620. setXYZW: function ( index, x, y, z, w ) {
  5621. index *= this.itemSize;
  5622. this.array[ index + 0 ] = x;
  5623. this.array[ index + 1 ] = y;
  5624. this.array[ index + 2 ] = z;
  5625. this.array[ index + 3 ] = w;
  5626. return this;
  5627. },
  5628. onUpload: function ( callback ) {
  5629. this.onUploadCallback = callback;
  5630. return this;
  5631. },
  5632. clone: function () {
  5633. return new this.constructor( this.array, this.itemSize ).copy( this );
  5634. },
  5635. toJSON: function () {
  5636. return {
  5637. itemSize: this.itemSize,
  5638. type: this.array.constructor.name,
  5639. array: Array.prototype.slice.call( this.array ),
  5640. normalized: this.normalized
  5641. };
  5642. }
  5643. } );
  5644. //
  5645. function Int8BufferAttribute( array, itemSize, normalized ) {
  5646. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5647. }
  5648. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5649. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5650. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5651. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5652. }
  5653. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5654. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5655. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5656. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5657. }
  5658. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5659. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5660. function Int16BufferAttribute( array, itemSize, normalized ) {
  5661. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5662. }
  5663. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5664. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5665. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5666. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5667. }
  5668. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5669. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5670. function Int32BufferAttribute( array, itemSize, normalized ) {
  5671. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5672. }
  5673. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5674. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5675. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5676. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5677. }
  5678. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5679. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5680. function Float16BufferAttribute( array, itemSize, normalized ) {
  5681. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5682. }
  5683. Float16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5684. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  5685. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  5686. function Float32BufferAttribute( array, itemSize, normalized ) {
  5687. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5688. }
  5689. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5690. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5691. function Float64BufferAttribute( array, itemSize, normalized ) {
  5692. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5693. }
  5694. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5695. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5696. function arrayMax( array ) {
  5697. if ( array.length === 0 ) return - Infinity;
  5698. let max = array[ 0 ];
  5699. for ( let i = 1, l = array.length; i < l; ++ i ) {
  5700. if ( array[ i ] > max ) max = array[ i ];
  5701. }
  5702. return max;
  5703. }
  5704. const TYPED_ARRAYS = {
  5705. Int8Array: Int8Array,
  5706. Uint8Array: Uint8Array,
  5707. Uint8ClampedArray: Uint8ClampedArray,
  5708. Int16Array: Int16Array,
  5709. Uint16Array: Uint16Array,
  5710. Int32Array: Int32Array,
  5711. Uint32Array: Uint32Array,
  5712. Float32Array: Float32Array,
  5713. Float64Array: Float64Array
  5714. };
  5715. function getTypedArray( type, buffer ) {
  5716. return new TYPED_ARRAYS[ type ]( buffer );
  5717. }
  5718. let _id = 0;
  5719. const _m1$2 = new Matrix4();
  5720. const _obj = new Object3D();
  5721. const _offset = new Vector3();
  5722. const _box$2 = new Box3();
  5723. const _boxMorphTargets = new Box3();
  5724. const _vector$4 = new Vector3();
  5725. function BufferGeometry() {
  5726. Object.defineProperty( this, 'id', { value: _id ++ } );
  5727. this.uuid = MathUtils.generateUUID();
  5728. this.name = '';
  5729. this.type = 'BufferGeometry';
  5730. this.index = null;
  5731. this.attributes = {};
  5732. this.morphAttributes = {};
  5733. this.morphTargetsRelative = false;
  5734. this.groups = [];
  5735. this.boundingBox = null;
  5736. this.boundingSphere = null;
  5737. this.drawRange = { start: 0, count: Infinity };
  5738. this.userData = {};
  5739. }
  5740. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5741. constructor: BufferGeometry,
  5742. isBufferGeometry: true,
  5743. getIndex: function () {
  5744. return this.index;
  5745. },
  5746. setIndex: function ( index ) {
  5747. if ( Array.isArray( index ) ) {
  5748. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5749. } else {
  5750. this.index = index;
  5751. }
  5752. return this;
  5753. },
  5754. getAttribute: function ( name ) {
  5755. return this.attributes[ name ];
  5756. },
  5757. setAttribute: function ( name, attribute ) {
  5758. this.attributes[ name ] = attribute;
  5759. return this;
  5760. },
  5761. deleteAttribute: function ( name ) {
  5762. delete this.attributes[ name ];
  5763. return this;
  5764. },
  5765. hasAttribute: function ( name ) {
  5766. return this.attributes[ name ] !== undefined;
  5767. },
  5768. addGroup: function ( start, count, materialIndex = 0 ) {
  5769. this.groups.push( {
  5770. start: start,
  5771. count: count,
  5772. materialIndex: materialIndex
  5773. } );
  5774. },
  5775. clearGroups: function () {
  5776. this.groups = [];
  5777. },
  5778. setDrawRange: function ( start, count ) {
  5779. this.drawRange.start = start;
  5780. this.drawRange.count = count;
  5781. },
  5782. applyMatrix4: function ( matrix ) {
  5783. const position = this.attributes.position;
  5784. if ( position !== undefined ) {
  5785. position.applyMatrix4( matrix );
  5786. position.needsUpdate = true;
  5787. }
  5788. const normal = this.attributes.normal;
  5789. if ( normal !== undefined ) {
  5790. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5791. normal.applyNormalMatrix( normalMatrix );
  5792. normal.needsUpdate = true;
  5793. }
  5794. const tangent = this.attributes.tangent;
  5795. if ( tangent !== undefined ) {
  5796. tangent.transformDirection( matrix );
  5797. tangent.needsUpdate = true;
  5798. }
  5799. if ( this.boundingBox !== null ) {
  5800. this.computeBoundingBox();
  5801. }
  5802. if ( this.boundingSphere !== null ) {
  5803. this.computeBoundingSphere();
  5804. }
  5805. return this;
  5806. },
  5807. rotateX: function ( angle ) {
  5808. // rotate geometry around world x-axis
  5809. _m1$2.makeRotationX( angle );
  5810. this.applyMatrix4( _m1$2 );
  5811. return this;
  5812. },
  5813. rotateY: function ( angle ) {
  5814. // rotate geometry around world y-axis
  5815. _m1$2.makeRotationY( angle );
  5816. this.applyMatrix4( _m1$2 );
  5817. return this;
  5818. },
  5819. rotateZ: function ( angle ) {
  5820. // rotate geometry around world z-axis
  5821. _m1$2.makeRotationZ( angle );
  5822. this.applyMatrix4( _m1$2 );
  5823. return this;
  5824. },
  5825. translate: function ( x, y, z ) {
  5826. // translate geometry
  5827. _m1$2.makeTranslation( x, y, z );
  5828. this.applyMatrix4( _m1$2 );
  5829. return this;
  5830. },
  5831. scale: function ( x, y, z ) {
  5832. // scale geometry
  5833. _m1$2.makeScale( x, y, z );
  5834. this.applyMatrix4( _m1$2 );
  5835. return this;
  5836. },
  5837. lookAt: function ( vector ) {
  5838. _obj.lookAt( vector );
  5839. _obj.updateMatrix();
  5840. this.applyMatrix4( _obj.matrix );
  5841. return this;
  5842. },
  5843. center: function () {
  5844. this.computeBoundingBox();
  5845. this.boundingBox.getCenter( _offset ).negate();
  5846. this.translate( _offset.x, _offset.y, _offset.z );
  5847. return this;
  5848. },
  5849. setFromPoints: function ( points ) {
  5850. const position = [];
  5851. for ( let i = 0, l = points.length; i < l; i ++ ) {
  5852. const point = points[ i ];
  5853. position.push( point.x, point.y, point.z || 0 );
  5854. }
  5855. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5856. return this;
  5857. },
  5858. computeBoundingBox: function () {
  5859. if ( this.boundingBox === null ) {
  5860. this.boundingBox = new Box3();
  5861. }
  5862. const position = this.attributes.position;
  5863. const morphAttributesPosition = this.morphAttributes.position;
  5864. if ( position && position.isGLBufferAttribute ) {
  5865. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this );
  5866. this.boundingBox.set(
  5867. new Vector3( - Infinity, - Infinity, - Infinity ),
  5868. new Vector3( + Infinity, + Infinity, + Infinity )
  5869. );
  5870. return;
  5871. }
  5872. if ( position !== undefined ) {
  5873. this.boundingBox.setFromBufferAttribute( position );
  5874. // process morph attributes if present
  5875. if ( morphAttributesPosition ) {
  5876. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5877. const morphAttribute = morphAttributesPosition[ i ];
  5878. _box$2.setFromBufferAttribute( morphAttribute );
  5879. if ( this.morphTargetsRelative ) {
  5880. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  5881. this.boundingBox.expandByPoint( _vector$4 );
  5882. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  5883. this.boundingBox.expandByPoint( _vector$4 );
  5884. } else {
  5885. this.boundingBox.expandByPoint( _box$2.min );
  5886. this.boundingBox.expandByPoint( _box$2.max );
  5887. }
  5888. }
  5889. }
  5890. } else {
  5891. this.boundingBox.makeEmpty();
  5892. }
  5893. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  5894. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  5895. }
  5896. },
  5897. computeBoundingSphere: function () {
  5898. if ( this.boundingSphere === null ) {
  5899. this.boundingSphere = new Sphere();
  5900. }
  5901. const position = this.attributes.position;
  5902. const morphAttributesPosition = this.morphAttributes.position;
  5903. if ( position && position.isGLBufferAttribute ) {
  5904. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this );
  5905. this.boundingSphere.set( new Vector3(), Infinity );
  5906. return;
  5907. }
  5908. if ( position ) {
  5909. // first, find the center of the bounding sphere
  5910. const center = this.boundingSphere.center;
  5911. _box$2.setFromBufferAttribute( position );
  5912. // process morph attributes if present
  5913. if ( morphAttributesPosition ) {
  5914. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5915. const morphAttribute = morphAttributesPosition[ i ];
  5916. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  5917. if ( this.morphTargetsRelative ) {
  5918. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  5919. _box$2.expandByPoint( _vector$4 );
  5920. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  5921. _box$2.expandByPoint( _vector$4 );
  5922. } else {
  5923. _box$2.expandByPoint( _boxMorphTargets.min );
  5924. _box$2.expandByPoint( _boxMorphTargets.max );
  5925. }
  5926. }
  5927. }
  5928. _box$2.getCenter( center );
  5929. // second, try to find a boundingSphere with a radius smaller than the
  5930. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  5931. let maxRadiusSq = 0;
  5932. for ( let i = 0, il = position.count; i < il; i ++ ) {
  5933. _vector$4.fromBufferAttribute( position, i );
  5934. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  5935. }
  5936. // process morph attributes if present
  5937. if ( morphAttributesPosition ) {
  5938. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  5939. const morphAttribute = morphAttributesPosition[ i ];
  5940. const morphTargetsRelative = this.morphTargetsRelative;
  5941. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  5942. _vector$4.fromBufferAttribute( morphAttribute, j );
  5943. if ( morphTargetsRelative ) {
  5944. _offset.fromBufferAttribute( position, j );
  5945. _vector$4.add( _offset );
  5946. }
  5947. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  5948. }
  5949. }
  5950. }
  5951. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  5952. if ( isNaN( this.boundingSphere.radius ) ) {
  5953. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  5954. }
  5955. }
  5956. },
  5957. computeFaceNormals: function () {
  5958. // backwards compatibility
  5959. },
  5960. computeTangents: function () {
  5961. const index = this.index;
  5962. const attributes = this.attributes;
  5963. // based on http://www.terathon.com/code/tangent.html
  5964. // (per vertex tangents)
  5965. if ( index === null ||
  5966. attributes.position === undefined ||
  5967. attributes.normal === undefined ||
  5968. attributes.uv === undefined ) {
  5969. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  5970. return;
  5971. }
  5972. const indices = index.array;
  5973. const positions = attributes.position.array;
  5974. const normals = attributes.normal.array;
  5975. const uvs = attributes.uv.array;
  5976. const nVertices = positions.length / 3;
  5977. if ( attributes.tangent === undefined ) {
  5978. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  5979. }
  5980. const tangents = attributes.tangent.array;
  5981. const tan1 = [], tan2 = [];
  5982. for ( let i = 0; i < nVertices; i ++ ) {
  5983. tan1[ i ] = new Vector3();
  5984. tan2[ i ] = new Vector3();
  5985. }
  5986. const vA = new Vector3(),
  5987. vB = new Vector3(),
  5988. vC = new Vector3(),
  5989. uvA = new Vector2(),
  5990. uvB = new Vector2(),
  5991. uvC = new Vector2(),
  5992. sdir = new Vector3(),
  5993. tdir = new Vector3();
  5994. function handleTriangle( a, b, c ) {
  5995. vA.fromArray( positions, a * 3 );
  5996. vB.fromArray( positions, b * 3 );
  5997. vC.fromArray( positions, c * 3 );
  5998. uvA.fromArray( uvs, a * 2 );
  5999. uvB.fromArray( uvs, b * 2 );
  6000. uvC.fromArray( uvs, c * 2 );
  6001. vB.sub( vA );
  6002. vC.sub( vA );
  6003. uvB.sub( uvA );
  6004. uvC.sub( uvA );
  6005. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6006. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6007. if ( ! isFinite( r ) ) return;
  6008. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6009. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6010. tan1[ a ].add( sdir );
  6011. tan1[ b ].add( sdir );
  6012. tan1[ c ].add( sdir );
  6013. tan2[ a ].add( tdir );
  6014. tan2[ b ].add( tdir );
  6015. tan2[ c ].add( tdir );
  6016. }
  6017. let groups = this.groups;
  6018. if ( groups.length === 0 ) {
  6019. groups = [ {
  6020. start: 0,
  6021. count: indices.length
  6022. } ];
  6023. }
  6024. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6025. const group = groups[ i ];
  6026. const start = group.start;
  6027. const count = group.count;
  6028. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6029. handleTriangle(
  6030. indices[ j + 0 ],
  6031. indices[ j + 1 ],
  6032. indices[ j + 2 ]
  6033. );
  6034. }
  6035. }
  6036. const tmp = new Vector3(), tmp2 = new Vector3();
  6037. const n = new Vector3(), n2 = new Vector3();
  6038. function handleVertex( v ) {
  6039. n.fromArray( normals, v * 3 );
  6040. n2.copy( n );
  6041. const t = tan1[ v ];
  6042. // Gram-Schmidt orthogonalize
  6043. tmp.copy( t );
  6044. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6045. // Calculate handedness
  6046. tmp2.crossVectors( n2, t );
  6047. const test = tmp2.dot( tan2[ v ] );
  6048. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6049. tangents[ v * 4 ] = tmp.x;
  6050. tangents[ v * 4 + 1 ] = tmp.y;
  6051. tangents[ v * 4 + 2 ] = tmp.z;
  6052. tangents[ v * 4 + 3 ] = w;
  6053. }
  6054. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6055. const group = groups[ i ];
  6056. const start = group.start;
  6057. const count = group.count;
  6058. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6059. handleVertex( indices[ j + 0 ] );
  6060. handleVertex( indices[ j + 1 ] );
  6061. handleVertex( indices[ j + 2 ] );
  6062. }
  6063. }
  6064. },
  6065. computeVertexNormals: function () {
  6066. const index = this.index;
  6067. const positionAttribute = this.getAttribute( 'position' );
  6068. if ( positionAttribute !== undefined ) {
  6069. let normalAttribute = this.getAttribute( 'normal' );
  6070. if ( normalAttribute === undefined ) {
  6071. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6072. this.setAttribute( 'normal', normalAttribute );
  6073. } else {
  6074. // reset existing normals to zero
  6075. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6076. normalAttribute.setXYZ( i, 0, 0, 0 );
  6077. }
  6078. }
  6079. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6080. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6081. const cb = new Vector3(), ab = new Vector3();
  6082. // indexed elements
  6083. if ( index ) {
  6084. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6085. const vA = index.getX( i + 0 );
  6086. const vB = index.getX( i + 1 );
  6087. const vC = index.getX( i + 2 );
  6088. pA.fromBufferAttribute( positionAttribute, vA );
  6089. pB.fromBufferAttribute( positionAttribute, vB );
  6090. pC.fromBufferAttribute( positionAttribute, vC );
  6091. cb.subVectors( pC, pB );
  6092. ab.subVectors( pA, pB );
  6093. cb.cross( ab );
  6094. nA.fromBufferAttribute( normalAttribute, vA );
  6095. nB.fromBufferAttribute( normalAttribute, vB );
  6096. nC.fromBufferAttribute( normalAttribute, vC );
  6097. nA.add( cb );
  6098. nB.add( cb );
  6099. nC.add( cb );
  6100. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6101. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6102. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6103. }
  6104. } else {
  6105. // non-indexed elements (unconnected triangle soup)
  6106. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6107. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6108. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6109. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6110. cb.subVectors( pC, pB );
  6111. ab.subVectors( pA, pB );
  6112. cb.cross( ab );
  6113. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6114. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6115. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6116. }
  6117. }
  6118. this.normalizeNormals();
  6119. normalAttribute.needsUpdate = true;
  6120. }
  6121. },
  6122. merge: function ( geometry, offset ) {
  6123. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6124. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6125. return;
  6126. }
  6127. if ( offset === undefined ) {
  6128. offset = 0;
  6129. console.warn(
  6130. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6131. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6132. );
  6133. }
  6134. const attributes = this.attributes;
  6135. for ( const key in attributes ) {
  6136. if ( geometry.attributes[ key ] === undefined ) continue;
  6137. const attribute1 = attributes[ key ];
  6138. const attributeArray1 = attribute1.array;
  6139. const attribute2 = geometry.attributes[ key ];
  6140. const attributeArray2 = attribute2.array;
  6141. const attributeOffset = attribute2.itemSize * offset;
  6142. const length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6143. for ( let i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6144. attributeArray1[ j ] = attributeArray2[ i ];
  6145. }
  6146. }
  6147. return this;
  6148. },
  6149. normalizeNormals: function () {
  6150. const normals = this.attributes.normal;
  6151. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6152. _vector$4.fromBufferAttribute( normals, i );
  6153. _vector$4.normalize();
  6154. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6155. }
  6156. },
  6157. toNonIndexed: function () {
  6158. function convertBufferAttribute( attribute, indices ) {
  6159. const array = attribute.array;
  6160. const itemSize = attribute.itemSize;
  6161. const normalized = attribute.normalized;
  6162. const array2 = new array.constructor( indices.length * itemSize );
  6163. let index = 0, index2 = 0;
  6164. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6165. index = indices[ i ] * itemSize;
  6166. for ( let j = 0; j < itemSize; j ++ ) {
  6167. array2[ index2 ++ ] = array[ index ++ ];
  6168. }
  6169. }
  6170. return new BufferAttribute( array2, itemSize, normalized );
  6171. }
  6172. //
  6173. if ( this.index === null ) {
  6174. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6175. return this;
  6176. }
  6177. const geometry2 = new BufferGeometry();
  6178. const indices = this.index.array;
  6179. const attributes = this.attributes;
  6180. // attributes
  6181. for ( const name in attributes ) {
  6182. const attribute = attributes[ name ];
  6183. const newAttribute = convertBufferAttribute( attribute, indices );
  6184. geometry2.setAttribute( name, newAttribute );
  6185. }
  6186. // morph attributes
  6187. const morphAttributes = this.morphAttributes;
  6188. for ( const name in morphAttributes ) {
  6189. const morphArray = [];
  6190. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6191. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6192. const attribute = morphAttribute[ i ];
  6193. const newAttribute = convertBufferAttribute( attribute, indices );
  6194. morphArray.push( newAttribute );
  6195. }
  6196. geometry2.morphAttributes[ name ] = morphArray;
  6197. }
  6198. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6199. // groups
  6200. const groups = this.groups;
  6201. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6202. const group = groups[ i ];
  6203. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6204. }
  6205. return geometry2;
  6206. },
  6207. toJSON: function () {
  6208. const data = {
  6209. metadata: {
  6210. version: 4.5,
  6211. type: 'BufferGeometry',
  6212. generator: 'BufferGeometry.toJSON'
  6213. }
  6214. };
  6215. // standard BufferGeometry serialization
  6216. data.uuid = this.uuid;
  6217. data.type = this.type;
  6218. if ( this.name !== '' ) data.name = this.name;
  6219. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6220. if ( this.parameters !== undefined ) {
  6221. const parameters = this.parameters;
  6222. for ( const key in parameters ) {
  6223. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6224. }
  6225. return data;
  6226. }
  6227. data.data = { attributes: {} };
  6228. const index = this.index;
  6229. if ( index !== null ) {
  6230. data.data.index = {
  6231. type: index.array.constructor.name,
  6232. array: Array.prototype.slice.call( index.array )
  6233. };
  6234. }
  6235. const attributes = this.attributes;
  6236. for ( const key in attributes ) {
  6237. const attribute = attributes[ key ];
  6238. const attributeData = attribute.toJSON( data.data );
  6239. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6240. data.data.attributes[ key ] = attributeData;
  6241. }
  6242. const morphAttributes = {};
  6243. let hasMorphAttributes = false;
  6244. for ( const key in this.morphAttributes ) {
  6245. const attributeArray = this.morphAttributes[ key ];
  6246. const array = [];
  6247. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6248. const attribute = attributeArray[ i ];
  6249. const attributeData = attribute.toJSON( data.data );
  6250. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6251. array.push( attributeData );
  6252. }
  6253. if ( array.length > 0 ) {
  6254. morphAttributes[ key ] = array;
  6255. hasMorphAttributes = true;
  6256. }
  6257. }
  6258. if ( hasMorphAttributes ) {
  6259. data.data.morphAttributes = morphAttributes;
  6260. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6261. }
  6262. const groups = this.groups;
  6263. if ( groups.length > 0 ) {
  6264. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6265. }
  6266. const boundingSphere = this.boundingSphere;
  6267. if ( boundingSphere !== null ) {
  6268. data.data.boundingSphere = {
  6269. center: boundingSphere.center.toArray(),
  6270. radius: boundingSphere.radius
  6271. };
  6272. }
  6273. return data;
  6274. },
  6275. clone: function () {
  6276. /*
  6277. // Handle primitives
  6278. const parameters = this.parameters;
  6279. if ( parameters !== undefined ) {
  6280. const values = [];
  6281. for ( const key in parameters ) {
  6282. values.push( parameters[ key ] );
  6283. }
  6284. const geometry = Object.create( this.constructor.prototype );
  6285. this.constructor.apply( geometry, values );
  6286. return geometry;
  6287. }
  6288. return new this.constructor().copy( this );
  6289. */
  6290. return new BufferGeometry().copy( this );
  6291. },
  6292. copy: function ( source ) {
  6293. // reset
  6294. this.index = null;
  6295. this.attributes = {};
  6296. this.morphAttributes = {};
  6297. this.groups = [];
  6298. this.boundingBox = null;
  6299. this.boundingSphere = null;
  6300. // used for storing cloned, shared data
  6301. const data = {};
  6302. // name
  6303. this.name = source.name;
  6304. // index
  6305. const index = source.index;
  6306. if ( index !== null ) {
  6307. this.setIndex( index.clone( data ) );
  6308. }
  6309. // attributes
  6310. const attributes = source.attributes;
  6311. for ( const name in attributes ) {
  6312. const attribute = attributes[ name ];
  6313. this.setAttribute( name, attribute.clone( data ) );
  6314. }
  6315. // morph attributes
  6316. const morphAttributes = source.morphAttributes;
  6317. for ( const name in morphAttributes ) {
  6318. const array = [];
  6319. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6320. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6321. array.push( morphAttribute[ i ].clone( data ) );
  6322. }
  6323. this.morphAttributes[ name ] = array;
  6324. }
  6325. this.morphTargetsRelative = source.morphTargetsRelative;
  6326. // groups
  6327. const groups = source.groups;
  6328. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6329. const group = groups[ i ];
  6330. this.addGroup( group.start, group.count, group.materialIndex );
  6331. }
  6332. // bounding box
  6333. const boundingBox = source.boundingBox;
  6334. if ( boundingBox !== null ) {
  6335. this.boundingBox = boundingBox.clone();
  6336. }
  6337. // bounding sphere
  6338. const boundingSphere = source.boundingSphere;
  6339. if ( boundingSphere !== null ) {
  6340. this.boundingSphere = boundingSphere.clone();
  6341. }
  6342. // draw range
  6343. this.drawRange.start = source.drawRange.start;
  6344. this.drawRange.count = source.drawRange.count;
  6345. // user data
  6346. this.userData = source.userData;
  6347. return this;
  6348. },
  6349. dispose: function () {
  6350. this.dispatchEvent( { type: 'dispose' } );
  6351. }
  6352. } );
  6353. const _inverseMatrix = new Matrix4();
  6354. const _ray = new Ray();
  6355. const _sphere = new Sphere();
  6356. const _vA = new Vector3();
  6357. const _vB = new Vector3();
  6358. const _vC = new Vector3();
  6359. const _tempA = new Vector3();
  6360. const _tempB = new Vector3();
  6361. const _tempC = new Vector3();
  6362. const _morphA = new Vector3();
  6363. const _morphB = new Vector3();
  6364. const _morphC = new Vector3();
  6365. const _uvA = new Vector2();
  6366. const _uvB = new Vector2();
  6367. const _uvC = new Vector2();
  6368. const _intersectionPoint = new Vector3();
  6369. const _intersectionPointWorld = new Vector3();
  6370. function Mesh( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6371. Object3D.call( this );
  6372. this.type = 'Mesh';
  6373. this.geometry = geometry;
  6374. this.material = material;
  6375. this.updateMorphTargets();
  6376. }
  6377. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6378. constructor: Mesh,
  6379. isMesh: true,
  6380. copy: function ( source ) {
  6381. Object3D.prototype.copy.call( this, source );
  6382. if ( source.morphTargetInfluences !== undefined ) {
  6383. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6384. }
  6385. if ( source.morphTargetDictionary !== undefined ) {
  6386. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6387. }
  6388. this.material = source.material;
  6389. this.geometry = source.geometry;
  6390. return this;
  6391. },
  6392. updateMorphTargets: function () {
  6393. const geometry = this.geometry;
  6394. if ( geometry.isBufferGeometry ) {
  6395. const morphAttributes = geometry.morphAttributes;
  6396. const keys = Object.keys( morphAttributes );
  6397. if ( keys.length > 0 ) {
  6398. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6399. if ( morphAttribute !== undefined ) {
  6400. this.morphTargetInfluences = [];
  6401. this.morphTargetDictionary = {};
  6402. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6403. const name = morphAttribute[ m ].name || String( m );
  6404. this.morphTargetInfluences.push( 0 );
  6405. this.morphTargetDictionary[ name ] = m;
  6406. }
  6407. }
  6408. }
  6409. } else {
  6410. const morphTargets = geometry.morphTargets;
  6411. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6412. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6413. }
  6414. }
  6415. },
  6416. raycast: function ( raycaster, intersects ) {
  6417. const geometry = this.geometry;
  6418. const material = this.material;
  6419. const matrixWorld = this.matrixWorld;
  6420. if ( material === undefined ) return;
  6421. // Checking boundingSphere distance to ray
  6422. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6423. _sphere.copy( geometry.boundingSphere );
  6424. _sphere.applyMatrix4( matrixWorld );
  6425. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6426. //
  6427. _inverseMatrix.copy( matrixWorld ).invert();
  6428. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6429. // Check boundingBox before continuing
  6430. if ( geometry.boundingBox !== null ) {
  6431. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6432. }
  6433. let intersection;
  6434. if ( geometry.isBufferGeometry ) {
  6435. const index = geometry.index;
  6436. const position = geometry.attributes.position;
  6437. const morphPosition = geometry.morphAttributes.position;
  6438. const morphTargetsRelative = geometry.morphTargetsRelative;
  6439. const uv = geometry.attributes.uv;
  6440. const uv2 = geometry.attributes.uv2;
  6441. const groups = geometry.groups;
  6442. const drawRange = geometry.drawRange;
  6443. if ( index !== null ) {
  6444. // indexed buffer geometry
  6445. if ( Array.isArray( material ) ) {
  6446. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6447. const group = groups[ i ];
  6448. const groupMaterial = material[ group.materialIndex ];
  6449. const start = Math.max( group.start, drawRange.start );
  6450. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6451. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6452. const a = index.getX( j );
  6453. const b = index.getX( j + 1 );
  6454. const c = index.getX( j + 2 );
  6455. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6456. if ( intersection ) {
  6457. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6458. intersection.face.materialIndex = group.materialIndex;
  6459. intersects.push( intersection );
  6460. }
  6461. }
  6462. }
  6463. } else {
  6464. const start = Math.max( 0, drawRange.start );
  6465. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6466. for ( let i = start, il = end; i < il; i += 3 ) {
  6467. const a = index.getX( i );
  6468. const b = index.getX( i + 1 );
  6469. const c = index.getX( i + 2 );
  6470. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6471. if ( intersection ) {
  6472. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6473. intersects.push( intersection );
  6474. }
  6475. }
  6476. }
  6477. } else if ( position !== undefined ) {
  6478. // non-indexed buffer geometry
  6479. if ( Array.isArray( material ) ) {
  6480. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6481. const group = groups[ i ];
  6482. const groupMaterial = material[ group.materialIndex ];
  6483. const start = Math.max( group.start, drawRange.start );
  6484. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6485. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6486. const a = j;
  6487. const b = j + 1;
  6488. const c = j + 2;
  6489. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6490. if ( intersection ) {
  6491. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6492. intersection.face.materialIndex = group.materialIndex;
  6493. intersects.push( intersection );
  6494. }
  6495. }
  6496. }
  6497. } else {
  6498. const start = Math.max( 0, drawRange.start );
  6499. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6500. for ( let i = start, il = end; i < il; i += 3 ) {
  6501. const a = i;
  6502. const b = i + 1;
  6503. const c = i + 2;
  6504. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6505. if ( intersection ) {
  6506. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6507. intersects.push( intersection );
  6508. }
  6509. }
  6510. }
  6511. }
  6512. } else if ( geometry.isGeometry ) {
  6513. console.error( 'THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6514. }
  6515. }
  6516. } );
  6517. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6518. let intersect;
  6519. if ( material.side === BackSide ) {
  6520. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6521. } else {
  6522. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6523. }
  6524. if ( intersect === null ) return null;
  6525. _intersectionPointWorld.copy( point );
  6526. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6527. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6528. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6529. return {
  6530. distance: distance,
  6531. point: _intersectionPointWorld.clone(),
  6532. object: object
  6533. };
  6534. }
  6535. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6536. _vA.fromBufferAttribute( position, a );
  6537. _vB.fromBufferAttribute( position, b );
  6538. _vC.fromBufferAttribute( position, c );
  6539. const morphInfluences = object.morphTargetInfluences;
  6540. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6541. _morphA.set( 0, 0, 0 );
  6542. _morphB.set( 0, 0, 0 );
  6543. _morphC.set( 0, 0, 0 );
  6544. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  6545. const influence = morphInfluences[ i ];
  6546. const morphAttribute = morphPosition[ i ];
  6547. if ( influence === 0 ) continue;
  6548. _tempA.fromBufferAttribute( morphAttribute, a );
  6549. _tempB.fromBufferAttribute( morphAttribute, b );
  6550. _tempC.fromBufferAttribute( morphAttribute, c );
  6551. if ( morphTargetsRelative ) {
  6552. _morphA.addScaledVector( _tempA, influence );
  6553. _morphB.addScaledVector( _tempB, influence );
  6554. _morphC.addScaledVector( _tempC, influence );
  6555. } else {
  6556. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6557. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6558. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6559. }
  6560. }
  6561. _vA.add( _morphA );
  6562. _vB.add( _morphB );
  6563. _vC.add( _morphC );
  6564. }
  6565. if ( object.isSkinnedMesh && material.skinning ) {
  6566. object.boneTransform( a, _vA );
  6567. object.boneTransform( b, _vB );
  6568. object.boneTransform( c, _vC );
  6569. }
  6570. const intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6571. if ( intersection ) {
  6572. if ( uv ) {
  6573. _uvA.fromBufferAttribute( uv, a );
  6574. _uvB.fromBufferAttribute( uv, b );
  6575. _uvC.fromBufferAttribute( uv, c );
  6576. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6577. }
  6578. if ( uv2 ) {
  6579. _uvA.fromBufferAttribute( uv2, a );
  6580. _uvB.fromBufferAttribute( uv2, b );
  6581. _uvC.fromBufferAttribute( uv2, c );
  6582. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6583. }
  6584. const face = {
  6585. a: a,
  6586. b: b,
  6587. c: c,
  6588. normal: new Vector3(),
  6589. materialIndex: 0
  6590. };
  6591. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6592. intersection.face = face;
  6593. }
  6594. return intersection;
  6595. }
  6596. class BoxGeometry extends BufferGeometry {
  6597. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  6598. super();
  6599. this.type = 'BoxGeometry';
  6600. this.parameters = {
  6601. width: width,
  6602. height: height,
  6603. depth: depth,
  6604. widthSegments: widthSegments,
  6605. heightSegments: heightSegments,
  6606. depthSegments: depthSegments
  6607. };
  6608. const scope = this;
  6609. // segments
  6610. widthSegments = Math.floor( widthSegments );
  6611. heightSegments = Math.floor( heightSegments );
  6612. depthSegments = Math.floor( depthSegments );
  6613. // buffers
  6614. const indices = [];
  6615. const vertices = [];
  6616. const normals = [];
  6617. const uvs = [];
  6618. // helper variables
  6619. let numberOfVertices = 0;
  6620. let groupStart = 0;
  6621. // build each side of the box geometry
  6622. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  6623. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  6624. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  6625. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  6626. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  6627. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  6628. // build geometry
  6629. this.setIndex( indices );
  6630. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  6631. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  6632. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  6633. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  6634. const segmentWidth = width / gridX;
  6635. const segmentHeight = height / gridY;
  6636. const widthHalf = width / 2;
  6637. const heightHalf = height / 2;
  6638. const depthHalf = depth / 2;
  6639. const gridX1 = gridX + 1;
  6640. const gridY1 = gridY + 1;
  6641. let vertexCounter = 0;
  6642. let groupCount = 0;
  6643. const vector = new Vector3();
  6644. // generate vertices, normals and uvs
  6645. for ( let iy = 0; iy < gridY1; iy ++ ) {
  6646. const y = iy * segmentHeight - heightHalf;
  6647. for ( let ix = 0; ix < gridX1; ix ++ ) {
  6648. const x = ix * segmentWidth - widthHalf;
  6649. // set values to correct vector component
  6650. vector[ u ] = x * udir;
  6651. vector[ v ] = y * vdir;
  6652. vector[ w ] = depthHalf;
  6653. // now apply vector to vertex buffer
  6654. vertices.push( vector.x, vector.y, vector.z );
  6655. // set values to correct vector component
  6656. vector[ u ] = 0;
  6657. vector[ v ] = 0;
  6658. vector[ w ] = depth > 0 ? 1 : - 1;
  6659. // now apply vector to normal buffer
  6660. normals.push( vector.x, vector.y, vector.z );
  6661. // uvs
  6662. uvs.push( ix / gridX );
  6663. uvs.push( 1 - ( iy / gridY ) );
  6664. // counters
  6665. vertexCounter += 1;
  6666. }
  6667. }
  6668. // indices
  6669. // 1. you need three indices to draw a single face
  6670. // 2. a single segment consists of two faces
  6671. // 3. so we need to generate six (2*3) indices per segment
  6672. for ( let iy = 0; iy < gridY; iy ++ ) {
  6673. for ( let ix = 0; ix < gridX; ix ++ ) {
  6674. const a = numberOfVertices + ix + gridX1 * iy;
  6675. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  6676. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  6677. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  6678. // faces
  6679. indices.push( a, b, d );
  6680. indices.push( b, c, d );
  6681. // increase counter
  6682. groupCount += 6;
  6683. }
  6684. }
  6685. // add a group to the geometry. this will ensure multi material support
  6686. scope.addGroup( groupStart, groupCount, materialIndex );
  6687. // calculate new start value for groups
  6688. groupStart += groupCount;
  6689. // update total number of vertices
  6690. numberOfVertices += vertexCounter;
  6691. }
  6692. }
  6693. }
  6694. /**
  6695. * Uniform Utilities
  6696. */
  6697. function cloneUniforms( src ) {
  6698. const dst = {};
  6699. for ( const u in src ) {
  6700. dst[ u ] = {};
  6701. for ( const p in src[ u ] ) {
  6702. const property = src[ u ][ p ];
  6703. if ( property && ( property.isColor ||
  6704. property.isMatrix3 || property.isMatrix4 ||
  6705. property.isVector2 || property.isVector3 || property.isVector4 ||
  6706. property.isTexture || property.isQuaternion ) ) {
  6707. dst[ u ][ p ] = property.clone();
  6708. } else if ( Array.isArray( property ) ) {
  6709. dst[ u ][ p ] = property.slice();
  6710. } else {
  6711. dst[ u ][ p ] = property;
  6712. }
  6713. }
  6714. }
  6715. return dst;
  6716. }
  6717. function mergeUniforms( uniforms ) {
  6718. const merged = {};
  6719. for ( let u = 0; u < uniforms.length; u ++ ) {
  6720. const tmp = cloneUniforms( uniforms[ u ] );
  6721. for ( const p in tmp ) {
  6722. merged[ p ] = tmp[ p ];
  6723. }
  6724. }
  6725. return merged;
  6726. }
  6727. // Legacy
  6728. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  6729. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  6730. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  6731. /**
  6732. * parameters = {
  6733. * defines: { "label" : "value" },
  6734. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  6735. *
  6736. * fragmentShader: <string>,
  6737. * vertexShader: <string>,
  6738. *
  6739. * wireframe: <boolean>,
  6740. * wireframeLinewidth: <float>,
  6741. *
  6742. * lights: <bool>,
  6743. *
  6744. * skinning: <bool>,
  6745. * morphTargets: <bool>,
  6746. * morphNormals: <bool>
  6747. * }
  6748. */
  6749. function ShaderMaterial( parameters ) {
  6750. Material.call( this );
  6751. this.type = 'ShaderMaterial';
  6752. this.defines = {};
  6753. this.uniforms = {};
  6754. this.vertexShader = default_vertex;
  6755. this.fragmentShader = default_fragment;
  6756. this.linewidth = 1;
  6757. this.wireframe = false;
  6758. this.wireframeLinewidth = 1;
  6759. this.fog = false; // set to use scene fog
  6760. this.lights = false; // set to use scene lights
  6761. this.clipping = false; // set to use user-defined clipping planes
  6762. this.skinning = false; // set to use skinning attribute streams
  6763. this.morphTargets = false; // set to use morph targets
  6764. this.morphNormals = false; // set to use morph normals
  6765. this.extensions = {
  6766. derivatives: false, // set to use derivatives
  6767. fragDepth: false, // set to use fragment depth values
  6768. drawBuffers: false, // set to use draw buffers
  6769. shaderTextureLOD: false // set to use shader texture LOD
  6770. };
  6771. // When rendered geometry doesn't include these attributes but the material does,
  6772. // use these default values in WebGL. This avoids errors when buffer data is missing.
  6773. this.defaultAttributeValues = {
  6774. 'color': [ 1, 1, 1 ],
  6775. 'uv': [ 0, 0 ],
  6776. 'uv2': [ 0, 0 ]
  6777. };
  6778. this.index0AttributeName = undefined;
  6779. this.uniformsNeedUpdate = false;
  6780. this.glslVersion = null;
  6781. if ( parameters !== undefined ) {
  6782. if ( parameters.attributes !== undefined ) {
  6783. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  6784. }
  6785. this.setValues( parameters );
  6786. }
  6787. }
  6788. ShaderMaterial.prototype = Object.create( Material.prototype );
  6789. ShaderMaterial.prototype.constructor = ShaderMaterial;
  6790. ShaderMaterial.prototype.isShaderMaterial = true;
  6791. ShaderMaterial.prototype.copy = function ( source ) {
  6792. Material.prototype.copy.call( this, source );
  6793. this.fragmentShader = source.fragmentShader;
  6794. this.vertexShader = source.vertexShader;
  6795. this.uniforms = cloneUniforms( source.uniforms );
  6796. this.defines = Object.assign( {}, source.defines );
  6797. this.wireframe = source.wireframe;
  6798. this.wireframeLinewidth = source.wireframeLinewidth;
  6799. this.lights = source.lights;
  6800. this.clipping = source.clipping;
  6801. this.skinning = source.skinning;
  6802. this.morphTargets = source.morphTargets;
  6803. this.morphNormals = source.morphNormals;
  6804. this.extensions = Object.assign( {}, source.extensions );
  6805. this.glslVersion = source.glslVersion;
  6806. return this;
  6807. };
  6808. ShaderMaterial.prototype.toJSON = function ( meta ) {
  6809. const data = Material.prototype.toJSON.call( this, meta );
  6810. data.glslVersion = this.glslVersion;
  6811. data.uniforms = {};
  6812. for ( const name in this.uniforms ) {
  6813. const uniform = this.uniforms[ name ];
  6814. const value = uniform.value;
  6815. if ( value && value.isTexture ) {
  6816. data.uniforms[ name ] = {
  6817. type: 't',
  6818. value: value.toJSON( meta ).uuid
  6819. };
  6820. } else if ( value && value.isColor ) {
  6821. data.uniforms[ name ] = {
  6822. type: 'c',
  6823. value: value.getHex()
  6824. };
  6825. } else if ( value && value.isVector2 ) {
  6826. data.uniforms[ name ] = {
  6827. type: 'v2',
  6828. value: value.toArray()
  6829. };
  6830. } else if ( value && value.isVector3 ) {
  6831. data.uniforms[ name ] = {
  6832. type: 'v3',
  6833. value: value.toArray()
  6834. };
  6835. } else if ( value && value.isVector4 ) {
  6836. data.uniforms[ name ] = {
  6837. type: 'v4',
  6838. value: value.toArray()
  6839. };
  6840. } else if ( value && value.isMatrix3 ) {
  6841. data.uniforms[ name ] = {
  6842. type: 'm3',
  6843. value: value.toArray()
  6844. };
  6845. } else if ( value && value.isMatrix4 ) {
  6846. data.uniforms[ name ] = {
  6847. type: 'm4',
  6848. value: value.toArray()
  6849. };
  6850. } else {
  6851. data.uniforms[ name ] = {
  6852. value: value
  6853. };
  6854. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  6855. }
  6856. }
  6857. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  6858. data.vertexShader = this.vertexShader;
  6859. data.fragmentShader = this.fragmentShader;
  6860. const extensions = {};
  6861. for ( const key in this.extensions ) {
  6862. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  6863. }
  6864. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  6865. return data;
  6866. };
  6867. function Camera() {
  6868. Object3D.call( this );
  6869. this.type = 'Camera';
  6870. this.matrixWorldInverse = new Matrix4();
  6871. this.projectionMatrix = new Matrix4();
  6872. this.projectionMatrixInverse = new Matrix4();
  6873. }
  6874. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6875. constructor: Camera,
  6876. isCamera: true,
  6877. copy: function ( source, recursive ) {
  6878. Object3D.prototype.copy.call( this, source, recursive );
  6879. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6880. this.projectionMatrix.copy( source.projectionMatrix );
  6881. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  6882. return this;
  6883. },
  6884. getWorldDirection: function ( target ) {
  6885. if ( target === undefined ) {
  6886. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  6887. target = new Vector3();
  6888. }
  6889. this.updateWorldMatrix( true, false );
  6890. const e = this.matrixWorld.elements;
  6891. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  6892. },
  6893. updateMatrixWorld: function ( force ) {
  6894. Object3D.prototype.updateMatrixWorld.call( this, force );
  6895. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  6896. },
  6897. updateWorldMatrix: function ( updateParents, updateChildren ) {
  6898. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  6899. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  6900. },
  6901. clone: function () {
  6902. return new this.constructor().copy( this );
  6903. }
  6904. } );
  6905. function PerspectiveCamera( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  6906. Camera.call( this );
  6907. this.type = 'PerspectiveCamera';
  6908. this.fov = fov;
  6909. this.zoom = 1;
  6910. this.near = near;
  6911. this.far = far;
  6912. this.focus = 10;
  6913. this.aspect = aspect;
  6914. this.view = null;
  6915. this.filmGauge = 35; // width of the film (default in millimeters)
  6916. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  6917. this.updateProjectionMatrix();
  6918. }
  6919. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  6920. constructor: PerspectiveCamera,
  6921. isPerspectiveCamera: true,
  6922. copy: function ( source, recursive ) {
  6923. Camera.prototype.copy.call( this, source, recursive );
  6924. this.fov = source.fov;
  6925. this.zoom = source.zoom;
  6926. this.near = source.near;
  6927. this.far = source.far;
  6928. this.focus = source.focus;
  6929. this.aspect = source.aspect;
  6930. this.view = source.view === null ? null : Object.assign( {}, source.view );
  6931. this.filmGauge = source.filmGauge;
  6932. this.filmOffset = source.filmOffset;
  6933. return this;
  6934. },
  6935. /**
  6936. * Sets the FOV by focal length in respect to the current .filmGauge.
  6937. *
  6938. * The default film gauge is 35, so that the focal length can be specified for
  6939. * a 35mm (full frame) camera.
  6940. *
  6941. * Values for focal length and film gauge must have the same unit.
  6942. */
  6943. setFocalLength: function ( focalLength ) {
  6944. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  6945. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  6946. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  6947. this.updateProjectionMatrix();
  6948. },
  6949. /**
  6950. * Calculates the focal length from the current .fov and .filmGauge.
  6951. */
  6952. getFocalLength: function () {
  6953. const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  6954. return 0.5 * this.getFilmHeight() / vExtentSlope;
  6955. },
  6956. getEffectiveFOV: function () {
  6957. return MathUtils.RAD2DEG * 2 * Math.atan(
  6958. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  6959. },
  6960. getFilmWidth: function () {
  6961. // film not completely covered in portrait format (aspect < 1)
  6962. return this.filmGauge * Math.min( this.aspect, 1 );
  6963. },
  6964. getFilmHeight: function () {
  6965. // film not completely covered in landscape format (aspect > 1)
  6966. return this.filmGauge / Math.max( this.aspect, 1 );
  6967. },
  6968. /**
  6969. * Sets an offset in a larger frustum. This is useful for multi-window or
  6970. * multi-monitor/multi-machine setups.
  6971. *
  6972. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6973. * the monitors are in grid like this
  6974. *
  6975. * +---+---+---+
  6976. * | A | B | C |
  6977. * +---+---+---+
  6978. * | D | E | F |
  6979. * +---+---+---+
  6980. *
  6981. * then for each monitor you would call it like this
  6982. *
  6983. * const w = 1920;
  6984. * const h = 1080;
  6985. * const fullWidth = w * 3;
  6986. * const fullHeight = h * 2;
  6987. *
  6988. * --A--
  6989. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  6990. * --B--
  6991. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  6992. * --C--
  6993. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  6994. * --D--
  6995. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  6996. * --E--
  6997. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  6998. * --F--
  6999. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7000. *
  7001. * Note there is no reason monitors have to be the same size or in a grid.
  7002. */
  7003. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  7004. this.aspect = fullWidth / fullHeight;
  7005. if ( this.view === null ) {
  7006. this.view = {
  7007. enabled: true,
  7008. fullWidth: 1,
  7009. fullHeight: 1,
  7010. offsetX: 0,
  7011. offsetY: 0,
  7012. width: 1,
  7013. height: 1
  7014. };
  7015. }
  7016. this.view.enabled = true;
  7017. this.view.fullWidth = fullWidth;
  7018. this.view.fullHeight = fullHeight;
  7019. this.view.offsetX = x;
  7020. this.view.offsetY = y;
  7021. this.view.width = width;
  7022. this.view.height = height;
  7023. this.updateProjectionMatrix();
  7024. },
  7025. clearViewOffset: function () {
  7026. if ( this.view !== null ) {
  7027. this.view.enabled = false;
  7028. }
  7029. this.updateProjectionMatrix();
  7030. },
  7031. updateProjectionMatrix: function () {
  7032. const near = this.near;
  7033. let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7034. let height = 2 * top;
  7035. let width = this.aspect * height;
  7036. let left = - 0.5 * width;
  7037. const view = this.view;
  7038. if ( this.view !== null && this.view.enabled ) {
  7039. const fullWidth = view.fullWidth,
  7040. fullHeight = view.fullHeight;
  7041. left += view.offsetX * width / fullWidth;
  7042. top -= view.offsetY * height / fullHeight;
  7043. width *= view.width / fullWidth;
  7044. height *= view.height / fullHeight;
  7045. }
  7046. const skew = this.filmOffset;
  7047. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7048. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  7049. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7050. },
  7051. toJSON: function ( meta ) {
  7052. const data = Object3D.prototype.toJSON.call( this, meta );
  7053. data.object.fov = this.fov;
  7054. data.object.zoom = this.zoom;
  7055. data.object.near = this.near;
  7056. data.object.far = this.far;
  7057. data.object.focus = this.focus;
  7058. data.object.aspect = this.aspect;
  7059. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7060. data.object.filmGauge = this.filmGauge;
  7061. data.object.filmOffset = this.filmOffset;
  7062. return data;
  7063. }
  7064. } );
  7065. const fov = 90, aspect = 1;
  7066. class CubeCamera extends Object3D {
  7067. constructor( near, far, renderTarget ) {
  7068. super();
  7069. this.type = 'CubeCamera';
  7070. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  7071. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  7072. return;
  7073. }
  7074. this.renderTarget = renderTarget;
  7075. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7076. cameraPX.layers = this.layers;
  7077. cameraPX.up.set( 0, - 1, 0 );
  7078. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  7079. this.add( cameraPX );
  7080. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7081. cameraNX.layers = this.layers;
  7082. cameraNX.up.set( 0, - 1, 0 );
  7083. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  7084. this.add( cameraNX );
  7085. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7086. cameraPY.layers = this.layers;
  7087. cameraPY.up.set( 0, 0, 1 );
  7088. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  7089. this.add( cameraPY );
  7090. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7091. cameraNY.layers = this.layers;
  7092. cameraNY.up.set( 0, 0, - 1 );
  7093. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  7094. this.add( cameraNY );
  7095. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7096. cameraPZ.layers = this.layers;
  7097. cameraPZ.up.set( 0, - 1, 0 );
  7098. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  7099. this.add( cameraPZ );
  7100. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7101. cameraNZ.layers = this.layers;
  7102. cameraNZ.up.set( 0, - 1, 0 );
  7103. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  7104. this.add( cameraNZ );
  7105. }
  7106. update( renderer, scene ) {
  7107. if ( this.parent === null ) this.updateMatrixWorld();
  7108. const renderTarget = this.renderTarget;
  7109. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7110. const currentXrEnabled = renderer.xr.enabled;
  7111. const currentRenderTarget = renderer.getRenderTarget();
  7112. renderer.xr.enabled = false;
  7113. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7114. renderTarget.texture.generateMipmaps = false;
  7115. renderer.setRenderTarget( renderTarget, 0 );
  7116. renderer.render( scene, cameraPX );
  7117. renderer.setRenderTarget( renderTarget, 1 );
  7118. renderer.render( scene, cameraNX );
  7119. renderer.setRenderTarget( renderTarget, 2 );
  7120. renderer.render( scene, cameraPY );
  7121. renderer.setRenderTarget( renderTarget, 3 );
  7122. renderer.render( scene, cameraNY );
  7123. renderer.setRenderTarget( renderTarget, 4 );
  7124. renderer.render( scene, cameraPZ );
  7125. renderTarget.texture.generateMipmaps = generateMipmaps;
  7126. renderer.setRenderTarget( renderTarget, 5 );
  7127. renderer.render( scene, cameraNZ );
  7128. renderer.setRenderTarget( currentRenderTarget );
  7129. renderer.xr.enabled = currentXrEnabled;
  7130. }
  7131. }
  7132. class CubeTexture extends Texture {
  7133. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  7134. images = images !== undefined ? images : [];
  7135. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7136. format = format !== undefined ? format : RGBFormat;
  7137. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7138. // Why CubeTexture._needsFlipEnvMap is necessary:
  7139. //
  7140. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7141. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7142. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7143. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7144. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7145. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7146. this._needsFlipEnvMap = true;
  7147. this.flipY = false;
  7148. }
  7149. get images() {
  7150. return this.image;
  7151. }
  7152. set images( value ) {
  7153. this.image = value;
  7154. }
  7155. }
  7156. CubeTexture.prototype.isCubeTexture = true;
  7157. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7158. constructor( size, options, dummy ) {
  7159. if ( Number.isInteger( options ) ) {
  7160. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  7161. options = dummy;
  7162. }
  7163. super( size, size, options );
  7164. options = options || {};
  7165. this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  7166. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7167. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7168. this.texture._needsFlipEnvMap = false;
  7169. }
  7170. fromEquirectangularTexture( renderer, texture ) {
  7171. this.texture.type = texture.type;
  7172. this.texture.format = RGBAFormat; // see #18859
  7173. this.texture.encoding = texture.encoding;
  7174. this.texture.generateMipmaps = texture.generateMipmaps;
  7175. this.texture.minFilter = texture.minFilter;
  7176. this.texture.magFilter = texture.magFilter;
  7177. const shader = {
  7178. uniforms: {
  7179. tEquirect: { value: null },
  7180. },
  7181. vertexShader: /* glsl */`
  7182. varying vec3 vWorldDirection;
  7183. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7184. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7185. }
  7186. void main() {
  7187. vWorldDirection = transformDirection( position, modelMatrix );
  7188. #include <begin_vertex>
  7189. #include <project_vertex>
  7190. }
  7191. `,
  7192. fragmentShader: /* glsl */`
  7193. uniform sampler2D tEquirect;
  7194. varying vec3 vWorldDirection;
  7195. #include <common>
  7196. void main() {
  7197. vec3 direction = normalize( vWorldDirection );
  7198. vec2 sampleUV = equirectUv( direction );
  7199. gl_FragColor = texture2D( tEquirect, sampleUV );
  7200. }
  7201. `
  7202. };
  7203. const geometry = new BoxGeometry( 5, 5, 5 );
  7204. const material = new ShaderMaterial( {
  7205. name: 'CubemapFromEquirect',
  7206. uniforms: cloneUniforms( shader.uniforms ),
  7207. vertexShader: shader.vertexShader,
  7208. fragmentShader: shader.fragmentShader,
  7209. side: BackSide,
  7210. blending: NoBlending
  7211. } );
  7212. material.uniforms.tEquirect.value = texture;
  7213. const mesh = new Mesh( geometry, material );
  7214. const currentMinFilter = texture.minFilter;
  7215. // Avoid blurred poles
  7216. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7217. const camera = new CubeCamera( 1, 10, this );
  7218. camera.update( renderer, mesh );
  7219. texture.minFilter = currentMinFilter;
  7220. mesh.geometry.dispose();
  7221. mesh.material.dispose();
  7222. return this;
  7223. }
  7224. clear( renderer, color, depth, stencil ) {
  7225. const currentRenderTarget = renderer.getRenderTarget();
  7226. for ( let i = 0; i < 6; i ++ ) {
  7227. renderer.setRenderTarget( this, i );
  7228. renderer.clear( color, depth, stencil );
  7229. }
  7230. renderer.setRenderTarget( currentRenderTarget );
  7231. }
  7232. }
  7233. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7234. class DataTexture extends Texture {
  7235. constructor( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  7236. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7237. this.image = { data: data || null, width: width || 1, height: height || 1 };
  7238. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7239. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7240. this.generateMipmaps = false;
  7241. this.flipY = false;
  7242. this.unpackAlignment = 1;
  7243. this.needsUpdate = true;
  7244. }
  7245. }
  7246. DataTexture.prototype.isDataTexture = true;
  7247. const _sphere$1 = /*@__PURE__*/ new Sphere();
  7248. const _vector$5 = /*@__PURE__*/ new Vector3();
  7249. class Frustum {
  7250. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  7251. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  7252. }
  7253. set( p0, p1, p2, p3, p4, p5 ) {
  7254. const planes = this.planes;
  7255. planes[ 0 ].copy( p0 );
  7256. planes[ 1 ].copy( p1 );
  7257. planes[ 2 ].copy( p2 );
  7258. planes[ 3 ].copy( p3 );
  7259. planes[ 4 ].copy( p4 );
  7260. planes[ 5 ].copy( p5 );
  7261. return this;
  7262. }
  7263. copy( frustum ) {
  7264. const planes = this.planes;
  7265. for ( let i = 0; i < 6; i ++ ) {
  7266. planes[ i ].copy( frustum.planes[ i ] );
  7267. }
  7268. return this;
  7269. }
  7270. setFromProjectionMatrix( m ) {
  7271. const planes = this.planes;
  7272. const me = m.elements;
  7273. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  7274. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  7275. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  7276. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  7277. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  7278. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  7279. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  7280. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  7281. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  7282. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  7283. return this;
  7284. }
  7285. intersectsObject( object ) {
  7286. const geometry = object.geometry;
  7287. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7288. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  7289. return this.intersectsSphere( _sphere$1 );
  7290. }
  7291. intersectsSprite( sprite ) {
  7292. _sphere$1.center.set( 0, 0, 0 );
  7293. _sphere$1.radius = 0.7071067811865476;
  7294. _sphere$1.applyMatrix4( sprite.matrixWorld );
  7295. return this.intersectsSphere( _sphere$1 );
  7296. }
  7297. intersectsSphere( sphere ) {
  7298. const planes = this.planes;
  7299. const center = sphere.center;
  7300. const negRadius = - sphere.radius;
  7301. for ( let i = 0; i < 6; i ++ ) {
  7302. const distance = planes[ i ].distanceToPoint( center );
  7303. if ( distance < negRadius ) {
  7304. return false;
  7305. }
  7306. }
  7307. return true;
  7308. }
  7309. intersectsBox( box ) {
  7310. const planes = this.planes;
  7311. for ( let i = 0; i < 6; i ++ ) {
  7312. const plane = planes[ i ];
  7313. // corner at max distance
  7314. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7315. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7316. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7317. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  7318. return false;
  7319. }
  7320. }
  7321. return true;
  7322. }
  7323. containsPoint( point ) {
  7324. const planes = this.planes;
  7325. for ( let i = 0; i < 6; i ++ ) {
  7326. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  7327. return false;
  7328. }
  7329. }
  7330. return true;
  7331. }
  7332. clone() {
  7333. return new this.constructor().copy( this );
  7334. }
  7335. }
  7336. function WebGLAnimation() {
  7337. let context = null;
  7338. let isAnimating = false;
  7339. let animationLoop = null;
  7340. let requestId = null;
  7341. function onAnimationFrame( time, frame ) {
  7342. animationLoop( time, frame );
  7343. requestId = context.requestAnimationFrame( onAnimationFrame );
  7344. }
  7345. return {
  7346. start: function () {
  7347. if ( isAnimating === true ) return;
  7348. if ( animationLoop === null ) return;
  7349. requestId = context.requestAnimationFrame( onAnimationFrame );
  7350. isAnimating = true;
  7351. },
  7352. stop: function () {
  7353. context.cancelAnimationFrame( requestId );
  7354. isAnimating = false;
  7355. },
  7356. setAnimationLoop: function ( callback ) {
  7357. animationLoop = callback;
  7358. },
  7359. setContext: function ( value ) {
  7360. context = value;
  7361. }
  7362. };
  7363. }
  7364. function WebGLAttributes( gl, capabilities ) {
  7365. const isWebGL2 = capabilities.isWebGL2;
  7366. const buffers = new WeakMap();
  7367. function createBuffer( attribute, bufferType ) {
  7368. const array = attribute.array;
  7369. const usage = attribute.usage;
  7370. const buffer = gl.createBuffer();
  7371. gl.bindBuffer( bufferType, buffer );
  7372. gl.bufferData( bufferType, array, usage );
  7373. attribute.onUploadCallback();
  7374. let type = 5126;
  7375. if ( array instanceof Float32Array ) {
  7376. type = 5126;
  7377. } else if ( array instanceof Float64Array ) {
  7378. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  7379. } else if ( array instanceof Uint16Array ) {
  7380. if ( attribute.isFloat16BufferAttribute ) {
  7381. if ( isWebGL2 ) {
  7382. type = 5131;
  7383. } else {
  7384. console.warn( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
  7385. }
  7386. } else {
  7387. type = 5123;
  7388. }
  7389. } else if ( array instanceof Int16Array ) {
  7390. type = 5122;
  7391. } else if ( array instanceof Uint32Array ) {
  7392. type = 5125;
  7393. } else if ( array instanceof Int32Array ) {
  7394. type = 5124;
  7395. } else if ( array instanceof Int8Array ) {
  7396. type = 5120;
  7397. } else if ( array instanceof Uint8Array ) {
  7398. type = 5121;
  7399. }
  7400. return {
  7401. buffer: buffer,
  7402. type: type,
  7403. bytesPerElement: array.BYTES_PER_ELEMENT,
  7404. version: attribute.version
  7405. };
  7406. }
  7407. function updateBuffer( buffer, attribute, bufferType ) {
  7408. const array = attribute.array;
  7409. const updateRange = attribute.updateRange;
  7410. gl.bindBuffer( bufferType, buffer );
  7411. if ( updateRange.count === - 1 ) {
  7412. // Not using update ranges
  7413. gl.bufferSubData( bufferType, 0, array );
  7414. } else {
  7415. if ( isWebGL2 ) {
  7416. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7417. array, updateRange.offset, updateRange.count );
  7418. } else {
  7419. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7420. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  7421. }
  7422. updateRange.count = - 1; // reset range
  7423. }
  7424. }
  7425. //
  7426. function get( attribute ) {
  7427. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7428. return buffers.get( attribute );
  7429. }
  7430. function remove( attribute ) {
  7431. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7432. const data = buffers.get( attribute );
  7433. if ( data ) {
  7434. gl.deleteBuffer( data.buffer );
  7435. buffers.delete( attribute );
  7436. }
  7437. }
  7438. function update( attribute, bufferType ) {
  7439. if ( attribute.isGLBufferAttribute ) {
  7440. const cached = buffers.get( attribute );
  7441. if ( ! cached || cached.version < attribute.version ) {
  7442. buffers.set( attribute, {
  7443. buffer: attribute.buffer,
  7444. type: attribute.type,
  7445. bytesPerElement: attribute.elementSize,
  7446. version: attribute.version
  7447. } );
  7448. }
  7449. return;
  7450. }
  7451. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7452. const data = buffers.get( attribute );
  7453. if ( data === undefined ) {
  7454. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  7455. } else if ( data.version < attribute.version ) {
  7456. updateBuffer( data.buffer, attribute, bufferType );
  7457. data.version = attribute.version;
  7458. }
  7459. }
  7460. return {
  7461. get: get,
  7462. remove: remove,
  7463. update: update
  7464. };
  7465. }
  7466. class PlaneGeometry extends BufferGeometry {
  7467. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  7468. super();
  7469. this.type = 'PlaneGeometry';
  7470. this.parameters = {
  7471. width: width,
  7472. height: height,
  7473. widthSegments: widthSegments,
  7474. heightSegments: heightSegments
  7475. };
  7476. const width_half = width / 2;
  7477. const height_half = height / 2;
  7478. const gridX = Math.floor( widthSegments );
  7479. const gridY = Math.floor( heightSegments );
  7480. const gridX1 = gridX + 1;
  7481. const gridY1 = gridY + 1;
  7482. const segment_width = width / gridX;
  7483. const segment_height = height / gridY;
  7484. //
  7485. const indices = [];
  7486. const vertices = [];
  7487. const normals = [];
  7488. const uvs = [];
  7489. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7490. const y = iy * segment_height - height_half;
  7491. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7492. const x = ix * segment_width - width_half;
  7493. vertices.push( x, - y, 0 );
  7494. normals.push( 0, 0, 1 );
  7495. uvs.push( ix / gridX );
  7496. uvs.push( 1 - ( iy / gridY ) );
  7497. }
  7498. }
  7499. for ( let iy = 0; iy < gridY; iy ++ ) {
  7500. for ( let ix = 0; ix < gridX; ix ++ ) {
  7501. const a = ix + gridX1 * iy;
  7502. const b = ix + gridX1 * ( iy + 1 );
  7503. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7504. const d = ( ix + 1 ) + gridX1 * iy;
  7505. indices.push( a, b, d );
  7506. indices.push( b, c, d );
  7507. }
  7508. }
  7509. this.setIndex( indices );
  7510. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7511. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7512. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7513. }
  7514. }
  7515. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  7516. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  7517. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  7518. 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.specularRoughness );\n\t#endif\n#endif";
  7519. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  7520. var begin_vertex = "vec3 transformed = vec3( position );";
  7521. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  7522. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\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\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_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_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * 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}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.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}\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_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";
  7523. 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";
  7524. 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";
  7525. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  7526. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  7527. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  7528. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  7529. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  7530. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  7531. var color_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
  7532. 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 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 max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\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 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}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\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}";
  7533. 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";
  7534. 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";
  7535. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  7536. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  7537. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  7538. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  7539. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  7540. 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}";
  7541. 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#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#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\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";
  7542. 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";
  7543. 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";
  7544. 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";
  7545. 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";
  7546. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  7547. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  7548. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  7549. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\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";
  7550. 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}";
  7551. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  7552. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  7553. 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 );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\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\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * 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\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * 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\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * 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 );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
  7554. 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 GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\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 getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.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 getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.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 getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.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 GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  7555. 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 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  7556. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  7557. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\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\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_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_Diffuse_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)";
  7558. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  7559. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\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\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, 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_Diffuse_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)";
  7560. 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.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\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.sheenColor = sheen;\n#endif";
  7561. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\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.specularRoughness;\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#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_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_Diffuse_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 CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * 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}";
  7562. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef 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\tgetPointDirectLightIrradiance( 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\tgetSpotDirectLightIrradiance( 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\tgetDirectionalDirectLightIrradiance( 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 );\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 );\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";
  7563. 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 += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";
  7564. 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";
  7565. 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";
  7566. 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";
  7567. 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";
  7568. 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";
  7569. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  7570. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  7571. 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";
  7572. 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";
  7573. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  7574. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  7575. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";
  7576. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  7577. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  7578. 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;";
  7579. 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";
  7580. 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";
  7581. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  7582. 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";
  7583. 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";
  7584. 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}";
  7585. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  7586. 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;";
  7587. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  7588. 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";
  7589. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  7590. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  7591. 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";
  7592. 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";
  7593. 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";
  7594. 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}";
  7595. 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";
  7596. 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";
  7597. 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";
  7598. 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";
  7599. 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";
  7600. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  7601. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  7602. 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; }";
  7603. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  7604. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  7605. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  7606. 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";
  7607. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  7608. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  7609. 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";
  7610. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  7611. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\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";
  7612. var background_frag = "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}";
  7613. var background_vert = "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}";
  7614. var cube_frag = "#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}";
  7615. var cube_vert = "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}";
  7616. var depth_frag = "#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 <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}";
  7617. var depth_vert = "#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}";
  7618. var distanceRGBA_frag = "#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 <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}";
  7619. var distanceRGBA_vert = "#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}";
  7620. var equirect_frag = "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}";
  7621. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  7622. var linedashed_frag = "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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  7623. var linedashed_vert = "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}";
  7624. var meshbasic_frag = "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 <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\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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7625. var meshbasic_vert = "#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#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\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 <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  7626. var meshlambert_frag = "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 <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_Diffuse_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_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7627. var meshlambert_vert = "#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}";
  7628. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\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 <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7629. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\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 <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#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\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\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  7630. var meshtoon_frag = "#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 <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 <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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7631. var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\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 <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#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#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\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7632. var meshphong_frag = "#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 <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 <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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7633. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\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 <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#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#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\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7634. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#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\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 <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_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 <lights_physical_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#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\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 <transmissionmap_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 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\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}";
  7635. var meshphysical_vert = "#define STANDARD\nvarying vec3 vViewPosition;\n#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\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 <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#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\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}";
  7636. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#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\n#include <packing>\n#include <uv_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}";
  7637. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#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\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 <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#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\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}";
  7638. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  7639. var points_vert = "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}";
  7640. var shadow_frag = "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}";
  7641. var shadow_vert = "#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_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 <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  7642. var sprite_frag = "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 <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\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  7643. var sprite_vert = "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}";
  7644. const ShaderChunk = {
  7645. alphamap_fragment: alphamap_fragment,
  7646. alphamap_pars_fragment: alphamap_pars_fragment,
  7647. alphatest_fragment: alphatest_fragment,
  7648. aomap_fragment: aomap_fragment,
  7649. aomap_pars_fragment: aomap_pars_fragment,
  7650. begin_vertex: begin_vertex,
  7651. beginnormal_vertex: beginnormal_vertex,
  7652. bsdfs: bsdfs,
  7653. bumpmap_pars_fragment: bumpmap_pars_fragment,
  7654. clipping_planes_fragment: clipping_planes_fragment,
  7655. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  7656. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  7657. clipping_planes_vertex: clipping_planes_vertex,
  7658. color_fragment: color_fragment,
  7659. color_pars_fragment: color_pars_fragment,
  7660. color_pars_vertex: color_pars_vertex,
  7661. color_vertex: color_vertex,
  7662. common: common,
  7663. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  7664. defaultnormal_vertex: defaultnormal_vertex,
  7665. displacementmap_pars_vertex: displacementmap_pars_vertex,
  7666. displacementmap_vertex: displacementmap_vertex,
  7667. emissivemap_fragment: emissivemap_fragment,
  7668. emissivemap_pars_fragment: emissivemap_pars_fragment,
  7669. encodings_fragment: encodings_fragment,
  7670. encodings_pars_fragment: encodings_pars_fragment,
  7671. envmap_fragment: envmap_fragment,
  7672. envmap_common_pars_fragment: envmap_common_pars_fragment,
  7673. envmap_pars_fragment: envmap_pars_fragment,
  7674. envmap_pars_vertex: envmap_pars_vertex,
  7675. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  7676. envmap_vertex: envmap_vertex,
  7677. fog_vertex: fog_vertex,
  7678. fog_pars_vertex: fog_pars_vertex,
  7679. fog_fragment: fog_fragment,
  7680. fog_pars_fragment: fog_pars_fragment,
  7681. gradientmap_pars_fragment: gradientmap_pars_fragment,
  7682. lightmap_fragment: lightmap_fragment,
  7683. lightmap_pars_fragment: lightmap_pars_fragment,
  7684. lights_lambert_vertex: lights_lambert_vertex,
  7685. lights_pars_begin: lights_pars_begin,
  7686. lights_toon_fragment: lights_toon_fragment,
  7687. lights_toon_pars_fragment: lights_toon_pars_fragment,
  7688. lights_phong_fragment: lights_phong_fragment,
  7689. lights_phong_pars_fragment: lights_phong_pars_fragment,
  7690. lights_physical_fragment: lights_physical_fragment,
  7691. lights_physical_pars_fragment: lights_physical_pars_fragment,
  7692. lights_fragment_begin: lights_fragment_begin,
  7693. lights_fragment_maps: lights_fragment_maps,
  7694. lights_fragment_end: lights_fragment_end,
  7695. logdepthbuf_fragment: logdepthbuf_fragment,
  7696. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  7697. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  7698. logdepthbuf_vertex: logdepthbuf_vertex,
  7699. map_fragment: map_fragment,
  7700. map_pars_fragment: map_pars_fragment,
  7701. map_particle_fragment: map_particle_fragment,
  7702. map_particle_pars_fragment: map_particle_pars_fragment,
  7703. metalnessmap_fragment: metalnessmap_fragment,
  7704. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  7705. morphnormal_vertex: morphnormal_vertex,
  7706. morphtarget_pars_vertex: morphtarget_pars_vertex,
  7707. morphtarget_vertex: morphtarget_vertex,
  7708. normal_fragment_begin: normal_fragment_begin,
  7709. normal_fragment_maps: normal_fragment_maps,
  7710. normalmap_pars_fragment: normalmap_pars_fragment,
  7711. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  7712. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  7713. clearcoat_pars_fragment: clearcoat_pars_fragment,
  7714. packing: packing,
  7715. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  7716. project_vertex: project_vertex,
  7717. dithering_fragment: dithering_fragment,
  7718. dithering_pars_fragment: dithering_pars_fragment,
  7719. roughnessmap_fragment: roughnessmap_fragment,
  7720. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  7721. shadowmap_pars_fragment: shadowmap_pars_fragment,
  7722. shadowmap_pars_vertex: shadowmap_pars_vertex,
  7723. shadowmap_vertex: shadowmap_vertex,
  7724. shadowmask_pars_fragment: shadowmask_pars_fragment,
  7725. skinbase_vertex: skinbase_vertex,
  7726. skinning_pars_vertex: skinning_pars_vertex,
  7727. skinning_vertex: skinning_vertex,
  7728. skinnormal_vertex: skinnormal_vertex,
  7729. specularmap_fragment: specularmap_fragment,
  7730. specularmap_pars_fragment: specularmap_pars_fragment,
  7731. tonemapping_fragment: tonemapping_fragment,
  7732. tonemapping_pars_fragment: tonemapping_pars_fragment,
  7733. transmissionmap_fragment: transmissionmap_fragment,
  7734. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  7735. uv_pars_fragment: uv_pars_fragment,
  7736. uv_pars_vertex: uv_pars_vertex,
  7737. uv_vertex: uv_vertex,
  7738. uv2_pars_fragment: uv2_pars_fragment,
  7739. uv2_pars_vertex: uv2_pars_vertex,
  7740. uv2_vertex: uv2_vertex,
  7741. worldpos_vertex: worldpos_vertex,
  7742. background_frag: background_frag,
  7743. background_vert: background_vert,
  7744. cube_frag: cube_frag,
  7745. cube_vert: cube_vert,
  7746. depth_frag: depth_frag,
  7747. depth_vert: depth_vert,
  7748. distanceRGBA_frag: distanceRGBA_frag,
  7749. distanceRGBA_vert: distanceRGBA_vert,
  7750. equirect_frag: equirect_frag,
  7751. equirect_vert: equirect_vert,
  7752. linedashed_frag: linedashed_frag,
  7753. linedashed_vert: linedashed_vert,
  7754. meshbasic_frag: meshbasic_frag,
  7755. meshbasic_vert: meshbasic_vert,
  7756. meshlambert_frag: meshlambert_frag,
  7757. meshlambert_vert: meshlambert_vert,
  7758. meshmatcap_frag: meshmatcap_frag,
  7759. meshmatcap_vert: meshmatcap_vert,
  7760. meshtoon_frag: meshtoon_frag,
  7761. meshtoon_vert: meshtoon_vert,
  7762. meshphong_frag: meshphong_frag,
  7763. meshphong_vert: meshphong_vert,
  7764. meshphysical_frag: meshphysical_frag,
  7765. meshphysical_vert: meshphysical_vert,
  7766. normal_frag: normal_frag,
  7767. normal_vert: normal_vert,
  7768. points_frag: points_frag,
  7769. points_vert: points_vert,
  7770. shadow_frag: shadow_frag,
  7771. shadow_vert: shadow_vert,
  7772. sprite_frag: sprite_frag,
  7773. sprite_vert: sprite_vert
  7774. };
  7775. /**
  7776. * Uniforms library for shared webgl shaders
  7777. */
  7778. const UniformsLib = {
  7779. common: {
  7780. diffuse: { value: new Color( 0xeeeeee ) },
  7781. opacity: { value: 1.0 },
  7782. map: { value: null },
  7783. uvTransform: { value: new Matrix3() },
  7784. uv2Transform: { value: new Matrix3() },
  7785. alphaMap: { value: null },
  7786. },
  7787. specularmap: {
  7788. specularMap: { value: null },
  7789. },
  7790. envmap: {
  7791. envMap: { value: null },
  7792. flipEnvMap: { value: - 1 },
  7793. reflectivity: { value: 1.0 },
  7794. refractionRatio: { value: 0.98 },
  7795. maxMipLevel: { value: 0 }
  7796. },
  7797. aomap: {
  7798. aoMap: { value: null },
  7799. aoMapIntensity: { value: 1 }
  7800. },
  7801. lightmap: {
  7802. lightMap: { value: null },
  7803. lightMapIntensity: { value: 1 }
  7804. },
  7805. emissivemap: {
  7806. emissiveMap: { value: null }
  7807. },
  7808. bumpmap: {
  7809. bumpMap: { value: null },
  7810. bumpScale: { value: 1 }
  7811. },
  7812. normalmap: {
  7813. normalMap: { value: null },
  7814. normalScale: { value: new Vector2( 1, 1 ) }
  7815. },
  7816. displacementmap: {
  7817. displacementMap: { value: null },
  7818. displacementScale: { value: 1 },
  7819. displacementBias: { value: 0 }
  7820. },
  7821. roughnessmap: {
  7822. roughnessMap: { value: null }
  7823. },
  7824. metalnessmap: {
  7825. metalnessMap: { value: null }
  7826. },
  7827. gradientmap: {
  7828. gradientMap: { value: null }
  7829. },
  7830. fog: {
  7831. fogDensity: { value: 0.00025 },
  7832. fogNear: { value: 1 },
  7833. fogFar: { value: 2000 },
  7834. fogColor: { value: new Color( 0xffffff ) }
  7835. },
  7836. lights: {
  7837. ambientLightColor: { value: [] },
  7838. lightProbe: { value: [] },
  7839. directionalLights: { value: [], properties: {
  7840. direction: {},
  7841. color: {}
  7842. } },
  7843. directionalLightShadows: { value: [], properties: {
  7844. shadowBias: {},
  7845. shadowNormalBias: {},
  7846. shadowRadius: {},
  7847. shadowMapSize: {}
  7848. } },
  7849. directionalShadowMap: { value: [] },
  7850. directionalShadowMatrix: { value: [] },
  7851. spotLights: { value: [], properties: {
  7852. color: {},
  7853. position: {},
  7854. direction: {},
  7855. distance: {},
  7856. coneCos: {},
  7857. penumbraCos: {},
  7858. decay: {}
  7859. } },
  7860. spotLightShadows: { value: [], properties: {
  7861. shadowBias: {},
  7862. shadowNormalBias: {},
  7863. shadowRadius: {},
  7864. shadowMapSize: {}
  7865. } },
  7866. spotShadowMap: { value: [] },
  7867. spotShadowMatrix: { value: [] },
  7868. pointLights: { value: [], properties: {
  7869. color: {},
  7870. position: {},
  7871. decay: {},
  7872. distance: {}
  7873. } },
  7874. pointLightShadows: { value: [], properties: {
  7875. shadowBias: {},
  7876. shadowNormalBias: {},
  7877. shadowRadius: {},
  7878. shadowMapSize: {},
  7879. shadowCameraNear: {},
  7880. shadowCameraFar: {}
  7881. } },
  7882. pointShadowMap: { value: [] },
  7883. pointShadowMatrix: { value: [] },
  7884. hemisphereLights: { value: [], properties: {
  7885. direction: {},
  7886. skyColor: {},
  7887. groundColor: {}
  7888. } },
  7889. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  7890. rectAreaLights: { value: [], properties: {
  7891. color: {},
  7892. position: {},
  7893. width: {},
  7894. height: {}
  7895. } },
  7896. ltc_1: { value: null },
  7897. ltc_2: { value: null }
  7898. },
  7899. points: {
  7900. diffuse: { value: new Color( 0xeeeeee ) },
  7901. opacity: { value: 1.0 },
  7902. size: { value: 1.0 },
  7903. scale: { value: 1.0 },
  7904. map: { value: null },
  7905. alphaMap: { value: null },
  7906. uvTransform: { value: new Matrix3() }
  7907. },
  7908. sprite: {
  7909. diffuse: { value: new Color( 0xeeeeee ) },
  7910. opacity: { value: 1.0 },
  7911. center: { value: new Vector2( 0.5, 0.5 ) },
  7912. rotation: { value: 0.0 },
  7913. map: { value: null },
  7914. alphaMap: { value: null },
  7915. uvTransform: { value: new Matrix3() }
  7916. }
  7917. };
  7918. const ShaderLib = {
  7919. basic: {
  7920. uniforms: mergeUniforms( [
  7921. UniformsLib.common,
  7922. UniformsLib.specularmap,
  7923. UniformsLib.envmap,
  7924. UniformsLib.aomap,
  7925. UniformsLib.lightmap,
  7926. UniformsLib.fog
  7927. ] ),
  7928. vertexShader: ShaderChunk.meshbasic_vert,
  7929. fragmentShader: ShaderChunk.meshbasic_frag
  7930. },
  7931. lambert: {
  7932. uniforms: mergeUniforms( [
  7933. UniformsLib.common,
  7934. UniformsLib.specularmap,
  7935. UniformsLib.envmap,
  7936. UniformsLib.aomap,
  7937. UniformsLib.lightmap,
  7938. UniformsLib.emissivemap,
  7939. UniformsLib.fog,
  7940. UniformsLib.lights,
  7941. {
  7942. emissive: { value: new Color( 0x000000 ) }
  7943. }
  7944. ] ),
  7945. vertexShader: ShaderChunk.meshlambert_vert,
  7946. fragmentShader: ShaderChunk.meshlambert_frag
  7947. },
  7948. phong: {
  7949. uniforms: mergeUniforms( [
  7950. UniformsLib.common,
  7951. UniformsLib.specularmap,
  7952. UniformsLib.envmap,
  7953. UniformsLib.aomap,
  7954. UniformsLib.lightmap,
  7955. UniformsLib.emissivemap,
  7956. UniformsLib.bumpmap,
  7957. UniformsLib.normalmap,
  7958. UniformsLib.displacementmap,
  7959. UniformsLib.fog,
  7960. UniformsLib.lights,
  7961. {
  7962. emissive: { value: new Color( 0x000000 ) },
  7963. specular: { value: new Color( 0x111111 ) },
  7964. shininess: { value: 30 }
  7965. }
  7966. ] ),
  7967. vertexShader: ShaderChunk.meshphong_vert,
  7968. fragmentShader: ShaderChunk.meshphong_frag
  7969. },
  7970. standard: {
  7971. uniforms: mergeUniforms( [
  7972. UniformsLib.common,
  7973. UniformsLib.envmap,
  7974. UniformsLib.aomap,
  7975. UniformsLib.lightmap,
  7976. UniformsLib.emissivemap,
  7977. UniformsLib.bumpmap,
  7978. UniformsLib.normalmap,
  7979. UniformsLib.displacementmap,
  7980. UniformsLib.roughnessmap,
  7981. UniformsLib.metalnessmap,
  7982. UniformsLib.fog,
  7983. UniformsLib.lights,
  7984. {
  7985. emissive: { value: new Color( 0x000000 ) },
  7986. roughness: { value: 1.0 },
  7987. metalness: { value: 0.0 },
  7988. envMapIntensity: { value: 1 } // temporary
  7989. }
  7990. ] ),
  7991. vertexShader: ShaderChunk.meshphysical_vert,
  7992. fragmentShader: ShaderChunk.meshphysical_frag
  7993. },
  7994. toon: {
  7995. uniforms: mergeUniforms( [
  7996. UniformsLib.common,
  7997. UniformsLib.aomap,
  7998. UniformsLib.lightmap,
  7999. UniformsLib.emissivemap,
  8000. UniformsLib.bumpmap,
  8001. UniformsLib.normalmap,
  8002. UniformsLib.displacementmap,
  8003. UniformsLib.gradientmap,
  8004. UniformsLib.fog,
  8005. UniformsLib.lights,
  8006. {
  8007. emissive: { value: new Color( 0x000000 ) }
  8008. }
  8009. ] ),
  8010. vertexShader: ShaderChunk.meshtoon_vert,
  8011. fragmentShader: ShaderChunk.meshtoon_frag
  8012. },
  8013. matcap: {
  8014. uniforms: mergeUniforms( [
  8015. UniformsLib.common,
  8016. UniformsLib.bumpmap,
  8017. UniformsLib.normalmap,
  8018. UniformsLib.displacementmap,
  8019. UniformsLib.fog,
  8020. {
  8021. matcap: { value: null }
  8022. }
  8023. ] ),
  8024. vertexShader: ShaderChunk.meshmatcap_vert,
  8025. fragmentShader: ShaderChunk.meshmatcap_frag
  8026. },
  8027. points: {
  8028. uniforms: mergeUniforms( [
  8029. UniformsLib.points,
  8030. UniformsLib.fog
  8031. ] ),
  8032. vertexShader: ShaderChunk.points_vert,
  8033. fragmentShader: ShaderChunk.points_frag
  8034. },
  8035. dashed: {
  8036. uniforms: mergeUniforms( [
  8037. UniformsLib.common,
  8038. UniformsLib.fog,
  8039. {
  8040. scale: { value: 1 },
  8041. dashSize: { value: 1 },
  8042. totalSize: { value: 2 }
  8043. }
  8044. ] ),
  8045. vertexShader: ShaderChunk.linedashed_vert,
  8046. fragmentShader: ShaderChunk.linedashed_frag
  8047. },
  8048. depth: {
  8049. uniforms: mergeUniforms( [
  8050. UniformsLib.common,
  8051. UniformsLib.displacementmap
  8052. ] ),
  8053. vertexShader: ShaderChunk.depth_vert,
  8054. fragmentShader: ShaderChunk.depth_frag
  8055. },
  8056. normal: {
  8057. uniforms: mergeUniforms( [
  8058. UniformsLib.common,
  8059. UniformsLib.bumpmap,
  8060. UniformsLib.normalmap,
  8061. UniformsLib.displacementmap,
  8062. {
  8063. opacity: { value: 1.0 }
  8064. }
  8065. ] ),
  8066. vertexShader: ShaderChunk.normal_vert,
  8067. fragmentShader: ShaderChunk.normal_frag
  8068. },
  8069. sprite: {
  8070. uniforms: mergeUniforms( [
  8071. UniformsLib.sprite,
  8072. UniformsLib.fog
  8073. ] ),
  8074. vertexShader: ShaderChunk.sprite_vert,
  8075. fragmentShader: ShaderChunk.sprite_frag
  8076. },
  8077. background: {
  8078. uniforms: {
  8079. uvTransform: { value: new Matrix3() },
  8080. t2D: { value: null },
  8081. },
  8082. vertexShader: ShaderChunk.background_vert,
  8083. fragmentShader: ShaderChunk.background_frag
  8084. },
  8085. /* -------------------------------------------------------------------------
  8086. // Cube map shader
  8087. ------------------------------------------------------------------------- */
  8088. cube: {
  8089. uniforms: mergeUniforms( [
  8090. UniformsLib.envmap,
  8091. {
  8092. opacity: { value: 1.0 }
  8093. }
  8094. ] ),
  8095. vertexShader: ShaderChunk.cube_vert,
  8096. fragmentShader: ShaderChunk.cube_frag
  8097. },
  8098. equirect: {
  8099. uniforms: {
  8100. tEquirect: { value: null },
  8101. },
  8102. vertexShader: ShaderChunk.equirect_vert,
  8103. fragmentShader: ShaderChunk.equirect_frag
  8104. },
  8105. distanceRGBA: {
  8106. uniforms: mergeUniforms( [
  8107. UniformsLib.common,
  8108. UniformsLib.displacementmap,
  8109. {
  8110. referencePosition: { value: new Vector3() },
  8111. nearDistance: { value: 1 },
  8112. farDistance: { value: 1000 }
  8113. }
  8114. ] ),
  8115. vertexShader: ShaderChunk.distanceRGBA_vert,
  8116. fragmentShader: ShaderChunk.distanceRGBA_frag
  8117. },
  8118. shadow: {
  8119. uniforms: mergeUniforms( [
  8120. UniformsLib.lights,
  8121. UniformsLib.fog,
  8122. {
  8123. color: { value: new Color( 0x00000 ) },
  8124. opacity: { value: 1.0 }
  8125. },
  8126. ] ),
  8127. vertexShader: ShaderChunk.shadow_vert,
  8128. fragmentShader: ShaderChunk.shadow_frag
  8129. }
  8130. };
  8131. ShaderLib.physical = {
  8132. uniforms: mergeUniforms( [
  8133. ShaderLib.standard.uniforms,
  8134. {
  8135. clearcoat: { value: 0 },
  8136. clearcoatMap: { value: null },
  8137. clearcoatRoughness: { value: 0 },
  8138. clearcoatRoughnessMap: { value: null },
  8139. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  8140. clearcoatNormalMap: { value: null },
  8141. sheen: { value: new Color( 0x000000 ) },
  8142. transmission: { value: 0 },
  8143. transmissionMap: { value: null },
  8144. }
  8145. ] ),
  8146. vertexShader: ShaderChunk.meshphysical_vert,
  8147. fragmentShader: ShaderChunk.meshphysical_frag
  8148. };
  8149. function WebGLBackground( renderer, cubemaps, state, objects, premultipliedAlpha ) {
  8150. const clearColor = new Color( 0x000000 );
  8151. let clearAlpha = 0;
  8152. let planeMesh;
  8153. let boxMesh;
  8154. let currentBackground = null;
  8155. let currentBackgroundVersion = 0;
  8156. let currentTonemapping = null;
  8157. function render( renderList, scene, camera, forceClear ) {
  8158. let background = scene.isScene === true ? scene.background : null;
  8159. if ( background && background.isTexture ) {
  8160. background = cubemaps.get( background );
  8161. }
  8162. // Ignore background in AR
  8163. // TODO: Reconsider this.
  8164. const xr = renderer.xr;
  8165. const session = xr.getSession && xr.getSession();
  8166. if ( session && session.environmentBlendMode === 'additive' ) {
  8167. background = null;
  8168. }
  8169. if ( background === null ) {
  8170. setClear( clearColor, clearAlpha );
  8171. } else if ( background && background.isColor ) {
  8172. setClear( background, 1 );
  8173. forceClear = true;
  8174. }
  8175. if ( renderer.autoClear || forceClear ) {
  8176. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8177. }
  8178. if ( background && ( background.isCubeTexture || background.mapping === CubeUVReflectionMapping ) ) {
  8179. if ( boxMesh === undefined ) {
  8180. boxMesh = new Mesh(
  8181. new BoxGeometry( 1, 1, 1 ),
  8182. new ShaderMaterial( {
  8183. name: 'BackgroundCubeMaterial',
  8184. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8185. vertexShader: ShaderLib.cube.vertexShader,
  8186. fragmentShader: ShaderLib.cube.fragmentShader,
  8187. side: BackSide,
  8188. depthTest: false,
  8189. depthWrite: false,
  8190. fog: false
  8191. } )
  8192. );
  8193. boxMesh.geometry.deleteAttribute( 'normal' );
  8194. boxMesh.geometry.deleteAttribute( 'uv' );
  8195. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8196. this.matrixWorld.copyPosition( camera.matrixWorld );
  8197. };
  8198. // enable code injection for non-built-in material
  8199. Object.defineProperty( boxMesh.material, 'envMap', {
  8200. get: function () {
  8201. return this.uniforms.envMap.value;
  8202. }
  8203. } );
  8204. objects.update( boxMesh );
  8205. }
  8206. boxMesh.material.uniforms.envMap.value = background;
  8207. boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background._needsFlipEnvMap ) ? - 1 : 1;
  8208. if ( currentBackground !== background ||
  8209. currentBackgroundVersion !== background.version ||
  8210. currentTonemapping !== renderer.toneMapping ) {
  8211. boxMesh.material.needsUpdate = true;
  8212. currentBackground = background;
  8213. currentBackgroundVersion = background.version;
  8214. currentTonemapping = renderer.toneMapping;
  8215. }
  8216. // push to the pre-sorted opaque render list
  8217. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8218. } else if ( background && background.isTexture ) {
  8219. if ( planeMesh === undefined ) {
  8220. planeMesh = new Mesh(
  8221. new PlaneGeometry( 2, 2 ),
  8222. new ShaderMaterial( {
  8223. name: 'BackgroundMaterial',
  8224. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8225. vertexShader: ShaderLib.background.vertexShader,
  8226. fragmentShader: ShaderLib.background.fragmentShader,
  8227. side: FrontSide,
  8228. depthTest: false,
  8229. depthWrite: false,
  8230. fog: false
  8231. } )
  8232. );
  8233. planeMesh.geometry.deleteAttribute( 'normal' );
  8234. // enable code injection for non-built-in material
  8235. Object.defineProperty( planeMesh.material, 'map', {
  8236. get: function () {
  8237. return this.uniforms.t2D.value;
  8238. }
  8239. } );
  8240. objects.update( planeMesh );
  8241. }
  8242. planeMesh.material.uniforms.t2D.value = background;
  8243. if ( background.matrixAutoUpdate === true ) {
  8244. background.updateMatrix();
  8245. }
  8246. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8247. if ( currentBackground !== background ||
  8248. currentBackgroundVersion !== background.version ||
  8249. currentTonemapping !== renderer.toneMapping ) {
  8250. planeMesh.material.needsUpdate = true;
  8251. currentBackground = background;
  8252. currentBackgroundVersion = background.version;
  8253. currentTonemapping = renderer.toneMapping;
  8254. }
  8255. // push to the pre-sorted opaque render list
  8256. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8257. }
  8258. }
  8259. function setClear( color, alpha ) {
  8260. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8261. }
  8262. return {
  8263. getClearColor: function () {
  8264. return clearColor;
  8265. },
  8266. setClearColor: function ( color, alpha = 1 ) {
  8267. clearColor.set( color );
  8268. clearAlpha = alpha;
  8269. setClear( clearColor, clearAlpha );
  8270. },
  8271. getClearAlpha: function () {
  8272. return clearAlpha;
  8273. },
  8274. setClearAlpha: function ( alpha ) {
  8275. clearAlpha = alpha;
  8276. setClear( clearColor, clearAlpha );
  8277. },
  8278. render: render
  8279. };
  8280. }
  8281. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  8282. const maxVertexAttributes = gl.getParameter( 34921 );
  8283. const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  8284. const vaoAvailable = capabilities.isWebGL2 || extension !== null;
  8285. const bindingStates = {};
  8286. const defaultState = createBindingState( null );
  8287. let currentState = defaultState;
  8288. function setup( object, material, program, geometry, index ) {
  8289. let updateBuffers = false;
  8290. if ( vaoAvailable ) {
  8291. const state = getBindingState( geometry, program, material );
  8292. if ( currentState !== state ) {
  8293. currentState = state;
  8294. bindVertexArrayObject( currentState.object );
  8295. }
  8296. updateBuffers = needsUpdate( geometry, index );
  8297. if ( updateBuffers ) saveCache( geometry, index );
  8298. } else {
  8299. const wireframe = ( material.wireframe === true );
  8300. if ( currentState.geometry !== geometry.id ||
  8301. currentState.program !== program.id ||
  8302. currentState.wireframe !== wireframe ) {
  8303. currentState.geometry = geometry.id;
  8304. currentState.program = program.id;
  8305. currentState.wireframe = wireframe;
  8306. updateBuffers = true;
  8307. }
  8308. }
  8309. if ( object.isInstancedMesh === true ) {
  8310. updateBuffers = true;
  8311. }
  8312. if ( index !== null ) {
  8313. attributes.update( index, 34963 );
  8314. }
  8315. if ( updateBuffers ) {
  8316. setupVertexAttributes( object, material, program, geometry );
  8317. if ( index !== null ) {
  8318. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  8319. }
  8320. }
  8321. }
  8322. function createVertexArrayObject() {
  8323. if ( capabilities.isWebGL2 ) return gl.createVertexArray();
  8324. return extension.createVertexArrayOES();
  8325. }
  8326. function bindVertexArrayObject( vao ) {
  8327. if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
  8328. return extension.bindVertexArrayOES( vao );
  8329. }
  8330. function deleteVertexArrayObject( vao ) {
  8331. if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
  8332. return extension.deleteVertexArrayOES( vao );
  8333. }
  8334. function getBindingState( geometry, program, material ) {
  8335. const wireframe = ( material.wireframe === true );
  8336. let programMap = bindingStates[ geometry.id ];
  8337. if ( programMap === undefined ) {
  8338. programMap = {};
  8339. bindingStates[ geometry.id ] = programMap;
  8340. }
  8341. let stateMap = programMap[ program.id ];
  8342. if ( stateMap === undefined ) {
  8343. stateMap = {};
  8344. programMap[ program.id ] = stateMap;
  8345. }
  8346. let state = stateMap[ wireframe ];
  8347. if ( state === undefined ) {
  8348. state = createBindingState( createVertexArrayObject() );
  8349. stateMap[ wireframe ] = state;
  8350. }
  8351. return state;
  8352. }
  8353. function createBindingState( vao ) {
  8354. const newAttributes = [];
  8355. const enabledAttributes = [];
  8356. const attributeDivisors = [];
  8357. for ( let i = 0; i < maxVertexAttributes; i ++ ) {
  8358. newAttributes[ i ] = 0;
  8359. enabledAttributes[ i ] = 0;
  8360. attributeDivisors[ i ] = 0;
  8361. }
  8362. return {
  8363. // for backward compatibility on non-VAO support browser
  8364. geometry: null,
  8365. program: null,
  8366. wireframe: false,
  8367. newAttributes: newAttributes,
  8368. enabledAttributes: enabledAttributes,
  8369. attributeDivisors: attributeDivisors,
  8370. object: vao,
  8371. attributes: {},
  8372. index: null
  8373. };
  8374. }
  8375. function needsUpdate( geometry, index ) {
  8376. const cachedAttributes = currentState.attributes;
  8377. const geometryAttributes = geometry.attributes;
  8378. let attributesNum = 0;
  8379. for ( const key in geometryAttributes ) {
  8380. const cachedAttribute = cachedAttributes[ key ];
  8381. const geometryAttribute = geometryAttributes[ key ];
  8382. if ( cachedAttribute === undefined ) return true;
  8383. if ( cachedAttribute.attribute !== geometryAttribute ) return true;
  8384. if ( cachedAttribute.data !== geometryAttribute.data ) return true;
  8385. attributesNum ++;
  8386. }
  8387. if ( currentState.attributesNum !== attributesNum ) return true;
  8388. if ( currentState.index !== index ) return true;
  8389. return false;
  8390. }
  8391. function saveCache( geometry, index ) {
  8392. const cache = {};
  8393. const attributes = geometry.attributes;
  8394. let attributesNum = 0;
  8395. for ( const key in attributes ) {
  8396. const attribute = attributes[ key ];
  8397. const data = {};
  8398. data.attribute = attribute;
  8399. if ( attribute.data ) {
  8400. data.data = attribute.data;
  8401. }
  8402. cache[ key ] = data;
  8403. attributesNum ++;
  8404. }
  8405. currentState.attributes = cache;
  8406. currentState.attributesNum = attributesNum;
  8407. currentState.index = index;
  8408. }
  8409. function initAttributes() {
  8410. const newAttributes = currentState.newAttributes;
  8411. for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {
  8412. newAttributes[ i ] = 0;
  8413. }
  8414. }
  8415. function enableAttribute( attribute ) {
  8416. enableAttributeAndDivisor( attribute, 0 );
  8417. }
  8418. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  8419. const newAttributes = currentState.newAttributes;
  8420. const enabledAttributes = currentState.enabledAttributes;
  8421. const attributeDivisors = currentState.attributeDivisors;
  8422. newAttributes[ attribute ] = 1;
  8423. if ( enabledAttributes[ attribute ] === 0 ) {
  8424. gl.enableVertexAttribArray( attribute );
  8425. enabledAttributes[ attribute ] = 1;
  8426. }
  8427. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  8428. const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  8429. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  8430. attributeDivisors[ attribute ] = meshPerAttribute;
  8431. }
  8432. }
  8433. function disableUnusedAttributes() {
  8434. const newAttributes = currentState.newAttributes;
  8435. const enabledAttributes = currentState.enabledAttributes;
  8436. for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  8437. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  8438. gl.disableVertexAttribArray( i );
  8439. enabledAttributes[ i ] = 0;
  8440. }
  8441. }
  8442. }
  8443. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  8444. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  8445. gl.vertexAttribIPointer( index, size, type, stride, offset );
  8446. } else {
  8447. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  8448. }
  8449. }
  8450. function setupVertexAttributes( object, material, program, geometry ) {
  8451. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  8452. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  8453. }
  8454. initAttributes();
  8455. const geometryAttributes = geometry.attributes;
  8456. const programAttributes = program.getAttributes();
  8457. const materialDefaultAttributeValues = material.defaultAttributeValues;
  8458. for ( const name in programAttributes ) {
  8459. const programAttribute = programAttributes[ name ];
  8460. if ( programAttribute >= 0 ) {
  8461. const geometryAttribute = geometryAttributes[ name ];
  8462. if ( geometryAttribute !== undefined ) {
  8463. const normalized = geometryAttribute.normalized;
  8464. const size = geometryAttribute.itemSize;
  8465. const attribute = attributes.get( geometryAttribute );
  8466. // TODO Attribute may not be available on context restore
  8467. if ( attribute === undefined ) continue;
  8468. const buffer = attribute.buffer;
  8469. const type = attribute.type;
  8470. const bytesPerElement = attribute.bytesPerElement;
  8471. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  8472. const data = geometryAttribute.data;
  8473. const stride = data.stride;
  8474. const offset = geometryAttribute.offset;
  8475. if ( data && data.isInstancedInterleavedBuffer ) {
  8476. enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  8477. if ( geometry._maxInstanceCount === undefined ) {
  8478. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  8479. }
  8480. } else {
  8481. enableAttribute( programAttribute );
  8482. }
  8483. gl.bindBuffer( 34962, buffer );
  8484. vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  8485. } else {
  8486. if ( geometryAttribute.isInstancedBufferAttribute ) {
  8487. enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  8488. if ( geometry._maxInstanceCount === undefined ) {
  8489. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  8490. }
  8491. } else {
  8492. enableAttribute( programAttribute );
  8493. }
  8494. gl.bindBuffer( 34962, buffer );
  8495. vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  8496. }
  8497. } else if ( name === 'instanceMatrix' ) {
  8498. const attribute = attributes.get( object.instanceMatrix );
  8499. // TODO Attribute may not be available on context restore
  8500. if ( attribute === undefined ) continue;
  8501. const buffer = attribute.buffer;
  8502. const type = attribute.type;
  8503. enableAttributeAndDivisor( programAttribute + 0, 1 );
  8504. enableAttributeAndDivisor( programAttribute + 1, 1 );
  8505. enableAttributeAndDivisor( programAttribute + 2, 1 );
  8506. enableAttributeAndDivisor( programAttribute + 3, 1 );
  8507. gl.bindBuffer( 34962, buffer );
  8508. gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  8509. gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  8510. gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  8511. gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  8512. } else if ( name === 'instanceColor' ) {
  8513. const attribute = attributes.get( object.instanceColor );
  8514. // TODO Attribute may not be available on context restore
  8515. if ( attribute === undefined ) continue;
  8516. const buffer = attribute.buffer;
  8517. const type = attribute.type;
  8518. enableAttributeAndDivisor( programAttribute, 1 );
  8519. gl.bindBuffer( 34962, buffer );
  8520. gl.vertexAttribPointer( programAttribute, 3, type, false, 12, 0 );
  8521. } else if ( materialDefaultAttributeValues !== undefined ) {
  8522. const value = materialDefaultAttributeValues[ name ];
  8523. if ( value !== undefined ) {
  8524. switch ( value.length ) {
  8525. case 2:
  8526. gl.vertexAttrib2fv( programAttribute, value );
  8527. break;
  8528. case 3:
  8529. gl.vertexAttrib3fv( programAttribute, value );
  8530. break;
  8531. case 4:
  8532. gl.vertexAttrib4fv( programAttribute, value );
  8533. break;
  8534. default:
  8535. gl.vertexAttrib1fv( programAttribute, value );
  8536. }
  8537. }
  8538. }
  8539. }
  8540. }
  8541. disableUnusedAttributes();
  8542. }
  8543. function dispose() {
  8544. reset();
  8545. for ( const geometryId in bindingStates ) {
  8546. const programMap = bindingStates[ geometryId ];
  8547. for ( const programId in programMap ) {
  8548. const stateMap = programMap[ programId ];
  8549. for ( const wireframe in stateMap ) {
  8550. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8551. delete stateMap[ wireframe ];
  8552. }
  8553. delete programMap[ programId ];
  8554. }
  8555. delete bindingStates[ geometryId ];
  8556. }
  8557. }
  8558. function releaseStatesOfGeometry( geometry ) {
  8559. if ( bindingStates[ geometry.id ] === undefined ) return;
  8560. const programMap = bindingStates[ geometry.id ];
  8561. for ( const programId in programMap ) {
  8562. const stateMap = programMap[ programId ];
  8563. for ( const wireframe in stateMap ) {
  8564. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8565. delete stateMap[ wireframe ];
  8566. }
  8567. delete programMap[ programId ];
  8568. }
  8569. delete bindingStates[ geometry.id ];
  8570. }
  8571. function releaseStatesOfProgram( program ) {
  8572. for ( const geometryId in bindingStates ) {
  8573. const programMap = bindingStates[ geometryId ];
  8574. if ( programMap[ program.id ] === undefined ) continue;
  8575. const stateMap = programMap[ program.id ];
  8576. for ( const wireframe in stateMap ) {
  8577. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8578. delete stateMap[ wireframe ];
  8579. }
  8580. delete programMap[ program.id ];
  8581. }
  8582. }
  8583. function reset() {
  8584. resetDefaultState();
  8585. if ( currentState === defaultState ) return;
  8586. currentState = defaultState;
  8587. bindVertexArrayObject( currentState.object );
  8588. }
  8589. // for backward-compatilibity
  8590. function resetDefaultState() {
  8591. defaultState.geometry = null;
  8592. defaultState.program = null;
  8593. defaultState.wireframe = false;
  8594. }
  8595. return {
  8596. setup: setup,
  8597. reset: reset,
  8598. resetDefaultState: resetDefaultState,
  8599. dispose: dispose,
  8600. releaseStatesOfGeometry: releaseStatesOfGeometry,
  8601. releaseStatesOfProgram: releaseStatesOfProgram,
  8602. initAttributes: initAttributes,
  8603. enableAttribute: enableAttribute,
  8604. disableUnusedAttributes: disableUnusedAttributes
  8605. };
  8606. }
  8607. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8608. const isWebGL2 = capabilities.isWebGL2;
  8609. let mode;
  8610. function setMode( value ) {
  8611. mode = value;
  8612. }
  8613. function render( start, count ) {
  8614. gl.drawArrays( mode, start, count );
  8615. info.update( count, mode, 1 );
  8616. }
  8617. function renderInstances( start, count, primcount ) {
  8618. if ( primcount === 0 ) return;
  8619. let extension, methodName;
  8620. if ( isWebGL2 ) {
  8621. extension = gl;
  8622. methodName = 'drawArraysInstanced';
  8623. } else {
  8624. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8625. methodName = 'drawArraysInstancedANGLE';
  8626. if ( extension === null ) {
  8627. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8628. return;
  8629. }
  8630. }
  8631. extension[ methodName ]( mode, start, count, primcount );
  8632. info.update( count, mode, primcount );
  8633. }
  8634. //
  8635. this.setMode = setMode;
  8636. this.render = render;
  8637. this.renderInstances = renderInstances;
  8638. }
  8639. function WebGLCapabilities( gl, extensions, parameters ) {
  8640. let maxAnisotropy;
  8641. function getMaxAnisotropy() {
  8642. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8643. if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
  8644. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8645. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8646. } else {
  8647. maxAnisotropy = 0;
  8648. }
  8649. return maxAnisotropy;
  8650. }
  8651. function getMaxPrecision( precision ) {
  8652. if ( precision === 'highp' ) {
  8653. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8654. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8655. return 'highp';
  8656. }
  8657. precision = 'mediump';
  8658. }
  8659. if ( precision === 'mediump' ) {
  8660. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8661. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8662. return 'mediump';
  8663. }
  8664. }
  8665. return 'lowp';
  8666. }
  8667. /* eslint-disable no-undef */
  8668. const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  8669. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  8670. /* eslint-enable no-undef */
  8671. let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8672. const maxPrecision = getMaxPrecision( precision );
  8673. if ( maxPrecision !== precision ) {
  8674. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8675. precision = maxPrecision;
  8676. }
  8677. const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8678. const maxTextures = gl.getParameter( 34930 );
  8679. const maxVertexTextures = gl.getParameter( 35660 );
  8680. const maxTextureSize = gl.getParameter( 3379 );
  8681. const maxCubemapSize = gl.getParameter( 34076 );
  8682. const maxAttributes = gl.getParameter( 34921 );
  8683. const maxVertexUniforms = gl.getParameter( 36347 );
  8684. const maxVaryings = gl.getParameter( 36348 );
  8685. const maxFragmentUniforms = gl.getParameter( 36349 );
  8686. const vertexTextures = maxVertexTextures > 0;
  8687. const floatFragmentTextures = isWebGL2 || extensions.has( 'OES_texture_float' );
  8688. const floatVertexTextures = vertexTextures && floatFragmentTextures;
  8689. const maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8690. return {
  8691. isWebGL2: isWebGL2,
  8692. getMaxAnisotropy: getMaxAnisotropy,
  8693. getMaxPrecision: getMaxPrecision,
  8694. precision: precision,
  8695. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8696. maxTextures: maxTextures,
  8697. maxVertexTextures: maxVertexTextures,
  8698. maxTextureSize: maxTextureSize,
  8699. maxCubemapSize: maxCubemapSize,
  8700. maxAttributes: maxAttributes,
  8701. maxVertexUniforms: maxVertexUniforms,
  8702. maxVaryings: maxVaryings,
  8703. maxFragmentUniforms: maxFragmentUniforms,
  8704. vertexTextures: vertexTextures,
  8705. floatFragmentTextures: floatFragmentTextures,
  8706. floatVertexTextures: floatVertexTextures,
  8707. maxSamples: maxSamples
  8708. };
  8709. }
  8710. function WebGLClipping( properties ) {
  8711. const scope = this;
  8712. let globalState = null,
  8713. numGlobalPlanes = 0,
  8714. localClippingEnabled = false,
  8715. renderingShadows = false;
  8716. const plane = new Plane(),
  8717. viewNormalMatrix = new Matrix3(),
  8718. uniform = { value: null, needsUpdate: false };
  8719. this.uniform = uniform;
  8720. this.numPlanes = 0;
  8721. this.numIntersection = 0;
  8722. this.init = function ( planes, enableLocalClipping, camera ) {
  8723. const enabled =
  8724. planes.length !== 0 ||
  8725. enableLocalClipping ||
  8726. // enable state of previous frame - the clipping code has to
  8727. // run another frame in order to reset the state:
  8728. numGlobalPlanes !== 0 ||
  8729. localClippingEnabled;
  8730. localClippingEnabled = enableLocalClipping;
  8731. globalState = projectPlanes( planes, camera, 0 );
  8732. numGlobalPlanes = planes.length;
  8733. return enabled;
  8734. };
  8735. this.beginShadows = function () {
  8736. renderingShadows = true;
  8737. projectPlanes( null );
  8738. };
  8739. this.endShadows = function () {
  8740. renderingShadows = false;
  8741. resetGlobalState();
  8742. };
  8743. this.setState = function ( material, camera, useCache ) {
  8744. const planes = material.clippingPlanes,
  8745. clipIntersection = material.clipIntersection,
  8746. clipShadows = material.clipShadows;
  8747. const materialProperties = properties.get( material );
  8748. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8749. // there's no local clipping
  8750. if ( renderingShadows ) {
  8751. // there's no global clipping
  8752. projectPlanes( null );
  8753. } else {
  8754. resetGlobalState();
  8755. }
  8756. } else {
  8757. const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8758. lGlobal = nGlobal * 4;
  8759. let dstArray = materialProperties.clippingState || null;
  8760. uniform.value = dstArray; // ensure unique state
  8761. dstArray = projectPlanes( planes, camera, lGlobal, useCache );
  8762. for ( let i = 0; i !== lGlobal; ++ i ) {
  8763. dstArray[ i ] = globalState[ i ];
  8764. }
  8765. materialProperties.clippingState = dstArray;
  8766. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8767. this.numPlanes += nGlobal;
  8768. }
  8769. };
  8770. function resetGlobalState() {
  8771. if ( uniform.value !== globalState ) {
  8772. uniform.value = globalState;
  8773. uniform.needsUpdate = numGlobalPlanes > 0;
  8774. }
  8775. scope.numPlanes = numGlobalPlanes;
  8776. scope.numIntersection = 0;
  8777. }
  8778. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8779. const nPlanes = planes !== null ? planes.length : 0;
  8780. let dstArray = null;
  8781. if ( nPlanes !== 0 ) {
  8782. dstArray = uniform.value;
  8783. if ( skipTransform !== true || dstArray === null ) {
  8784. const flatSize = dstOffset + nPlanes * 4,
  8785. viewMatrix = camera.matrixWorldInverse;
  8786. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8787. if ( dstArray === null || dstArray.length < flatSize ) {
  8788. dstArray = new Float32Array( flatSize );
  8789. }
  8790. for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8791. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8792. plane.normal.toArray( dstArray, i4 );
  8793. dstArray[ i4 + 3 ] = plane.constant;
  8794. }
  8795. }
  8796. uniform.value = dstArray;
  8797. uniform.needsUpdate = true;
  8798. }
  8799. scope.numPlanes = nPlanes;
  8800. scope.numIntersection = 0;
  8801. return dstArray;
  8802. }
  8803. }
  8804. function WebGLCubeMaps( renderer ) {
  8805. let cubemaps = new WeakMap();
  8806. function mapTextureMapping( texture, mapping ) {
  8807. if ( mapping === EquirectangularReflectionMapping ) {
  8808. texture.mapping = CubeReflectionMapping;
  8809. } else if ( mapping === EquirectangularRefractionMapping ) {
  8810. texture.mapping = CubeRefractionMapping;
  8811. }
  8812. return texture;
  8813. }
  8814. function get( texture ) {
  8815. if ( texture && texture.isTexture ) {
  8816. const mapping = texture.mapping;
  8817. if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
  8818. if ( cubemaps.has( texture ) ) {
  8819. const cubemap = cubemaps.get( texture ).texture;
  8820. return mapTextureMapping( cubemap, texture.mapping );
  8821. } else {
  8822. const image = texture.image;
  8823. if ( image && image.height > 0 ) {
  8824. const currentRenderTarget = renderer.getRenderTarget();
  8825. const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
  8826. renderTarget.fromEquirectangularTexture( renderer, texture );
  8827. cubemaps.set( texture, renderTarget );
  8828. renderer.setRenderTarget( currentRenderTarget );
  8829. texture.addEventListener( 'dispose', onTextureDispose );
  8830. return mapTextureMapping( renderTarget.texture, texture.mapping );
  8831. } else {
  8832. // image not yet ready. try the conversion next frame
  8833. return null;
  8834. }
  8835. }
  8836. }
  8837. }
  8838. return texture;
  8839. }
  8840. function onTextureDispose( event ) {
  8841. const texture = event.target;
  8842. texture.removeEventListener( 'dispose', onTextureDispose );
  8843. const cubemap = cubemaps.get( texture );
  8844. if ( cubemap !== undefined ) {
  8845. cubemaps.delete( texture );
  8846. cubemap.dispose();
  8847. }
  8848. }
  8849. function dispose() {
  8850. cubemaps = new WeakMap();
  8851. }
  8852. return {
  8853. get: get,
  8854. dispose: dispose
  8855. };
  8856. }
  8857. function WebGLExtensions( gl ) {
  8858. const extensions = {};
  8859. function getExtension( name ) {
  8860. if ( extensions[ name ] !== undefined ) {
  8861. return extensions[ name ];
  8862. }
  8863. let extension;
  8864. switch ( name ) {
  8865. case 'WEBGL_depth_texture':
  8866. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  8867. break;
  8868. case 'EXT_texture_filter_anisotropic':
  8869. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  8870. break;
  8871. case 'WEBGL_compressed_texture_s3tc':
  8872. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  8873. break;
  8874. case 'WEBGL_compressed_texture_pvrtc':
  8875. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  8876. break;
  8877. default:
  8878. extension = gl.getExtension( name );
  8879. }
  8880. extensions[ name ] = extension;
  8881. return extension;
  8882. }
  8883. return {
  8884. has: function ( name ) {
  8885. return getExtension( name ) !== null;
  8886. },
  8887. init: function ( capabilities ) {
  8888. if ( capabilities.isWebGL2 ) {
  8889. getExtension( 'EXT_color_buffer_float' );
  8890. } else {
  8891. getExtension( 'WEBGL_depth_texture' );
  8892. getExtension( 'OES_texture_float' );
  8893. getExtension( 'OES_texture_half_float' );
  8894. getExtension( 'OES_texture_half_float_linear' );
  8895. getExtension( 'OES_standard_derivatives' );
  8896. getExtension( 'OES_element_index_uint' );
  8897. getExtension( 'OES_vertex_array_object' );
  8898. getExtension( 'ANGLE_instanced_arrays' );
  8899. }
  8900. getExtension( 'OES_texture_float_linear' );
  8901. getExtension( 'EXT_color_buffer_half_float' );
  8902. },
  8903. get: function ( name ) {
  8904. const extension = getExtension( name );
  8905. if ( extension === null ) {
  8906. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  8907. }
  8908. return extension;
  8909. }
  8910. };
  8911. }
  8912. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  8913. const geometries = {};
  8914. const wireframeAttributes = new WeakMap();
  8915. function onGeometryDispose( event ) {
  8916. const geometry = event.target;
  8917. if ( geometry.index !== null ) {
  8918. attributes.remove( geometry.index );
  8919. }
  8920. for ( const name in geometry.attributes ) {
  8921. attributes.remove( geometry.attributes[ name ] );
  8922. }
  8923. geometry.removeEventListener( 'dispose', onGeometryDispose );
  8924. delete geometries[ geometry.id ];
  8925. const attribute = wireframeAttributes.get( geometry );
  8926. if ( attribute ) {
  8927. attributes.remove( attribute );
  8928. wireframeAttributes.delete( geometry );
  8929. }
  8930. bindingStates.releaseStatesOfGeometry( geometry );
  8931. if ( geometry.isInstancedBufferGeometry === true ) {
  8932. delete geometry._maxInstanceCount;
  8933. }
  8934. //
  8935. info.memory.geometries --;
  8936. }
  8937. function get( object, geometry ) {
  8938. if ( geometries[ geometry.id ] === true ) return geometry;
  8939. geometry.addEventListener( 'dispose', onGeometryDispose );
  8940. geometries[ geometry.id ] = true;
  8941. info.memory.geometries ++;
  8942. return geometry;
  8943. }
  8944. function update( geometry ) {
  8945. const geometryAttributes = geometry.attributes;
  8946. // Updating index buffer in VAO now. See WebGLBindingStates.
  8947. for ( const name in geometryAttributes ) {
  8948. attributes.update( geometryAttributes[ name ], 34962 );
  8949. }
  8950. // morph targets
  8951. const morphAttributes = geometry.morphAttributes;
  8952. for ( const name in morphAttributes ) {
  8953. const array = morphAttributes[ name ];
  8954. for ( let i = 0, l = array.length; i < l; i ++ ) {
  8955. attributes.update( array[ i ], 34962 );
  8956. }
  8957. }
  8958. }
  8959. function updateWireframeAttribute( geometry ) {
  8960. const indices = [];
  8961. const geometryIndex = geometry.index;
  8962. const geometryPosition = geometry.attributes.position;
  8963. let version = 0;
  8964. if ( geometryIndex !== null ) {
  8965. const array = geometryIndex.array;
  8966. version = geometryIndex.version;
  8967. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  8968. const a = array[ i + 0 ];
  8969. const b = array[ i + 1 ];
  8970. const c = array[ i + 2 ];
  8971. indices.push( a, b, b, c, c, a );
  8972. }
  8973. } else {
  8974. const array = geometryPosition.array;
  8975. version = geometryPosition.version;
  8976. for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  8977. const a = i + 0;
  8978. const b = i + 1;
  8979. const c = i + 2;
  8980. indices.push( a, b, b, c, c, a );
  8981. }
  8982. }
  8983. const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  8984. attribute.version = version;
  8985. // Updating index buffer in VAO now. See WebGLBindingStates
  8986. //
  8987. const previousAttribute = wireframeAttributes.get( geometry );
  8988. if ( previousAttribute ) attributes.remove( previousAttribute );
  8989. //
  8990. wireframeAttributes.set( geometry, attribute );
  8991. }
  8992. function getWireframeAttribute( geometry ) {
  8993. const currentAttribute = wireframeAttributes.get( geometry );
  8994. if ( currentAttribute ) {
  8995. const geometryIndex = geometry.index;
  8996. if ( geometryIndex !== null ) {
  8997. // if the attribute is obsolete, create a new one
  8998. if ( currentAttribute.version < geometryIndex.version ) {
  8999. updateWireframeAttribute( geometry );
  9000. }
  9001. }
  9002. } else {
  9003. updateWireframeAttribute( geometry );
  9004. }
  9005. return wireframeAttributes.get( geometry );
  9006. }
  9007. return {
  9008. get: get,
  9009. update: update,
  9010. getWireframeAttribute: getWireframeAttribute
  9011. };
  9012. }
  9013. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9014. const isWebGL2 = capabilities.isWebGL2;
  9015. let mode;
  9016. function setMode( value ) {
  9017. mode = value;
  9018. }
  9019. let type, bytesPerElement;
  9020. function setIndex( value ) {
  9021. type = value.type;
  9022. bytesPerElement = value.bytesPerElement;
  9023. }
  9024. function render( start, count ) {
  9025. gl.drawElements( mode, count, type, start * bytesPerElement );
  9026. info.update( count, mode, 1 );
  9027. }
  9028. function renderInstances( start, count, primcount ) {
  9029. if ( primcount === 0 ) return;
  9030. let extension, methodName;
  9031. if ( isWebGL2 ) {
  9032. extension = gl;
  9033. methodName = 'drawElementsInstanced';
  9034. } else {
  9035. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9036. methodName = 'drawElementsInstancedANGLE';
  9037. if ( extension === null ) {
  9038. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9039. return;
  9040. }
  9041. }
  9042. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9043. info.update( count, mode, primcount );
  9044. }
  9045. //
  9046. this.setMode = setMode;
  9047. this.setIndex = setIndex;
  9048. this.render = render;
  9049. this.renderInstances = renderInstances;
  9050. }
  9051. function WebGLInfo( gl ) {
  9052. const memory = {
  9053. geometries: 0,
  9054. textures: 0
  9055. };
  9056. const render = {
  9057. frame: 0,
  9058. calls: 0,
  9059. triangles: 0,
  9060. points: 0,
  9061. lines: 0
  9062. };
  9063. function update( count, mode, instanceCount ) {
  9064. render.calls ++;
  9065. switch ( mode ) {
  9066. case 4:
  9067. render.triangles += instanceCount * ( count / 3 );
  9068. break;
  9069. case 1:
  9070. render.lines += instanceCount * ( count / 2 );
  9071. break;
  9072. case 3:
  9073. render.lines += instanceCount * ( count - 1 );
  9074. break;
  9075. case 2:
  9076. render.lines += instanceCount * count;
  9077. break;
  9078. case 0:
  9079. render.points += instanceCount * count;
  9080. break;
  9081. default:
  9082. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9083. break;
  9084. }
  9085. }
  9086. function reset() {
  9087. render.frame ++;
  9088. render.calls = 0;
  9089. render.triangles = 0;
  9090. render.points = 0;
  9091. render.lines = 0;
  9092. }
  9093. return {
  9094. memory: memory,
  9095. render: render,
  9096. programs: null,
  9097. autoReset: true,
  9098. reset: reset,
  9099. update: update
  9100. };
  9101. }
  9102. function numericalSort( a, b ) {
  9103. return a[ 0 ] - b[ 0 ];
  9104. }
  9105. function absNumericalSort( a, b ) {
  9106. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9107. }
  9108. function WebGLMorphtargets( gl ) {
  9109. const influencesList = {};
  9110. const morphInfluences = new Float32Array( 8 );
  9111. const workInfluences = [];
  9112. for ( let i = 0; i < 8; i ++ ) {
  9113. workInfluences[ i ] = [ i, 0 ];
  9114. }
  9115. function update( object, geometry, material, program ) {
  9116. const objectInfluences = object.morphTargetInfluences;
  9117. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9118. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9119. const length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9120. let influences = influencesList[ geometry.id ];
  9121. if ( influences === undefined ) {
  9122. // initialise list
  9123. influences = [];
  9124. for ( let i = 0; i < length; i ++ ) {
  9125. influences[ i ] = [ i, 0 ];
  9126. }
  9127. influencesList[ geometry.id ] = influences;
  9128. }
  9129. // Collect influences
  9130. for ( let i = 0; i < length; i ++ ) {
  9131. const influence = influences[ i ];
  9132. influence[ 0 ] = i;
  9133. influence[ 1 ] = objectInfluences[ i ];
  9134. }
  9135. influences.sort( absNumericalSort );
  9136. for ( let i = 0; i < 8; i ++ ) {
  9137. if ( i < length && influences[ i ][ 1 ] ) {
  9138. workInfluences[ i ][ 0 ] = influences[ i ][ 0 ];
  9139. workInfluences[ i ][ 1 ] = influences[ i ][ 1 ];
  9140. } else {
  9141. workInfluences[ i ][ 0 ] = Number.MAX_SAFE_INTEGER;
  9142. workInfluences[ i ][ 1 ] = 0;
  9143. }
  9144. }
  9145. workInfluences.sort( numericalSort );
  9146. const morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9147. const morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9148. let morphInfluencesSum = 0;
  9149. for ( let i = 0; i < 8; i ++ ) {
  9150. const influence = workInfluences[ i ];
  9151. const index = influence[ 0 ];
  9152. const value = influence[ 1 ];
  9153. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  9154. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== morphTargets[ index ] ) {
  9155. geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9156. }
  9157. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== morphNormals[ index ] ) {
  9158. geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9159. }
  9160. morphInfluences[ i ] = value;
  9161. morphInfluencesSum += value;
  9162. } else {
  9163. if ( morphTargets && geometry.hasAttribute( 'morphTarget' + i ) === true ) {
  9164. geometry.deleteAttribute( 'morphTarget' + i );
  9165. }
  9166. if ( morphNormals && geometry.hasAttribute( 'morphNormal' + i ) === true ) {
  9167. geometry.deleteAttribute( 'morphNormal' + i );
  9168. }
  9169. morphInfluences[ i ] = 0;
  9170. }
  9171. }
  9172. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9173. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9174. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9175. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9176. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  9177. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9178. }
  9179. return {
  9180. update: update
  9181. };
  9182. }
  9183. function WebGLObjects( gl, geometries, attributes, info ) {
  9184. let updateMap = new WeakMap();
  9185. function update( object ) {
  9186. const frame = info.render.frame;
  9187. const geometry = object.geometry;
  9188. const buffergeometry = geometries.get( object, geometry );
  9189. // Update once per frame
  9190. if ( updateMap.get( buffergeometry ) !== frame ) {
  9191. geometries.update( buffergeometry );
  9192. updateMap.set( buffergeometry, frame );
  9193. }
  9194. if ( object.isInstancedMesh ) {
  9195. if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {
  9196. object.addEventListener( 'dispose', onInstancedMeshDispose );
  9197. }
  9198. attributes.update( object.instanceMatrix, 34962 );
  9199. if ( object.instanceColor !== null ) {
  9200. attributes.update( object.instanceColor, 34962 );
  9201. }
  9202. }
  9203. return buffergeometry;
  9204. }
  9205. function dispose() {
  9206. updateMap = new WeakMap();
  9207. }
  9208. function onInstancedMeshDispose( event ) {
  9209. const instancedMesh = event.target;
  9210. instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
  9211. attributes.remove( instancedMesh.instanceMatrix );
  9212. if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
  9213. }
  9214. return {
  9215. update: update,
  9216. dispose: dispose
  9217. };
  9218. }
  9219. class DataTexture2DArray extends Texture {
  9220. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  9221. super( null );
  9222. this.image = { data, width, height, depth };
  9223. this.magFilter = NearestFilter;
  9224. this.minFilter = NearestFilter;
  9225. this.wrapR = ClampToEdgeWrapping;
  9226. this.generateMipmaps = false;
  9227. this.flipY = false;
  9228. this.needsUpdate = true;
  9229. }
  9230. }
  9231. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9232. class DataTexture3D extends Texture {
  9233. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  9234. // We're going to add .setXXX() methods for setting properties later.
  9235. // Users can still set in DataTexture3D directly.
  9236. //
  9237. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9238. // texture.anisotropy = 16;
  9239. //
  9240. // See #14839
  9241. super( null );
  9242. this.image = { data, width, height, depth };
  9243. this.magFilter = NearestFilter;
  9244. this.minFilter = NearestFilter;
  9245. this.wrapR = ClampToEdgeWrapping;
  9246. this.generateMipmaps = false;
  9247. this.flipY = false;
  9248. this.needsUpdate = true;
  9249. }
  9250. }
  9251. DataTexture3D.prototype.isDataTexture3D = true;
  9252. /**
  9253. * Uniforms of a program.
  9254. * Those form a tree structure with a special top-level container for the root,
  9255. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9256. *
  9257. *
  9258. * Properties of inner nodes including the top-level container:
  9259. *
  9260. * .seq - array of nested uniforms
  9261. * .map - nested uniforms by name
  9262. *
  9263. *
  9264. * Methods of all nodes except the top-level container:
  9265. *
  9266. * .setValue( gl, value, [textures] )
  9267. *
  9268. * uploads a uniform value(s)
  9269. * the 'textures' parameter is needed for sampler uniforms
  9270. *
  9271. *
  9272. * Static methods of the top-level container (textures factorizations):
  9273. *
  9274. * .upload( gl, seq, values, textures )
  9275. *
  9276. * sets uniforms in 'seq' to 'values[id].value'
  9277. *
  9278. * .seqWithValue( seq, values ) : filteredSeq
  9279. *
  9280. * filters 'seq' entries with corresponding entry in values
  9281. *
  9282. *
  9283. * Methods of the top-level container (textures factorizations):
  9284. *
  9285. * .setValue( gl, name, value, textures )
  9286. *
  9287. * sets uniform with name 'name' to 'value'
  9288. *
  9289. * .setOptional( gl, obj, prop )
  9290. *
  9291. * like .set for an optional property of the object
  9292. *
  9293. */
  9294. const emptyTexture = new Texture();
  9295. const emptyTexture2dArray = new DataTexture2DArray();
  9296. const emptyTexture3d = new DataTexture3D();
  9297. const emptyCubeTexture = new CubeTexture();
  9298. // --- Utilities ---
  9299. // Array Caches (provide typed arrays for temporary by size)
  9300. const arrayCacheF32 = [];
  9301. const arrayCacheI32 = [];
  9302. // Float32Array caches used for uploading Matrix uniforms
  9303. const mat4array = new Float32Array( 16 );
  9304. const mat3array = new Float32Array( 9 );
  9305. const mat2array = new Float32Array( 4 );
  9306. // Flattening for arrays of vectors and matrices
  9307. function flatten( array, nBlocks, blockSize ) {
  9308. const firstElem = array[ 0 ];
  9309. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9310. // unoptimized: ! isNaN( firstElem )
  9311. // see http://jacksondunstan.com/articles/983
  9312. const n = nBlocks * blockSize;
  9313. let r = arrayCacheF32[ n ];
  9314. if ( r === undefined ) {
  9315. r = new Float32Array( n );
  9316. arrayCacheF32[ n ] = r;
  9317. }
  9318. if ( nBlocks !== 0 ) {
  9319. firstElem.toArray( r, 0 );
  9320. for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9321. offset += blockSize;
  9322. array[ i ].toArray( r, offset );
  9323. }
  9324. }
  9325. return r;
  9326. }
  9327. function arraysEqual( a, b ) {
  9328. if ( a.length !== b.length ) return false;
  9329. for ( let i = 0, l = a.length; i < l; i ++ ) {
  9330. if ( a[ i ] !== b[ i ] ) return false;
  9331. }
  9332. return true;
  9333. }
  9334. function copyArray( a, b ) {
  9335. for ( let i = 0, l = b.length; i < l; i ++ ) {
  9336. a[ i ] = b[ i ];
  9337. }
  9338. }
  9339. // Texture unit allocation
  9340. function allocTexUnits( textures, n ) {
  9341. let r = arrayCacheI32[ n ];
  9342. if ( r === undefined ) {
  9343. r = new Int32Array( n );
  9344. arrayCacheI32[ n ] = r;
  9345. }
  9346. for ( let i = 0; i !== n; ++ i ) {
  9347. r[ i ] = textures.allocateTextureUnit();
  9348. }
  9349. return r;
  9350. }
  9351. // --- Setters ---
  9352. // Note: Defining these methods externally, because they come in a bunch
  9353. // and this way their names minify.
  9354. // Single scalar
  9355. function setValueV1f( gl, v ) {
  9356. const cache = this.cache;
  9357. if ( cache[ 0 ] === v ) return;
  9358. gl.uniform1f( this.addr, v );
  9359. cache[ 0 ] = v;
  9360. }
  9361. // Single float vector (from flat array or THREE.VectorN)
  9362. function setValueV2f( gl, v ) {
  9363. const cache = this.cache;
  9364. if ( v.x !== undefined ) {
  9365. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9366. gl.uniform2f( this.addr, v.x, v.y );
  9367. cache[ 0 ] = v.x;
  9368. cache[ 1 ] = v.y;
  9369. }
  9370. } else {
  9371. if ( arraysEqual( cache, v ) ) return;
  9372. gl.uniform2fv( this.addr, v );
  9373. copyArray( cache, v );
  9374. }
  9375. }
  9376. function setValueV3f( gl, v ) {
  9377. const cache = this.cache;
  9378. if ( v.x !== undefined ) {
  9379. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9380. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9381. cache[ 0 ] = v.x;
  9382. cache[ 1 ] = v.y;
  9383. cache[ 2 ] = v.z;
  9384. }
  9385. } else if ( v.r !== undefined ) {
  9386. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9387. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9388. cache[ 0 ] = v.r;
  9389. cache[ 1 ] = v.g;
  9390. cache[ 2 ] = v.b;
  9391. }
  9392. } else {
  9393. if ( arraysEqual( cache, v ) ) return;
  9394. gl.uniform3fv( this.addr, v );
  9395. copyArray( cache, v );
  9396. }
  9397. }
  9398. function setValueV4f( gl, v ) {
  9399. const cache = this.cache;
  9400. if ( v.x !== undefined ) {
  9401. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9402. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9403. cache[ 0 ] = v.x;
  9404. cache[ 1 ] = v.y;
  9405. cache[ 2 ] = v.z;
  9406. cache[ 3 ] = v.w;
  9407. }
  9408. } else {
  9409. if ( arraysEqual( cache, v ) ) return;
  9410. gl.uniform4fv( this.addr, v );
  9411. copyArray( cache, v );
  9412. }
  9413. }
  9414. // Single matrix (from flat array or MatrixN)
  9415. function setValueM2( gl, v ) {
  9416. const cache = this.cache;
  9417. const elements = v.elements;
  9418. if ( elements === undefined ) {
  9419. if ( arraysEqual( cache, v ) ) return;
  9420. gl.uniformMatrix2fv( this.addr, false, v );
  9421. copyArray( cache, v );
  9422. } else {
  9423. if ( arraysEqual( cache, elements ) ) return;
  9424. mat2array.set( elements );
  9425. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9426. copyArray( cache, elements );
  9427. }
  9428. }
  9429. function setValueM3( gl, v ) {
  9430. const cache = this.cache;
  9431. const elements = v.elements;
  9432. if ( elements === undefined ) {
  9433. if ( arraysEqual( cache, v ) ) return;
  9434. gl.uniformMatrix3fv( this.addr, false, v );
  9435. copyArray( cache, v );
  9436. } else {
  9437. if ( arraysEqual( cache, elements ) ) return;
  9438. mat3array.set( elements );
  9439. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9440. copyArray( cache, elements );
  9441. }
  9442. }
  9443. function setValueM4( gl, v ) {
  9444. const cache = this.cache;
  9445. const elements = v.elements;
  9446. if ( elements === undefined ) {
  9447. if ( arraysEqual( cache, v ) ) return;
  9448. gl.uniformMatrix4fv( this.addr, false, v );
  9449. copyArray( cache, v );
  9450. } else {
  9451. if ( arraysEqual( cache, elements ) ) return;
  9452. mat4array.set( elements );
  9453. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9454. copyArray( cache, elements );
  9455. }
  9456. }
  9457. // Single texture (2D / Cube)
  9458. function setValueT1( gl, v, textures ) {
  9459. const cache = this.cache;
  9460. const unit = textures.allocateTextureUnit();
  9461. if ( cache[ 0 ] !== unit ) {
  9462. gl.uniform1i( this.addr, unit );
  9463. cache[ 0 ] = unit;
  9464. }
  9465. textures.safeSetTexture2D( v || emptyTexture, unit );
  9466. }
  9467. function setValueT2DArray1( gl, v, textures ) {
  9468. const cache = this.cache;
  9469. const unit = textures.allocateTextureUnit();
  9470. if ( cache[ 0 ] !== unit ) {
  9471. gl.uniform1i( this.addr, unit );
  9472. cache[ 0 ] = unit;
  9473. }
  9474. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9475. }
  9476. function setValueT3D1( gl, v, textures ) {
  9477. const cache = this.cache;
  9478. const unit = textures.allocateTextureUnit();
  9479. if ( cache[ 0 ] !== unit ) {
  9480. gl.uniform1i( this.addr, unit );
  9481. cache[ 0 ] = unit;
  9482. }
  9483. textures.setTexture3D( v || emptyTexture3d, unit );
  9484. }
  9485. function setValueT6( gl, v, textures ) {
  9486. const cache = this.cache;
  9487. const unit = textures.allocateTextureUnit();
  9488. if ( cache[ 0 ] !== unit ) {
  9489. gl.uniform1i( this.addr, unit );
  9490. cache[ 0 ] = unit;
  9491. }
  9492. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9493. }
  9494. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9495. function setValueV1i( gl, v ) {
  9496. const cache = this.cache;
  9497. if ( cache[ 0 ] === v ) return;
  9498. gl.uniform1i( this.addr, v );
  9499. cache[ 0 ] = v;
  9500. }
  9501. function setValueV2i( gl, v ) {
  9502. const cache = this.cache;
  9503. if ( arraysEqual( cache, v ) ) return;
  9504. gl.uniform2iv( this.addr, v );
  9505. copyArray( cache, v );
  9506. }
  9507. function setValueV3i( gl, v ) {
  9508. const cache = this.cache;
  9509. if ( arraysEqual( cache, v ) ) return;
  9510. gl.uniform3iv( this.addr, v );
  9511. copyArray( cache, v );
  9512. }
  9513. function setValueV4i( gl, v ) {
  9514. const cache = this.cache;
  9515. if ( arraysEqual( cache, v ) ) return;
  9516. gl.uniform4iv( this.addr, v );
  9517. copyArray( cache, v );
  9518. }
  9519. // uint
  9520. function setValueV1ui( gl, v ) {
  9521. const cache = this.cache;
  9522. if ( cache[ 0 ] === v ) return;
  9523. gl.uniform1ui( this.addr, v );
  9524. cache[ 0 ] = v;
  9525. }
  9526. // Helper to pick the right setter for the singular case
  9527. function getSingularSetter( type ) {
  9528. switch ( type ) {
  9529. case 0x1406: return setValueV1f; // FLOAT
  9530. case 0x8b50: return setValueV2f; // _VEC2
  9531. case 0x8b51: return setValueV3f; // _VEC3
  9532. case 0x8b52: return setValueV4f; // _VEC4
  9533. case 0x8b5a: return setValueM2; // _MAT2
  9534. case 0x8b5b: return setValueM3; // _MAT3
  9535. case 0x8b5c: return setValueM4; // _MAT4
  9536. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  9537. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  9538. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  9539. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  9540. case 0x1405: return setValueV1ui; // UINT
  9541. case 0x8b5e: // SAMPLER_2D
  9542. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9543. case 0x8dca: // INT_SAMPLER_2D
  9544. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9545. case 0x8b62: // SAMPLER_2D_SHADOW
  9546. return setValueT1;
  9547. case 0x8b5f: // SAMPLER_3D
  9548. case 0x8dcb: // INT_SAMPLER_3D
  9549. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  9550. return setValueT3D1;
  9551. case 0x8b60: // SAMPLER_CUBE
  9552. case 0x8dcc: // INT_SAMPLER_CUBE
  9553. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9554. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9555. return setValueT6;
  9556. case 0x8dc1: // SAMPLER_2D_ARRAY
  9557. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  9558. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  9559. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  9560. return setValueT2DArray1;
  9561. }
  9562. }
  9563. // Array of scalars
  9564. function setValueV1fArray( gl, v ) {
  9565. gl.uniform1fv( this.addr, v );
  9566. }
  9567. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9568. function setValueV1iArray( gl, v ) {
  9569. gl.uniform1iv( this.addr, v );
  9570. }
  9571. function setValueV2iArray( gl, v ) {
  9572. gl.uniform2iv( this.addr, v );
  9573. }
  9574. function setValueV3iArray( gl, v ) {
  9575. gl.uniform3iv( this.addr, v );
  9576. }
  9577. function setValueV4iArray( gl, v ) {
  9578. gl.uniform4iv( this.addr, v );
  9579. }
  9580. // Array of vectors (flat or from THREE classes)
  9581. function setValueV2fArray( gl, v ) {
  9582. const data = flatten( v, this.size, 2 );
  9583. gl.uniform2fv( this.addr, data );
  9584. }
  9585. function setValueV3fArray( gl, v ) {
  9586. const data = flatten( v, this.size, 3 );
  9587. gl.uniform3fv( this.addr, data );
  9588. }
  9589. function setValueV4fArray( gl, v ) {
  9590. const data = flatten( v, this.size, 4 );
  9591. gl.uniform4fv( this.addr, data );
  9592. }
  9593. // Array of matrices (flat or from THREE clases)
  9594. function setValueM2Array( gl, v ) {
  9595. const data = flatten( v, this.size, 4 );
  9596. gl.uniformMatrix2fv( this.addr, false, data );
  9597. }
  9598. function setValueM3Array( gl, v ) {
  9599. const data = flatten( v, this.size, 9 );
  9600. gl.uniformMatrix3fv( this.addr, false, data );
  9601. }
  9602. function setValueM4Array( gl, v ) {
  9603. const data = flatten( v, this.size, 16 );
  9604. gl.uniformMatrix4fv( this.addr, false, data );
  9605. }
  9606. // Array of textures (2D / Cube)
  9607. function setValueT1Array( gl, v, textures ) {
  9608. const n = v.length;
  9609. const units = allocTexUnits( textures, n );
  9610. gl.uniform1iv( this.addr, units );
  9611. for ( let i = 0; i !== n; ++ i ) {
  9612. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9613. }
  9614. }
  9615. function setValueT6Array( gl, v, textures ) {
  9616. const n = v.length;
  9617. const units = allocTexUnits( textures, n );
  9618. gl.uniform1iv( this.addr, units );
  9619. for ( let i = 0; i !== n; ++ i ) {
  9620. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9621. }
  9622. }
  9623. // Helper to pick the right setter for a pure (bottom-level) array
  9624. function getPureArraySetter( type ) {
  9625. switch ( type ) {
  9626. case 0x1406: return setValueV1fArray; // FLOAT
  9627. case 0x8b50: return setValueV2fArray; // _VEC2
  9628. case 0x8b51: return setValueV3fArray; // _VEC3
  9629. case 0x8b52: return setValueV4fArray; // _VEC4
  9630. case 0x8b5a: return setValueM2Array; // _MAT2
  9631. case 0x8b5b: return setValueM3Array; // _MAT3
  9632. case 0x8b5c: return setValueM4Array; // _MAT4
  9633. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  9634. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  9635. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  9636. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  9637. case 0x8b5e: // SAMPLER_2D
  9638. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9639. case 0x8dca: // INT_SAMPLER_2D
  9640. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9641. case 0x8b62: // SAMPLER_2D_SHADOW
  9642. return setValueT1Array;
  9643. case 0x8b60: // SAMPLER_CUBE
  9644. case 0x8dcc: // INT_SAMPLER_CUBE
  9645. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9646. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9647. return setValueT6Array;
  9648. }
  9649. }
  9650. // --- Uniform Classes ---
  9651. function SingleUniform( id, activeInfo, addr ) {
  9652. this.id = id;
  9653. this.addr = addr;
  9654. this.cache = [];
  9655. this.setValue = getSingularSetter( activeInfo.type );
  9656. // this.path = activeInfo.name; // DEBUG
  9657. }
  9658. function PureArrayUniform( id, activeInfo, addr ) {
  9659. this.id = id;
  9660. this.addr = addr;
  9661. this.cache = [];
  9662. this.size = activeInfo.size;
  9663. this.setValue = getPureArraySetter( activeInfo.type );
  9664. // this.path = activeInfo.name; // DEBUG
  9665. }
  9666. PureArrayUniform.prototype.updateCache = function ( data ) {
  9667. const cache = this.cache;
  9668. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9669. this.cache = new Float32Array( data.length );
  9670. }
  9671. copyArray( cache, data );
  9672. };
  9673. function StructuredUniform( id ) {
  9674. this.id = id;
  9675. this.seq = [];
  9676. this.map = {};
  9677. }
  9678. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9679. const seq = this.seq;
  9680. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9681. const u = seq[ i ];
  9682. u.setValue( gl, value[ u.id ], textures );
  9683. }
  9684. };
  9685. // --- Top-level ---
  9686. // Parser - builds up the property tree from the path strings
  9687. const RePathPart = /(\w+)(\])?(\[|\.)?/g;
  9688. // extracts
  9689. // - the identifier (member name or array index)
  9690. // - followed by an optional right bracket (found when array index)
  9691. // - followed by an optional left bracket or dot (type of subscript)
  9692. //
  9693. // Note: These portions can be read in a non-overlapping fashion and
  9694. // allow straightforward parsing of the hierarchy that WebGL encodes
  9695. // in the uniform names.
  9696. function addUniform( container, uniformObject ) {
  9697. container.seq.push( uniformObject );
  9698. container.map[ uniformObject.id ] = uniformObject;
  9699. }
  9700. function parseUniform( activeInfo, addr, container ) {
  9701. const path = activeInfo.name,
  9702. pathLength = path.length;
  9703. // reset RegExp object, because of the early exit of a previous run
  9704. RePathPart.lastIndex = 0;
  9705. while ( true ) {
  9706. const match = RePathPart.exec( path ),
  9707. matchEnd = RePathPart.lastIndex;
  9708. let id = match[ 1 ];
  9709. const idIsIndex = match[ 2 ] === ']',
  9710. subscript = match[ 3 ];
  9711. if ( idIsIndex ) id = id | 0; // convert to integer
  9712. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9713. // bare name or "pure" bottom-level array "[0]" suffix
  9714. addUniform( container, subscript === undefined ?
  9715. new SingleUniform( id, activeInfo, addr ) :
  9716. new PureArrayUniform( id, activeInfo, addr ) );
  9717. break;
  9718. } else {
  9719. // step into inner node / create it in case it doesn't exist
  9720. const map = container.map;
  9721. let next = map[ id ];
  9722. if ( next === undefined ) {
  9723. next = new StructuredUniform( id );
  9724. addUniform( container, next );
  9725. }
  9726. container = next;
  9727. }
  9728. }
  9729. }
  9730. // Root Container
  9731. function WebGLUniforms( gl, program ) {
  9732. this.seq = [];
  9733. this.map = {};
  9734. const n = gl.getProgramParameter( program, 35718 );
  9735. for ( let i = 0; i < n; ++ i ) {
  9736. const info = gl.getActiveUniform( program, i ),
  9737. addr = gl.getUniformLocation( program, info.name );
  9738. parseUniform( info, addr, this );
  9739. }
  9740. }
  9741. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9742. const u = this.map[ name ];
  9743. if ( u !== undefined ) u.setValue( gl, value, textures );
  9744. };
  9745. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9746. const v = object[ name ];
  9747. if ( v !== undefined ) this.setValue( gl, name, v );
  9748. };
  9749. // Static interface
  9750. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9751. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9752. const u = seq[ i ],
  9753. v = values[ u.id ];
  9754. if ( v.needsUpdate !== false ) {
  9755. // note: always updating when .needsUpdate is undefined
  9756. u.setValue( gl, v.value, textures );
  9757. }
  9758. }
  9759. };
  9760. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9761. const r = [];
  9762. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9763. const u = seq[ i ];
  9764. if ( u.id in values ) r.push( u );
  9765. }
  9766. return r;
  9767. };
  9768. function WebGLShader( gl, type, string ) {
  9769. const shader = gl.createShader( type );
  9770. gl.shaderSource( shader, string );
  9771. gl.compileShader( shader );
  9772. return shader;
  9773. }
  9774. let programIdCount = 0;
  9775. function addLineNumbers( string ) {
  9776. const lines = string.split( '\n' );
  9777. for ( let i = 0; i < lines.length; i ++ ) {
  9778. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9779. }
  9780. return lines.join( '\n' );
  9781. }
  9782. function getEncodingComponents( encoding ) {
  9783. switch ( encoding ) {
  9784. case LinearEncoding:
  9785. return [ 'Linear', '( value )' ];
  9786. case sRGBEncoding:
  9787. return [ 'sRGB', '( value )' ];
  9788. case RGBEEncoding:
  9789. return [ 'RGBE', '( value )' ];
  9790. case RGBM7Encoding:
  9791. return [ 'RGBM', '( value, 7.0 )' ];
  9792. case RGBM16Encoding:
  9793. return [ 'RGBM', '( value, 16.0 )' ];
  9794. case RGBDEncoding:
  9795. return [ 'RGBD', '( value, 256.0 )' ];
  9796. case GammaEncoding:
  9797. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9798. case LogLuvEncoding:
  9799. return [ 'LogLuv', '( value )' ];
  9800. default:
  9801. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  9802. return [ 'Linear', '( value )' ];
  9803. }
  9804. }
  9805. function getShaderErrors( gl, shader, type ) {
  9806. const status = gl.getShaderParameter( shader, 35713 );
  9807. const log = gl.getShaderInfoLog( shader ).trim();
  9808. if ( status && log === '' ) return '';
  9809. // --enable-privileged-webgl-extension
  9810. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9811. const source = gl.getShaderSource( shader );
  9812. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  9813. }
  9814. function getTexelDecodingFunction( functionName, encoding ) {
  9815. const components = getEncodingComponents( encoding );
  9816. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9817. }
  9818. function getTexelEncodingFunction( functionName, encoding ) {
  9819. const components = getEncodingComponents( encoding );
  9820. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9821. }
  9822. function getToneMappingFunction( functionName, toneMapping ) {
  9823. let toneMappingName;
  9824. switch ( toneMapping ) {
  9825. case LinearToneMapping:
  9826. toneMappingName = 'Linear';
  9827. break;
  9828. case ReinhardToneMapping:
  9829. toneMappingName = 'Reinhard';
  9830. break;
  9831. case CineonToneMapping:
  9832. toneMappingName = 'OptimizedCineon';
  9833. break;
  9834. case ACESFilmicToneMapping:
  9835. toneMappingName = 'ACESFilmic';
  9836. break;
  9837. case CustomToneMapping:
  9838. toneMappingName = 'Custom';
  9839. break;
  9840. default:
  9841. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  9842. toneMappingName = 'Linear';
  9843. }
  9844. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  9845. }
  9846. function generateExtensions( parameters ) {
  9847. const chunks = [
  9848. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  9849. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  9850. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  9851. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  9852. ];
  9853. return chunks.filter( filterEmptyLine ).join( '\n' );
  9854. }
  9855. function generateDefines( defines ) {
  9856. const chunks = [];
  9857. for ( const name in defines ) {
  9858. const value = defines[ name ];
  9859. if ( value === false ) continue;
  9860. chunks.push( '#define ' + name + ' ' + value );
  9861. }
  9862. return chunks.join( '\n' );
  9863. }
  9864. function fetchAttributeLocations( gl, program ) {
  9865. const attributes = {};
  9866. const n = gl.getProgramParameter( program, 35721 );
  9867. for ( let i = 0; i < n; i ++ ) {
  9868. const info = gl.getActiveAttrib( program, i );
  9869. const name = info.name;
  9870. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  9871. attributes[ name ] = gl.getAttribLocation( program, name );
  9872. }
  9873. return attributes;
  9874. }
  9875. function filterEmptyLine( string ) {
  9876. return string !== '';
  9877. }
  9878. function replaceLightNums( string, parameters ) {
  9879. return string
  9880. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  9881. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  9882. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  9883. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  9884. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  9885. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  9886. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  9887. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  9888. }
  9889. function replaceClippingPlaneNums( string, parameters ) {
  9890. return string
  9891. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  9892. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  9893. }
  9894. // Resolve Includes
  9895. const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  9896. function resolveIncludes( string ) {
  9897. return string.replace( includePattern, includeReplacer );
  9898. }
  9899. function includeReplacer( match, include ) {
  9900. const string = ShaderChunk[ include ];
  9901. if ( string === undefined ) {
  9902. throw new Error( 'Can not resolve #include <' + include + '>' );
  9903. }
  9904. return resolveIncludes( string );
  9905. }
  9906. // Unroll Loops
  9907. const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  9908. 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;
  9909. function unrollLoops( string ) {
  9910. return string
  9911. .replace( unrollLoopPattern, loopReplacer )
  9912. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  9913. }
  9914. function deprecatedLoopReplacer( match, start, end, snippet ) {
  9915. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  9916. return loopReplacer( match, start, end, snippet );
  9917. }
  9918. function loopReplacer( match, start, end, snippet ) {
  9919. let string = '';
  9920. for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
  9921. string += snippet
  9922. .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )
  9923. .replace( /UNROLLED_LOOP_INDEX/g, i );
  9924. }
  9925. return string;
  9926. }
  9927. //
  9928. function generatePrecision( parameters ) {
  9929. let precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  9930. if ( parameters.precision === 'highp' ) {
  9931. precisionstring += '\n#define HIGH_PRECISION';
  9932. } else if ( parameters.precision === 'mediump' ) {
  9933. precisionstring += '\n#define MEDIUM_PRECISION';
  9934. } else if ( parameters.precision === 'lowp' ) {
  9935. precisionstring += '\n#define LOW_PRECISION';
  9936. }
  9937. return precisionstring;
  9938. }
  9939. function generateShadowMapTypeDefine( parameters ) {
  9940. let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  9941. if ( parameters.shadowMapType === PCFShadowMap ) {
  9942. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  9943. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  9944. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  9945. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  9946. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  9947. }
  9948. return shadowMapTypeDefine;
  9949. }
  9950. function generateEnvMapTypeDefine( parameters ) {
  9951. let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9952. if ( parameters.envMap ) {
  9953. switch ( parameters.envMapMode ) {
  9954. case CubeReflectionMapping:
  9955. case CubeRefractionMapping:
  9956. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  9957. break;
  9958. case CubeUVReflectionMapping:
  9959. case CubeUVRefractionMapping:
  9960. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  9961. break;
  9962. }
  9963. }
  9964. return envMapTypeDefine;
  9965. }
  9966. function generateEnvMapModeDefine( parameters ) {
  9967. let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  9968. if ( parameters.envMap ) {
  9969. switch ( parameters.envMapMode ) {
  9970. case CubeRefractionMapping:
  9971. case CubeUVRefractionMapping:
  9972. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  9973. break;
  9974. }
  9975. }
  9976. return envMapModeDefine;
  9977. }
  9978. function generateEnvMapBlendingDefine( parameters ) {
  9979. let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  9980. if ( parameters.envMap ) {
  9981. switch ( parameters.combine ) {
  9982. case MultiplyOperation:
  9983. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  9984. break;
  9985. case MixOperation:
  9986. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  9987. break;
  9988. case AddOperation:
  9989. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  9990. break;
  9991. }
  9992. }
  9993. return envMapBlendingDefine;
  9994. }
  9995. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  9996. const gl = renderer.getContext();
  9997. const defines = parameters.defines;
  9998. let vertexShader = parameters.vertexShader;
  9999. let fragmentShader = parameters.fragmentShader;
  10000. const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  10001. const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  10002. const envMapModeDefine = generateEnvMapModeDefine( parameters );
  10003. const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  10004. const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10005. const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  10006. const customDefines = generateDefines( defines );
  10007. const program = gl.createProgram();
  10008. let prefixVertex, prefixFragment;
  10009. let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10010. if ( parameters.isRawShaderMaterial ) {
  10011. prefixVertex = [
  10012. customDefines
  10013. ].filter( filterEmptyLine ).join( '\n' );
  10014. if ( prefixVertex.length > 0 ) {
  10015. prefixVertex += '\n';
  10016. }
  10017. prefixFragment = [
  10018. customExtensions,
  10019. customDefines
  10020. ].filter( filterEmptyLine ).join( '\n' );
  10021. if ( prefixFragment.length > 0 ) {
  10022. prefixFragment += '\n';
  10023. }
  10024. } else {
  10025. prefixVertex = [
  10026. generatePrecision( parameters ),
  10027. '#define SHADER_NAME ' + parameters.shaderName,
  10028. customDefines,
  10029. parameters.instancing ? '#define USE_INSTANCING' : '',
  10030. parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
  10031. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10032. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10033. '#define MAX_BONES ' + parameters.maxBones,
  10034. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10035. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10036. parameters.map ? '#define USE_MAP' : '',
  10037. parameters.envMap ? '#define USE_ENVMAP' : '',
  10038. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10039. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10040. parameters.aoMap ? '#define USE_AOMAP' : '',
  10041. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10042. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10043. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10044. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10045. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10046. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10047. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10048. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10049. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10050. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10051. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10052. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10053. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10054. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10055. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10056. parameters.vertexColors ? '#define USE_COLOR' : '',
  10057. parameters.vertexUvs ? '#define USE_UV' : '',
  10058. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10059. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10060. parameters.skinning ? '#define USE_SKINNING' : '',
  10061. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10062. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10063. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10064. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10065. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10066. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10067. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10068. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10069. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10070. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10071. 'uniform mat4 modelMatrix;',
  10072. 'uniform mat4 modelViewMatrix;',
  10073. 'uniform mat4 projectionMatrix;',
  10074. 'uniform mat4 viewMatrix;',
  10075. 'uniform mat3 normalMatrix;',
  10076. 'uniform vec3 cameraPosition;',
  10077. 'uniform bool isOrthographic;',
  10078. '#ifdef USE_INSTANCING',
  10079. ' attribute mat4 instanceMatrix;',
  10080. '#endif',
  10081. '#ifdef USE_INSTANCING_COLOR',
  10082. ' attribute vec3 instanceColor;',
  10083. '#endif',
  10084. 'attribute vec3 position;',
  10085. 'attribute vec3 normal;',
  10086. 'attribute vec2 uv;',
  10087. '#ifdef USE_TANGENT',
  10088. ' attribute vec4 tangent;',
  10089. '#endif',
  10090. '#ifdef USE_COLOR',
  10091. ' attribute vec3 color;',
  10092. '#endif',
  10093. '#ifdef USE_MORPHTARGETS',
  10094. ' attribute vec3 morphTarget0;',
  10095. ' attribute vec3 morphTarget1;',
  10096. ' attribute vec3 morphTarget2;',
  10097. ' attribute vec3 morphTarget3;',
  10098. ' #ifdef USE_MORPHNORMALS',
  10099. ' attribute vec3 morphNormal0;',
  10100. ' attribute vec3 morphNormal1;',
  10101. ' attribute vec3 morphNormal2;',
  10102. ' attribute vec3 morphNormal3;',
  10103. ' #else',
  10104. ' attribute vec3 morphTarget4;',
  10105. ' attribute vec3 morphTarget5;',
  10106. ' attribute vec3 morphTarget6;',
  10107. ' attribute vec3 morphTarget7;',
  10108. ' #endif',
  10109. '#endif',
  10110. '#ifdef USE_SKINNING',
  10111. ' attribute vec4 skinIndex;',
  10112. ' attribute vec4 skinWeight;',
  10113. '#endif',
  10114. '\n'
  10115. ].filter( filterEmptyLine ).join( '\n' );
  10116. prefixFragment = [
  10117. customExtensions,
  10118. generatePrecision( parameters ),
  10119. '#define SHADER_NAME ' + parameters.shaderName,
  10120. customDefines,
  10121. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10122. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10123. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10124. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10125. parameters.map ? '#define USE_MAP' : '',
  10126. parameters.matcap ? '#define USE_MATCAP' : '',
  10127. parameters.envMap ? '#define USE_ENVMAP' : '',
  10128. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10129. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10130. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10131. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10132. parameters.aoMap ? '#define USE_AOMAP' : '',
  10133. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10134. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10135. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10136. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10137. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10138. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10139. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10140. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10141. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10142. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10143. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10144. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10145. parameters.sheen ? '#define USE_SHEEN' : '',
  10146. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10147. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10148. parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
  10149. parameters.vertexUvs ? '#define USE_UV' : '',
  10150. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10151. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10152. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10153. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10154. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10155. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10156. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10157. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10158. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10159. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10160. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10161. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  10162. 'uniform mat4 viewMatrix;',
  10163. 'uniform vec3 cameraPosition;',
  10164. 'uniform bool isOrthographic;',
  10165. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10166. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10167. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10168. parameters.dithering ? '#define DITHERING' : '',
  10169. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  10170. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10171. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10172. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10173. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10174. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  10175. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  10176. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  10177. '\n'
  10178. ].filter( filterEmptyLine ).join( '\n' );
  10179. }
  10180. vertexShader = resolveIncludes( vertexShader );
  10181. vertexShader = replaceLightNums( vertexShader, parameters );
  10182. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10183. fragmentShader = resolveIncludes( fragmentShader );
  10184. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10185. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10186. vertexShader = unrollLoops( vertexShader );
  10187. fragmentShader = unrollLoops( fragmentShader );
  10188. if ( parameters.isWebGL2 && parameters.isRawShaderMaterial !== true ) {
  10189. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10190. versionString = '#version 300 es\n';
  10191. prefixVertex = [
  10192. '#define attribute in',
  10193. '#define varying out',
  10194. '#define texture2D texture'
  10195. ].join( '\n' ) + '\n' + prefixVertex;
  10196. prefixFragment = [
  10197. '#define varying in',
  10198. ( parameters.glslVersion === GLSL3 ) ? '' : 'out highp vec4 pc_fragColor;',
  10199. ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor',
  10200. '#define gl_FragDepthEXT gl_FragDepth',
  10201. '#define texture2D texture',
  10202. '#define textureCube texture',
  10203. '#define texture2DProj textureProj',
  10204. '#define texture2DLodEXT textureLod',
  10205. '#define texture2DProjLodEXT textureProjLod',
  10206. '#define textureCubeLodEXT textureLod',
  10207. '#define texture2DGradEXT textureGrad',
  10208. '#define texture2DProjGradEXT textureProjGrad',
  10209. '#define textureCubeGradEXT textureGrad'
  10210. ].join( '\n' ) + '\n' + prefixFragment;
  10211. }
  10212. const vertexGlsl = versionString + prefixVertex + vertexShader;
  10213. const fragmentGlsl = versionString + prefixFragment + fragmentShader;
  10214. // console.log( '*VERTEX*', vertexGlsl );
  10215. // console.log( '*FRAGMENT*', fragmentGlsl );
  10216. const glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10217. const glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10218. gl.attachShader( program, glVertexShader );
  10219. gl.attachShader( program, glFragmentShader );
  10220. // Force a particular attribute to index 0.
  10221. if ( parameters.index0AttributeName !== undefined ) {
  10222. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  10223. } else if ( parameters.morphTargets === true ) {
  10224. // programs with morphTargets displace position out of attribute 0
  10225. gl.bindAttribLocation( program, 0, 'position' );
  10226. }
  10227. gl.linkProgram( program );
  10228. // check for link errors
  10229. if ( renderer.debug.checkShaderErrors ) {
  10230. const programLog = gl.getProgramInfoLog( program ).trim();
  10231. const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10232. const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10233. let runnable = true;
  10234. let haveDiagnostics = true;
  10235. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10236. runnable = false;
  10237. const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10238. const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10239. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10240. } else if ( programLog !== '' ) {
  10241. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10242. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10243. haveDiagnostics = false;
  10244. }
  10245. if ( haveDiagnostics ) {
  10246. this.diagnostics = {
  10247. runnable: runnable,
  10248. programLog: programLog,
  10249. vertexShader: {
  10250. log: vertexLog,
  10251. prefix: prefixVertex
  10252. },
  10253. fragmentShader: {
  10254. log: fragmentLog,
  10255. prefix: prefixFragment
  10256. }
  10257. };
  10258. }
  10259. }
  10260. // Clean up
  10261. // Crashes in iOS9 and iOS10. #18402
  10262. // gl.detachShader( program, glVertexShader );
  10263. // gl.detachShader( program, glFragmentShader );
  10264. gl.deleteShader( glVertexShader );
  10265. gl.deleteShader( glFragmentShader );
  10266. // set up caching for uniform locations
  10267. let cachedUniforms;
  10268. this.getUniforms = function () {
  10269. if ( cachedUniforms === undefined ) {
  10270. cachedUniforms = new WebGLUniforms( gl, program );
  10271. }
  10272. return cachedUniforms;
  10273. };
  10274. // set up caching for attribute locations
  10275. let cachedAttributes;
  10276. this.getAttributes = function () {
  10277. if ( cachedAttributes === undefined ) {
  10278. cachedAttributes = fetchAttributeLocations( gl, program );
  10279. }
  10280. return cachedAttributes;
  10281. };
  10282. // free resource
  10283. this.destroy = function () {
  10284. bindingStates.releaseStatesOfProgram( this );
  10285. gl.deleteProgram( program );
  10286. this.program = undefined;
  10287. };
  10288. //
  10289. this.name = parameters.shaderName;
  10290. this.id = programIdCount ++;
  10291. this.cacheKey = cacheKey;
  10292. this.usedTimes = 1;
  10293. this.program = program;
  10294. this.vertexShader = glVertexShader;
  10295. this.fragmentShader = glFragmentShader;
  10296. return this;
  10297. }
  10298. function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingStates, clipping ) {
  10299. const programs = [];
  10300. const isWebGL2 = capabilities.isWebGL2;
  10301. const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10302. const floatVertexTextures = capabilities.floatVertexTextures;
  10303. const maxVertexUniforms = capabilities.maxVertexUniforms;
  10304. const vertexTextures = capabilities.vertexTextures;
  10305. let precision = capabilities.precision;
  10306. const shaderIDs = {
  10307. MeshDepthMaterial: 'depth',
  10308. MeshDistanceMaterial: 'distanceRGBA',
  10309. MeshNormalMaterial: 'normal',
  10310. MeshBasicMaterial: 'basic',
  10311. MeshLambertMaterial: 'lambert',
  10312. MeshPhongMaterial: 'phong',
  10313. MeshToonMaterial: 'toon',
  10314. MeshStandardMaterial: 'physical',
  10315. MeshPhysicalMaterial: 'physical',
  10316. MeshMatcapMaterial: 'matcap',
  10317. LineBasicMaterial: 'basic',
  10318. LineDashedMaterial: 'dashed',
  10319. PointsMaterial: 'points',
  10320. ShadowMaterial: 'shadow',
  10321. SpriteMaterial: 'sprite'
  10322. };
  10323. const parameterNames = [
  10324. 'precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor',
  10325. 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV',
  10326. 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap',
  10327. 'roughnessMap', 'metalnessMap', 'gradientMap',
  10328. 'alphaMap', 'combine', 'vertexColors', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2',
  10329. 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning',
  10330. 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals',
  10331. 'maxMorphTargets', 'maxMorphNormals', 'premultipliedAlpha',
  10332. 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
  10333. 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
  10334. 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
  10335. 'alphaTest', 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering',
  10336. 'sheen', 'transmissionMap'
  10337. ];
  10338. function getMaxBones( object ) {
  10339. const skeleton = object.skeleton;
  10340. const bones = skeleton.bones;
  10341. if ( floatVertexTextures ) {
  10342. return 1024;
  10343. } else {
  10344. // default for when object is not specified
  10345. // ( for example when prebuilding shader to be used with multiple objects )
  10346. //
  10347. // - leave some extra space for other uniforms
  10348. // - limit here is ANGLE's 254 max uniform vectors
  10349. // (up to 54 should be safe)
  10350. const nVertexUniforms = maxVertexUniforms;
  10351. const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10352. const maxBones = Math.min( nVertexMatrices, bones.length );
  10353. if ( maxBones < bones.length ) {
  10354. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10355. return 0;
  10356. }
  10357. return maxBones;
  10358. }
  10359. }
  10360. function getTextureEncodingFromMap( map ) {
  10361. let encoding;
  10362. if ( map && map.isTexture ) {
  10363. encoding = map.encoding;
  10364. } else if ( map && map.isWebGLRenderTarget ) {
  10365. console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' );
  10366. encoding = map.texture.encoding;
  10367. } else {
  10368. encoding = LinearEncoding;
  10369. }
  10370. return encoding;
  10371. }
  10372. function getParameters( material, lights, shadows, scene, object ) {
  10373. const fog = scene.fog;
  10374. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  10375. const envMap = cubemaps.get( material.envMap || environment );
  10376. const shaderID = shaderIDs[ material.type ];
  10377. // heuristics to create shader parameters according to lights in the scene
  10378. // (not to blow over maxLights budget)
  10379. const maxBones = object.isSkinnedMesh ? getMaxBones( object ) : 0;
  10380. if ( material.precision !== null ) {
  10381. precision = capabilities.getMaxPrecision( material.precision );
  10382. if ( precision !== material.precision ) {
  10383. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10384. }
  10385. }
  10386. let vertexShader, fragmentShader;
  10387. if ( shaderID ) {
  10388. const shader = ShaderLib[ shaderID ];
  10389. vertexShader = shader.vertexShader;
  10390. fragmentShader = shader.fragmentShader;
  10391. } else {
  10392. vertexShader = material.vertexShader;
  10393. fragmentShader = material.fragmentShader;
  10394. }
  10395. const currentRenderTarget = renderer.getRenderTarget();
  10396. const parameters = {
  10397. isWebGL2: isWebGL2,
  10398. shaderID: shaderID,
  10399. shaderName: material.type,
  10400. vertexShader: vertexShader,
  10401. fragmentShader: fragmentShader,
  10402. defines: material.defines,
  10403. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10404. glslVersion: material.glslVersion,
  10405. precision: precision,
  10406. instancing: object.isInstancedMesh === true,
  10407. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10408. supportsVertexTextures: vertexTextures,
  10409. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  10410. map: !! material.map,
  10411. mapEncoding: getTextureEncodingFromMap( material.map ),
  10412. matcap: !! material.matcap,
  10413. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  10414. envMap: !! envMap,
  10415. envMapMode: envMap && envMap.mapping,
  10416. envMapEncoding: getTextureEncodingFromMap( envMap ),
  10417. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  10418. lightMap: !! material.lightMap,
  10419. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  10420. aoMap: !! material.aoMap,
  10421. emissiveMap: !! material.emissiveMap,
  10422. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  10423. bumpMap: !! material.bumpMap,
  10424. normalMap: !! material.normalMap,
  10425. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10426. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10427. clearcoatMap: !! material.clearcoatMap,
  10428. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  10429. clearcoatNormalMap: !! material.clearcoatNormalMap,
  10430. displacementMap: !! material.displacementMap,
  10431. roughnessMap: !! material.roughnessMap,
  10432. metalnessMap: !! material.metalnessMap,
  10433. specularMap: !! material.specularMap,
  10434. alphaMap: !! material.alphaMap,
  10435. gradientMap: !! material.gradientMap,
  10436. sheen: !! material.sheen,
  10437. transmissionMap: !! material.transmissionMap,
  10438. combine: material.combine,
  10439. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10440. vertexColors: material.vertexColors,
  10441. 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,
  10442. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.transmissionMap ) && !! material.displacementMap,
  10443. fog: !! fog,
  10444. useFog: material.fog,
  10445. fogExp2: ( fog && fog.isFogExp2 ),
  10446. flatShading: !! material.flatShading,
  10447. sizeAttenuation: material.sizeAttenuation,
  10448. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10449. skinning: material.skinning && maxBones > 0,
  10450. maxBones: maxBones,
  10451. useVertexTexture: floatVertexTextures,
  10452. morphTargets: material.morphTargets,
  10453. morphNormals: material.morphNormals,
  10454. maxMorphTargets: renderer.maxMorphTargets,
  10455. maxMorphNormals: renderer.maxMorphNormals,
  10456. numDirLights: lights.directional.length,
  10457. numPointLights: lights.point.length,
  10458. numSpotLights: lights.spot.length,
  10459. numRectAreaLights: lights.rectArea.length,
  10460. numHemiLights: lights.hemi.length,
  10461. numDirLightShadows: lights.directionalShadowMap.length,
  10462. numPointLightShadows: lights.pointShadowMap.length,
  10463. numSpotLightShadows: lights.spotShadowMap.length,
  10464. numClippingPlanes: clipping.numPlanes,
  10465. numClipIntersection: clipping.numIntersection,
  10466. dithering: material.dithering,
  10467. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  10468. shadowMapType: renderer.shadowMap.type,
  10469. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  10470. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10471. premultipliedAlpha: material.premultipliedAlpha,
  10472. alphaTest: material.alphaTest,
  10473. doubleSided: material.side === DoubleSide,
  10474. flipSided: material.side === BackSide,
  10475. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  10476. index0AttributeName: material.index0AttributeName,
  10477. extensionDerivatives: material.extensions && material.extensions.derivatives,
  10478. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  10479. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  10480. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  10481. rendererExtensionFragDepth: isWebGL2 || extensions.has( 'EXT_frag_depth' ),
  10482. rendererExtensionDrawBuffers: isWebGL2 || extensions.has( 'WEBGL_draw_buffers' ),
  10483. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has( 'EXT_shader_texture_lod' ),
  10484. customProgramCacheKey: material.customProgramCacheKey()
  10485. };
  10486. return parameters;
  10487. }
  10488. function getProgramCacheKey( parameters ) {
  10489. const array = [];
  10490. if ( parameters.shaderID ) {
  10491. array.push( parameters.shaderID );
  10492. } else {
  10493. array.push( parameters.fragmentShader );
  10494. array.push( parameters.vertexShader );
  10495. }
  10496. if ( parameters.defines !== undefined ) {
  10497. for ( const name in parameters.defines ) {
  10498. array.push( name );
  10499. array.push( parameters.defines[ name ] );
  10500. }
  10501. }
  10502. if ( parameters.isRawShaderMaterial === false ) {
  10503. for ( let i = 0; i < parameterNames.length; i ++ ) {
  10504. array.push( parameters[ parameterNames[ i ] ] );
  10505. }
  10506. array.push( renderer.outputEncoding );
  10507. array.push( renderer.gammaFactor );
  10508. }
  10509. array.push( parameters.customProgramCacheKey );
  10510. return array.join();
  10511. }
  10512. function getUniforms( material ) {
  10513. const shaderID = shaderIDs[ material.type ];
  10514. let uniforms;
  10515. if ( shaderID ) {
  10516. const shader = ShaderLib[ shaderID ];
  10517. uniforms = UniformsUtils.clone( shader.uniforms );
  10518. } else {
  10519. uniforms = material.uniforms;
  10520. }
  10521. return uniforms;
  10522. }
  10523. function acquireProgram( parameters, cacheKey ) {
  10524. let program;
  10525. // Check if code has been already compiled
  10526. for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
  10527. const preexistingProgram = programs[ p ];
  10528. if ( preexistingProgram.cacheKey === cacheKey ) {
  10529. program = preexistingProgram;
  10530. ++ program.usedTimes;
  10531. break;
  10532. }
  10533. }
  10534. if ( program === undefined ) {
  10535. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  10536. programs.push( program );
  10537. }
  10538. return program;
  10539. }
  10540. function releaseProgram( program ) {
  10541. if ( -- program.usedTimes === 0 ) {
  10542. // Remove from unordered set
  10543. const i = programs.indexOf( program );
  10544. programs[ i ] = programs[ programs.length - 1 ];
  10545. programs.pop();
  10546. // Free WebGL resources
  10547. program.destroy();
  10548. }
  10549. }
  10550. return {
  10551. getParameters: getParameters,
  10552. getProgramCacheKey: getProgramCacheKey,
  10553. getUniforms: getUniforms,
  10554. acquireProgram: acquireProgram,
  10555. releaseProgram: releaseProgram,
  10556. // Exposed for resource monitoring & error feedback via renderer.info:
  10557. programs: programs
  10558. };
  10559. }
  10560. function WebGLProperties() {
  10561. let properties = new WeakMap();
  10562. function get( object ) {
  10563. let map = properties.get( object );
  10564. if ( map === undefined ) {
  10565. map = {};
  10566. properties.set( object, map );
  10567. }
  10568. return map;
  10569. }
  10570. function remove( object ) {
  10571. properties.delete( object );
  10572. }
  10573. function update( object, key, value ) {
  10574. properties.get( object )[ key ] = value;
  10575. }
  10576. function dispose() {
  10577. properties = new WeakMap();
  10578. }
  10579. return {
  10580. get: get,
  10581. remove: remove,
  10582. update: update,
  10583. dispose: dispose
  10584. };
  10585. }
  10586. function painterSortStable( a, b ) {
  10587. if ( a.groupOrder !== b.groupOrder ) {
  10588. return a.groupOrder - b.groupOrder;
  10589. } else if ( a.renderOrder !== b.renderOrder ) {
  10590. return a.renderOrder - b.renderOrder;
  10591. } else if ( a.program !== b.program ) {
  10592. return a.program.id - b.program.id;
  10593. } else if ( a.material.id !== b.material.id ) {
  10594. return a.material.id - b.material.id;
  10595. } else if ( a.z !== b.z ) {
  10596. return a.z - b.z;
  10597. } else {
  10598. return a.id - b.id;
  10599. }
  10600. }
  10601. function reversePainterSortStable( a, b ) {
  10602. if ( a.groupOrder !== b.groupOrder ) {
  10603. return a.groupOrder - b.groupOrder;
  10604. } else if ( a.renderOrder !== b.renderOrder ) {
  10605. return a.renderOrder - b.renderOrder;
  10606. } else if ( a.z !== b.z ) {
  10607. return b.z - a.z;
  10608. } else {
  10609. return a.id - b.id;
  10610. }
  10611. }
  10612. function WebGLRenderList( properties ) {
  10613. const renderItems = [];
  10614. let renderItemsIndex = 0;
  10615. const opaque = [];
  10616. const transparent = [];
  10617. const defaultProgram = { id: - 1 };
  10618. function init() {
  10619. renderItemsIndex = 0;
  10620. opaque.length = 0;
  10621. transparent.length = 0;
  10622. }
  10623. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10624. let renderItem = renderItems[ renderItemsIndex ];
  10625. const materialProperties = properties.get( material );
  10626. if ( renderItem === undefined ) {
  10627. renderItem = {
  10628. id: object.id,
  10629. object: object,
  10630. geometry: geometry,
  10631. material: material,
  10632. program: materialProperties.program || defaultProgram,
  10633. groupOrder: groupOrder,
  10634. renderOrder: object.renderOrder,
  10635. z: z,
  10636. group: group
  10637. };
  10638. renderItems[ renderItemsIndex ] = renderItem;
  10639. } else {
  10640. renderItem.id = object.id;
  10641. renderItem.object = object;
  10642. renderItem.geometry = geometry;
  10643. renderItem.material = material;
  10644. renderItem.program = materialProperties.program || defaultProgram;
  10645. renderItem.groupOrder = groupOrder;
  10646. renderItem.renderOrder = object.renderOrder;
  10647. renderItem.z = z;
  10648. renderItem.group = group;
  10649. }
  10650. renderItemsIndex ++;
  10651. return renderItem;
  10652. }
  10653. function push( object, geometry, material, groupOrder, z, group ) {
  10654. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10655. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10656. }
  10657. function unshift( object, geometry, material, groupOrder, z, group ) {
  10658. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10659. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10660. }
  10661. function sort( customOpaqueSort, customTransparentSort ) {
  10662. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  10663. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  10664. }
  10665. function finish() {
  10666. // Clear references from inactive renderItems in the list
  10667. for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  10668. const renderItem = renderItems[ i ];
  10669. if ( renderItem.id === null ) break;
  10670. renderItem.id = null;
  10671. renderItem.object = null;
  10672. renderItem.geometry = null;
  10673. renderItem.material = null;
  10674. renderItem.program = null;
  10675. renderItem.group = null;
  10676. }
  10677. }
  10678. return {
  10679. opaque: opaque,
  10680. transparent: transparent,
  10681. init: init,
  10682. push: push,
  10683. unshift: unshift,
  10684. finish: finish,
  10685. sort: sort
  10686. };
  10687. }
  10688. function WebGLRenderLists( properties ) {
  10689. let lists = new WeakMap();
  10690. function get( scene, renderCallDepth ) {
  10691. let list;
  10692. if ( lists.has( scene ) === false ) {
  10693. list = new WebGLRenderList( properties );
  10694. lists.set( scene, [ list ] );
  10695. } else {
  10696. if ( renderCallDepth >= lists.get( scene ).length ) {
  10697. list = new WebGLRenderList( properties );
  10698. lists.get( scene ).push( list );
  10699. } else {
  10700. list = lists.get( scene )[ renderCallDepth ];
  10701. }
  10702. }
  10703. return list;
  10704. }
  10705. function dispose() {
  10706. lists = new WeakMap();
  10707. }
  10708. return {
  10709. get: get,
  10710. dispose: dispose
  10711. };
  10712. }
  10713. function UniformsCache() {
  10714. const lights = {};
  10715. return {
  10716. get: function ( light ) {
  10717. if ( lights[ light.id ] !== undefined ) {
  10718. return lights[ light.id ];
  10719. }
  10720. let uniforms;
  10721. switch ( light.type ) {
  10722. case 'DirectionalLight':
  10723. uniforms = {
  10724. direction: new Vector3(),
  10725. color: new Color()
  10726. };
  10727. break;
  10728. case 'SpotLight':
  10729. uniforms = {
  10730. position: new Vector3(),
  10731. direction: new Vector3(),
  10732. color: new Color(),
  10733. distance: 0,
  10734. coneCos: 0,
  10735. penumbraCos: 0,
  10736. decay: 0
  10737. };
  10738. break;
  10739. case 'PointLight':
  10740. uniforms = {
  10741. position: new Vector3(),
  10742. color: new Color(),
  10743. distance: 0,
  10744. decay: 0
  10745. };
  10746. break;
  10747. case 'HemisphereLight':
  10748. uniforms = {
  10749. direction: new Vector3(),
  10750. skyColor: new Color(),
  10751. groundColor: new Color()
  10752. };
  10753. break;
  10754. case 'RectAreaLight':
  10755. uniforms = {
  10756. color: new Color(),
  10757. position: new Vector3(),
  10758. halfWidth: new Vector3(),
  10759. halfHeight: new Vector3()
  10760. };
  10761. break;
  10762. }
  10763. lights[ light.id ] = uniforms;
  10764. return uniforms;
  10765. }
  10766. };
  10767. }
  10768. function ShadowUniformsCache() {
  10769. const lights = {};
  10770. return {
  10771. get: function ( light ) {
  10772. if ( lights[ light.id ] !== undefined ) {
  10773. return lights[ light.id ];
  10774. }
  10775. let uniforms;
  10776. switch ( light.type ) {
  10777. case 'DirectionalLight':
  10778. uniforms = {
  10779. shadowBias: 0,
  10780. shadowNormalBias: 0,
  10781. shadowRadius: 1,
  10782. shadowMapSize: new Vector2()
  10783. };
  10784. break;
  10785. case 'SpotLight':
  10786. uniforms = {
  10787. shadowBias: 0,
  10788. shadowNormalBias: 0,
  10789. shadowRadius: 1,
  10790. shadowMapSize: new Vector2()
  10791. };
  10792. break;
  10793. case 'PointLight':
  10794. uniforms = {
  10795. shadowBias: 0,
  10796. shadowNormalBias: 0,
  10797. shadowRadius: 1,
  10798. shadowMapSize: new Vector2(),
  10799. shadowCameraNear: 1,
  10800. shadowCameraFar: 1000
  10801. };
  10802. break;
  10803. // TODO (abelnation): set RectAreaLight shadow uniforms
  10804. }
  10805. lights[ light.id ] = uniforms;
  10806. return uniforms;
  10807. }
  10808. };
  10809. }
  10810. let nextVersion = 0;
  10811. function shadowCastingLightsFirst( lightA, lightB ) {
  10812. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  10813. }
  10814. function WebGLLights( extensions, capabilities ) {
  10815. const cache = new UniformsCache();
  10816. const shadowCache = ShadowUniformsCache();
  10817. const state = {
  10818. version: 0,
  10819. hash: {
  10820. directionalLength: - 1,
  10821. pointLength: - 1,
  10822. spotLength: - 1,
  10823. rectAreaLength: - 1,
  10824. hemiLength: - 1,
  10825. numDirectionalShadows: - 1,
  10826. numPointShadows: - 1,
  10827. numSpotShadows: - 1
  10828. },
  10829. ambient: [ 0, 0, 0 ],
  10830. probe: [],
  10831. directional: [],
  10832. directionalShadow: [],
  10833. directionalShadowMap: [],
  10834. directionalShadowMatrix: [],
  10835. spot: [],
  10836. spotShadow: [],
  10837. spotShadowMap: [],
  10838. spotShadowMatrix: [],
  10839. rectArea: [],
  10840. rectAreaLTC1: null,
  10841. rectAreaLTC2: null,
  10842. point: [],
  10843. pointShadow: [],
  10844. pointShadowMap: [],
  10845. pointShadowMatrix: [],
  10846. hemi: []
  10847. };
  10848. for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  10849. const vector3 = new Vector3();
  10850. const matrix4 = new Matrix4();
  10851. const matrix42 = new Matrix4();
  10852. function setup( lights ) {
  10853. let r = 0, g = 0, b = 0;
  10854. for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  10855. let directionalLength = 0;
  10856. let pointLength = 0;
  10857. let spotLength = 0;
  10858. let rectAreaLength = 0;
  10859. let hemiLength = 0;
  10860. let numDirectionalShadows = 0;
  10861. let numPointShadows = 0;
  10862. let numSpotShadows = 0;
  10863. lights.sort( shadowCastingLightsFirst );
  10864. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  10865. const light = lights[ i ];
  10866. const color = light.color;
  10867. const intensity = light.intensity;
  10868. const distance = light.distance;
  10869. const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10870. if ( light.isAmbientLight ) {
  10871. r += color.r * intensity;
  10872. g += color.g * intensity;
  10873. b += color.b * intensity;
  10874. } else if ( light.isLightProbe ) {
  10875. for ( let j = 0; j < 9; j ++ ) {
  10876. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  10877. }
  10878. } else if ( light.isDirectionalLight ) {
  10879. const uniforms = cache.get( light );
  10880. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10881. if ( light.castShadow ) {
  10882. const shadow = light.shadow;
  10883. const shadowUniforms = shadowCache.get( light );
  10884. shadowUniforms.shadowBias = shadow.bias;
  10885. shadowUniforms.shadowNormalBias = shadow.normalBias;
  10886. shadowUniforms.shadowRadius = shadow.radius;
  10887. shadowUniforms.shadowMapSize = shadow.mapSize;
  10888. state.directionalShadow[ directionalLength ] = shadowUniforms;
  10889. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10890. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10891. numDirectionalShadows ++;
  10892. }
  10893. state.directional[ directionalLength ] = uniforms;
  10894. directionalLength ++;
  10895. } else if ( light.isSpotLight ) {
  10896. const uniforms = cache.get( light );
  10897. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10898. uniforms.color.copy( color ).multiplyScalar( intensity );
  10899. uniforms.distance = distance;
  10900. uniforms.coneCos = Math.cos( light.angle );
  10901. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10902. uniforms.decay = light.decay;
  10903. if ( light.castShadow ) {
  10904. const shadow = light.shadow;
  10905. const shadowUniforms = shadowCache.get( light );
  10906. shadowUniforms.shadowBias = shadow.bias;
  10907. shadowUniforms.shadowNormalBias = shadow.normalBias;
  10908. shadowUniforms.shadowRadius = shadow.radius;
  10909. shadowUniforms.shadowMapSize = shadow.mapSize;
  10910. state.spotShadow[ spotLength ] = shadowUniforms;
  10911. state.spotShadowMap[ spotLength ] = shadowMap;
  10912. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10913. numSpotShadows ++;
  10914. }
  10915. state.spot[ spotLength ] = uniforms;
  10916. spotLength ++;
  10917. } else if ( light.isRectAreaLight ) {
  10918. const uniforms = cache.get( light );
  10919. // (a) intensity is the total visible light emitted
  10920. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10921. // (b) intensity is the brightness of the light
  10922. uniforms.color.copy( color ).multiplyScalar( intensity );
  10923. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10924. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10925. state.rectArea[ rectAreaLength ] = uniforms;
  10926. rectAreaLength ++;
  10927. } else if ( light.isPointLight ) {
  10928. const uniforms = cache.get( light );
  10929. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10930. uniforms.distance = light.distance;
  10931. uniforms.decay = light.decay;
  10932. if ( light.castShadow ) {
  10933. const shadow = light.shadow;
  10934. const shadowUniforms = shadowCache.get( light );
  10935. shadowUniforms.shadowBias = shadow.bias;
  10936. shadowUniforms.shadowNormalBias = shadow.normalBias;
  10937. shadowUniforms.shadowRadius = shadow.radius;
  10938. shadowUniforms.shadowMapSize = shadow.mapSize;
  10939. shadowUniforms.shadowCameraNear = shadow.camera.near;
  10940. shadowUniforms.shadowCameraFar = shadow.camera.far;
  10941. state.pointShadow[ pointLength ] = shadowUniforms;
  10942. state.pointShadowMap[ pointLength ] = shadowMap;
  10943. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10944. numPointShadows ++;
  10945. }
  10946. state.point[ pointLength ] = uniforms;
  10947. pointLength ++;
  10948. } else if ( light.isHemisphereLight ) {
  10949. const uniforms = cache.get( light );
  10950. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10951. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10952. state.hemi[ hemiLength ] = uniforms;
  10953. hemiLength ++;
  10954. }
  10955. }
  10956. if ( rectAreaLength > 0 ) {
  10957. if ( capabilities.isWebGL2 ) {
  10958. // WebGL 2
  10959. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  10960. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  10961. } else {
  10962. // WebGL 1
  10963. if ( extensions.has( 'OES_texture_float_linear' ) === true ) {
  10964. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  10965. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  10966. } else if ( extensions.has( 'OES_texture_half_float_linear' ) === true ) {
  10967. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  10968. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  10969. } else {
  10970. console.error( 'THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.' );
  10971. }
  10972. }
  10973. }
  10974. state.ambient[ 0 ] = r;
  10975. state.ambient[ 1 ] = g;
  10976. state.ambient[ 2 ] = b;
  10977. const hash = state.hash;
  10978. if ( hash.directionalLength !== directionalLength ||
  10979. hash.pointLength !== pointLength ||
  10980. hash.spotLength !== spotLength ||
  10981. hash.rectAreaLength !== rectAreaLength ||
  10982. hash.hemiLength !== hemiLength ||
  10983. hash.numDirectionalShadows !== numDirectionalShadows ||
  10984. hash.numPointShadows !== numPointShadows ||
  10985. hash.numSpotShadows !== numSpotShadows ) {
  10986. state.directional.length = directionalLength;
  10987. state.spot.length = spotLength;
  10988. state.rectArea.length = rectAreaLength;
  10989. state.point.length = pointLength;
  10990. state.hemi.length = hemiLength;
  10991. state.directionalShadow.length = numDirectionalShadows;
  10992. state.directionalShadowMap.length = numDirectionalShadows;
  10993. state.pointShadow.length = numPointShadows;
  10994. state.pointShadowMap.length = numPointShadows;
  10995. state.spotShadow.length = numSpotShadows;
  10996. state.spotShadowMap.length = numSpotShadows;
  10997. state.directionalShadowMatrix.length = numDirectionalShadows;
  10998. state.pointShadowMatrix.length = numPointShadows;
  10999. state.spotShadowMatrix.length = numSpotShadows;
  11000. hash.directionalLength = directionalLength;
  11001. hash.pointLength = pointLength;
  11002. hash.spotLength = spotLength;
  11003. hash.rectAreaLength = rectAreaLength;
  11004. hash.hemiLength = hemiLength;
  11005. hash.numDirectionalShadows = numDirectionalShadows;
  11006. hash.numPointShadows = numPointShadows;
  11007. hash.numSpotShadows = numSpotShadows;
  11008. state.version = nextVersion ++;
  11009. }
  11010. }
  11011. function setupView( lights, camera ) {
  11012. let directionalLength = 0;
  11013. let pointLength = 0;
  11014. let spotLength = 0;
  11015. let rectAreaLength = 0;
  11016. let hemiLength = 0;
  11017. const viewMatrix = camera.matrixWorldInverse;
  11018. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11019. const light = lights[ i ];
  11020. if ( light.isDirectionalLight ) {
  11021. const uniforms = state.directional[ directionalLength ];
  11022. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11023. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11024. uniforms.direction.sub( vector3 );
  11025. uniforms.direction.transformDirection( viewMatrix );
  11026. directionalLength ++;
  11027. } else if ( light.isSpotLight ) {
  11028. const uniforms = state.spot[ spotLength ];
  11029. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11030. uniforms.position.applyMatrix4( viewMatrix );
  11031. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11032. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11033. uniforms.direction.sub( vector3 );
  11034. uniforms.direction.transformDirection( viewMatrix );
  11035. spotLength ++;
  11036. } else if ( light.isRectAreaLight ) {
  11037. const uniforms = state.rectArea[ rectAreaLength ];
  11038. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11039. uniforms.position.applyMatrix4( viewMatrix );
  11040. // extract local rotation of light to derive width/height half vectors
  11041. matrix42.identity();
  11042. matrix4.copy( light.matrixWorld );
  11043. matrix4.premultiply( viewMatrix );
  11044. matrix42.extractRotation( matrix4 );
  11045. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11046. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11047. uniforms.halfWidth.applyMatrix4( matrix42 );
  11048. uniforms.halfHeight.applyMatrix4( matrix42 );
  11049. rectAreaLength ++;
  11050. } else if ( light.isPointLight ) {
  11051. const uniforms = state.point[ pointLength ];
  11052. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11053. uniforms.position.applyMatrix4( viewMatrix );
  11054. pointLength ++;
  11055. } else if ( light.isHemisphereLight ) {
  11056. const uniforms = state.hemi[ hemiLength ];
  11057. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11058. uniforms.direction.transformDirection( viewMatrix );
  11059. uniforms.direction.normalize();
  11060. hemiLength ++;
  11061. }
  11062. }
  11063. }
  11064. return {
  11065. setup: setup,
  11066. setupView: setupView,
  11067. state: state
  11068. };
  11069. }
  11070. function WebGLRenderState( extensions, capabilities ) {
  11071. const lights = new WebGLLights( extensions, capabilities );
  11072. const lightsArray = [];
  11073. const shadowsArray = [];
  11074. function init() {
  11075. lightsArray.length = 0;
  11076. shadowsArray.length = 0;
  11077. }
  11078. function pushLight( light ) {
  11079. lightsArray.push( light );
  11080. }
  11081. function pushShadow( shadowLight ) {
  11082. shadowsArray.push( shadowLight );
  11083. }
  11084. function setupLights() {
  11085. lights.setup( lightsArray );
  11086. }
  11087. function setupLightsView( camera ) {
  11088. lights.setupView( lightsArray, camera );
  11089. }
  11090. const state = {
  11091. lightsArray: lightsArray,
  11092. shadowsArray: shadowsArray,
  11093. lights: lights
  11094. };
  11095. return {
  11096. init: init,
  11097. state: state,
  11098. setupLights: setupLights,
  11099. setupLightsView: setupLightsView,
  11100. pushLight: pushLight,
  11101. pushShadow: pushShadow
  11102. };
  11103. }
  11104. function WebGLRenderStates( extensions, capabilities ) {
  11105. let renderStates = new WeakMap();
  11106. function get( scene, renderCallDepth = 0 ) {
  11107. let renderState;
  11108. if ( renderStates.has( scene ) === false ) {
  11109. renderState = new WebGLRenderState( extensions, capabilities );
  11110. renderStates.set( scene, [ renderState ] );
  11111. } else {
  11112. if ( renderCallDepth >= renderStates.get( scene ).length ) {
  11113. renderState = new WebGLRenderState( extensions, capabilities );
  11114. renderStates.get( scene ).push( renderState );
  11115. } else {
  11116. renderState = renderStates.get( scene )[ renderCallDepth ];
  11117. }
  11118. }
  11119. return renderState;
  11120. }
  11121. function dispose() {
  11122. renderStates = new WeakMap();
  11123. }
  11124. return {
  11125. get: get,
  11126. dispose: dispose
  11127. };
  11128. }
  11129. /**
  11130. * parameters = {
  11131. *
  11132. * opacity: <float>,
  11133. *
  11134. * map: new THREE.Texture( <Image> ),
  11135. *
  11136. * alphaMap: new THREE.Texture( <Image> ),
  11137. *
  11138. * displacementMap: new THREE.Texture( <Image> ),
  11139. * displacementScale: <float>,
  11140. * displacementBias: <float>,
  11141. *
  11142. * wireframe: <boolean>,
  11143. * wireframeLinewidth: <float>
  11144. * }
  11145. */
  11146. class MeshDepthMaterial extends Material {
  11147. constructor( parameters ) {
  11148. super();
  11149. this.type = 'MeshDepthMaterial';
  11150. this.depthPacking = BasicDepthPacking;
  11151. this.skinning = false;
  11152. this.morphTargets = false;
  11153. this.map = null;
  11154. this.alphaMap = null;
  11155. this.displacementMap = null;
  11156. this.displacementScale = 1;
  11157. this.displacementBias = 0;
  11158. this.wireframe = false;
  11159. this.wireframeLinewidth = 1;
  11160. this.fog = false;
  11161. this.setValues( parameters );
  11162. }
  11163. copy( source ) {
  11164. super.copy( source );
  11165. this.depthPacking = source.depthPacking;
  11166. this.skinning = source.skinning;
  11167. this.morphTargets = source.morphTargets;
  11168. this.map = source.map;
  11169. this.alphaMap = source.alphaMap;
  11170. this.displacementMap = source.displacementMap;
  11171. this.displacementScale = source.displacementScale;
  11172. this.displacementBias = source.displacementBias;
  11173. this.wireframe = source.wireframe;
  11174. this.wireframeLinewidth = source.wireframeLinewidth;
  11175. return this;
  11176. }
  11177. }
  11178. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11179. /**
  11180. * parameters = {
  11181. *
  11182. * referencePosition: <float>,
  11183. * nearDistance: <float>,
  11184. * farDistance: <float>,
  11185. *
  11186. * skinning: <bool>,
  11187. * morphTargets: <bool>,
  11188. *
  11189. * map: new THREE.Texture( <Image> ),
  11190. *
  11191. * alphaMap: new THREE.Texture( <Image> ),
  11192. *
  11193. * displacementMap: new THREE.Texture( <Image> ),
  11194. * displacementScale: <float>,
  11195. * displacementBias: <float>
  11196. *
  11197. * }
  11198. */
  11199. class MeshDistanceMaterial extends Material {
  11200. constructor( parameters ) {
  11201. super();
  11202. this.type = 'MeshDistanceMaterial';
  11203. this.referencePosition = new Vector3();
  11204. this.nearDistance = 1;
  11205. this.farDistance = 1000;
  11206. this.skinning = false;
  11207. this.morphTargets = false;
  11208. this.map = null;
  11209. this.alphaMap = null;
  11210. this.displacementMap = null;
  11211. this.displacementScale = 1;
  11212. this.displacementBias = 0;
  11213. this.fog = false;
  11214. this.setValues( parameters );
  11215. }
  11216. copy( source ) {
  11217. super.copy( source );
  11218. this.referencePosition.copy( source.referencePosition );
  11219. this.nearDistance = source.nearDistance;
  11220. this.farDistance = source.farDistance;
  11221. this.skinning = source.skinning;
  11222. this.morphTargets = source.morphTargets;
  11223. this.map = source.map;
  11224. this.alphaMap = source.alphaMap;
  11225. this.displacementMap = source.displacementMap;
  11226. this.displacementScale = source.displacementScale;
  11227. this.displacementBias = source.displacementBias;
  11228. return this;
  11229. }
  11230. }
  11231. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11232. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 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, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  11233. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11234. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11235. let _frustum = new Frustum();
  11236. const _shadowMapSize = new Vector2(),
  11237. _viewportSize = new Vector2(),
  11238. _viewport = new Vector4(),
  11239. _depthMaterials = [],
  11240. _distanceMaterials = [],
  11241. _materialCache = {};
  11242. const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11243. const shadowMaterialVertical = new ShaderMaterial( {
  11244. defines: {
  11245. SAMPLE_RATE: 2.0 / 8.0,
  11246. HALF_SAMPLE_RATE: 1.0 / 8.0
  11247. },
  11248. uniforms: {
  11249. shadow_pass: { value: null },
  11250. resolution: { value: new Vector2() },
  11251. radius: { value: 4.0 }
  11252. },
  11253. vertexShader: vsm_vert,
  11254. fragmentShader: vsm_frag
  11255. } );
  11256. const shadowMaterialHorizontal = shadowMaterialVertical.clone();
  11257. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  11258. const fullScreenTri = new BufferGeometry();
  11259. fullScreenTri.setAttribute(
  11260. 'position',
  11261. new BufferAttribute(
  11262. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  11263. 3
  11264. )
  11265. );
  11266. const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  11267. const scope = this;
  11268. this.enabled = false;
  11269. this.autoUpdate = true;
  11270. this.needsUpdate = false;
  11271. this.type = PCFShadowMap;
  11272. this.render = function ( lights, scene, camera ) {
  11273. if ( scope.enabled === false ) return;
  11274. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11275. if ( lights.length === 0 ) return;
  11276. const currentRenderTarget = _renderer.getRenderTarget();
  11277. const activeCubeFace = _renderer.getActiveCubeFace();
  11278. const activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11279. const _state = _renderer.state;
  11280. // Set GL state for depth map.
  11281. _state.setBlending( NoBlending );
  11282. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11283. _state.buffers.depth.setTest( true );
  11284. _state.setScissorTest( false );
  11285. // render depth map
  11286. for ( let i = 0, il = lights.length; i < il; i ++ ) {
  11287. const light = lights[ i ];
  11288. const shadow = light.shadow;
  11289. if ( shadow === undefined ) {
  11290. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11291. continue;
  11292. }
  11293. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;
  11294. _shadowMapSize.copy( shadow.mapSize );
  11295. const shadowFrameExtents = shadow.getFrameExtents();
  11296. _shadowMapSize.multiply( shadowFrameExtents );
  11297. _viewportSize.copy( shadow.mapSize );
  11298. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  11299. if ( _shadowMapSize.x > maxTextureSize ) {
  11300. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  11301. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11302. shadow.mapSize.x = _viewportSize.x;
  11303. }
  11304. if ( _shadowMapSize.y > maxTextureSize ) {
  11305. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  11306. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11307. shadow.mapSize.y = _viewportSize.y;
  11308. }
  11309. }
  11310. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11311. const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  11312. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11313. shadow.map.texture.name = light.name + '.shadowMap';
  11314. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11315. shadow.camera.updateProjectionMatrix();
  11316. }
  11317. if ( shadow.map === null ) {
  11318. const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11319. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11320. shadow.map.texture.name = light.name + '.shadowMap';
  11321. shadow.camera.updateProjectionMatrix();
  11322. }
  11323. _renderer.setRenderTarget( shadow.map );
  11324. _renderer.clear();
  11325. const viewportCount = shadow.getViewportCount();
  11326. for ( let vp = 0; vp < viewportCount; vp ++ ) {
  11327. const viewport = shadow.getViewport( vp );
  11328. _viewport.set(
  11329. _viewportSize.x * viewport.x,
  11330. _viewportSize.y * viewport.y,
  11331. _viewportSize.x * viewport.z,
  11332. _viewportSize.y * viewport.w
  11333. );
  11334. _state.viewport( _viewport );
  11335. shadow.updateMatrices( light, vp );
  11336. _frustum = shadow.getFrustum();
  11337. renderObject( scene, camera, shadow.camera, light, this.type );
  11338. }
  11339. // do blur pass for VSM
  11340. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11341. VSMPass( shadow, camera );
  11342. }
  11343. shadow.needsUpdate = false;
  11344. }
  11345. scope.needsUpdate = false;
  11346. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11347. };
  11348. function VSMPass( shadow, camera ) {
  11349. const geometry = _objects.update( fullScreenMesh );
  11350. // vertical pass
  11351. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11352. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11353. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11354. _renderer.setRenderTarget( shadow.mapPass );
  11355. _renderer.clear();
  11356. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  11357. // horizontal pass
  11358. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11359. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  11360. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  11361. _renderer.setRenderTarget( shadow.map );
  11362. _renderer.clear();
  11363. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );
  11364. }
  11365. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11366. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11367. let material = _depthMaterials[ index ];
  11368. if ( material === undefined ) {
  11369. material = new MeshDepthMaterial( {
  11370. depthPacking: RGBADepthPacking,
  11371. morphTargets: useMorphing,
  11372. skinning: useSkinning
  11373. } );
  11374. _depthMaterials[ index ] = material;
  11375. }
  11376. return material;
  11377. }
  11378. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11379. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11380. let material = _distanceMaterials[ index ];
  11381. if ( material === undefined ) {
  11382. material = new MeshDistanceMaterial( {
  11383. morphTargets: useMorphing,
  11384. skinning: useSkinning
  11385. } );
  11386. _distanceMaterials[ index ] = material;
  11387. }
  11388. return material;
  11389. }
  11390. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  11391. let result = null;
  11392. let getMaterialVariant = getDepthMaterialVariant;
  11393. let customMaterial = object.customDepthMaterial;
  11394. if ( light.isPointLight === true ) {
  11395. getMaterialVariant = getDistanceMaterialVariant;
  11396. customMaterial = object.customDistanceMaterial;
  11397. }
  11398. if ( customMaterial === undefined ) {
  11399. let useMorphing = false;
  11400. if ( material.morphTargets === true ) {
  11401. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11402. }
  11403. let useSkinning = false;
  11404. if ( object.isSkinnedMesh === true ) {
  11405. if ( material.skinning === true ) {
  11406. useSkinning = true;
  11407. } else {
  11408. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11409. }
  11410. }
  11411. const useInstancing = object.isInstancedMesh === true;
  11412. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  11413. } else {
  11414. result = customMaterial;
  11415. }
  11416. if ( _renderer.localClippingEnabled &&
  11417. material.clipShadows === true &&
  11418. material.clippingPlanes.length !== 0 ) {
  11419. // in this case we need a unique material instance reflecting the
  11420. // appropriate state
  11421. const keyA = result.uuid, keyB = material.uuid;
  11422. let materialsForVariant = _materialCache[ keyA ];
  11423. if ( materialsForVariant === undefined ) {
  11424. materialsForVariant = {};
  11425. _materialCache[ keyA ] = materialsForVariant;
  11426. }
  11427. let cachedMaterial = materialsForVariant[ keyB ];
  11428. if ( cachedMaterial === undefined ) {
  11429. cachedMaterial = result.clone();
  11430. materialsForVariant[ keyB ] = cachedMaterial;
  11431. }
  11432. result = cachedMaterial;
  11433. }
  11434. result.visible = material.visible;
  11435. result.wireframe = material.wireframe;
  11436. if ( type === VSMShadowMap ) {
  11437. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  11438. } else {
  11439. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  11440. }
  11441. result.clipShadows = material.clipShadows;
  11442. result.clippingPlanes = material.clippingPlanes;
  11443. result.clipIntersection = material.clipIntersection;
  11444. result.wireframeLinewidth = material.wireframeLinewidth;
  11445. result.linewidth = material.linewidth;
  11446. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  11447. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  11448. result.nearDistance = shadowCameraNear;
  11449. result.farDistance = shadowCameraFar;
  11450. }
  11451. return result;
  11452. }
  11453. function renderObject( object, camera, shadowCamera, light, type ) {
  11454. if ( object.visible === false ) return;
  11455. const visible = object.layers.test( camera.layers );
  11456. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11457. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11458. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11459. const geometry = _objects.update( object );
  11460. const material = object.material;
  11461. if ( Array.isArray( material ) ) {
  11462. const groups = geometry.groups;
  11463. for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
  11464. const group = groups[ k ];
  11465. const groupMaterial = material[ group.materialIndex ];
  11466. if ( groupMaterial && groupMaterial.visible ) {
  11467. const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  11468. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11469. }
  11470. }
  11471. } else if ( material.visible ) {
  11472. const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  11473. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11474. }
  11475. }
  11476. }
  11477. const children = object.children;
  11478. for ( let i = 0, l = children.length; i < l; i ++ ) {
  11479. renderObject( children[ i ], camera, shadowCamera, light, type );
  11480. }
  11481. }
  11482. }
  11483. function WebGLState( gl, extensions, capabilities ) {
  11484. const isWebGL2 = capabilities.isWebGL2;
  11485. function ColorBuffer() {
  11486. let locked = false;
  11487. const color = new Vector4();
  11488. let currentColorMask = null;
  11489. const currentColorClear = new Vector4( 0, 0, 0, 0 );
  11490. return {
  11491. setMask: function ( colorMask ) {
  11492. if ( currentColorMask !== colorMask && ! locked ) {
  11493. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11494. currentColorMask = colorMask;
  11495. }
  11496. },
  11497. setLocked: function ( lock ) {
  11498. locked = lock;
  11499. },
  11500. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11501. if ( premultipliedAlpha === true ) {
  11502. r *= a; g *= a; b *= a;
  11503. }
  11504. color.set( r, g, b, a );
  11505. if ( currentColorClear.equals( color ) === false ) {
  11506. gl.clearColor( r, g, b, a );
  11507. currentColorClear.copy( color );
  11508. }
  11509. },
  11510. reset: function () {
  11511. locked = false;
  11512. currentColorMask = null;
  11513. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11514. }
  11515. };
  11516. }
  11517. function DepthBuffer() {
  11518. let locked = false;
  11519. let currentDepthMask = null;
  11520. let currentDepthFunc = null;
  11521. let currentDepthClear = null;
  11522. return {
  11523. setTest: function ( depthTest ) {
  11524. if ( depthTest ) {
  11525. enable( 2929 );
  11526. } else {
  11527. disable( 2929 );
  11528. }
  11529. },
  11530. setMask: function ( depthMask ) {
  11531. if ( currentDepthMask !== depthMask && ! locked ) {
  11532. gl.depthMask( depthMask );
  11533. currentDepthMask = depthMask;
  11534. }
  11535. },
  11536. setFunc: function ( depthFunc ) {
  11537. if ( currentDepthFunc !== depthFunc ) {
  11538. if ( depthFunc ) {
  11539. switch ( depthFunc ) {
  11540. case NeverDepth:
  11541. gl.depthFunc( 512 );
  11542. break;
  11543. case AlwaysDepth:
  11544. gl.depthFunc( 519 );
  11545. break;
  11546. case LessDepth:
  11547. gl.depthFunc( 513 );
  11548. break;
  11549. case LessEqualDepth:
  11550. gl.depthFunc( 515 );
  11551. break;
  11552. case EqualDepth:
  11553. gl.depthFunc( 514 );
  11554. break;
  11555. case GreaterEqualDepth:
  11556. gl.depthFunc( 518 );
  11557. break;
  11558. case GreaterDepth:
  11559. gl.depthFunc( 516 );
  11560. break;
  11561. case NotEqualDepth:
  11562. gl.depthFunc( 517 );
  11563. break;
  11564. default:
  11565. gl.depthFunc( 515 );
  11566. }
  11567. } else {
  11568. gl.depthFunc( 515 );
  11569. }
  11570. currentDepthFunc = depthFunc;
  11571. }
  11572. },
  11573. setLocked: function ( lock ) {
  11574. locked = lock;
  11575. },
  11576. setClear: function ( depth ) {
  11577. if ( currentDepthClear !== depth ) {
  11578. gl.clearDepth( depth );
  11579. currentDepthClear = depth;
  11580. }
  11581. },
  11582. reset: function () {
  11583. locked = false;
  11584. currentDepthMask = null;
  11585. currentDepthFunc = null;
  11586. currentDepthClear = null;
  11587. }
  11588. };
  11589. }
  11590. function StencilBuffer() {
  11591. let locked = false;
  11592. let currentStencilMask = null;
  11593. let currentStencilFunc = null;
  11594. let currentStencilRef = null;
  11595. let currentStencilFuncMask = null;
  11596. let currentStencilFail = null;
  11597. let currentStencilZFail = null;
  11598. let currentStencilZPass = null;
  11599. let currentStencilClear = null;
  11600. return {
  11601. setTest: function ( stencilTest ) {
  11602. if ( ! locked ) {
  11603. if ( stencilTest ) {
  11604. enable( 2960 );
  11605. } else {
  11606. disable( 2960 );
  11607. }
  11608. }
  11609. },
  11610. setMask: function ( stencilMask ) {
  11611. if ( currentStencilMask !== stencilMask && ! locked ) {
  11612. gl.stencilMask( stencilMask );
  11613. currentStencilMask = stencilMask;
  11614. }
  11615. },
  11616. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11617. if ( currentStencilFunc !== stencilFunc ||
  11618. currentStencilRef !== stencilRef ||
  11619. currentStencilFuncMask !== stencilMask ) {
  11620. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11621. currentStencilFunc = stencilFunc;
  11622. currentStencilRef = stencilRef;
  11623. currentStencilFuncMask = stencilMask;
  11624. }
  11625. },
  11626. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11627. if ( currentStencilFail !== stencilFail ||
  11628. currentStencilZFail !== stencilZFail ||
  11629. currentStencilZPass !== stencilZPass ) {
  11630. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11631. currentStencilFail = stencilFail;
  11632. currentStencilZFail = stencilZFail;
  11633. currentStencilZPass = stencilZPass;
  11634. }
  11635. },
  11636. setLocked: function ( lock ) {
  11637. locked = lock;
  11638. },
  11639. setClear: function ( stencil ) {
  11640. if ( currentStencilClear !== stencil ) {
  11641. gl.clearStencil( stencil );
  11642. currentStencilClear = stencil;
  11643. }
  11644. },
  11645. reset: function () {
  11646. locked = false;
  11647. currentStencilMask = null;
  11648. currentStencilFunc = null;
  11649. currentStencilRef = null;
  11650. currentStencilFuncMask = null;
  11651. currentStencilFail = null;
  11652. currentStencilZFail = null;
  11653. currentStencilZPass = null;
  11654. currentStencilClear = null;
  11655. }
  11656. };
  11657. }
  11658. //
  11659. const colorBuffer = new ColorBuffer();
  11660. const depthBuffer = new DepthBuffer();
  11661. const stencilBuffer = new StencilBuffer();
  11662. let enabledCapabilities = {};
  11663. let currentProgram = null;
  11664. let currentBlendingEnabled = false;
  11665. let currentBlending = null;
  11666. let currentBlendEquation = null;
  11667. let currentBlendSrc = null;
  11668. let currentBlendDst = null;
  11669. let currentBlendEquationAlpha = null;
  11670. let currentBlendSrcAlpha = null;
  11671. let currentBlendDstAlpha = null;
  11672. let currentPremultipledAlpha = false;
  11673. let currentFlipSided = null;
  11674. let currentCullFace = null;
  11675. let currentLineWidth = null;
  11676. let currentPolygonOffsetFactor = null;
  11677. let currentPolygonOffsetUnits = null;
  11678. const maxTextures = gl.getParameter( 35661 );
  11679. let lineWidthAvailable = false;
  11680. let version = 0;
  11681. const glVersion = gl.getParameter( 7938 );
  11682. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11683. version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] );
  11684. lineWidthAvailable = ( version >= 1.0 );
  11685. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11686. version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] );
  11687. lineWidthAvailable = ( version >= 2.0 );
  11688. }
  11689. let currentTextureSlot = null;
  11690. let currentBoundTextures = {};
  11691. const currentScissor = new Vector4();
  11692. const currentViewport = new Vector4();
  11693. function createTexture( type, target, count ) {
  11694. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11695. const texture = gl.createTexture();
  11696. gl.bindTexture( type, texture );
  11697. gl.texParameteri( type, 10241, 9728 );
  11698. gl.texParameteri( type, 10240, 9728 );
  11699. for ( let i = 0; i < count; i ++ ) {
  11700. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11701. }
  11702. return texture;
  11703. }
  11704. const emptyTextures = {};
  11705. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11706. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11707. // init
  11708. colorBuffer.setClear( 0, 0, 0, 1 );
  11709. depthBuffer.setClear( 1 );
  11710. stencilBuffer.setClear( 0 );
  11711. enable( 2929 );
  11712. depthBuffer.setFunc( LessEqualDepth );
  11713. setFlipSided( false );
  11714. setCullFace( CullFaceBack );
  11715. enable( 2884 );
  11716. setBlending( NoBlending );
  11717. //
  11718. function enable( id ) {
  11719. if ( enabledCapabilities[ id ] !== true ) {
  11720. gl.enable( id );
  11721. enabledCapabilities[ id ] = true;
  11722. }
  11723. }
  11724. function disable( id ) {
  11725. if ( enabledCapabilities[ id ] !== false ) {
  11726. gl.disable( id );
  11727. enabledCapabilities[ id ] = false;
  11728. }
  11729. }
  11730. function useProgram( program ) {
  11731. if ( currentProgram !== program ) {
  11732. gl.useProgram( program );
  11733. currentProgram = program;
  11734. return true;
  11735. }
  11736. return false;
  11737. }
  11738. const equationToGL = {
  11739. [ AddEquation ]: 32774,
  11740. [ SubtractEquation ]: 32778,
  11741. [ ReverseSubtractEquation ]: 32779
  11742. };
  11743. if ( isWebGL2 ) {
  11744. equationToGL[ MinEquation ] = 32775;
  11745. equationToGL[ MaxEquation ] = 32776;
  11746. } else {
  11747. const extension = extensions.get( 'EXT_blend_minmax' );
  11748. if ( extension !== null ) {
  11749. equationToGL[ MinEquation ] = extension.MIN_EXT;
  11750. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  11751. }
  11752. }
  11753. const factorToGL = {
  11754. [ ZeroFactor ]: 0,
  11755. [ OneFactor ]: 1,
  11756. [ SrcColorFactor ]: 768,
  11757. [ SrcAlphaFactor ]: 770,
  11758. [ SrcAlphaSaturateFactor ]: 776,
  11759. [ DstColorFactor ]: 774,
  11760. [ DstAlphaFactor ]: 772,
  11761. [ OneMinusSrcColorFactor ]: 769,
  11762. [ OneMinusSrcAlphaFactor ]: 771,
  11763. [ OneMinusDstColorFactor ]: 775,
  11764. [ OneMinusDstAlphaFactor ]: 773
  11765. };
  11766. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11767. if ( blending === NoBlending ) {
  11768. if ( currentBlendingEnabled === true ) {
  11769. disable( 3042 );
  11770. currentBlendingEnabled = false;
  11771. }
  11772. return;
  11773. }
  11774. if ( currentBlendingEnabled === false ) {
  11775. enable( 3042 );
  11776. currentBlendingEnabled = true;
  11777. }
  11778. if ( blending !== CustomBlending ) {
  11779. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11780. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11781. gl.blendEquation( 32774 );
  11782. currentBlendEquation = AddEquation;
  11783. currentBlendEquationAlpha = AddEquation;
  11784. }
  11785. if ( premultipliedAlpha ) {
  11786. switch ( blending ) {
  11787. case NormalBlending:
  11788. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11789. break;
  11790. case AdditiveBlending:
  11791. gl.blendFunc( 1, 1 );
  11792. break;
  11793. case SubtractiveBlending:
  11794. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11795. break;
  11796. case MultiplyBlending:
  11797. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11798. break;
  11799. default:
  11800. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11801. break;
  11802. }
  11803. } else {
  11804. switch ( blending ) {
  11805. case NormalBlending:
  11806. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11807. break;
  11808. case AdditiveBlending:
  11809. gl.blendFunc( 770, 1 );
  11810. break;
  11811. case SubtractiveBlending:
  11812. gl.blendFunc( 0, 769 );
  11813. break;
  11814. case MultiplyBlending:
  11815. gl.blendFunc( 0, 768 );
  11816. break;
  11817. default:
  11818. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11819. break;
  11820. }
  11821. }
  11822. currentBlendSrc = null;
  11823. currentBlendDst = null;
  11824. currentBlendSrcAlpha = null;
  11825. currentBlendDstAlpha = null;
  11826. currentBlending = blending;
  11827. currentPremultipledAlpha = premultipliedAlpha;
  11828. }
  11829. return;
  11830. }
  11831. // custom blending
  11832. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11833. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11834. blendDstAlpha = blendDstAlpha || blendDst;
  11835. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11836. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  11837. currentBlendEquation = blendEquation;
  11838. currentBlendEquationAlpha = blendEquationAlpha;
  11839. }
  11840. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11841. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  11842. currentBlendSrc = blendSrc;
  11843. currentBlendDst = blendDst;
  11844. currentBlendSrcAlpha = blendSrcAlpha;
  11845. currentBlendDstAlpha = blendDstAlpha;
  11846. }
  11847. currentBlending = blending;
  11848. currentPremultipledAlpha = null;
  11849. }
  11850. function setMaterial( material, frontFaceCW ) {
  11851. material.side === DoubleSide
  11852. ? disable( 2884 )
  11853. : enable( 2884 );
  11854. let flipSided = ( material.side === BackSide );
  11855. if ( frontFaceCW ) flipSided = ! flipSided;
  11856. setFlipSided( flipSided );
  11857. ( material.blending === NormalBlending && material.transparent === false )
  11858. ? setBlending( NoBlending )
  11859. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11860. depthBuffer.setFunc( material.depthFunc );
  11861. depthBuffer.setTest( material.depthTest );
  11862. depthBuffer.setMask( material.depthWrite );
  11863. colorBuffer.setMask( material.colorWrite );
  11864. const stencilWrite = material.stencilWrite;
  11865. stencilBuffer.setTest( stencilWrite );
  11866. if ( stencilWrite ) {
  11867. stencilBuffer.setMask( material.stencilWriteMask );
  11868. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  11869. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  11870. }
  11871. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11872. material.alphaToCoverage === true
  11873. ? enable( 32926 )
  11874. : disable( 32926 );
  11875. }
  11876. //
  11877. function setFlipSided( flipSided ) {
  11878. if ( currentFlipSided !== flipSided ) {
  11879. if ( flipSided ) {
  11880. gl.frontFace( 2304 );
  11881. } else {
  11882. gl.frontFace( 2305 );
  11883. }
  11884. currentFlipSided = flipSided;
  11885. }
  11886. }
  11887. function setCullFace( cullFace ) {
  11888. if ( cullFace !== CullFaceNone ) {
  11889. enable( 2884 );
  11890. if ( cullFace !== currentCullFace ) {
  11891. if ( cullFace === CullFaceBack ) {
  11892. gl.cullFace( 1029 );
  11893. } else if ( cullFace === CullFaceFront ) {
  11894. gl.cullFace( 1028 );
  11895. } else {
  11896. gl.cullFace( 1032 );
  11897. }
  11898. }
  11899. } else {
  11900. disable( 2884 );
  11901. }
  11902. currentCullFace = cullFace;
  11903. }
  11904. function setLineWidth( width ) {
  11905. if ( width !== currentLineWidth ) {
  11906. if ( lineWidthAvailable ) gl.lineWidth( width );
  11907. currentLineWidth = width;
  11908. }
  11909. }
  11910. function setPolygonOffset( polygonOffset, factor, units ) {
  11911. if ( polygonOffset ) {
  11912. enable( 32823 );
  11913. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11914. gl.polygonOffset( factor, units );
  11915. currentPolygonOffsetFactor = factor;
  11916. currentPolygonOffsetUnits = units;
  11917. }
  11918. } else {
  11919. disable( 32823 );
  11920. }
  11921. }
  11922. function setScissorTest( scissorTest ) {
  11923. if ( scissorTest ) {
  11924. enable( 3089 );
  11925. } else {
  11926. disable( 3089 );
  11927. }
  11928. }
  11929. // texture
  11930. function activeTexture( webglSlot ) {
  11931. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11932. if ( currentTextureSlot !== webglSlot ) {
  11933. gl.activeTexture( webglSlot );
  11934. currentTextureSlot = webglSlot;
  11935. }
  11936. }
  11937. function bindTexture( webglType, webglTexture ) {
  11938. if ( currentTextureSlot === null ) {
  11939. activeTexture();
  11940. }
  11941. let boundTexture = currentBoundTextures[ currentTextureSlot ];
  11942. if ( boundTexture === undefined ) {
  11943. boundTexture = { type: undefined, texture: undefined };
  11944. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11945. }
  11946. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11947. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11948. boundTexture.type = webglType;
  11949. boundTexture.texture = webglTexture;
  11950. }
  11951. }
  11952. function unbindTexture() {
  11953. const boundTexture = currentBoundTextures[ currentTextureSlot ];
  11954. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  11955. gl.bindTexture( boundTexture.type, null );
  11956. boundTexture.type = undefined;
  11957. boundTexture.texture = undefined;
  11958. }
  11959. }
  11960. function compressedTexImage2D() {
  11961. try {
  11962. gl.compressedTexImage2D.apply( gl, arguments );
  11963. } catch ( error ) {
  11964. console.error( 'THREE.WebGLState:', error );
  11965. }
  11966. }
  11967. function texImage2D() {
  11968. try {
  11969. gl.texImage2D.apply( gl, arguments );
  11970. } catch ( error ) {
  11971. console.error( 'THREE.WebGLState:', error );
  11972. }
  11973. }
  11974. function texImage3D() {
  11975. try {
  11976. gl.texImage3D.apply( gl, arguments );
  11977. } catch ( error ) {
  11978. console.error( 'THREE.WebGLState:', error );
  11979. }
  11980. }
  11981. //
  11982. function scissor( scissor ) {
  11983. if ( currentScissor.equals( scissor ) === false ) {
  11984. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11985. currentScissor.copy( scissor );
  11986. }
  11987. }
  11988. function viewport( viewport ) {
  11989. if ( currentViewport.equals( viewport ) === false ) {
  11990. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11991. currentViewport.copy( viewport );
  11992. }
  11993. }
  11994. //
  11995. function reset() {
  11996. // reset state
  11997. gl.disable( 3042 );
  11998. gl.disable( 2884 );
  11999. gl.disable( 2929 );
  12000. gl.disable( 32823 );
  12001. gl.disable( 3089 );
  12002. gl.disable( 2960 );
  12003. gl.disable( 32926 );
  12004. gl.blendEquation( 32774 );
  12005. gl.blendFunc( 1, 0 );
  12006. gl.blendFuncSeparate( 1, 0, 1, 0 );
  12007. gl.colorMask( true, true, true, true );
  12008. gl.clearColor( 0, 0, 0, 0 );
  12009. gl.depthMask( true );
  12010. gl.depthFunc( 513 );
  12011. gl.clearDepth( 1 );
  12012. gl.stencilMask( 0xffffffff );
  12013. gl.stencilFunc( 519, 0, 0xffffffff );
  12014. gl.stencilOp( 7680, 7680, 7680 );
  12015. gl.clearStencil( 0 );
  12016. gl.cullFace( 1029 );
  12017. gl.frontFace( 2305 );
  12018. gl.polygonOffset( 0, 0 );
  12019. gl.activeTexture( 33984 );
  12020. gl.useProgram( null );
  12021. gl.lineWidth( 1 );
  12022. gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
  12023. gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );
  12024. // reset internals
  12025. enabledCapabilities = {};
  12026. currentTextureSlot = null;
  12027. currentBoundTextures = {};
  12028. currentProgram = null;
  12029. currentBlendingEnabled = false;
  12030. currentBlending = null;
  12031. currentBlendEquation = null;
  12032. currentBlendSrc = null;
  12033. currentBlendDst = null;
  12034. currentBlendEquationAlpha = null;
  12035. currentBlendSrcAlpha = null;
  12036. currentBlendDstAlpha = null;
  12037. currentPremultipledAlpha = false;
  12038. currentFlipSided = null;
  12039. currentCullFace = null;
  12040. currentLineWidth = null;
  12041. currentPolygonOffsetFactor = null;
  12042. currentPolygonOffsetUnits = null;
  12043. colorBuffer.reset();
  12044. depthBuffer.reset();
  12045. stencilBuffer.reset();
  12046. }
  12047. return {
  12048. buffers: {
  12049. color: colorBuffer,
  12050. depth: depthBuffer,
  12051. stencil: stencilBuffer
  12052. },
  12053. enable: enable,
  12054. disable: disable,
  12055. useProgram: useProgram,
  12056. setBlending: setBlending,
  12057. setMaterial: setMaterial,
  12058. setFlipSided: setFlipSided,
  12059. setCullFace: setCullFace,
  12060. setLineWidth: setLineWidth,
  12061. setPolygonOffset: setPolygonOffset,
  12062. setScissorTest: setScissorTest,
  12063. activeTexture: activeTexture,
  12064. bindTexture: bindTexture,
  12065. unbindTexture: unbindTexture,
  12066. compressedTexImage2D: compressedTexImage2D,
  12067. texImage2D: texImage2D,
  12068. texImage3D: texImage3D,
  12069. scissor: scissor,
  12070. viewport: viewport,
  12071. reset: reset
  12072. };
  12073. }
  12074. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12075. const isWebGL2 = capabilities.isWebGL2;
  12076. const maxTextures = capabilities.maxTextures;
  12077. const maxCubemapSize = capabilities.maxCubemapSize;
  12078. const maxTextureSize = capabilities.maxTextureSize;
  12079. const maxSamples = capabilities.maxSamples;
  12080. const _videoTextures = new WeakMap();
  12081. let _canvas;
  12082. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12083. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12084. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12085. let useOffscreenCanvas = false;
  12086. try {
  12087. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  12088. && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;
  12089. } catch ( err ) {
  12090. // Ignore any errors
  12091. }
  12092. function createCanvas( width, height ) {
  12093. // Use OffscreenCanvas when available. Specially needed in web workers
  12094. return useOffscreenCanvas ?
  12095. new OffscreenCanvas( width, height ) :
  12096. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12097. }
  12098. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12099. let scale = 1;
  12100. // handle case if texture exceeds max size
  12101. if ( image.width > maxSize || image.height > maxSize ) {
  12102. scale = maxSize / Math.max( image.width, image.height );
  12103. }
  12104. // only perform resize if necessary
  12105. if ( scale < 1 || needsPowerOfTwo === true ) {
  12106. // only perform resize for certain image types
  12107. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12108. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12109. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12110. const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12111. const width = floor( scale * image.width );
  12112. const height = floor( scale * image.height );
  12113. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12114. // cube textures can't reuse the same canvas
  12115. const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12116. canvas.width = width;
  12117. canvas.height = height;
  12118. const context = canvas.getContext( '2d' );
  12119. context.drawImage( image, 0, 0, width, height );
  12120. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12121. return canvas;
  12122. } else {
  12123. if ( 'data' in image ) {
  12124. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12125. }
  12126. return image;
  12127. }
  12128. }
  12129. return image;
  12130. }
  12131. function isPowerOfTwo( image ) {
  12132. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  12133. }
  12134. function textureNeedsPowerOfTwo( texture ) {
  12135. if ( isWebGL2 ) return false;
  12136. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12137. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12138. }
  12139. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12140. return texture.generateMipmaps && supportsMips &&
  12141. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12142. }
  12143. function generateMipmap( target, texture, width, height ) {
  12144. _gl.generateMipmap( target );
  12145. const textureProperties = properties.get( texture );
  12146. textureProperties.__maxMipLevel = Math.log2( Math.max( width, height ) );
  12147. }
  12148. function getInternalFormat( internalFormatName, glFormat, glType ) {
  12149. if ( isWebGL2 === false ) return glFormat;
  12150. if ( internalFormatName !== null ) {
  12151. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  12152. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  12153. }
  12154. let internalFormat = glFormat;
  12155. if ( glFormat === 6403 ) {
  12156. if ( glType === 5126 ) internalFormat = 33326;
  12157. if ( glType === 5131 ) internalFormat = 33325;
  12158. if ( glType === 5121 ) internalFormat = 33321;
  12159. }
  12160. if ( glFormat === 6407 ) {
  12161. if ( glType === 5126 ) internalFormat = 34837;
  12162. if ( glType === 5131 ) internalFormat = 34843;
  12163. if ( glType === 5121 ) internalFormat = 32849;
  12164. }
  12165. if ( glFormat === 6408 ) {
  12166. if ( glType === 5126 ) internalFormat = 34836;
  12167. if ( glType === 5131 ) internalFormat = 34842;
  12168. if ( glType === 5121 ) internalFormat = 32856;
  12169. }
  12170. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12171. internalFormat === 34842 || internalFormat === 34836 ) {
  12172. extensions.get( 'EXT_color_buffer_float' );
  12173. }
  12174. return internalFormat;
  12175. }
  12176. // Fallback filters for non-power-of-2 textures
  12177. function filterFallback( f ) {
  12178. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12179. return 9728;
  12180. }
  12181. return 9729;
  12182. }
  12183. //
  12184. function onTextureDispose( event ) {
  12185. const texture = event.target;
  12186. texture.removeEventListener( 'dispose', onTextureDispose );
  12187. deallocateTexture( texture );
  12188. if ( texture.isVideoTexture ) {
  12189. _videoTextures.delete( texture );
  12190. }
  12191. info.memory.textures --;
  12192. }
  12193. function onRenderTargetDispose( event ) {
  12194. const renderTarget = event.target;
  12195. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12196. deallocateRenderTarget( renderTarget );
  12197. info.memory.textures --;
  12198. }
  12199. //
  12200. function deallocateTexture( texture ) {
  12201. const textureProperties = properties.get( texture );
  12202. if ( textureProperties.__webglInit === undefined ) return;
  12203. _gl.deleteTexture( textureProperties.__webglTexture );
  12204. properties.remove( texture );
  12205. }
  12206. function deallocateRenderTarget( renderTarget ) {
  12207. const texture = renderTarget.texture;
  12208. const renderTargetProperties = properties.get( renderTarget );
  12209. const textureProperties = properties.get( texture );
  12210. if ( ! renderTarget ) return;
  12211. if ( textureProperties.__webglTexture !== undefined ) {
  12212. _gl.deleteTexture( textureProperties.__webglTexture );
  12213. }
  12214. if ( renderTarget.depthTexture ) {
  12215. renderTarget.depthTexture.dispose();
  12216. }
  12217. if ( renderTarget.isWebGLCubeRenderTarget ) {
  12218. for ( let i = 0; i < 6; i ++ ) {
  12219. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12220. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12221. }
  12222. } else {
  12223. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12224. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12225. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  12226. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  12227. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  12228. }
  12229. properties.remove( texture );
  12230. properties.remove( renderTarget );
  12231. }
  12232. //
  12233. let textureUnits = 0;
  12234. function resetTextureUnits() {
  12235. textureUnits = 0;
  12236. }
  12237. function allocateTextureUnit() {
  12238. const textureUnit = textureUnits;
  12239. if ( textureUnit >= maxTextures ) {
  12240. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  12241. }
  12242. textureUnits += 1;
  12243. return textureUnit;
  12244. }
  12245. //
  12246. function setTexture2D( texture, slot ) {
  12247. const textureProperties = properties.get( texture );
  12248. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12249. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12250. const image = texture.image;
  12251. if ( image === undefined ) {
  12252. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12253. } else if ( image.complete === false ) {
  12254. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12255. } else {
  12256. uploadTexture( textureProperties, texture, slot );
  12257. return;
  12258. }
  12259. }
  12260. state.activeTexture( 33984 + slot );
  12261. state.bindTexture( 3553, textureProperties.__webglTexture );
  12262. }
  12263. function setTexture2DArray( texture, slot ) {
  12264. const textureProperties = properties.get( texture );
  12265. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12266. uploadTexture( textureProperties, texture, slot );
  12267. return;
  12268. }
  12269. state.activeTexture( 33984 + slot );
  12270. state.bindTexture( 35866, textureProperties.__webglTexture );
  12271. }
  12272. function setTexture3D( texture, slot ) {
  12273. const textureProperties = properties.get( texture );
  12274. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12275. uploadTexture( textureProperties, texture, slot );
  12276. return;
  12277. }
  12278. state.activeTexture( 33984 + slot );
  12279. state.bindTexture( 32879, textureProperties.__webglTexture );
  12280. }
  12281. function setTextureCube( texture, slot ) {
  12282. const textureProperties = properties.get( texture );
  12283. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12284. uploadCubeTexture( textureProperties, texture, slot );
  12285. return;
  12286. }
  12287. state.activeTexture( 33984 + slot );
  12288. state.bindTexture( 34067, textureProperties.__webglTexture );
  12289. }
  12290. const wrappingToGL = {
  12291. [ RepeatWrapping ]: 10497,
  12292. [ ClampToEdgeWrapping ]: 33071,
  12293. [ MirroredRepeatWrapping ]: 33648
  12294. };
  12295. const filterToGL = {
  12296. [ NearestFilter ]: 9728,
  12297. [ NearestMipmapNearestFilter ]: 9984,
  12298. [ NearestMipmapLinearFilter ]: 9986,
  12299. [ LinearFilter ]: 9729,
  12300. [ LinearMipmapNearestFilter ]: 9985,
  12301. [ LinearMipmapLinearFilter ]: 9987
  12302. };
  12303. function setTextureParameters( textureType, texture, supportsMips ) {
  12304. if ( supportsMips ) {
  12305. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  12306. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  12307. if ( textureType === 32879 || textureType === 35866 ) {
  12308. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  12309. }
  12310. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  12311. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  12312. } else {
  12313. _gl.texParameteri( textureType, 10242, 33071 );
  12314. _gl.texParameteri( textureType, 10243, 33071 );
  12315. if ( textureType === 32879 || textureType === 35866 ) {
  12316. _gl.texParameteri( textureType, 32882, 33071 );
  12317. }
  12318. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12319. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12320. }
  12321. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12322. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12323. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12324. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12325. }
  12326. }
  12327. if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
  12328. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12329. if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
  12330. if ( isWebGL2 === false && ( texture.type === HalfFloatType && extensions.has( 'OES_texture_half_float_linear' ) === false ) ) return; // verify extension for WebGL 1 only
  12331. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12332. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12333. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12334. }
  12335. }
  12336. }
  12337. function initTexture( textureProperties, texture ) {
  12338. if ( textureProperties.__webglInit === undefined ) {
  12339. textureProperties.__webglInit = true;
  12340. texture.addEventListener( 'dispose', onTextureDispose );
  12341. textureProperties.__webglTexture = _gl.createTexture();
  12342. info.memory.textures ++;
  12343. }
  12344. }
  12345. function uploadTexture( textureProperties, texture, slot ) {
  12346. let textureType = 3553;
  12347. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12348. if ( texture.isDataTexture3D ) textureType = 32879;
  12349. initTexture( textureProperties, texture );
  12350. state.activeTexture( 33984 + slot );
  12351. state.bindTexture( textureType, textureProperties.__webglTexture );
  12352. _gl.pixelStorei( 37440, texture.flipY );
  12353. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12354. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12355. _gl.pixelStorei( 37443, 0 );
  12356. const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12357. const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  12358. const supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12359. glFormat = utils.convert( texture.format );
  12360. let glType = utils.convert( texture.type ),
  12361. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12362. setTextureParameters( textureType, texture, supportsMips );
  12363. let mipmap;
  12364. const mipmaps = texture.mipmaps;
  12365. if ( texture.isDepthTexture ) {
  12366. // populate depth texture with dummy data
  12367. glInternalFormat = 6402;
  12368. if ( isWebGL2 ) {
  12369. if ( texture.type === FloatType ) {
  12370. glInternalFormat = 36012;
  12371. } else if ( texture.type === UnsignedIntType ) {
  12372. glInternalFormat = 33190;
  12373. } else if ( texture.type === UnsignedInt248Type ) {
  12374. glInternalFormat = 35056;
  12375. } else {
  12376. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12377. }
  12378. } else {
  12379. if ( texture.type === FloatType ) {
  12380. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  12381. }
  12382. }
  12383. // validation checks for WebGL 1
  12384. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12385. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12386. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12387. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12388. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12389. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12390. texture.type = UnsignedShortType;
  12391. glType = utils.convert( texture.type );
  12392. }
  12393. }
  12394. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  12395. // Depth stencil textures need the DEPTH_STENCIL internal format
  12396. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12397. glInternalFormat = 34041;
  12398. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12399. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12400. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12401. if ( texture.type !== UnsignedInt248Type ) {
  12402. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12403. texture.type = UnsignedInt248Type;
  12404. glType = utils.convert( texture.type );
  12405. }
  12406. }
  12407. //
  12408. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12409. } else if ( texture.isDataTexture ) {
  12410. // use manually created mipmaps if available
  12411. // if there are no manual mipmaps
  12412. // set 0 level mipmap and then use GL to generate other mipmap levels
  12413. if ( mipmaps.length > 0 && supportsMips ) {
  12414. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12415. mipmap = mipmaps[ i ];
  12416. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12417. }
  12418. texture.generateMipmaps = false;
  12419. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12420. } else {
  12421. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12422. textureProperties.__maxMipLevel = 0;
  12423. }
  12424. } else if ( texture.isCompressedTexture ) {
  12425. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12426. mipmap = mipmaps[ i ];
  12427. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12428. if ( glFormat !== null ) {
  12429. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12430. } else {
  12431. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12432. }
  12433. } else {
  12434. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12435. }
  12436. }
  12437. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12438. } else if ( texture.isDataTexture2DArray ) {
  12439. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12440. textureProperties.__maxMipLevel = 0;
  12441. } else if ( texture.isDataTexture3D ) {
  12442. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12443. textureProperties.__maxMipLevel = 0;
  12444. } else {
  12445. // regular Texture (image, video, canvas)
  12446. // use manually created mipmaps if available
  12447. // if there are no manual mipmaps
  12448. // set 0 level mipmap and then use GL to generate other mipmap levels
  12449. if ( mipmaps.length > 0 && supportsMips ) {
  12450. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12451. mipmap = mipmaps[ i ];
  12452. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12453. }
  12454. texture.generateMipmaps = false;
  12455. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12456. } else {
  12457. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12458. textureProperties.__maxMipLevel = 0;
  12459. }
  12460. }
  12461. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12462. generateMipmap( textureType, texture, image.width, image.height );
  12463. }
  12464. textureProperties.__version = texture.version;
  12465. if ( texture.onUpdate ) texture.onUpdate( texture );
  12466. }
  12467. function uploadCubeTexture( textureProperties, texture, slot ) {
  12468. if ( texture.image.length !== 6 ) return;
  12469. initTexture( textureProperties, texture );
  12470. state.activeTexture( 33984 + slot );
  12471. state.bindTexture( 34067, textureProperties.__webglTexture );
  12472. _gl.pixelStorei( 37440, texture.flipY );
  12473. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12474. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12475. _gl.pixelStorei( 37443, 0 );
  12476. const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  12477. const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12478. const cubeImage = [];
  12479. for ( let i = 0; i < 6; i ++ ) {
  12480. if ( ! isCompressed && ! isDataTexture ) {
  12481. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  12482. } else {
  12483. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12484. }
  12485. }
  12486. const image = cubeImage[ 0 ],
  12487. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12488. glFormat = utils.convert( texture.format ),
  12489. glType = utils.convert( texture.type ),
  12490. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12491. setTextureParameters( 34067, texture, supportsMips );
  12492. let mipmaps;
  12493. if ( isCompressed ) {
  12494. for ( let i = 0; i < 6; i ++ ) {
  12495. mipmaps = cubeImage[ i ].mipmaps;
  12496. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12497. const mipmap = mipmaps[ j ];
  12498. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12499. if ( glFormat !== null ) {
  12500. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12501. } else {
  12502. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12503. }
  12504. } else {
  12505. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12506. }
  12507. }
  12508. }
  12509. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12510. } else {
  12511. mipmaps = texture.mipmaps;
  12512. for ( let i = 0; i < 6; i ++ ) {
  12513. if ( isDataTexture ) {
  12514. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12515. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12516. const mipmap = mipmaps[ j ];
  12517. const mipmapImage = mipmap.image[ i ].image;
  12518. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  12519. }
  12520. } else {
  12521. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12522. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12523. const mipmap = mipmaps[ j ];
  12524. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12525. }
  12526. }
  12527. }
  12528. textureProperties.__maxMipLevel = mipmaps.length;
  12529. }
  12530. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12531. // We assume images for cube map have the same size.
  12532. generateMipmap( 34067, texture, image.width, image.height );
  12533. }
  12534. textureProperties.__version = texture.version;
  12535. if ( texture.onUpdate ) texture.onUpdate( texture );
  12536. }
  12537. // Render targets
  12538. // Setup storage for target texture and bind it to correct framebuffer
  12539. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12540. const texture = renderTarget.texture;
  12541. const glFormat = utils.convert( texture.format );
  12542. const glType = utils.convert( texture.type );
  12543. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12544. if ( textureTarget === 32879 || textureTarget === 35866 ) {
  12545. state.texImage3D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null );
  12546. } else {
  12547. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12548. }
  12549. _gl.bindFramebuffer( 36160, framebuffer );
  12550. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( texture ).__webglTexture, 0 );
  12551. _gl.bindFramebuffer( 36160, null );
  12552. }
  12553. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12554. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12555. _gl.bindRenderbuffer( 36161, renderbuffer );
  12556. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12557. let glInternalFormat = 33189;
  12558. if ( isMultisample ) {
  12559. const depthTexture = renderTarget.depthTexture;
  12560. if ( depthTexture && depthTexture.isDepthTexture ) {
  12561. if ( depthTexture.type === FloatType ) {
  12562. glInternalFormat = 36012;
  12563. } else if ( depthTexture.type === UnsignedIntType ) {
  12564. glInternalFormat = 33190;
  12565. }
  12566. }
  12567. const samples = getRenderTargetSamples( renderTarget );
  12568. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12569. } else {
  12570. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12571. }
  12572. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12573. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12574. if ( isMultisample ) {
  12575. const samples = getRenderTargetSamples( renderTarget );
  12576. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12577. } else {
  12578. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12579. }
  12580. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12581. } else {
  12582. const texture = renderTarget.texture;
  12583. const glFormat = utils.convert( texture.format );
  12584. const glType = utils.convert( texture.type );
  12585. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12586. if ( isMultisample ) {
  12587. const samples = getRenderTargetSamples( renderTarget );
  12588. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12589. } else {
  12590. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12591. }
  12592. }
  12593. _gl.bindRenderbuffer( 36161, null );
  12594. }
  12595. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12596. function setupDepthTexture( framebuffer, renderTarget ) {
  12597. const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  12598. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12599. _gl.bindFramebuffer( 36160, framebuffer );
  12600. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12601. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12602. }
  12603. // upload an empty depth texture with framebuffer size
  12604. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12605. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12606. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12607. renderTarget.depthTexture.image.width = renderTarget.width;
  12608. renderTarget.depthTexture.image.height = renderTarget.height;
  12609. renderTarget.depthTexture.needsUpdate = true;
  12610. }
  12611. setTexture2D( renderTarget.depthTexture, 0 );
  12612. const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12613. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12614. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12615. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12616. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12617. } else {
  12618. throw new Error( 'Unknown depthTexture format' );
  12619. }
  12620. }
  12621. // Setup GL resources for a non-texture depth buffer
  12622. function setupDepthRenderbuffer( renderTarget ) {
  12623. const renderTargetProperties = properties.get( renderTarget );
  12624. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12625. if ( renderTarget.depthTexture ) {
  12626. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12627. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12628. } else {
  12629. if ( isCube ) {
  12630. renderTargetProperties.__webglDepthbuffer = [];
  12631. for ( let i = 0; i < 6; i ++ ) {
  12632. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12633. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12634. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  12635. }
  12636. } else {
  12637. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12638. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12639. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  12640. }
  12641. }
  12642. _gl.bindFramebuffer( 36160, null );
  12643. }
  12644. // Set up GL resources for the render target
  12645. function setupRenderTarget( renderTarget ) {
  12646. const texture = renderTarget.texture;
  12647. const renderTargetProperties = properties.get( renderTarget );
  12648. const textureProperties = properties.get( texture );
  12649. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12650. textureProperties.__webglTexture = _gl.createTexture();
  12651. info.memory.textures ++;
  12652. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12653. const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12654. const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  12655. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12656. // Handles WebGL2 RGBFormat fallback - #18858
  12657. if ( isWebGL2 && texture.format === RGBFormat && ( texture.type === FloatType || texture.type === HalfFloatType ) ) {
  12658. texture.format = RGBAFormat;
  12659. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  12660. }
  12661. // Setup framebuffer
  12662. if ( isCube ) {
  12663. renderTargetProperties.__webglFramebuffer = [];
  12664. for ( let i = 0; i < 6; i ++ ) {
  12665. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12666. }
  12667. } else {
  12668. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12669. if ( isMultisample ) {
  12670. if ( isWebGL2 ) {
  12671. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12672. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12673. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12674. const glFormat = utils.convert( texture.format );
  12675. const glType = utils.convert( texture.type );
  12676. const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12677. const samples = getRenderTargetSamples( renderTarget );
  12678. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12679. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12680. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12681. _gl.bindRenderbuffer( 36161, null );
  12682. if ( renderTarget.depthBuffer ) {
  12683. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12684. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12685. }
  12686. _gl.bindFramebuffer( 36160, null );
  12687. } else {
  12688. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12689. }
  12690. }
  12691. }
  12692. // Setup color buffer
  12693. if ( isCube ) {
  12694. state.bindTexture( 34067, textureProperties.__webglTexture );
  12695. setTextureParameters( 34067, texture, supportsMips );
  12696. for ( let i = 0; i < 6; i ++ ) {
  12697. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12698. }
  12699. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12700. generateMipmap( 34067, texture, renderTarget.width, renderTarget.height );
  12701. }
  12702. state.bindTexture( 34067, null );
  12703. } else {
  12704. let glTextureType = 3553;
  12705. if ( isRenderTarget3D ) {
  12706. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  12707. if ( isWebGL2 ) {
  12708. const isTexture3D = texture.isDataTexture3D;
  12709. glTextureType = isTexture3D ? 32879 : 35866;
  12710. } else {
  12711. console.warn( 'THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.' );
  12712. }
  12713. }
  12714. state.bindTexture( glTextureType, textureProperties.__webglTexture );
  12715. setTextureParameters( glTextureType, texture, supportsMips );
  12716. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType );
  12717. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12718. generateMipmap( 3553, texture, renderTarget.width, renderTarget.height );
  12719. }
  12720. state.bindTexture( 3553, null );
  12721. }
  12722. // Setup depth and stencil buffers
  12723. if ( renderTarget.depthBuffer ) {
  12724. setupDepthRenderbuffer( renderTarget );
  12725. }
  12726. }
  12727. function updateRenderTargetMipmap( renderTarget ) {
  12728. const texture = renderTarget.texture;
  12729. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12730. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12731. const target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  12732. const webglTexture = properties.get( texture ).__webglTexture;
  12733. state.bindTexture( target, webglTexture );
  12734. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12735. state.bindTexture( target, null );
  12736. }
  12737. }
  12738. function updateMultisampleRenderTarget( renderTarget ) {
  12739. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12740. if ( isWebGL2 ) {
  12741. const renderTargetProperties = properties.get( renderTarget );
  12742. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12743. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12744. const width = renderTarget.width;
  12745. const height = renderTarget.height;
  12746. let mask = 16384;
  12747. if ( renderTarget.depthBuffer ) mask |= 256;
  12748. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12749. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12750. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  12751. } else {
  12752. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12753. }
  12754. }
  12755. }
  12756. function getRenderTargetSamples( renderTarget ) {
  12757. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12758. Math.min( maxSamples, renderTarget.samples ) : 0;
  12759. }
  12760. function updateVideoTexture( texture ) {
  12761. const frame = info.render.frame;
  12762. // Check the last frame we updated the VideoTexture
  12763. if ( _videoTextures.get( texture ) !== frame ) {
  12764. _videoTextures.set( texture, frame );
  12765. texture.update();
  12766. }
  12767. }
  12768. // backwards compatibility
  12769. let warnedTexture2D = false;
  12770. let warnedTextureCube = false;
  12771. function safeSetTexture2D( texture, slot ) {
  12772. if ( texture && texture.isWebGLRenderTarget ) {
  12773. if ( warnedTexture2D === false ) {
  12774. console.warn( 'THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.' );
  12775. warnedTexture2D = true;
  12776. }
  12777. texture = texture.texture;
  12778. }
  12779. setTexture2D( texture, slot );
  12780. }
  12781. function safeSetTextureCube( texture, slot ) {
  12782. if ( texture && texture.isWebGLCubeRenderTarget ) {
  12783. if ( warnedTextureCube === false ) {
  12784. console.warn( 'THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.' );
  12785. warnedTextureCube = true;
  12786. }
  12787. texture = texture.texture;
  12788. }
  12789. setTextureCube( texture, slot );
  12790. }
  12791. //
  12792. this.allocateTextureUnit = allocateTextureUnit;
  12793. this.resetTextureUnits = resetTextureUnits;
  12794. this.setTexture2D = setTexture2D;
  12795. this.setTexture2DArray = setTexture2DArray;
  12796. this.setTexture3D = setTexture3D;
  12797. this.setTextureCube = setTextureCube;
  12798. this.setupRenderTarget = setupRenderTarget;
  12799. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12800. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12801. this.safeSetTexture2D = safeSetTexture2D;
  12802. this.safeSetTextureCube = safeSetTextureCube;
  12803. }
  12804. function WebGLUtils( gl, extensions, capabilities ) {
  12805. const isWebGL2 = capabilities.isWebGL2;
  12806. function convert( p ) {
  12807. let extension;
  12808. if ( p === UnsignedByteType ) return 5121;
  12809. if ( p === UnsignedShort4444Type ) return 32819;
  12810. if ( p === UnsignedShort5551Type ) return 32820;
  12811. if ( p === UnsignedShort565Type ) return 33635;
  12812. if ( p === ByteType ) return 5120;
  12813. if ( p === ShortType ) return 5122;
  12814. if ( p === UnsignedShortType ) return 5123;
  12815. if ( p === IntType ) return 5124;
  12816. if ( p === UnsignedIntType ) return 5125;
  12817. if ( p === FloatType ) return 5126;
  12818. if ( p === HalfFloatType ) {
  12819. if ( isWebGL2 ) return 5131;
  12820. extension = extensions.get( 'OES_texture_half_float' );
  12821. if ( extension !== null ) {
  12822. return extension.HALF_FLOAT_OES;
  12823. } else {
  12824. return null;
  12825. }
  12826. }
  12827. if ( p === AlphaFormat ) return 6406;
  12828. if ( p === RGBFormat ) return 6407;
  12829. if ( p === RGBAFormat ) return 6408;
  12830. if ( p === LuminanceFormat ) return 6409;
  12831. if ( p === LuminanceAlphaFormat ) return 6410;
  12832. if ( p === DepthFormat ) return 6402;
  12833. if ( p === DepthStencilFormat ) return 34041;
  12834. if ( p === RedFormat ) return 6403;
  12835. // WebGL2 formats.
  12836. if ( p === RedIntegerFormat ) return 36244;
  12837. if ( p === RGFormat ) return 33319;
  12838. if ( p === RGIntegerFormat ) return 33320;
  12839. if ( p === RGBIntegerFormat ) return 36248;
  12840. if ( p === RGBAIntegerFormat ) return 36249;
  12841. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12842. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12843. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12844. if ( extension !== null ) {
  12845. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12846. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12847. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12848. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12849. } else {
  12850. return null;
  12851. }
  12852. }
  12853. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12854. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12855. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12856. if ( extension !== null ) {
  12857. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12858. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12859. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12860. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12861. } else {
  12862. return null;
  12863. }
  12864. }
  12865. if ( p === RGB_ETC1_Format ) {
  12866. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12867. if ( extension !== null ) {
  12868. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12869. } else {
  12870. return null;
  12871. }
  12872. }
  12873. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  12874. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  12875. if ( extension !== null ) {
  12876. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  12877. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  12878. }
  12879. }
  12880. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12881. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12882. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12883. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12884. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  12885. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  12886. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  12887. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  12888. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  12889. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  12890. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12891. if ( extension !== null ) {
  12892. // TODO Complete?
  12893. return p;
  12894. } else {
  12895. return null;
  12896. }
  12897. }
  12898. if ( p === RGBA_BPTC_Format ) {
  12899. extension = extensions.get( 'EXT_texture_compression_bptc' );
  12900. if ( extension !== null ) {
  12901. // TODO Complete?
  12902. return p;
  12903. } else {
  12904. return null;
  12905. }
  12906. }
  12907. if ( p === UnsignedInt248Type ) {
  12908. if ( isWebGL2 ) return 34042;
  12909. extension = extensions.get( 'WEBGL_depth_texture' );
  12910. if ( extension !== null ) {
  12911. return extension.UNSIGNED_INT_24_8_WEBGL;
  12912. } else {
  12913. return null;
  12914. }
  12915. }
  12916. }
  12917. return { convert: convert };
  12918. }
  12919. class ArrayCamera extends PerspectiveCamera {
  12920. constructor( array = [] ) {
  12921. super();
  12922. this.cameras = array;
  12923. }
  12924. }
  12925. ArrayCamera.prototype.isArrayCamera = true;
  12926. class Group extends Object3D {
  12927. constructor() {
  12928. super();
  12929. this.type = 'Group';
  12930. }
  12931. }
  12932. Group.prototype.isGroup = true;
  12933. function WebXRController() {
  12934. this._targetRay = null;
  12935. this._grip = null;
  12936. this._hand = null;
  12937. }
  12938. Object.assign( WebXRController.prototype, {
  12939. constructor: WebXRController,
  12940. getHandSpace: function () {
  12941. if ( this._hand === null ) {
  12942. this._hand = new Group();
  12943. this._hand.matrixAutoUpdate = false;
  12944. this._hand.visible = false;
  12945. this._hand.joints = {};
  12946. this._hand.inputState = { pinching: false };
  12947. }
  12948. return this._hand;
  12949. },
  12950. getTargetRaySpace: function () {
  12951. if ( this._targetRay === null ) {
  12952. this._targetRay = new Group();
  12953. this._targetRay.matrixAutoUpdate = false;
  12954. this._targetRay.visible = false;
  12955. }
  12956. return this._targetRay;
  12957. },
  12958. getGripSpace: function () {
  12959. if ( this._grip === null ) {
  12960. this._grip = new Group();
  12961. this._grip.matrixAutoUpdate = false;
  12962. this._grip.visible = false;
  12963. }
  12964. return this._grip;
  12965. },
  12966. dispatchEvent: function ( event ) {
  12967. if ( this._targetRay !== null ) {
  12968. this._targetRay.dispatchEvent( event );
  12969. }
  12970. if ( this._grip !== null ) {
  12971. this._grip.dispatchEvent( event );
  12972. }
  12973. if ( this._hand !== null ) {
  12974. this._hand.dispatchEvent( event );
  12975. }
  12976. return this;
  12977. },
  12978. disconnect: function ( inputSource ) {
  12979. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  12980. if ( this._targetRay !== null ) {
  12981. this._targetRay.visible = false;
  12982. }
  12983. if ( this._grip !== null ) {
  12984. this._grip.visible = false;
  12985. }
  12986. if ( this._hand !== null ) {
  12987. this._hand.visible = false;
  12988. }
  12989. return this;
  12990. },
  12991. update: function ( inputSource, frame, referenceSpace ) {
  12992. let inputPose = null;
  12993. let gripPose = null;
  12994. let handPose = null;
  12995. const targetRay = this._targetRay;
  12996. const grip = this._grip;
  12997. const hand = this._hand;
  12998. if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) {
  12999. if ( targetRay !== null ) {
  13000. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13001. if ( inputPose !== null ) {
  13002. targetRay.matrix.fromArray( inputPose.transform.matrix );
  13003. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  13004. }
  13005. }
  13006. if ( hand && inputSource.hand ) {
  13007. handPose = true;
  13008. for ( const inputjoint of inputSource.hand.values() ) {
  13009. // Update the joints groups with the XRJoint poses
  13010. const jointPose = frame.getJointPose( inputjoint, referenceSpace );
  13011. if ( hand.joints[ inputjoint.jointName ] === undefined ) {
  13012. // The transform of this joint will be updated with the joint pose on each frame
  13013. const joint = new Group();
  13014. joint.matrixAutoUpdate = false;
  13015. joint.visible = false;
  13016. hand.joints[ inputjoint.jointName ] = joint;
  13017. // ??
  13018. hand.add( joint );
  13019. }
  13020. const joint = hand.joints[ inputjoint.jointName ];
  13021. if ( jointPose !== null ) {
  13022. joint.matrix.fromArray( jointPose.transform.matrix );
  13023. joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
  13024. joint.jointRadius = jointPose.radius;
  13025. }
  13026. joint.visible = jointPose !== null;
  13027. }
  13028. // Custom events
  13029. // Check pinchz
  13030. const indexTip = hand.joints[ 'index-finger-tip' ];
  13031. const thumbTip = hand.joints[ 'thumb-tip' ];
  13032. const distance = indexTip.position.distanceTo( thumbTip.position );
  13033. const distanceToPinch = 0.02;
  13034. const threshold = 0.005;
  13035. if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
  13036. hand.inputState.pinching = false;
  13037. this.dispatchEvent( {
  13038. type: 'pinchend',
  13039. handedness: inputSource.handedness,
  13040. target: this
  13041. } );
  13042. } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
  13043. hand.inputState.pinching = true;
  13044. this.dispatchEvent( {
  13045. type: 'pinchstart',
  13046. handedness: inputSource.handedness,
  13047. target: this
  13048. } );
  13049. }
  13050. } else {
  13051. if ( grip !== null && inputSource.gripSpace ) {
  13052. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  13053. if ( gripPose !== null ) {
  13054. grip.matrix.fromArray( gripPose.transform.matrix );
  13055. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  13056. }
  13057. }
  13058. }
  13059. }
  13060. if ( targetRay !== null ) {
  13061. targetRay.visible = ( inputPose !== null );
  13062. }
  13063. if ( grip !== null ) {
  13064. grip.visible = ( gripPose !== null );
  13065. }
  13066. if ( hand !== null ) {
  13067. hand.visible = ( handPose !== null );
  13068. }
  13069. return this;
  13070. }
  13071. } );
  13072. function WebXRManager( renderer, gl ) {
  13073. const scope = this;
  13074. let session = null;
  13075. let framebufferScaleFactor = 1.0;
  13076. let referenceSpace = null;
  13077. let referenceSpaceType = 'local-floor';
  13078. let pose = null;
  13079. const controllers = [];
  13080. const inputSourcesMap = new Map();
  13081. //
  13082. const cameraL = new PerspectiveCamera();
  13083. cameraL.layers.enable( 1 );
  13084. cameraL.viewport = new Vector4();
  13085. const cameraR = new PerspectiveCamera();
  13086. cameraR.layers.enable( 2 );
  13087. cameraR.viewport = new Vector4();
  13088. const cameras = [ cameraL, cameraR ];
  13089. const cameraVR = new ArrayCamera();
  13090. cameraVR.layers.enable( 1 );
  13091. cameraVR.layers.enable( 2 );
  13092. let _currentDepthNear = null;
  13093. let _currentDepthFar = null;
  13094. //
  13095. this.enabled = false;
  13096. this.isPresenting = false;
  13097. this.getController = function ( index ) {
  13098. let controller = controllers[ index ];
  13099. if ( controller === undefined ) {
  13100. controller = new WebXRController();
  13101. controllers[ index ] = controller;
  13102. }
  13103. return controller.getTargetRaySpace();
  13104. };
  13105. this.getControllerGrip = function ( index ) {
  13106. let controller = controllers[ index ];
  13107. if ( controller === undefined ) {
  13108. controller = new WebXRController();
  13109. controllers[ index ] = controller;
  13110. }
  13111. return controller.getGripSpace();
  13112. };
  13113. this.getHand = function ( index ) {
  13114. let controller = controllers[ index ];
  13115. if ( controller === undefined ) {
  13116. controller = new WebXRController();
  13117. controllers[ index ] = controller;
  13118. }
  13119. return controller.getHandSpace();
  13120. };
  13121. //
  13122. function onSessionEvent( event ) {
  13123. const controller = inputSourcesMap.get( event.inputSource );
  13124. if ( controller ) {
  13125. controller.dispatchEvent( { type: event.type, data: event.inputSource } );
  13126. }
  13127. }
  13128. function onSessionEnd() {
  13129. inputSourcesMap.forEach( function ( controller, inputSource ) {
  13130. controller.disconnect( inputSource );
  13131. } );
  13132. inputSourcesMap.clear();
  13133. _currentDepthNear = null;
  13134. _currentDepthFar = null;
  13135. //
  13136. renderer.setFramebuffer( null );
  13137. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13138. animation.stop();
  13139. scope.isPresenting = false;
  13140. scope.dispatchEvent( { type: 'sessionend' } );
  13141. }
  13142. this.setFramebufferScaleFactor = function ( value ) {
  13143. framebufferScaleFactor = value;
  13144. if ( scope.isPresenting === true ) {
  13145. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  13146. }
  13147. };
  13148. this.setReferenceSpaceType = function ( value ) {
  13149. referenceSpaceType = value;
  13150. if ( scope.isPresenting === true ) {
  13151. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  13152. }
  13153. };
  13154. this.getReferenceSpace = function () {
  13155. return referenceSpace;
  13156. };
  13157. this.getSession = function () {
  13158. return session;
  13159. };
  13160. this.setSession = async function ( value ) {
  13161. session = value;
  13162. if ( session !== null ) {
  13163. session.addEventListener( 'select', onSessionEvent );
  13164. session.addEventListener( 'selectstart', onSessionEvent );
  13165. session.addEventListener( 'selectend', onSessionEvent );
  13166. session.addEventListener( 'squeeze', onSessionEvent );
  13167. session.addEventListener( 'squeezestart', onSessionEvent );
  13168. session.addEventListener( 'squeezeend', onSessionEvent );
  13169. session.addEventListener( 'end', onSessionEnd );
  13170. session.addEventListener( 'inputsourceschange', onInputSourcesChange );
  13171. const attributes = gl.getContextAttributes();
  13172. if ( attributes.xrCompatible !== true ) {
  13173. await gl.makeXRCompatible();
  13174. }
  13175. const layerInit = {
  13176. antialias: attributes.antialias,
  13177. alpha: attributes.alpha,
  13178. depth: attributes.depth,
  13179. stencil: attributes.stencil,
  13180. framebufferScaleFactor: framebufferScaleFactor
  13181. };
  13182. // eslint-disable-next-line no-undef
  13183. const baseLayer = new XRWebGLLayer( session, gl, layerInit );
  13184. session.updateRenderState( { baseLayer: baseLayer } );
  13185. referenceSpace = await session.requestReferenceSpace( referenceSpaceType );
  13186. animation.setContext( session );
  13187. animation.start();
  13188. scope.isPresenting = true;
  13189. scope.dispatchEvent( { type: 'sessionstart' } );
  13190. }
  13191. };
  13192. function onInputSourcesChange( event ) {
  13193. const inputSources = session.inputSources;
  13194. // Assign inputSources to available controllers
  13195. for ( let i = 0; i < controllers.length; i ++ ) {
  13196. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  13197. }
  13198. // Notify disconnected
  13199. for ( let i = 0; i < event.removed.length; i ++ ) {
  13200. const inputSource = event.removed[ i ];
  13201. const controller = inputSourcesMap.get( inputSource );
  13202. if ( controller ) {
  13203. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13204. inputSourcesMap.delete( inputSource );
  13205. }
  13206. }
  13207. // Notify connected
  13208. for ( let i = 0; i < event.added.length; i ++ ) {
  13209. const inputSource = event.added[ i ];
  13210. const controller = inputSourcesMap.get( inputSource );
  13211. if ( controller ) {
  13212. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  13213. }
  13214. }
  13215. }
  13216. //
  13217. const cameraLPos = new Vector3();
  13218. const cameraRPos = new Vector3();
  13219. /**
  13220. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13221. * the cameras' projection and world matrices have already been set.
  13222. * And that near and far planes are identical for both cameras.
  13223. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13224. */
  13225. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13226. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13227. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13228. const ipd = cameraLPos.distanceTo( cameraRPos );
  13229. const projL = cameraL.projectionMatrix.elements;
  13230. const projR = cameraR.projectionMatrix.elements;
  13231. // VR systems will have identical far and near planes, and
  13232. // most likely identical top and bottom frustum extents.
  13233. // Use the left camera for these values.
  13234. const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13235. const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13236. const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13237. const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13238. const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13239. const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13240. const left = near * leftFov;
  13241. const right = near * rightFov;
  13242. // Calculate the new camera's position offset from the
  13243. // left camera. xOffset should be roughly half `ipd`.
  13244. const zOffset = ipd / ( - leftFov + rightFov );
  13245. const xOffset = zOffset * - leftFov;
  13246. // TODO: Better way to apply this offset?
  13247. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13248. camera.translateX( xOffset );
  13249. camera.translateZ( zOffset );
  13250. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13251. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13252. // Find the union of the frustum values of the cameras and scale
  13253. // the values so that the near plane's position does not change in world space,
  13254. // although must now be relative to the new union camera.
  13255. const near2 = near + zOffset;
  13256. const far2 = far + zOffset;
  13257. const left2 = left - xOffset;
  13258. const right2 = right + ( ipd - xOffset );
  13259. const top2 = topFov * far / far2 * near2;
  13260. const bottom2 = bottomFov * far / far2 * near2;
  13261. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13262. }
  13263. function updateCamera( camera, parent ) {
  13264. if ( parent === null ) {
  13265. camera.matrixWorld.copy( camera.matrix );
  13266. } else {
  13267. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13268. }
  13269. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13270. }
  13271. this.getCamera = function ( camera ) {
  13272. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13273. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13274. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  13275. // Note that the new renderState won't apply until the next frame. See #18320
  13276. session.updateRenderState( {
  13277. depthNear: cameraVR.near,
  13278. depthFar: cameraVR.far
  13279. } );
  13280. _currentDepthNear = cameraVR.near;
  13281. _currentDepthFar = cameraVR.far;
  13282. }
  13283. const parent = camera.parent;
  13284. const cameras = cameraVR.cameras;
  13285. updateCamera( cameraVR, parent );
  13286. for ( let i = 0; i < cameras.length; i ++ ) {
  13287. updateCamera( cameras[ i ], parent );
  13288. }
  13289. // update camera and its children
  13290. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13291. camera.matrix.copy( cameraVR.matrix );
  13292. camera.matrix.decompose( camera.position, camera.quaternion, camera.scale );
  13293. const children = camera.children;
  13294. for ( let i = 0, l = children.length; i < l; i ++ ) {
  13295. children[ i ].updateMatrixWorld( true );
  13296. }
  13297. // update projection matrix for proper view frustum culling
  13298. if ( cameras.length === 2 ) {
  13299. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13300. } else {
  13301. // assume single camera setup (AR)
  13302. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  13303. }
  13304. return cameraVR;
  13305. };
  13306. // Animation Loop
  13307. let onAnimationFrameCallback = null;
  13308. function onAnimationFrame( time, frame ) {
  13309. pose = frame.getViewerPose( referenceSpace );
  13310. if ( pose !== null ) {
  13311. const views = pose.views;
  13312. const baseLayer = session.renderState.baseLayer;
  13313. renderer.setFramebuffer( baseLayer.framebuffer );
  13314. let cameraVRNeedsUpdate = false;
  13315. // check if it's necessary to rebuild cameraVR's camera list
  13316. if ( views.length !== cameraVR.cameras.length ) {
  13317. cameraVR.cameras.length = 0;
  13318. cameraVRNeedsUpdate = true;
  13319. }
  13320. for ( let i = 0; i < views.length; i ++ ) {
  13321. const view = views[ i ];
  13322. const viewport = baseLayer.getViewport( view );
  13323. const camera = cameras[ i ];
  13324. camera.matrix.fromArray( view.transform.matrix );
  13325. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13326. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13327. if ( i === 0 ) {
  13328. cameraVR.matrix.copy( camera.matrix );
  13329. }
  13330. if ( cameraVRNeedsUpdate === true ) {
  13331. cameraVR.cameras.push( camera );
  13332. }
  13333. }
  13334. }
  13335. //
  13336. const inputSources = session.inputSources;
  13337. for ( let i = 0; i < controllers.length; i ++ ) {
  13338. const controller = controllers[ i ];
  13339. const inputSource = inputSources[ i ];
  13340. controller.update( inputSource, frame, referenceSpace );
  13341. }
  13342. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  13343. }
  13344. const animation = new WebGLAnimation();
  13345. animation.setAnimationLoop( onAnimationFrame );
  13346. this.setAnimationLoop = function ( callback ) {
  13347. onAnimationFrameCallback = callback;
  13348. };
  13349. this.dispose = function () {};
  13350. }
  13351. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13352. function WebGLMaterials( properties ) {
  13353. function refreshFogUniforms( uniforms, fog ) {
  13354. uniforms.fogColor.value.copy( fog.color );
  13355. if ( fog.isFog ) {
  13356. uniforms.fogNear.value = fog.near;
  13357. uniforms.fogFar.value = fog.far;
  13358. } else if ( fog.isFogExp2 ) {
  13359. uniforms.fogDensity.value = fog.density;
  13360. }
  13361. }
  13362. function refreshMaterialUniforms( uniforms, material, pixelRatio, height ) {
  13363. if ( material.isMeshBasicMaterial ) {
  13364. refreshUniformsCommon( uniforms, material );
  13365. } else if ( material.isMeshLambertMaterial ) {
  13366. refreshUniformsCommon( uniforms, material );
  13367. refreshUniformsLambert( uniforms, material );
  13368. } else if ( material.isMeshToonMaterial ) {
  13369. refreshUniformsCommon( uniforms, material );
  13370. refreshUniformsToon( uniforms, material );
  13371. } else if ( material.isMeshPhongMaterial ) {
  13372. refreshUniformsCommon( uniforms, material );
  13373. refreshUniformsPhong( uniforms, material );
  13374. } else if ( material.isMeshStandardMaterial ) {
  13375. refreshUniformsCommon( uniforms, material );
  13376. if ( material.isMeshPhysicalMaterial ) {
  13377. refreshUniformsPhysical( uniforms, material );
  13378. } else {
  13379. refreshUniformsStandard( uniforms, material );
  13380. }
  13381. } else if ( material.isMeshMatcapMaterial ) {
  13382. refreshUniformsCommon( uniforms, material );
  13383. refreshUniformsMatcap( uniforms, material );
  13384. } else if ( material.isMeshDepthMaterial ) {
  13385. refreshUniformsCommon( uniforms, material );
  13386. refreshUniformsDepth( uniforms, material );
  13387. } else if ( material.isMeshDistanceMaterial ) {
  13388. refreshUniformsCommon( uniforms, material );
  13389. refreshUniformsDistance( uniforms, material );
  13390. } else if ( material.isMeshNormalMaterial ) {
  13391. refreshUniformsCommon( uniforms, material );
  13392. refreshUniformsNormal( uniforms, material );
  13393. } else if ( material.isLineBasicMaterial ) {
  13394. refreshUniformsLine( uniforms, material );
  13395. if ( material.isLineDashedMaterial ) {
  13396. refreshUniformsDash( uniforms, material );
  13397. }
  13398. } else if ( material.isPointsMaterial ) {
  13399. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  13400. } else if ( material.isSpriteMaterial ) {
  13401. refreshUniformsSprites( uniforms, material );
  13402. } else if ( material.isShadowMaterial ) {
  13403. uniforms.color.value.copy( material.color );
  13404. uniforms.opacity.value = material.opacity;
  13405. } else if ( material.isShaderMaterial ) {
  13406. material.uniformsNeedUpdate = false; // #15581
  13407. }
  13408. }
  13409. function refreshUniformsCommon( uniforms, material ) {
  13410. uniforms.opacity.value = material.opacity;
  13411. if ( material.color ) {
  13412. uniforms.diffuse.value.copy( material.color );
  13413. }
  13414. if ( material.emissive ) {
  13415. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13416. }
  13417. if ( material.map ) {
  13418. uniforms.map.value = material.map;
  13419. }
  13420. if ( material.alphaMap ) {
  13421. uniforms.alphaMap.value = material.alphaMap;
  13422. }
  13423. if ( material.specularMap ) {
  13424. uniforms.specularMap.value = material.specularMap;
  13425. }
  13426. const envMap = properties.get( material ).envMap;
  13427. if ( envMap ) {
  13428. uniforms.envMap.value = envMap;
  13429. uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap._needsFlipEnvMap ) ? - 1 : 1;
  13430. uniforms.reflectivity.value = material.reflectivity;
  13431. uniforms.refractionRatio.value = material.refractionRatio;
  13432. const maxMipLevel = properties.get( envMap ).__maxMipLevel;
  13433. if ( maxMipLevel !== undefined ) {
  13434. uniforms.maxMipLevel.value = maxMipLevel;
  13435. }
  13436. }
  13437. if ( material.lightMap ) {
  13438. uniforms.lightMap.value = material.lightMap;
  13439. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13440. }
  13441. if ( material.aoMap ) {
  13442. uniforms.aoMap.value = material.aoMap;
  13443. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13444. }
  13445. // uv repeat and offset setting priorities
  13446. // 1. color map
  13447. // 2. specular map
  13448. // 3. displacementMap map
  13449. // 4. normal map
  13450. // 5. bump map
  13451. // 6. roughnessMap map
  13452. // 7. metalnessMap map
  13453. // 8. alphaMap map
  13454. // 9. emissiveMap map
  13455. // 10. clearcoat map
  13456. // 11. clearcoat normal map
  13457. // 12. clearcoat roughnessMap map
  13458. let uvScaleMap;
  13459. if ( material.map ) {
  13460. uvScaleMap = material.map;
  13461. } else if ( material.specularMap ) {
  13462. uvScaleMap = material.specularMap;
  13463. } else if ( material.displacementMap ) {
  13464. uvScaleMap = material.displacementMap;
  13465. } else if ( material.normalMap ) {
  13466. uvScaleMap = material.normalMap;
  13467. } else if ( material.bumpMap ) {
  13468. uvScaleMap = material.bumpMap;
  13469. } else if ( material.roughnessMap ) {
  13470. uvScaleMap = material.roughnessMap;
  13471. } else if ( material.metalnessMap ) {
  13472. uvScaleMap = material.metalnessMap;
  13473. } else if ( material.alphaMap ) {
  13474. uvScaleMap = material.alphaMap;
  13475. } else if ( material.emissiveMap ) {
  13476. uvScaleMap = material.emissiveMap;
  13477. } else if ( material.clearcoatMap ) {
  13478. uvScaleMap = material.clearcoatMap;
  13479. } else if ( material.clearcoatNormalMap ) {
  13480. uvScaleMap = material.clearcoatNormalMap;
  13481. } else if ( material.clearcoatRoughnessMap ) {
  13482. uvScaleMap = material.clearcoatRoughnessMap;
  13483. }
  13484. if ( uvScaleMap !== undefined ) {
  13485. // backwards compatibility
  13486. if ( uvScaleMap.isWebGLRenderTarget ) {
  13487. uvScaleMap = uvScaleMap.texture;
  13488. }
  13489. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13490. uvScaleMap.updateMatrix();
  13491. }
  13492. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13493. }
  13494. // uv repeat and offset setting priorities for uv2
  13495. // 1. ao map
  13496. // 2. light map
  13497. let uv2ScaleMap;
  13498. if ( material.aoMap ) {
  13499. uv2ScaleMap = material.aoMap;
  13500. } else if ( material.lightMap ) {
  13501. uv2ScaleMap = material.lightMap;
  13502. }
  13503. if ( uv2ScaleMap !== undefined ) {
  13504. // backwards compatibility
  13505. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  13506. uv2ScaleMap = uv2ScaleMap.texture;
  13507. }
  13508. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  13509. uv2ScaleMap.updateMatrix();
  13510. }
  13511. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  13512. }
  13513. }
  13514. function refreshUniformsLine( uniforms, material ) {
  13515. uniforms.diffuse.value.copy( material.color );
  13516. uniforms.opacity.value = material.opacity;
  13517. }
  13518. function refreshUniformsDash( uniforms, material ) {
  13519. uniforms.dashSize.value = material.dashSize;
  13520. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13521. uniforms.scale.value = material.scale;
  13522. }
  13523. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  13524. uniforms.diffuse.value.copy( material.color );
  13525. uniforms.opacity.value = material.opacity;
  13526. uniforms.size.value = material.size * pixelRatio;
  13527. uniforms.scale.value = height * 0.5;
  13528. if ( material.map ) {
  13529. uniforms.map.value = material.map;
  13530. }
  13531. if ( material.alphaMap ) {
  13532. uniforms.alphaMap.value = material.alphaMap;
  13533. }
  13534. // uv repeat and offset setting priorities
  13535. // 1. color map
  13536. // 2. alpha map
  13537. let uvScaleMap;
  13538. if ( material.map ) {
  13539. uvScaleMap = material.map;
  13540. } else if ( material.alphaMap ) {
  13541. uvScaleMap = material.alphaMap;
  13542. }
  13543. if ( uvScaleMap !== undefined ) {
  13544. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13545. uvScaleMap.updateMatrix();
  13546. }
  13547. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13548. }
  13549. }
  13550. function refreshUniformsSprites( uniforms, material ) {
  13551. uniforms.diffuse.value.copy( material.color );
  13552. uniforms.opacity.value = material.opacity;
  13553. uniforms.rotation.value = material.rotation;
  13554. if ( material.map ) {
  13555. uniforms.map.value = material.map;
  13556. }
  13557. if ( material.alphaMap ) {
  13558. uniforms.alphaMap.value = material.alphaMap;
  13559. }
  13560. // uv repeat and offset setting priorities
  13561. // 1. color map
  13562. // 2. alpha map
  13563. let uvScaleMap;
  13564. if ( material.map ) {
  13565. uvScaleMap = material.map;
  13566. } else if ( material.alphaMap ) {
  13567. uvScaleMap = material.alphaMap;
  13568. }
  13569. if ( uvScaleMap !== undefined ) {
  13570. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13571. uvScaleMap.updateMatrix();
  13572. }
  13573. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13574. }
  13575. }
  13576. function refreshUniformsLambert( uniforms, material ) {
  13577. if ( material.emissiveMap ) {
  13578. uniforms.emissiveMap.value = material.emissiveMap;
  13579. }
  13580. }
  13581. function refreshUniformsPhong( uniforms, material ) {
  13582. uniforms.specular.value.copy( material.specular );
  13583. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13584. if ( material.emissiveMap ) {
  13585. uniforms.emissiveMap.value = material.emissiveMap;
  13586. }
  13587. if ( material.bumpMap ) {
  13588. uniforms.bumpMap.value = material.bumpMap;
  13589. uniforms.bumpScale.value = material.bumpScale;
  13590. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13591. }
  13592. if ( material.normalMap ) {
  13593. uniforms.normalMap.value = material.normalMap;
  13594. uniforms.normalScale.value.copy( material.normalScale );
  13595. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13596. }
  13597. if ( material.displacementMap ) {
  13598. uniforms.displacementMap.value = material.displacementMap;
  13599. uniforms.displacementScale.value = material.displacementScale;
  13600. uniforms.displacementBias.value = material.displacementBias;
  13601. }
  13602. }
  13603. function refreshUniformsToon( uniforms, material ) {
  13604. if ( material.gradientMap ) {
  13605. uniforms.gradientMap.value = material.gradientMap;
  13606. }
  13607. if ( material.emissiveMap ) {
  13608. uniforms.emissiveMap.value = material.emissiveMap;
  13609. }
  13610. if ( material.bumpMap ) {
  13611. uniforms.bumpMap.value = material.bumpMap;
  13612. uniforms.bumpScale.value = material.bumpScale;
  13613. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13614. }
  13615. if ( material.normalMap ) {
  13616. uniforms.normalMap.value = material.normalMap;
  13617. uniforms.normalScale.value.copy( material.normalScale );
  13618. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13619. }
  13620. if ( material.displacementMap ) {
  13621. uniforms.displacementMap.value = material.displacementMap;
  13622. uniforms.displacementScale.value = material.displacementScale;
  13623. uniforms.displacementBias.value = material.displacementBias;
  13624. }
  13625. }
  13626. function refreshUniformsStandard( uniforms, material ) {
  13627. uniforms.roughness.value = material.roughness;
  13628. uniforms.metalness.value = material.metalness;
  13629. if ( material.roughnessMap ) {
  13630. uniforms.roughnessMap.value = material.roughnessMap;
  13631. }
  13632. if ( material.metalnessMap ) {
  13633. uniforms.metalnessMap.value = material.metalnessMap;
  13634. }
  13635. if ( material.emissiveMap ) {
  13636. uniforms.emissiveMap.value = material.emissiveMap;
  13637. }
  13638. if ( material.bumpMap ) {
  13639. uniforms.bumpMap.value = material.bumpMap;
  13640. uniforms.bumpScale.value = material.bumpScale;
  13641. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13642. }
  13643. if ( material.normalMap ) {
  13644. uniforms.normalMap.value = material.normalMap;
  13645. uniforms.normalScale.value.copy( material.normalScale );
  13646. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13647. }
  13648. if ( material.displacementMap ) {
  13649. uniforms.displacementMap.value = material.displacementMap;
  13650. uniforms.displacementScale.value = material.displacementScale;
  13651. uniforms.displacementBias.value = material.displacementBias;
  13652. }
  13653. const envMap = properties.get( material ).envMap;
  13654. if ( envMap ) {
  13655. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13656. uniforms.envMapIntensity.value = material.envMapIntensity;
  13657. }
  13658. }
  13659. function refreshUniformsPhysical( uniforms, material ) {
  13660. refreshUniformsStandard( uniforms, material );
  13661. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  13662. uniforms.clearcoat.value = material.clearcoat;
  13663. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  13664. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  13665. if ( material.clearcoatMap ) {
  13666. uniforms.clearcoatMap.value = material.clearcoatMap;
  13667. }
  13668. if ( material.clearcoatRoughnessMap ) {
  13669. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  13670. }
  13671. if ( material.clearcoatNormalMap ) {
  13672. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  13673. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  13674. if ( material.side === BackSide ) {
  13675. uniforms.clearcoatNormalScale.value.negate();
  13676. }
  13677. }
  13678. uniforms.transmission.value = material.transmission;
  13679. if ( material.transmissionMap ) {
  13680. uniforms.transmissionMap.value = material.transmissionMap;
  13681. }
  13682. }
  13683. function refreshUniformsMatcap( uniforms, material ) {
  13684. if ( material.matcap ) {
  13685. uniforms.matcap.value = material.matcap;
  13686. }
  13687. if ( material.bumpMap ) {
  13688. uniforms.bumpMap.value = material.bumpMap;
  13689. uniforms.bumpScale.value = material.bumpScale;
  13690. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13691. }
  13692. if ( material.normalMap ) {
  13693. uniforms.normalMap.value = material.normalMap;
  13694. uniforms.normalScale.value.copy( material.normalScale );
  13695. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13696. }
  13697. if ( material.displacementMap ) {
  13698. uniforms.displacementMap.value = material.displacementMap;
  13699. uniforms.displacementScale.value = material.displacementScale;
  13700. uniforms.displacementBias.value = material.displacementBias;
  13701. }
  13702. }
  13703. function refreshUniformsDepth( uniforms, material ) {
  13704. if ( material.displacementMap ) {
  13705. uniforms.displacementMap.value = material.displacementMap;
  13706. uniforms.displacementScale.value = material.displacementScale;
  13707. uniforms.displacementBias.value = material.displacementBias;
  13708. }
  13709. }
  13710. function refreshUniformsDistance( uniforms, material ) {
  13711. if ( material.displacementMap ) {
  13712. uniforms.displacementMap.value = material.displacementMap;
  13713. uniforms.displacementScale.value = material.displacementScale;
  13714. uniforms.displacementBias.value = material.displacementBias;
  13715. }
  13716. uniforms.referencePosition.value.copy( material.referencePosition );
  13717. uniforms.nearDistance.value = material.nearDistance;
  13718. uniforms.farDistance.value = material.farDistance;
  13719. }
  13720. function refreshUniformsNormal( uniforms, material ) {
  13721. if ( material.bumpMap ) {
  13722. uniforms.bumpMap.value = material.bumpMap;
  13723. uniforms.bumpScale.value = material.bumpScale;
  13724. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13725. }
  13726. if ( material.normalMap ) {
  13727. uniforms.normalMap.value = material.normalMap;
  13728. uniforms.normalScale.value.copy( material.normalScale );
  13729. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13730. }
  13731. if ( material.displacementMap ) {
  13732. uniforms.displacementMap.value = material.displacementMap;
  13733. uniforms.displacementScale.value = material.displacementScale;
  13734. uniforms.displacementBias.value = material.displacementBias;
  13735. }
  13736. }
  13737. return {
  13738. refreshFogUniforms: refreshFogUniforms,
  13739. refreshMaterialUniforms: refreshMaterialUniforms
  13740. };
  13741. }
  13742. function createCanvasElement() {
  13743. const canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13744. canvas.style.display = 'block';
  13745. return canvas;
  13746. }
  13747. function WebGLRenderer( parameters ) {
  13748. parameters = parameters || {};
  13749. const _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  13750. _context = parameters.context !== undefined ? parameters.context : null,
  13751. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13752. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13753. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13754. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13755. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13756. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13757. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13758. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13759. let currentRenderList = null;
  13760. let currentRenderState = null;
  13761. // render() can be called from within a callback triggered by another render.
  13762. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  13763. const renderListStack = [];
  13764. const renderStateStack = [];
  13765. // public properties
  13766. this.domElement = _canvas;
  13767. // Debug configuration container
  13768. this.debug = {
  13769. /**
  13770. * Enables error checking and reporting when shader programs are being compiled
  13771. * @type {boolean}
  13772. */
  13773. checkShaderErrors: true
  13774. };
  13775. // clearing
  13776. this.autoClear = true;
  13777. this.autoClearColor = true;
  13778. this.autoClearDepth = true;
  13779. this.autoClearStencil = true;
  13780. // scene graph
  13781. this.sortObjects = true;
  13782. // user-defined clipping
  13783. this.clippingPlanes = [];
  13784. this.localClippingEnabled = false;
  13785. // physically based shading
  13786. this.gammaFactor = 2.0; // for backwards compatibility
  13787. this.outputEncoding = LinearEncoding;
  13788. // physical lights
  13789. this.physicallyCorrectLights = false;
  13790. // tone mapping
  13791. this.toneMapping = NoToneMapping;
  13792. this.toneMappingExposure = 1.0;
  13793. // morphs
  13794. this.maxMorphTargets = 8;
  13795. this.maxMorphNormals = 4;
  13796. // internal properties
  13797. const _this = this;
  13798. let _isContextLost = false;
  13799. // internal state cache
  13800. let _framebuffer = null;
  13801. let _currentActiveCubeFace = 0;
  13802. let _currentActiveMipmapLevel = 0;
  13803. let _currentRenderTarget = null;
  13804. let _currentFramebuffer = null;
  13805. let _currentMaterialId = - 1;
  13806. let _currentCamera = null;
  13807. const _currentViewport = new Vector4();
  13808. const _currentScissor = new Vector4();
  13809. let _currentScissorTest = null;
  13810. //
  13811. let _width = _canvas.width;
  13812. let _height = _canvas.height;
  13813. let _pixelRatio = 1;
  13814. let _opaqueSort = null;
  13815. let _transparentSort = null;
  13816. const _viewport = new Vector4( 0, 0, _width, _height );
  13817. const _scissor = new Vector4( 0, 0, _width, _height );
  13818. let _scissorTest = false;
  13819. // frustum
  13820. const _frustum = new Frustum();
  13821. // clipping
  13822. let _clippingEnabled = false;
  13823. let _localClippingEnabled = false;
  13824. // camera matrices cache
  13825. const _projScreenMatrix = new Matrix4();
  13826. const _vector3 = new Vector3();
  13827. const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  13828. function getTargetPixelRatio() {
  13829. return _currentRenderTarget === null ? _pixelRatio : 1;
  13830. }
  13831. // initialize
  13832. let _gl = _context;
  13833. function getContext( contextNames, contextAttributes ) {
  13834. for ( let i = 0; i < contextNames.length; i ++ ) {
  13835. const contextName = contextNames[ i ];
  13836. const context = _canvas.getContext( contextName, contextAttributes );
  13837. if ( context !== null ) return context;
  13838. }
  13839. return null;
  13840. }
  13841. try {
  13842. const contextAttributes = {
  13843. alpha: _alpha,
  13844. depth: _depth,
  13845. stencil: _stencil,
  13846. antialias: _antialias,
  13847. premultipliedAlpha: _premultipliedAlpha,
  13848. preserveDrawingBuffer: _preserveDrawingBuffer,
  13849. powerPreference: _powerPreference,
  13850. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  13851. };
  13852. // event listeners must be registered before WebGL context is created, see #12753
  13853. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13854. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13855. if ( _gl === null ) {
  13856. const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  13857. if ( _this.isWebGL1Renderer === true ) {
  13858. contextNames.shift();
  13859. }
  13860. _gl = getContext( contextNames, contextAttributes );
  13861. if ( _gl === null ) {
  13862. if ( getContext( contextNames ) ) {
  13863. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13864. } else {
  13865. throw new Error( 'Error creating WebGL context.' );
  13866. }
  13867. }
  13868. }
  13869. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13870. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13871. _gl.getShaderPrecisionFormat = function () {
  13872. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13873. };
  13874. }
  13875. } catch ( error ) {
  13876. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13877. throw error;
  13878. }
  13879. let extensions, capabilities, state, info;
  13880. let properties, textures, cubemaps, attributes, geometries, objects;
  13881. let programCache, materials, renderLists, renderStates, clipping;
  13882. let background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13883. let utils, bindingStates;
  13884. function initGLContext() {
  13885. extensions = new WebGLExtensions( _gl );
  13886. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13887. extensions.init( capabilities );
  13888. utils = new WebGLUtils( _gl, extensions, capabilities );
  13889. state = new WebGLState( _gl, extensions, capabilities );
  13890. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  13891. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  13892. info = new WebGLInfo( _gl );
  13893. properties = new WebGLProperties();
  13894. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13895. cubemaps = new WebGLCubeMaps( _this );
  13896. attributes = new WebGLAttributes( _gl, capabilities );
  13897. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  13898. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  13899. objects = new WebGLObjects( _gl, geometries, attributes, info );
  13900. morphtargets = new WebGLMorphtargets( _gl );
  13901. clipping = new WebGLClipping( properties );
  13902. programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates, clipping );
  13903. materials = new WebGLMaterials( properties );
  13904. renderLists = new WebGLRenderLists( properties );
  13905. renderStates = new WebGLRenderStates( extensions, capabilities );
  13906. background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
  13907. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13908. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13909. info.programs = programCache.programs;
  13910. _this.capabilities = capabilities;
  13911. _this.extensions = extensions;
  13912. _this.properties = properties;
  13913. _this.renderLists = renderLists;
  13914. _this.state = state;
  13915. _this.info = info;
  13916. }
  13917. initGLContext();
  13918. // xr
  13919. const xr = new WebXRManager( _this, _gl );
  13920. this.xr = xr;
  13921. // shadow map
  13922. const shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13923. this.shadowMap = shadowMap;
  13924. // API
  13925. this.getContext = function () {
  13926. return _gl;
  13927. };
  13928. this.getContextAttributes = function () {
  13929. return _gl.getContextAttributes();
  13930. };
  13931. this.forceContextLoss = function () {
  13932. const extension = extensions.get( 'WEBGL_lose_context' );
  13933. if ( extension ) extension.loseContext();
  13934. };
  13935. this.forceContextRestore = function () {
  13936. const extension = extensions.get( 'WEBGL_lose_context' );
  13937. if ( extension ) extension.restoreContext();
  13938. };
  13939. this.getPixelRatio = function () {
  13940. return _pixelRatio;
  13941. };
  13942. this.setPixelRatio = function ( value ) {
  13943. if ( value === undefined ) return;
  13944. _pixelRatio = value;
  13945. this.setSize( _width, _height, false );
  13946. };
  13947. this.getSize = function ( target ) {
  13948. if ( target === undefined ) {
  13949. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13950. target = new Vector2();
  13951. }
  13952. return target.set( _width, _height );
  13953. };
  13954. this.setSize = function ( width, height, updateStyle ) {
  13955. if ( xr.isPresenting ) {
  13956. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13957. return;
  13958. }
  13959. _width = width;
  13960. _height = height;
  13961. _canvas.width = Math.floor( width * _pixelRatio );
  13962. _canvas.height = Math.floor( height * _pixelRatio );
  13963. if ( updateStyle !== false ) {
  13964. _canvas.style.width = width + 'px';
  13965. _canvas.style.height = height + 'px';
  13966. }
  13967. this.setViewport( 0, 0, width, height );
  13968. };
  13969. this.getDrawingBufferSize = function ( target ) {
  13970. if ( target === undefined ) {
  13971. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13972. target = new Vector2();
  13973. }
  13974. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  13975. };
  13976. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13977. _width = width;
  13978. _height = height;
  13979. _pixelRatio = pixelRatio;
  13980. _canvas.width = Math.floor( width * pixelRatio );
  13981. _canvas.height = Math.floor( height * pixelRatio );
  13982. this.setViewport( 0, 0, width, height );
  13983. };
  13984. this.getCurrentViewport = function ( target ) {
  13985. if ( target === undefined ) {
  13986. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13987. target = new Vector4();
  13988. }
  13989. return target.copy( _currentViewport );
  13990. };
  13991. this.getViewport = function ( target ) {
  13992. return target.copy( _viewport );
  13993. };
  13994. this.setViewport = function ( x, y, width, height ) {
  13995. if ( x.isVector4 ) {
  13996. _viewport.set( x.x, x.y, x.z, x.w );
  13997. } else {
  13998. _viewport.set( x, y, width, height );
  13999. }
  14000. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14001. };
  14002. this.getScissor = function ( target ) {
  14003. return target.copy( _scissor );
  14004. };
  14005. this.setScissor = function ( x, y, width, height ) {
  14006. if ( x.isVector4 ) {
  14007. _scissor.set( x.x, x.y, x.z, x.w );
  14008. } else {
  14009. _scissor.set( x, y, width, height );
  14010. }
  14011. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14012. };
  14013. this.getScissorTest = function () {
  14014. return _scissorTest;
  14015. };
  14016. this.setScissorTest = function ( boolean ) {
  14017. state.setScissorTest( _scissorTest = boolean );
  14018. };
  14019. this.setOpaqueSort = function ( method ) {
  14020. _opaqueSort = method;
  14021. };
  14022. this.setTransparentSort = function ( method ) {
  14023. _transparentSort = method;
  14024. };
  14025. // Clearing
  14026. this.getClearColor = function ( target ) {
  14027. if ( target === undefined ) {
  14028. console.warn( 'WebGLRenderer: .getClearColor() now requires a Color as an argument' );
  14029. target = new Color();
  14030. }
  14031. return target.copy( background.getClearColor() );
  14032. };
  14033. this.setClearColor = function () {
  14034. background.setClearColor.apply( background, arguments );
  14035. };
  14036. this.getClearAlpha = function () {
  14037. return background.getClearAlpha();
  14038. };
  14039. this.setClearAlpha = function () {
  14040. background.setClearAlpha.apply( background, arguments );
  14041. };
  14042. this.clear = function ( color, depth, stencil ) {
  14043. let bits = 0;
  14044. if ( color === undefined || color ) bits |= 16384;
  14045. if ( depth === undefined || depth ) bits |= 256;
  14046. if ( stencil === undefined || stencil ) bits |= 1024;
  14047. _gl.clear( bits );
  14048. };
  14049. this.clearColor = function () {
  14050. this.clear( true, false, false );
  14051. };
  14052. this.clearDepth = function () {
  14053. this.clear( false, true, false );
  14054. };
  14055. this.clearStencil = function () {
  14056. this.clear( false, false, true );
  14057. };
  14058. //
  14059. this.dispose = function () {
  14060. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14061. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14062. renderLists.dispose();
  14063. renderStates.dispose();
  14064. properties.dispose();
  14065. cubemaps.dispose();
  14066. objects.dispose();
  14067. bindingStates.dispose();
  14068. xr.dispose();
  14069. animation.stop();
  14070. };
  14071. // Events
  14072. function onContextLost( event ) {
  14073. event.preventDefault();
  14074. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14075. _isContextLost = true;
  14076. }
  14077. function onContextRestore( /* event */ ) {
  14078. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14079. _isContextLost = false;
  14080. initGLContext();
  14081. }
  14082. function onMaterialDispose( event ) {
  14083. const material = event.target;
  14084. material.removeEventListener( 'dispose', onMaterialDispose );
  14085. deallocateMaterial( material );
  14086. }
  14087. // Buffer deallocation
  14088. function deallocateMaterial( material ) {
  14089. releaseMaterialProgramReferences( material );
  14090. properties.remove( material );
  14091. }
  14092. function releaseMaterialProgramReferences( material ) {
  14093. const programs = properties.get( material ).programs;
  14094. if ( programs !== undefined ) {
  14095. programs.forEach( function ( program ) {
  14096. programCache.releaseProgram( program );
  14097. } );
  14098. }
  14099. }
  14100. // Buffer rendering
  14101. function renderObjectImmediate( object, program ) {
  14102. object.render( function ( object ) {
  14103. _this.renderBufferImmediate( object, program );
  14104. } );
  14105. }
  14106. this.renderBufferImmediate = function ( object, program ) {
  14107. bindingStates.initAttributes();
  14108. const buffers = properties.get( object );
  14109. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14110. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14111. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14112. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14113. const programAttributes = program.getAttributes();
  14114. if ( object.hasPositions ) {
  14115. _gl.bindBuffer( 34962, buffers.position );
  14116. _gl.bufferData( 34962, object.positionArray, 35048 );
  14117. bindingStates.enableAttribute( programAttributes.position );
  14118. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14119. }
  14120. if ( object.hasNormals ) {
  14121. _gl.bindBuffer( 34962, buffers.normal );
  14122. _gl.bufferData( 34962, object.normalArray, 35048 );
  14123. bindingStates.enableAttribute( programAttributes.normal );
  14124. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14125. }
  14126. if ( object.hasUvs ) {
  14127. _gl.bindBuffer( 34962, buffers.uv );
  14128. _gl.bufferData( 34962, object.uvArray, 35048 );
  14129. bindingStates.enableAttribute( programAttributes.uv );
  14130. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14131. }
  14132. if ( object.hasColors ) {
  14133. _gl.bindBuffer( 34962, buffers.color );
  14134. _gl.bufferData( 34962, object.colorArray, 35048 );
  14135. bindingStates.enableAttribute( programAttributes.color );
  14136. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14137. }
  14138. bindingStates.disableUnusedAttributes();
  14139. _gl.drawArrays( 4, 0, object.count );
  14140. object.count = 0;
  14141. };
  14142. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  14143. if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14144. const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14145. const program = setProgram( camera, scene, material, object );
  14146. state.setMaterial( material, frontFaceCW );
  14147. //
  14148. let index = geometry.index;
  14149. const position = geometry.attributes.position;
  14150. //
  14151. if ( index === null ) {
  14152. if ( position === undefined || position.count === 0 ) return;
  14153. } else if ( index.count === 0 ) {
  14154. return;
  14155. }
  14156. //
  14157. let rangeFactor = 1;
  14158. if ( material.wireframe === true ) {
  14159. index = geometries.getWireframeAttribute( geometry );
  14160. rangeFactor = 2;
  14161. }
  14162. if ( material.morphTargets || material.morphNormals ) {
  14163. morphtargets.update( object, geometry, material, program );
  14164. }
  14165. bindingStates.setup( object, material, program, geometry, index );
  14166. let attribute;
  14167. let renderer = bufferRenderer;
  14168. if ( index !== null ) {
  14169. attribute = attributes.get( index );
  14170. renderer = indexedBufferRenderer;
  14171. renderer.setIndex( attribute );
  14172. }
  14173. //
  14174. const dataCount = ( index !== null ) ? index.count : position.count;
  14175. const rangeStart = geometry.drawRange.start * rangeFactor;
  14176. const rangeCount = geometry.drawRange.count * rangeFactor;
  14177. const groupStart = group !== null ? group.start * rangeFactor : 0;
  14178. const groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14179. const drawStart = Math.max( rangeStart, groupStart );
  14180. const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14181. const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14182. if ( drawCount === 0 ) return;
  14183. //
  14184. if ( object.isMesh ) {
  14185. if ( material.wireframe === true ) {
  14186. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14187. renderer.setMode( 1 );
  14188. } else {
  14189. renderer.setMode( 4 );
  14190. }
  14191. } else if ( object.isLine ) {
  14192. let lineWidth = material.linewidth;
  14193. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14194. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14195. if ( object.isLineSegments ) {
  14196. renderer.setMode( 1 );
  14197. } else if ( object.isLineLoop ) {
  14198. renderer.setMode( 2 );
  14199. } else {
  14200. renderer.setMode( 3 );
  14201. }
  14202. } else if ( object.isPoints ) {
  14203. renderer.setMode( 0 );
  14204. } else if ( object.isSprite ) {
  14205. renderer.setMode( 4 );
  14206. }
  14207. if ( object.isInstancedMesh ) {
  14208. renderer.renderInstances( drawStart, drawCount, object.count );
  14209. } else if ( geometry.isInstancedBufferGeometry ) {
  14210. const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  14211. renderer.renderInstances( drawStart, drawCount, instanceCount );
  14212. } else {
  14213. renderer.render( drawStart, drawCount );
  14214. }
  14215. };
  14216. // Compile
  14217. this.compile = function ( scene, camera ) {
  14218. currentRenderState = renderStates.get( scene );
  14219. currentRenderState.init();
  14220. scene.traverseVisible( function ( object ) {
  14221. if ( object.isLight && object.layers.test( camera.layers ) ) {
  14222. currentRenderState.pushLight( object );
  14223. if ( object.castShadow ) {
  14224. currentRenderState.pushShadow( object );
  14225. }
  14226. }
  14227. } );
  14228. currentRenderState.setupLights();
  14229. scene.traverse( function ( object ) {
  14230. const material = object.material;
  14231. if ( material ) {
  14232. if ( Array.isArray( material ) ) {
  14233. for ( let i = 0; i < material.length; i ++ ) {
  14234. const material2 = material[ i ];
  14235. getProgram( material2, scene, object );
  14236. }
  14237. } else {
  14238. getProgram( material, scene, object );
  14239. }
  14240. }
  14241. } );
  14242. };
  14243. // Animation Loop
  14244. let onAnimationFrameCallback = null;
  14245. function onAnimationFrame( time ) {
  14246. if ( xr.isPresenting ) return;
  14247. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14248. }
  14249. const animation = new WebGLAnimation();
  14250. animation.setAnimationLoop( onAnimationFrame );
  14251. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14252. this.setAnimationLoop = function ( callback ) {
  14253. onAnimationFrameCallback = callback;
  14254. xr.setAnimationLoop( callback );
  14255. ( callback === null ) ? animation.stop() : animation.start();
  14256. };
  14257. // Rendering
  14258. this.render = function ( scene, camera ) {
  14259. let renderTarget, forceClear;
  14260. if ( arguments[ 2 ] !== undefined ) {
  14261. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14262. renderTarget = arguments[ 2 ];
  14263. }
  14264. if ( arguments[ 3 ] !== undefined ) {
  14265. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14266. forceClear = arguments[ 3 ];
  14267. }
  14268. if ( camera !== undefined && camera.isCamera !== true ) {
  14269. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14270. return;
  14271. }
  14272. if ( _isContextLost === true ) return;
  14273. // reset caching for this frame
  14274. bindingStates.resetDefaultState();
  14275. _currentMaterialId = - 1;
  14276. _currentCamera = null;
  14277. // update scene graph
  14278. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14279. // update camera matrices and frustum
  14280. if ( camera.parent === null ) camera.updateMatrixWorld();
  14281. if ( xr.enabled === true && xr.isPresenting === true ) {
  14282. camera = xr.getCamera( camera );
  14283. }
  14284. //
  14285. if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14286. currentRenderState = renderStates.get( scene, renderStateStack.length );
  14287. currentRenderState.init();
  14288. renderStateStack.push( currentRenderState );
  14289. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14290. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  14291. _localClippingEnabled = this.localClippingEnabled;
  14292. _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14293. currentRenderList = renderLists.get( scene, renderListStack.length );
  14294. currentRenderList.init();
  14295. renderListStack.push( currentRenderList );
  14296. projectObject( scene, camera, 0, _this.sortObjects );
  14297. currentRenderList.finish();
  14298. if ( _this.sortObjects === true ) {
  14299. currentRenderList.sort( _opaqueSort, _transparentSort );
  14300. }
  14301. //
  14302. if ( _clippingEnabled === true ) clipping.beginShadows();
  14303. const shadowsArray = currentRenderState.state.shadowsArray;
  14304. shadowMap.render( shadowsArray, scene, camera );
  14305. currentRenderState.setupLights();
  14306. currentRenderState.setupLightsView( camera );
  14307. if ( _clippingEnabled === true ) clipping.endShadows();
  14308. //
  14309. if ( this.info.autoReset === true ) this.info.reset();
  14310. if ( renderTarget !== undefined ) {
  14311. this.setRenderTarget( renderTarget );
  14312. }
  14313. //
  14314. background.render( currentRenderList, scene, camera, forceClear );
  14315. // render scene
  14316. const opaqueObjects = currentRenderList.opaque;
  14317. const transparentObjects = currentRenderList.transparent;
  14318. if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
  14319. if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
  14320. //
  14321. if ( _currentRenderTarget !== null ) {
  14322. // Generate mipmap if we're using any kind of mipmap filtering
  14323. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14324. // resolve multisample renderbuffers to a single-sample texture if necessary
  14325. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14326. }
  14327. //
  14328. if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
  14329. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14330. state.buffers.depth.setTest( true );
  14331. state.buffers.depth.setMask( true );
  14332. state.buffers.color.setMask( true );
  14333. state.setPolygonOffset( false );
  14334. // _gl.finish();
  14335. renderStateStack.pop();
  14336. if ( renderStateStack.length > 0 ) {
  14337. currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
  14338. } else {
  14339. currentRenderState = null;
  14340. }
  14341. renderListStack.pop();
  14342. if ( renderListStack.length > 0 ) {
  14343. currentRenderList = renderListStack[ renderListStack.length - 1 ];
  14344. } else {
  14345. currentRenderList = null;
  14346. }
  14347. };
  14348. function projectObject( object, camera, groupOrder, sortObjects ) {
  14349. if ( object.visible === false ) return;
  14350. const visible = object.layers.test( camera.layers );
  14351. if ( visible ) {
  14352. if ( object.isGroup ) {
  14353. groupOrder = object.renderOrder;
  14354. } else if ( object.isLOD ) {
  14355. if ( object.autoUpdate === true ) object.update( camera );
  14356. } else if ( object.isLight ) {
  14357. currentRenderState.pushLight( object );
  14358. if ( object.castShadow ) {
  14359. currentRenderState.pushShadow( object );
  14360. }
  14361. } else if ( object.isSprite ) {
  14362. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14363. if ( sortObjects ) {
  14364. _vector3.setFromMatrixPosition( object.matrixWorld )
  14365. .applyMatrix4( _projScreenMatrix );
  14366. }
  14367. const geometry = objects.update( object );
  14368. const material = object.material;
  14369. if ( material.visible ) {
  14370. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14371. }
  14372. }
  14373. } else if ( object.isImmediateRenderObject ) {
  14374. if ( sortObjects ) {
  14375. _vector3.setFromMatrixPosition( object.matrixWorld )
  14376. .applyMatrix4( _projScreenMatrix );
  14377. }
  14378. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14379. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14380. if ( object.isSkinnedMesh ) {
  14381. // update skeleton only once in a frame
  14382. if ( object.skeleton.frame !== info.render.frame ) {
  14383. object.skeleton.update();
  14384. object.skeleton.frame = info.render.frame;
  14385. }
  14386. }
  14387. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14388. if ( sortObjects ) {
  14389. _vector3.setFromMatrixPosition( object.matrixWorld )
  14390. .applyMatrix4( _projScreenMatrix );
  14391. }
  14392. const geometry = objects.update( object );
  14393. const material = object.material;
  14394. if ( Array.isArray( material ) ) {
  14395. const groups = geometry.groups;
  14396. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  14397. const group = groups[ i ];
  14398. const groupMaterial = material[ group.materialIndex ];
  14399. if ( groupMaterial && groupMaterial.visible ) {
  14400. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14401. }
  14402. }
  14403. } else if ( material.visible ) {
  14404. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14405. }
  14406. }
  14407. }
  14408. }
  14409. const children = object.children;
  14410. for ( let i = 0, l = children.length; i < l; i ++ ) {
  14411. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14412. }
  14413. }
  14414. function renderObjects( renderList, scene, camera ) {
  14415. const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14416. for ( let i = 0, l = renderList.length; i < l; i ++ ) {
  14417. const renderItem = renderList[ i ];
  14418. const object = renderItem.object;
  14419. const geometry = renderItem.geometry;
  14420. const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14421. const group = renderItem.group;
  14422. if ( camera.isArrayCamera ) {
  14423. const cameras = camera.cameras;
  14424. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  14425. const camera2 = cameras[ j ];
  14426. if ( object.layers.test( camera2.layers ) ) {
  14427. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14428. currentRenderState.setupLightsView( camera2 );
  14429. renderObject( object, scene, camera2, geometry, material, group );
  14430. }
  14431. }
  14432. } else {
  14433. renderObject( object, scene, camera, geometry, material, group );
  14434. }
  14435. }
  14436. }
  14437. function renderObject( object, scene, camera, geometry, material, group ) {
  14438. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14439. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14440. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14441. if ( object.isImmediateRenderObject ) {
  14442. const program = setProgram( camera, scene, material, object );
  14443. state.setMaterial( material );
  14444. bindingStates.reset();
  14445. renderObjectImmediate( object, program );
  14446. } else {
  14447. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  14448. }
  14449. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14450. }
  14451. function getProgram( material, scene, object ) {
  14452. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14453. const materialProperties = properties.get( material );
  14454. const lights = currentRenderState.state.lights;
  14455. const shadowsArray = currentRenderState.state.shadowsArray;
  14456. const lightsStateVersion = lights.state.version;
  14457. const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
  14458. const programCacheKey = programCache.getProgramCacheKey( parameters );
  14459. let programs = materialProperties.programs;
  14460. // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
  14461. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14462. materialProperties.fog = scene.fog;
  14463. materialProperties.envMap = cubemaps.get( material.envMap || materialProperties.environment );
  14464. if ( programs === undefined ) {
  14465. // new material
  14466. material.addEventListener( 'dispose', onMaterialDispose );
  14467. programs = new Map();
  14468. materialProperties.programs = programs;
  14469. }
  14470. let program = programs.get( programCacheKey );
  14471. if ( program !== undefined ) {
  14472. // early out if program and light state is identical
  14473. if ( materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion ) {
  14474. updateCommonMaterialProperties( material, parameters );
  14475. return program;
  14476. }
  14477. } else {
  14478. parameters.uniforms = programCache.getUniforms( material );
  14479. material.onBeforeCompile( parameters, _this );
  14480. program = programCache.acquireProgram( parameters, programCacheKey );
  14481. programs.set( programCacheKey, program );
  14482. materialProperties.uniforms = parameters.uniforms;
  14483. }
  14484. const uniforms = materialProperties.uniforms;
  14485. if ( ( ! material.isShaderMaterial && ! material.isRawShaderMaterial ) || material.clipping === true ) {
  14486. uniforms.clippingPlanes = clipping.uniform;
  14487. }
  14488. updateCommonMaterialProperties( material, parameters );
  14489. // store the light setup it was created for
  14490. materialProperties.needsLights = materialNeedsLights( material );
  14491. materialProperties.lightsStateVersion = lightsStateVersion;
  14492. if ( materialProperties.needsLights ) {
  14493. // wire up the material to this renderer's lighting state
  14494. uniforms.ambientLightColor.value = lights.state.ambient;
  14495. uniforms.lightProbe.value = lights.state.probe;
  14496. uniforms.directionalLights.value = lights.state.directional;
  14497. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14498. uniforms.spotLights.value = lights.state.spot;
  14499. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14500. uniforms.rectAreaLights.value = lights.state.rectArea;
  14501. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14502. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14503. uniforms.pointLights.value = lights.state.point;
  14504. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14505. uniforms.hemisphereLights.value = lights.state.hemi;
  14506. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14507. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14508. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14509. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14510. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14511. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14512. // TODO (abelnation): add area lights shadow info to uniforms
  14513. }
  14514. const progUniforms = program.getUniforms();
  14515. const uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14516. materialProperties.currentProgram = program;
  14517. materialProperties.uniformsList = uniformsList;
  14518. return program;
  14519. }
  14520. function updateCommonMaterialProperties( material, parameters ) {
  14521. const materialProperties = properties.get( material );
  14522. materialProperties.outputEncoding = parameters.outputEncoding;
  14523. materialProperties.instancing = parameters.instancing;
  14524. materialProperties.numClippingPlanes = parameters.numClippingPlanes;
  14525. materialProperties.numIntersection = parameters.numClipIntersection;
  14526. }
  14527. function setProgram( camera, scene, material, object ) {
  14528. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14529. textures.resetTextureUnits();
  14530. const fog = scene.fog;
  14531. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  14532. const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14533. const envMap = cubemaps.get( material.envMap || environment );
  14534. const materialProperties = properties.get( material );
  14535. const lights = currentRenderState.state.lights;
  14536. if ( _clippingEnabled === true ) {
  14537. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  14538. const useCache =
  14539. camera === _currentCamera &&
  14540. material.id === _currentMaterialId;
  14541. // we might want to call this function with some ClippingGroup
  14542. // object instead of the material, once it becomes feasible
  14543. // (#8465, #8379)
  14544. clipping.setState( material, camera, useCache );
  14545. }
  14546. }
  14547. //
  14548. let needsProgramChange = false;
  14549. if ( material.version === materialProperties.__version ) {
  14550. if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  14551. needsProgramChange = true;
  14552. } else if ( materialProperties.outputEncoding !== encoding ) {
  14553. needsProgramChange = true;
  14554. } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
  14555. needsProgramChange = true;
  14556. } else if ( ! object.isInstancedMesh && materialProperties.instancing === true ) {
  14557. needsProgramChange = true;
  14558. } else if ( materialProperties.envMap !== envMap ) {
  14559. needsProgramChange = true;
  14560. } else if ( material.fog && materialProperties.fog !== fog ) {
  14561. needsProgramChange = true;
  14562. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14563. ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
  14564. materialProperties.numIntersection !== clipping.numIntersection ) ) {
  14565. needsProgramChange = true;
  14566. }
  14567. } else {
  14568. needsProgramChange = true;
  14569. materialProperties.__version = material.version;
  14570. }
  14571. //
  14572. let program = materialProperties.currentProgram;
  14573. if ( needsProgramChange === true ) {
  14574. program = getProgram( material, scene, object );
  14575. }
  14576. let refreshProgram = false;
  14577. let refreshMaterial = false;
  14578. let refreshLights = false;
  14579. const p_uniforms = program.getUniforms(),
  14580. m_uniforms = materialProperties.uniforms;
  14581. if ( state.useProgram( program.program ) ) {
  14582. refreshProgram = true;
  14583. refreshMaterial = true;
  14584. refreshLights = true;
  14585. }
  14586. if ( material.id !== _currentMaterialId ) {
  14587. _currentMaterialId = material.id;
  14588. refreshMaterial = true;
  14589. }
  14590. if ( refreshProgram || _currentCamera !== camera ) {
  14591. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14592. if ( capabilities.logarithmicDepthBuffer ) {
  14593. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14594. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14595. }
  14596. if ( _currentCamera !== camera ) {
  14597. _currentCamera = camera;
  14598. // lighting uniforms depend on the camera so enforce an update
  14599. // now, in case this material supports lights - or later, when
  14600. // the next material that does gets activated:
  14601. refreshMaterial = true; // set to true on material change
  14602. refreshLights = true; // remains set until update done
  14603. }
  14604. // load material specific uniforms
  14605. // (shader material also gets them for the sake of genericity)
  14606. if ( material.isShaderMaterial ||
  14607. material.isMeshPhongMaterial ||
  14608. material.isMeshToonMaterial ||
  14609. material.isMeshStandardMaterial ||
  14610. material.envMap ) {
  14611. const uCamPos = p_uniforms.map.cameraPosition;
  14612. if ( uCamPos !== undefined ) {
  14613. uCamPos.setValue( _gl,
  14614. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14615. }
  14616. }
  14617. if ( material.isMeshPhongMaterial ||
  14618. material.isMeshToonMaterial ||
  14619. material.isMeshLambertMaterial ||
  14620. material.isMeshBasicMaterial ||
  14621. material.isMeshStandardMaterial ||
  14622. material.isShaderMaterial ) {
  14623. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  14624. }
  14625. if ( material.isMeshPhongMaterial ||
  14626. material.isMeshToonMaterial ||
  14627. material.isMeshLambertMaterial ||
  14628. material.isMeshBasicMaterial ||
  14629. material.isMeshStandardMaterial ||
  14630. material.isShaderMaterial ||
  14631. material.isShadowMaterial ||
  14632. material.skinning ) {
  14633. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14634. }
  14635. }
  14636. // skinning uniforms must be set even if material didn't change
  14637. // auto-setting of texture unit for bone texture must go before other textures
  14638. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14639. if ( material.skinning ) {
  14640. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14641. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14642. const skeleton = object.skeleton;
  14643. if ( skeleton ) {
  14644. const bones = skeleton.bones;
  14645. if ( capabilities.floatVertexTextures ) {
  14646. if ( skeleton.boneTexture === null ) {
  14647. // layout (1 matrix = 4 pixels)
  14648. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14649. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14650. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14651. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14652. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14653. let size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14654. size = MathUtils.ceilPowerOfTwo( size );
  14655. size = Math.max( size, 4 );
  14656. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14657. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14658. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14659. skeleton.boneMatrices = boneMatrices;
  14660. skeleton.boneTexture = boneTexture;
  14661. skeleton.boneTextureSize = size;
  14662. }
  14663. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14664. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14665. } else {
  14666. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14667. }
  14668. }
  14669. }
  14670. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  14671. materialProperties.receiveShadow = object.receiveShadow;
  14672. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  14673. }
  14674. if ( refreshMaterial ) {
  14675. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14676. if ( materialProperties.needsLights ) {
  14677. // the current material requires lighting info
  14678. // note: all lighting uniforms are always set correctly
  14679. // they simply reference the renderer's state for their
  14680. // values
  14681. //
  14682. // use the current material's .needsUpdate flags to set
  14683. // the GL state when required
  14684. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14685. }
  14686. // refresh uniforms common to several materials
  14687. if ( fog && material.fog ) {
  14688. materials.refreshFogUniforms( m_uniforms, fog );
  14689. }
  14690. materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height );
  14691. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14692. }
  14693. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14694. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14695. material.uniformsNeedUpdate = false;
  14696. }
  14697. if ( material.isSpriteMaterial ) {
  14698. p_uniforms.setValue( _gl, 'center', object.center );
  14699. }
  14700. // common matrices
  14701. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14702. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14703. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14704. return program;
  14705. }
  14706. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14707. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14708. uniforms.ambientLightColor.needsUpdate = value;
  14709. uniforms.lightProbe.needsUpdate = value;
  14710. uniforms.directionalLights.needsUpdate = value;
  14711. uniforms.directionalLightShadows.needsUpdate = value;
  14712. uniforms.pointLights.needsUpdate = value;
  14713. uniforms.pointLightShadows.needsUpdate = value;
  14714. uniforms.spotLights.needsUpdate = value;
  14715. uniforms.spotLightShadows.needsUpdate = value;
  14716. uniforms.rectAreaLights.needsUpdate = value;
  14717. uniforms.hemisphereLights.needsUpdate = value;
  14718. }
  14719. function materialNeedsLights( material ) {
  14720. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  14721. material.isMeshStandardMaterial || material.isShadowMaterial ||
  14722. ( material.isShaderMaterial && material.lights === true );
  14723. }
  14724. //
  14725. this.setFramebuffer = function ( value ) {
  14726. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  14727. _framebuffer = value;
  14728. };
  14729. this.getActiveCubeFace = function () {
  14730. return _currentActiveCubeFace;
  14731. };
  14732. this.getActiveMipmapLevel = function () {
  14733. return _currentActiveMipmapLevel;
  14734. };
  14735. this.getRenderTarget = function () {
  14736. return _currentRenderTarget;
  14737. };
  14738. this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  14739. _currentRenderTarget = renderTarget;
  14740. _currentActiveCubeFace = activeCubeFace;
  14741. _currentActiveMipmapLevel = activeMipmapLevel;
  14742. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14743. textures.setupRenderTarget( renderTarget );
  14744. }
  14745. let framebuffer = _framebuffer;
  14746. let isCube = false;
  14747. let isRenderTarget3D = false;
  14748. if ( renderTarget ) {
  14749. const texture = renderTarget.texture;
  14750. if ( texture.isDataTexture3D || texture.isDataTexture2DArray ) {
  14751. isRenderTarget3D = true;
  14752. }
  14753. const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14754. if ( renderTarget.isWebGLCubeRenderTarget ) {
  14755. framebuffer = __webglFramebuffer[ activeCubeFace ];
  14756. isCube = true;
  14757. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14758. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14759. } else {
  14760. framebuffer = __webglFramebuffer;
  14761. }
  14762. _currentViewport.copy( renderTarget.viewport );
  14763. _currentScissor.copy( renderTarget.scissor );
  14764. _currentScissorTest = renderTarget.scissorTest;
  14765. } else {
  14766. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  14767. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  14768. _currentScissorTest = _scissorTest;
  14769. }
  14770. if ( _currentFramebuffer !== framebuffer ) {
  14771. _gl.bindFramebuffer( 36160, framebuffer );
  14772. _currentFramebuffer = framebuffer;
  14773. }
  14774. state.viewport( _currentViewport );
  14775. state.scissor( _currentScissor );
  14776. state.setScissorTest( _currentScissorTest );
  14777. if ( isCube ) {
  14778. const textureProperties = properties.get( renderTarget.texture );
  14779. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
  14780. } else if ( isRenderTarget3D ) {
  14781. const textureProperties = properties.get( renderTarget.texture );
  14782. const layer = activeCubeFace || 0;
  14783. _gl.framebufferTextureLayer( 36160, 36064, textureProperties.__webglTexture, activeMipmapLevel || 0, layer );
  14784. }
  14785. };
  14786. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  14787. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14788. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14789. return;
  14790. }
  14791. let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14792. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  14793. framebuffer = framebuffer[ activeCubeFaceIndex ];
  14794. }
  14795. if ( framebuffer ) {
  14796. let restore = false;
  14797. if ( framebuffer !== _currentFramebuffer ) {
  14798. _gl.bindFramebuffer( 36160, framebuffer );
  14799. restore = true;
  14800. }
  14801. try {
  14802. const texture = renderTarget.texture;
  14803. const textureFormat = texture.format;
  14804. const textureType = texture.type;
  14805. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14806. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14807. return;
  14808. }
  14809. const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ) );
  14810. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // Edge and Chrome Mac < 52 (#9513)
  14811. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.has( 'OES_texture_float' ) || extensions.has( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14812. ! halfFloatSupportedByExt ) {
  14813. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14814. return;
  14815. }
  14816. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14817. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14818. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14819. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14820. }
  14821. } else {
  14822. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14823. }
  14824. } finally {
  14825. if ( restore ) {
  14826. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14827. }
  14828. }
  14829. }
  14830. };
  14831. this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
  14832. const levelScale = Math.pow( 2, - level );
  14833. const width = Math.floor( texture.image.width * levelScale );
  14834. const height = Math.floor( texture.image.height * levelScale );
  14835. const glFormat = utils.convert( texture.format );
  14836. textures.setTexture2D( texture, 0 );
  14837. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  14838. state.unbindTexture();
  14839. };
  14840. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
  14841. const width = srcTexture.image.width;
  14842. const height = srcTexture.image.height;
  14843. const glFormat = utils.convert( dstTexture.format );
  14844. const glType = utils.convert( dstTexture.type );
  14845. textures.setTexture2D( dstTexture, 0 );
  14846. // As another texture upload may have changed pixelStorei
  14847. // parameters, make sure they are correct for the dstTexture
  14848. _gl.pixelStorei( 37440, dstTexture.flipY );
  14849. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  14850. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  14851. if ( srcTexture.isDataTexture ) {
  14852. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14853. } else {
  14854. if ( srcTexture.isCompressedTexture ) {
  14855. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  14856. } else {
  14857. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  14858. }
  14859. }
  14860. // Generate mipmaps only when copying level 0
  14861. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  14862. state.unbindTexture();
  14863. };
  14864. this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
  14865. if ( _this.isWebGL1Renderer ) {
  14866. console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.' );
  14867. return;
  14868. }
  14869. const { width, height, data } = srcTexture.image;
  14870. const glFormat = utils.convert( dstTexture.format );
  14871. const glType = utils.convert( dstTexture.type );
  14872. let glTarget;
  14873. if ( dstTexture.isDataTexture3D ) {
  14874. textures.setTexture3D( dstTexture, 0 );
  14875. glTarget = 32879;
  14876. } else if ( dstTexture.isDataTexture2DArray ) {
  14877. textures.setTexture2DArray( dstTexture, 0 );
  14878. glTarget = 35866;
  14879. } else {
  14880. console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
  14881. return;
  14882. }
  14883. _gl.pixelStorei( 37440, dstTexture.flipY );
  14884. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  14885. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  14886. const unpackRowLen = _gl.getParameter( 3314 );
  14887. const unpackImageHeight = _gl.getParameter( 32878 );
  14888. const unpackSkipPixels = _gl.getParameter( 3316 );
  14889. const unpackSkipRows = _gl.getParameter( 3315 );
  14890. const unpackSkipImages = _gl.getParameter( 32877 );
  14891. _gl.pixelStorei( 3314, width );
  14892. _gl.pixelStorei( 32878, height );
  14893. _gl.pixelStorei( 3316, sourceBox.min.x );
  14894. _gl.pixelStorei( 3315, sourceBox.min.y );
  14895. _gl.pixelStorei( 32877, sourceBox.min.z );
  14896. _gl.texSubImage3D(
  14897. glTarget,
  14898. level,
  14899. position.x,
  14900. position.y,
  14901. position.z,
  14902. sourceBox.max.x - sourceBox.min.x + 1,
  14903. sourceBox.max.y - sourceBox.min.y + 1,
  14904. sourceBox.max.z - sourceBox.min.z + 1,
  14905. glFormat,
  14906. glType,
  14907. data
  14908. );
  14909. _gl.pixelStorei( 3314, unpackRowLen );
  14910. _gl.pixelStorei( 32878, unpackImageHeight );
  14911. _gl.pixelStorei( 3316, unpackSkipPixels );
  14912. _gl.pixelStorei( 3315, unpackSkipRows );
  14913. _gl.pixelStorei( 32877, unpackSkipImages );
  14914. // Generate mipmaps only when copying level 0
  14915. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
  14916. state.unbindTexture();
  14917. };
  14918. this.initTexture = function ( texture ) {
  14919. textures.setTexture2D( texture, 0 );
  14920. state.unbindTexture();
  14921. };
  14922. this.resetState = function () {
  14923. state.reset();
  14924. bindingStates.reset();
  14925. };
  14926. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  14927. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  14928. }
  14929. }
  14930. class WebGL1Renderer extends WebGLRenderer {}
  14931. WebGL1Renderer.prototype.isWebGL1Renderer = true;
  14932. class FogExp2 {
  14933. constructor( color, density ) {
  14934. this.name = '';
  14935. this.color = new Color( color );
  14936. this.density = ( density !== undefined ) ? density : 0.00025;
  14937. }
  14938. clone() {
  14939. return new FogExp2( this.color, this.density );
  14940. }
  14941. toJSON( /* meta */ ) {
  14942. return {
  14943. type: 'FogExp2',
  14944. color: this.color.getHex(),
  14945. density: this.density
  14946. };
  14947. }
  14948. }
  14949. FogExp2.prototype.isFogExp2 = true;
  14950. class Fog {
  14951. constructor( color, near, far ) {
  14952. this.name = '';
  14953. this.color = new Color( color );
  14954. this.near = ( near !== undefined ) ? near : 1;
  14955. this.far = ( far !== undefined ) ? far : 1000;
  14956. }
  14957. clone() {
  14958. return new Fog( this.color, this.near, this.far );
  14959. }
  14960. toJSON( /* meta */ ) {
  14961. return {
  14962. type: 'Fog',
  14963. color: this.color.getHex(),
  14964. near: this.near,
  14965. far: this.far
  14966. };
  14967. }
  14968. }
  14969. Fog.prototype.isFog = true;
  14970. class Scene extends Object3D {
  14971. constructor() {
  14972. super();
  14973. this.type = 'Scene';
  14974. this.background = null;
  14975. this.environment = null;
  14976. this.fog = null;
  14977. this.overrideMaterial = null;
  14978. this.autoUpdate = true; // checked by the renderer
  14979. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  14980. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  14981. }
  14982. }
  14983. copy( source, recursive ) {
  14984. super.copy( source, recursive );
  14985. if ( source.background !== null ) this.background = source.background.clone();
  14986. if ( source.environment !== null ) this.environment = source.environment.clone();
  14987. if ( source.fog !== null ) this.fog = source.fog.clone();
  14988. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14989. this.autoUpdate = source.autoUpdate;
  14990. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14991. return this;
  14992. }
  14993. toJSON( meta ) {
  14994. const data = super.toJSON( meta );
  14995. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14996. if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
  14997. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14998. return data;
  14999. }
  15000. }
  15001. Scene.prototype.isScene = true;
  15002. function InterleavedBuffer( array, stride ) {
  15003. this.array = array;
  15004. this.stride = stride;
  15005. this.count = array !== undefined ? array.length / stride : 0;
  15006. this.usage = StaticDrawUsage;
  15007. this.updateRange = { offset: 0, count: - 1 };
  15008. this.version = 0;
  15009. this.uuid = MathUtils.generateUUID();
  15010. }
  15011. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15012. set: function ( value ) {
  15013. if ( value === true ) this.version ++;
  15014. }
  15015. } );
  15016. Object.assign( InterleavedBuffer.prototype, {
  15017. isInterleavedBuffer: true,
  15018. onUploadCallback: function () {},
  15019. setUsage: function ( value ) {
  15020. this.usage = value;
  15021. return this;
  15022. },
  15023. copy: function ( source ) {
  15024. this.array = new source.array.constructor( source.array );
  15025. this.count = source.count;
  15026. this.stride = source.stride;
  15027. this.usage = source.usage;
  15028. return this;
  15029. },
  15030. copyAt: function ( index1, attribute, index2 ) {
  15031. index1 *= this.stride;
  15032. index2 *= attribute.stride;
  15033. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  15034. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15035. }
  15036. return this;
  15037. },
  15038. set: function ( value, offset = 0 ) {
  15039. this.array.set( value, offset );
  15040. return this;
  15041. },
  15042. clone: function ( data ) {
  15043. if ( data.arrayBuffers === undefined ) {
  15044. data.arrayBuffers = {};
  15045. }
  15046. if ( this.array.buffer._uuid === undefined ) {
  15047. this.array.buffer._uuid = MathUtils.generateUUID();
  15048. }
  15049. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15050. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  15051. }
  15052. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  15053. const ib = new InterleavedBuffer( array, this.stride );
  15054. ib.setUsage( this.usage );
  15055. return ib;
  15056. },
  15057. onUpload: function ( callback ) {
  15058. this.onUploadCallback = callback;
  15059. return this;
  15060. },
  15061. toJSON: function ( data ) {
  15062. if ( data.arrayBuffers === undefined ) {
  15063. data.arrayBuffers = {};
  15064. }
  15065. // generate UUID for array buffer if necessary
  15066. if ( this.array.buffer._uuid === undefined ) {
  15067. this.array.buffer._uuid = MathUtils.generateUUID();
  15068. }
  15069. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15070. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  15071. }
  15072. //
  15073. return {
  15074. uuid: this.uuid,
  15075. buffer: this.array.buffer._uuid,
  15076. type: this.array.constructor.name,
  15077. stride: this.stride
  15078. };
  15079. }
  15080. } );
  15081. const _vector$6 = new Vector3();
  15082. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15083. this.name = '';
  15084. this.data = interleavedBuffer;
  15085. this.itemSize = itemSize;
  15086. this.offset = offset;
  15087. this.normalized = normalized === true;
  15088. }
  15089. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15090. count: {
  15091. get: function () {
  15092. return this.data.count;
  15093. }
  15094. },
  15095. array: {
  15096. get: function () {
  15097. return this.data.array;
  15098. }
  15099. },
  15100. needsUpdate: {
  15101. set: function ( value ) {
  15102. this.data.needsUpdate = value;
  15103. }
  15104. }
  15105. } );
  15106. Object.assign( InterleavedBufferAttribute.prototype, {
  15107. isInterleavedBufferAttribute: true,
  15108. applyMatrix4: function ( m ) {
  15109. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  15110. _vector$6.x = this.getX( i );
  15111. _vector$6.y = this.getY( i );
  15112. _vector$6.z = this.getZ( i );
  15113. _vector$6.applyMatrix4( m );
  15114. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  15115. }
  15116. return this;
  15117. },
  15118. setX: function ( index, x ) {
  15119. this.data.array[ index * this.data.stride + this.offset ] = x;
  15120. return this;
  15121. },
  15122. setY: function ( index, y ) {
  15123. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15124. return this;
  15125. },
  15126. setZ: function ( index, z ) {
  15127. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15128. return this;
  15129. },
  15130. setW: function ( index, w ) {
  15131. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15132. return this;
  15133. },
  15134. getX: function ( index ) {
  15135. return this.data.array[ index * this.data.stride + this.offset ];
  15136. },
  15137. getY: function ( index ) {
  15138. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15139. },
  15140. getZ: function ( index ) {
  15141. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15142. },
  15143. getW: function ( index ) {
  15144. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15145. },
  15146. setXY: function ( index, x, y ) {
  15147. index = index * this.data.stride + this.offset;
  15148. this.data.array[ index + 0 ] = x;
  15149. this.data.array[ index + 1 ] = y;
  15150. return this;
  15151. },
  15152. setXYZ: function ( index, x, y, z ) {
  15153. index = index * this.data.stride + this.offset;
  15154. this.data.array[ index + 0 ] = x;
  15155. this.data.array[ index + 1 ] = y;
  15156. this.data.array[ index + 2 ] = z;
  15157. return this;
  15158. },
  15159. setXYZW: function ( index, x, y, z, w ) {
  15160. index = index * this.data.stride + this.offset;
  15161. this.data.array[ index + 0 ] = x;
  15162. this.data.array[ index + 1 ] = y;
  15163. this.data.array[ index + 2 ] = z;
  15164. this.data.array[ index + 3 ] = w;
  15165. return this;
  15166. },
  15167. clone: function ( data ) {
  15168. if ( data === undefined ) {
  15169. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  15170. const array = [];
  15171. for ( let i = 0; i < this.count; i ++ ) {
  15172. const index = i * this.data.stride + this.offset;
  15173. for ( let j = 0; j < this.itemSize; j ++ ) {
  15174. array.push( this.data.array[ index + j ] );
  15175. }
  15176. }
  15177. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  15178. } else {
  15179. if ( data.interleavedBuffers === undefined ) {
  15180. data.interleavedBuffers = {};
  15181. }
  15182. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15183. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  15184. }
  15185. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  15186. }
  15187. },
  15188. toJSON: function ( data ) {
  15189. if ( data === undefined ) {
  15190. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  15191. const array = [];
  15192. for ( let i = 0; i < this.count; i ++ ) {
  15193. const index = i * this.data.stride + this.offset;
  15194. for ( let j = 0; j < this.itemSize; j ++ ) {
  15195. array.push( this.data.array[ index + j ] );
  15196. }
  15197. }
  15198. // deinterleave data and save it as an ordinary buffer attribute for now
  15199. return {
  15200. itemSize: this.itemSize,
  15201. type: this.array.constructor.name,
  15202. array: array,
  15203. normalized: this.normalized
  15204. };
  15205. } else {
  15206. // save as true interlaved attribtue
  15207. if ( data.interleavedBuffers === undefined ) {
  15208. data.interleavedBuffers = {};
  15209. }
  15210. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15211. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  15212. }
  15213. return {
  15214. isInterleavedBufferAttribute: true,
  15215. itemSize: this.itemSize,
  15216. data: this.data.uuid,
  15217. offset: this.offset,
  15218. normalized: this.normalized
  15219. };
  15220. }
  15221. }
  15222. } );
  15223. /**
  15224. * parameters = {
  15225. * color: <hex>,
  15226. * map: new THREE.Texture( <Image> ),
  15227. * alphaMap: new THREE.Texture( <Image> ),
  15228. * rotation: <float>,
  15229. * sizeAttenuation: <bool>
  15230. * }
  15231. */
  15232. class SpriteMaterial extends Material {
  15233. constructor( parameters ) {
  15234. super();
  15235. this.type = 'SpriteMaterial';
  15236. this.color = new Color( 0xffffff );
  15237. this.map = null;
  15238. this.alphaMap = null;
  15239. this.rotation = 0;
  15240. this.sizeAttenuation = true;
  15241. this.transparent = true;
  15242. this.setValues( parameters );
  15243. }
  15244. copy( source ) {
  15245. super.copy( source );
  15246. this.color.copy( source.color );
  15247. this.map = source.map;
  15248. this.alphaMap = source.alphaMap;
  15249. this.rotation = source.rotation;
  15250. this.sizeAttenuation = source.sizeAttenuation;
  15251. return this;
  15252. }
  15253. }
  15254. SpriteMaterial.prototype.isSpriteMaterial = true;
  15255. let _geometry;
  15256. const _intersectPoint = /*@__PURE__*/ new Vector3();
  15257. const _worldScale = /*@__PURE__*/ new Vector3();
  15258. const _mvPosition = /*@__PURE__*/ new Vector3();
  15259. const _alignedPosition = /*@__PURE__*/ new Vector2();
  15260. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  15261. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  15262. const _vA$1 = /*@__PURE__*/ new Vector3();
  15263. const _vB$1 = /*@__PURE__*/ new Vector3();
  15264. const _vC$1 = /*@__PURE__*/ new Vector3();
  15265. const _uvA$1 = /*@__PURE__*/ new Vector2();
  15266. const _uvB$1 = /*@__PURE__*/ new Vector2();
  15267. const _uvC$1 = /*@__PURE__*/ new Vector2();
  15268. class Sprite extends Object3D {
  15269. constructor( material ) {
  15270. super();
  15271. this.type = 'Sprite';
  15272. if ( _geometry === undefined ) {
  15273. _geometry = new BufferGeometry();
  15274. const float32Array = new Float32Array( [
  15275. - 0.5, - 0.5, 0, 0, 0,
  15276. 0.5, - 0.5, 0, 1, 0,
  15277. 0.5, 0.5, 0, 1, 1,
  15278. - 0.5, 0.5, 0, 0, 1
  15279. ] );
  15280. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15281. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15282. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15283. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15284. }
  15285. this.geometry = _geometry;
  15286. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15287. this.center = new Vector2( 0.5, 0.5 );
  15288. }
  15289. raycast( raycaster, intersects ) {
  15290. if ( raycaster.camera === null ) {
  15291. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  15292. }
  15293. _worldScale.setFromMatrixScale( this.matrixWorld );
  15294. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  15295. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  15296. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15297. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15298. _worldScale.multiplyScalar( - _mvPosition.z );
  15299. }
  15300. const rotation = this.material.rotation;
  15301. let sin, cos;
  15302. if ( rotation !== 0 ) {
  15303. cos = Math.cos( rotation );
  15304. sin = Math.sin( rotation );
  15305. }
  15306. const center = this.center;
  15307. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15308. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15309. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15310. _uvA$1.set( 0, 0 );
  15311. _uvB$1.set( 1, 0 );
  15312. _uvC$1.set( 1, 1 );
  15313. // check first triangle
  15314. let intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  15315. if ( intersect === null ) {
  15316. // check second triangle
  15317. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15318. _uvB$1.set( 0, 1 );
  15319. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  15320. if ( intersect === null ) {
  15321. return;
  15322. }
  15323. }
  15324. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  15325. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15326. intersects.push( {
  15327. distance: distance,
  15328. point: _intersectPoint.clone(),
  15329. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  15330. face: null,
  15331. object: this
  15332. } );
  15333. }
  15334. copy( source ) {
  15335. super.copy( source );
  15336. if ( source.center !== undefined ) this.center.copy( source.center );
  15337. this.material = source.material;
  15338. return this;
  15339. }
  15340. }
  15341. Sprite.prototype.isSprite = true;
  15342. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15343. // compute position in camera space
  15344. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15345. // to check if rotation is not zero
  15346. if ( sin !== undefined ) {
  15347. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  15348. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  15349. } else {
  15350. _rotatedPosition.copy( _alignedPosition );
  15351. }
  15352. vertexPosition.copy( mvPosition );
  15353. vertexPosition.x += _rotatedPosition.x;
  15354. vertexPosition.y += _rotatedPosition.y;
  15355. // transform to world space
  15356. vertexPosition.applyMatrix4( _viewWorldMatrix );
  15357. }
  15358. const _v1$4 = /*@__PURE__*/ new Vector3();
  15359. const _v2$2 = /*@__PURE__*/ new Vector3();
  15360. class LOD extends Object3D {
  15361. constructor() {
  15362. super();
  15363. this._currentLevel = 0;
  15364. this.type = 'LOD';
  15365. Object.defineProperties( this, {
  15366. levels: {
  15367. enumerable: true,
  15368. value: []
  15369. },
  15370. isLOD: {
  15371. value: true,
  15372. }
  15373. } );
  15374. this.autoUpdate = true;
  15375. }
  15376. copy( source ) {
  15377. super.copy( source, false );
  15378. const levels = source.levels;
  15379. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15380. const level = levels[ i ];
  15381. this.addLevel( level.object.clone(), level.distance );
  15382. }
  15383. this.autoUpdate = source.autoUpdate;
  15384. return this;
  15385. }
  15386. addLevel( object, distance = 0 ) {
  15387. distance = Math.abs( distance );
  15388. const levels = this.levels;
  15389. let l;
  15390. for ( l = 0; l < levels.length; l ++ ) {
  15391. if ( distance < levels[ l ].distance ) {
  15392. break;
  15393. }
  15394. }
  15395. levels.splice( l, 0, { distance: distance, object: object } );
  15396. this.add( object );
  15397. return this;
  15398. }
  15399. getCurrentLevel() {
  15400. return this._currentLevel;
  15401. }
  15402. getObjectForDistance( distance ) {
  15403. const levels = this.levels;
  15404. if ( levels.length > 0 ) {
  15405. let i, l;
  15406. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15407. if ( distance < levels[ i ].distance ) {
  15408. break;
  15409. }
  15410. }
  15411. return levels[ i - 1 ].object;
  15412. }
  15413. return null;
  15414. }
  15415. raycast( raycaster, intersects ) {
  15416. const levels = this.levels;
  15417. if ( levels.length > 0 ) {
  15418. _v1$4.setFromMatrixPosition( this.matrixWorld );
  15419. const distance = raycaster.ray.origin.distanceTo( _v1$4 );
  15420. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15421. }
  15422. }
  15423. update( camera ) {
  15424. const levels = this.levels;
  15425. if ( levels.length > 1 ) {
  15426. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  15427. _v2$2.setFromMatrixPosition( this.matrixWorld );
  15428. const distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  15429. levels[ 0 ].object.visible = true;
  15430. let i, l;
  15431. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15432. if ( distance >= levels[ i ].distance ) {
  15433. levels[ i - 1 ].object.visible = false;
  15434. levels[ i ].object.visible = true;
  15435. } else {
  15436. break;
  15437. }
  15438. }
  15439. this._currentLevel = i - 1;
  15440. for ( ; i < l; i ++ ) {
  15441. levels[ i ].object.visible = false;
  15442. }
  15443. }
  15444. }
  15445. toJSON( meta ) {
  15446. const data = super.toJSON( meta );
  15447. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  15448. data.object.levels = [];
  15449. const levels = this.levels;
  15450. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15451. const level = levels[ i ];
  15452. data.object.levels.push( {
  15453. object: level.object.uuid,
  15454. distance: level.distance
  15455. } );
  15456. }
  15457. return data;
  15458. }
  15459. }
  15460. const _basePosition = new Vector3();
  15461. const _skinIndex = new Vector4();
  15462. const _skinWeight = new Vector4();
  15463. const _vector$7 = new Vector3();
  15464. const _matrix$1 = new Matrix4();
  15465. function SkinnedMesh( geometry, material ) {
  15466. Mesh.call( this, geometry, material );
  15467. this.type = 'SkinnedMesh';
  15468. this.bindMode = 'attached';
  15469. this.bindMatrix = new Matrix4();
  15470. this.bindMatrixInverse = new Matrix4();
  15471. }
  15472. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15473. constructor: SkinnedMesh,
  15474. isSkinnedMesh: true,
  15475. copy: function ( source ) {
  15476. Mesh.prototype.copy.call( this, source );
  15477. this.bindMode = source.bindMode;
  15478. this.bindMatrix.copy( source.bindMatrix );
  15479. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  15480. this.skeleton = source.skeleton;
  15481. return this;
  15482. },
  15483. bind: function ( skeleton, bindMatrix ) {
  15484. this.skeleton = skeleton;
  15485. if ( bindMatrix === undefined ) {
  15486. this.updateMatrixWorld( true );
  15487. this.skeleton.calculateInverses();
  15488. bindMatrix = this.matrixWorld;
  15489. }
  15490. this.bindMatrix.copy( bindMatrix );
  15491. this.bindMatrixInverse.copy( bindMatrix ).invert();
  15492. },
  15493. pose: function () {
  15494. this.skeleton.pose();
  15495. },
  15496. normalizeSkinWeights: function () {
  15497. const vector = new Vector4();
  15498. const skinWeight = this.geometry.attributes.skinWeight;
  15499. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  15500. vector.x = skinWeight.getX( i );
  15501. vector.y = skinWeight.getY( i );
  15502. vector.z = skinWeight.getZ( i );
  15503. vector.w = skinWeight.getW( i );
  15504. const scale = 1.0 / vector.manhattanLength();
  15505. if ( scale !== Infinity ) {
  15506. vector.multiplyScalar( scale );
  15507. } else {
  15508. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15509. }
  15510. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15511. }
  15512. },
  15513. updateMatrixWorld: function ( force ) {
  15514. Mesh.prototype.updateMatrixWorld.call( this, force );
  15515. if ( this.bindMode === 'attached' ) {
  15516. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  15517. } else if ( this.bindMode === 'detached' ) {
  15518. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  15519. } else {
  15520. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15521. }
  15522. },
  15523. boneTransform: function ( index, target ) {
  15524. const skeleton = this.skeleton;
  15525. const geometry = this.geometry;
  15526. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  15527. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  15528. _basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  15529. target.set( 0, 0, 0 );
  15530. for ( let i = 0; i < 4; i ++ ) {
  15531. const weight = _skinWeight.getComponent( i );
  15532. if ( weight !== 0 ) {
  15533. const boneIndex = _skinIndex.getComponent( i );
  15534. _matrix$1.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  15535. target.addScaledVector( _vector$7.copy( _basePosition ).applyMatrix4( _matrix$1 ), weight );
  15536. }
  15537. }
  15538. return target.applyMatrix4( this.bindMatrixInverse );
  15539. }
  15540. } );
  15541. function Bone() {
  15542. Object3D.call( this );
  15543. this.type = 'Bone';
  15544. }
  15545. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15546. constructor: Bone,
  15547. isBone: true
  15548. } );
  15549. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  15550. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  15551. class Skeleton {
  15552. constructor( bones = [], boneInverses = [] ) {
  15553. this.uuid = MathUtils.generateUUID();
  15554. this.bones = bones.slice( 0 );
  15555. this.boneInverses = boneInverses;
  15556. this.boneMatrices = null;
  15557. this.boneTexture = null;
  15558. this.boneTextureSize = 0;
  15559. this.frame = - 1;
  15560. this.init();
  15561. }
  15562. init() {
  15563. const bones = this.bones;
  15564. const boneInverses = this.boneInverses;
  15565. this.boneMatrices = new Float32Array( bones.length * 16 );
  15566. // calculate inverse bone matrices if necessary
  15567. if ( boneInverses.length === 0 ) {
  15568. this.calculateInverses();
  15569. } else {
  15570. // handle special case
  15571. if ( bones.length !== boneInverses.length ) {
  15572. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  15573. this.boneInverses = [];
  15574. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15575. this.boneInverses.push( new Matrix4() );
  15576. }
  15577. }
  15578. }
  15579. }
  15580. calculateInverses() {
  15581. this.boneInverses.length = 0;
  15582. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15583. const inverse = new Matrix4();
  15584. if ( this.bones[ i ] ) {
  15585. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  15586. }
  15587. this.boneInverses.push( inverse );
  15588. }
  15589. }
  15590. pose() {
  15591. // recover the bind-time world matrices
  15592. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15593. const bone = this.bones[ i ];
  15594. if ( bone ) {
  15595. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  15596. }
  15597. }
  15598. // compute the local matrices, positions, rotations and scales
  15599. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15600. const bone = this.bones[ i ];
  15601. if ( bone ) {
  15602. if ( bone.parent && bone.parent.isBone ) {
  15603. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  15604. bone.matrix.multiply( bone.matrixWorld );
  15605. } else {
  15606. bone.matrix.copy( bone.matrixWorld );
  15607. }
  15608. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15609. }
  15610. }
  15611. }
  15612. update() {
  15613. const bones = this.bones;
  15614. const boneInverses = this.boneInverses;
  15615. const boneMatrices = this.boneMatrices;
  15616. const boneTexture = this.boneTexture;
  15617. // flatten bone matrices to array
  15618. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  15619. // compute the offset between the current and the original transform
  15620. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  15621. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15622. _offsetMatrix.toArray( boneMatrices, i * 16 );
  15623. }
  15624. if ( boneTexture !== null ) {
  15625. boneTexture.needsUpdate = true;
  15626. }
  15627. }
  15628. clone() {
  15629. return new Skeleton( this.bones, this.boneInverses );
  15630. }
  15631. getBoneByName( name ) {
  15632. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15633. const bone = this.bones[ i ];
  15634. if ( bone.name === name ) {
  15635. return bone;
  15636. }
  15637. }
  15638. return undefined;
  15639. }
  15640. dispose( ) {
  15641. if ( this.boneTexture !== null ) {
  15642. this.boneTexture.dispose();
  15643. this.boneTexture = null;
  15644. }
  15645. }
  15646. fromJSON( json, bones ) {
  15647. this.uuid = json.uuid;
  15648. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  15649. const uuid = json.bones[ i ];
  15650. let bone = bones[ uuid ];
  15651. if ( bone === undefined ) {
  15652. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  15653. bone = new Bone();
  15654. }
  15655. this.bones.push( bone );
  15656. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  15657. }
  15658. this.init();
  15659. return this;
  15660. }
  15661. toJSON() {
  15662. const data = {
  15663. metadata: {
  15664. version: 4.5,
  15665. type: 'Skeleton',
  15666. generator: 'Skeleton.toJSON'
  15667. },
  15668. bones: [],
  15669. boneInverses: []
  15670. };
  15671. data.uuid = this.uuid;
  15672. const bones = this.bones;
  15673. const boneInverses = this.boneInverses;
  15674. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  15675. const bone = bones[ i ];
  15676. data.bones.push( bone.uuid );
  15677. const boneInverse = boneInverses[ i ];
  15678. data.boneInverses.push( boneInverse.toArray() );
  15679. }
  15680. return data;
  15681. }
  15682. }
  15683. const _instanceLocalMatrix = new Matrix4();
  15684. const _instanceWorldMatrix = new Matrix4();
  15685. const _instanceIntersects = [];
  15686. const _mesh = new Mesh();
  15687. function InstancedMesh( geometry, material, count ) {
  15688. Mesh.call( this, geometry, material );
  15689. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  15690. this.instanceColor = null;
  15691. this.count = count;
  15692. this.frustumCulled = false;
  15693. }
  15694. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15695. constructor: InstancedMesh,
  15696. isInstancedMesh: true,
  15697. copy: function ( source ) {
  15698. Mesh.prototype.copy.call( this, source );
  15699. this.instanceMatrix.copy( source.instanceMatrix );
  15700. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  15701. this.count = source.count;
  15702. return this;
  15703. },
  15704. getColorAt: function ( index, color ) {
  15705. color.fromArray( this.instanceColor.array, index * 3 );
  15706. },
  15707. getMatrixAt: function ( index, matrix ) {
  15708. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  15709. },
  15710. raycast: function ( raycaster, intersects ) {
  15711. const matrixWorld = this.matrixWorld;
  15712. const raycastTimes = this.count;
  15713. _mesh.geometry = this.geometry;
  15714. _mesh.material = this.material;
  15715. if ( _mesh.material === undefined ) return;
  15716. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  15717. // calculate the world matrix for each instance
  15718. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  15719. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  15720. // the mesh represents this single instance
  15721. _mesh.matrixWorld = _instanceWorldMatrix;
  15722. _mesh.raycast( raycaster, _instanceIntersects );
  15723. // process the result of raycast
  15724. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  15725. const intersect = _instanceIntersects[ i ];
  15726. intersect.instanceId = instanceId;
  15727. intersect.object = this;
  15728. intersects.push( intersect );
  15729. }
  15730. _instanceIntersects.length = 0;
  15731. }
  15732. },
  15733. setColorAt: function ( index, color ) {
  15734. if ( this.instanceColor === null ) {
  15735. this.instanceColor = new BufferAttribute( new Float32Array( this.count * 3 ), 3 );
  15736. }
  15737. color.toArray( this.instanceColor.array, index * 3 );
  15738. },
  15739. setMatrixAt: function ( index, matrix ) {
  15740. matrix.toArray( this.instanceMatrix.array, index * 16 );
  15741. },
  15742. updateMorphTargets: function () {
  15743. },
  15744. dispose: function () {
  15745. this.dispatchEvent( { type: 'dispose' } );
  15746. }
  15747. } );
  15748. /**
  15749. * parameters = {
  15750. * color: <hex>,
  15751. * opacity: <float>,
  15752. *
  15753. * linewidth: <float>,
  15754. * linecap: "round",
  15755. * linejoin: "round"
  15756. * }
  15757. */
  15758. class LineBasicMaterial extends Material {
  15759. constructor( parameters ) {
  15760. super();
  15761. this.type = 'LineBasicMaterial';
  15762. this.color = new Color( 0xffffff );
  15763. this.linewidth = 1;
  15764. this.linecap = 'round';
  15765. this.linejoin = 'round';
  15766. this.morphTargets = false;
  15767. this.setValues( parameters );
  15768. }
  15769. copy( source ) {
  15770. super.copy( source );
  15771. this.color.copy( source.color );
  15772. this.linewidth = source.linewidth;
  15773. this.linecap = source.linecap;
  15774. this.linejoin = source.linejoin;
  15775. this.morphTargets = source.morphTargets;
  15776. return this;
  15777. }
  15778. }
  15779. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15780. const _start = new Vector3();
  15781. const _end = new Vector3();
  15782. const _inverseMatrix$1 = new Matrix4();
  15783. const _ray$1 = new Ray();
  15784. const _sphere$2 = new Sphere();
  15785. function Line( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  15786. Object3D.call( this );
  15787. this.type = 'Line';
  15788. this.geometry = geometry;
  15789. this.material = material;
  15790. this.updateMorphTargets();
  15791. }
  15792. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15793. constructor: Line,
  15794. isLine: true,
  15795. copy: function ( source ) {
  15796. Object3D.prototype.copy.call( this, source );
  15797. this.material = source.material;
  15798. this.geometry = source.geometry;
  15799. return this;
  15800. },
  15801. computeLineDistances: function () {
  15802. const geometry = this.geometry;
  15803. if ( geometry.isBufferGeometry ) {
  15804. // we assume non-indexed geometry
  15805. if ( geometry.index === null ) {
  15806. const positionAttribute = geometry.attributes.position;
  15807. const lineDistances = [ 0 ];
  15808. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15809. _start.fromBufferAttribute( positionAttribute, i - 1 );
  15810. _end.fromBufferAttribute( positionAttribute, i );
  15811. lineDistances[ i ] = lineDistances[ i - 1 ];
  15812. lineDistances[ i ] += _start.distanceTo( _end );
  15813. }
  15814. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15815. } else {
  15816. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15817. }
  15818. } else if ( geometry.isGeometry ) {
  15819. console.error( 'THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15820. }
  15821. return this;
  15822. },
  15823. raycast: function ( raycaster, intersects ) {
  15824. const geometry = this.geometry;
  15825. const matrixWorld = this.matrixWorld;
  15826. const threshold = raycaster.params.Line.threshold;
  15827. // Checking boundingSphere distance to ray
  15828. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15829. _sphere$2.copy( geometry.boundingSphere );
  15830. _sphere$2.applyMatrix4( matrixWorld );
  15831. _sphere$2.radius += threshold;
  15832. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  15833. //
  15834. _inverseMatrix$1.copy( matrixWorld ).invert();
  15835. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  15836. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15837. const localThresholdSq = localThreshold * localThreshold;
  15838. const vStart = new Vector3();
  15839. const vEnd = new Vector3();
  15840. const interSegment = new Vector3();
  15841. const interRay = new Vector3();
  15842. const step = this.isLineSegments ? 2 : 1;
  15843. if ( geometry.isBufferGeometry ) {
  15844. const index = geometry.index;
  15845. const attributes = geometry.attributes;
  15846. const positionAttribute = attributes.position;
  15847. if ( index !== null ) {
  15848. const indices = index.array;
  15849. for ( let i = 0, l = indices.length - 1; i < l; i += step ) {
  15850. const a = indices[ i ];
  15851. const b = indices[ i + 1 ];
  15852. vStart.fromBufferAttribute( positionAttribute, a );
  15853. vEnd.fromBufferAttribute( positionAttribute, b );
  15854. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15855. if ( distSq > localThresholdSq ) continue;
  15856. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15857. const distance = raycaster.ray.origin.distanceTo( interRay );
  15858. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15859. intersects.push( {
  15860. distance: distance,
  15861. // What do we want? intersection point on the ray or on the segment??
  15862. // point: raycaster.ray.at( distance ),
  15863. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15864. index: i,
  15865. face: null,
  15866. faceIndex: null,
  15867. object: this
  15868. } );
  15869. }
  15870. } else {
  15871. for ( let i = 0, l = positionAttribute.count - 1; i < l; i += step ) {
  15872. vStart.fromBufferAttribute( positionAttribute, i );
  15873. vEnd.fromBufferAttribute( positionAttribute, i + 1 );
  15874. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15875. if ( distSq > localThresholdSq ) continue;
  15876. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15877. const distance = raycaster.ray.origin.distanceTo( interRay );
  15878. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15879. intersects.push( {
  15880. distance: distance,
  15881. // What do we want? intersection point on the ray or on the segment??
  15882. // point: raycaster.ray.at( distance ),
  15883. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15884. index: i,
  15885. face: null,
  15886. faceIndex: null,
  15887. object: this
  15888. } );
  15889. }
  15890. }
  15891. } else if ( geometry.isGeometry ) {
  15892. console.error( 'THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15893. }
  15894. },
  15895. updateMorphTargets: function () {
  15896. const geometry = this.geometry;
  15897. if ( geometry.isBufferGeometry ) {
  15898. const morphAttributes = geometry.morphAttributes;
  15899. const keys = Object.keys( morphAttributes );
  15900. if ( keys.length > 0 ) {
  15901. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  15902. if ( morphAttribute !== undefined ) {
  15903. this.morphTargetInfluences = [];
  15904. this.morphTargetDictionary = {};
  15905. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  15906. const name = morphAttribute[ m ].name || String( m );
  15907. this.morphTargetInfluences.push( 0 );
  15908. this.morphTargetDictionary[ name ] = m;
  15909. }
  15910. }
  15911. }
  15912. } else {
  15913. const morphTargets = geometry.morphTargets;
  15914. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  15915. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15916. }
  15917. }
  15918. }
  15919. } );
  15920. const _start$1 = new Vector3();
  15921. const _end$1 = new Vector3();
  15922. function LineSegments( geometry, material ) {
  15923. Line.call( this, geometry, material );
  15924. this.type = 'LineSegments';
  15925. }
  15926. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15927. constructor: LineSegments,
  15928. isLineSegments: true,
  15929. computeLineDistances: function () {
  15930. const geometry = this.geometry;
  15931. if ( geometry.isBufferGeometry ) {
  15932. // we assume non-indexed geometry
  15933. if ( geometry.index === null ) {
  15934. const positionAttribute = geometry.attributes.position;
  15935. const lineDistances = [];
  15936. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15937. _start$1.fromBufferAttribute( positionAttribute, i );
  15938. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  15939. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15940. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  15941. }
  15942. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15943. } else {
  15944. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15945. }
  15946. } else if ( geometry.isGeometry ) {
  15947. console.error( 'THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15948. }
  15949. return this;
  15950. }
  15951. } );
  15952. class LineLoop extends Line {
  15953. constructor( geometry, material ) {
  15954. super( geometry, material );
  15955. this.type = 'LineLoop';
  15956. }
  15957. }
  15958. LineLoop.prototype.isLineLoop = true;
  15959. /**
  15960. * parameters = {
  15961. * color: <hex>,
  15962. * opacity: <float>,
  15963. * map: new THREE.Texture( <Image> ),
  15964. * alphaMap: new THREE.Texture( <Image> ),
  15965. *
  15966. * size: <float>,
  15967. * sizeAttenuation: <bool>
  15968. *
  15969. * morphTargets: <bool>
  15970. * }
  15971. */
  15972. class PointsMaterial extends Material {
  15973. constructor( parameters ) {
  15974. super();
  15975. this.type = 'PointsMaterial';
  15976. this.color = new Color( 0xffffff );
  15977. this.map = null;
  15978. this.alphaMap = null;
  15979. this.size = 1;
  15980. this.sizeAttenuation = true;
  15981. this.morphTargets = false;
  15982. this.setValues( parameters );
  15983. }
  15984. copy( source ) {
  15985. super.copy( source );
  15986. this.color.copy( source.color );
  15987. this.map = source.map;
  15988. this.alphaMap = source.alphaMap;
  15989. this.size = source.size;
  15990. this.sizeAttenuation = source.sizeAttenuation;
  15991. this.morphTargets = source.morphTargets;
  15992. return this;
  15993. }
  15994. }
  15995. PointsMaterial.prototype.isPointsMaterial = true;
  15996. const _inverseMatrix$2 = new Matrix4();
  15997. const _ray$2 = new Ray();
  15998. const _sphere$3 = new Sphere();
  15999. const _position$1 = new Vector3();
  16000. function Points( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  16001. Object3D.call( this );
  16002. this.type = 'Points';
  16003. this.geometry = geometry;
  16004. this.material = material;
  16005. this.updateMorphTargets();
  16006. }
  16007. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16008. constructor: Points,
  16009. isPoints: true,
  16010. copy: function ( source ) {
  16011. Object3D.prototype.copy.call( this, source );
  16012. this.material = source.material;
  16013. this.geometry = source.geometry;
  16014. return this;
  16015. },
  16016. raycast: function ( raycaster, intersects ) {
  16017. const geometry = this.geometry;
  16018. const matrixWorld = this.matrixWorld;
  16019. const threshold = raycaster.params.Points.threshold;
  16020. // Checking boundingSphere distance to ray
  16021. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16022. _sphere$3.copy( geometry.boundingSphere );
  16023. _sphere$3.applyMatrix4( matrixWorld );
  16024. _sphere$3.radius += threshold;
  16025. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16026. //
  16027. _inverseMatrix$2.copy( matrixWorld ).invert();
  16028. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16029. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16030. const localThresholdSq = localThreshold * localThreshold;
  16031. if ( geometry.isBufferGeometry ) {
  16032. const index = geometry.index;
  16033. const attributes = geometry.attributes;
  16034. const positionAttribute = attributes.position;
  16035. if ( index !== null ) {
  16036. const indices = index.array;
  16037. for ( let i = 0, il = indices.length; i < il; i ++ ) {
  16038. const a = indices[ i ];
  16039. _position$1.fromBufferAttribute( positionAttribute, a );
  16040. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16041. }
  16042. } else {
  16043. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  16044. _position$1.fromBufferAttribute( positionAttribute, i );
  16045. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16046. }
  16047. }
  16048. } else {
  16049. console.error( 'THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16050. }
  16051. },
  16052. updateMorphTargets: function () {
  16053. const geometry = this.geometry;
  16054. if ( geometry.isBufferGeometry ) {
  16055. const morphAttributes = geometry.morphAttributes;
  16056. const keys = Object.keys( morphAttributes );
  16057. if ( keys.length > 0 ) {
  16058. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  16059. if ( morphAttribute !== undefined ) {
  16060. this.morphTargetInfluences = [];
  16061. this.morphTargetDictionary = {};
  16062. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16063. const name = morphAttribute[ m ].name || String( m );
  16064. this.morphTargetInfluences.push( 0 );
  16065. this.morphTargetDictionary[ name ] = m;
  16066. }
  16067. }
  16068. }
  16069. } else {
  16070. const morphTargets = geometry.morphTargets;
  16071. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16072. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16073. }
  16074. }
  16075. }
  16076. } );
  16077. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  16078. const rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16079. if ( rayPointDistanceSq < localThresholdSq ) {
  16080. const intersectPoint = new Vector3();
  16081. _ray$2.closestPointToPoint( point, intersectPoint );
  16082. intersectPoint.applyMatrix4( matrixWorld );
  16083. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16084. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16085. intersects.push( {
  16086. distance: distance,
  16087. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16088. point: intersectPoint,
  16089. index: index,
  16090. face: null,
  16091. object: object
  16092. } );
  16093. }
  16094. }
  16095. class VideoTexture extends Texture {
  16096. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16097. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16098. this.format = format !== undefined ? format : RGBFormat;
  16099. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16100. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16101. this.generateMipmaps = false;
  16102. const scope = this;
  16103. function updateVideo() {
  16104. scope.needsUpdate = true;
  16105. video.requestVideoFrameCallback( updateVideo );
  16106. }
  16107. if ( 'requestVideoFrameCallback' in video ) {
  16108. video.requestVideoFrameCallback( updateVideo );
  16109. }
  16110. }
  16111. clone() {
  16112. return new this.constructor( this.image ).copy( this );
  16113. }
  16114. update() {
  16115. const video = this.image;
  16116. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  16117. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  16118. this.needsUpdate = true;
  16119. }
  16120. }
  16121. }
  16122. VideoTexture.prototype.isVideoTexture = true;
  16123. class CompressedTexture extends Texture {
  16124. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16125. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16126. this.image = { width: width, height: height };
  16127. this.mipmaps = mipmaps;
  16128. // no flipping for cube textures
  16129. // (also flipping doesn't work for compressed textures )
  16130. this.flipY = false;
  16131. // can't generate mipmaps for compressed textures
  16132. // mips must be embedded in DDS files
  16133. this.generateMipmaps = false;
  16134. }
  16135. }
  16136. CompressedTexture.prototype.isCompressedTexture = true;
  16137. class CanvasTexture extends Texture {
  16138. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16139. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16140. this.needsUpdate = true;
  16141. }
  16142. }
  16143. CanvasTexture.prototype.isCanvasTexture = true;
  16144. class DepthTexture extends Texture {
  16145. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16146. format = format !== undefined ? format : DepthFormat;
  16147. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16148. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16149. }
  16150. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16151. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16152. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16153. this.image = { width: width, height: height };
  16154. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16155. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16156. this.flipY = false;
  16157. this.generateMipmaps = false;
  16158. }
  16159. }
  16160. DepthTexture.prototype.isDepthTexture = true;
  16161. class CircleGeometry extends BufferGeometry {
  16162. constructor( radius = 1, segments = 8, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16163. super();
  16164. this.type = 'CircleGeometry';
  16165. this.parameters = {
  16166. radius: radius,
  16167. segments: segments,
  16168. thetaStart: thetaStart,
  16169. thetaLength: thetaLength
  16170. };
  16171. segments = Math.max( 3, segments );
  16172. // buffers
  16173. const indices = [];
  16174. const vertices = [];
  16175. const normals = [];
  16176. const uvs = [];
  16177. // helper variables
  16178. const vertex = new Vector3();
  16179. const uv = new Vector2();
  16180. // center point
  16181. vertices.push( 0, 0, 0 );
  16182. normals.push( 0, 0, 1 );
  16183. uvs.push( 0.5, 0.5 );
  16184. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  16185. const segment = thetaStart + s / segments * thetaLength;
  16186. // vertex
  16187. vertex.x = radius * Math.cos( segment );
  16188. vertex.y = radius * Math.sin( segment );
  16189. vertices.push( vertex.x, vertex.y, vertex.z );
  16190. // normal
  16191. normals.push( 0, 0, 1 );
  16192. // uvs
  16193. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  16194. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  16195. uvs.push( uv.x, uv.y );
  16196. }
  16197. // indices
  16198. for ( let i = 1; i <= segments; i ++ ) {
  16199. indices.push( i, i + 1, 0 );
  16200. }
  16201. // build geometry
  16202. this.setIndex( indices );
  16203. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16204. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16205. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16206. }
  16207. }
  16208. class CylinderGeometry extends BufferGeometry {
  16209. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16210. super();
  16211. this.type = 'CylinderGeometry';
  16212. this.parameters = {
  16213. radiusTop: radiusTop,
  16214. radiusBottom: radiusBottom,
  16215. height: height,
  16216. radialSegments: radialSegments,
  16217. heightSegments: heightSegments,
  16218. openEnded: openEnded,
  16219. thetaStart: thetaStart,
  16220. thetaLength: thetaLength
  16221. };
  16222. const scope = this;
  16223. radialSegments = Math.floor( radialSegments );
  16224. heightSegments = Math.floor( heightSegments );
  16225. // buffers
  16226. const indices = [];
  16227. const vertices = [];
  16228. const normals = [];
  16229. const uvs = [];
  16230. // helper variables
  16231. let index = 0;
  16232. const indexArray = [];
  16233. const halfHeight = height / 2;
  16234. let groupStart = 0;
  16235. // generate geometry
  16236. generateTorso();
  16237. if ( openEnded === false ) {
  16238. if ( radiusTop > 0 ) generateCap( true );
  16239. if ( radiusBottom > 0 ) generateCap( false );
  16240. }
  16241. // build geometry
  16242. this.setIndex( indices );
  16243. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16244. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16245. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16246. function generateTorso() {
  16247. const normal = new Vector3();
  16248. const vertex = new Vector3();
  16249. let groupCount = 0;
  16250. // this will be used to calculate the normal
  16251. const slope = ( radiusBottom - radiusTop ) / height;
  16252. // generate vertices, normals and uvs
  16253. for ( let y = 0; y <= heightSegments; y ++ ) {
  16254. const indexRow = [];
  16255. const v = y / heightSegments;
  16256. // calculate the radius of the current row
  16257. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  16258. for ( let x = 0; x <= radialSegments; x ++ ) {
  16259. const u = x / radialSegments;
  16260. const theta = u * thetaLength + thetaStart;
  16261. const sinTheta = Math.sin( theta );
  16262. const cosTheta = Math.cos( theta );
  16263. // vertex
  16264. vertex.x = radius * sinTheta;
  16265. vertex.y = - v * height + halfHeight;
  16266. vertex.z = radius * cosTheta;
  16267. vertices.push( vertex.x, vertex.y, vertex.z );
  16268. // normal
  16269. normal.set( sinTheta, slope, cosTheta ).normalize();
  16270. normals.push( normal.x, normal.y, normal.z );
  16271. // uv
  16272. uvs.push( u, 1 - v );
  16273. // save index of vertex in respective row
  16274. indexRow.push( index ++ );
  16275. }
  16276. // now save vertices of the row in our index array
  16277. indexArray.push( indexRow );
  16278. }
  16279. // generate indices
  16280. for ( let x = 0; x < radialSegments; x ++ ) {
  16281. for ( let y = 0; y < heightSegments; y ++ ) {
  16282. // we use the index array to access the correct indices
  16283. const a = indexArray[ y ][ x ];
  16284. const b = indexArray[ y + 1 ][ x ];
  16285. const c = indexArray[ y + 1 ][ x + 1 ];
  16286. const d = indexArray[ y ][ x + 1 ];
  16287. // faces
  16288. indices.push( a, b, d );
  16289. indices.push( b, c, d );
  16290. // update group counter
  16291. groupCount += 6;
  16292. }
  16293. }
  16294. // add a group to the geometry. this will ensure multi material support
  16295. scope.addGroup( groupStart, groupCount, 0 );
  16296. // calculate new start value for groups
  16297. groupStart += groupCount;
  16298. }
  16299. function generateCap( top ) {
  16300. // save the index of the first center vertex
  16301. const centerIndexStart = index;
  16302. const uv = new Vector2();
  16303. const vertex = new Vector3();
  16304. let groupCount = 0;
  16305. const radius = ( top === true ) ? radiusTop : radiusBottom;
  16306. const sign = ( top === true ) ? 1 : - 1;
  16307. // first we generate the center vertex data of the cap.
  16308. // because the geometry needs one set of uvs per face,
  16309. // we must generate a center vertex per face/segment
  16310. for ( let x = 1; x <= radialSegments; x ++ ) {
  16311. // vertex
  16312. vertices.push( 0, halfHeight * sign, 0 );
  16313. // normal
  16314. normals.push( 0, sign, 0 );
  16315. // uv
  16316. uvs.push( 0.5, 0.5 );
  16317. // increase index
  16318. index ++;
  16319. }
  16320. // save the index of the last center vertex
  16321. const centerIndexEnd = index;
  16322. // now we generate the surrounding vertices, normals and uvs
  16323. for ( let x = 0; x <= radialSegments; x ++ ) {
  16324. const u = x / radialSegments;
  16325. const theta = u * thetaLength + thetaStart;
  16326. const cosTheta = Math.cos( theta );
  16327. const sinTheta = Math.sin( theta );
  16328. // vertex
  16329. vertex.x = radius * sinTheta;
  16330. vertex.y = halfHeight * sign;
  16331. vertex.z = radius * cosTheta;
  16332. vertices.push( vertex.x, vertex.y, vertex.z );
  16333. // normal
  16334. normals.push( 0, sign, 0 );
  16335. // uv
  16336. uv.x = ( cosTheta * 0.5 ) + 0.5;
  16337. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  16338. uvs.push( uv.x, uv.y );
  16339. // increase index
  16340. index ++;
  16341. }
  16342. // generate indices
  16343. for ( let x = 0; x < radialSegments; x ++ ) {
  16344. const c = centerIndexStart + x;
  16345. const i = centerIndexEnd + x;
  16346. if ( top === true ) {
  16347. // face top
  16348. indices.push( i, i + 1, c );
  16349. } else {
  16350. // face bottom
  16351. indices.push( i + 1, i, c );
  16352. }
  16353. groupCount += 3;
  16354. }
  16355. // add a group to the geometry. this will ensure multi material support
  16356. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  16357. // calculate new start value for groups
  16358. groupStart += groupCount;
  16359. }
  16360. }
  16361. }
  16362. class ConeGeometry extends CylinderGeometry {
  16363. constructor( radius = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16364. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16365. this.type = 'ConeGeometry';
  16366. this.parameters = {
  16367. radius: radius,
  16368. height: height,
  16369. radialSegments: radialSegments,
  16370. heightSegments: heightSegments,
  16371. openEnded: openEnded,
  16372. thetaStart: thetaStart,
  16373. thetaLength: thetaLength
  16374. };
  16375. }
  16376. }
  16377. class PolyhedronGeometry extends BufferGeometry {
  16378. constructor( vertices, indices, radius = 1, detail = 0 ) {
  16379. super();
  16380. this.type = 'PolyhedronGeometry';
  16381. this.parameters = {
  16382. vertices: vertices,
  16383. indices: indices,
  16384. radius: radius,
  16385. detail: detail
  16386. };
  16387. // default buffer data
  16388. const vertexBuffer = [];
  16389. const uvBuffer = [];
  16390. // the subdivision creates the vertex buffer data
  16391. subdivide( detail );
  16392. // all vertices should lie on a conceptual sphere with a given radius
  16393. applyRadius( radius );
  16394. // finally, create the uv data
  16395. generateUVs();
  16396. // build non-indexed geometry
  16397. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16398. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16399. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16400. if ( detail === 0 ) {
  16401. this.computeVertexNormals(); // flat normals
  16402. } else {
  16403. this.normalizeNormals(); // smooth normals
  16404. }
  16405. // helper functions
  16406. function subdivide( detail ) {
  16407. const a = new Vector3();
  16408. const b = new Vector3();
  16409. const c = new Vector3();
  16410. // iterate over all faces and apply a subdivison with the given detail value
  16411. for ( let i = 0; i < indices.length; i += 3 ) {
  16412. // get the vertices of the face
  16413. getVertexByIndex( indices[ i + 0 ], a );
  16414. getVertexByIndex( indices[ i + 1 ], b );
  16415. getVertexByIndex( indices[ i + 2 ], c );
  16416. // perform subdivision
  16417. subdivideFace( a, b, c, detail );
  16418. }
  16419. }
  16420. function subdivideFace( a, b, c, detail ) {
  16421. const cols = detail + 1;
  16422. // we use this multidimensional array as a data structure for creating the subdivision
  16423. const v = [];
  16424. // construct all of the vertices for this subdivision
  16425. for ( let i = 0; i <= cols; i ++ ) {
  16426. v[ i ] = [];
  16427. const aj = a.clone().lerp( c, i / cols );
  16428. const bj = b.clone().lerp( c, i / cols );
  16429. const rows = cols - i;
  16430. for ( let j = 0; j <= rows; j ++ ) {
  16431. if ( j === 0 && i === cols ) {
  16432. v[ i ][ j ] = aj;
  16433. } else {
  16434. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16435. }
  16436. }
  16437. }
  16438. // construct all of the faces
  16439. for ( let i = 0; i < cols; i ++ ) {
  16440. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16441. const k = Math.floor( j / 2 );
  16442. if ( j % 2 === 0 ) {
  16443. pushVertex( v[ i ][ k + 1 ] );
  16444. pushVertex( v[ i + 1 ][ k ] );
  16445. pushVertex( v[ i ][ k ] );
  16446. } else {
  16447. pushVertex( v[ i ][ k + 1 ] );
  16448. pushVertex( v[ i + 1 ][ k + 1 ] );
  16449. pushVertex( v[ i + 1 ][ k ] );
  16450. }
  16451. }
  16452. }
  16453. }
  16454. function applyRadius( radius ) {
  16455. const vertex = new Vector3();
  16456. // iterate over the entire buffer and apply the radius to each vertex
  16457. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  16458. vertex.x = vertexBuffer[ i + 0 ];
  16459. vertex.y = vertexBuffer[ i + 1 ];
  16460. vertex.z = vertexBuffer[ i + 2 ];
  16461. vertex.normalize().multiplyScalar( radius );
  16462. vertexBuffer[ i + 0 ] = vertex.x;
  16463. vertexBuffer[ i + 1 ] = vertex.y;
  16464. vertexBuffer[ i + 2 ] = vertex.z;
  16465. }
  16466. }
  16467. function generateUVs() {
  16468. const vertex = new Vector3();
  16469. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  16470. vertex.x = vertexBuffer[ i + 0 ];
  16471. vertex.y = vertexBuffer[ i + 1 ];
  16472. vertex.z = vertexBuffer[ i + 2 ];
  16473. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16474. const v = inclination( vertex ) / Math.PI + 0.5;
  16475. uvBuffer.push( u, 1 - v );
  16476. }
  16477. correctUVs();
  16478. correctSeam();
  16479. }
  16480. function correctSeam() {
  16481. // handle case when face straddles the seam, see #3269
  16482. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  16483. // uv data of a single face
  16484. const x0 = uvBuffer[ i + 0 ];
  16485. const x1 = uvBuffer[ i + 2 ];
  16486. const x2 = uvBuffer[ i + 4 ];
  16487. const max = Math.max( x0, x1, x2 );
  16488. const min = Math.min( x0, x1, x2 );
  16489. // 0.9 is somewhat arbitrary
  16490. if ( max > 0.9 && min < 0.1 ) {
  16491. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16492. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16493. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16494. }
  16495. }
  16496. }
  16497. function pushVertex( vertex ) {
  16498. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16499. }
  16500. function getVertexByIndex( index, vertex ) {
  16501. const stride = index * 3;
  16502. vertex.x = vertices[ stride + 0 ];
  16503. vertex.y = vertices[ stride + 1 ];
  16504. vertex.z = vertices[ stride + 2 ];
  16505. }
  16506. function correctUVs() {
  16507. const a = new Vector3();
  16508. const b = new Vector3();
  16509. const c = new Vector3();
  16510. const centroid = new Vector3();
  16511. const uvA = new Vector2();
  16512. const uvB = new Vector2();
  16513. const uvC = new Vector2();
  16514. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16515. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16516. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16517. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16518. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16519. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16520. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16521. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16522. const azi = azimuth( centroid );
  16523. correctUV( uvA, j + 0, a, azi );
  16524. correctUV( uvB, j + 2, b, azi );
  16525. correctUV( uvC, j + 4, c, azi );
  16526. }
  16527. }
  16528. function correctUV( uv, stride, vector, azimuth ) {
  16529. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16530. uvBuffer[ stride ] = uv.x - 1;
  16531. }
  16532. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16533. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16534. }
  16535. }
  16536. // Angle around the Y axis, counter-clockwise when looking from above.
  16537. function azimuth( vector ) {
  16538. return Math.atan2( vector.z, - vector.x );
  16539. }
  16540. // Angle above the XZ plane.
  16541. function inclination( vector ) {
  16542. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16543. }
  16544. }
  16545. }
  16546. class DodecahedronGeometry extends PolyhedronGeometry {
  16547. constructor( radius = 1, detail = 0 ) {
  16548. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16549. const r = 1 / t;
  16550. const vertices = [
  16551. // (±1, ±1, ±1)
  16552. - 1, - 1, - 1, - 1, - 1, 1,
  16553. - 1, 1, - 1, - 1, 1, 1,
  16554. 1, - 1, - 1, 1, - 1, 1,
  16555. 1, 1, - 1, 1, 1, 1,
  16556. // (0, ±1/φ, ±φ)
  16557. 0, - r, - t, 0, - r, t,
  16558. 0, r, - t, 0, r, t,
  16559. // (±1/φ, ±φ, 0)
  16560. - r, - t, 0, - r, t, 0,
  16561. r, - t, 0, r, t, 0,
  16562. // (±φ, 0, ±1/φ)
  16563. - t, 0, - r, t, 0, - r,
  16564. - t, 0, r, t, 0, r
  16565. ];
  16566. const indices = [
  16567. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16568. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16569. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16570. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16571. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16572. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16573. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16574. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16575. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16576. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16577. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16578. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16579. ];
  16580. super( vertices, indices, radius, detail );
  16581. this.type = 'DodecahedronGeometry';
  16582. this.parameters = {
  16583. radius: radius,
  16584. detail: detail
  16585. };
  16586. }
  16587. }
  16588. const _v0$2 = new Vector3();
  16589. const _v1$5 = new Vector3();
  16590. const _normal$1 = new Vector3();
  16591. const _triangle = new Triangle();
  16592. class EdgesGeometry extends BufferGeometry {
  16593. constructor( geometry, thresholdAngle ) {
  16594. super();
  16595. this.type = 'EdgesGeometry';
  16596. this.parameters = {
  16597. thresholdAngle: thresholdAngle
  16598. };
  16599. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  16600. if ( geometry.isGeometry === true ) {
  16601. console.error( 'THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16602. return;
  16603. }
  16604. const precisionPoints = 4;
  16605. const precision = Math.pow( 10, precisionPoints );
  16606. const thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  16607. const indexAttr = geometry.getIndex();
  16608. const positionAttr = geometry.getAttribute( 'position' );
  16609. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  16610. const indexArr = [ 0, 0, 0 ];
  16611. const vertKeys = [ 'a', 'b', 'c' ];
  16612. const hashes = new Array( 3 );
  16613. const edgeData = {};
  16614. const vertices = [];
  16615. for ( let i = 0; i < indexCount; i += 3 ) {
  16616. if ( indexAttr ) {
  16617. indexArr[ 0 ] = indexAttr.getX( i );
  16618. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  16619. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  16620. } else {
  16621. indexArr[ 0 ] = i;
  16622. indexArr[ 1 ] = i + 1;
  16623. indexArr[ 2 ] = i + 2;
  16624. }
  16625. const { a, b, c } = _triangle;
  16626. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  16627. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  16628. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  16629. _triangle.getNormal( _normal$1 );
  16630. // create hashes for the edge from the vertices
  16631. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  16632. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  16633. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  16634. // skip degenerate triangles
  16635. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  16636. continue;
  16637. }
  16638. // iterate over every edge
  16639. for ( let j = 0; j < 3; j ++ ) {
  16640. // get the first and next vertex making up the edge
  16641. const jNext = ( j + 1 ) % 3;
  16642. const vecHash0 = hashes[ j ];
  16643. const vecHash1 = hashes[ jNext ];
  16644. const v0 = _triangle[ vertKeys[ j ] ];
  16645. const v1 = _triangle[ vertKeys[ jNext ] ];
  16646. const hash = `${ vecHash0 }_${ vecHash1 }`;
  16647. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  16648. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  16649. // if we found a sibling edge add it into the vertex array if
  16650. // it meets the angle threshold and delete the edge from the map.
  16651. if ( _normal$1.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  16652. vertices.push( v0.x, v0.y, v0.z );
  16653. vertices.push( v1.x, v1.y, v1.z );
  16654. }
  16655. edgeData[ reverseHash ] = null;
  16656. } else if ( ! ( hash in edgeData ) ) {
  16657. // if we've already got an edge here then skip adding a new one
  16658. edgeData[ hash ] = {
  16659. index0: indexArr[ j ],
  16660. index1: indexArr[ jNext ],
  16661. normal: _normal$1.clone(),
  16662. };
  16663. }
  16664. }
  16665. }
  16666. // iterate over all remaining, unmatched edges and add them to the vertex array
  16667. for ( const key in edgeData ) {
  16668. if ( edgeData[ key ] ) {
  16669. const { index0, index1 } = edgeData[ key ];
  16670. _v0$2.fromBufferAttribute( positionAttr, index0 );
  16671. _v1$5.fromBufferAttribute( positionAttr, index1 );
  16672. vertices.push( _v0$2.x, _v0$2.y, _v0$2.z );
  16673. vertices.push( _v1$5.x, _v1$5.y, _v1$5.z );
  16674. }
  16675. }
  16676. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16677. }
  16678. }
  16679. /**
  16680. * Port from https://github.com/mapbox/earcut (v2.2.2)
  16681. */
  16682. const Earcut = {
  16683. triangulate: function ( data, holeIndices, dim ) {
  16684. dim = dim || 2;
  16685. const hasHoles = holeIndices && holeIndices.length;
  16686. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  16687. let outerNode = linkedList( data, 0, outerLen, dim, true );
  16688. const triangles = [];
  16689. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  16690. let minX, minY, maxX, maxY, x, y, invSize;
  16691. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16692. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16693. if ( data.length > 80 * dim ) {
  16694. minX = maxX = data[ 0 ];
  16695. minY = maxY = data[ 1 ];
  16696. for ( let i = dim; i < outerLen; i += dim ) {
  16697. x = data[ i ];
  16698. y = data[ i + 1 ];
  16699. if ( x < minX ) minX = x;
  16700. if ( y < minY ) minY = y;
  16701. if ( x > maxX ) maxX = x;
  16702. if ( y > maxY ) maxY = y;
  16703. }
  16704. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16705. invSize = Math.max( maxX - minX, maxY - minY );
  16706. invSize = invSize !== 0 ? 1 / invSize : 0;
  16707. }
  16708. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16709. return triangles;
  16710. }
  16711. };
  16712. // create a circular doubly linked list from polygon points in the specified winding order
  16713. function linkedList( data, start, end, dim, clockwise ) {
  16714. let i, last;
  16715. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16716. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16717. } else {
  16718. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16719. }
  16720. if ( last && equals( last, last.next ) ) {
  16721. removeNode( last );
  16722. last = last.next;
  16723. }
  16724. return last;
  16725. }
  16726. // eliminate colinear or duplicate points
  16727. function filterPoints( start, end ) {
  16728. if ( ! start ) return start;
  16729. if ( ! end ) end = start;
  16730. let p = start,
  16731. again;
  16732. do {
  16733. again = false;
  16734. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16735. removeNode( p );
  16736. p = end = p.prev;
  16737. if ( p === p.next ) break;
  16738. again = true;
  16739. } else {
  16740. p = p.next;
  16741. }
  16742. } while ( again || p !== end );
  16743. return end;
  16744. }
  16745. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16746. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16747. if ( ! ear ) return;
  16748. // interlink polygon nodes in z-order
  16749. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16750. let stop = ear,
  16751. prev, next;
  16752. // iterate through ears, slicing them one by one
  16753. while ( ear.prev !== ear.next ) {
  16754. prev = ear.prev;
  16755. next = ear.next;
  16756. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16757. // cut off the triangle
  16758. triangles.push( prev.i / dim );
  16759. triangles.push( ear.i / dim );
  16760. triangles.push( next.i / dim );
  16761. removeNode( ear );
  16762. // skipping the next vertex leads to less sliver triangles
  16763. ear = next.next;
  16764. stop = next.next;
  16765. continue;
  16766. }
  16767. ear = next;
  16768. // if we looped through the whole remaining polygon and can't find any more ears
  16769. if ( ear === stop ) {
  16770. // try filtering points and slicing again
  16771. if ( ! pass ) {
  16772. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16773. // if this didn't work, try curing all small self-intersections locally
  16774. } else if ( pass === 1 ) {
  16775. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  16776. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16777. // as a last resort, try splitting the remaining polygon into two
  16778. } else if ( pass === 2 ) {
  16779. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16780. }
  16781. break;
  16782. }
  16783. }
  16784. }
  16785. // check whether a polygon node forms a valid ear with adjacent nodes
  16786. function isEar( ear ) {
  16787. const a = ear.prev,
  16788. b = ear,
  16789. c = ear.next;
  16790. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16791. // now make sure we don't have other points inside the potential ear
  16792. let p = ear.next.next;
  16793. while ( p !== ear.prev ) {
  16794. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16795. area( p.prev, p, p.next ) >= 0 ) return false;
  16796. p = p.next;
  16797. }
  16798. return true;
  16799. }
  16800. function isEarHashed( ear, minX, minY, invSize ) {
  16801. const a = ear.prev,
  16802. b = ear,
  16803. c = ear.next;
  16804. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16805. // triangle bbox; min & max are calculated like this for speed
  16806. const minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16807. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16808. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16809. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16810. // z-order range for the current triangle bbox;
  16811. const minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16812. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16813. let p = ear.prevZ,
  16814. n = ear.nextZ;
  16815. // look for points inside the triangle in both directions
  16816. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  16817. if ( p !== ear.prev && p !== ear.next &&
  16818. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16819. area( p.prev, p, p.next ) >= 0 ) return false;
  16820. p = p.prevZ;
  16821. if ( n !== ear.prev && n !== ear.next &&
  16822. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  16823. area( n.prev, n, n.next ) >= 0 ) return false;
  16824. n = n.nextZ;
  16825. }
  16826. // look for remaining points in decreasing z-order
  16827. while ( p && p.z >= minZ ) {
  16828. if ( p !== ear.prev && p !== ear.next &&
  16829. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16830. area( p.prev, p, p.next ) >= 0 ) return false;
  16831. p = p.prevZ;
  16832. }
  16833. // look for remaining points in increasing z-order
  16834. while ( n && n.z <= maxZ ) {
  16835. if ( n !== ear.prev && n !== ear.next &&
  16836. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  16837. area( n.prev, n, n.next ) >= 0 ) return false;
  16838. n = n.nextZ;
  16839. }
  16840. return true;
  16841. }
  16842. // go through all polygon nodes and cure small local self-intersections
  16843. function cureLocalIntersections( start, triangles, dim ) {
  16844. let p = start;
  16845. do {
  16846. const a = p.prev,
  16847. b = p.next.next;
  16848. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16849. triangles.push( a.i / dim );
  16850. triangles.push( p.i / dim );
  16851. triangles.push( b.i / dim );
  16852. // remove two nodes involved
  16853. removeNode( p );
  16854. removeNode( p.next );
  16855. p = start = b;
  16856. }
  16857. p = p.next;
  16858. } while ( p !== start );
  16859. return filterPoints( p );
  16860. }
  16861. // try splitting polygon into two and triangulate them independently
  16862. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16863. // look for a valid diagonal that divides the polygon into two
  16864. let a = start;
  16865. do {
  16866. let b = a.next.next;
  16867. while ( b !== a.prev ) {
  16868. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16869. // split the polygon in two by the diagonal
  16870. let c = splitPolygon( a, b );
  16871. // filter colinear points around the cuts
  16872. a = filterPoints( a, a.next );
  16873. c = filterPoints( c, c.next );
  16874. // run earcut on each half
  16875. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16876. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16877. return;
  16878. }
  16879. b = b.next;
  16880. }
  16881. a = a.next;
  16882. } while ( a !== start );
  16883. }
  16884. // link every hole into the outer loop, producing a single-ring polygon without holes
  16885. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16886. const queue = [];
  16887. let i, len, start, end, list;
  16888. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16889. start = holeIndices[ i ] * dim;
  16890. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16891. list = linkedList( data, start, end, dim, false );
  16892. if ( list === list.next ) list.steiner = true;
  16893. queue.push( getLeftmost( list ) );
  16894. }
  16895. queue.sort( compareX );
  16896. // process holes from left to right
  16897. for ( i = 0; i < queue.length; i ++ ) {
  16898. eliminateHole( queue[ i ], outerNode );
  16899. outerNode = filterPoints( outerNode, outerNode.next );
  16900. }
  16901. return outerNode;
  16902. }
  16903. function compareX( a, b ) {
  16904. return a.x - b.x;
  16905. }
  16906. // find a bridge between vertices that connects hole with an outer ring and and link it
  16907. function eliminateHole( hole, outerNode ) {
  16908. outerNode = findHoleBridge( hole, outerNode );
  16909. if ( outerNode ) {
  16910. const b = splitPolygon( outerNode, hole );
  16911. // filter collinear points around the cuts
  16912. filterPoints( outerNode, outerNode.next );
  16913. filterPoints( b, b.next );
  16914. }
  16915. }
  16916. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  16917. function findHoleBridge( hole, outerNode ) {
  16918. let p = outerNode;
  16919. const hx = hole.x;
  16920. const hy = hole.y;
  16921. let qx = - Infinity, m;
  16922. // find a segment intersected by a ray from the hole's leftmost point to the left;
  16923. // segment's endpoint with lesser x will be potential connection point
  16924. do {
  16925. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  16926. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  16927. if ( x <= hx && x > qx ) {
  16928. qx = x;
  16929. if ( x === hx ) {
  16930. if ( hy === p.y ) return p;
  16931. if ( hy === p.next.y ) return p.next;
  16932. }
  16933. m = p.x < p.next.x ? p : p.next;
  16934. }
  16935. }
  16936. p = p.next;
  16937. } while ( p !== outerNode );
  16938. if ( ! m ) return null;
  16939. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  16940. // look for points inside the triangle of hole point, segment intersection and endpoint;
  16941. // if there are no points found, we have a valid connection;
  16942. // otherwise choose the point of the minimum angle with the ray as connection point
  16943. const stop = m,
  16944. mx = m.x,
  16945. my = m.y;
  16946. let tanMin = Infinity, tan;
  16947. p = m;
  16948. do {
  16949. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  16950. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  16951. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  16952. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  16953. m = p;
  16954. tanMin = tan;
  16955. }
  16956. }
  16957. p = p.next;
  16958. } while ( p !== stop );
  16959. return m;
  16960. }
  16961. // whether sector in vertex m contains sector in vertex p in the same coordinates
  16962. function sectorContainsSector( m, p ) {
  16963. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  16964. }
  16965. // interlink polygon nodes in z-order
  16966. function indexCurve( start, minX, minY, invSize ) {
  16967. let p = start;
  16968. do {
  16969. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  16970. p.prevZ = p.prev;
  16971. p.nextZ = p.next;
  16972. p = p.next;
  16973. } while ( p !== start );
  16974. p.prevZ.nextZ = null;
  16975. p.prevZ = null;
  16976. sortLinked( p );
  16977. }
  16978. // Simon Tatham's linked list merge sort algorithm
  16979. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  16980. function sortLinked( list ) {
  16981. let i, p, q, e, tail, numMerges, pSize, qSize,
  16982. inSize = 1;
  16983. do {
  16984. p = list;
  16985. list = null;
  16986. tail = null;
  16987. numMerges = 0;
  16988. while ( p ) {
  16989. numMerges ++;
  16990. q = p;
  16991. pSize = 0;
  16992. for ( i = 0; i < inSize; i ++ ) {
  16993. pSize ++;
  16994. q = q.nextZ;
  16995. if ( ! q ) break;
  16996. }
  16997. qSize = inSize;
  16998. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  16999. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17000. e = p;
  17001. p = p.nextZ;
  17002. pSize --;
  17003. } else {
  17004. e = q;
  17005. q = q.nextZ;
  17006. qSize --;
  17007. }
  17008. if ( tail ) tail.nextZ = e;
  17009. else list = e;
  17010. e.prevZ = tail;
  17011. tail = e;
  17012. }
  17013. p = q;
  17014. }
  17015. tail.nextZ = null;
  17016. inSize *= 2;
  17017. } while ( numMerges > 1 );
  17018. return list;
  17019. }
  17020. // z-order of a point given coords and inverse of the longer side of data bbox
  17021. function zOrder( x, y, minX, minY, invSize ) {
  17022. // coords are transformed into non-negative 15-bit integer range
  17023. x = 32767 * ( x - minX ) * invSize;
  17024. y = 32767 * ( y - minY ) * invSize;
  17025. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17026. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17027. x = ( x | ( x << 2 ) ) & 0x33333333;
  17028. x = ( x | ( x << 1 ) ) & 0x55555555;
  17029. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17030. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17031. y = ( y | ( y << 2 ) ) & 0x33333333;
  17032. y = ( y | ( y << 1 ) ) & 0x55555555;
  17033. return x | ( y << 1 );
  17034. }
  17035. // find the leftmost node of a polygon ring
  17036. function getLeftmost( start ) {
  17037. let p = start,
  17038. leftmost = start;
  17039. do {
  17040. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17041. p = p.next;
  17042. } while ( p !== start );
  17043. return leftmost;
  17044. }
  17045. // check if a point lies within a convex triangle
  17046. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17047. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17048. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17049. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17050. }
  17051. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17052. function isValidDiagonal( a, b ) {
  17053. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  17054. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  17055. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  17056. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  17057. }
  17058. // signed area of a triangle
  17059. function area( p, q, r ) {
  17060. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17061. }
  17062. // check if two points are equal
  17063. function equals( p1, p2 ) {
  17064. return p1.x === p2.x && p1.y === p2.y;
  17065. }
  17066. // check if two segments intersect
  17067. function intersects( p1, q1, p2, q2 ) {
  17068. const o1 = sign( area( p1, q1, p2 ) );
  17069. const o2 = sign( area( p1, q1, q2 ) );
  17070. const o3 = sign( area( p2, q2, p1 ) );
  17071. const o4 = sign( area( p2, q2, q1 ) );
  17072. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  17073. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  17074. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  17075. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  17076. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  17077. return false;
  17078. }
  17079. // for collinear points p, q, r, check if point q lies on segment pr
  17080. function onSegment( p, q, r ) {
  17081. 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 );
  17082. }
  17083. function sign( num ) {
  17084. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  17085. }
  17086. // check if a polygon diagonal intersects any polygon segments
  17087. function intersectsPolygon( a, b ) {
  17088. let p = a;
  17089. do {
  17090. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17091. intersects( p, p.next, a, b ) ) return true;
  17092. p = p.next;
  17093. } while ( p !== a );
  17094. return false;
  17095. }
  17096. // check if a polygon diagonal is locally inside the polygon
  17097. function locallyInside( a, b ) {
  17098. return area( a.prev, a, a.next ) < 0 ?
  17099. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17100. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17101. }
  17102. // check if the middle point of a polygon diagonal is inside the polygon
  17103. function middleInside( a, b ) {
  17104. let p = a,
  17105. inside = false;
  17106. const px = ( a.x + b.x ) / 2,
  17107. py = ( a.y + b.y ) / 2;
  17108. do {
  17109. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17110. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17111. inside = ! inside;
  17112. p = p.next;
  17113. } while ( p !== a );
  17114. return inside;
  17115. }
  17116. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17117. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17118. function splitPolygon( a, b ) {
  17119. const a2 = new Node( a.i, a.x, a.y ),
  17120. b2 = new Node( b.i, b.x, b.y ),
  17121. an = a.next,
  17122. bp = b.prev;
  17123. a.next = b;
  17124. b.prev = a;
  17125. a2.next = an;
  17126. an.prev = a2;
  17127. b2.next = a2;
  17128. a2.prev = b2;
  17129. bp.next = b2;
  17130. b2.prev = bp;
  17131. return b2;
  17132. }
  17133. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17134. function insertNode( i, x, y, last ) {
  17135. const p = new Node( i, x, y );
  17136. if ( ! last ) {
  17137. p.prev = p;
  17138. p.next = p;
  17139. } else {
  17140. p.next = last.next;
  17141. p.prev = last;
  17142. last.next.prev = p;
  17143. last.next = p;
  17144. }
  17145. return p;
  17146. }
  17147. function removeNode( p ) {
  17148. p.next.prev = p.prev;
  17149. p.prev.next = p.next;
  17150. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17151. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17152. }
  17153. function Node( i, x, y ) {
  17154. // vertex index in coordinates array
  17155. this.i = i;
  17156. // vertex coordinates
  17157. this.x = x;
  17158. this.y = y;
  17159. // previous and next vertex nodes in a polygon ring
  17160. this.prev = null;
  17161. this.next = null;
  17162. // z-order curve value
  17163. this.z = null;
  17164. // previous and next nodes in z-order
  17165. this.prevZ = null;
  17166. this.nextZ = null;
  17167. // indicates whether this is a steiner point
  17168. this.steiner = false;
  17169. }
  17170. function signedArea( data, start, end, dim ) {
  17171. let sum = 0;
  17172. for ( let i = start, j = end - dim; i < end; i += dim ) {
  17173. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17174. j = i;
  17175. }
  17176. return sum;
  17177. }
  17178. const ShapeUtils = {
  17179. // calculate area of the contour polygon
  17180. area: function ( contour ) {
  17181. const n = contour.length;
  17182. let a = 0.0;
  17183. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  17184. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17185. }
  17186. return a * 0.5;
  17187. },
  17188. isClockWise: function ( pts ) {
  17189. return ShapeUtils.area( pts ) < 0;
  17190. },
  17191. triangulateShape: function ( contour, holes ) {
  17192. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17193. const holeIndices = []; // array of hole indices
  17194. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17195. removeDupEndPts( contour );
  17196. addContour( vertices, contour );
  17197. //
  17198. let holeIndex = contour.length;
  17199. holes.forEach( removeDupEndPts );
  17200. for ( let i = 0; i < holes.length; i ++ ) {
  17201. holeIndices.push( holeIndex );
  17202. holeIndex += holes[ i ].length;
  17203. addContour( vertices, holes[ i ] );
  17204. }
  17205. //
  17206. const triangles = Earcut.triangulate( vertices, holeIndices );
  17207. //
  17208. for ( let i = 0; i < triangles.length; i += 3 ) {
  17209. faces.push( triangles.slice( i, i + 3 ) );
  17210. }
  17211. return faces;
  17212. }
  17213. };
  17214. function removeDupEndPts( points ) {
  17215. const l = points.length;
  17216. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17217. points.pop();
  17218. }
  17219. }
  17220. function addContour( vertices, contour ) {
  17221. for ( let i = 0; i < contour.length; i ++ ) {
  17222. vertices.push( contour[ i ].x );
  17223. vertices.push( contour[ i ].y );
  17224. }
  17225. }
  17226. /**
  17227. * Creates extruded geometry from a path shape.
  17228. *
  17229. * parameters = {
  17230. *
  17231. * curveSegments: <int>, // number of points on the curves
  17232. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17233. * depth: <float>, // Depth to extrude the shape
  17234. *
  17235. * bevelEnabled: <bool>, // turn on bevel
  17236. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17237. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17238. * bevelOffset: <float>, // how far from shape outline does bevel start
  17239. * bevelSegments: <int>, // number of bevel layers
  17240. *
  17241. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17242. *
  17243. * UVGenerator: <Object> // object that provides UV generator functions
  17244. *
  17245. * }
  17246. */
  17247. class ExtrudeGeometry extends BufferGeometry {
  17248. constructor( shapes, options ) {
  17249. super();
  17250. this.type = 'ExtrudeGeometry';
  17251. this.parameters = {
  17252. shapes: shapes,
  17253. options: options
  17254. };
  17255. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17256. const scope = this;
  17257. const verticesArray = [];
  17258. const uvArray = [];
  17259. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  17260. const shape = shapes[ i ];
  17261. addShape( shape );
  17262. }
  17263. // build geometry
  17264. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17265. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17266. this.computeVertexNormals();
  17267. // functions
  17268. function addShape( shape ) {
  17269. const placeholder = [];
  17270. // options
  17271. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17272. const steps = options.steps !== undefined ? options.steps : 1;
  17273. let depth = options.depth !== undefined ? options.depth : 100;
  17274. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17275. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17276. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17277. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17278. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17279. const extrudePath = options.extrudePath;
  17280. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17281. // deprecated options
  17282. if ( options.amount !== undefined ) {
  17283. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17284. depth = options.amount;
  17285. }
  17286. //
  17287. let extrudePts, extrudeByPath = false;
  17288. let splineTube, binormal, normal, position2;
  17289. if ( extrudePath ) {
  17290. extrudePts = extrudePath.getSpacedPoints( steps );
  17291. extrudeByPath = true;
  17292. bevelEnabled = false; // bevels not supported for path extrusion
  17293. // SETUP TNB variables
  17294. // TODO1 - have a .isClosed in spline?
  17295. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17296. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17297. binormal = new Vector3();
  17298. normal = new Vector3();
  17299. position2 = new Vector3();
  17300. }
  17301. // Safeguards if bevels are not enabled
  17302. if ( ! bevelEnabled ) {
  17303. bevelSegments = 0;
  17304. bevelThickness = 0;
  17305. bevelSize = 0;
  17306. bevelOffset = 0;
  17307. }
  17308. // Variables initialization
  17309. const shapePoints = shape.extractPoints( curveSegments );
  17310. let vertices = shapePoints.shape;
  17311. const holes = shapePoints.holes;
  17312. const reverse = ! ShapeUtils.isClockWise( vertices );
  17313. if ( reverse ) {
  17314. vertices = vertices.reverse();
  17315. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17316. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17317. const ahole = holes[ h ];
  17318. if ( ShapeUtils.isClockWise( ahole ) ) {
  17319. holes[ h ] = ahole.reverse();
  17320. }
  17321. }
  17322. }
  17323. const faces = ShapeUtils.triangulateShape( vertices, holes );
  17324. /* Vertices */
  17325. const contour = vertices; // vertices has all points but contour has only points of circumference
  17326. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17327. const ahole = holes[ h ];
  17328. vertices = vertices.concat( ahole );
  17329. }
  17330. function scalePt2( pt, vec, size ) {
  17331. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  17332. return vec.clone().multiplyScalar( size ).add( pt );
  17333. }
  17334. const vlen = vertices.length, flen = faces.length;
  17335. // Find directions for point movement
  17336. function getBevelVec( inPt, inPrev, inNext ) {
  17337. // computes for inPt the corresponding point inPt' on a new contour
  17338. // shifted by 1 unit (length of normalized vector) to the left
  17339. // if we walk along contour clockwise, this new contour is outside the old one
  17340. //
  17341. // inPt' is the intersection of the two lines parallel to the two
  17342. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17343. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17344. // good reading for geometry algorithms (here: line-line intersection)
  17345. // http://geomalgorithms.com/a05-_intersect-1.html
  17346. const v_prev_x = inPt.x - inPrev.x,
  17347. v_prev_y = inPt.y - inPrev.y;
  17348. const v_next_x = inNext.x - inPt.x,
  17349. v_next_y = inNext.y - inPt.y;
  17350. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17351. // check for collinear edges
  17352. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17353. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17354. // not collinear
  17355. // length of vectors for normalizing
  17356. const v_prev_len = Math.sqrt( v_prev_lensq );
  17357. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17358. // shift adjacent points by unit vectors to the left
  17359. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17360. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17361. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17362. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17363. // scaling factor for v_prev to intersection point
  17364. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17365. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17366. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17367. // vector from inPt to intersection point
  17368. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17369. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17370. // Don't normalize!, otherwise sharp corners become ugly
  17371. // but prevent crazy spikes
  17372. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17373. if ( v_trans_lensq <= 2 ) {
  17374. return new Vector2( v_trans_x, v_trans_y );
  17375. } else {
  17376. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17377. }
  17378. } else {
  17379. // handle special case of collinear edges
  17380. let direction_eq = false; // assumes: opposite
  17381. if ( v_prev_x > Number.EPSILON ) {
  17382. if ( v_next_x > Number.EPSILON ) {
  17383. direction_eq = true;
  17384. }
  17385. } else {
  17386. if ( v_prev_x < - Number.EPSILON ) {
  17387. if ( v_next_x < - Number.EPSILON ) {
  17388. direction_eq = true;
  17389. }
  17390. } else {
  17391. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17392. direction_eq = true;
  17393. }
  17394. }
  17395. }
  17396. if ( direction_eq ) {
  17397. // console.log("Warning: lines are a straight sequence");
  17398. v_trans_x = - v_prev_y;
  17399. v_trans_y = v_prev_x;
  17400. shrink_by = Math.sqrt( v_prev_lensq );
  17401. } else {
  17402. // console.log("Warning: lines are a straight spike");
  17403. v_trans_x = v_prev_x;
  17404. v_trans_y = v_prev_y;
  17405. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17406. }
  17407. }
  17408. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17409. }
  17410. const contourMovements = [];
  17411. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17412. if ( j === il ) j = 0;
  17413. if ( k === il ) k = 0;
  17414. // (j)---(i)---(k)
  17415. // console.log('i,j,k', i, j , k)
  17416. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17417. }
  17418. const holesMovements = [];
  17419. let oneHoleMovements, verticesMovements = contourMovements.concat();
  17420. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17421. const ahole = holes[ h ];
  17422. oneHoleMovements = [];
  17423. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17424. if ( j === il ) j = 0;
  17425. if ( k === il ) k = 0;
  17426. // (j)---(i)---(k)
  17427. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17428. }
  17429. holesMovements.push( oneHoleMovements );
  17430. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17431. }
  17432. // Loop bevelSegments, 1 for the front, 1 for the back
  17433. for ( let b = 0; b < bevelSegments; b ++ ) {
  17434. //for ( b = bevelSegments; b > 0; b -- ) {
  17435. const t = b / bevelSegments;
  17436. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17437. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17438. // contract shape
  17439. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  17440. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17441. v( vert.x, vert.y, - z );
  17442. }
  17443. // expand holes
  17444. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17445. const ahole = holes[ h ];
  17446. oneHoleMovements = holesMovements[ h ];
  17447. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  17448. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17449. v( vert.x, vert.y, - z );
  17450. }
  17451. }
  17452. }
  17453. const bs = bevelSize + bevelOffset;
  17454. // Back facing vertices
  17455. for ( let i = 0; i < vlen; i ++ ) {
  17456. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17457. if ( ! extrudeByPath ) {
  17458. v( vert.x, vert.y, 0 );
  17459. } else {
  17460. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17461. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17462. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17463. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17464. v( position2.x, position2.y, position2.z );
  17465. }
  17466. }
  17467. // Add stepped vertices...
  17468. // Including front facing vertices
  17469. for ( let s = 1; s <= steps; s ++ ) {
  17470. for ( let i = 0; i < vlen; i ++ ) {
  17471. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17472. if ( ! extrudeByPath ) {
  17473. v( vert.x, vert.y, depth / steps * s );
  17474. } else {
  17475. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17476. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17477. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17478. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17479. v( position2.x, position2.y, position2.z );
  17480. }
  17481. }
  17482. }
  17483. // Add bevel segments planes
  17484. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17485. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  17486. const t = b / bevelSegments;
  17487. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17488. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17489. // contract shape
  17490. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  17491. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17492. v( vert.x, vert.y, depth + z );
  17493. }
  17494. // expand holes
  17495. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17496. const ahole = holes[ h ];
  17497. oneHoleMovements = holesMovements[ h ];
  17498. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  17499. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17500. if ( ! extrudeByPath ) {
  17501. v( vert.x, vert.y, depth + z );
  17502. } else {
  17503. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17504. }
  17505. }
  17506. }
  17507. }
  17508. /* Faces */
  17509. // Top and bottom faces
  17510. buildLidFaces();
  17511. // Sides faces
  17512. buildSideFaces();
  17513. ///// Internal functions
  17514. function buildLidFaces() {
  17515. const start = verticesArray.length / 3;
  17516. if ( bevelEnabled ) {
  17517. let layer = 0; // steps + 1
  17518. let offset = vlen * layer;
  17519. // Bottom faces
  17520. for ( let i = 0; i < flen; i ++ ) {
  17521. const face = faces[ i ];
  17522. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17523. }
  17524. layer = steps + bevelSegments * 2;
  17525. offset = vlen * layer;
  17526. // Top faces
  17527. for ( let i = 0; i < flen; i ++ ) {
  17528. const face = faces[ i ];
  17529. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17530. }
  17531. } else {
  17532. // Bottom faces
  17533. for ( let i = 0; i < flen; i ++ ) {
  17534. const face = faces[ i ];
  17535. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17536. }
  17537. // Top faces
  17538. for ( let i = 0; i < flen; i ++ ) {
  17539. const face = faces[ i ];
  17540. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17541. }
  17542. }
  17543. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17544. }
  17545. // Create faces for the z-sides of the shape
  17546. function buildSideFaces() {
  17547. const start = verticesArray.length / 3;
  17548. let layeroffset = 0;
  17549. sidewalls( contour, layeroffset );
  17550. layeroffset += contour.length;
  17551. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17552. const ahole = holes[ h ];
  17553. sidewalls( ahole, layeroffset );
  17554. //, true
  17555. layeroffset += ahole.length;
  17556. }
  17557. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17558. }
  17559. function sidewalls( contour, layeroffset ) {
  17560. let i = contour.length;
  17561. while ( -- i >= 0 ) {
  17562. const j = i;
  17563. let k = i - 1;
  17564. if ( k < 0 ) k = contour.length - 1;
  17565. //console.log('b', i,j, i-1, k,vertices.length);
  17566. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  17567. const slen1 = vlen * s;
  17568. const slen2 = vlen * ( s + 1 );
  17569. const a = layeroffset + j + slen1,
  17570. b = layeroffset + k + slen1,
  17571. c = layeroffset + k + slen2,
  17572. d = layeroffset + j + slen2;
  17573. f4( a, b, c, d );
  17574. }
  17575. }
  17576. }
  17577. function v( x, y, z ) {
  17578. placeholder.push( x );
  17579. placeholder.push( y );
  17580. placeholder.push( z );
  17581. }
  17582. function f3( a, b, c ) {
  17583. addVertex( a );
  17584. addVertex( b );
  17585. addVertex( c );
  17586. const nextIndex = verticesArray.length / 3;
  17587. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17588. addUV( uvs[ 0 ] );
  17589. addUV( uvs[ 1 ] );
  17590. addUV( uvs[ 2 ] );
  17591. }
  17592. function f4( a, b, c, d ) {
  17593. addVertex( a );
  17594. addVertex( b );
  17595. addVertex( d );
  17596. addVertex( b );
  17597. addVertex( c );
  17598. addVertex( d );
  17599. const nextIndex = verticesArray.length / 3;
  17600. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17601. addUV( uvs[ 0 ] );
  17602. addUV( uvs[ 1 ] );
  17603. addUV( uvs[ 3 ] );
  17604. addUV( uvs[ 1 ] );
  17605. addUV( uvs[ 2 ] );
  17606. addUV( uvs[ 3 ] );
  17607. }
  17608. function addVertex( index ) {
  17609. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17610. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17611. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17612. }
  17613. function addUV( vector2 ) {
  17614. uvArray.push( vector2.x );
  17615. uvArray.push( vector2.y );
  17616. }
  17617. }
  17618. }
  17619. toJSON() {
  17620. const data = BufferGeometry.prototype.toJSON.call( this );
  17621. const shapes = this.parameters.shapes;
  17622. const options = this.parameters.options;
  17623. return toJSON( shapes, options, data );
  17624. }
  17625. }
  17626. const WorldUVGenerator = {
  17627. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17628. const a_x = vertices[ indexA * 3 ];
  17629. const a_y = vertices[ indexA * 3 + 1 ];
  17630. const b_x = vertices[ indexB * 3 ];
  17631. const b_y = vertices[ indexB * 3 + 1 ];
  17632. const c_x = vertices[ indexC * 3 ];
  17633. const c_y = vertices[ indexC * 3 + 1 ];
  17634. return [
  17635. new Vector2( a_x, a_y ),
  17636. new Vector2( b_x, b_y ),
  17637. new Vector2( c_x, c_y )
  17638. ];
  17639. },
  17640. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17641. const a_x = vertices[ indexA * 3 ];
  17642. const a_y = vertices[ indexA * 3 + 1 ];
  17643. const a_z = vertices[ indexA * 3 + 2 ];
  17644. const b_x = vertices[ indexB * 3 ];
  17645. const b_y = vertices[ indexB * 3 + 1 ];
  17646. const b_z = vertices[ indexB * 3 + 2 ];
  17647. const c_x = vertices[ indexC * 3 ];
  17648. const c_y = vertices[ indexC * 3 + 1 ];
  17649. const c_z = vertices[ indexC * 3 + 2 ];
  17650. const d_x = vertices[ indexD * 3 ];
  17651. const d_y = vertices[ indexD * 3 + 1 ];
  17652. const d_z = vertices[ indexD * 3 + 2 ];
  17653. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17654. return [
  17655. new Vector2( a_x, 1 - a_z ),
  17656. new Vector2( b_x, 1 - b_z ),
  17657. new Vector2( c_x, 1 - c_z ),
  17658. new Vector2( d_x, 1 - d_z )
  17659. ];
  17660. } else {
  17661. return [
  17662. new Vector2( a_y, 1 - a_z ),
  17663. new Vector2( b_y, 1 - b_z ),
  17664. new Vector2( c_y, 1 - c_z ),
  17665. new Vector2( d_y, 1 - d_z )
  17666. ];
  17667. }
  17668. }
  17669. };
  17670. function toJSON( shapes, options, data ) {
  17671. data.shapes = [];
  17672. if ( Array.isArray( shapes ) ) {
  17673. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  17674. const shape = shapes[ i ];
  17675. data.shapes.push( shape.uuid );
  17676. }
  17677. } else {
  17678. data.shapes.push( shapes.uuid );
  17679. }
  17680. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17681. return data;
  17682. }
  17683. class IcosahedronGeometry extends PolyhedronGeometry {
  17684. constructor( radius = 1, detail = 0 ) {
  17685. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17686. const vertices = [
  17687. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17688. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17689. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17690. ];
  17691. const indices = [
  17692. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17693. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17694. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17695. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17696. ];
  17697. super( vertices, indices, radius, detail );
  17698. this.type = 'IcosahedronGeometry';
  17699. this.parameters = {
  17700. radius: radius,
  17701. detail: detail
  17702. };
  17703. }
  17704. }
  17705. class LatheGeometry extends BufferGeometry {
  17706. constructor( points, segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
  17707. super();
  17708. this.type = 'LatheGeometry';
  17709. this.parameters = {
  17710. points: points,
  17711. segments: segments,
  17712. phiStart: phiStart,
  17713. phiLength: phiLength
  17714. };
  17715. segments = Math.floor( segments );
  17716. // clamp phiLength so it's in range of [ 0, 2PI ]
  17717. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  17718. // buffers
  17719. const indices = [];
  17720. const vertices = [];
  17721. const uvs = [];
  17722. // helper variables
  17723. const inverseSegments = 1.0 / segments;
  17724. const vertex = new Vector3();
  17725. const uv = new Vector2();
  17726. // generate vertices and uvs
  17727. for ( let i = 0; i <= segments; i ++ ) {
  17728. const phi = phiStart + i * inverseSegments * phiLength;
  17729. const sin = Math.sin( phi );
  17730. const cos = Math.cos( phi );
  17731. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  17732. // vertex
  17733. vertex.x = points[ j ].x * sin;
  17734. vertex.y = points[ j ].y;
  17735. vertex.z = points[ j ].x * cos;
  17736. vertices.push( vertex.x, vertex.y, vertex.z );
  17737. // uv
  17738. uv.x = i / segments;
  17739. uv.y = j / ( points.length - 1 );
  17740. uvs.push( uv.x, uv.y );
  17741. }
  17742. }
  17743. // indices
  17744. for ( let i = 0; i < segments; i ++ ) {
  17745. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  17746. const base = j + i * points.length;
  17747. const a = base;
  17748. const b = base + points.length;
  17749. const c = base + points.length + 1;
  17750. const d = base + 1;
  17751. // faces
  17752. indices.push( a, b, d );
  17753. indices.push( b, c, d );
  17754. }
  17755. }
  17756. // build geometry
  17757. this.setIndex( indices );
  17758. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17759. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17760. // generate normals
  17761. this.computeVertexNormals();
  17762. // if the geometry is closed, we need to average the normals along the seam.
  17763. // because the corresponding vertices are identical (but still have different UVs).
  17764. if ( phiLength === Math.PI * 2 ) {
  17765. const normals = this.attributes.normal.array;
  17766. const n1 = new Vector3();
  17767. const n2 = new Vector3();
  17768. const n = new Vector3();
  17769. // this is the buffer offset for the last line of vertices
  17770. const base = segments * points.length * 3;
  17771. for ( let i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  17772. // select the normal of the vertex in the first line
  17773. n1.x = normals[ j + 0 ];
  17774. n1.y = normals[ j + 1 ];
  17775. n1.z = normals[ j + 2 ];
  17776. // select the normal of the vertex in the last line
  17777. n2.x = normals[ base + j + 0 ];
  17778. n2.y = normals[ base + j + 1 ];
  17779. n2.z = normals[ base + j + 2 ];
  17780. // average normals
  17781. n.addVectors( n1, n2 ).normalize();
  17782. // assign the new values to both normals
  17783. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  17784. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  17785. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  17786. }
  17787. }
  17788. }
  17789. }
  17790. class OctahedronGeometry extends PolyhedronGeometry {
  17791. constructor( radius = 1, detail = 0 ) {
  17792. const vertices = [
  17793. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17794. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17795. ];
  17796. const indices = [
  17797. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17798. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17799. 1, 3, 4, 1, 4, 2
  17800. ];
  17801. super( vertices, indices, radius, detail );
  17802. this.type = 'OctahedronGeometry';
  17803. this.parameters = {
  17804. radius: radius,
  17805. detail: detail
  17806. };
  17807. }
  17808. }
  17809. /**
  17810. * Parametric Surfaces Geometry
  17811. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  17812. */
  17813. function ParametricGeometry( func, slices, stacks ) {
  17814. BufferGeometry.call( this );
  17815. this.type = 'ParametricGeometry';
  17816. this.parameters = {
  17817. func: func,
  17818. slices: slices,
  17819. stacks: stacks
  17820. };
  17821. // buffers
  17822. const indices = [];
  17823. const vertices = [];
  17824. const normals = [];
  17825. const uvs = [];
  17826. const EPS = 0.00001;
  17827. const normal = new Vector3();
  17828. const p0 = new Vector3(), p1 = new Vector3();
  17829. const pu = new Vector3(), pv = new Vector3();
  17830. if ( func.length < 3 ) {
  17831. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17832. }
  17833. // generate vertices, normals and uvs
  17834. const sliceCount = slices + 1;
  17835. for ( let i = 0; i <= stacks; i ++ ) {
  17836. const v = i / stacks;
  17837. for ( let j = 0; j <= slices; j ++ ) {
  17838. const u = j / slices;
  17839. // vertex
  17840. func( u, v, p0 );
  17841. vertices.push( p0.x, p0.y, p0.z );
  17842. // normal
  17843. // approximate tangent vectors via finite differences
  17844. if ( u - EPS >= 0 ) {
  17845. func( u - EPS, v, p1 );
  17846. pu.subVectors( p0, p1 );
  17847. } else {
  17848. func( u + EPS, v, p1 );
  17849. pu.subVectors( p1, p0 );
  17850. }
  17851. if ( v - EPS >= 0 ) {
  17852. func( u, v - EPS, p1 );
  17853. pv.subVectors( p0, p1 );
  17854. } else {
  17855. func( u, v + EPS, p1 );
  17856. pv.subVectors( p1, p0 );
  17857. }
  17858. // cross product of tangent vectors returns surface normal
  17859. normal.crossVectors( pu, pv ).normalize();
  17860. normals.push( normal.x, normal.y, normal.z );
  17861. // uv
  17862. uvs.push( u, v );
  17863. }
  17864. }
  17865. // generate indices
  17866. for ( let i = 0; i < stacks; i ++ ) {
  17867. for ( let j = 0; j < slices; j ++ ) {
  17868. const a = i * sliceCount + j;
  17869. const b = i * sliceCount + j + 1;
  17870. const c = ( i + 1 ) * sliceCount + j + 1;
  17871. const d = ( i + 1 ) * sliceCount + j;
  17872. // faces one and two
  17873. indices.push( a, b, d );
  17874. indices.push( b, c, d );
  17875. }
  17876. }
  17877. // build geometry
  17878. this.setIndex( indices );
  17879. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17880. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17881. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17882. }
  17883. ParametricGeometry.prototype = Object.create( BufferGeometry.prototype );
  17884. ParametricGeometry.prototype.constructor = ParametricGeometry;
  17885. class RingGeometry extends BufferGeometry {
  17886. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 8, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17887. super();
  17888. this.type = 'RingGeometry';
  17889. this.parameters = {
  17890. innerRadius: innerRadius,
  17891. outerRadius: outerRadius,
  17892. thetaSegments: thetaSegments,
  17893. phiSegments: phiSegments,
  17894. thetaStart: thetaStart,
  17895. thetaLength: thetaLength
  17896. };
  17897. thetaSegments = Math.max( 3, thetaSegments );
  17898. phiSegments = Math.max( 1, phiSegments );
  17899. // buffers
  17900. const indices = [];
  17901. const vertices = [];
  17902. const normals = [];
  17903. const uvs = [];
  17904. // some helper variables
  17905. let radius = innerRadius;
  17906. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  17907. const vertex = new Vector3();
  17908. const uv = new Vector2();
  17909. // generate vertices, normals and uvs
  17910. for ( let j = 0; j <= phiSegments; j ++ ) {
  17911. for ( let i = 0; i <= thetaSegments; i ++ ) {
  17912. // values are generate from the inside of the ring to the outside
  17913. const segment = thetaStart + i / thetaSegments * thetaLength;
  17914. // vertex
  17915. vertex.x = radius * Math.cos( segment );
  17916. vertex.y = radius * Math.sin( segment );
  17917. vertices.push( vertex.x, vertex.y, vertex.z );
  17918. // normal
  17919. normals.push( 0, 0, 1 );
  17920. // uv
  17921. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  17922. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  17923. uvs.push( uv.x, uv.y );
  17924. }
  17925. // increase the radius for next row of vertices
  17926. radius += radiusStep;
  17927. }
  17928. // indices
  17929. for ( let j = 0; j < phiSegments; j ++ ) {
  17930. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  17931. for ( let i = 0; i < thetaSegments; i ++ ) {
  17932. const segment = i + thetaSegmentLevel;
  17933. const a = segment;
  17934. const b = segment + thetaSegments + 1;
  17935. const c = segment + thetaSegments + 2;
  17936. const d = segment + 1;
  17937. // faces
  17938. indices.push( a, b, d );
  17939. indices.push( b, c, d );
  17940. }
  17941. }
  17942. // build geometry
  17943. this.setIndex( indices );
  17944. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17945. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17946. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17947. }
  17948. }
  17949. class ShapeGeometry extends BufferGeometry {
  17950. constructor( shapes, curveSegments = 12 ) {
  17951. super();
  17952. this.type = 'ShapeGeometry';
  17953. this.parameters = {
  17954. shapes: shapes,
  17955. curveSegments: curveSegments
  17956. };
  17957. // buffers
  17958. const indices = [];
  17959. const vertices = [];
  17960. const normals = [];
  17961. const uvs = [];
  17962. // helper variables
  17963. let groupStart = 0;
  17964. let groupCount = 0;
  17965. // allow single and array values for "shapes" parameter
  17966. if ( Array.isArray( shapes ) === false ) {
  17967. addShape( shapes );
  17968. } else {
  17969. for ( let i = 0; i < shapes.length; i ++ ) {
  17970. addShape( shapes[ i ] );
  17971. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  17972. groupStart += groupCount;
  17973. groupCount = 0;
  17974. }
  17975. }
  17976. // build geometry
  17977. this.setIndex( indices );
  17978. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17979. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17980. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17981. // helper functions
  17982. function addShape( shape ) {
  17983. const indexOffset = vertices.length / 3;
  17984. const points = shape.extractPoints( curveSegments );
  17985. let shapeVertices = points.shape;
  17986. const shapeHoles = points.holes;
  17987. // check direction of vertices
  17988. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  17989. shapeVertices = shapeVertices.reverse();
  17990. }
  17991. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  17992. const shapeHole = shapeHoles[ i ];
  17993. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  17994. shapeHoles[ i ] = shapeHole.reverse();
  17995. }
  17996. }
  17997. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  17998. // join vertices of inner and outer paths to a single array
  17999. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18000. const shapeHole = shapeHoles[ i ];
  18001. shapeVertices = shapeVertices.concat( shapeHole );
  18002. }
  18003. // vertices, normals, uvs
  18004. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18005. const vertex = shapeVertices[ i ];
  18006. vertices.push( vertex.x, vertex.y, 0 );
  18007. normals.push( 0, 0, 1 );
  18008. uvs.push( vertex.x, vertex.y ); // world uvs
  18009. }
  18010. // incides
  18011. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  18012. const face = faces[ i ];
  18013. const a = face[ 0 ] + indexOffset;
  18014. const b = face[ 1 ] + indexOffset;
  18015. const c = face[ 2 ] + indexOffset;
  18016. indices.push( a, b, c );
  18017. groupCount += 3;
  18018. }
  18019. }
  18020. }
  18021. toJSON() {
  18022. const data = BufferGeometry.prototype.toJSON.call( this );
  18023. const shapes = this.parameters.shapes;
  18024. return toJSON$1( shapes, data );
  18025. }
  18026. }
  18027. function toJSON$1( shapes, data ) {
  18028. data.shapes = [];
  18029. if ( Array.isArray( shapes ) ) {
  18030. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18031. const shape = shapes[ i ];
  18032. data.shapes.push( shape.uuid );
  18033. }
  18034. } else {
  18035. data.shapes.push( shapes.uuid );
  18036. }
  18037. return data;
  18038. }
  18039. class SphereGeometry extends BufferGeometry {
  18040. constructor( radius = 1, widthSegments = 8, heightSegments = 6, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  18041. super();
  18042. this.type = 'SphereGeometry';
  18043. this.parameters = {
  18044. radius: radius,
  18045. widthSegments: widthSegments,
  18046. heightSegments: heightSegments,
  18047. phiStart: phiStart,
  18048. phiLength: phiLength,
  18049. thetaStart: thetaStart,
  18050. thetaLength: thetaLength
  18051. };
  18052. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  18053. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  18054. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18055. let index = 0;
  18056. const grid = [];
  18057. const vertex = new Vector3();
  18058. const normal = new Vector3();
  18059. // buffers
  18060. const indices = [];
  18061. const vertices = [];
  18062. const normals = [];
  18063. const uvs = [];
  18064. // generate vertices, normals and uvs
  18065. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  18066. const verticesRow = [];
  18067. const v = iy / heightSegments;
  18068. // special case for the poles
  18069. let uOffset = 0;
  18070. if ( iy == 0 && thetaStart == 0 ) {
  18071. uOffset = 0.5 / widthSegments;
  18072. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18073. uOffset = - 0.5 / widthSegments;
  18074. }
  18075. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  18076. const u = ix / widthSegments;
  18077. // vertex
  18078. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18079. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18080. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18081. vertices.push( vertex.x, vertex.y, vertex.z );
  18082. // normal
  18083. normal.copy( vertex ).normalize();
  18084. normals.push( normal.x, normal.y, normal.z );
  18085. // uv
  18086. uvs.push( u + uOffset, 1 - v );
  18087. verticesRow.push( index ++ );
  18088. }
  18089. grid.push( verticesRow );
  18090. }
  18091. // indices
  18092. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  18093. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  18094. const a = grid[ iy ][ ix + 1 ];
  18095. const b = grid[ iy ][ ix ];
  18096. const c = grid[ iy + 1 ][ ix ];
  18097. const d = grid[ iy + 1 ][ ix + 1 ];
  18098. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18099. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18100. }
  18101. }
  18102. // build geometry
  18103. this.setIndex( indices );
  18104. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18105. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18106. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18107. }
  18108. }
  18109. class TetrahedronGeometry extends PolyhedronGeometry {
  18110. constructor( radius = 1, detail = 0 ) {
  18111. const vertices = [
  18112. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  18113. ];
  18114. const indices = [
  18115. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  18116. ];
  18117. super( vertices, indices, radius, detail );
  18118. this.type = 'TetrahedronGeometry';
  18119. this.parameters = {
  18120. radius: radius,
  18121. detail: detail
  18122. };
  18123. }
  18124. }
  18125. /**
  18126. * Text = 3D Text
  18127. *
  18128. * parameters = {
  18129. * font: <THREE.Font>, // font
  18130. *
  18131. * size: <float>, // size of the text
  18132. * height: <float>, // thickness to extrude text
  18133. * curveSegments: <int>, // number of points on the curves
  18134. *
  18135. * bevelEnabled: <bool>, // turn on bevel
  18136. * bevelThickness: <float>, // how deep into text bevel goes
  18137. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18138. * bevelOffset: <float> // how far from text outline does bevel start
  18139. * }
  18140. */
  18141. class TextGeometry extends ExtrudeGeometry {
  18142. constructor( text, parameters = {} ) {
  18143. const font = parameters.font;
  18144. if ( ! ( font && font.isFont ) ) {
  18145. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18146. return new BufferGeometry();
  18147. }
  18148. const shapes = font.generateShapes( text, parameters.size );
  18149. // translate parameters to ExtrudeGeometry API
  18150. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18151. // defaults
  18152. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18153. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18154. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18155. super( shapes, parameters );
  18156. this.type = 'TextGeometry';
  18157. }
  18158. }
  18159. class TorusGeometry extends BufferGeometry {
  18160. constructor( radius = 1, tube = 0.4, radialSegments = 8, tubularSegments = 6, arc = Math.PI * 2 ) {
  18161. super();
  18162. this.type = 'TorusGeometry';
  18163. this.parameters = {
  18164. radius: radius,
  18165. tube: tube,
  18166. radialSegments: radialSegments,
  18167. tubularSegments: tubularSegments,
  18168. arc: arc
  18169. };
  18170. radialSegments = Math.floor( radialSegments );
  18171. tubularSegments = Math.floor( tubularSegments );
  18172. // buffers
  18173. const indices = [];
  18174. const vertices = [];
  18175. const normals = [];
  18176. const uvs = [];
  18177. // helper variables
  18178. const center = new Vector3();
  18179. const vertex = new Vector3();
  18180. const normal = new Vector3();
  18181. // generate vertices, normals and uvs
  18182. for ( let j = 0; j <= radialSegments; j ++ ) {
  18183. for ( let i = 0; i <= tubularSegments; i ++ ) {
  18184. const u = i / tubularSegments * arc;
  18185. const v = j / radialSegments * Math.PI * 2;
  18186. // vertex
  18187. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  18188. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  18189. vertex.z = tube * Math.sin( v );
  18190. vertices.push( vertex.x, vertex.y, vertex.z );
  18191. // normal
  18192. center.x = radius * Math.cos( u );
  18193. center.y = radius * Math.sin( u );
  18194. normal.subVectors( vertex, center ).normalize();
  18195. normals.push( normal.x, normal.y, normal.z );
  18196. // uv
  18197. uvs.push( i / tubularSegments );
  18198. uvs.push( j / radialSegments );
  18199. }
  18200. }
  18201. // generate indices
  18202. for ( let j = 1; j <= radialSegments; j ++ ) {
  18203. for ( let i = 1; i <= tubularSegments; i ++ ) {
  18204. // indices
  18205. const a = ( tubularSegments + 1 ) * j + i - 1;
  18206. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  18207. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  18208. const d = ( tubularSegments + 1 ) * j + i;
  18209. // faces
  18210. indices.push( a, b, d );
  18211. indices.push( b, c, d );
  18212. }
  18213. }
  18214. // build geometry
  18215. this.setIndex( indices );
  18216. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18217. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18218. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18219. }
  18220. }
  18221. class TorusKnotGeometry extends BufferGeometry {
  18222. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  18223. super();
  18224. this.type = 'TorusKnotGeometry';
  18225. this.parameters = {
  18226. radius: radius,
  18227. tube: tube,
  18228. tubularSegments: tubularSegments,
  18229. radialSegments: radialSegments,
  18230. p: p,
  18231. q: q
  18232. };
  18233. tubularSegments = Math.floor( tubularSegments );
  18234. radialSegments = Math.floor( radialSegments );
  18235. // buffers
  18236. const indices = [];
  18237. const vertices = [];
  18238. const normals = [];
  18239. const uvs = [];
  18240. // helper variables
  18241. const vertex = new Vector3();
  18242. const normal = new Vector3();
  18243. const P1 = new Vector3();
  18244. const P2 = new Vector3();
  18245. const B = new Vector3();
  18246. const T = new Vector3();
  18247. const N = new Vector3();
  18248. // generate vertices, normals and uvs
  18249. for ( let i = 0; i <= tubularSegments; ++ i ) {
  18250. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  18251. const u = i / tubularSegments * p * Math.PI * 2;
  18252. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  18253. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  18254. calculatePositionOnCurve( u, p, q, radius, P1 );
  18255. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  18256. // calculate orthonormal basis
  18257. T.subVectors( P2, P1 );
  18258. N.addVectors( P2, P1 );
  18259. B.crossVectors( T, N );
  18260. N.crossVectors( B, T );
  18261. // normalize B, N. T can be ignored, we don't use it
  18262. B.normalize();
  18263. N.normalize();
  18264. for ( let j = 0; j <= radialSegments; ++ j ) {
  18265. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  18266. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  18267. const v = j / radialSegments * Math.PI * 2;
  18268. const cx = - tube * Math.cos( v );
  18269. const cy = tube * Math.sin( v );
  18270. // now calculate the final vertex position.
  18271. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  18272. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  18273. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  18274. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  18275. vertices.push( vertex.x, vertex.y, vertex.z );
  18276. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  18277. normal.subVectors( vertex, P1 ).normalize();
  18278. normals.push( normal.x, normal.y, normal.z );
  18279. // uv
  18280. uvs.push( i / tubularSegments );
  18281. uvs.push( j / radialSegments );
  18282. }
  18283. }
  18284. // generate indices
  18285. for ( let j = 1; j <= tubularSegments; j ++ ) {
  18286. for ( let i = 1; i <= radialSegments; i ++ ) {
  18287. // indices
  18288. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  18289. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  18290. const c = ( radialSegments + 1 ) * j + i;
  18291. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  18292. // faces
  18293. indices.push( a, b, d );
  18294. indices.push( b, c, d );
  18295. }
  18296. }
  18297. // build geometry
  18298. this.setIndex( indices );
  18299. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18300. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18301. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18302. // this function calculates the current position on the torus curve
  18303. function calculatePositionOnCurve( u, p, q, radius, position ) {
  18304. const cu = Math.cos( u );
  18305. const su = Math.sin( u );
  18306. const quOverP = q / p * u;
  18307. const cs = Math.cos( quOverP );
  18308. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  18309. position.y = radius * ( 2 + cs ) * su * 0.5;
  18310. position.z = radius * Math.sin( quOverP ) * 0.5;
  18311. }
  18312. }
  18313. }
  18314. class TubeGeometry extends BufferGeometry {
  18315. constructor( path, tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  18316. super();
  18317. this.type = 'TubeGeometry';
  18318. this.parameters = {
  18319. path: path,
  18320. tubularSegments: tubularSegments,
  18321. radius: radius,
  18322. radialSegments: radialSegments,
  18323. closed: closed
  18324. };
  18325. const frames = path.computeFrenetFrames( tubularSegments, closed );
  18326. // expose internals
  18327. this.tangents = frames.tangents;
  18328. this.normals = frames.normals;
  18329. this.binormals = frames.binormals;
  18330. // helper variables
  18331. const vertex = new Vector3();
  18332. const normal = new Vector3();
  18333. const uv = new Vector2();
  18334. let P = new Vector3();
  18335. // buffer
  18336. const vertices = [];
  18337. const normals = [];
  18338. const uvs = [];
  18339. const indices = [];
  18340. // create buffer data
  18341. generateBufferData();
  18342. // build geometry
  18343. this.setIndex( indices );
  18344. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18345. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18346. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18347. // functions
  18348. function generateBufferData() {
  18349. for ( let i = 0; i < tubularSegments; i ++ ) {
  18350. generateSegment( i );
  18351. }
  18352. // if the geometry is not closed, generate the last row of vertices and normals
  18353. // at the regular position on the given path
  18354. //
  18355. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  18356. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  18357. // uvs are generated in a separate function.
  18358. // this makes it easy compute correct values for closed geometries
  18359. generateUVs();
  18360. // finally create faces
  18361. generateIndices();
  18362. }
  18363. function generateSegment( i ) {
  18364. // we use getPointAt to sample evenly distributed points from the given path
  18365. P = path.getPointAt( i / tubularSegments, P );
  18366. // retrieve corresponding normal and binormal
  18367. const N = frames.normals[ i ];
  18368. const B = frames.binormals[ i ];
  18369. // generate normals and vertices for the current segment
  18370. for ( let j = 0; j <= radialSegments; j ++ ) {
  18371. const v = j / radialSegments * Math.PI * 2;
  18372. const sin = Math.sin( v );
  18373. const cos = - Math.cos( v );
  18374. // normal
  18375. normal.x = ( cos * N.x + sin * B.x );
  18376. normal.y = ( cos * N.y + sin * B.y );
  18377. normal.z = ( cos * N.z + sin * B.z );
  18378. normal.normalize();
  18379. normals.push( normal.x, normal.y, normal.z );
  18380. // vertex
  18381. vertex.x = P.x + radius * normal.x;
  18382. vertex.y = P.y + radius * normal.y;
  18383. vertex.z = P.z + radius * normal.z;
  18384. vertices.push( vertex.x, vertex.y, vertex.z );
  18385. }
  18386. }
  18387. function generateIndices() {
  18388. for ( let j = 1; j <= tubularSegments; j ++ ) {
  18389. for ( let i = 1; i <= radialSegments; i ++ ) {
  18390. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  18391. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  18392. const c = ( radialSegments + 1 ) * j + i;
  18393. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  18394. // faces
  18395. indices.push( a, b, d );
  18396. indices.push( b, c, d );
  18397. }
  18398. }
  18399. }
  18400. function generateUVs() {
  18401. for ( let i = 0; i <= tubularSegments; i ++ ) {
  18402. for ( let j = 0; j <= radialSegments; j ++ ) {
  18403. uv.x = i / tubularSegments;
  18404. uv.y = j / radialSegments;
  18405. uvs.push( uv.x, uv.y );
  18406. }
  18407. }
  18408. }
  18409. }
  18410. toJSON() {
  18411. const data = BufferGeometry.prototype.toJSON.call( this );
  18412. data.path = this.parameters.path.toJSON();
  18413. return data;
  18414. }
  18415. }
  18416. class WireframeGeometry extends BufferGeometry {
  18417. constructor( geometry ) {
  18418. super();
  18419. this.type = 'WireframeGeometry';
  18420. if ( geometry.isGeometry === true ) {
  18421. console.error( 'THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  18422. return;
  18423. }
  18424. // buffer
  18425. const vertices = [];
  18426. // helper variables
  18427. const edge = [ 0, 0 ], edges = {};
  18428. const vertex = new Vector3();
  18429. if ( geometry.index !== null ) {
  18430. // indexed BufferGeometry
  18431. const position = geometry.attributes.position;
  18432. const indices = geometry.index;
  18433. let groups = geometry.groups;
  18434. if ( groups.length === 0 ) {
  18435. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  18436. }
  18437. // create a data structure that contains all eges without duplicates
  18438. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  18439. const group = groups[ o ];
  18440. const start = group.start;
  18441. const count = group.count;
  18442. for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
  18443. for ( let j = 0; j < 3; j ++ ) {
  18444. const edge1 = indices.getX( i + j );
  18445. const edge2 = indices.getX( i + ( j + 1 ) % 3 );
  18446. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  18447. edge[ 1 ] = Math.max( edge1, edge2 );
  18448. const key = edge[ 0 ] + ',' + edge[ 1 ];
  18449. if ( edges[ key ] === undefined ) {
  18450. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  18451. }
  18452. }
  18453. }
  18454. }
  18455. // generate vertices
  18456. for ( const key in edges ) {
  18457. const e = edges[ key ];
  18458. vertex.fromBufferAttribute( position, e.index1 );
  18459. vertices.push( vertex.x, vertex.y, vertex.z );
  18460. vertex.fromBufferAttribute( position, e.index2 );
  18461. vertices.push( vertex.x, vertex.y, vertex.z );
  18462. }
  18463. } else {
  18464. // non-indexed BufferGeometry
  18465. const position = geometry.attributes.position;
  18466. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  18467. for ( let j = 0; j < 3; j ++ ) {
  18468. // three edges per triangle, an edge is represented as (index1, index2)
  18469. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  18470. const index1 = 3 * i + j;
  18471. vertex.fromBufferAttribute( position, index1 );
  18472. vertices.push( vertex.x, vertex.y, vertex.z );
  18473. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  18474. vertex.fromBufferAttribute( position, index2 );
  18475. vertices.push( vertex.x, vertex.y, vertex.z );
  18476. }
  18477. }
  18478. }
  18479. // build geometry
  18480. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18481. }
  18482. }
  18483. var Geometries = /*#__PURE__*/Object.freeze({
  18484. __proto__: null,
  18485. BoxGeometry: BoxGeometry,
  18486. BoxBufferGeometry: BoxGeometry,
  18487. CircleGeometry: CircleGeometry,
  18488. CircleBufferGeometry: CircleGeometry,
  18489. ConeGeometry: ConeGeometry,
  18490. ConeBufferGeometry: ConeGeometry,
  18491. CylinderGeometry: CylinderGeometry,
  18492. CylinderBufferGeometry: CylinderGeometry,
  18493. DodecahedronGeometry: DodecahedronGeometry,
  18494. DodecahedronBufferGeometry: DodecahedronGeometry,
  18495. EdgesGeometry: EdgesGeometry,
  18496. ExtrudeGeometry: ExtrudeGeometry,
  18497. ExtrudeBufferGeometry: ExtrudeGeometry,
  18498. IcosahedronGeometry: IcosahedronGeometry,
  18499. IcosahedronBufferGeometry: IcosahedronGeometry,
  18500. LatheGeometry: LatheGeometry,
  18501. LatheBufferGeometry: LatheGeometry,
  18502. OctahedronGeometry: OctahedronGeometry,
  18503. OctahedronBufferGeometry: OctahedronGeometry,
  18504. ParametricGeometry: ParametricGeometry,
  18505. ParametricBufferGeometry: ParametricGeometry,
  18506. PlaneGeometry: PlaneGeometry,
  18507. PlaneBufferGeometry: PlaneGeometry,
  18508. PolyhedronGeometry: PolyhedronGeometry,
  18509. PolyhedronBufferGeometry: PolyhedronGeometry,
  18510. RingGeometry: RingGeometry,
  18511. RingBufferGeometry: RingGeometry,
  18512. ShapeGeometry: ShapeGeometry,
  18513. ShapeBufferGeometry: ShapeGeometry,
  18514. SphereGeometry: SphereGeometry,
  18515. SphereBufferGeometry: SphereGeometry,
  18516. TetrahedronGeometry: TetrahedronGeometry,
  18517. TetrahedronBufferGeometry: TetrahedronGeometry,
  18518. TextGeometry: TextGeometry,
  18519. TextBufferGeometry: TextGeometry,
  18520. TorusGeometry: TorusGeometry,
  18521. TorusBufferGeometry: TorusGeometry,
  18522. TorusKnotGeometry: TorusKnotGeometry,
  18523. TorusKnotBufferGeometry: TorusKnotGeometry,
  18524. TubeGeometry: TubeGeometry,
  18525. TubeBufferGeometry: TubeGeometry,
  18526. WireframeGeometry: WireframeGeometry
  18527. });
  18528. /**
  18529. * parameters = {
  18530. * color: <THREE.Color>
  18531. * }
  18532. */
  18533. class ShadowMaterial extends Material {
  18534. constructor( parameters ) {
  18535. super();
  18536. this.type = 'ShadowMaterial';
  18537. this.color = new Color( 0x000000 );
  18538. this.transparent = true;
  18539. this.setValues( parameters );
  18540. }
  18541. copy( source ) {
  18542. super.copy( source );
  18543. this.color.copy( source.color );
  18544. return this;
  18545. }
  18546. }
  18547. ShadowMaterial.prototype.isShadowMaterial = true;
  18548. class RawShaderMaterial extends ShaderMaterial {
  18549. constructor( parameters ) {
  18550. super( parameters );
  18551. this.type = 'RawShaderMaterial';
  18552. }
  18553. }
  18554. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18555. /**
  18556. * parameters = {
  18557. * color: <hex>,
  18558. * roughness: <float>,
  18559. * metalness: <float>,
  18560. * opacity: <float>,
  18561. *
  18562. * map: new THREE.Texture( <Image> ),
  18563. *
  18564. * lightMap: new THREE.Texture( <Image> ),
  18565. * lightMapIntensity: <float>
  18566. *
  18567. * aoMap: new THREE.Texture( <Image> ),
  18568. * aoMapIntensity: <float>
  18569. *
  18570. * emissive: <hex>,
  18571. * emissiveIntensity: <float>
  18572. * emissiveMap: new THREE.Texture( <Image> ),
  18573. *
  18574. * bumpMap: new THREE.Texture( <Image> ),
  18575. * bumpScale: <float>,
  18576. *
  18577. * normalMap: new THREE.Texture( <Image> ),
  18578. * normalMapType: THREE.TangentSpaceNormalMap,
  18579. * normalScale: <Vector2>,
  18580. *
  18581. * displacementMap: new THREE.Texture( <Image> ),
  18582. * displacementScale: <float>,
  18583. * displacementBias: <float>,
  18584. *
  18585. * roughnessMap: new THREE.Texture( <Image> ),
  18586. *
  18587. * metalnessMap: new THREE.Texture( <Image> ),
  18588. *
  18589. * alphaMap: new THREE.Texture( <Image> ),
  18590. *
  18591. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18592. * envMapIntensity: <float>
  18593. *
  18594. * refractionRatio: <float>,
  18595. *
  18596. * wireframe: <boolean>,
  18597. * wireframeLinewidth: <float>,
  18598. *
  18599. * skinning: <bool>,
  18600. * morphTargets: <bool>,
  18601. * morphNormals: <bool>,
  18602. *
  18603. * flatShading: <bool>
  18604. * }
  18605. */
  18606. function MeshStandardMaterial( parameters ) {
  18607. Material.call( this );
  18608. this.defines = { 'STANDARD': '' };
  18609. this.type = 'MeshStandardMaterial';
  18610. this.color = new Color( 0xffffff ); // diffuse
  18611. this.roughness = 1.0;
  18612. this.metalness = 0.0;
  18613. this.map = null;
  18614. this.lightMap = null;
  18615. this.lightMapIntensity = 1.0;
  18616. this.aoMap = null;
  18617. this.aoMapIntensity = 1.0;
  18618. this.emissive = new Color( 0x000000 );
  18619. this.emissiveIntensity = 1.0;
  18620. this.emissiveMap = null;
  18621. this.bumpMap = null;
  18622. this.bumpScale = 1;
  18623. this.normalMap = null;
  18624. this.normalMapType = TangentSpaceNormalMap;
  18625. this.normalScale = new Vector2( 1, 1 );
  18626. this.displacementMap = null;
  18627. this.displacementScale = 1;
  18628. this.displacementBias = 0;
  18629. this.roughnessMap = null;
  18630. this.metalnessMap = null;
  18631. this.alphaMap = null;
  18632. this.envMap = null;
  18633. this.envMapIntensity = 1.0;
  18634. this.refractionRatio = 0.98;
  18635. this.wireframe = false;
  18636. this.wireframeLinewidth = 1;
  18637. this.wireframeLinecap = 'round';
  18638. this.wireframeLinejoin = 'round';
  18639. this.skinning = false;
  18640. this.morphTargets = false;
  18641. this.morphNormals = false;
  18642. this.flatShading = false;
  18643. this.vertexTangents = false;
  18644. this.setValues( parameters );
  18645. }
  18646. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18647. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18648. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18649. MeshStandardMaterial.prototype.copy = function ( source ) {
  18650. Material.prototype.copy.call( this, source );
  18651. this.defines = { 'STANDARD': '' };
  18652. this.color.copy( source.color );
  18653. this.roughness = source.roughness;
  18654. this.metalness = source.metalness;
  18655. this.map = source.map;
  18656. this.lightMap = source.lightMap;
  18657. this.lightMapIntensity = source.lightMapIntensity;
  18658. this.aoMap = source.aoMap;
  18659. this.aoMapIntensity = source.aoMapIntensity;
  18660. this.emissive.copy( source.emissive );
  18661. this.emissiveMap = source.emissiveMap;
  18662. this.emissiveIntensity = source.emissiveIntensity;
  18663. this.bumpMap = source.bumpMap;
  18664. this.bumpScale = source.bumpScale;
  18665. this.normalMap = source.normalMap;
  18666. this.normalMapType = source.normalMapType;
  18667. this.normalScale.copy( source.normalScale );
  18668. this.displacementMap = source.displacementMap;
  18669. this.displacementScale = source.displacementScale;
  18670. this.displacementBias = source.displacementBias;
  18671. this.roughnessMap = source.roughnessMap;
  18672. this.metalnessMap = source.metalnessMap;
  18673. this.alphaMap = source.alphaMap;
  18674. this.envMap = source.envMap;
  18675. this.envMapIntensity = source.envMapIntensity;
  18676. this.refractionRatio = source.refractionRatio;
  18677. this.wireframe = source.wireframe;
  18678. this.wireframeLinewidth = source.wireframeLinewidth;
  18679. this.wireframeLinecap = source.wireframeLinecap;
  18680. this.wireframeLinejoin = source.wireframeLinejoin;
  18681. this.skinning = source.skinning;
  18682. this.morphTargets = source.morphTargets;
  18683. this.morphNormals = source.morphNormals;
  18684. this.flatShading = source.flatShading;
  18685. this.vertexTangents = source.vertexTangents;
  18686. return this;
  18687. };
  18688. /**
  18689. * parameters = {
  18690. * clearcoat: <float>,
  18691. * clearcoatMap: new THREE.Texture( <Image> ),
  18692. * clearcoatRoughness: <float>,
  18693. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  18694. * clearcoatNormalScale: <Vector2>,
  18695. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  18696. *
  18697. * reflectivity: <float>,
  18698. * ior: <float>,
  18699. *
  18700. * sheen: <Color>,
  18701. *
  18702. * transmission: <float>,
  18703. * transmissionMap: new THREE.Texture( <Image> )
  18704. * }
  18705. */
  18706. function MeshPhysicalMaterial( parameters ) {
  18707. MeshStandardMaterial.call( this );
  18708. this.defines = {
  18709. 'STANDARD': '',
  18710. 'PHYSICAL': ''
  18711. };
  18712. this.type = 'MeshPhysicalMaterial';
  18713. this.clearcoat = 0.0;
  18714. this.clearcoatMap = null;
  18715. this.clearcoatRoughness = 0.0;
  18716. this.clearcoatRoughnessMap = null;
  18717. this.clearcoatNormalScale = new Vector2( 1, 1 );
  18718. this.clearcoatNormalMap = null;
  18719. this.reflectivity = 0.5; // maps to F0 = 0.04
  18720. Object.defineProperty( this, 'ior', {
  18721. get: function () {
  18722. return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity );
  18723. },
  18724. set: function ( ior ) {
  18725. this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 );
  18726. }
  18727. } );
  18728. this.sheen = null; // null will disable sheen bsdf
  18729. this.transmission = 0.0;
  18730. this.transmissionMap = null;
  18731. this.setValues( parameters );
  18732. }
  18733. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18734. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18735. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18736. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18737. MeshStandardMaterial.prototype.copy.call( this, source );
  18738. this.defines = {
  18739. 'STANDARD': '',
  18740. 'PHYSICAL': ''
  18741. };
  18742. this.clearcoat = source.clearcoat;
  18743. this.clearcoatMap = source.clearcoatMap;
  18744. this.clearcoatRoughness = source.clearcoatRoughness;
  18745. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  18746. this.clearcoatNormalMap = source.clearcoatNormalMap;
  18747. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  18748. this.reflectivity = source.reflectivity;
  18749. if ( source.sheen ) {
  18750. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  18751. } else {
  18752. this.sheen = null;
  18753. }
  18754. this.transmission = source.transmission;
  18755. this.transmissionMap = source.transmissionMap;
  18756. return this;
  18757. };
  18758. /**
  18759. * parameters = {
  18760. * color: <hex>,
  18761. * specular: <hex>,
  18762. * shininess: <float>,
  18763. * opacity: <float>,
  18764. *
  18765. * map: new THREE.Texture( <Image> ),
  18766. *
  18767. * lightMap: new THREE.Texture( <Image> ),
  18768. * lightMapIntensity: <float>
  18769. *
  18770. * aoMap: new THREE.Texture( <Image> ),
  18771. * aoMapIntensity: <float>
  18772. *
  18773. * emissive: <hex>,
  18774. * emissiveIntensity: <float>
  18775. * emissiveMap: new THREE.Texture( <Image> ),
  18776. *
  18777. * bumpMap: new THREE.Texture( <Image> ),
  18778. * bumpScale: <float>,
  18779. *
  18780. * normalMap: new THREE.Texture( <Image> ),
  18781. * normalMapType: THREE.TangentSpaceNormalMap,
  18782. * normalScale: <Vector2>,
  18783. *
  18784. * displacementMap: new THREE.Texture( <Image> ),
  18785. * displacementScale: <float>,
  18786. * displacementBias: <float>,
  18787. *
  18788. * specularMap: new THREE.Texture( <Image> ),
  18789. *
  18790. * alphaMap: new THREE.Texture( <Image> ),
  18791. *
  18792. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18793. * combine: THREE.MultiplyOperation,
  18794. * reflectivity: <float>,
  18795. * refractionRatio: <float>,
  18796. *
  18797. * wireframe: <boolean>,
  18798. * wireframeLinewidth: <float>,
  18799. *
  18800. * skinning: <bool>,
  18801. * morphTargets: <bool>,
  18802. * morphNormals: <bool>,
  18803. *
  18804. * flatShading: <bool>
  18805. * }
  18806. */
  18807. class MeshPhongMaterial extends Material {
  18808. constructor( parameters ) {
  18809. super();
  18810. this.type = 'MeshPhongMaterial';
  18811. this.color = new Color( 0xffffff ); // diffuse
  18812. this.specular = new Color( 0x111111 );
  18813. this.shininess = 30;
  18814. this.map = null;
  18815. this.lightMap = null;
  18816. this.lightMapIntensity = 1.0;
  18817. this.aoMap = null;
  18818. this.aoMapIntensity = 1.0;
  18819. this.emissive = new Color( 0x000000 );
  18820. this.emissiveIntensity = 1.0;
  18821. this.emissiveMap = null;
  18822. this.bumpMap = null;
  18823. this.bumpScale = 1;
  18824. this.normalMap = null;
  18825. this.normalMapType = TangentSpaceNormalMap;
  18826. this.normalScale = new Vector2( 1, 1 );
  18827. this.displacementMap = null;
  18828. this.displacementScale = 1;
  18829. this.displacementBias = 0;
  18830. this.specularMap = null;
  18831. this.alphaMap = null;
  18832. this.envMap = null;
  18833. this.combine = MultiplyOperation;
  18834. this.reflectivity = 1;
  18835. this.refractionRatio = 0.98;
  18836. this.wireframe = false;
  18837. this.wireframeLinewidth = 1;
  18838. this.wireframeLinecap = 'round';
  18839. this.wireframeLinejoin = 'round';
  18840. this.skinning = false;
  18841. this.morphTargets = false;
  18842. this.morphNormals = false;
  18843. this.flatShading = false;
  18844. this.setValues( parameters );
  18845. }
  18846. copy( source ) {
  18847. super.copy( source );
  18848. this.color.copy( source.color );
  18849. this.specular.copy( source.specular );
  18850. this.shininess = source.shininess;
  18851. this.map = source.map;
  18852. this.lightMap = source.lightMap;
  18853. this.lightMapIntensity = source.lightMapIntensity;
  18854. this.aoMap = source.aoMap;
  18855. this.aoMapIntensity = source.aoMapIntensity;
  18856. this.emissive.copy( source.emissive );
  18857. this.emissiveMap = source.emissiveMap;
  18858. this.emissiveIntensity = source.emissiveIntensity;
  18859. this.bumpMap = source.bumpMap;
  18860. this.bumpScale = source.bumpScale;
  18861. this.normalMap = source.normalMap;
  18862. this.normalMapType = source.normalMapType;
  18863. this.normalScale.copy( source.normalScale );
  18864. this.displacementMap = source.displacementMap;
  18865. this.displacementScale = source.displacementScale;
  18866. this.displacementBias = source.displacementBias;
  18867. this.specularMap = source.specularMap;
  18868. this.alphaMap = source.alphaMap;
  18869. this.envMap = source.envMap;
  18870. this.combine = source.combine;
  18871. this.reflectivity = source.reflectivity;
  18872. this.refractionRatio = source.refractionRatio;
  18873. this.wireframe = source.wireframe;
  18874. this.wireframeLinewidth = source.wireframeLinewidth;
  18875. this.wireframeLinecap = source.wireframeLinecap;
  18876. this.wireframeLinejoin = source.wireframeLinejoin;
  18877. this.skinning = source.skinning;
  18878. this.morphTargets = source.morphTargets;
  18879. this.morphNormals = source.morphNormals;
  18880. this.flatShading = source.flatShading;
  18881. return this;
  18882. }
  18883. }
  18884. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18885. /**
  18886. * parameters = {
  18887. * color: <hex>,
  18888. *
  18889. * map: new THREE.Texture( <Image> ),
  18890. * gradientMap: new THREE.Texture( <Image> ),
  18891. *
  18892. * lightMap: new THREE.Texture( <Image> ),
  18893. * lightMapIntensity: <float>
  18894. *
  18895. * aoMap: new THREE.Texture( <Image> ),
  18896. * aoMapIntensity: <float>
  18897. *
  18898. * emissive: <hex>,
  18899. * emissiveIntensity: <float>
  18900. * emissiveMap: new THREE.Texture( <Image> ),
  18901. *
  18902. * bumpMap: new THREE.Texture( <Image> ),
  18903. * bumpScale: <float>,
  18904. *
  18905. * normalMap: new THREE.Texture( <Image> ),
  18906. * normalMapType: THREE.TangentSpaceNormalMap,
  18907. * normalScale: <Vector2>,
  18908. *
  18909. * displacementMap: new THREE.Texture( <Image> ),
  18910. * displacementScale: <float>,
  18911. * displacementBias: <float>,
  18912. *
  18913. * alphaMap: new THREE.Texture( <Image> ),
  18914. *
  18915. * wireframe: <boolean>,
  18916. * wireframeLinewidth: <float>,
  18917. *
  18918. * skinning: <bool>,
  18919. * morphTargets: <bool>,
  18920. * morphNormals: <bool>
  18921. * }
  18922. */
  18923. class MeshToonMaterial extends Material {
  18924. constructor( parameters ) {
  18925. super();
  18926. this.defines = { 'TOON': '' };
  18927. this.type = 'MeshToonMaterial';
  18928. this.color = new Color( 0xffffff );
  18929. this.map = null;
  18930. this.gradientMap = null;
  18931. this.lightMap = null;
  18932. this.lightMapIntensity = 1.0;
  18933. this.aoMap = null;
  18934. this.aoMapIntensity = 1.0;
  18935. this.emissive = new Color( 0x000000 );
  18936. this.emissiveIntensity = 1.0;
  18937. this.emissiveMap = null;
  18938. this.bumpMap = null;
  18939. this.bumpScale = 1;
  18940. this.normalMap = null;
  18941. this.normalMapType = TangentSpaceNormalMap;
  18942. this.normalScale = new Vector2( 1, 1 );
  18943. this.displacementMap = null;
  18944. this.displacementScale = 1;
  18945. this.displacementBias = 0;
  18946. this.alphaMap = null;
  18947. this.wireframe = false;
  18948. this.wireframeLinewidth = 1;
  18949. this.wireframeLinecap = 'round';
  18950. this.wireframeLinejoin = 'round';
  18951. this.skinning = false;
  18952. this.morphTargets = false;
  18953. this.morphNormals = false;
  18954. this.setValues( parameters );
  18955. }
  18956. copy( source ) {
  18957. super.copy( source );
  18958. this.color.copy( source.color );
  18959. this.map = source.map;
  18960. this.gradientMap = source.gradientMap;
  18961. this.lightMap = source.lightMap;
  18962. this.lightMapIntensity = source.lightMapIntensity;
  18963. this.aoMap = source.aoMap;
  18964. this.aoMapIntensity = source.aoMapIntensity;
  18965. this.emissive.copy( source.emissive );
  18966. this.emissiveMap = source.emissiveMap;
  18967. this.emissiveIntensity = source.emissiveIntensity;
  18968. this.bumpMap = source.bumpMap;
  18969. this.bumpScale = source.bumpScale;
  18970. this.normalMap = source.normalMap;
  18971. this.normalMapType = source.normalMapType;
  18972. this.normalScale.copy( source.normalScale );
  18973. this.displacementMap = source.displacementMap;
  18974. this.displacementScale = source.displacementScale;
  18975. this.displacementBias = source.displacementBias;
  18976. this.alphaMap = source.alphaMap;
  18977. this.wireframe = source.wireframe;
  18978. this.wireframeLinewidth = source.wireframeLinewidth;
  18979. this.wireframeLinecap = source.wireframeLinecap;
  18980. this.wireframeLinejoin = source.wireframeLinejoin;
  18981. this.skinning = source.skinning;
  18982. this.morphTargets = source.morphTargets;
  18983. this.morphNormals = source.morphNormals;
  18984. return this;
  18985. }
  18986. }
  18987. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  18988. /**
  18989. * parameters = {
  18990. * opacity: <float>,
  18991. *
  18992. * bumpMap: new THREE.Texture( <Image> ),
  18993. * bumpScale: <float>,
  18994. *
  18995. * normalMap: new THREE.Texture( <Image> ),
  18996. * normalMapType: THREE.TangentSpaceNormalMap,
  18997. * normalScale: <Vector2>,
  18998. *
  18999. * displacementMap: new THREE.Texture( <Image> ),
  19000. * displacementScale: <float>,
  19001. * displacementBias: <float>,
  19002. *
  19003. * wireframe: <boolean>,
  19004. * wireframeLinewidth: <float>
  19005. *
  19006. * skinning: <bool>,
  19007. * morphTargets: <bool>,
  19008. * morphNormals: <bool>,
  19009. *
  19010. * flatShading: <bool>
  19011. * }
  19012. */
  19013. class MeshNormalMaterial extends Material {
  19014. constructor( parameters ) {
  19015. super();
  19016. this.type = 'MeshNormalMaterial';
  19017. this.bumpMap = null;
  19018. this.bumpScale = 1;
  19019. this.normalMap = null;
  19020. this.normalMapType = TangentSpaceNormalMap;
  19021. this.normalScale = new Vector2( 1, 1 );
  19022. this.displacementMap = null;
  19023. this.displacementScale = 1;
  19024. this.displacementBias = 0;
  19025. this.wireframe = false;
  19026. this.wireframeLinewidth = 1;
  19027. this.fog = false;
  19028. this.skinning = false;
  19029. this.morphTargets = false;
  19030. this.morphNormals = false;
  19031. this.flatShading = false;
  19032. this.setValues( parameters );
  19033. }
  19034. copy( source ) {
  19035. super.copy( source );
  19036. this.bumpMap = source.bumpMap;
  19037. this.bumpScale = source.bumpScale;
  19038. this.normalMap = source.normalMap;
  19039. this.normalMapType = source.normalMapType;
  19040. this.normalScale.copy( source.normalScale );
  19041. this.displacementMap = source.displacementMap;
  19042. this.displacementScale = source.displacementScale;
  19043. this.displacementBias = source.displacementBias;
  19044. this.wireframe = source.wireframe;
  19045. this.wireframeLinewidth = source.wireframeLinewidth;
  19046. this.skinning = source.skinning;
  19047. this.morphTargets = source.morphTargets;
  19048. this.morphNormals = source.morphNormals;
  19049. this.flatShading = source.flatShading;
  19050. return this;
  19051. }
  19052. }
  19053. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19054. /**
  19055. * parameters = {
  19056. * color: <hex>,
  19057. * opacity: <float>,
  19058. *
  19059. * map: new THREE.Texture( <Image> ),
  19060. *
  19061. * lightMap: new THREE.Texture( <Image> ),
  19062. * lightMapIntensity: <float>
  19063. *
  19064. * aoMap: new THREE.Texture( <Image> ),
  19065. * aoMapIntensity: <float>
  19066. *
  19067. * emissive: <hex>,
  19068. * emissiveIntensity: <float>
  19069. * emissiveMap: new THREE.Texture( <Image> ),
  19070. *
  19071. * specularMap: new THREE.Texture( <Image> ),
  19072. *
  19073. * alphaMap: new THREE.Texture( <Image> ),
  19074. *
  19075. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19076. * combine: THREE.Multiply,
  19077. * reflectivity: <float>,
  19078. * refractionRatio: <float>,
  19079. *
  19080. * wireframe: <boolean>,
  19081. * wireframeLinewidth: <float>,
  19082. *
  19083. * skinning: <bool>,
  19084. * morphTargets: <bool>,
  19085. * morphNormals: <bool>
  19086. * }
  19087. */
  19088. class MeshLambertMaterial extends Material {
  19089. constructor( parameters ) {
  19090. super();
  19091. this.type = 'MeshLambertMaterial';
  19092. this.color = new Color( 0xffffff ); // diffuse
  19093. this.map = null;
  19094. this.lightMap = null;
  19095. this.lightMapIntensity = 1.0;
  19096. this.aoMap = null;
  19097. this.aoMapIntensity = 1.0;
  19098. this.emissive = new Color( 0x000000 );
  19099. this.emissiveIntensity = 1.0;
  19100. this.emissiveMap = null;
  19101. this.specularMap = null;
  19102. this.alphaMap = null;
  19103. this.envMap = null;
  19104. this.combine = MultiplyOperation;
  19105. this.reflectivity = 1;
  19106. this.refractionRatio = 0.98;
  19107. this.wireframe = false;
  19108. this.wireframeLinewidth = 1;
  19109. this.wireframeLinecap = 'round';
  19110. this.wireframeLinejoin = 'round';
  19111. this.skinning = false;
  19112. this.morphTargets = false;
  19113. this.morphNormals = false;
  19114. this.setValues( parameters );
  19115. }
  19116. copy( source ) {
  19117. super.copy( source );
  19118. this.color.copy( source.color );
  19119. this.map = source.map;
  19120. this.lightMap = source.lightMap;
  19121. this.lightMapIntensity = source.lightMapIntensity;
  19122. this.aoMap = source.aoMap;
  19123. this.aoMapIntensity = source.aoMapIntensity;
  19124. this.emissive.copy( source.emissive );
  19125. this.emissiveMap = source.emissiveMap;
  19126. this.emissiveIntensity = source.emissiveIntensity;
  19127. this.specularMap = source.specularMap;
  19128. this.alphaMap = source.alphaMap;
  19129. this.envMap = source.envMap;
  19130. this.combine = source.combine;
  19131. this.reflectivity = source.reflectivity;
  19132. this.refractionRatio = source.refractionRatio;
  19133. this.wireframe = source.wireframe;
  19134. this.wireframeLinewidth = source.wireframeLinewidth;
  19135. this.wireframeLinecap = source.wireframeLinecap;
  19136. this.wireframeLinejoin = source.wireframeLinejoin;
  19137. this.skinning = source.skinning;
  19138. this.morphTargets = source.morphTargets;
  19139. this.morphNormals = source.morphNormals;
  19140. return this;
  19141. }
  19142. }
  19143. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19144. /**
  19145. * parameters = {
  19146. * color: <hex>,
  19147. * opacity: <float>,
  19148. *
  19149. * matcap: new THREE.Texture( <Image> ),
  19150. *
  19151. * map: new THREE.Texture( <Image> ),
  19152. *
  19153. * bumpMap: new THREE.Texture( <Image> ),
  19154. * bumpScale: <float>,
  19155. *
  19156. * normalMap: new THREE.Texture( <Image> ),
  19157. * normalMapType: THREE.TangentSpaceNormalMap,
  19158. * normalScale: <Vector2>,
  19159. *
  19160. * displacementMap: new THREE.Texture( <Image> ),
  19161. * displacementScale: <float>,
  19162. * displacementBias: <float>,
  19163. *
  19164. * alphaMap: new THREE.Texture( <Image> ),
  19165. *
  19166. * skinning: <bool>,
  19167. * morphTargets: <bool>,
  19168. * morphNormals: <bool>
  19169. *
  19170. * flatShading: <bool>
  19171. * }
  19172. */
  19173. class MeshMatcapMaterial extends Material {
  19174. constructor( parameters ) {
  19175. super();
  19176. this.defines = { 'MATCAP': '' };
  19177. this.type = 'MeshMatcapMaterial';
  19178. this.color = new Color( 0xffffff ); // diffuse
  19179. this.matcap = null;
  19180. this.map = null;
  19181. this.bumpMap = null;
  19182. this.bumpScale = 1;
  19183. this.normalMap = null;
  19184. this.normalMapType = TangentSpaceNormalMap;
  19185. this.normalScale = new Vector2( 1, 1 );
  19186. this.displacementMap = null;
  19187. this.displacementScale = 1;
  19188. this.displacementBias = 0;
  19189. this.alphaMap = null;
  19190. this.skinning = false;
  19191. this.morphTargets = false;
  19192. this.morphNormals = false;
  19193. this.flatShading = false;
  19194. this.setValues( parameters );
  19195. }
  19196. copy( source ) {
  19197. super.copy( source );
  19198. this.defines = { 'MATCAP': '' };
  19199. this.color.copy( source.color );
  19200. this.matcap = source.matcap;
  19201. this.map = source.map;
  19202. this.bumpMap = source.bumpMap;
  19203. this.bumpScale = source.bumpScale;
  19204. this.normalMap = source.normalMap;
  19205. this.normalMapType = source.normalMapType;
  19206. this.normalScale.copy( source.normalScale );
  19207. this.displacementMap = source.displacementMap;
  19208. this.displacementScale = source.displacementScale;
  19209. this.displacementBias = source.displacementBias;
  19210. this.alphaMap = source.alphaMap;
  19211. this.skinning = source.skinning;
  19212. this.morphTargets = source.morphTargets;
  19213. this.morphNormals = source.morphNormals;
  19214. this.flatShading = source.flatShading;
  19215. return this;
  19216. }
  19217. }
  19218. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19219. /**
  19220. * parameters = {
  19221. * color: <hex>,
  19222. * opacity: <float>,
  19223. *
  19224. * linewidth: <float>,
  19225. *
  19226. * scale: <float>,
  19227. * dashSize: <float>,
  19228. * gapSize: <float>
  19229. * }
  19230. */
  19231. class LineDashedMaterial extends LineBasicMaterial {
  19232. constructor( parameters ) {
  19233. super();
  19234. this.type = 'LineDashedMaterial';
  19235. this.scale = 1;
  19236. this.dashSize = 3;
  19237. this.gapSize = 1;
  19238. this.setValues( parameters );
  19239. }
  19240. copy( source ) {
  19241. super.copy( source );
  19242. this.scale = source.scale;
  19243. this.dashSize = source.dashSize;
  19244. this.gapSize = source.gapSize;
  19245. return this;
  19246. }
  19247. }
  19248. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19249. var Materials = /*#__PURE__*/Object.freeze({
  19250. __proto__: null,
  19251. ShadowMaterial: ShadowMaterial,
  19252. SpriteMaterial: SpriteMaterial,
  19253. RawShaderMaterial: RawShaderMaterial,
  19254. ShaderMaterial: ShaderMaterial,
  19255. PointsMaterial: PointsMaterial,
  19256. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19257. MeshStandardMaterial: MeshStandardMaterial,
  19258. MeshPhongMaterial: MeshPhongMaterial,
  19259. MeshToonMaterial: MeshToonMaterial,
  19260. MeshNormalMaterial: MeshNormalMaterial,
  19261. MeshLambertMaterial: MeshLambertMaterial,
  19262. MeshDepthMaterial: MeshDepthMaterial,
  19263. MeshDistanceMaterial: MeshDistanceMaterial,
  19264. MeshBasicMaterial: MeshBasicMaterial,
  19265. MeshMatcapMaterial: MeshMatcapMaterial,
  19266. LineDashedMaterial: LineDashedMaterial,
  19267. LineBasicMaterial: LineBasicMaterial,
  19268. Material: Material
  19269. });
  19270. const AnimationUtils = {
  19271. // same as Array.prototype.slice, but also works on typed arrays
  19272. arraySlice: function ( array, from, to ) {
  19273. if ( AnimationUtils.isTypedArray( array ) ) {
  19274. // in ios9 array.subarray(from, undefined) will return empty array
  19275. // but array.subarray(from) or array.subarray(from, len) is correct
  19276. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19277. }
  19278. return array.slice( from, to );
  19279. },
  19280. // converts an array to a specific type
  19281. convertArray: function ( array, type, forceClone ) {
  19282. if ( ! array || // let 'undefined' and 'null' pass
  19283. ! forceClone && array.constructor === type ) return array;
  19284. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19285. return new type( array ); // create typed array
  19286. }
  19287. return Array.prototype.slice.call( array ); // create Array
  19288. },
  19289. isTypedArray: function ( object ) {
  19290. return ArrayBuffer.isView( object ) &&
  19291. ! ( object instanceof DataView );
  19292. },
  19293. // returns an array by which times and values can be sorted
  19294. getKeyframeOrder: function ( times ) {
  19295. function compareTime( i, j ) {
  19296. return times[ i ] - times[ j ];
  19297. }
  19298. const n = times.length;
  19299. const result = new Array( n );
  19300. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  19301. result.sort( compareTime );
  19302. return result;
  19303. },
  19304. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19305. sortedArray: function ( values, stride, order ) {
  19306. const nValues = values.length;
  19307. const result = new values.constructor( nValues );
  19308. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19309. const srcOffset = order[ i ] * stride;
  19310. for ( let j = 0; j !== stride; ++ j ) {
  19311. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19312. }
  19313. }
  19314. return result;
  19315. },
  19316. // function for parsing AOS keyframe formats
  19317. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19318. let i = 1, key = jsonKeys[ 0 ];
  19319. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19320. key = jsonKeys[ i ++ ];
  19321. }
  19322. if ( key === undefined ) return; // no data
  19323. let value = key[ valuePropertyName ];
  19324. if ( value === undefined ) return; // no data
  19325. if ( Array.isArray( value ) ) {
  19326. do {
  19327. value = key[ valuePropertyName ];
  19328. if ( value !== undefined ) {
  19329. times.push( key.time );
  19330. values.push.apply( values, value ); // push all elements
  19331. }
  19332. key = jsonKeys[ i ++ ];
  19333. } while ( key !== undefined );
  19334. } else if ( value.toArray !== undefined ) {
  19335. // ...assume THREE.Math-ish
  19336. do {
  19337. value = key[ valuePropertyName ];
  19338. if ( value !== undefined ) {
  19339. times.push( key.time );
  19340. value.toArray( values, values.length );
  19341. }
  19342. key = jsonKeys[ i ++ ];
  19343. } while ( key !== undefined );
  19344. } else {
  19345. // otherwise push as-is
  19346. do {
  19347. value = key[ valuePropertyName ];
  19348. if ( value !== undefined ) {
  19349. times.push( key.time );
  19350. values.push( value );
  19351. }
  19352. key = jsonKeys[ i ++ ];
  19353. } while ( key !== undefined );
  19354. }
  19355. },
  19356. subclip: function ( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  19357. const clip = sourceClip.clone();
  19358. clip.name = name;
  19359. const tracks = [];
  19360. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19361. const track = clip.tracks[ i ];
  19362. const valueSize = track.getValueSize();
  19363. const times = [];
  19364. const values = [];
  19365. for ( let j = 0; j < track.times.length; ++ j ) {
  19366. const frame = track.times[ j ] * fps;
  19367. if ( frame < startFrame || frame >= endFrame ) continue;
  19368. times.push( track.times[ j ] );
  19369. for ( let k = 0; k < valueSize; ++ k ) {
  19370. values.push( track.values[ j * valueSize + k ] );
  19371. }
  19372. }
  19373. if ( times.length === 0 ) continue;
  19374. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  19375. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  19376. tracks.push( track );
  19377. }
  19378. clip.tracks = tracks;
  19379. // find minimum .times value across all tracks in the trimmed clip
  19380. let minStartTime = Infinity;
  19381. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19382. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  19383. minStartTime = clip.tracks[ i ].times[ 0 ];
  19384. }
  19385. }
  19386. // shift all tracks such that clip begins at t=0
  19387. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19388. clip.tracks[ i ].shift( - 1 * minStartTime );
  19389. }
  19390. clip.resetDuration();
  19391. return clip;
  19392. },
  19393. makeClipAdditive: function ( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  19394. if ( fps <= 0 ) fps = 30;
  19395. const numTracks = referenceClip.tracks.length;
  19396. const referenceTime = referenceFrame / fps;
  19397. // Make each track's values relative to the values at the reference frame
  19398. for ( let i = 0; i < numTracks; ++ i ) {
  19399. const referenceTrack = referenceClip.tracks[ i ];
  19400. const referenceTrackType = referenceTrack.ValueTypeName;
  19401. // Skip this track if it's non-numeric
  19402. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  19403. // Find the track in the target clip whose name and type matches the reference track
  19404. const targetTrack = targetClip.tracks.find( function ( track ) {
  19405. return track.name === referenceTrack.name
  19406. && track.ValueTypeName === referenceTrackType;
  19407. } );
  19408. if ( targetTrack === undefined ) continue;
  19409. let referenceOffset = 0;
  19410. const referenceValueSize = referenceTrack.getValueSize();
  19411. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  19412. referenceOffset = referenceValueSize / 3;
  19413. }
  19414. let targetOffset = 0;
  19415. const targetValueSize = targetTrack.getValueSize();
  19416. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  19417. targetOffset = targetValueSize / 3;
  19418. }
  19419. const lastIndex = referenceTrack.times.length - 1;
  19420. let referenceValue;
  19421. // Find the value to subtract out of the track
  19422. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  19423. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  19424. const startIndex = referenceOffset;
  19425. const endIndex = referenceValueSize - referenceOffset;
  19426. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  19427. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  19428. // Reference frame is after the last keyframe, so just use the last keyframe
  19429. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  19430. const endIndex = startIndex + referenceValueSize - referenceOffset;
  19431. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  19432. } else {
  19433. // Interpolate to the reference value
  19434. const interpolant = referenceTrack.createInterpolant();
  19435. const startIndex = referenceOffset;
  19436. const endIndex = referenceValueSize - referenceOffset;
  19437. interpolant.evaluate( referenceTime );
  19438. referenceValue = AnimationUtils.arraySlice( interpolant.resultBuffer, startIndex, endIndex );
  19439. }
  19440. // Conjugate the quaternion
  19441. if ( referenceTrackType === 'quaternion' ) {
  19442. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  19443. referenceQuat.toArray( referenceValue );
  19444. }
  19445. // Subtract the reference value from all of the track values
  19446. const numTimes = targetTrack.times.length;
  19447. for ( let j = 0; j < numTimes; ++ j ) {
  19448. const valueStart = j * targetValueSize + targetOffset;
  19449. if ( referenceTrackType === 'quaternion' ) {
  19450. // Multiply the conjugate for quaternion track types
  19451. Quaternion.multiplyQuaternionsFlat(
  19452. targetTrack.values,
  19453. valueStart,
  19454. referenceValue,
  19455. 0,
  19456. targetTrack.values,
  19457. valueStart
  19458. );
  19459. } else {
  19460. const valueEnd = targetValueSize - targetOffset * 2;
  19461. // Subtract each value for all other numeric track types
  19462. for ( let k = 0; k < valueEnd; ++ k ) {
  19463. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  19464. }
  19465. }
  19466. }
  19467. }
  19468. targetClip.blendMode = AdditiveAnimationBlendMode;
  19469. return targetClip;
  19470. }
  19471. };
  19472. /**
  19473. * Abstract base class of interpolants over parametric samples.
  19474. *
  19475. * The parameter domain is one dimensional, typically the time or a path
  19476. * along a curve defined by the data.
  19477. *
  19478. * The sample values can have any dimensionality and derived classes may
  19479. * apply special interpretations to the data.
  19480. *
  19481. * This class provides the interval seek in a Template Method, deferring
  19482. * the actual interpolation to derived classes.
  19483. *
  19484. * Time complexity is O(1) for linear access crossing at most two points
  19485. * and O(log N) for random access, where N is the number of positions.
  19486. *
  19487. * References:
  19488. *
  19489. * http://www.oodesign.com/template-method-pattern.html
  19490. *
  19491. */
  19492. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19493. this.parameterPositions = parameterPositions;
  19494. this._cachedIndex = 0;
  19495. this.resultBuffer = resultBuffer !== undefined ?
  19496. resultBuffer : new sampleValues.constructor( sampleSize );
  19497. this.sampleValues = sampleValues;
  19498. this.valueSize = sampleSize;
  19499. }
  19500. Object.assign( Interpolant.prototype, {
  19501. evaluate: function ( t ) {
  19502. const pp = this.parameterPositions;
  19503. let i1 = this._cachedIndex,
  19504. t1 = pp[ i1 ],
  19505. t0 = pp[ i1 - 1 ];
  19506. validate_interval: {
  19507. seek: {
  19508. let right;
  19509. linear_scan: {
  19510. //- See http://jsperf.com/comparison-to-undefined/3
  19511. //- slower code:
  19512. //-
  19513. //- if ( t >= t1 || t1 === undefined ) {
  19514. forward_scan: if ( ! ( t < t1 ) ) {
  19515. for ( let giveUpAt = i1 + 2; ; ) {
  19516. if ( t1 === undefined ) {
  19517. if ( t < t0 ) break forward_scan;
  19518. // after end
  19519. i1 = pp.length;
  19520. this._cachedIndex = i1;
  19521. return this.afterEnd_( i1 - 1, t, t0 );
  19522. }
  19523. if ( i1 === giveUpAt ) break; // this loop
  19524. t0 = t1;
  19525. t1 = pp[ ++ i1 ];
  19526. if ( t < t1 ) {
  19527. // we have arrived at the sought interval
  19528. break seek;
  19529. }
  19530. }
  19531. // prepare binary search on the right side of the index
  19532. right = pp.length;
  19533. break linear_scan;
  19534. }
  19535. //- slower code:
  19536. //- if ( t < t0 || t0 === undefined ) {
  19537. if ( ! ( t >= t0 ) ) {
  19538. // looping?
  19539. const t1global = pp[ 1 ];
  19540. if ( t < t1global ) {
  19541. i1 = 2; // + 1, using the scan for the details
  19542. t0 = t1global;
  19543. }
  19544. // linear reverse scan
  19545. for ( let giveUpAt = i1 - 2; ; ) {
  19546. if ( t0 === undefined ) {
  19547. // before start
  19548. this._cachedIndex = 0;
  19549. return this.beforeStart_( 0, t, t1 );
  19550. }
  19551. if ( i1 === giveUpAt ) break; // this loop
  19552. t1 = t0;
  19553. t0 = pp[ -- i1 - 1 ];
  19554. if ( t >= t0 ) {
  19555. // we have arrived at the sought interval
  19556. break seek;
  19557. }
  19558. }
  19559. // prepare binary search on the left side of the index
  19560. right = i1;
  19561. i1 = 0;
  19562. break linear_scan;
  19563. }
  19564. // the interval is valid
  19565. break validate_interval;
  19566. } // linear scan
  19567. // binary search
  19568. while ( i1 < right ) {
  19569. const mid = ( i1 + right ) >>> 1;
  19570. if ( t < pp[ mid ] ) {
  19571. right = mid;
  19572. } else {
  19573. i1 = mid + 1;
  19574. }
  19575. }
  19576. t1 = pp[ i1 ];
  19577. t0 = pp[ i1 - 1 ];
  19578. // check boundary cases, again
  19579. if ( t0 === undefined ) {
  19580. this._cachedIndex = 0;
  19581. return this.beforeStart_( 0, t, t1 );
  19582. }
  19583. if ( t1 === undefined ) {
  19584. i1 = pp.length;
  19585. this._cachedIndex = i1;
  19586. return this.afterEnd_( i1 - 1, t0, t );
  19587. }
  19588. } // seek
  19589. this._cachedIndex = i1;
  19590. this.intervalChanged_( i1, t0, t1 );
  19591. } // validate_interval
  19592. return this.interpolate_( i1, t0, t, t1 );
  19593. },
  19594. settings: null, // optional, subclass-specific settings structure
  19595. // Note: The indirection allows central control of many interpolants.
  19596. // --- Protected interface
  19597. DefaultSettings_: {},
  19598. getSettings_: function () {
  19599. return this.settings || this.DefaultSettings_;
  19600. },
  19601. copySampleValue_: function ( index ) {
  19602. // copies a sample value to the result buffer
  19603. const result = this.resultBuffer,
  19604. values = this.sampleValues,
  19605. stride = this.valueSize,
  19606. offset = index * stride;
  19607. for ( let i = 0; i !== stride; ++ i ) {
  19608. result[ i ] = values[ offset + i ];
  19609. }
  19610. return result;
  19611. },
  19612. // Template methods for derived classes:
  19613. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19614. throw new Error( 'call to abstract method' );
  19615. // implementations shall return this.resultBuffer
  19616. },
  19617. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19618. // empty
  19619. }
  19620. } );
  19621. // DECLARE ALIAS AFTER assign prototype
  19622. Object.assign( Interpolant.prototype, {
  19623. //( 0, t, t0 ), returns this.resultBuffer
  19624. beforeStart_: Interpolant.prototype.copySampleValue_,
  19625. //( N-1, tN-1, t ), returns this.resultBuffer
  19626. afterEnd_: Interpolant.prototype.copySampleValue_,
  19627. } );
  19628. /**
  19629. * Fast and simple cubic spline interpolant.
  19630. *
  19631. * It was derived from a Hermitian construction setting the first derivative
  19632. * at each sample position to the linear slope between neighboring positions
  19633. * over their parameter interval.
  19634. */
  19635. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19636. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19637. this._weightPrev = - 0;
  19638. this._offsetPrev = - 0;
  19639. this._weightNext = - 0;
  19640. this._offsetNext = - 0;
  19641. }
  19642. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19643. constructor: CubicInterpolant,
  19644. DefaultSettings_: {
  19645. endingStart: ZeroCurvatureEnding,
  19646. endingEnd: ZeroCurvatureEnding
  19647. },
  19648. intervalChanged_: function ( i1, t0, t1 ) {
  19649. const pp = this.parameterPositions;
  19650. let iPrev = i1 - 2,
  19651. iNext = i1 + 1,
  19652. tPrev = pp[ iPrev ],
  19653. tNext = pp[ iNext ];
  19654. if ( tPrev === undefined ) {
  19655. switch ( this.getSettings_().endingStart ) {
  19656. case ZeroSlopeEnding:
  19657. // f'(t0) = 0
  19658. iPrev = i1;
  19659. tPrev = 2 * t0 - t1;
  19660. break;
  19661. case WrapAroundEnding:
  19662. // use the other end of the curve
  19663. iPrev = pp.length - 2;
  19664. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19665. break;
  19666. default: // ZeroCurvatureEnding
  19667. // f''(t0) = 0 a.k.a. Natural Spline
  19668. iPrev = i1;
  19669. tPrev = t1;
  19670. }
  19671. }
  19672. if ( tNext === undefined ) {
  19673. switch ( this.getSettings_().endingEnd ) {
  19674. case ZeroSlopeEnding:
  19675. // f'(tN) = 0
  19676. iNext = i1;
  19677. tNext = 2 * t1 - t0;
  19678. break;
  19679. case WrapAroundEnding:
  19680. // use the other end of the curve
  19681. iNext = 1;
  19682. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19683. break;
  19684. default: // ZeroCurvatureEnding
  19685. // f''(tN) = 0, a.k.a. Natural Spline
  19686. iNext = i1 - 1;
  19687. tNext = t0;
  19688. }
  19689. }
  19690. const halfDt = ( t1 - t0 ) * 0.5,
  19691. stride = this.valueSize;
  19692. this._weightPrev = halfDt / ( t0 - tPrev );
  19693. this._weightNext = halfDt / ( tNext - t1 );
  19694. this._offsetPrev = iPrev * stride;
  19695. this._offsetNext = iNext * stride;
  19696. },
  19697. interpolate_: function ( i1, t0, t, t1 ) {
  19698. const result = this.resultBuffer,
  19699. values = this.sampleValues,
  19700. stride = this.valueSize,
  19701. o1 = i1 * stride, o0 = o1 - stride,
  19702. oP = this._offsetPrev, oN = this._offsetNext,
  19703. wP = this._weightPrev, wN = this._weightNext,
  19704. p = ( t - t0 ) / ( t1 - t0 ),
  19705. pp = p * p,
  19706. ppp = pp * p;
  19707. // evaluate polynomials
  19708. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  19709. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19710. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19711. const sN = wN * ppp - wN * pp;
  19712. // combine data linearly
  19713. for ( let i = 0; i !== stride; ++ i ) {
  19714. result[ i ] =
  19715. sP * values[ oP + i ] +
  19716. s0 * values[ o0 + i ] +
  19717. s1 * values[ o1 + i ] +
  19718. sN * values[ oN + i ];
  19719. }
  19720. return result;
  19721. }
  19722. } );
  19723. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19724. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19725. }
  19726. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19727. constructor: LinearInterpolant,
  19728. interpolate_: function ( i1, t0, t, t1 ) {
  19729. const result = this.resultBuffer,
  19730. values = this.sampleValues,
  19731. stride = this.valueSize,
  19732. offset1 = i1 * stride,
  19733. offset0 = offset1 - stride,
  19734. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19735. weight0 = 1 - weight1;
  19736. for ( let i = 0; i !== stride; ++ i ) {
  19737. result[ i ] =
  19738. values[ offset0 + i ] * weight0 +
  19739. values[ offset1 + i ] * weight1;
  19740. }
  19741. return result;
  19742. }
  19743. } );
  19744. /**
  19745. *
  19746. * Interpolant that evaluates to the sample value at the position preceeding
  19747. * the parameter.
  19748. */
  19749. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19750. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19751. }
  19752. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19753. constructor: DiscreteInterpolant,
  19754. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19755. return this.copySampleValue_( i1 - 1 );
  19756. }
  19757. } );
  19758. class KeyframeTrack {
  19759. constructor( name, times, values, interpolation ) {
  19760. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19761. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19762. this.name = name;
  19763. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19764. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19765. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19766. }
  19767. // Serialization (in static context, because of constructor invocation
  19768. // and automatic invocation of .toJSON):
  19769. static toJSON( track ) {
  19770. const trackType = track.constructor;
  19771. let json;
  19772. // derived classes can define a static toJSON method
  19773. if ( trackType.toJSON !== this.toJSON ) {
  19774. json = trackType.toJSON( track );
  19775. } else {
  19776. // by default, we assume the data can be serialized as-is
  19777. json = {
  19778. 'name': track.name,
  19779. 'times': AnimationUtils.convertArray( track.times, Array ),
  19780. 'values': AnimationUtils.convertArray( track.values, Array )
  19781. };
  19782. const interpolation = track.getInterpolation();
  19783. if ( interpolation !== track.DefaultInterpolation ) {
  19784. json.interpolation = interpolation;
  19785. }
  19786. }
  19787. json.type = track.ValueTypeName; // mandatory
  19788. return json;
  19789. }
  19790. InterpolantFactoryMethodDiscrete( result ) {
  19791. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19792. }
  19793. InterpolantFactoryMethodLinear( result ) {
  19794. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19795. }
  19796. InterpolantFactoryMethodSmooth( result ) {
  19797. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19798. }
  19799. setInterpolation( interpolation ) {
  19800. let factoryMethod;
  19801. switch ( interpolation ) {
  19802. case InterpolateDiscrete:
  19803. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19804. break;
  19805. case InterpolateLinear:
  19806. factoryMethod = this.InterpolantFactoryMethodLinear;
  19807. break;
  19808. case InterpolateSmooth:
  19809. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19810. break;
  19811. }
  19812. if ( factoryMethod === undefined ) {
  19813. const message = 'unsupported interpolation for ' +
  19814. this.ValueTypeName + ' keyframe track named ' + this.name;
  19815. if ( this.createInterpolant === undefined ) {
  19816. // fall back to default, unless the default itself is messed up
  19817. if ( interpolation !== this.DefaultInterpolation ) {
  19818. this.setInterpolation( this.DefaultInterpolation );
  19819. } else {
  19820. throw new Error( message ); // fatal, in this case
  19821. }
  19822. }
  19823. console.warn( 'THREE.KeyframeTrack:', message );
  19824. return this;
  19825. }
  19826. this.createInterpolant = factoryMethod;
  19827. return this;
  19828. }
  19829. getInterpolation() {
  19830. switch ( this.createInterpolant ) {
  19831. case this.InterpolantFactoryMethodDiscrete:
  19832. return InterpolateDiscrete;
  19833. case this.InterpolantFactoryMethodLinear:
  19834. return InterpolateLinear;
  19835. case this.InterpolantFactoryMethodSmooth:
  19836. return InterpolateSmooth;
  19837. }
  19838. }
  19839. getValueSize() {
  19840. return this.values.length / this.times.length;
  19841. }
  19842. // move all keyframes either forwards or backwards in time
  19843. shift( timeOffset ) {
  19844. if ( timeOffset !== 0.0 ) {
  19845. const times = this.times;
  19846. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  19847. times[ i ] += timeOffset;
  19848. }
  19849. }
  19850. return this;
  19851. }
  19852. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19853. scale( timeScale ) {
  19854. if ( timeScale !== 1.0 ) {
  19855. const times = this.times;
  19856. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  19857. times[ i ] *= timeScale;
  19858. }
  19859. }
  19860. return this;
  19861. }
  19862. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19863. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19864. trim( startTime, endTime ) {
  19865. const times = this.times,
  19866. nKeys = times.length;
  19867. let from = 0,
  19868. to = nKeys - 1;
  19869. while ( from !== nKeys && times[ from ] < startTime ) {
  19870. ++ from;
  19871. }
  19872. while ( to !== - 1 && times[ to ] > endTime ) {
  19873. -- to;
  19874. }
  19875. ++ to; // inclusive -> exclusive bound
  19876. if ( from !== 0 || to !== nKeys ) {
  19877. // empty tracks are forbidden, so keep at least one keyframe
  19878. if ( from >= to ) {
  19879. to = Math.max( to, 1 );
  19880. from = to - 1;
  19881. }
  19882. const stride = this.getValueSize();
  19883. this.times = AnimationUtils.arraySlice( times, from, to );
  19884. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19885. }
  19886. return this;
  19887. }
  19888. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19889. validate() {
  19890. let valid = true;
  19891. const valueSize = this.getValueSize();
  19892. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19893. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19894. valid = false;
  19895. }
  19896. const times = this.times,
  19897. values = this.values,
  19898. nKeys = times.length;
  19899. if ( nKeys === 0 ) {
  19900. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19901. valid = false;
  19902. }
  19903. let prevTime = null;
  19904. for ( let i = 0; i !== nKeys; i ++ ) {
  19905. const currTime = times[ i ];
  19906. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19907. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19908. valid = false;
  19909. break;
  19910. }
  19911. if ( prevTime !== null && prevTime > currTime ) {
  19912. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19913. valid = false;
  19914. break;
  19915. }
  19916. prevTime = currTime;
  19917. }
  19918. if ( values !== undefined ) {
  19919. if ( AnimationUtils.isTypedArray( values ) ) {
  19920. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  19921. const value = values[ i ];
  19922. if ( isNaN( value ) ) {
  19923. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19924. valid = false;
  19925. break;
  19926. }
  19927. }
  19928. }
  19929. }
  19930. return valid;
  19931. }
  19932. // removes equivalent sequential keys as common in morph target sequences
  19933. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19934. optimize() {
  19935. // times or values may be shared with other tracks, so overwriting is unsafe
  19936. const times = AnimationUtils.arraySlice( this.times ),
  19937. values = AnimationUtils.arraySlice( this.values ),
  19938. stride = this.getValueSize(),
  19939. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19940. lastIndex = times.length - 1;
  19941. let writeIndex = 1;
  19942. for ( let i = 1; i < lastIndex; ++ i ) {
  19943. let keep = false;
  19944. const time = times[ i ];
  19945. const timeNext = times[ i + 1 ];
  19946. // remove adjacent keyframes scheduled at the same time
  19947. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  19948. if ( ! smoothInterpolation ) {
  19949. // remove unnecessary keyframes same as their neighbors
  19950. const offset = i * stride,
  19951. offsetP = offset - stride,
  19952. offsetN = offset + stride;
  19953. for ( let j = 0; j !== stride; ++ j ) {
  19954. const value = values[ offset + j ];
  19955. if ( value !== values[ offsetP + j ] ||
  19956. value !== values[ offsetN + j ] ) {
  19957. keep = true;
  19958. break;
  19959. }
  19960. }
  19961. } else {
  19962. keep = true;
  19963. }
  19964. }
  19965. // in-place compaction
  19966. if ( keep ) {
  19967. if ( i !== writeIndex ) {
  19968. times[ writeIndex ] = times[ i ];
  19969. const readOffset = i * stride,
  19970. writeOffset = writeIndex * stride;
  19971. for ( let j = 0; j !== stride; ++ j ) {
  19972. values[ writeOffset + j ] = values[ readOffset + j ];
  19973. }
  19974. }
  19975. ++ writeIndex;
  19976. }
  19977. }
  19978. // flush last keyframe (compaction looks ahead)
  19979. if ( lastIndex > 0 ) {
  19980. times[ writeIndex ] = times[ lastIndex ];
  19981. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  19982. values[ writeOffset + j ] = values[ readOffset + j ];
  19983. }
  19984. ++ writeIndex;
  19985. }
  19986. if ( writeIndex !== times.length ) {
  19987. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  19988. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  19989. } else {
  19990. this.times = times;
  19991. this.values = values;
  19992. }
  19993. return this;
  19994. }
  19995. clone() {
  19996. const times = AnimationUtils.arraySlice( this.times, 0 );
  19997. const values = AnimationUtils.arraySlice( this.values, 0 );
  19998. const TypedKeyframeTrack = this.constructor;
  19999. const track = new TypedKeyframeTrack( this.name, times, values );
  20000. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20001. track.createInterpolant = this.createInterpolant;
  20002. return track;
  20003. }
  20004. }
  20005. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  20006. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  20007. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  20008. /**
  20009. * A Track of Boolean keyframe values.
  20010. */
  20011. class BooleanKeyframeTrack extends KeyframeTrack {}
  20012. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  20013. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  20014. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  20015. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  20016. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  20017. /**
  20018. * A Track of keyframe values that represent color.
  20019. */
  20020. class ColorKeyframeTrack extends KeyframeTrack {}
  20021. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  20022. /**
  20023. * A Track of numeric keyframe values.
  20024. */
  20025. class NumberKeyframeTrack extends KeyframeTrack {}
  20026. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  20027. /**
  20028. * Spherical linear unit quaternion interpolant.
  20029. */
  20030. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20031. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20032. }
  20033. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20034. constructor: QuaternionLinearInterpolant,
  20035. interpolate_: function ( i1, t0, t, t1 ) {
  20036. const result = this.resultBuffer,
  20037. values = this.sampleValues,
  20038. stride = this.valueSize,
  20039. alpha = ( t - t0 ) / ( t1 - t0 );
  20040. let offset = i1 * stride;
  20041. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  20042. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20043. }
  20044. return result;
  20045. }
  20046. } );
  20047. /**
  20048. * A Track of quaternion keyframe values.
  20049. */
  20050. class QuaternionKeyframeTrack extends KeyframeTrack {
  20051. InterpolantFactoryMethodLinear( result ) {
  20052. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20053. }
  20054. }
  20055. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  20056. // ValueBufferType is inherited
  20057. QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  20058. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  20059. /**
  20060. * A Track that interpolates Strings
  20061. */
  20062. class StringKeyframeTrack extends KeyframeTrack {}
  20063. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  20064. StringKeyframeTrack.prototype.ValueBufferType = Array;
  20065. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  20066. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  20067. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  20068. /**
  20069. * A Track of vectored keyframe values.
  20070. */
  20071. class VectorKeyframeTrack extends KeyframeTrack {}
  20072. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  20073. class AnimationClip {
  20074. constructor( name, duration = - 1, tracks, blendMode = NormalAnimationBlendMode ) {
  20075. this.name = name;
  20076. this.tracks = tracks;
  20077. this.duration = duration;
  20078. this.blendMode = blendMode;
  20079. this.uuid = MathUtils.generateUUID();
  20080. // this means it should figure out its duration by scanning the tracks
  20081. if ( this.duration < 0 ) {
  20082. this.resetDuration();
  20083. }
  20084. }
  20085. static parse( json ) {
  20086. const tracks = [],
  20087. jsonTracks = json.tracks,
  20088. frameTime = 1.0 / ( json.fps || 1.0 );
  20089. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20090. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20091. }
  20092. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  20093. clip.uuid = json.uuid;
  20094. return clip;
  20095. }
  20096. static toJSON( clip ) {
  20097. const tracks = [],
  20098. clipTracks = clip.tracks;
  20099. const json = {
  20100. 'name': clip.name,
  20101. 'duration': clip.duration,
  20102. 'tracks': tracks,
  20103. 'uuid': clip.uuid,
  20104. 'blendMode': clip.blendMode
  20105. };
  20106. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20107. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20108. }
  20109. return json;
  20110. }
  20111. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  20112. const numMorphTargets = morphTargetSequence.length;
  20113. const tracks = [];
  20114. for ( let i = 0; i < numMorphTargets; i ++ ) {
  20115. let times = [];
  20116. let values = [];
  20117. times.push(
  20118. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20119. i,
  20120. ( i + 1 ) % numMorphTargets );
  20121. values.push( 0, 1, 0 );
  20122. const order = AnimationUtils.getKeyframeOrder( times );
  20123. times = AnimationUtils.sortedArray( times, 1, order );
  20124. values = AnimationUtils.sortedArray( values, 1, order );
  20125. // if there is a key at the first frame, duplicate it as the
  20126. // last frame as well for perfect loop.
  20127. if ( ! noLoop && times[ 0 ] === 0 ) {
  20128. times.push( numMorphTargets );
  20129. values.push( values[ 0 ] );
  20130. }
  20131. tracks.push(
  20132. new NumberKeyframeTrack(
  20133. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20134. times, values
  20135. ).scale( 1.0 / fps ) );
  20136. }
  20137. return new this( name, - 1, tracks );
  20138. }
  20139. static findByName( objectOrClipArray, name ) {
  20140. let clipArray = objectOrClipArray;
  20141. if ( ! Array.isArray( objectOrClipArray ) ) {
  20142. const o = objectOrClipArray;
  20143. clipArray = o.geometry && o.geometry.animations || o.animations;
  20144. }
  20145. for ( let i = 0; i < clipArray.length; i ++ ) {
  20146. if ( clipArray[ i ].name === name ) {
  20147. return clipArray[ i ];
  20148. }
  20149. }
  20150. return null;
  20151. }
  20152. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  20153. const animationToMorphTargets = {};
  20154. // tested with https://regex101.com/ on trick sequences
  20155. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20156. const pattern = /^([\w-]*?)([\d]+)$/;
  20157. // sort morph target names into animation groups based
  20158. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20159. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  20160. const morphTarget = morphTargets[ i ];
  20161. const parts = morphTarget.name.match( pattern );
  20162. if ( parts && parts.length > 1 ) {
  20163. const name = parts[ 1 ];
  20164. let animationMorphTargets = animationToMorphTargets[ name ];
  20165. if ( ! animationMorphTargets ) {
  20166. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20167. }
  20168. animationMorphTargets.push( morphTarget );
  20169. }
  20170. }
  20171. const clips = [];
  20172. for ( const name in animationToMorphTargets ) {
  20173. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20174. }
  20175. return clips;
  20176. }
  20177. // parse the animation.hierarchy format
  20178. static parseAnimation( animation, bones ) {
  20179. if ( ! animation ) {
  20180. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20181. return null;
  20182. }
  20183. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20184. // only return track if there are actually keys.
  20185. if ( animationKeys.length !== 0 ) {
  20186. const times = [];
  20187. const values = [];
  20188. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20189. // empty keys are filtered out, so check again
  20190. if ( times.length !== 0 ) {
  20191. destTracks.push( new trackType( trackName, times, values ) );
  20192. }
  20193. }
  20194. };
  20195. const tracks = [];
  20196. const clipName = animation.name || 'default';
  20197. const fps = animation.fps || 30;
  20198. const blendMode = animation.blendMode;
  20199. // automatic length determination in AnimationClip.
  20200. let duration = animation.length || - 1;
  20201. const hierarchyTracks = animation.hierarchy || [];
  20202. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  20203. const animationKeys = hierarchyTracks[ h ].keys;
  20204. // skip empty tracks
  20205. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20206. // process morph targets
  20207. if ( animationKeys[ 0 ].morphTargets ) {
  20208. // figure out all morph targets used in this track
  20209. const morphTargetNames = {};
  20210. let k;
  20211. for ( k = 0; k < animationKeys.length; k ++ ) {
  20212. if ( animationKeys[ k ].morphTargets ) {
  20213. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20214. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20215. }
  20216. }
  20217. }
  20218. // create a track for each morph target with all zero
  20219. // morphTargetInfluences except for the keys in which
  20220. // the morphTarget is named.
  20221. for ( const morphTargetName in morphTargetNames ) {
  20222. const times = [];
  20223. const values = [];
  20224. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20225. const animationKey = animationKeys[ k ];
  20226. times.push( animationKey.time );
  20227. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20228. }
  20229. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20230. }
  20231. duration = morphTargetNames.length * ( fps || 1.0 );
  20232. } else {
  20233. // ...assume skeletal animation
  20234. const boneName = '.bones[' + bones[ h ].name + ']';
  20235. addNonemptyTrack(
  20236. VectorKeyframeTrack, boneName + '.position',
  20237. animationKeys, 'pos', tracks );
  20238. addNonemptyTrack(
  20239. QuaternionKeyframeTrack, boneName + '.quaternion',
  20240. animationKeys, 'rot', tracks );
  20241. addNonemptyTrack(
  20242. VectorKeyframeTrack, boneName + '.scale',
  20243. animationKeys, 'scl', tracks );
  20244. }
  20245. }
  20246. if ( tracks.length === 0 ) {
  20247. return null;
  20248. }
  20249. const clip = new this( clipName, duration, tracks, blendMode );
  20250. return clip;
  20251. }
  20252. resetDuration() {
  20253. const tracks = this.tracks;
  20254. let duration = 0;
  20255. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  20256. const track = this.tracks[ i ];
  20257. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20258. }
  20259. this.duration = duration;
  20260. return this;
  20261. }
  20262. trim() {
  20263. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20264. this.tracks[ i ].trim( 0, this.duration );
  20265. }
  20266. return this;
  20267. }
  20268. validate() {
  20269. let valid = true;
  20270. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20271. valid = valid && this.tracks[ i ].validate();
  20272. }
  20273. return valid;
  20274. }
  20275. optimize() {
  20276. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20277. this.tracks[ i ].optimize();
  20278. }
  20279. return this;
  20280. }
  20281. clone() {
  20282. const tracks = [];
  20283. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20284. tracks.push( this.tracks[ i ].clone() );
  20285. }
  20286. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  20287. }
  20288. toJSON() {
  20289. return this.constructor.toJSON( this );
  20290. }
  20291. }
  20292. function getTrackTypeForValueTypeName( typeName ) {
  20293. switch ( typeName.toLowerCase() ) {
  20294. case 'scalar':
  20295. case 'double':
  20296. case 'float':
  20297. case 'number':
  20298. case 'integer':
  20299. return NumberKeyframeTrack;
  20300. case 'vector':
  20301. case 'vector2':
  20302. case 'vector3':
  20303. case 'vector4':
  20304. return VectorKeyframeTrack;
  20305. case 'color':
  20306. return ColorKeyframeTrack;
  20307. case 'quaternion':
  20308. return QuaternionKeyframeTrack;
  20309. case 'bool':
  20310. case 'boolean':
  20311. return BooleanKeyframeTrack;
  20312. case 'string':
  20313. return StringKeyframeTrack;
  20314. }
  20315. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20316. }
  20317. function parseKeyframeTrack( json ) {
  20318. if ( json.type === undefined ) {
  20319. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20320. }
  20321. const trackType = getTrackTypeForValueTypeName( json.type );
  20322. if ( json.times === undefined ) {
  20323. const times = [], values = [];
  20324. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20325. json.times = times;
  20326. json.values = values;
  20327. }
  20328. // derived classes can define a static parse method
  20329. if ( trackType.parse !== undefined ) {
  20330. return trackType.parse( json );
  20331. } else {
  20332. // by default, we assume a constructor compatible with the base
  20333. return new trackType( json.name, json.times, json.values, json.interpolation );
  20334. }
  20335. }
  20336. const Cache = {
  20337. enabled: false,
  20338. files: {},
  20339. add: function ( key, file ) {
  20340. if ( this.enabled === false ) return;
  20341. // console.log( 'THREE.Cache', 'Adding key:', key );
  20342. this.files[ key ] = file;
  20343. },
  20344. get: function ( key ) {
  20345. if ( this.enabled === false ) return;
  20346. // console.log( 'THREE.Cache', 'Checking key:', key );
  20347. return this.files[ key ];
  20348. },
  20349. remove: function ( key ) {
  20350. delete this.files[ key ];
  20351. },
  20352. clear: function () {
  20353. this.files = {};
  20354. }
  20355. };
  20356. function LoadingManager( onLoad, onProgress, onError ) {
  20357. const scope = this;
  20358. let isLoading = false;
  20359. let itemsLoaded = 0;
  20360. let itemsTotal = 0;
  20361. let urlModifier = undefined;
  20362. const handlers = [];
  20363. // Refer to #5689 for the reason why we don't set .onStart
  20364. // in the constructor
  20365. this.onStart = undefined;
  20366. this.onLoad = onLoad;
  20367. this.onProgress = onProgress;
  20368. this.onError = onError;
  20369. this.itemStart = function ( url ) {
  20370. itemsTotal ++;
  20371. if ( isLoading === false ) {
  20372. if ( scope.onStart !== undefined ) {
  20373. scope.onStart( url, itemsLoaded, itemsTotal );
  20374. }
  20375. }
  20376. isLoading = true;
  20377. };
  20378. this.itemEnd = function ( url ) {
  20379. itemsLoaded ++;
  20380. if ( scope.onProgress !== undefined ) {
  20381. scope.onProgress( url, itemsLoaded, itemsTotal );
  20382. }
  20383. if ( itemsLoaded === itemsTotal ) {
  20384. isLoading = false;
  20385. if ( scope.onLoad !== undefined ) {
  20386. scope.onLoad();
  20387. }
  20388. }
  20389. };
  20390. this.itemError = function ( url ) {
  20391. if ( scope.onError !== undefined ) {
  20392. scope.onError( url );
  20393. }
  20394. };
  20395. this.resolveURL = function ( url ) {
  20396. if ( urlModifier ) {
  20397. return urlModifier( url );
  20398. }
  20399. return url;
  20400. };
  20401. this.setURLModifier = function ( transform ) {
  20402. urlModifier = transform;
  20403. return this;
  20404. };
  20405. this.addHandler = function ( regex, loader ) {
  20406. handlers.push( regex, loader );
  20407. return this;
  20408. };
  20409. this.removeHandler = function ( regex ) {
  20410. const index = handlers.indexOf( regex );
  20411. if ( index !== - 1 ) {
  20412. handlers.splice( index, 2 );
  20413. }
  20414. return this;
  20415. };
  20416. this.getHandler = function ( file ) {
  20417. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  20418. const regex = handlers[ i ];
  20419. const loader = handlers[ i + 1 ];
  20420. if ( regex.global ) regex.lastIndex = 0; // see #17920
  20421. if ( regex.test( file ) ) {
  20422. return loader;
  20423. }
  20424. }
  20425. return null;
  20426. };
  20427. }
  20428. const DefaultLoadingManager = new LoadingManager();
  20429. function Loader( manager ) {
  20430. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20431. this.crossOrigin = 'anonymous';
  20432. this.withCredentials = false;
  20433. this.path = '';
  20434. this.resourcePath = '';
  20435. this.requestHeader = {};
  20436. }
  20437. Object.assign( Loader.prototype, {
  20438. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  20439. loadAsync: function ( url, onProgress ) {
  20440. const scope = this;
  20441. return new Promise( function ( resolve, reject ) {
  20442. scope.load( url, resolve, onProgress, reject );
  20443. } );
  20444. },
  20445. parse: function ( /* data */ ) {},
  20446. setCrossOrigin: function ( crossOrigin ) {
  20447. this.crossOrigin = crossOrigin;
  20448. return this;
  20449. },
  20450. setWithCredentials: function ( value ) {
  20451. this.withCredentials = value;
  20452. return this;
  20453. },
  20454. setPath: function ( path ) {
  20455. this.path = path;
  20456. return this;
  20457. },
  20458. setResourcePath: function ( resourcePath ) {
  20459. this.resourcePath = resourcePath;
  20460. return this;
  20461. },
  20462. setRequestHeader: function ( requestHeader ) {
  20463. this.requestHeader = requestHeader;
  20464. return this;
  20465. }
  20466. } );
  20467. const loading = {};
  20468. function FileLoader( manager ) {
  20469. Loader.call( this, manager );
  20470. }
  20471. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20472. constructor: FileLoader,
  20473. load: function ( url, onLoad, onProgress, onError ) {
  20474. if ( url === undefined ) url = '';
  20475. if ( this.path !== undefined ) url = this.path + url;
  20476. url = this.manager.resolveURL( url );
  20477. const scope = this;
  20478. const cached = Cache.get( url );
  20479. if ( cached !== undefined ) {
  20480. scope.manager.itemStart( url );
  20481. setTimeout( function () {
  20482. if ( onLoad ) onLoad( cached );
  20483. scope.manager.itemEnd( url );
  20484. }, 0 );
  20485. return cached;
  20486. }
  20487. // Check if request is duplicate
  20488. if ( loading[ url ] !== undefined ) {
  20489. loading[ url ].push( {
  20490. onLoad: onLoad,
  20491. onProgress: onProgress,
  20492. onError: onError
  20493. } );
  20494. return;
  20495. }
  20496. // Check for data: URI
  20497. const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20498. const dataUriRegexResult = url.match( dataUriRegex );
  20499. let request;
  20500. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20501. if ( dataUriRegexResult ) {
  20502. const mimeType = dataUriRegexResult[ 1 ];
  20503. const isBase64 = !! dataUriRegexResult[ 2 ];
  20504. let data = dataUriRegexResult[ 3 ];
  20505. data = decodeURIComponent( data );
  20506. if ( isBase64 ) data = atob( data );
  20507. try {
  20508. let response;
  20509. const responseType = ( this.responseType || '' ).toLowerCase();
  20510. switch ( responseType ) {
  20511. case 'arraybuffer':
  20512. case 'blob':
  20513. const view = new Uint8Array( data.length );
  20514. for ( let i = 0; i < data.length; i ++ ) {
  20515. view[ i ] = data.charCodeAt( i );
  20516. }
  20517. if ( responseType === 'blob' ) {
  20518. response = new Blob( [ view.buffer ], { type: mimeType } );
  20519. } else {
  20520. response = view.buffer;
  20521. }
  20522. break;
  20523. case 'document':
  20524. const parser = new DOMParser();
  20525. response = parser.parseFromString( data, mimeType );
  20526. break;
  20527. case 'json':
  20528. response = JSON.parse( data );
  20529. break;
  20530. default: // 'text' or other
  20531. response = data;
  20532. break;
  20533. }
  20534. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20535. setTimeout( function () {
  20536. if ( onLoad ) onLoad( response );
  20537. scope.manager.itemEnd( url );
  20538. }, 0 );
  20539. } catch ( error ) {
  20540. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20541. setTimeout( function () {
  20542. if ( onError ) onError( error );
  20543. scope.manager.itemError( url );
  20544. scope.manager.itemEnd( url );
  20545. }, 0 );
  20546. }
  20547. } else {
  20548. // Initialise array for duplicate requests
  20549. loading[ url ] = [];
  20550. loading[ url ].push( {
  20551. onLoad: onLoad,
  20552. onProgress: onProgress,
  20553. onError: onError
  20554. } );
  20555. request = new XMLHttpRequest();
  20556. request.open( 'GET', url, true );
  20557. request.addEventListener( 'load', function ( event ) {
  20558. const response = this.response;
  20559. const callbacks = loading[ url ];
  20560. delete loading[ url ];
  20561. if ( this.status === 200 || this.status === 0 ) {
  20562. // Some browsers return HTTP Status 0 when using non-http protocol
  20563. // e.g. 'file://' or 'data://'. Handle as success.
  20564. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20565. // Add to cache only on HTTP success, so that we do not cache
  20566. // error response bodies as proper responses to requests.
  20567. Cache.add( url, response );
  20568. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20569. const callback = callbacks[ i ];
  20570. if ( callback.onLoad ) callback.onLoad( response );
  20571. }
  20572. scope.manager.itemEnd( url );
  20573. } else {
  20574. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20575. const callback = callbacks[ i ];
  20576. if ( callback.onError ) callback.onError( event );
  20577. }
  20578. scope.manager.itemError( url );
  20579. scope.manager.itemEnd( url );
  20580. }
  20581. }, false );
  20582. request.addEventListener( 'progress', function ( event ) {
  20583. const callbacks = loading[ url ];
  20584. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20585. const callback = callbacks[ i ];
  20586. if ( callback.onProgress ) callback.onProgress( event );
  20587. }
  20588. }, false );
  20589. request.addEventListener( 'error', function ( event ) {
  20590. const callbacks = loading[ url ];
  20591. delete loading[ url ];
  20592. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20593. const callback = callbacks[ i ];
  20594. if ( callback.onError ) callback.onError( event );
  20595. }
  20596. scope.manager.itemError( url );
  20597. scope.manager.itemEnd( url );
  20598. }, false );
  20599. request.addEventListener( 'abort', function ( event ) {
  20600. const callbacks = loading[ url ];
  20601. delete loading[ url ];
  20602. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20603. const callback = callbacks[ i ];
  20604. if ( callback.onError ) callback.onError( event );
  20605. }
  20606. scope.manager.itemError( url );
  20607. scope.manager.itemEnd( url );
  20608. }, false );
  20609. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20610. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20611. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20612. for ( const header in this.requestHeader ) {
  20613. request.setRequestHeader( header, this.requestHeader[ header ] );
  20614. }
  20615. request.send( null );
  20616. }
  20617. scope.manager.itemStart( url );
  20618. return request;
  20619. },
  20620. setResponseType: function ( value ) {
  20621. this.responseType = value;
  20622. return this;
  20623. },
  20624. setMimeType: function ( value ) {
  20625. this.mimeType = value;
  20626. return this;
  20627. }
  20628. } );
  20629. class AnimationLoader extends Loader {
  20630. constructor( manager ) {
  20631. super( manager );
  20632. }
  20633. load( url, onLoad, onProgress, onError ) {
  20634. const scope = this;
  20635. const loader = new FileLoader( this.manager );
  20636. loader.setPath( this.path );
  20637. loader.setRequestHeader( this.requestHeader );
  20638. loader.setWithCredentials( this.withCredentials );
  20639. loader.load( url, function ( text ) {
  20640. try {
  20641. onLoad( scope.parse( JSON.parse( text ) ) );
  20642. } catch ( e ) {
  20643. if ( onError ) {
  20644. onError( e );
  20645. } else {
  20646. console.error( e );
  20647. }
  20648. scope.manager.itemError( url );
  20649. }
  20650. }, onProgress, onError );
  20651. }
  20652. parse( json ) {
  20653. const animations = [];
  20654. for ( let i = 0; i < json.length; i ++ ) {
  20655. const clip = AnimationClip.parse( json[ i ] );
  20656. animations.push( clip );
  20657. }
  20658. return animations;
  20659. }
  20660. }
  20661. /**
  20662. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20663. *
  20664. * Sub classes have to implement the parse() method which will be used in load().
  20665. */
  20666. function CompressedTextureLoader( manager ) {
  20667. Loader.call( this, manager );
  20668. }
  20669. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20670. constructor: CompressedTextureLoader,
  20671. load: function ( url, onLoad, onProgress, onError ) {
  20672. const scope = this;
  20673. const images = [];
  20674. const texture = new CompressedTexture();
  20675. const loader = new FileLoader( this.manager );
  20676. loader.setPath( this.path );
  20677. loader.setResponseType( 'arraybuffer' );
  20678. loader.setRequestHeader( this.requestHeader );
  20679. loader.setWithCredentials( scope.withCredentials );
  20680. let loaded = 0;
  20681. function loadTexture( i ) {
  20682. loader.load( url[ i ], function ( buffer ) {
  20683. const texDatas = scope.parse( buffer, true );
  20684. images[ i ] = {
  20685. width: texDatas.width,
  20686. height: texDatas.height,
  20687. format: texDatas.format,
  20688. mipmaps: texDatas.mipmaps
  20689. };
  20690. loaded += 1;
  20691. if ( loaded === 6 ) {
  20692. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  20693. texture.image = images;
  20694. texture.format = texDatas.format;
  20695. texture.needsUpdate = true;
  20696. if ( onLoad ) onLoad( texture );
  20697. }
  20698. }, onProgress, onError );
  20699. }
  20700. if ( Array.isArray( url ) ) {
  20701. for ( let i = 0, il = url.length; i < il; ++ i ) {
  20702. loadTexture( i );
  20703. }
  20704. } else {
  20705. // compressed cubemap texture stored in a single DDS file
  20706. loader.load( url, function ( buffer ) {
  20707. const texDatas = scope.parse( buffer, true );
  20708. if ( texDatas.isCubemap ) {
  20709. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20710. for ( let f = 0; f < faces; f ++ ) {
  20711. images[ f ] = { mipmaps: [] };
  20712. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  20713. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20714. images[ f ].format = texDatas.format;
  20715. images[ f ].width = texDatas.width;
  20716. images[ f ].height = texDatas.height;
  20717. }
  20718. }
  20719. texture.image = images;
  20720. } else {
  20721. texture.image.width = texDatas.width;
  20722. texture.image.height = texDatas.height;
  20723. texture.mipmaps = texDatas.mipmaps;
  20724. }
  20725. if ( texDatas.mipmapCount === 1 ) {
  20726. texture.minFilter = LinearFilter;
  20727. }
  20728. texture.format = texDatas.format;
  20729. texture.needsUpdate = true;
  20730. if ( onLoad ) onLoad( texture );
  20731. }, onProgress, onError );
  20732. }
  20733. return texture;
  20734. }
  20735. } );
  20736. class ImageLoader extends Loader {
  20737. constructor( manager ) {
  20738. super( manager );
  20739. }
  20740. load( url, onLoad, onProgress, onError ) {
  20741. if ( this.path !== undefined ) url = this.path + url;
  20742. url = this.manager.resolveURL( url );
  20743. const scope = this;
  20744. const cached = Cache.get( url );
  20745. if ( cached !== undefined ) {
  20746. scope.manager.itemStart( url );
  20747. setTimeout( function () {
  20748. if ( onLoad ) onLoad( cached );
  20749. scope.manager.itemEnd( url );
  20750. }, 0 );
  20751. return cached;
  20752. }
  20753. const image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20754. function onImageLoad() {
  20755. image.removeEventListener( 'load', onImageLoad, false );
  20756. image.removeEventListener( 'error', onImageError, false );
  20757. Cache.add( url, this );
  20758. if ( onLoad ) onLoad( this );
  20759. scope.manager.itemEnd( url );
  20760. }
  20761. function onImageError( event ) {
  20762. image.removeEventListener( 'load', onImageLoad, false );
  20763. image.removeEventListener( 'error', onImageError, false );
  20764. if ( onError ) onError( event );
  20765. scope.manager.itemError( url );
  20766. scope.manager.itemEnd( url );
  20767. }
  20768. image.addEventListener( 'load', onImageLoad, false );
  20769. image.addEventListener( 'error', onImageError, false );
  20770. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20771. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20772. }
  20773. scope.manager.itemStart( url );
  20774. image.src = url;
  20775. return image;
  20776. }
  20777. }
  20778. class CubeTextureLoader extends Loader {
  20779. constructor( manager ) {
  20780. super( manager );
  20781. }
  20782. load( urls, onLoad, onProgress, onError ) {
  20783. const texture = new CubeTexture();
  20784. const loader = new ImageLoader( this.manager );
  20785. loader.setCrossOrigin( this.crossOrigin );
  20786. loader.setPath( this.path );
  20787. let loaded = 0;
  20788. function loadTexture( i ) {
  20789. loader.load( urls[ i ], function ( image ) {
  20790. texture.images[ i ] = image;
  20791. loaded ++;
  20792. if ( loaded === 6 ) {
  20793. texture.needsUpdate = true;
  20794. if ( onLoad ) onLoad( texture );
  20795. }
  20796. }, undefined, onError );
  20797. }
  20798. for ( let i = 0; i < urls.length; ++ i ) {
  20799. loadTexture( i );
  20800. }
  20801. return texture;
  20802. }
  20803. }
  20804. /**
  20805. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20806. *
  20807. * Sub classes have to implement the parse() method which will be used in load().
  20808. */
  20809. function DataTextureLoader( manager ) {
  20810. Loader.call( this, manager );
  20811. }
  20812. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20813. constructor: DataTextureLoader,
  20814. load: function ( url, onLoad, onProgress, onError ) {
  20815. const scope = this;
  20816. const texture = new DataTexture();
  20817. const loader = new FileLoader( this.manager );
  20818. loader.setResponseType( 'arraybuffer' );
  20819. loader.setRequestHeader( this.requestHeader );
  20820. loader.setPath( this.path );
  20821. loader.setWithCredentials( scope.withCredentials );
  20822. loader.load( url, function ( buffer ) {
  20823. const texData = scope.parse( buffer );
  20824. if ( ! texData ) return;
  20825. if ( texData.image !== undefined ) {
  20826. texture.image = texData.image;
  20827. } else if ( texData.data !== undefined ) {
  20828. texture.image.width = texData.width;
  20829. texture.image.height = texData.height;
  20830. texture.image.data = texData.data;
  20831. }
  20832. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20833. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20834. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20835. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  20836. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20837. if ( texData.encoding !== undefined ) {
  20838. texture.encoding = texData.encoding;
  20839. }
  20840. if ( texData.flipY !== undefined ) {
  20841. texture.flipY = texData.flipY;
  20842. }
  20843. if ( texData.format !== undefined ) {
  20844. texture.format = texData.format;
  20845. }
  20846. if ( texData.type !== undefined ) {
  20847. texture.type = texData.type;
  20848. }
  20849. if ( texData.mipmaps !== undefined ) {
  20850. texture.mipmaps = texData.mipmaps;
  20851. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  20852. }
  20853. if ( texData.mipmapCount === 1 ) {
  20854. texture.minFilter = LinearFilter;
  20855. }
  20856. if ( texData.generateMipmaps !== undefined ) {
  20857. texture.generateMipmaps = texData.generateMipmaps;
  20858. }
  20859. texture.needsUpdate = true;
  20860. if ( onLoad ) onLoad( texture, texData );
  20861. }, onProgress, onError );
  20862. return texture;
  20863. }
  20864. } );
  20865. function TextureLoader( manager ) {
  20866. Loader.call( this, manager );
  20867. }
  20868. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20869. constructor: TextureLoader,
  20870. load: function ( url, onLoad, onProgress, onError ) {
  20871. const texture = new Texture();
  20872. const loader = new ImageLoader( this.manager );
  20873. loader.setCrossOrigin( this.crossOrigin );
  20874. loader.setPath( this.path );
  20875. loader.load( url, function ( image ) {
  20876. texture.image = image;
  20877. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20878. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20879. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20880. texture.needsUpdate = true;
  20881. if ( onLoad !== undefined ) {
  20882. onLoad( texture );
  20883. }
  20884. }, onProgress, onError );
  20885. return texture;
  20886. }
  20887. } );
  20888. /**
  20889. * Extensible curve object.
  20890. *
  20891. * Some common of curve methods:
  20892. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  20893. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  20894. * .getPoints(), .getSpacedPoints()
  20895. * .getLength()
  20896. * .updateArcLengths()
  20897. *
  20898. * This following curves inherit from THREE.Curve:
  20899. *
  20900. * -- 2D curves --
  20901. * THREE.ArcCurve
  20902. * THREE.CubicBezierCurve
  20903. * THREE.EllipseCurve
  20904. * THREE.LineCurve
  20905. * THREE.QuadraticBezierCurve
  20906. * THREE.SplineCurve
  20907. *
  20908. * -- 3D curves --
  20909. * THREE.CatmullRomCurve3
  20910. * THREE.CubicBezierCurve3
  20911. * THREE.LineCurve3
  20912. * THREE.QuadraticBezierCurve3
  20913. *
  20914. * A series of curves can be represented as a THREE.CurvePath.
  20915. *
  20916. **/
  20917. function Curve() {
  20918. this.type = 'Curve';
  20919. this.arcLengthDivisions = 200;
  20920. }
  20921. Object.assign( Curve.prototype, {
  20922. // Virtual base class method to overwrite and implement in subclasses
  20923. // - t [0 .. 1]
  20924. getPoint: function ( /* t, optionalTarget */ ) {
  20925. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20926. return null;
  20927. },
  20928. // Get point at relative position in curve according to arc length
  20929. // - u [0 .. 1]
  20930. getPointAt: function ( u, optionalTarget ) {
  20931. const t = this.getUtoTmapping( u );
  20932. return this.getPoint( t, optionalTarget );
  20933. },
  20934. // Get sequence of points using getPoint( t )
  20935. getPoints: function ( divisions = 5 ) {
  20936. const points = [];
  20937. for ( let d = 0; d <= divisions; d ++ ) {
  20938. points.push( this.getPoint( d / divisions ) );
  20939. }
  20940. return points;
  20941. },
  20942. // Get sequence of points using getPointAt( u )
  20943. getSpacedPoints: function ( divisions = 5 ) {
  20944. const points = [];
  20945. for ( let d = 0; d <= divisions; d ++ ) {
  20946. points.push( this.getPointAt( d / divisions ) );
  20947. }
  20948. return points;
  20949. },
  20950. // Get total curve arc length
  20951. getLength: function () {
  20952. const lengths = this.getLengths();
  20953. return lengths[ lengths.length - 1 ];
  20954. },
  20955. // Get list of cumulative segment lengths
  20956. getLengths: function ( divisions ) {
  20957. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20958. if ( this.cacheArcLengths &&
  20959. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20960. ! this.needsUpdate ) {
  20961. return this.cacheArcLengths;
  20962. }
  20963. this.needsUpdate = false;
  20964. const cache = [];
  20965. let current, last = this.getPoint( 0 );
  20966. let sum = 0;
  20967. cache.push( 0 );
  20968. for ( let p = 1; p <= divisions; p ++ ) {
  20969. current = this.getPoint( p / divisions );
  20970. sum += current.distanceTo( last );
  20971. cache.push( sum );
  20972. last = current;
  20973. }
  20974. this.cacheArcLengths = cache;
  20975. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  20976. },
  20977. updateArcLengths: function () {
  20978. this.needsUpdate = true;
  20979. this.getLengths();
  20980. },
  20981. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20982. getUtoTmapping: function ( u, distance ) {
  20983. const arcLengths = this.getLengths();
  20984. let i = 0;
  20985. const il = arcLengths.length;
  20986. let targetArcLength; // The targeted u distance value to get
  20987. if ( distance ) {
  20988. targetArcLength = distance;
  20989. } else {
  20990. targetArcLength = u * arcLengths[ il - 1 ];
  20991. }
  20992. // binary search for the index with largest value smaller than target u distance
  20993. let low = 0, high = il - 1, comparison;
  20994. while ( low <= high ) {
  20995. 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
  20996. comparison = arcLengths[ i ] - targetArcLength;
  20997. if ( comparison < 0 ) {
  20998. low = i + 1;
  20999. } else if ( comparison > 0 ) {
  21000. high = i - 1;
  21001. } else {
  21002. high = i;
  21003. break;
  21004. // DONE
  21005. }
  21006. }
  21007. i = high;
  21008. if ( arcLengths[ i ] === targetArcLength ) {
  21009. return i / ( il - 1 );
  21010. }
  21011. // we could get finer grain at lengths, or use simple interpolation between two points
  21012. const lengthBefore = arcLengths[ i ];
  21013. const lengthAfter = arcLengths[ i + 1 ];
  21014. const segmentLength = lengthAfter - lengthBefore;
  21015. // determine where we are between the 'before' and 'after' points
  21016. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21017. // add that fractional amount to t
  21018. const t = ( i + segmentFraction ) / ( il - 1 );
  21019. return t;
  21020. },
  21021. // Returns a unit vector tangent at t
  21022. // In case any sub curve does not implement its tangent derivation,
  21023. // 2 points a small delta apart will be used to find its gradient
  21024. // which seems to give a reasonable approximation
  21025. getTangent: function ( t, optionalTarget ) {
  21026. const delta = 0.0001;
  21027. let t1 = t - delta;
  21028. let t2 = t + delta;
  21029. // Capping in case of danger
  21030. if ( t1 < 0 ) t1 = 0;
  21031. if ( t2 > 1 ) t2 = 1;
  21032. const pt1 = this.getPoint( t1 );
  21033. const pt2 = this.getPoint( t2 );
  21034. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  21035. tangent.copy( pt2 ).sub( pt1 ).normalize();
  21036. return tangent;
  21037. },
  21038. getTangentAt: function ( u, optionalTarget ) {
  21039. const t = this.getUtoTmapping( u );
  21040. return this.getTangent( t, optionalTarget );
  21041. },
  21042. computeFrenetFrames: function ( segments, closed ) {
  21043. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21044. const normal = new Vector3();
  21045. const tangents = [];
  21046. const normals = [];
  21047. const binormals = [];
  21048. const vec = new Vector3();
  21049. const mat = new Matrix4();
  21050. // compute the tangent vectors for each segment on the curve
  21051. for ( let i = 0; i <= segments; i ++ ) {
  21052. const u = i / segments;
  21053. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  21054. tangents[ i ].normalize();
  21055. }
  21056. // select an initial normal vector perpendicular to the first tangent vector,
  21057. // and in the direction of the minimum tangent xyz component
  21058. normals[ 0 ] = new Vector3();
  21059. binormals[ 0 ] = new Vector3();
  21060. let min = Number.MAX_VALUE;
  21061. const tx = Math.abs( tangents[ 0 ].x );
  21062. const ty = Math.abs( tangents[ 0 ].y );
  21063. const tz = Math.abs( tangents[ 0 ].z );
  21064. if ( tx <= min ) {
  21065. min = tx;
  21066. normal.set( 1, 0, 0 );
  21067. }
  21068. if ( ty <= min ) {
  21069. min = ty;
  21070. normal.set( 0, 1, 0 );
  21071. }
  21072. if ( tz <= min ) {
  21073. normal.set( 0, 0, 1 );
  21074. }
  21075. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21076. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21077. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21078. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21079. for ( let i = 1; i <= segments; i ++ ) {
  21080. normals[ i ] = normals[ i - 1 ].clone();
  21081. binormals[ i ] = binormals[ i - 1 ].clone();
  21082. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21083. if ( vec.length() > Number.EPSILON ) {
  21084. vec.normalize();
  21085. const theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21086. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21087. }
  21088. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21089. }
  21090. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21091. if ( closed === true ) {
  21092. let theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21093. theta /= segments;
  21094. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21095. theta = - theta;
  21096. }
  21097. for ( let i = 1; i <= segments; i ++ ) {
  21098. // twist a little...
  21099. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21100. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21101. }
  21102. }
  21103. return {
  21104. tangents: tangents,
  21105. normals: normals,
  21106. binormals: binormals
  21107. };
  21108. },
  21109. clone: function () {
  21110. return new this.constructor().copy( this );
  21111. },
  21112. copy: function ( source ) {
  21113. this.arcLengthDivisions = source.arcLengthDivisions;
  21114. return this;
  21115. },
  21116. toJSON: function () {
  21117. const data = {
  21118. metadata: {
  21119. version: 4.5,
  21120. type: 'Curve',
  21121. generator: 'Curve.toJSON'
  21122. }
  21123. };
  21124. data.arcLengthDivisions = this.arcLengthDivisions;
  21125. data.type = this.type;
  21126. return data;
  21127. },
  21128. fromJSON: function ( json ) {
  21129. this.arcLengthDivisions = json.arcLengthDivisions;
  21130. return this;
  21131. }
  21132. } );
  21133. class EllipseCurve extends Curve {
  21134. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  21135. super();
  21136. this.type = 'EllipseCurve';
  21137. this.aX = aX;
  21138. this.aY = aY;
  21139. this.xRadius = xRadius;
  21140. this.yRadius = yRadius;
  21141. this.aStartAngle = aStartAngle;
  21142. this.aEndAngle = aEndAngle;
  21143. this.aClockwise = aClockwise;
  21144. this.aRotation = aRotation;
  21145. }
  21146. getPoint( t, optionalTarget ) {
  21147. const point = optionalTarget || new Vector2();
  21148. const twoPi = Math.PI * 2;
  21149. let deltaAngle = this.aEndAngle - this.aStartAngle;
  21150. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21151. // ensures that deltaAngle is 0 .. 2 PI
  21152. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21153. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21154. if ( deltaAngle < Number.EPSILON ) {
  21155. if ( samePoints ) {
  21156. deltaAngle = 0;
  21157. } else {
  21158. deltaAngle = twoPi;
  21159. }
  21160. }
  21161. if ( this.aClockwise === true && ! samePoints ) {
  21162. if ( deltaAngle === twoPi ) {
  21163. deltaAngle = - twoPi;
  21164. } else {
  21165. deltaAngle = deltaAngle - twoPi;
  21166. }
  21167. }
  21168. const angle = this.aStartAngle + t * deltaAngle;
  21169. let x = this.aX + this.xRadius * Math.cos( angle );
  21170. let y = this.aY + this.yRadius * Math.sin( angle );
  21171. if ( this.aRotation !== 0 ) {
  21172. const cos = Math.cos( this.aRotation );
  21173. const sin = Math.sin( this.aRotation );
  21174. const tx = x - this.aX;
  21175. const ty = y - this.aY;
  21176. // Rotate the point about the center of the ellipse.
  21177. x = tx * cos - ty * sin + this.aX;
  21178. y = tx * sin + ty * cos + this.aY;
  21179. }
  21180. return point.set( x, y );
  21181. }
  21182. copy( source ) {
  21183. super.copy( source );
  21184. this.aX = source.aX;
  21185. this.aY = source.aY;
  21186. this.xRadius = source.xRadius;
  21187. this.yRadius = source.yRadius;
  21188. this.aStartAngle = source.aStartAngle;
  21189. this.aEndAngle = source.aEndAngle;
  21190. this.aClockwise = source.aClockwise;
  21191. this.aRotation = source.aRotation;
  21192. return this;
  21193. }
  21194. toJSON() {
  21195. const data = super.toJSON();
  21196. data.aX = this.aX;
  21197. data.aY = this.aY;
  21198. data.xRadius = this.xRadius;
  21199. data.yRadius = this.yRadius;
  21200. data.aStartAngle = this.aStartAngle;
  21201. data.aEndAngle = this.aEndAngle;
  21202. data.aClockwise = this.aClockwise;
  21203. data.aRotation = this.aRotation;
  21204. return data;
  21205. }
  21206. fromJSON( json ) {
  21207. super.fromJSON( json );
  21208. this.aX = json.aX;
  21209. this.aY = json.aY;
  21210. this.xRadius = json.xRadius;
  21211. this.yRadius = json.yRadius;
  21212. this.aStartAngle = json.aStartAngle;
  21213. this.aEndAngle = json.aEndAngle;
  21214. this.aClockwise = json.aClockwise;
  21215. this.aRotation = json.aRotation;
  21216. return this;
  21217. }
  21218. }
  21219. EllipseCurve.prototype.isEllipseCurve = true;
  21220. class ArcCurve extends EllipseCurve {
  21221. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21222. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21223. this.type = 'ArcCurve';
  21224. }
  21225. }
  21226. ArcCurve.prototype.isArcCurve = true;
  21227. /**
  21228. * Centripetal CatmullRom Curve - which is useful for avoiding
  21229. * cusps and self-intersections in non-uniform catmull rom curves.
  21230. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21231. *
  21232. * curve.type accepts centripetal(default), chordal and catmullrom
  21233. * curve.tension is used for catmullrom which defaults to 0.5
  21234. */
  21235. /*
  21236. Based on an optimized c++ solution in
  21237. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21238. - http://ideone.com/NoEbVM
  21239. This CubicPoly class could be used for reusing some variables and calculations,
  21240. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21241. which can be placed in CurveUtils.
  21242. */
  21243. function CubicPoly() {
  21244. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21245. /*
  21246. * Compute coefficients for a cubic polynomial
  21247. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21248. * such that
  21249. * p(0) = x0, p(1) = x1
  21250. * and
  21251. * p'(0) = t0, p'(1) = t1.
  21252. */
  21253. function init( x0, x1, t0, t1 ) {
  21254. c0 = x0;
  21255. c1 = t0;
  21256. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21257. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21258. }
  21259. return {
  21260. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21261. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21262. },
  21263. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21264. // compute tangents when parameterized in [t1,t2]
  21265. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21266. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21267. // rescale tangents for parametrization in [0,1]
  21268. t1 *= dt1;
  21269. t2 *= dt1;
  21270. init( x1, x2, t1, t2 );
  21271. },
  21272. calc: function ( t ) {
  21273. const t2 = t * t;
  21274. const t3 = t2 * t;
  21275. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21276. }
  21277. };
  21278. }
  21279. //
  21280. const tmp = new Vector3();
  21281. const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21282. class CatmullRomCurve3 extends Curve {
  21283. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  21284. super();
  21285. this.type = 'CatmullRomCurve3';
  21286. this.points = points;
  21287. this.closed = closed;
  21288. this.curveType = curveType;
  21289. this.tension = tension;
  21290. }
  21291. getPoint( t, optionalTarget = new Vector3() ) {
  21292. const point = optionalTarget;
  21293. const points = this.points;
  21294. const l = points.length;
  21295. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21296. let intPoint = Math.floor( p );
  21297. let weight = p - intPoint;
  21298. if ( this.closed ) {
  21299. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21300. } else if ( weight === 0 && intPoint === l - 1 ) {
  21301. intPoint = l - 2;
  21302. weight = 1;
  21303. }
  21304. let p0, p3; // 4 points (p1 & p2 defined below)
  21305. if ( this.closed || intPoint > 0 ) {
  21306. p0 = points[ ( intPoint - 1 ) % l ];
  21307. } else {
  21308. // extrapolate first point
  21309. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21310. p0 = tmp;
  21311. }
  21312. const p1 = points[ intPoint % l ];
  21313. const p2 = points[ ( intPoint + 1 ) % l ];
  21314. if ( this.closed || intPoint + 2 < l ) {
  21315. p3 = points[ ( intPoint + 2 ) % l ];
  21316. } else {
  21317. // extrapolate last point
  21318. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21319. p3 = tmp;
  21320. }
  21321. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21322. // init Centripetal / Chordal Catmull-Rom
  21323. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21324. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21325. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21326. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21327. // safety check for repeated points
  21328. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21329. if ( dt0 < 1e-4 ) dt0 = dt1;
  21330. if ( dt2 < 1e-4 ) dt2 = dt1;
  21331. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21332. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21333. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21334. } else if ( this.curveType === 'catmullrom' ) {
  21335. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21336. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21337. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21338. }
  21339. point.set(
  21340. px.calc( weight ),
  21341. py.calc( weight ),
  21342. pz.calc( weight )
  21343. );
  21344. return point;
  21345. }
  21346. copy( source ) {
  21347. super.copy( source );
  21348. this.points = [];
  21349. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  21350. const point = source.points[ i ];
  21351. this.points.push( point.clone() );
  21352. }
  21353. this.closed = source.closed;
  21354. this.curveType = source.curveType;
  21355. this.tension = source.tension;
  21356. return this;
  21357. }
  21358. toJSON() {
  21359. const data = super.toJSON();
  21360. data.points = [];
  21361. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  21362. const point = this.points[ i ];
  21363. data.points.push( point.toArray() );
  21364. }
  21365. data.closed = this.closed;
  21366. data.curveType = this.curveType;
  21367. data.tension = this.tension;
  21368. return data;
  21369. }
  21370. fromJSON( json ) {
  21371. super.fromJSON( json );
  21372. this.points = [];
  21373. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  21374. const point = json.points[ i ];
  21375. this.points.push( new Vector3().fromArray( point ) );
  21376. }
  21377. this.closed = json.closed;
  21378. this.curveType = json.curveType;
  21379. this.tension = json.tension;
  21380. return this;
  21381. }
  21382. }
  21383. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21384. /**
  21385. * Bezier Curves formulas obtained from
  21386. * http://en.wikipedia.org/wiki/Bézier_curve
  21387. */
  21388. function CatmullRom( t, p0, p1, p2, p3 ) {
  21389. const v0 = ( p2 - p0 ) * 0.5;
  21390. const v1 = ( p3 - p1 ) * 0.5;
  21391. const t2 = t * t;
  21392. const t3 = t * t2;
  21393. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21394. }
  21395. //
  21396. function QuadraticBezierP0( t, p ) {
  21397. const k = 1 - t;
  21398. return k * k * p;
  21399. }
  21400. function QuadraticBezierP1( t, p ) {
  21401. return 2 * ( 1 - t ) * t * p;
  21402. }
  21403. function QuadraticBezierP2( t, p ) {
  21404. return t * t * p;
  21405. }
  21406. function QuadraticBezier( t, p0, p1, p2 ) {
  21407. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21408. QuadraticBezierP2( t, p2 );
  21409. }
  21410. //
  21411. function CubicBezierP0( t, p ) {
  21412. const k = 1 - t;
  21413. return k * k * k * p;
  21414. }
  21415. function CubicBezierP1( t, p ) {
  21416. const k = 1 - t;
  21417. return 3 * k * k * t * p;
  21418. }
  21419. function CubicBezierP2( t, p ) {
  21420. return 3 * ( 1 - t ) * t * t * p;
  21421. }
  21422. function CubicBezierP3( t, p ) {
  21423. return t * t * t * p;
  21424. }
  21425. function CubicBezier( t, p0, p1, p2, p3 ) {
  21426. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21427. CubicBezierP3( t, p3 );
  21428. }
  21429. class CubicBezierCurve extends Curve {
  21430. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  21431. super();
  21432. this.type = 'CubicBezierCurve';
  21433. this.v0 = v0;
  21434. this.v1 = v1;
  21435. this.v2 = v2;
  21436. this.v3 = v3;
  21437. }
  21438. getPoint( t, optionalTarget = new Vector2() ) {
  21439. const point = optionalTarget;
  21440. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21441. point.set(
  21442. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21443. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21444. );
  21445. return point;
  21446. }
  21447. copy( source ) {
  21448. super.copy( source );
  21449. this.v0.copy( source.v0 );
  21450. this.v1.copy( source.v1 );
  21451. this.v2.copy( source.v2 );
  21452. this.v3.copy( source.v3 );
  21453. return this;
  21454. }
  21455. toJSON() {
  21456. const data = super.toJSON();
  21457. data.v0 = this.v0.toArray();
  21458. data.v1 = this.v1.toArray();
  21459. data.v2 = this.v2.toArray();
  21460. data.v3 = this.v3.toArray();
  21461. return data;
  21462. }
  21463. fromJSON( json ) {
  21464. super.fromJSON( json );
  21465. this.v0.fromArray( json.v0 );
  21466. this.v1.fromArray( json.v1 );
  21467. this.v2.fromArray( json.v2 );
  21468. this.v3.fromArray( json.v3 );
  21469. return this;
  21470. }
  21471. }
  21472. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21473. class CubicBezierCurve3 extends Curve {
  21474. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  21475. super();
  21476. this.type = 'CubicBezierCurve3';
  21477. this.v0 = v0;
  21478. this.v1 = v1;
  21479. this.v2 = v2;
  21480. this.v3 = v3;
  21481. }
  21482. getPoint( t, optionalTarget = new Vector3() ) {
  21483. const point = optionalTarget;
  21484. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21485. point.set(
  21486. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21487. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21488. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21489. );
  21490. return point;
  21491. }
  21492. copy( source ) {
  21493. super.copy( source );
  21494. this.v0.copy( source.v0 );
  21495. this.v1.copy( source.v1 );
  21496. this.v2.copy( source.v2 );
  21497. this.v3.copy( source.v3 );
  21498. return this;
  21499. }
  21500. toJSON() {
  21501. const data = super.toJSON();
  21502. data.v0 = this.v0.toArray();
  21503. data.v1 = this.v1.toArray();
  21504. data.v2 = this.v2.toArray();
  21505. data.v3 = this.v3.toArray();
  21506. return data;
  21507. }
  21508. fromJSON( json ) {
  21509. super.fromJSON( json );
  21510. this.v0.fromArray( json.v0 );
  21511. this.v1.fromArray( json.v1 );
  21512. this.v2.fromArray( json.v2 );
  21513. this.v3.fromArray( json.v3 );
  21514. return this;
  21515. }
  21516. }
  21517. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21518. class LineCurve extends Curve {
  21519. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  21520. super();
  21521. this.type = 'LineCurve';
  21522. this.v1 = v1;
  21523. this.v2 = v2;
  21524. }
  21525. getPoint( t, optionalTarget = new Vector2() ) {
  21526. const point = optionalTarget;
  21527. if ( t === 1 ) {
  21528. point.copy( this.v2 );
  21529. } else {
  21530. point.copy( this.v2 ).sub( this.v1 );
  21531. point.multiplyScalar( t ).add( this.v1 );
  21532. }
  21533. return point;
  21534. }
  21535. // Line curve is linear, so we can overwrite default getPointAt
  21536. getPointAt( u, optionalTarget ) {
  21537. return this.getPoint( u, optionalTarget );
  21538. }
  21539. getTangent( t, optionalTarget ) {
  21540. const tangent = optionalTarget || new Vector2();
  21541. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  21542. return tangent;
  21543. }
  21544. copy( source ) {
  21545. super.copy( source );
  21546. this.v1.copy( source.v1 );
  21547. this.v2.copy( source.v2 );
  21548. return this;
  21549. }
  21550. toJSON() {
  21551. const data = super.toJSON();
  21552. data.v1 = this.v1.toArray();
  21553. data.v2 = this.v2.toArray();
  21554. return data;
  21555. }
  21556. fromJSON( json ) {
  21557. super.fromJSON( json );
  21558. this.v1.fromArray( json.v1 );
  21559. this.v2.fromArray( json.v2 );
  21560. return this;
  21561. }
  21562. }
  21563. LineCurve.prototype.isLineCurve = true;
  21564. class LineCurve3 extends Curve {
  21565. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  21566. super();
  21567. this.type = 'LineCurve3';
  21568. this.isLineCurve3 = true;
  21569. this.v1 = v1;
  21570. this.v2 = v2;
  21571. }
  21572. getPoint( t, optionalTarget = new Vector3() ) {
  21573. const point = optionalTarget;
  21574. if ( t === 1 ) {
  21575. point.copy( this.v2 );
  21576. } else {
  21577. point.copy( this.v2 ).sub( this.v1 );
  21578. point.multiplyScalar( t ).add( this.v1 );
  21579. }
  21580. return point;
  21581. }
  21582. // Line curve is linear, so we can overwrite default getPointAt
  21583. getPointAt( u, optionalTarget ) {
  21584. return this.getPoint( u, optionalTarget );
  21585. }
  21586. copy( source ) {
  21587. super.copy( source );
  21588. this.v1.copy( source.v1 );
  21589. this.v2.copy( source.v2 );
  21590. return this;
  21591. }
  21592. toJSON() {
  21593. const data = super.toJSON();
  21594. data.v1 = this.v1.toArray();
  21595. data.v2 = this.v2.toArray();
  21596. return data;
  21597. }
  21598. fromJSON( json ) {
  21599. super.fromJSON( json );
  21600. this.v1.fromArray( json.v1 );
  21601. this.v2.fromArray( json.v2 );
  21602. return this;
  21603. }
  21604. }
  21605. class QuadraticBezierCurve extends Curve {
  21606. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  21607. super();
  21608. this.type = 'QuadraticBezierCurve';
  21609. this.v0 = v0;
  21610. this.v1 = v1;
  21611. this.v2 = v2;
  21612. }
  21613. getPoint( t, optionalTarget = new Vector2() ) {
  21614. const point = optionalTarget;
  21615. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21616. point.set(
  21617. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21618. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21619. );
  21620. return point;
  21621. }
  21622. copy( source ) {
  21623. super.copy( source );
  21624. this.v0.copy( source.v0 );
  21625. this.v1.copy( source.v1 );
  21626. this.v2.copy( source.v2 );
  21627. return this;
  21628. }
  21629. toJSON() {
  21630. const data = super.toJSON();
  21631. data.v0 = this.v0.toArray();
  21632. data.v1 = this.v1.toArray();
  21633. data.v2 = this.v2.toArray();
  21634. return data;
  21635. }
  21636. fromJSON( json ) {
  21637. super.fromJSON( json );
  21638. this.v0.fromArray( json.v0 );
  21639. this.v1.fromArray( json.v1 );
  21640. this.v2.fromArray( json.v2 );
  21641. return this;
  21642. }
  21643. }
  21644. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21645. class QuadraticBezierCurve3 extends Curve {
  21646. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  21647. super();
  21648. this.type = 'QuadraticBezierCurve3';
  21649. this.v0 = v0;
  21650. this.v1 = v1;
  21651. this.v2 = v2;
  21652. }
  21653. getPoint( t, optionalTarget = new Vector3() ) {
  21654. const point = optionalTarget;
  21655. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21656. point.set(
  21657. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21658. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21659. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21660. );
  21661. return point;
  21662. }
  21663. copy( source ) {
  21664. super.copy( source );
  21665. this.v0.copy( source.v0 );
  21666. this.v1.copy( source.v1 );
  21667. this.v2.copy( source.v2 );
  21668. return this;
  21669. }
  21670. toJSON() {
  21671. const data = super.toJSON();
  21672. data.v0 = this.v0.toArray();
  21673. data.v1 = this.v1.toArray();
  21674. data.v2 = this.v2.toArray();
  21675. return data;
  21676. }
  21677. fromJSON( json ) {
  21678. super.fromJSON( json );
  21679. this.v0.fromArray( json.v0 );
  21680. this.v1.fromArray( json.v1 );
  21681. this.v2.fromArray( json.v2 );
  21682. return this;
  21683. }
  21684. }
  21685. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21686. class SplineCurve extends Curve {
  21687. constructor( points = [] ) {
  21688. super();
  21689. this.type = 'SplineCurve';
  21690. this.points = points;
  21691. }
  21692. getPoint( t, optionalTarget = new Vector2() ) {
  21693. const point = optionalTarget;
  21694. const points = this.points;
  21695. const p = ( points.length - 1 ) * t;
  21696. const intPoint = Math.floor( p );
  21697. const weight = p - intPoint;
  21698. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21699. const p1 = points[ intPoint ];
  21700. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21701. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21702. point.set(
  21703. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21704. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21705. );
  21706. return point;
  21707. }
  21708. copy( source ) {
  21709. super.copy( source );
  21710. this.points = [];
  21711. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  21712. const point = source.points[ i ];
  21713. this.points.push( point.clone() );
  21714. }
  21715. return this;
  21716. }
  21717. toJSON() {
  21718. const data = super.toJSON();
  21719. data.points = [];
  21720. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  21721. const point = this.points[ i ];
  21722. data.points.push( point.toArray() );
  21723. }
  21724. return data;
  21725. }
  21726. fromJSON( json ) {
  21727. super.fromJSON( json );
  21728. this.points = [];
  21729. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  21730. const point = json.points[ i ];
  21731. this.points.push( new Vector2().fromArray( point ) );
  21732. }
  21733. return this;
  21734. }
  21735. }
  21736. SplineCurve.prototype.isSplineCurve = true;
  21737. var Curves = /*#__PURE__*/Object.freeze({
  21738. __proto__: null,
  21739. ArcCurve: ArcCurve,
  21740. CatmullRomCurve3: CatmullRomCurve3,
  21741. CubicBezierCurve: CubicBezierCurve,
  21742. CubicBezierCurve3: CubicBezierCurve3,
  21743. EllipseCurve: EllipseCurve,
  21744. LineCurve: LineCurve,
  21745. LineCurve3: LineCurve3,
  21746. QuadraticBezierCurve: QuadraticBezierCurve,
  21747. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21748. SplineCurve: SplineCurve
  21749. });
  21750. /**************************************************************
  21751. * Curved Path - a curve path is simply a array of connected
  21752. * curves, but retains the api of a curve
  21753. **************************************************************/
  21754. class CurvePath extends Curve {
  21755. constructor() {
  21756. super();
  21757. this.type = 'CurvePath';
  21758. this.curves = [];
  21759. this.autoClose = false; // Automatically closes the path
  21760. }
  21761. add( curve ) {
  21762. this.curves.push( curve );
  21763. }
  21764. closePath() {
  21765. // Add a line curve if start and end of lines are not connected
  21766. const startPoint = this.curves[ 0 ].getPoint( 0 );
  21767. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21768. if ( ! startPoint.equals( endPoint ) ) {
  21769. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21770. }
  21771. }
  21772. // To get accurate point with reference to
  21773. // entire path distance at time t,
  21774. // following has to be done:
  21775. // 1. Length of each sub path have to be known
  21776. // 2. Locate and identify type of curve
  21777. // 3. Get t for the curve
  21778. // 4. Return curve.getPointAt(t')
  21779. getPoint( t ) {
  21780. const d = t * this.getLength();
  21781. const curveLengths = this.getCurveLengths();
  21782. let i = 0;
  21783. // To think about boundaries points.
  21784. while ( i < curveLengths.length ) {
  21785. if ( curveLengths[ i ] >= d ) {
  21786. const diff = curveLengths[ i ] - d;
  21787. const curve = this.curves[ i ];
  21788. const segmentLength = curve.getLength();
  21789. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21790. return curve.getPointAt( u );
  21791. }
  21792. i ++;
  21793. }
  21794. return null;
  21795. // loop where sum != 0, sum > d , sum+1 <d
  21796. }
  21797. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21798. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21799. // getPoint() depends on getLength
  21800. getLength() {
  21801. const lens = this.getCurveLengths();
  21802. return lens[ lens.length - 1 ];
  21803. }
  21804. // cacheLengths must be recalculated.
  21805. updateArcLengths() {
  21806. this.needsUpdate = true;
  21807. this.cacheLengths = null;
  21808. this.getCurveLengths();
  21809. }
  21810. // Compute lengths and cache them
  21811. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21812. getCurveLengths() {
  21813. // We use cache values if curves and cache array are same length
  21814. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21815. return this.cacheLengths;
  21816. }
  21817. // Get length of sub-curve
  21818. // Push sums into cached array
  21819. const lengths = [];
  21820. let sums = 0;
  21821. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  21822. sums += this.curves[ i ].getLength();
  21823. lengths.push( sums );
  21824. }
  21825. this.cacheLengths = lengths;
  21826. return lengths;
  21827. }
  21828. getSpacedPoints( divisions = 40 ) {
  21829. const points = [];
  21830. for ( let i = 0; i <= divisions; i ++ ) {
  21831. points.push( this.getPoint( i / divisions ) );
  21832. }
  21833. if ( this.autoClose ) {
  21834. points.push( points[ 0 ] );
  21835. }
  21836. return points;
  21837. }
  21838. getPoints( divisions = 12 ) {
  21839. const points = [];
  21840. let last;
  21841. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21842. const curve = curves[ i ];
  21843. const resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21844. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21845. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21846. : divisions;
  21847. const pts = curve.getPoints( resolution );
  21848. for ( let j = 0; j < pts.length; j ++ ) {
  21849. const point = pts[ j ];
  21850. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21851. points.push( point );
  21852. last = point;
  21853. }
  21854. }
  21855. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21856. points.push( points[ 0 ] );
  21857. }
  21858. return points;
  21859. }
  21860. copy( source ) {
  21861. super.copy( source );
  21862. this.curves = [];
  21863. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  21864. const curve = source.curves[ i ];
  21865. this.curves.push( curve.clone() );
  21866. }
  21867. this.autoClose = source.autoClose;
  21868. return this;
  21869. }
  21870. toJSON() {
  21871. const data = super.toJSON();
  21872. data.autoClose = this.autoClose;
  21873. data.curves = [];
  21874. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  21875. const curve = this.curves[ i ];
  21876. data.curves.push( curve.toJSON() );
  21877. }
  21878. return data;
  21879. }
  21880. fromJSON( json ) {
  21881. super.fromJSON( json );
  21882. this.autoClose = json.autoClose;
  21883. this.curves = [];
  21884. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  21885. const curve = json.curves[ i ];
  21886. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21887. }
  21888. return this;
  21889. }
  21890. }
  21891. class Path extends CurvePath {
  21892. constructor( points ) {
  21893. super();
  21894. this.type = 'Path';
  21895. this.currentPoint = new Vector2();
  21896. if ( points ) {
  21897. this.setFromPoints( points );
  21898. }
  21899. }
  21900. setFromPoints( points ) {
  21901. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  21902. for ( let i = 1, l = points.length; i < l; i ++ ) {
  21903. this.lineTo( points[ i ].x, points[ i ].y );
  21904. }
  21905. return this;
  21906. }
  21907. moveTo( x, y ) {
  21908. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21909. return this;
  21910. }
  21911. lineTo( x, y ) {
  21912. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21913. this.curves.push( curve );
  21914. this.currentPoint.set( x, y );
  21915. return this;
  21916. }
  21917. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21918. const curve = new QuadraticBezierCurve(
  21919. this.currentPoint.clone(),
  21920. new Vector2( aCPx, aCPy ),
  21921. new Vector2( aX, aY )
  21922. );
  21923. this.curves.push( curve );
  21924. this.currentPoint.set( aX, aY );
  21925. return this;
  21926. }
  21927. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21928. const curve = new CubicBezierCurve(
  21929. this.currentPoint.clone(),
  21930. new Vector2( aCP1x, aCP1y ),
  21931. new Vector2( aCP2x, aCP2y ),
  21932. new Vector2( aX, aY )
  21933. );
  21934. this.curves.push( curve );
  21935. this.currentPoint.set( aX, aY );
  21936. return this;
  21937. }
  21938. splineThru( pts /*Array of Vector*/ ) {
  21939. const npts = [ this.currentPoint.clone() ].concat( pts );
  21940. const curve = new SplineCurve( npts );
  21941. this.curves.push( curve );
  21942. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21943. return this;
  21944. }
  21945. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21946. const x0 = this.currentPoint.x;
  21947. const y0 = this.currentPoint.y;
  21948. this.absarc( aX + x0, aY + y0, aRadius,
  21949. aStartAngle, aEndAngle, aClockwise );
  21950. return this;
  21951. }
  21952. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21953. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21954. return this;
  21955. }
  21956. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21957. const x0 = this.currentPoint.x;
  21958. const y0 = this.currentPoint.y;
  21959. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21960. return this;
  21961. }
  21962. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21963. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21964. if ( this.curves.length > 0 ) {
  21965. // if a previous curve is present, attempt to join
  21966. const firstPoint = curve.getPoint( 0 );
  21967. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21968. this.lineTo( firstPoint.x, firstPoint.y );
  21969. }
  21970. }
  21971. this.curves.push( curve );
  21972. const lastPoint = curve.getPoint( 1 );
  21973. this.currentPoint.copy( lastPoint );
  21974. return this;
  21975. }
  21976. copy( source ) {
  21977. super.copy( source );
  21978. this.currentPoint.copy( source.currentPoint );
  21979. return this;
  21980. }
  21981. toJSON() {
  21982. const data = super.toJSON();
  21983. data.currentPoint = this.currentPoint.toArray();
  21984. return data;
  21985. }
  21986. fromJSON( json ) {
  21987. super.fromJSON( json );
  21988. this.currentPoint.fromArray( json.currentPoint );
  21989. return this;
  21990. }
  21991. }
  21992. class Shape extends Path {
  21993. constructor( points ) {
  21994. super( points );
  21995. this.uuid = MathUtils.generateUUID();
  21996. this.type = 'Shape';
  21997. this.holes = [];
  21998. }
  21999. getPointsHoles( divisions ) {
  22000. const holesPts = [];
  22001. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  22002. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22003. }
  22004. return holesPts;
  22005. }
  22006. // get points of shape and holes (keypoints based on segments parameter)
  22007. extractPoints( divisions ) {
  22008. return {
  22009. shape: this.getPoints( divisions ),
  22010. holes: this.getPointsHoles( divisions )
  22011. };
  22012. }
  22013. copy( source ) {
  22014. super.copy( source );
  22015. this.holes = [];
  22016. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  22017. const hole = source.holes[ i ];
  22018. this.holes.push( hole.clone() );
  22019. }
  22020. return this;
  22021. }
  22022. toJSON() {
  22023. const data = super.toJSON();
  22024. data.uuid = this.uuid;
  22025. data.holes = [];
  22026. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  22027. const hole = this.holes[ i ];
  22028. data.holes.push( hole.toJSON() );
  22029. }
  22030. return data;
  22031. }
  22032. fromJSON( json ) {
  22033. super.fromJSON( json );
  22034. this.uuid = json.uuid;
  22035. this.holes = [];
  22036. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  22037. const hole = json.holes[ i ];
  22038. this.holes.push( new Path().fromJSON( hole ) );
  22039. }
  22040. return this;
  22041. }
  22042. }
  22043. class Light extends Object3D {
  22044. constructor( color, intensity = 1 ) {
  22045. super();
  22046. this.type = 'Light';
  22047. this.color = new Color( color );
  22048. this.intensity = intensity;
  22049. }
  22050. copy( source ) {
  22051. super.copy( source );
  22052. this.color.copy( source.color );
  22053. this.intensity = source.intensity;
  22054. return this;
  22055. }
  22056. toJSON( meta ) {
  22057. const data = super.toJSON( meta );
  22058. data.object.color = this.color.getHex();
  22059. data.object.intensity = this.intensity;
  22060. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22061. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22062. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22063. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22064. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22065. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22066. return data;
  22067. }
  22068. }
  22069. Light.prototype.isLight = true;
  22070. class HemisphereLight extends Light {
  22071. constructor( skyColor, groundColor, intensity ) {
  22072. super( skyColor, intensity );
  22073. this.type = 'HemisphereLight';
  22074. this.position.copy( Object3D.DefaultUp );
  22075. this.updateMatrix();
  22076. this.groundColor = new Color( groundColor );
  22077. }
  22078. copy( source ) {
  22079. Light.prototype.copy.call( this, source );
  22080. this.groundColor.copy( source.groundColor );
  22081. return this;
  22082. }
  22083. }
  22084. HemisphereLight.prototype.isHemisphereLight = true;
  22085. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  22086. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  22087. const _lookTarget = /*@__PURE__*/ new Vector3();
  22088. class LightShadow {
  22089. constructor( camera ) {
  22090. this.camera = camera;
  22091. this.bias = 0;
  22092. this.normalBias = 0;
  22093. this.radius = 1;
  22094. this.mapSize = new Vector2( 512, 512 );
  22095. this.map = null;
  22096. this.mapPass = null;
  22097. this.matrix = new Matrix4();
  22098. this.autoUpdate = true;
  22099. this.needsUpdate = false;
  22100. this._frustum = new Frustum();
  22101. this._frameExtents = new Vector2( 1, 1 );
  22102. this._viewportCount = 1;
  22103. this._viewports = [
  22104. new Vector4( 0, 0, 1, 1 )
  22105. ];
  22106. }
  22107. getViewportCount() {
  22108. return this._viewportCount;
  22109. }
  22110. getFrustum() {
  22111. return this._frustum;
  22112. }
  22113. updateMatrices( light ) {
  22114. const shadowCamera = this.camera;
  22115. const shadowMatrix = this.matrix;
  22116. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  22117. shadowCamera.position.copy( _lightPositionWorld );
  22118. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  22119. shadowCamera.lookAt( _lookTarget );
  22120. shadowCamera.updateMatrixWorld();
  22121. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  22122. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  22123. shadowMatrix.set(
  22124. 0.5, 0.0, 0.0, 0.5,
  22125. 0.0, 0.5, 0.0, 0.5,
  22126. 0.0, 0.0, 0.5, 0.5,
  22127. 0.0, 0.0, 0.0, 1.0
  22128. );
  22129. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  22130. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  22131. }
  22132. getViewport( viewportIndex ) {
  22133. return this._viewports[ viewportIndex ];
  22134. }
  22135. getFrameExtents() {
  22136. return this._frameExtents;
  22137. }
  22138. copy( source ) {
  22139. this.camera = source.camera.clone();
  22140. this.bias = source.bias;
  22141. this.radius = source.radius;
  22142. this.mapSize.copy( source.mapSize );
  22143. return this;
  22144. }
  22145. clone() {
  22146. return new this.constructor().copy( this );
  22147. }
  22148. toJSON() {
  22149. const object = {};
  22150. if ( this.bias !== 0 ) object.bias = this.bias;
  22151. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  22152. if ( this.radius !== 1 ) object.radius = this.radius;
  22153. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22154. object.camera = this.camera.toJSON( false ).object;
  22155. delete object.camera.matrix;
  22156. return object;
  22157. }
  22158. }
  22159. class SpotLightShadow extends LightShadow {
  22160. constructor() {
  22161. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22162. this.focus = 1;
  22163. }
  22164. updateMatrices( light ) {
  22165. const camera = this.camera;
  22166. const fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  22167. const aspect = this.mapSize.width / this.mapSize.height;
  22168. const far = light.distance || camera.far;
  22169. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22170. camera.fov = fov;
  22171. camera.aspect = aspect;
  22172. camera.far = far;
  22173. camera.updateProjectionMatrix();
  22174. }
  22175. super.updateMatrices( light );
  22176. }
  22177. }
  22178. SpotLightShadow.prototype.isSpotLightShadow = true;
  22179. class SpotLight extends Light {
  22180. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 1 ) {
  22181. super( color, intensity );
  22182. this.type = 'SpotLight';
  22183. this.position.copy( Object3D.DefaultUp );
  22184. this.updateMatrix();
  22185. this.target = new Object3D();
  22186. this.distance = distance;
  22187. this.angle = angle;
  22188. this.penumbra = penumbra;
  22189. this.decay = decay; // for physically correct lights, should be 2.
  22190. this.shadow = new SpotLightShadow();
  22191. }
  22192. get power() {
  22193. // intensity = power per solid angle.
  22194. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22195. return this.intensity * Math.PI;
  22196. }
  22197. set power( power ) {
  22198. // intensity = power per solid angle.
  22199. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22200. this.intensity = power / Math.PI;
  22201. }
  22202. copy( source ) {
  22203. super.copy( source );
  22204. this.distance = source.distance;
  22205. this.angle = source.angle;
  22206. this.penumbra = source.penumbra;
  22207. this.decay = source.decay;
  22208. this.target = source.target.clone();
  22209. this.shadow = source.shadow.clone();
  22210. return this;
  22211. }
  22212. }
  22213. SpotLight.prototype.isSpotLight = true;
  22214. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  22215. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  22216. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  22217. class PointLightShadow extends LightShadow {
  22218. constructor() {
  22219. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22220. this._frameExtents = new Vector2( 4, 2 );
  22221. this._viewportCount = 6;
  22222. this._viewports = [
  22223. // These viewports map a cube-map onto a 2D texture with the
  22224. // following orientation:
  22225. //
  22226. // xzXZ
  22227. // y Y
  22228. //
  22229. // X - Positive x direction
  22230. // x - Negative x direction
  22231. // Y - Positive y direction
  22232. // y - Negative y direction
  22233. // Z - Positive z direction
  22234. // z - Negative z direction
  22235. // positive X
  22236. new Vector4( 2, 1, 1, 1 ),
  22237. // negative X
  22238. new Vector4( 0, 1, 1, 1 ),
  22239. // positive Z
  22240. new Vector4( 3, 1, 1, 1 ),
  22241. // negative Z
  22242. new Vector4( 1, 1, 1, 1 ),
  22243. // positive Y
  22244. new Vector4( 3, 0, 1, 1 ),
  22245. // negative Y
  22246. new Vector4( 1, 0, 1, 1 )
  22247. ];
  22248. this._cubeDirections = [
  22249. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  22250. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  22251. ];
  22252. this._cubeUps = [
  22253. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  22254. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  22255. ];
  22256. }
  22257. updateMatrices( light, viewportIndex = 0 ) {
  22258. const camera = this.camera;
  22259. const shadowMatrix = this.matrix;
  22260. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  22261. camera.position.copy( _lightPositionWorld$1 );
  22262. _lookTarget$1.copy( camera.position );
  22263. _lookTarget$1.add( this._cubeDirections[ viewportIndex ] );
  22264. camera.up.copy( this._cubeUps[ viewportIndex ] );
  22265. camera.lookAt( _lookTarget$1 );
  22266. camera.updateMatrixWorld();
  22267. shadowMatrix.makeTranslation( - _lightPositionWorld$1.x, - _lightPositionWorld$1.y, - _lightPositionWorld$1.z );
  22268. _projScreenMatrix$1.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  22269. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  22270. }
  22271. }
  22272. PointLightShadow.prototype.isPointLightShadow = true;
  22273. class PointLight extends Light {
  22274. constructor( color, intensity, distance = 0, decay = 1 ) {
  22275. super( color, intensity );
  22276. this.type = 'PointLight';
  22277. this.distance = distance;
  22278. this.decay = decay; // for physically correct lights, should be 2.
  22279. this.shadow = new PointLightShadow();
  22280. }
  22281. get power() {
  22282. // intensity = power per solid angle.
  22283. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22284. return this.intensity * 4 * Math.PI;
  22285. }
  22286. set power( power ) {
  22287. // intensity = power per solid angle.
  22288. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22289. this.intensity = power / ( 4 * Math.PI );
  22290. }
  22291. copy( source ) {
  22292. super.copy( source );
  22293. this.distance = source.distance;
  22294. this.decay = source.decay;
  22295. this.shadow = source.shadow.clone();
  22296. return this;
  22297. }
  22298. }
  22299. PointLight.prototype.isPointLight = true;
  22300. class OrthographicCamera extends Camera {
  22301. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  22302. super();
  22303. this.type = 'OrthographicCamera';
  22304. this.zoom = 1;
  22305. this.view = null;
  22306. this.left = left;
  22307. this.right = right;
  22308. this.top = top;
  22309. this.bottom = bottom;
  22310. this.near = near;
  22311. this.far = far;
  22312. this.updateProjectionMatrix();
  22313. }
  22314. copy( source, recursive ) {
  22315. super.copy( source, recursive );
  22316. this.left = source.left;
  22317. this.right = source.right;
  22318. this.top = source.top;
  22319. this.bottom = source.bottom;
  22320. this.near = source.near;
  22321. this.far = source.far;
  22322. this.zoom = source.zoom;
  22323. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22324. return this;
  22325. }
  22326. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  22327. if ( this.view === null ) {
  22328. this.view = {
  22329. enabled: true,
  22330. fullWidth: 1,
  22331. fullHeight: 1,
  22332. offsetX: 0,
  22333. offsetY: 0,
  22334. width: 1,
  22335. height: 1
  22336. };
  22337. }
  22338. this.view.enabled = true;
  22339. this.view.fullWidth = fullWidth;
  22340. this.view.fullHeight = fullHeight;
  22341. this.view.offsetX = x;
  22342. this.view.offsetY = y;
  22343. this.view.width = width;
  22344. this.view.height = height;
  22345. this.updateProjectionMatrix();
  22346. }
  22347. clearViewOffset() {
  22348. if ( this.view !== null ) {
  22349. this.view.enabled = false;
  22350. }
  22351. this.updateProjectionMatrix();
  22352. }
  22353. updateProjectionMatrix() {
  22354. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22355. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22356. const cx = ( this.right + this.left ) / 2;
  22357. const cy = ( this.top + this.bottom ) / 2;
  22358. let left = cx - dx;
  22359. let right = cx + dx;
  22360. let top = cy + dy;
  22361. let bottom = cy - dy;
  22362. if ( this.view !== null && this.view.enabled ) {
  22363. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  22364. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  22365. left += scaleW * this.view.offsetX;
  22366. right = left + scaleW * this.view.width;
  22367. top -= scaleH * this.view.offsetY;
  22368. bottom = top - scaleH * this.view.height;
  22369. }
  22370. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22371. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  22372. }
  22373. toJSON( meta ) {
  22374. const data = Object3D.prototype.toJSON.call( this, meta );
  22375. data.object.zoom = this.zoom;
  22376. data.object.left = this.left;
  22377. data.object.right = this.right;
  22378. data.object.top = this.top;
  22379. data.object.bottom = this.bottom;
  22380. data.object.near = this.near;
  22381. data.object.far = this.far;
  22382. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22383. return data;
  22384. }
  22385. }
  22386. OrthographicCamera.prototype.isOrthographicCamera = true;
  22387. class DirectionalLightShadow extends LightShadow {
  22388. constructor() {
  22389. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22390. }
  22391. }
  22392. DirectionalLightShadow.prototype.isDirectionalLightShadow = true;
  22393. class DirectionalLight extends Light {
  22394. constructor( color, intensity ) {
  22395. super( color, intensity );
  22396. this.type = 'DirectionalLight';
  22397. this.position.copy( Object3D.DefaultUp );
  22398. this.updateMatrix();
  22399. this.target = new Object3D();
  22400. this.shadow = new DirectionalLightShadow();
  22401. }
  22402. copy( source ) {
  22403. super.copy( source );
  22404. this.target = source.target.clone();
  22405. this.shadow = source.shadow.clone();
  22406. return this;
  22407. }
  22408. }
  22409. DirectionalLight.prototype.isDirectionalLight = true;
  22410. class AmbientLight extends Light {
  22411. constructor( color, intensity ) {
  22412. super( color, intensity );
  22413. this.type = 'AmbientLight';
  22414. }
  22415. }
  22416. AmbientLight.prototype.isAmbientLight = true;
  22417. class RectAreaLight extends Light {
  22418. constructor( color, intensity, width = 10, height = 10 ) {
  22419. super( color, intensity );
  22420. this.type = 'RectAreaLight';
  22421. this.width = width;
  22422. this.height = height;
  22423. }
  22424. copy( source ) {
  22425. super.copy( source );
  22426. this.width = source.width;
  22427. this.height = source.height;
  22428. return this;
  22429. }
  22430. toJSON( meta ) {
  22431. const data = super.toJSON( meta );
  22432. data.object.width = this.width;
  22433. data.object.height = this.height;
  22434. return data;
  22435. }
  22436. }
  22437. RectAreaLight.prototype.isRectAreaLight = true;
  22438. /**
  22439. * Primary reference:
  22440. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  22441. *
  22442. * Secondary reference:
  22443. * https://www.ppsloan.org/publications/StupidSH36.pdf
  22444. */
  22445. // 3-band SH defined by 9 coefficients
  22446. class SphericalHarmonics3 {
  22447. constructor() {
  22448. this.coefficients = [];
  22449. for ( let i = 0; i < 9; i ++ ) {
  22450. this.coefficients.push( new Vector3() );
  22451. }
  22452. }
  22453. set( coefficients ) {
  22454. for ( let i = 0; i < 9; i ++ ) {
  22455. this.coefficients[ i ].copy( coefficients[ i ] );
  22456. }
  22457. return this;
  22458. }
  22459. zero() {
  22460. for ( let i = 0; i < 9; i ++ ) {
  22461. this.coefficients[ i ].set( 0, 0, 0 );
  22462. }
  22463. return this;
  22464. }
  22465. // get the radiance in the direction of the normal
  22466. // target is a Vector3
  22467. getAt( normal, target ) {
  22468. // normal is assumed to be unit length
  22469. const x = normal.x, y = normal.y, z = normal.z;
  22470. const coeff = this.coefficients;
  22471. // band 0
  22472. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  22473. // band 1
  22474. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  22475. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  22476. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  22477. // band 2
  22478. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  22479. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  22480. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  22481. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  22482. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  22483. return target;
  22484. }
  22485. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  22486. // target is a Vector3
  22487. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  22488. getIrradianceAt( normal, target ) {
  22489. // normal is assumed to be unit length
  22490. const x = normal.x, y = normal.y, z = normal.z;
  22491. const coeff = this.coefficients;
  22492. // band 0
  22493. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  22494. // band 1
  22495. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  22496. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  22497. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  22498. // band 2
  22499. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  22500. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  22501. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  22502. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  22503. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  22504. return target;
  22505. }
  22506. add( sh ) {
  22507. for ( let i = 0; i < 9; i ++ ) {
  22508. this.coefficients[ i ].add( sh.coefficients[ i ] );
  22509. }
  22510. return this;
  22511. }
  22512. addScaledSH( sh, s ) {
  22513. for ( let i = 0; i < 9; i ++ ) {
  22514. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  22515. }
  22516. return this;
  22517. }
  22518. scale( s ) {
  22519. for ( let i = 0; i < 9; i ++ ) {
  22520. this.coefficients[ i ].multiplyScalar( s );
  22521. }
  22522. return this;
  22523. }
  22524. lerp( sh, alpha ) {
  22525. for ( let i = 0; i < 9; i ++ ) {
  22526. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  22527. }
  22528. return this;
  22529. }
  22530. equals( sh ) {
  22531. for ( let i = 0; i < 9; i ++ ) {
  22532. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  22533. return false;
  22534. }
  22535. }
  22536. return true;
  22537. }
  22538. copy( sh ) {
  22539. return this.set( sh.coefficients );
  22540. }
  22541. clone() {
  22542. return new this.constructor().copy( this );
  22543. }
  22544. fromArray( array, offset = 0 ) {
  22545. const coefficients = this.coefficients;
  22546. for ( let i = 0; i < 9; i ++ ) {
  22547. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  22548. }
  22549. return this;
  22550. }
  22551. toArray( array = [], offset = 0 ) {
  22552. const coefficients = this.coefficients;
  22553. for ( let i = 0; i < 9; i ++ ) {
  22554. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  22555. }
  22556. return array;
  22557. }
  22558. // evaluate the basis functions
  22559. // shBasis is an Array[ 9 ]
  22560. static getBasisAt( normal, shBasis ) {
  22561. // normal is assumed to be unit length
  22562. const x = normal.x, y = normal.y, z = normal.z;
  22563. // band 0
  22564. shBasis[ 0 ] = 0.282095;
  22565. // band 1
  22566. shBasis[ 1 ] = 0.488603 * y;
  22567. shBasis[ 2 ] = 0.488603 * z;
  22568. shBasis[ 3 ] = 0.488603 * x;
  22569. // band 2
  22570. shBasis[ 4 ] = 1.092548 * x * y;
  22571. shBasis[ 5 ] = 1.092548 * y * z;
  22572. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  22573. shBasis[ 7 ] = 1.092548 * x * z;
  22574. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  22575. }
  22576. }
  22577. SphericalHarmonics3.prototype.isSphericalHarmonics3 = true;
  22578. class LightProbe extends Light {
  22579. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  22580. super( undefined, intensity );
  22581. this.sh = sh;
  22582. }
  22583. copy( source ) {
  22584. super.copy( source );
  22585. this.sh.copy( source.sh );
  22586. return this;
  22587. }
  22588. fromJSON( json ) {
  22589. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  22590. this.sh.fromArray( json.sh );
  22591. return this;
  22592. }
  22593. toJSON( meta ) {
  22594. const data = super.toJSON( meta );
  22595. data.object.sh = this.sh.toArray();
  22596. return data;
  22597. }
  22598. }
  22599. LightProbe.prototype.isLightProbe = true;
  22600. class MaterialLoader extends Loader {
  22601. constructor( manager ) {
  22602. super( manager );
  22603. this.textures = {};
  22604. }
  22605. load( url, onLoad, onProgress, onError ) {
  22606. const scope = this;
  22607. const loader = new FileLoader( scope.manager );
  22608. loader.setPath( scope.path );
  22609. loader.setRequestHeader( scope.requestHeader );
  22610. loader.setWithCredentials( scope.withCredentials );
  22611. loader.load( url, function ( text ) {
  22612. try {
  22613. onLoad( scope.parse( JSON.parse( text ) ) );
  22614. } catch ( e ) {
  22615. if ( onError ) {
  22616. onError( e );
  22617. } else {
  22618. console.error( e );
  22619. }
  22620. scope.manager.itemError( url );
  22621. }
  22622. }, onProgress, onError );
  22623. }
  22624. parse( json ) {
  22625. const textures = this.textures;
  22626. function getTexture( name ) {
  22627. if ( textures[ name ] === undefined ) {
  22628. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22629. }
  22630. return textures[ name ];
  22631. }
  22632. const material = new Materials[ json.type ]();
  22633. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22634. if ( json.name !== undefined ) material.name = json.name;
  22635. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  22636. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22637. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22638. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  22639. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22640. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  22641. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22642. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  22643. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  22644. if ( json.fog !== undefined ) material.fog = json.fog;
  22645. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22646. if ( json.blending !== undefined ) material.blending = json.blending;
  22647. if ( json.combine !== undefined ) material.combine = json.combine;
  22648. if ( json.side !== undefined ) material.side = json.side;
  22649. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22650. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22651. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22652. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22653. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22654. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22655. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  22656. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  22657. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  22658. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  22659. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  22660. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  22661. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  22662. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  22663. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22664. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22665. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22666. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22667. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22668. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22669. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22670. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22671. if ( json.scale !== undefined ) material.scale = json.scale;
  22672. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22673. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22674. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22675. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22676. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22677. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22678. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22679. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  22680. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  22681. if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents;
  22682. if ( json.visible !== undefined ) material.visible = json.visible;
  22683. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  22684. if ( json.userData !== undefined ) material.userData = json.userData;
  22685. if ( json.vertexColors !== undefined ) {
  22686. if ( typeof json.vertexColors === 'number' ) {
  22687. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  22688. } else {
  22689. material.vertexColors = json.vertexColors;
  22690. }
  22691. }
  22692. // Shader Material
  22693. if ( json.uniforms !== undefined ) {
  22694. for ( const name in json.uniforms ) {
  22695. const uniform = json.uniforms[ name ];
  22696. material.uniforms[ name ] = {};
  22697. switch ( uniform.type ) {
  22698. case 't':
  22699. material.uniforms[ name ].value = getTexture( uniform.value );
  22700. break;
  22701. case 'c':
  22702. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22703. break;
  22704. case 'v2':
  22705. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22706. break;
  22707. case 'v3':
  22708. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22709. break;
  22710. case 'v4':
  22711. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22712. break;
  22713. case 'm3':
  22714. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22715. break;
  22716. case 'm4':
  22717. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22718. break;
  22719. default:
  22720. material.uniforms[ name ].value = uniform.value;
  22721. }
  22722. }
  22723. }
  22724. if ( json.defines !== undefined ) material.defines = json.defines;
  22725. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22726. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22727. if ( json.extensions !== undefined ) {
  22728. for ( const key in json.extensions ) {
  22729. material.extensions[ key ] = json.extensions[ key ];
  22730. }
  22731. }
  22732. // Deprecated
  22733. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22734. // for PointsMaterial
  22735. if ( json.size !== undefined ) material.size = json.size;
  22736. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22737. // maps
  22738. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22739. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22740. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  22741. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22742. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22743. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22744. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22745. if ( json.normalScale !== undefined ) {
  22746. let normalScale = json.normalScale;
  22747. if ( Array.isArray( normalScale ) === false ) {
  22748. // Blender exporter used to export a scalar. See #7459
  22749. normalScale = [ normalScale, normalScale ];
  22750. }
  22751. material.normalScale = new Vector2().fromArray( normalScale );
  22752. }
  22753. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22754. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22755. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22756. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22757. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22758. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22759. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22760. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22761. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22762. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22763. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22764. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22765. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22766. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22767. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22768. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22769. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22770. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  22771. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  22772. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  22773. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  22774. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  22775. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  22776. return material;
  22777. }
  22778. setTextures( value ) {
  22779. this.textures = value;
  22780. return this;
  22781. }
  22782. }
  22783. const LoaderUtils = {
  22784. decodeText: function ( array ) {
  22785. if ( typeof TextDecoder !== 'undefined' ) {
  22786. return new TextDecoder().decode( array );
  22787. }
  22788. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22789. // throws a "maximum call stack size exceeded" error for large arrays.
  22790. let s = '';
  22791. for ( let i = 0, il = array.length; i < il; i ++ ) {
  22792. // Implicitly assumes little-endian.
  22793. s += String.fromCharCode( array[ i ] );
  22794. }
  22795. try {
  22796. // merges multi-byte utf-8 characters.
  22797. return decodeURIComponent( escape( s ) );
  22798. } catch ( e ) { // see #16358
  22799. return s;
  22800. }
  22801. },
  22802. extractUrlBase: function ( url ) {
  22803. const index = url.lastIndexOf( '/' );
  22804. if ( index === - 1 ) return './';
  22805. return url.substr( 0, index + 1 );
  22806. }
  22807. };
  22808. function InstancedBufferGeometry() {
  22809. BufferGeometry.call( this );
  22810. this.type = 'InstancedBufferGeometry';
  22811. this.instanceCount = Infinity;
  22812. }
  22813. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22814. constructor: InstancedBufferGeometry,
  22815. isInstancedBufferGeometry: true,
  22816. copy: function ( source ) {
  22817. BufferGeometry.prototype.copy.call( this, source );
  22818. this.instanceCount = source.instanceCount;
  22819. return this;
  22820. },
  22821. clone: function () {
  22822. return new this.constructor().copy( this );
  22823. },
  22824. toJSON: function () {
  22825. const data = BufferGeometry.prototype.toJSON.call( this );
  22826. data.instanceCount = this.instanceCount;
  22827. data.isInstancedBufferGeometry = true;
  22828. return data;
  22829. }
  22830. } );
  22831. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  22832. if ( typeof ( normalized ) === 'number' ) {
  22833. meshPerAttribute = normalized;
  22834. normalized = false;
  22835. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  22836. }
  22837. BufferAttribute.call( this, array, itemSize, normalized );
  22838. this.meshPerAttribute = meshPerAttribute || 1;
  22839. }
  22840. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  22841. constructor: InstancedBufferAttribute,
  22842. isInstancedBufferAttribute: true,
  22843. copy: function ( source ) {
  22844. BufferAttribute.prototype.copy.call( this, source );
  22845. this.meshPerAttribute = source.meshPerAttribute;
  22846. return this;
  22847. },
  22848. toJSON: function () {
  22849. const data = BufferAttribute.prototype.toJSON.call( this );
  22850. data.meshPerAttribute = this.meshPerAttribute;
  22851. data.isInstancedBufferAttribute = true;
  22852. return data;
  22853. }
  22854. } );
  22855. class BufferGeometryLoader extends Loader {
  22856. constructor( manager ) {
  22857. super( manager );
  22858. }
  22859. load( url, onLoad, onProgress, onError ) {
  22860. const scope = this;
  22861. const loader = new FileLoader( scope.manager );
  22862. loader.setPath( scope.path );
  22863. loader.setRequestHeader( scope.requestHeader );
  22864. loader.setWithCredentials( scope.withCredentials );
  22865. loader.load( url, function ( text ) {
  22866. try {
  22867. onLoad( scope.parse( JSON.parse( text ) ) );
  22868. } catch ( e ) {
  22869. if ( onError ) {
  22870. onError( e );
  22871. } else {
  22872. console.error( e );
  22873. }
  22874. scope.manager.itemError( url );
  22875. }
  22876. }, onProgress, onError );
  22877. }
  22878. parse( json ) {
  22879. const interleavedBufferMap = {};
  22880. const arrayBufferMap = {};
  22881. function getInterleavedBuffer( json, uuid ) {
  22882. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  22883. const interleavedBuffers = json.interleavedBuffers;
  22884. const interleavedBuffer = interleavedBuffers[ uuid ];
  22885. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  22886. const array = getTypedArray( interleavedBuffer.type, buffer );
  22887. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  22888. ib.uuid = interleavedBuffer.uuid;
  22889. interleavedBufferMap[ uuid ] = ib;
  22890. return ib;
  22891. }
  22892. function getArrayBuffer( json, uuid ) {
  22893. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  22894. const arrayBuffers = json.arrayBuffers;
  22895. const arrayBuffer = arrayBuffers[ uuid ];
  22896. const ab = new Uint32Array( arrayBuffer ).buffer;
  22897. arrayBufferMap[ uuid ] = ab;
  22898. return ab;
  22899. }
  22900. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  22901. const index = json.data.index;
  22902. if ( index !== undefined ) {
  22903. const typedArray = getTypedArray( index.type, index.array );
  22904. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22905. }
  22906. const attributes = json.data.attributes;
  22907. for ( const key in attributes ) {
  22908. const attribute = attributes[ key ];
  22909. let bufferAttribute;
  22910. if ( attribute.isInterleavedBufferAttribute ) {
  22911. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  22912. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  22913. } else {
  22914. const typedArray = getTypedArray( attribute.type, attribute.array );
  22915. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  22916. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  22917. }
  22918. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22919. geometry.setAttribute( key, bufferAttribute );
  22920. }
  22921. const morphAttributes = json.data.morphAttributes;
  22922. if ( morphAttributes ) {
  22923. for ( const key in morphAttributes ) {
  22924. const attributeArray = morphAttributes[ key ];
  22925. const array = [];
  22926. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  22927. const attribute = attributeArray[ i ];
  22928. let bufferAttribute;
  22929. if ( attribute.isInterleavedBufferAttribute ) {
  22930. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  22931. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  22932. } else {
  22933. const typedArray = getTypedArray( attribute.type, attribute.array );
  22934. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22935. }
  22936. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22937. array.push( bufferAttribute );
  22938. }
  22939. geometry.morphAttributes[ key ] = array;
  22940. }
  22941. }
  22942. const morphTargetsRelative = json.data.morphTargetsRelative;
  22943. if ( morphTargetsRelative ) {
  22944. geometry.morphTargetsRelative = true;
  22945. }
  22946. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22947. if ( groups !== undefined ) {
  22948. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  22949. const group = groups[ i ];
  22950. geometry.addGroup( group.start, group.count, group.materialIndex );
  22951. }
  22952. }
  22953. const boundingSphere = json.data.boundingSphere;
  22954. if ( boundingSphere !== undefined ) {
  22955. const center = new Vector3();
  22956. if ( boundingSphere.center !== undefined ) {
  22957. center.fromArray( boundingSphere.center );
  22958. }
  22959. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22960. }
  22961. if ( json.name ) geometry.name = json.name;
  22962. if ( json.userData ) geometry.userData = json.userData;
  22963. return geometry;
  22964. }
  22965. }
  22966. class ObjectLoader extends Loader {
  22967. constructor( manager ) {
  22968. super( manager );
  22969. }
  22970. load( url, onLoad, onProgress, onError ) {
  22971. const scope = this;
  22972. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22973. this.resourcePath = this.resourcePath || path;
  22974. const loader = new FileLoader( this.manager );
  22975. loader.setPath( this.path );
  22976. loader.setRequestHeader( this.requestHeader );
  22977. loader.setWithCredentials( this.withCredentials );
  22978. loader.load( url, function ( text ) {
  22979. let json = null;
  22980. try {
  22981. json = JSON.parse( text );
  22982. } catch ( error ) {
  22983. if ( onError !== undefined ) onError( error );
  22984. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22985. return;
  22986. }
  22987. const metadata = json.metadata;
  22988. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22989. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22990. return;
  22991. }
  22992. scope.parse( json, onLoad );
  22993. }, onProgress, onError );
  22994. }
  22995. parse( json, onLoad ) {
  22996. const animations = this.parseAnimations( json.animations );
  22997. const shapes = this.parseShapes( json.shapes );
  22998. const geometries = this.parseGeometries( json.geometries, shapes );
  22999. const images = this.parseImages( json.images, function () {
  23000. if ( onLoad !== undefined ) onLoad( object );
  23001. } );
  23002. const textures = this.parseTextures( json.textures, images );
  23003. const materials = this.parseMaterials( json.materials, textures );
  23004. const object = this.parseObject( json.object, geometries, materials, animations );
  23005. const skeletons = this.parseSkeletons( json.skeletons, object );
  23006. this.bindSkeletons( object, skeletons );
  23007. //
  23008. if ( onLoad !== undefined ) {
  23009. let hasImages = false;
  23010. for ( const uuid in images ) {
  23011. if ( images[ uuid ] instanceof HTMLImageElement ) {
  23012. hasImages = true;
  23013. break;
  23014. }
  23015. }
  23016. if ( hasImages === false ) onLoad( object );
  23017. }
  23018. return object;
  23019. }
  23020. parseShapes( json ) {
  23021. const shapes = {};
  23022. if ( json !== undefined ) {
  23023. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23024. const shape = new Shape().fromJSON( json[ i ] );
  23025. shapes[ shape.uuid ] = shape;
  23026. }
  23027. }
  23028. return shapes;
  23029. }
  23030. parseSkeletons( json, object ) {
  23031. const skeletons = {};
  23032. const bones = {};
  23033. // generate bone lookup table
  23034. object.traverse( function ( child ) {
  23035. if ( child.isBone ) bones[ child.uuid ] = child;
  23036. } );
  23037. // create skeletons
  23038. if ( json !== undefined ) {
  23039. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23040. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  23041. skeletons[ skeleton.uuid ] = skeleton;
  23042. }
  23043. }
  23044. return skeletons;
  23045. }
  23046. parseGeometries( json, shapes ) {
  23047. const geometries = {};
  23048. let geometryShapes;
  23049. if ( json !== undefined ) {
  23050. const bufferGeometryLoader = new BufferGeometryLoader();
  23051. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23052. let geometry;
  23053. const data = json[ i ];
  23054. switch ( data.type ) {
  23055. case 'PlaneGeometry':
  23056. case 'PlaneBufferGeometry':
  23057. geometry = new Geometries[ data.type ](
  23058. data.width,
  23059. data.height,
  23060. data.widthSegments,
  23061. data.heightSegments
  23062. );
  23063. break;
  23064. case 'BoxGeometry':
  23065. case 'BoxBufferGeometry':
  23066. geometry = new Geometries[ data.type ](
  23067. data.width,
  23068. data.height,
  23069. data.depth,
  23070. data.widthSegments,
  23071. data.heightSegments,
  23072. data.depthSegments
  23073. );
  23074. break;
  23075. case 'CircleGeometry':
  23076. case 'CircleBufferGeometry':
  23077. geometry = new Geometries[ data.type ](
  23078. data.radius,
  23079. data.segments,
  23080. data.thetaStart,
  23081. data.thetaLength
  23082. );
  23083. break;
  23084. case 'CylinderGeometry':
  23085. case 'CylinderBufferGeometry':
  23086. geometry = new Geometries[ data.type ](
  23087. data.radiusTop,
  23088. data.radiusBottom,
  23089. data.height,
  23090. data.radialSegments,
  23091. data.heightSegments,
  23092. data.openEnded,
  23093. data.thetaStart,
  23094. data.thetaLength
  23095. );
  23096. break;
  23097. case 'ConeGeometry':
  23098. case 'ConeBufferGeometry':
  23099. geometry = new Geometries[ data.type ](
  23100. data.radius,
  23101. data.height,
  23102. data.radialSegments,
  23103. data.heightSegments,
  23104. data.openEnded,
  23105. data.thetaStart,
  23106. data.thetaLength
  23107. );
  23108. break;
  23109. case 'SphereGeometry':
  23110. case 'SphereBufferGeometry':
  23111. geometry = new Geometries[ data.type ](
  23112. data.radius,
  23113. data.widthSegments,
  23114. data.heightSegments,
  23115. data.phiStart,
  23116. data.phiLength,
  23117. data.thetaStart,
  23118. data.thetaLength
  23119. );
  23120. break;
  23121. case 'DodecahedronGeometry':
  23122. case 'DodecahedronBufferGeometry':
  23123. case 'IcosahedronGeometry':
  23124. case 'IcosahedronBufferGeometry':
  23125. case 'OctahedronGeometry':
  23126. case 'OctahedronBufferGeometry':
  23127. case 'TetrahedronGeometry':
  23128. case 'TetrahedronBufferGeometry':
  23129. geometry = new Geometries[ data.type ](
  23130. data.radius,
  23131. data.detail
  23132. );
  23133. break;
  23134. case 'RingGeometry':
  23135. case 'RingBufferGeometry':
  23136. geometry = new Geometries[ data.type ](
  23137. data.innerRadius,
  23138. data.outerRadius,
  23139. data.thetaSegments,
  23140. data.phiSegments,
  23141. data.thetaStart,
  23142. data.thetaLength
  23143. );
  23144. break;
  23145. case 'TorusGeometry':
  23146. case 'TorusBufferGeometry':
  23147. geometry = new Geometries[ data.type ](
  23148. data.radius,
  23149. data.tube,
  23150. data.radialSegments,
  23151. data.tubularSegments,
  23152. data.arc
  23153. );
  23154. break;
  23155. case 'TorusKnotGeometry':
  23156. case 'TorusKnotBufferGeometry':
  23157. geometry = new Geometries[ data.type ](
  23158. data.radius,
  23159. data.tube,
  23160. data.tubularSegments,
  23161. data.radialSegments,
  23162. data.p,
  23163. data.q
  23164. );
  23165. break;
  23166. case 'TubeGeometry':
  23167. case 'TubeBufferGeometry':
  23168. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23169. // User defined curves or instances of CurvePath will not be deserialized.
  23170. geometry = new Geometries[ data.type ](
  23171. new Curves[ data.path.type ]().fromJSON( data.path ),
  23172. data.tubularSegments,
  23173. data.radius,
  23174. data.radialSegments,
  23175. data.closed
  23176. );
  23177. break;
  23178. case 'LatheGeometry':
  23179. case 'LatheBufferGeometry':
  23180. geometry = new Geometries[ data.type ](
  23181. data.points,
  23182. data.segments,
  23183. data.phiStart,
  23184. data.phiLength
  23185. );
  23186. break;
  23187. case 'PolyhedronGeometry':
  23188. case 'PolyhedronBufferGeometry':
  23189. geometry = new Geometries[ data.type ](
  23190. data.vertices,
  23191. data.indices,
  23192. data.radius,
  23193. data.details
  23194. );
  23195. break;
  23196. case 'ShapeGeometry':
  23197. case 'ShapeBufferGeometry':
  23198. geometryShapes = [];
  23199. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23200. const shape = shapes[ data.shapes[ j ] ];
  23201. geometryShapes.push( shape );
  23202. }
  23203. geometry = new Geometries[ data.type ](
  23204. geometryShapes,
  23205. data.curveSegments
  23206. );
  23207. break;
  23208. case 'ExtrudeGeometry':
  23209. case 'ExtrudeBufferGeometry':
  23210. geometryShapes = [];
  23211. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23212. const shape = shapes[ data.shapes[ j ] ];
  23213. geometryShapes.push( shape );
  23214. }
  23215. const extrudePath = data.options.extrudePath;
  23216. if ( extrudePath !== undefined ) {
  23217. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23218. }
  23219. geometry = new Geometries[ data.type ](
  23220. geometryShapes,
  23221. data.options
  23222. );
  23223. break;
  23224. case 'BufferGeometry':
  23225. case 'InstancedBufferGeometry':
  23226. geometry = bufferGeometryLoader.parse( data );
  23227. break;
  23228. case 'Geometry':
  23229. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  23230. break;
  23231. default:
  23232. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23233. continue;
  23234. }
  23235. geometry.uuid = data.uuid;
  23236. if ( data.name !== undefined ) geometry.name = data.name;
  23237. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23238. geometries[ data.uuid ] = geometry;
  23239. }
  23240. }
  23241. return geometries;
  23242. }
  23243. parseMaterials( json, textures ) {
  23244. const cache = {}; // MultiMaterial
  23245. const materials = {};
  23246. if ( json !== undefined ) {
  23247. const loader = new MaterialLoader();
  23248. loader.setTextures( textures );
  23249. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23250. const data = json[ i ];
  23251. if ( data.type === 'MultiMaterial' ) {
  23252. // Deprecated
  23253. const array = [];
  23254. for ( let j = 0; j < data.materials.length; j ++ ) {
  23255. const material = data.materials[ j ];
  23256. if ( cache[ material.uuid ] === undefined ) {
  23257. cache[ material.uuid ] = loader.parse( material );
  23258. }
  23259. array.push( cache[ material.uuid ] );
  23260. }
  23261. materials[ data.uuid ] = array;
  23262. } else {
  23263. if ( cache[ data.uuid ] === undefined ) {
  23264. cache[ data.uuid ] = loader.parse( data );
  23265. }
  23266. materials[ data.uuid ] = cache[ data.uuid ];
  23267. }
  23268. }
  23269. }
  23270. return materials;
  23271. }
  23272. parseAnimations( json ) {
  23273. const animations = {};
  23274. if ( json !== undefined ) {
  23275. for ( let i = 0; i < json.length; i ++ ) {
  23276. const data = json[ i ];
  23277. const clip = AnimationClip.parse( data );
  23278. animations[ clip.uuid ] = clip;
  23279. }
  23280. }
  23281. return animations;
  23282. }
  23283. parseImages( json, onLoad ) {
  23284. const scope = this;
  23285. const images = {};
  23286. let loader;
  23287. function loadImage( url ) {
  23288. scope.manager.itemStart( url );
  23289. return loader.load( url, function () {
  23290. scope.manager.itemEnd( url );
  23291. }, undefined, function () {
  23292. scope.manager.itemError( url );
  23293. scope.manager.itemEnd( url );
  23294. } );
  23295. }
  23296. function deserializeImage( image ) {
  23297. if ( typeof image === 'string' ) {
  23298. const url = image;
  23299. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  23300. return loadImage( path );
  23301. } else {
  23302. if ( image.data ) {
  23303. return {
  23304. data: getTypedArray( image.type, image.data ),
  23305. width: image.width,
  23306. height: image.height
  23307. };
  23308. } else {
  23309. return null;
  23310. }
  23311. }
  23312. }
  23313. if ( json !== undefined && json.length > 0 ) {
  23314. const manager = new LoadingManager( onLoad );
  23315. loader = new ImageLoader( manager );
  23316. loader.setCrossOrigin( this.crossOrigin );
  23317. for ( let i = 0, il = json.length; i < il; i ++ ) {
  23318. const image = json[ i ];
  23319. const url = image.url;
  23320. if ( Array.isArray( url ) ) {
  23321. // load array of images e.g CubeTexture
  23322. images[ image.uuid ] = [];
  23323. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  23324. const currentUrl = url[ j ];
  23325. const deserializedImage = deserializeImage( currentUrl );
  23326. if ( deserializedImage !== null ) {
  23327. if ( deserializedImage instanceof HTMLImageElement ) {
  23328. images[ image.uuid ].push( deserializedImage );
  23329. } else {
  23330. // special case: handle array of data textures for cube textures
  23331. images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  23332. }
  23333. }
  23334. }
  23335. } else {
  23336. // load single image
  23337. const deserializedImage = deserializeImage( image.url );
  23338. if ( deserializedImage !== null ) {
  23339. images[ image.uuid ] = deserializedImage;
  23340. }
  23341. }
  23342. }
  23343. }
  23344. return images;
  23345. }
  23346. parseTextures( json, images ) {
  23347. function parseConstant( value, type ) {
  23348. if ( typeof value === 'number' ) return value;
  23349. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23350. return type[ value ];
  23351. }
  23352. const textures = {};
  23353. if ( json !== undefined ) {
  23354. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23355. const data = json[ i ];
  23356. if ( data.image === undefined ) {
  23357. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23358. }
  23359. if ( images[ data.image ] === undefined ) {
  23360. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23361. }
  23362. let texture;
  23363. const image = images[ data.image ];
  23364. if ( Array.isArray( image ) ) {
  23365. texture = new CubeTexture( image );
  23366. if ( image.length === 6 ) texture.needsUpdate = true;
  23367. } else {
  23368. if ( image && image.data ) {
  23369. texture = new DataTexture( image.data, image.width, image.height );
  23370. } else {
  23371. texture = new Texture( image );
  23372. }
  23373. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  23374. }
  23375. texture.uuid = data.uuid;
  23376. if ( data.name !== undefined ) texture.name = data.name;
  23377. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23378. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23379. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23380. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23381. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23382. if ( data.wrap !== undefined ) {
  23383. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23384. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23385. }
  23386. if ( data.format !== undefined ) texture.format = data.format;
  23387. if ( data.type !== undefined ) texture.type = data.type;
  23388. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23389. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23390. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23391. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23392. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23393. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23394. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23395. textures[ data.uuid ] = texture;
  23396. }
  23397. }
  23398. return textures;
  23399. }
  23400. parseObject( data, geometries, materials, animations ) {
  23401. let object;
  23402. function getGeometry( name ) {
  23403. if ( geometries[ name ] === undefined ) {
  23404. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23405. }
  23406. return geometries[ name ];
  23407. }
  23408. function getMaterial( name ) {
  23409. if ( name === undefined ) return undefined;
  23410. if ( Array.isArray( name ) ) {
  23411. const array = [];
  23412. for ( let i = 0, l = name.length; i < l; i ++ ) {
  23413. const uuid = name[ i ];
  23414. if ( materials[ uuid ] === undefined ) {
  23415. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23416. }
  23417. array.push( materials[ uuid ] );
  23418. }
  23419. return array;
  23420. }
  23421. if ( materials[ name ] === undefined ) {
  23422. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23423. }
  23424. return materials[ name ];
  23425. }
  23426. let geometry, material;
  23427. switch ( data.type ) {
  23428. case 'Scene':
  23429. object = new Scene();
  23430. if ( data.background !== undefined ) {
  23431. if ( Number.isInteger( data.background ) ) {
  23432. object.background = new Color( data.background );
  23433. }
  23434. }
  23435. if ( data.fog !== undefined ) {
  23436. if ( data.fog.type === 'Fog' ) {
  23437. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23438. } else if ( data.fog.type === 'FogExp2' ) {
  23439. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23440. }
  23441. }
  23442. break;
  23443. case 'PerspectiveCamera':
  23444. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23445. if ( data.focus !== undefined ) object.focus = data.focus;
  23446. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23447. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23448. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23449. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23450. break;
  23451. case 'OrthographicCamera':
  23452. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23453. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23454. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23455. break;
  23456. case 'AmbientLight':
  23457. object = new AmbientLight( data.color, data.intensity );
  23458. break;
  23459. case 'DirectionalLight':
  23460. object = new DirectionalLight( data.color, data.intensity );
  23461. break;
  23462. case 'PointLight':
  23463. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23464. break;
  23465. case 'RectAreaLight':
  23466. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23467. break;
  23468. case 'SpotLight':
  23469. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23470. break;
  23471. case 'HemisphereLight':
  23472. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23473. break;
  23474. case 'LightProbe':
  23475. object = new LightProbe().fromJSON( data );
  23476. break;
  23477. case 'SkinnedMesh':
  23478. geometry = getGeometry( data.geometry );
  23479. material = getMaterial( data.material );
  23480. object = new SkinnedMesh( geometry, material );
  23481. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  23482. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  23483. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  23484. break;
  23485. case 'Mesh':
  23486. geometry = getGeometry( data.geometry );
  23487. material = getMaterial( data.material );
  23488. object = new Mesh( geometry, material );
  23489. break;
  23490. case 'InstancedMesh':
  23491. geometry = getGeometry( data.geometry );
  23492. material = getMaterial( data.material );
  23493. const count = data.count;
  23494. const instanceMatrix = data.instanceMatrix;
  23495. object = new InstancedMesh( geometry, material, count );
  23496. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  23497. break;
  23498. case 'LOD':
  23499. object = new LOD();
  23500. break;
  23501. case 'Line':
  23502. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  23503. break;
  23504. case 'LineLoop':
  23505. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23506. break;
  23507. case 'LineSegments':
  23508. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23509. break;
  23510. case 'PointCloud':
  23511. case 'Points':
  23512. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23513. break;
  23514. case 'Sprite':
  23515. object = new Sprite( getMaterial( data.material ) );
  23516. break;
  23517. case 'Group':
  23518. object = new Group();
  23519. break;
  23520. case 'Bone':
  23521. object = new Bone();
  23522. break;
  23523. default:
  23524. object = new Object3D();
  23525. }
  23526. object.uuid = data.uuid;
  23527. if ( data.name !== undefined ) object.name = data.name;
  23528. if ( data.matrix !== undefined ) {
  23529. object.matrix.fromArray( data.matrix );
  23530. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23531. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23532. } else {
  23533. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23534. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23535. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23536. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23537. }
  23538. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23539. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23540. if ( data.shadow ) {
  23541. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23542. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  23543. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23544. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23545. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23546. }
  23547. if ( data.visible !== undefined ) object.visible = data.visible;
  23548. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23549. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23550. if ( data.userData !== undefined ) object.userData = data.userData;
  23551. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23552. if ( data.children !== undefined ) {
  23553. const children = data.children;
  23554. for ( let i = 0; i < children.length; i ++ ) {
  23555. object.add( this.parseObject( children[ i ], geometries, materials, animations ) );
  23556. }
  23557. }
  23558. if ( data.animations !== undefined ) {
  23559. const objectAnimations = data.animations;
  23560. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  23561. const uuid = objectAnimations[ i ];
  23562. object.animations.push( animations[ uuid ] );
  23563. }
  23564. }
  23565. if ( data.type === 'LOD' ) {
  23566. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  23567. const levels = data.levels;
  23568. for ( let l = 0; l < levels.length; l ++ ) {
  23569. const level = levels[ l ];
  23570. const child = object.getObjectByProperty( 'uuid', level.object );
  23571. if ( child !== undefined ) {
  23572. object.addLevel( child, level.distance );
  23573. }
  23574. }
  23575. }
  23576. return object;
  23577. }
  23578. bindSkeletons( object, skeletons ) {
  23579. if ( Object.keys( skeletons ).length === 0 ) return;
  23580. object.traverse( function ( child ) {
  23581. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  23582. const skeleton = skeletons[ child.skeleton ];
  23583. if ( skeleton === undefined ) {
  23584. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  23585. } else {
  23586. child.bind( skeleton, child.bindMatrix );
  23587. }
  23588. }
  23589. } );
  23590. }
  23591. /* DEPRECATED */
  23592. setTexturePath( value ) {
  23593. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  23594. return this.setResourcePath( value );
  23595. }
  23596. }
  23597. const TEXTURE_MAPPING = {
  23598. UVMapping: UVMapping,
  23599. CubeReflectionMapping: CubeReflectionMapping,
  23600. CubeRefractionMapping: CubeRefractionMapping,
  23601. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23602. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23603. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23604. CubeUVRefractionMapping: CubeUVRefractionMapping
  23605. };
  23606. const TEXTURE_WRAPPING = {
  23607. RepeatWrapping: RepeatWrapping,
  23608. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23609. MirroredRepeatWrapping: MirroredRepeatWrapping
  23610. };
  23611. const TEXTURE_FILTER = {
  23612. NearestFilter: NearestFilter,
  23613. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23614. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23615. LinearFilter: LinearFilter,
  23616. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23617. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23618. };
  23619. function ImageBitmapLoader( manager ) {
  23620. if ( typeof createImageBitmap === 'undefined' ) {
  23621. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23622. }
  23623. if ( typeof fetch === 'undefined' ) {
  23624. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23625. }
  23626. Loader.call( this, manager );
  23627. this.options = { premultiplyAlpha: 'none' };
  23628. }
  23629. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23630. constructor: ImageBitmapLoader,
  23631. isImageBitmapLoader: true,
  23632. setOptions: function setOptions( options ) {
  23633. this.options = options;
  23634. return this;
  23635. },
  23636. load: function ( url, onLoad, onProgress, onError ) {
  23637. if ( url === undefined ) url = '';
  23638. if ( this.path !== undefined ) url = this.path + url;
  23639. url = this.manager.resolveURL( url );
  23640. const scope = this;
  23641. const cached = Cache.get( url );
  23642. if ( cached !== undefined ) {
  23643. scope.manager.itemStart( url );
  23644. setTimeout( function () {
  23645. if ( onLoad ) onLoad( cached );
  23646. scope.manager.itemEnd( url );
  23647. }, 0 );
  23648. return cached;
  23649. }
  23650. const fetchOptions = {};
  23651. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  23652. fetchOptions.headers = this.requestHeader;
  23653. fetch( url, fetchOptions ).then( function ( res ) {
  23654. return res.blob();
  23655. } ).then( function ( blob ) {
  23656. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  23657. } ).then( function ( imageBitmap ) {
  23658. Cache.add( url, imageBitmap );
  23659. if ( onLoad ) onLoad( imageBitmap );
  23660. scope.manager.itemEnd( url );
  23661. } ).catch( function ( e ) {
  23662. if ( onError ) onError( e );
  23663. scope.manager.itemError( url );
  23664. scope.manager.itemEnd( url );
  23665. } );
  23666. scope.manager.itemStart( url );
  23667. }
  23668. } );
  23669. class ShapePath {
  23670. constructor() {
  23671. this.type = 'ShapePath';
  23672. this.color = new Color();
  23673. this.subPaths = [];
  23674. this.currentPath = null;
  23675. }
  23676. moveTo( x, y ) {
  23677. this.currentPath = new Path();
  23678. this.subPaths.push( this.currentPath );
  23679. this.currentPath.moveTo( x, y );
  23680. return this;
  23681. }
  23682. lineTo( x, y ) {
  23683. this.currentPath.lineTo( x, y );
  23684. return this;
  23685. }
  23686. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  23687. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23688. return this;
  23689. }
  23690. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23691. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23692. return this;
  23693. }
  23694. splineThru( pts ) {
  23695. this.currentPath.splineThru( pts );
  23696. return this;
  23697. }
  23698. toShapes( isCCW, noHoles ) {
  23699. function toShapesNoHoles( inSubpaths ) {
  23700. const shapes = [];
  23701. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23702. const tmpPath = inSubpaths[ i ];
  23703. const tmpShape = new Shape();
  23704. tmpShape.curves = tmpPath.curves;
  23705. shapes.push( tmpShape );
  23706. }
  23707. return shapes;
  23708. }
  23709. function isPointInsidePolygon( inPt, inPolygon ) {
  23710. const polyLen = inPolygon.length;
  23711. // inPt on polygon contour => immediate success or
  23712. // toggling of inside/outside at every single! intersection point of an edge
  23713. // with the horizontal line through inPt, left of inPt
  23714. // not counting lowerY endpoints of edges and whole edges on that line
  23715. let inside = false;
  23716. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23717. let edgeLowPt = inPolygon[ p ];
  23718. let edgeHighPt = inPolygon[ q ];
  23719. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  23720. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  23721. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23722. // not parallel
  23723. if ( edgeDy < 0 ) {
  23724. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23725. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23726. }
  23727. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23728. if ( inPt.y === edgeLowPt.y ) {
  23729. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23730. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23731. } else {
  23732. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23733. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23734. if ( perpEdge < 0 ) continue;
  23735. inside = ! inside; // true intersection left of inPt
  23736. }
  23737. } else {
  23738. // parallel or collinear
  23739. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23740. // edge lies on the same horizontal line as inPt
  23741. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23742. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23743. // continue;
  23744. }
  23745. }
  23746. return inside;
  23747. }
  23748. const isClockWise = ShapeUtils.isClockWise;
  23749. const subPaths = this.subPaths;
  23750. if ( subPaths.length === 0 ) return [];
  23751. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23752. let solid, tmpPath, tmpShape;
  23753. const shapes = [];
  23754. if ( subPaths.length === 1 ) {
  23755. tmpPath = subPaths[ 0 ];
  23756. tmpShape = new Shape();
  23757. tmpShape.curves = tmpPath.curves;
  23758. shapes.push( tmpShape );
  23759. return shapes;
  23760. }
  23761. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23762. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23763. // console.log("Holes first", holesFirst);
  23764. const betterShapeHoles = [];
  23765. const newShapes = [];
  23766. let newShapeHoles = [];
  23767. let mainIdx = 0;
  23768. let tmpPoints;
  23769. newShapes[ mainIdx ] = undefined;
  23770. newShapeHoles[ mainIdx ] = [];
  23771. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  23772. tmpPath = subPaths[ i ];
  23773. tmpPoints = tmpPath.getPoints();
  23774. solid = isClockWise( tmpPoints );
  23775. solid = isCCW ? ! solid : solid;
  23776. if ( solid ) {
  23777. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23778. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23779. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23780. if ( holesFirst ) mainIdx ++;
  23781. newShapeHoles[ mainIdx ] = [];
  23782. //console.log('cw', i);
  23783. } else {
  23784. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23785. //console.log('ccw', i);
  23786. }
  23787. }
  23788. // only Holes? -> probably all Shapes with wrong orientation
  23789. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23790. if ( newShapes.length > 1 ) {
  23791. let ambiguous = false;
  23792. const toChange = [];
  23793. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23794. betterShapeHoles[ sIdx ] = [];
  23795. }
  23796. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23797. const sho = newShapeHoles[ sIdx ];
  23798. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23799. const ho = sho[ hIdx ];
  23800. let hole_unassigned = true;
  23801. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23802. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23803. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23804. if ( hole_unassigned ) {
  23805. hole_unassigned = false;
  23806. betterShapeHoles[ s2Idx ].push( ho );
  23807. } else {
  23808. ambiguous = true;
  23809. }
  23810. }
  23811. }
  23812. if ( hole_unassigned ) {
  23813. betterShapeHoles[ sIdx ].push( ho );
  23814. }
  23815. }
  23816. }
  23817. // console.log("ambiguous: ", ambiguous);
  23818. if ( toChange.length > 0 ) {
  23819. // console.log("to change: ", toChange);
  23820. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23821. }
  23822. }
  23823. let tmpHoles;
  23824. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  23825. tmpShape = newShapes[ i ].s;
  23826. shapes.push( tmpShape );
  23827. tmpHoles = newShapeHoles[ i ];
  23828. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23829. tmpShape.holes.push( tmpHoles[ j ].h );
  23830. }
  23831. }
  23832. //console.log("shape", shapes);
  23833. return shapes;
  23834. }
  23835. }
  23836. class Font {
  23837. constructor( data ) {
  23838. this.type = 'Font';
  23839. this.data = data;
  23840. }
  23841. generateShapes( text, size = 100 ) {
  23842. const shapes = [];
  23843. const paths = createPaths( text, size, this.data );
  23844. for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
  23845. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23846. }
  23847. return shapes;
  23848. }
  23849. }
  23850. function createPaths( text, size, data ) {
  23851. const chars = Array.from( text );
  23852. const scale = size / data.resolution;
  23853. const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23854. const paths = [];
  23855. let offsetX = 0, offsetY = 0;
  23856. for ( let i = 0; i < chars.length; i ++ ) {
  23857. const char = chars[ i ];
  23858. if ( char === '\n' ) {
  23859. offsetX = 0;
  23860. offsetY -= line_height;
  23861. } else {
  23862. const ret = createPath( char, scale, offsetX, offsetY, data );
  23863. offsetX += ret.offsetX;
  23864. paths.push( ret.path );
  23865. }
  23866. }
  23867. return paths;
  23868. }
  23869. function createPath( char, scale, offsetX, offsetY, data ) {
  23870. const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23871. if ( ! glyph ) {
  23872. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  23873. return;
  23874. }
  23875. const path = new ShapePath();
  23876. let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23877. if ( glyph.o ) {
  23878. const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23879. for ( let i = 0, l = outline.length; i < l; ) {
  23880. const action = outline[ i ++ ];
  23881. switch ( action ) {
  23882. case 'm': // moveTo
  23883. x = outline[ i ++ ] * scale + offsetX;
  23884. y = outline[ i ++ ] * scale + offsetY;
  23885. path.moveTo( x, y );
  23886. break;
  23887. case 'l': // lineTo
  23888. x = outline[ i ++ ] * scale + offsetX;
  23889. y = outline[ i ++ ] * scale + offsetY;
  23890. path.lineTo( x, y );
  23891. break;
  23892. case 'q': // quadraticCurveTo
  23893. cpx = outline[ i ++ ] * scale + offsetX;
  23894. cpy = outline[ i ++ ] * scale + offsetY;
  23895. cpx1 = outline[ i ++ ] * scale + offsetX;
  23896. cpy1 = outline[ i ++ ] * scale + offsetY;
  23897. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23898. break;
  23899. case 'b': // bezierCurveTo
  23900. cpx = outline[ i ++ ] * scale + offsetX;
  23901. cpy = outline[ i ++ ] * scale + offsetY;
  23902. cpx1 = outline[ i ++ ] * scale + offsetX;
  23903. cpy1 = outline[ i ++ ] * scale + offsetY;
  23904. cpx2 = outline[ i ++ ] * scale + offsetX;
  23905. cpy2 = outline[ i ++ ] * scale + offsetY;
  23906. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23907. break;
  23908. }
  23909. }
  23910. }
  23911. return { offsetX: glyph.ha * scale, path: path };
  23912. }
  23913. Font.prototype.isFont = true;
  23914. class FontLoader extends Loader {
  23915. constructor( manager ) {
  23916. super( manager );
  23917. }
  23918. load( url, onLoad, onProgress, onError ) {
  23919. const scope = this;
  23920. const loader = new FileLoader( this.manager );
  23921. loader.setPath( this.path );
  23922. loader.setRequestHeader( this.requestHeader );
  23923. loader.setWithCredentials( scope.withCredentials );
  23924. loader.load( url, function ( text ) {
  23925. let json;
  23926. try {
  23927. json = JSON.parse( text );
  23928. } catch ( e ) {
  23929. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23930. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23931. }
  23932. const font = scope.parse( json );
  23933. if ( onLoad ) onLoad( font );
  23934. }, onProgress, onError );
  23935. }
  23936. parse( json ) {
  23937. return new Font( json );
  23938. }
  23939. }
  23940. let _context;
  23941. const AudioContext = {
  23942. getContext: function () {
  23943. if ( _context === undefined ) {
  23944. _context = new ( window.AudioContext || window.webkitAudioContext )();
  23945. }
  23946. return _context;
  23947. },
  23948. setContext: function ( value ) {
  23949. _context = value;
  23950. }
  23951. };
  23952. class AudioLoader extends Loader {
  23953. constructor( manager ) {
  23954. super( manager );
  23955. }
  23956. load( url, onLoad, onProgress, onError ) {
  23957. const scope = this;
  23958. const loader = new FileLoader( this.manager );
  23959. loader.setResponseType( 'arraybuffer' );
  23960. loader.setPath( this.path );
  23961. loader.setRequestHeader( this.requestHeader );
  23962. loader.setWithCredentials( this.withCredentials );
  23963. loader.load( url, function ( buffer ) {
  23964. try {
  23965. // Create a copy of the buffer. The `decodeAudioData` method
  23966. // detaches the buffer when complete, preventing reuse.
  23967. const bufferCopy = buffer.slice( 0 );
  23968. const context = AudioContext.getContext();
  23969. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23970. onLoad( audioBuffer );
  23971. } );
  23972. } catch ( e ) {
  23973. if ( onError ) {
  23974. onError( e );
  23975. } else {
  23976. console.error( e );
  23977. }
  23978. scope.manager.itemError( url );
  23979. }
  23980. }, onProgress, onError );
  23981. }
  23982. }
  23983. class HemisphereLightProbe extends LightProbe {
  23984. constructor( skyColor, groundColor, intensity = 1 ) {
  23985. super( undefined, intensity );
  23986. const color1 = new Color().set( skyColor );
  23987. const color2 = new Color().set( groundColor );
  23988. const sky = new Vector3( color1.r, color1.g, color1.b );
  23989. const ground = new Vector3( color2.r, color2.g, color2.b );
  23990. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  23991. const c0 = Math.sqrt( Math.PI );
  23992. const c1 = c0 * Math.sqrt( 0.75 );
  23993. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  23994. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  23995. }
  23996. }
  23997. HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
  23998. class AmbientLightProbe extends LightProbe {
  23999. constructor( color, intensity = 1 ) {
  24000. super( undefined, intensity );
  24001. const color1 = new Color().set( color );
  24002. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24003. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24004. }
  24005. }
  24006. AmbientLightProbe.prototype.isAmbientLightProbe = true;
  24007. const _eyeRight = new Matrix4();
  24008. const _eyeLeft = new Matrix4();
  24009. class StereoCamera {
  24010. constructor() {
  24011. this.type = 'StereoCamera';
  24012. this.aspect = 1;
  24013. this.eyeSep = 0.064;
  24014. this.cameraL = new PerspectiveCamera();
  24015. this.cameraL.layers.enable( 1 );
  24016. this.cameraL.matrixAutoUpdate = false;
  24017. this.cameraR = new PerspectiveCamera();
  24018. this.cameraR.layers.enable( 2 );
  24019. this.cameraR.matrixAutoUpdate = false;
  24020. this._cache = {
  24021. focus: null,
  24022. fov: null,
  24023. aspect: null,
  24024. near: null,
  24025. far: null,
  24026. zoom: null,
  24027. eyeSep: null
  24028. };
  24029. }
  24030. update( camera ) {
  24031. const cache = this._cache;
  24032. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  24033. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  24034. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  24035. if ( needsUpdate ) {
  24036. cache.focus = camera.focus;
  24037. cache.fov = camera.fov;
  24038. cache.aspect = camera.aspect * this.aspect;
  24039. cache.near = camera.near;
  24040. cache.far = camera.far;
  24041. cache.zoom = camera.zoom;
  24042. cache.eyeSep = this.eyeSep;
  24043. // Off-axis stereoscopic effect based on
  24044. // http://paulbourke.net/stereographics/stereorender/
  24045. const projectionMatrix = camera.projectionMatrix.clone();
  24046. const eyeSepHalf = cache.eyeSep / 2;
  24047. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24048. const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  24049. let xmin, xmax;
  24050. // translate xOffset
  24051. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  24052. _eyeRight.elements[ 12 ] = eyeSepHalf;
  24053. // for left eye
  24054. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  24055. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24056. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24057. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24058. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24059. // for right eye
  24060. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  24061. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24062. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24063. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24064. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24065. }
  24066. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  24067. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  24068. }
  24069. }
  24070. class Clock {
  24071. constructor( autoStart ) {
  24072. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24073. this.startTime = 0;
  24074. this.oldTime = 0;
  24075. this.elapsedTime = 0;
  24076. this.running = false;
  24077. }
  24078. start() {
  24079. this.startTime = now();
  24080. this.oldTime = this.startTime;
  24081. this.elapsedTime = 0;
  24082. this.running = true;
  24083. }
  24084. stop() {
  24085. this.getElapsedTime();
  24086. this.running = false;
  24087. this.autoStart = false;
  24088. }
  24089. getElapsedTime() {
  24090. this.getDelta();
  24091. return this.elapsedTime;
  24092. }
  24093. getDelta() {
  24094. let diff = 0;
  24095. if ( this.autoStart && ! this.running ) {
  24096. this.start();
  24097. return 0;
  24098. }
  24099. if ( this.running ) {
  24100. const newTime = now();
  24101. diff = ( newTime - this.oldTime ) / 1000;
  24102. this.oldTime = newTime;
  24103. this.elapsedTime += diff;
  24104. }
  24105. return diff;
  24106. }
  24107. }
  24108. function now() {
  24109. return ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24110. }
  24111. const _position$2 = /*@__PURE__*/ new Vector3();
  24112. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  24113. const _scale$1 = /*@__PURE__*/ new Vector3();
  24114. const _orientation = /*@__PURE__*/ new Vector3();
  24115. class AudioListener extends Object3D {
  24116. constructor() {
  24117. super();
  24118. this.type = 'AudioListener';
  24119. this.context = AudioContext.getContext();
  24120. this.gain = this.context.createGain();
  24121. this.gain.connect( this.context.destination );
  24122. this.filter = null;
  24123. this.timeDelta = 0;
  24124. // private
  24125. this._clock = new Clock();
  24126. }
  24127. getInput() {
  24128. return this.gain;
  24129. }
  24130. removeFilter() {
  24131. if ( this.filter !== null ) {
  24132. this.gain.disconnect( this.filter );
  24133. this.filter.disconnect( this.context.destination );
  24134. this.gain.connect( this.context.destination );
  24135. this.filter = null;
  24136. }
  24137. return this;
  24138. }
  24139. getFilter() {
  24140. return this.filter;
  24141. }
  24142. setFilter( value ) {
  24143. if ( this.filter !== null ) {
  24144. this.gain.disconnect( this.filter );
  24145. this.filter.disconnect( this.context.destination );
  24146. } else {
  24147. this.gain.disconnect( this.context.destination );
  24148. }
  24149. this.filter = value;
  24150. this.gain.connect( this.filter );
  24151. this.filter.connect( this.context.destination );
  24152. return this;
  24153. }
  24154. getMasterVolume() {
  24155. return this.gain.gain.value;
  24156. }
  24157. setMasterVolume( value ) {
  24158. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24159. return this;
  24160. }
  24161. updateMatrixWorld( force ) {
  24162. super.updateMatrixWorld( force );
  24163. const listener = this.context.listener;
  24164. const up = this.up;
  24165. this.timeDelta = this._clock.getDelta();
  24166. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  24167. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  24168. if ( listener.positionX ) {
  24169. // code path for Chrome (see #14393)
  24170. const endTime = this.context.currentTime + this.timeDelta;
  24171. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  24172. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  24173. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  24174. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  24175. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  24176. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  24177. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24178. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24179. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24180. } else {
  24181. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  24182. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  24183. }
  24184. }
  24185. }
  24186. class Audio extends Object3D {
  24187. constructor( listener ) {
  24188. super();
  24189. this.type = 'Audio';
  24190. this.listener = listener;
  24191. this.context = listener.context;
  24192. this.gain = this.context.createGain();
  24193. this.gain.connect( listener.getInput() );
  24194. this.autoplay = false;
  24195. this.buffer = null;
  24196. this.detune = 0;
  24197. this.loop = false;
  24198. this.loopStart = 0;
  24199. this.loopEnd = 0;
  24200. this.offset = 0;
  24201. this.duration = undefined;
  24202. this.playbackRate = 1;
  24203. this.isPlaying = false;
  24204. this.hasPlaybackControl = true;
  24205. this.source = null;
  24206. this.sourceType = 'empty';
  24207. this._startedAt = 0;
  24208. this._progress = 0;
  24209. this._connected = false;
  24210. this.filters = [];
  24211. }
  24212. getOutput() {
  24213. return this.gain;
  24214. }
  24215. setNodeSource( audioNode ) {
  24216. this.hasPlaybackControl = false;
  24217. this.sourceType = 'audioNode';
  24218. this.source = audioNode;
  24219. this.connect();
  24220. return this;
  24221. }
  24222. setMediaElementSource( mediaElement ) {
  24223. this.hasPlaybackControl = false;
  24224. this.sourceType = 'mediaNode';
  24225. this.source = this.context.createMediaElementSource( mediaElement );
  24226. this.connect();
  24227. return this;
  24228. }
  24229. setMediaStreamSource( mediaStream ) {
  24230. this.hasPlaybackControl = false;
  24231. this.sourceType = 'mediaStreamNode';
  24232. this.source = this.context.createMediaStreamSource( mediaStream );
  24233. this.connect();
  24234. return this;
  24235. }
  24236. setBuffer( audioBuffer ) {
  24237. this.buffer = audioBuffer;
  24238. this.sourceType = 'buffer';
  24239. if ( this.autoplay ) this.play();
  24240. return this;
  24241. }
  24242. play( delay = 0 ) {
  24243. if ( this.isPlaying === true ) {
  24244. console.warn( 'THREE.Audio: Audio is already playing.' );
  24245. return;
  24246. }
  24247. if ( this.hasPlaybackControl === false ) {
  24248. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24249. return;
  24250. }
  24251. this._startedAt = this.context.currentTime + delay;
  24252. const source = this.context.createBufferSource();
  24253. source.buffer = this.buffer;
  24254. source.loop = this.loop;
  24255. source.loopStart = this.loopStart;
  24256. source.loopEnd = this.loopEnd;
  24257. source.onended = this.onEnded.bind( this );
  24258. source.start( this._startedAt, this._progress + this.offset, this.duration );
  24259. this.isPlaying = true;
  24260. this.source = source;
  24261. this.setDetune( this.detune );
  24262. this.setPlaybackRate( this.playbackRate );
  24263. return this.connect();
  24264. }
  24265. pause() {
  24266. if ( this.hasPlaybackControl === false ) {
  24267. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24268. return;
  24269. }
  24270. if ( this.isPlaying === true ) {
  24271. // update current progress
  24272. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  24273. if ( this.loop === true ) {
  24274. // ensure _progress does not exceed duration with looped audios
  24275. this._progress = this._progress % ( this.duration || this.buffer.duration );
  24276. }
  24277. this.source.stop();
  24278. this.source.onended = null;
  24279. this.isPlaying = false;
  24280. }
  24281. return this;
  24282. }
  24283. stop() {
  24284. if ( this.hasPlaybackControl === false ) {
  24285. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24286. return;
  24287. }
  24288. this._progress = 0;
  24289. this.source.stop();
  24290. this.source.onended = null;
  24291. this.isPlaying = false;
  24292. return this;
  24293. }
  24294. connect() {
  24295. if ( this.filters.length > 0 ) {
  24296. this.source.connect( this.filters[ 0 ] );
  24297. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  24298. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24299. }
  24300. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24301. } else {
  24302. this.source.connect( this.getOutput() );
  24303. }
  24304. this._connected = true;
  24305. return this;
  24306. }
  24307. disconnect() {
  24308. if ( this.filters.length > 0 ) {
  24309. this.source.disconnect( this.filters[ 0 ] );
  24310. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  24311. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24312. }
  24313. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24314. } else {
  24315. this.source.disconnect( this.getOutput() );
  24316. }
  24317. this._connected = false;
  24318. return this;
  24319. }
  24320. getFilters() {
  24321. return this.filters;
  24322. }
  24323. setFilters( value ) {
  24324. if ( ! value ) value = [];
  24325. if ( this._connected === true ) {
  24326. this.disconnect();
  24327. this.filters = value.slice();
  24328. this.connect();
  24329. } else {
  24330. this.filters = value.slice();
  24331. }
  24332. return this;
  24333. }
  24334. setDetune( value ) {
  24335. this.detune = value;
  24336. if ( this.source.detune === undefined ) return; // only set detune when available
  24337. if ( this.isPlaying === true ) {
  24338. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24339. }
  24340. return this;
  24341. }
  24342. getDetune() {
  24343. return this.detune;
  24344. }
  24345. getFilter() {
  24346. return this.getFilters()[ 0 ];
  24347. }
  24348. setFilter( filter ) {
  24349. return this.setFilters( filter ? [ filter ] : [] );
  24350. }
  24351. setPlaybackRate( value ) {
  24352. if ( this.hasPlaybackControl === false ) {
  24353. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24354. return;
  24355. }
  24356. this.playbackRate = value;
  24357. if ( this.isPlaying === true ) {
  24358. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24359. }
  24360. return this;
  24361. }
  24362. getPlaybackRate() {
  24363. return this.playbackRate;
  24364. }
  24365. onEnded() {
  24366. this.isPlaying = false;
  24367. }
  24368. getLoop() {
  24369. if ( this.hasPlaybackControl === false ) {
  24370. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24371. return false;
  24372. }
  24373. return this.loop;
  24374. }
  24375. setLoop( value ) {
  24376. if ( this.hasPlaybackControl === false ) {
  24377. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24378. return;
  24379. }
  24380. this.loop = value;
  24381. if ( this.isPlaying === true ) {
  24382. this.source.loop = this.loop;
  24383. }
  24384. return this;
  24385. }
  24386. setLoopStart( value ) {
  24387. this.loopStart = value;
  24388. return this;
  24389. }
  24390. setLoopEnd( value ) {
  24391. this.loopEnd = value;
  24392. return this;
  24393. }
  24394. getVolume() {
  24395. return this.gain.gain.value;
  24396. }
  24397. setVolume( value ) {
  24398. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24399. return this;
  24400. }
  24401. }
  24402. const _position$3 = /*@__PURE__*/ new Vector3();
  24403. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  24404. const _scale$2 = /*@__PURE__*/ new Vector3();
  24405. const _orientation$1 = /*@__PURE__*/ new Vector3();
  24406. class PositionalAudio extends Audio {
  24407. constructor( listener ) {
  24408. super( listener );
  24409. this.panner = this.context.createPanner();
  24410. this.panner.panningModel = 'HRTF';
  24411. this.panner.connect( this.gain );
  24412. }
  24413. getOutput() {
  24414. return this.panner;
  24415. }
  24416. getRefDistance() {
  24417. return this.panner.refDistance;
  24418. }
  24419. setRefDistance( value ) {
  24420. this.panner.refDistance = value;
  24421. return this;
  24422. }
  24423. getRolloffFactor() {
  24424. return this.panner.rolloffFactor;
  24425. }
  24426. setRolloffFactor( value ) {
  24427. this.panner.rolloffFactor = value;
  24428. return this;
  24429. }
  24430. getDistanceModel() {
  24431. return this.panner.distanceModel;
  24432. }
  24433. setDistanceModel( value ) {
  24434. this.panner.distanceModel = value;
  24435. return this;
  24436. }
  24437. getMaxDistance() {
  24438. return this.panner.maxDistance;
  24439. }
  24440. setMaxDistance( value ) {
  24441. this.panner.maxDistance = value;
  24442. return this;
  24443. }
  24444. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24445. this.panner.coneInnerAngle = coneInnerAngle;
  24446. this.panner.coneOuterAngle = coneOuterAngle;
  24447. this.panner.coneOuterGain = coneOuterGain;
  24448. return this;
  24449. }
  24450. updateMatrixWorld( force ) {
  24451. super.updateMatrixWorld( force );
  24452. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24453. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  24454. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  24455. const panner = this.panner;
  24456. if ( panner.positionX ) {
  24457. // code path for Chrome and Firefox (see #14393)
  24458. const endTime = this.context.currentTime + this.listener.timeDelta;
  24459. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  24460. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  24461. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  24462. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  24463. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  24464. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  24465. } else {
  24466. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  24467. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  24468. }
  24469. }
  24470. }
  24471. class AudioAnalyser {
  24472. constructor( audio, fftSize = 2048 ) {
  24473. this.analyser = audio.context.createAnalyser();
  24474. this.analyser.fftSize = fftSize;
  24475. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24476. audio.getOutput().connect( this.analyser );
  24477. }
  24478. getFrequencyData() {
  24479. this.analyser.getByteFrequencyData( this.data );
  24480. return this.data;
  24481. }
  24482. getAverageFrequency() {
  24483. let value = 0;
  24484. const data = this.getFrequencyData();
  24485. for ( let i = 0; i < data.length; i ++ ) {
  24486. value += data[ i ];
  24487. }
  24488. return value / data.length;
  24489. }
  24490. }
  24491. class PropertyMixer {
  24492. constructor( binding, typeName, valueSize ) {
  24493. this.binding = binding;
  24494. this.valueSize = valueSize;
  24495. let mixFunction,
  24496. mixFunctionAdditive,
  24497. setIdentity;
  24498. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  24499. //
  24500. // interpolators can use .buffer as their .result
  24501. // the data then goes to 'incoming'
  24502. //
  24503. // 'accu0' and 'accu1' are used frame-interleaved for
  24504. // the cumulative result and are compared to detect
  24505. // changes
  24506. //
  24507. // 'orig' stores the original state of the property
  24508. //
  24509. // 'add' is used for additive cumulative results
  24510. //
  24511. // 'work' is optional and is only present for quaternion types. It is used
  24512. // to store intermediate quaternion multiplication results
  24513. switch ( typeName ) {
  24514. case 'quaternion':
  24515. mixFunction = this._slerp;
  24516. mixFunctionAdditive = this._slerpAdditive;
  24517. setIdentity = this._setAdditiveIdentityQuaternion;
  24518. this.buffer = new Float64Array( valueSize * 6 );
  24519. this._workIndex = 5;
  24520. break;
  24521. case 'string':
  24522. case 'bool':
  24523. mixFunction = this._select;
  24524. // Use the regular mix function and for additive on these types,
  24525. // additive is not relevant for non-numeric types
  24526. mixFunctionAdditive = this._select;
  24527. setIdentity = this._setAdditiveIdentityOther;
  24528. this.buffer = new Array( valueSize * 5 );
  24529. break;
  24530. default:
  24531. mixFunction = this._lerp;
  24532. mixFunctionAdditive = this._lerpAdditive;
  24533. setIdentity = this._setAdditiveIdentityNumeric;
  24534. this.buffer = new Float64Array( valueSize * 5 );
  24535. }
  24536. this._mixBufferRegion = mixFunction;
  24537. this._mixBufferRegionAdditive = mixFunctionAdditive;
  24538. this._setIdentity = setIdentity;
  24539. this._origIndex = 3;
  24540. this._addIndex = 4;
  24541. this.cumulativeWeight = 0;
  24542. this.cumulativeWeightAdditive = 0;
  24543. this.useCount = 0;
  24544. this.referenceCount = 0;
  24545. }
  24546. // accumulate data in the 'incoming' region into 'accu<i>'
  24547. accumulate( accuIndex, weight ) {
  24548. // note: happily accumulating nothing when weight = 0, the caller knows
  24549. // the weight and shouldn't have made the call in the first place
  24550. const buffer = this.buffer,
  24551. stride = this.valueSize,
  24552. offset = accuIndex * stride + stride;
  24553. let currentWeight = this.cumulativeWeight;
  24554. if ( currentWeight === 0 ) {
  24555. // accuN := incoming * weight
  24556. for ( let i = 0; i !== stride; ++ i ) {
  24557. buffer[ offset + i ] = buffer[ i ];
  24558. }
  24559. currentWeight = weight;
  24560. } else {
  24561. // accuN := accuN + incoming * weight
  24562. currentWeight += weight;
  24563. const mix = weight / currentWeight;
  24564. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24565. }
  24566. this.cumulativeWeight = currentWeight;
  24567. }
  24568. // accumulate data in the 'incoming' region into 'add'
  24569. accumulateAdditive( weight ) {
  24570. const buffer = this.buffer,
  24571. stride = this.valueSize,
  24572. offset = stride * this._addIndex;
  24573. if ( this.cumulativeWeightAdditive === 0 ) {
  24574. // add = identity
  24575. this._setIdentity();
  24576. }
  24577. // add := add + incoming * weight
  24578. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  24579. this.cumulativeWeightAdditive += weight;
  24580. }
  24581. // apply the state of 'accu<i>' to the binding when accus differ
  24582. apply( accuIndex ) {
  24583. const stride = this.valueSize,
  24584. buffer = this.buffer,
  24585. offset = accuIndex * stride + stride,
  24586. weight = this.cumulativeWeight,
  24587. weightAdditive = this.cumulativeWeightAdditive,
  24588. binding = this.binding;
  24589. this.cumulativeWeight = 0;
  24590. this.cumulativeWeightAdditive = 0;
  24591. if ( weight < 1 ) {
  24592. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24593. const originalValueOffset = stride * this._origIndex;
  24594. this._mixBufferRegion(
  24595. buffer, offset, originalValueOffset, 1 - weight, stride );
  24596. }
  24597. if ( weightAdditive > 0 ) {
  24598. // accuN := accuN + additive accuN
  24599. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  24600. }
  24601. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  24602. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24603. // value has changed -> update scene graph
  24604. binding.setValue( buffer, offset );
  24605. break;
  24606. }
  24607. }
  24608. }
  24609. // remember the state of the bound property and copy it to both accus
  24610. saveOriginalState() {
  24611. const binding = this.binding;
  24612. const buffer = this.buffer,
  24613. stride = this.valueSize,
  24614. originalValueOffset = stride * this._origIndex;
  24615. binding.getValue( buffer, originalValueOffset );
  24616. // accu[0..1] := orig -- initially detect changes against the original
  24617. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24618. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24619. }
  24620. // Add to identity for additive
  24621. this._setIdentity();
  24622. this.cumulativeWeight = 0;
  24623. this.cumulativeWeightAdditive = 0;
  24624. }
  24625. // apply the state previously taken via 'saveOriginalState' to the binding
  24626. restoreOriginalState() {
  24627. const originalValueOffset = this.valueSize * 3;
  24628. this.binding.setValue( this.buffer, originalValueOffset );
  24629. }
  24630. _setAdditiveIdentityNumeric() {
  24631. const startIndex = this._addIndex * this.valueSize;
  24632. const endIndex = startIndex + this.valueSize;
  24633. for ( let i = startIndex; i < endIndex; i ++ ) {
  24634. this.buffer[ i ] = 0;
  24635. }
  24636. }
  24637. _setAdditiveIdentityQuaternion() {
  24638. this._setAdditiveIdentityNumeric();
  24639. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  24640. }
  24641. _setAdditiveIdentityOther() {
  24642. const startIndex = this._origIndex * this.valueSize;
  24643. const targetIndex = this._addIndex * this.valueSize;
  24644. for ( let i = 0; i < this.valueSize; i ++ ) {
  24645. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  24646. }
  24647. }
  24648. // mix functions
  24649. _select( buffer, dstOffset, srcOffset, t, stride ) {
  24650. if ( t >= 0.5 ) {
  24651. for ( let i = 0; i !== stride; ++ i ) {
  24652. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24653. }
  24654. }
  24655. }
  24656. _slerp( buffer, dstOffset, srcOffset, t ) {
  24657. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24658. }
  24659. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  24660. const workOffset = this._workIndex * stride;
  24661. // Store result in intermediate buffer offset
  24662. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  24663. // Slerp to the intermediate result
  24664. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  24665. }
  24666. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  24667. const s = 1 - t;
  24668. for ( let i = 0; i !== stride; ++ i ) {
  24669. const j = dstOffset + i;
  24670. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24671. }
  24672. }
  24673. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  24674. for ( let i = 0; i !== stride; ++ i ) {
  24675. const j = dstOffset + i;
  24676. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  24677. }
  24678. }
  24679. }
  24680. // Characters [].:/ are reserved for track binding syntax.
  24681. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24682. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  24683. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24684. // only latin characters, and the unicode \p{L} is not yet supported. So
  24685. // instead, we exclude reserved characters and match everything else.
  24686. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  24687. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24688. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24689. // be matched to parse the rest of the track name.
  24690. const _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  24691. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24692. const _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  24693. // Object on target node, and accessor. May not contain reserved
  24694. // characters. Accessor may contain any character except closing bracket.
  24695. const _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  24696. // Property and accessor. May not contain reserved characters. Accessor may
  24697. // contain any non-bracket characters.
  24698. const _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  24699. const _trackRe = new RegExp( ''
  24700. + '^'
  24701. + _directoryRe
  24702. + _nodeRe
  24703. + _objectRe
  24704. + _propertyRe
  24705. + '$'
  24706. );
  24707. const _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24708. function Composite( targetGroup, path, optionalParsedPath ) {
  24709. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24710. this._targetGroup = targetGroup;
  24711. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24712. }
  24713. Object.assign( Composite.prototype, {
  24714. getValue: function ( array, offset ) {
  24715. this.bind(); // bind all binding
  24716. const firstValidIndex = this._targetGroup.nCachedObjects_,
  24717. binding = this._bindings[ firstValidIndex ];
  24718. // and only call .getValue on the first
  24719. if ( binding !== undefined ) binding.getValue( array, offset );
  24720. },
  24721. setValue: function ( array, offset ) {
  24722. const bindings = this._bindings;
  24723. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24724. bindings[ i ].setValue( array, offset );
  24725. }
  24726. },
  24727. bind: function () {
  24728. const bindings = this._bindings;
  24729. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24730. bindings[ i ].bind();
  24731. }
  24732. },
  24733. unbind: function () {
  24734. const bindings = this._bindings;
  24735. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24736. bindings[ i ].unbind();
  24737. }
  24738. }
  24739. } );
  24740. function PropertyBinding( rootNode, path, parsedPath ) {
  24741. this.path = path;
  24742. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24743. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24744. this.rootNode = rootNode;
  24745. }
  24746. Object.assign( PropertyBinding, {
  24747. Composite: Composite,
  24748. create: function ( root, path, parsedPath ) {
  24749. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24750. return new PropertyBinding( root, path, parsedPath );
  24751. } else {
  24752. return new PropertyBinding.Composite( root, path, parsedPath );
  24753. }
  24754. },
  24755. /**
  24756. * Replaces spaces with underscores and removes unsupported characters from
  24757. * node names, to ensure compatibility with parseTrackName().
  24758. *
  24759. * @param {string} name Node name to be sanitized.
  24760. * @return {string}
  24761. */
  24762. sanitizeNodeName: function ( name ) {
  24763. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  24764. },
  24765. parseTrackName: function ( trackName ) {
  24766. const matches = _trackRe.exec( trackName );
  24767. if ( ! matches ) {
  24768. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24769. }
  24770. const results = {
  24771. // directoryName: matches[ 1 ], // (tschw) currently unused
  24772. nodeName: matches[ 2 ],
  24773. objectName: matches[ 3 ],
  24774. objectIndex: matches[ 4 ],
  24775. propertyName: matches[ 5 ], // required
  24776. propertyIndex: matches[ 6 ]
  24777. };
  24778. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24779. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24780. const objectName = results.nodeName.substring( lastDot + 1 );
  24781. // Object names must be checked against an allowlist. Otherwise, there
  24782. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24783. // 'bar' could be the objectName, or part of a nodeName (which can
  24784. // include '.' characters).
  24785. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24786. results.nodeName = results.nodeName.substring( 0, lastDot );
  24787. results.objectName = objectName;
  24788. }
  24789. }
  24790. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24791. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24792. }
  24793. return results;
  24794. },
  24795. findNode: function ( root, nodeName ) {
  24796. if ( ! nodeName || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24797. return root;
  24798. }
  24799. // search into skeleton bones.
  24800. if ( root.skeleton ) {
  24801. const bone = root.skeleton.getBoneByName( nodeName );
  24802. if ( bone !== undefined ) {
  24803. return bone;
  24804. }
  24805. }
  24806. // search into node subtree.
  24807. if ( root.children ) {
  24808. const searchNodeSubtree = function ( children ) {
  24809. for ( let i = 0; i < children.length; i ++ ) {
  24810. const childNode = children[ i ];
  24811. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24812. return childNode;
  24813. }
  24814. const result = searchNodeSubtree( childNode.children );
  24815. if ( result ) return result;
  24816. }
  24817. return null;
  24818. };
  24819. const subTreeNode = searchNodeSubtree( root.children );
  24820. if ( subTreeNode ) {
  24821. return subTreeNode;
  24822. }
  24823. }
  24824. return null;
  24825. }
  24826. } );
  24827. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24828. // these are used to "bind" a nonexistent property
  24829. _getValue_unavailable: function () {},
  24830. _setValue_unavailable: function () {},
  24831. BindingType: {
  24832. Direct: 0,
  24833. EntireArray: 1,
  24834. ArrayElement: 2,
  24835. HasFromToArray: 3
  24836. },
  24837. Versioning: {
  24838. None: 0,
  24839. NeedsUpdate: 1,
  24840. MatrixWorldNeedsUpdate: 2
  24841. },
  24842. GetterByBindingType: [
  24843. function getValue_direct( buffer, offset ) {
  24844. buffer[ offset ] = this.node[ this.propertyName ];
  24845. },
  24846. function getValue_array( buffer, offset ) {
  24847. const source = this.resolvedProperty;
  24848. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  24849. buffer[ offset ++ ] = source[ i ];
  24850. }
  24851. },
  24852. function getValue_arrayElement( buffer, offset ) {
  24853. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  24854. },
  24855. function getValue_toArray( buffer, offset ) {
  24856. this.resolvedProperty.toArray( buffer, offset );
  24857. }
  24858. ],
  24859. SetterByBindingTypeAndVersioning: [
  24860. [
  24861. // Direct
  24862. function setValue_direct( buffer, offset ) {
  24863. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24864. },
  24865. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  24866. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24867. this.targetObject.needsUpdate = true;
  24868. },
  24869. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24870. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24871. this.targetObject.matrixWorldNeedsUpdate = true;
  24872. }
  24873. ], [
  24874. // EntireArray
  24875. function setValue_array( buffer, offset ) {
  24876. const dest = this.resolvedProperty;
  24877. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  24878. dest[ i ] = buffer[ offset ++ ];
  24879. }
  24880. },
  24881. function setValue_array_setNeedsUpdate( buffer, offset ) {
  24882. const dest = this.resolvedProperty;
  24883. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  24884. dest[ i ] = buffer[ offset ++ ];
  24885. }
  24886. this.targetObject.needsUpdate = true;
  24887. },
  24888. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24889. const dest = this.resolvedProperty;
  24890. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  24891. dest[ i ] = buffer[ offset ++ ];
  24892. }
  24893. this.targetObject.matrixWorldNeedsUpdate = true;
  24894. }
  24895. ], [
  24896. // ArrayElement
  24897. function setValue_arrayElement( buffer, offset ) {
  24898. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24899. },
  24900. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  24901. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24902. this.targetObject.needsUpdate = true;
  24903. },
  24904. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24905. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24906. this.targetObject.matrixWorldNeedsUpdate = true;
  24907. }
  24908. ], [
  24909. // HasToFromArray
  24910. function setValue_fromArray( buffer, offset ) {
  24911. this.resolvedProperty.fromArray( buffer, offset );
  24912. },
  24913. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  24914. this.resolvedProperty.fromArray( buffer, offset );
  24915. this.targetObject.needsUpdate = true;
  24916. },
  24917. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24918. this.resolvedProperty.fromArray( buffer, offset );
  24919. this.targetObject.matrixWorldNeedsUpdate = true;
  24920. }
  24921. ]
  24922. ],
  24923. getValue: function getValue_unbound( targetArray, offset ) {
  24924. this.bind();
  24925. this.getValue( targetArray, offset );
  24926. // Note: This class uses a State pattern on a per-method basis:
  24927. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  24928. // prototype version of these methods with one that represents
  24929. // the bound state. When the property is not found, the methods
  24930. // become no-ops.
  24931. },
  24932. setValue: function getValue_unbound( sourceArray, offset ) {
  24933. this.bind();
  24934. this.setValue( sourceArray, offset );
  24935. },
  24936. // create getter / setter pair for a property in the scene graph
  24937. bind: function () {
  24938. let targetObject = this.node;
  24939. const parsedPath = this.parsedPath;
  24940. const objectName = parsedPath.objectName;
  24941. const propertyName = parsedPath.propertyName;
  24942. let propertyIndex = parsedPath.propertyIndex;
  24943. if ( ! targetObject ) {
  24944. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  24945. this.node = targetObject;
  24946. }
  24947. // set fail state so we can just 'return' on error
  24948. this.getValue = this._getValue_unavailable;
  24949. this.setValue = this._setValue_unavailable;
  24950. // ensure there is a value node
  24951. if ( ! targetObject ) {
  24952. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  24953. return;
  24954. }
  24955. if ( objectName ) {
  24956. let objectIndex = parsedPath.objectIndex;
  24957. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  24958. switch ( objectName ) {
  24959. case 'materials':
  24960. if ( ! targetObject.material ) {
  24961. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  24962. return;
  24963. }
  24964. if ( ! targetObject.material.materials ) {
  24965. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  24966. return;
  24967. }
  24968. targetObject = targetObject.material.materials;
  24969. break;
  24970. case 'bones':
  24971. if ( ! targetObject.skeleton ) {
  24972. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  24973. return;
  24974. }
  24975. // potential future optimization: skip this if propertyIndex is already an integer
  24976. // and convert the integer string to a true integer.
  24977. targetObject = targetObject.skeleton.bones;
  24978. // support resolving morphTarget names into indices.
  24979. for ( let i = 0; i < targetObject.length; i ++ ) {
  24980. if ( targetObject[ i ].name === objectIndex ) {
  24981. objectIndex = i;
  24982. break;
  24983. }
  24984. }
  24985. break;
  24986. default:
  24987. if ( targetObject[ objectName ] === undefined ) {
  24988. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  24989. return;
  24990. }
  24991. targetObject = targetObject[ objectName ];
  24992. }
  24993. if ( objectIndex !== undefined ) {
  24994. if ( targetObject[ objectIndex ] === undefined ) {
  24995. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  24996. return;
  24997. }
  24998. targetObject = targetObject[ objectIndex ];
  24999. }
  25000. }
  25001. // resolve property
  25002. const nodeProperty = targetObject[ propertyName ];
  25003. if ( nodeProperty === undefined ) {
  25004. const nodeName = parsedPath.nodeName;
  25005. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25006. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25007. return;
  25008. }
  25009. // determine versioning scheme
  25010. let versioning = this.Versioning.None;
  25011. this.targetObject = targetObject;
  25012. if ( targetObject.needsUpdate !== undefined ) { // material
  25013. versioning = this.Versioning.NeedsUpdate;
  25014. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25015. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25016. }
  25017. // determine how the property gets bound
  25018. let bindingType = this.BindingType.Direct;
  25019. if ( propertyIndex !== undefined ) {
  25020. // access a sub element of the property array (only primitives are supported right now)
  25021. if ( propertyName === 'morphTargetInfluences' ) {
  25022. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25023. // support resolving morphTarget names into indices.
  25024. if ( ! targetObject.geometry ) {
  25025. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25026. return;
  25027. }
  25028. if ( targetObject.geometry.isBufferGeometry ) {
  25029. if ( ! targetObject.geometry.morphAttributes ) {
  25030. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25031. return;
  25032. }
  25033. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  25034. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  25035. }
  25036. } else {
  25037. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  25038. return;
  25039. }
  25040. }
  25041. bindingType = this.BindingType.ArrayElement;
  25042. this.resolvedProperty = nodeProperty;
  25043. this.propertyIndex = propertyIndex;
  25044. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25045. // must use copy for Object3D.Euler/Quaternion
  25046. bindingType = this.BindingType.HasFromToArray;
  25047. this.resolvedProperty = nodeProperty;
  25048. } else if ( Array.isArray( nodeProperty ) ) {
  25049. bindingType = this.BindingType.EntireArray;
  25050. this.resolvedProperty = nodeProperty;
  25051. } else {
  25052. this.propertyName = propertyName;
  25053. }
  25054. // select getter / setter
  25055. this.getValue = this.GetterByBindingType[ bindingType ];
  25056. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25057. },
  25058. unbind: function () {
  25059. this.node = null;
  25060. // back to the prototype version of getValue / setValue
  25061. // note: avoiding to mutate the shape of 'this' via 'delete'
  25062. this.getValue = this._getValue_unbound;
  25063. this.setValue = this._setValue_unbound;
  25064. }
  25065. } );
  25066. // DECLARE ALIAS AFTER assign prototype
  25067. Object.assign( PropertyBinding.prototype, {
  25068. // initial state of these methods that calls 'bind'
  25069. _getValue_unbound: PropertyBinding.prototype.getValue,
  25070. _setValue_unbound: PropertyBinding.prototype.setValue,
  25071. } );
  25072. /**
  25073. *
  25074. * A group of objects that receives a shared animation state.
  25075. *
  25076. * Usage:
  25077. *
  25078. * - Add objects you would otherwise pass as 'root' to the
  25079. * constructor or the .clipAction method of AnimationMixer.
  25080. *
  25081. * - Instead pass this object as 'root'.
  25082. *
  25083. * - You can also add and remove objects later when the mixer
  25084. * is running.
  25085. *
  25086. * Note:
  25087. *
  25088. * Objects of this class appear as one object to the mixer,
  25089. * so cache control of the individual objects must be done
  25090. * on the group.
  25091. *
  25092. * Limitation:
  25093. *
  25094. * - The animated properties must be compatible among the
  25095. * all objects in the group.
  25096. *
  25097. * - A single property can either be controlled through a
  25098. * target group or directly, but not both.
  25099. */
  25100. class AnimationObjectGroup {
  25101. constructor() {
  25102. this.uuid = MathUtils.generateUUID();
  25103. // cached objects followed by the active ones
  25104. this._objects = Array.prototype.slice.call( arguments );
  25105. this.nCachedObjects_ = 0; // threshold
  25106. // note: read by PropertyBinding.Composite
  25107. const indices = {};
  25108. this._indicesByUUID = indices; // for bookkeeping
  25109. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25110. indices[ arguments[ i ].uuid ] = i;
  25111. }
  25112. this._paths = []; // inside: string
  25113. this._parsedPaths = []; // inside: { we don't care, here }
  25114. this._bindings = []; // inside: Array< PropertyBinding >
  25115. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25116. const scope = this;
  25117. this.stats = {
  25118. objects: {
  25119. get total() {
  25120. return scope._objects.length;
  25121. },
  25122. get inUse() {
  25123. return this.total - scope.nCachedObjects_;
  25124. }
  25125. },
  25126. get bindingsPerObject() {
  25127. return scope._bindings.length;
  25128. }
  25129. };
  25130. }
  25131. add() {
  25132. const objects = this._objects,
  25133. indicesByUUID = this._indicesByUUID,
  25134. paths = this._paths,
  25135. parsedPaths = this._parsedPaths,
  25136. bindings = this._bindings,
  25137. nBindings = bindings.length;
  25138. let knownObject = undefined,
  25139. nObjects = objects.length,
  25140. nCachedObjects = this.nCachedObjects_;
  25141. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25142. const object = arguments[ i ],
  25143. uuid = object.uuid;
  25144. let index = indicesByUUID[ uuid ];
  25145. if ( index === undefined ) {
  25146. // unknown object -> add it to the ACTIVE region
  25147. index = nObjects ++;
  25148. indicesByUUID[ uuid ] = index;
  25149. objects.push( object );
  25150. // accounting is done, now do the same for all bindings
  25151. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25152. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25153. }
  25154. } else if ( index < nCachedObjects ) {
  25155. knownObject = objects[ index ];
  25156. // move existing object to the ACTIVE region
  25157. const firstActiveIndex = -- nCachedObjects,
  25158. lastCachedObject = objects[ firstActiveIndex ];
  25159. indicesByUUID[ lastCachedObject.uuid ] = index;
  25160. objects[ index ] = lastCachedObject;
  25161. indicesByUUID[ uuid ] = firstActiveIndex;
  25162. objects[ firstActiveIndex ] = object;
  25163. // accounting is done, now do the same for all bindings
  25164. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25165. const bindingsForPath = bindings[ j ],
  25166. lastCached = bindingsForPath[ firstActiveIndex ];
  25167. let binding = bindingsForPath[ index ];
  25168. bindingsForPath[ index ] = lastCached;
  25169. if ( binding === undefined ) {
  25170. // since we do not bother to create new bindings
  25171. // for objects that are cached, the binding may
  25172. // or may not exist
  25173. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25174. }
  25175. bindingsForPath[ firstActiveIndex ] = binding;
  25176. }
  25177. } else if ( objects[ index ] !== knownObject ) {
  25178. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25179. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25180. } // else the object is already where we want it to be
  25181. } // for arguments
  25182. this.nCachedObjects_ = nCachedObjects;
  25183. }
  25184. remove() {
  25185. const objects = this._objects,
  25186. indicesByUUID = this._indicesByUUID,
  25187. bindings = this._bindings,
  25188. nBindings = bindings.length;
  25189. let nCachedObjects = this.nCachedObjects_;
  25190. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25191. const object = arguments[ i ],
  25192. uuid = object.uuid,
  25193. index = indicesByUUID[ uuid ];
  25194. if ( index !== undefined && index >= nCachedObjects ) {
  25195. // move existing object into the CACHED region
  25196. const lastCachedIndex = nCachedObjects ++,
  25197. firstActiveObject = objects[ lastCachedIndex ];
  25198. indicesByUUID[ firstActiveObject.uuid ] = index;
  25199. objects[ index ] = firstActiveObject;
  25200. indicesByUUID[ uuid ] = lastCachedIndex;
  25201. objects[ lastCachedIndex ] = object;
  25202. // accounting is done, now do the same for all bindings
  25203. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25204. const bindingsForPath = bindings[ j ],
  25205. firstActive = bindingsForPath[ lastCachedIndex ],
  25206. binding = bindingsForPath[ index ];
  25207. bindingsForPath[ index ] = firstActive;
  25208. bindingsForPath[ lastCachedIndex ] = binding;
  25209. }
  25210. }
  25211. } // for arguments
  25212. this.nCachedObjects_ = nCachedObjects;
  25213. }
  25214. // remove & forget
  25215. uncache() {
  25216. const objects = this._objects,
  25217. indicesByUUID = this._indicesByUUID,
  25218. bindings = this._bindings,
  25219. nBindings = bindings.length;
  25220. let nCachedObjects = this.nCachedObjects_,
  25221. nObjects = objects.length;
  25222. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25223. const object = arguments[ i ],
  25224. uuid = object.uuid,
  25225. index = indicesByUUID[ uuid ];
  25226. if ( index !== undefined ) {
  25227. delete indicesByUUID[ uuid ];
  25228. if ( index < nCachedObjects ) {
  25229. // object is cached, shrink the CACHED region
  25230. const firstActiveIndex = -- nCachedObjects,
  25231. lastCachedObject = objects[ firstActiveIndex ],
  25232. lastIndex = -- nObjects,
  25233. lastObject = objects[ lastIndex ];
  25234. // last cached object takes this object's place
  25235. indicesByUUID[ lastCachedObject.uuid ] = index;
  25236. objects[ index ] = lastCachedObject;
  25237. // last object goes to the activated slot and pop
  25238. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25239. objects[ firstActiveIndex ] = lastObject;
  25240. objects.pop();
  25241. // accounting is done, now do the same for all bindings
  25242. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25243. const bindingsForPath = bindings[ j ],
  25244. lastCached = bindingsForPath[ firstActiveIndex ],
  25245. last = bindingsForPath[ lastIndex ];
  25246. bindingsForPath[ index ] = lastCached;
  25247. bindingsForPath[ firstActiveIndex ] = last;
  25248. bindingsForPath.pop();
  25249. }
  25250. } else {
  25251. // object is active, just swap with the last and pop
  25252. const lastIndex = -- nObjects,
  25253. lastObject = objects[ lastIndex ];
  25254. if ( lastIndex > 0 ) {
  25255. indicesByUUID[ lastObject.uuid ] = index;
  25256. }
  25257. objects[ index ] = lastObject;
  25258. objects.pop();
  25259. // accounting is done, now do the same for all bindings
  25260. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25261. const bindingsForPath = bindings[ j ];
  25262. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25263. bindingsForPath.pop();
  25264. }
  25265. } // cached or active
  25266. } // if object is known
  25267. } // for arguments
  25268. this.nCachedObjects_ = nCachedObjects;
  25269. }
  25270. // Internal interface used by befriended PropertyBinding.Composite:
  25271. subscribe_( path, parsedPath ) {
  25272. // returns an array of bindings for the given path that is changed
  25273. // according to the contained objects in the group
  25274. const indicesByPath = this._bindingsIndicesByPath;
  25275. let index = indicesByPath[ path ];
  25276. const bindings = this._bindings;
  25277. if ( index !== undefined ) return bindings[ index ];
  25278. const paths = this._paths,
  25279. parsedPaths = this._parsedPaths,
  25280. objects = this._objects,
  25281. nObjects = objects.length,
  25282. nCachedObjects = this.nCachedObjects_,
  25283. bindingsForPath = new Array( nObjects );
  25284. index = bindings.length;
  25285. indicesByPath[ path ] = index;
  25286. paths.push( path );
  25287. parsedPaths.push( parsedPath );
  25288. bindings.push( bindingsForPath );
  25289. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25290. const object = objects[ i ];
  25291. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25292. }
  25293. return bindingsForPath;
  25294. }
  25295. unsubscribe_( path ) {
  25296. // tells the group to forget about a property path and no longer
  25297. // update the array previously obtained with 'subscribe_'
  25298. const indicesByPath = this._bindingsIndicesByPath,
  25299. index = indicesByPath[ path ];
  25300. if ( index !== undefined ) {
  25301. const paths = this._paths,
  25302. parsedPaths = this._parsedPaths,
  25303. bindings = this._bindings,
  25304. lastBindingsIndex = bindings.length - 1,
  25305. lastBindings = bindings[ lastBindingsIndex ],
  25306. lastBindingsPath = path[ lastBindingsIndex ];
  25307. indicesByPath[ lastBindingsPath ] = index;
  25308. bindings[ index ] = lastBindings;
  25309. bindings.pop();
  25310. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25311. parsedPaths.pop();
  25312. paths[ index ] = paths[ lastBindingsIndex ];
  25313. paths.pop();
  25314. }
  25315. }
  25316. }
  25317. AnimationObjectGroup.prototype.isAnimationObjectGroup = true;
  25318. class AnimationAction {
  25319. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  25320. this._mixer = mixer;
  25321. this._clip = clip;
  25322. this._localRoot = localRoot;
  25323. this.blendMode = blendMode;
  25324. const tracks = clip.tracks,
  25325. nTracks = tracks.length,
  25326. interpolants = new Array( nTracks );
  25327. const interpolantSettings = {
  25328. endingStart: ZeroCurvatureEnding,
  25329. endingEnd: ZeroCurvatureEnding
  25330. };
  25331. for ( let i = 0; i !== nTracks; ++ i ) {
  25332. const interpolant = tracks[ i ].createInterpolant( null );
  25333. interpolants[ i ] = interpolant;
  25334. interpolant.settings = interpolantSettings;
  25335. }
  25336. this._interpolantSettings = interpolantSettings;
  25337. this._interpolants = interpolants; // bound by the mixer
  25338. // inside: PropertyMixer (managed by the mixer)
  25339. this._propertyBindings = new Array( nTracks );
  25340. this._cacheIndex = null; // for the memory manager
  25341. this._byClipCacheIndex = null; // for the memory manager
  25342. this._timeScaleInterpolant = null;
  25343. this._weightInterpolant = null;
  25344. this.loop = LoopRepeat;
  25345. this._loopCount = - 1;
  25346. // global mixer time when the action is to be started
  25347. // it's set back to 'null' upon start of the action
  25348. this._startTime = null;
  25349. // scaled local time of the action
  25350. // gets clamped or wrapped to 0..clip.duration according to loop
  25351. this.time = 0;
  25352. this.timeScale = 1;
  25353. this._effectiveTimeScale = 1;
  25354. this.weight = 1;
  25355. this._effectiveWeight = 1;
  25356. this.repetitions = Infinity; // no. of repetitions when looping
  25357. this.paused = false; // true -> zero effective time scale
  25358. this.enabled = true; // false -> zero effective weight
  25359. this.clampWhenFinished = false;// keep feeding the last frame?
  25360. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25361. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25362. }
  25363. // State & Scheduling
  25364. play() {
  25365. this._mixer._activateAction( this );
  25366. return this;
  25367. }
  25368. stop() {
  25369. this._mixer._deactivateAction( this );
  25370. return this.reset();
  25371. }
  25372. reset() {
  25373. this.paused = false;
  25374. this.enabled = true;
  25375. this.time = 0; // restart clip
  25376. this._loopCount = - 1;// forget previous loops
  25377. this._startTime = null;// forget scheduling
  25378. return this.stopFading().stopWarping();
  25379. }
  25380. isRunning() {
  25381. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25382. this._startTime === null && this._mixer._isActiveAction( this );
  25383. }
  25384. // return true when play has been called
  25385. isScheduled() {
  25386. return this._mixer._isActiveAction( this );
  25387. }
  25388. startAt( time ) {
  25389. this._startTime = time;
  25390. return this;
  25391. }
  25392. setLoop( mode, repetitions ) {
  25393. this.loop = mode;
  25394. this.repetitions = repetitions;
  25395. return this;
  25396. }
  25397. // Weight
  25398. // set the weight stopping any scheduled fading
  25399. // although .enabled = false yields an effective weight of zero, this
  25400. // method does *not* change .enabled, because it would be confusing
  25401. setEffectiveWeight( weight ) {
  25402. this.weight = weight;
  25403. // note: same logic as when updated at runtime
  25404. this._effectiveWeight = this.enabled ? weight : 0;
  25405. return this.stopFading();
  25406. }
  25407. // return the weight considering fading and .enabled
  25408. getEffectiveWeight() {
  25409. return this._effectiveWeight;
  25410. }
  25411. fadeIn( duration ) {
  25412. return this._scheduleFading( duration, 0, 1 );
  25413. }
  25414. fadeOut( duration ) {
  25415. return this._scheduleFading( duration, 1, 0 );
  25416. }
  25417. crossFadeFrom( fadeOutAction, duration, warp ) {
  25418. fadeOutAction.fadeOut( duration );
  25419. this.fadeIn( duration );
  25420. if ( warp ) {
  25421. const fadeInDuration = this._clip.duration,
  25422. fadeOutDuration = fadeOutAction._clip.duration,
  25423. startEndRatio = fadeOutDuration / fadeInDuration,
  25424. endStartRatio = fadeInDuration / fadeOutDuration;
  25425. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25426. this.warp( endStartRatio, 1.0, duration );
  25427. }
  25428. return this;
  25429. }
  25430. crossFadeTo( fadeInAction, duration, warp ) {
  25431. return fadeInAction.crossFadeFrom( this, duration, warp );
  25432. }
  25433. stopFading() {
  25434. const weightInterpolant = this._weightInterpolant;
  25435. if ( weightInterpolant !== null ) {
  25436. this._weightInterpolant = null;
  25437. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25438. }
  25439. return this;
  25440. }
  25441. // Time Scale Control
  25442. // set the time scale stopping any scheduled warping
  25443. // although .paused = true yields an effective time scale of zero, this
  25444. // method does *not* change .paused, because it would be confusing
  25445. setEffectiveTimeScale( timeScale ) {
  25446. this.timeScale = timeScale;
  25447. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25448. return this.stopWarping();
  25449. }
  25450. // return the time scale considering warping and .paused
  25451. getEffectiveTimeScale() {
  25452. return this._effectiveTimeScale;
  25453. }
  25454. setDuration( duration ) {
  25455. this.timeScale = this._clip.duration / duration;
  25456. return this.stopWarping();
  25457. }
  25458. syncWith( action ) {
  25459. this.time = action.time;
  25460. this.timeScale = action.timeScale;
  25461. return this.stopWarping();
  25462. }
  25463. halt( duration ) {
  25464. return this.warp( this._effectiveTimeScale, 0, duration );
  25465. }
  25466. warp( startTimeScale, endTimeScale, duration ) {
  25467. const mixer = this._mixer,
  25468. now = mixer.time,
  25469. timeScale = this.timeScale;
  25470. let interpolant = this._timeScaleInterpolant;
  25471. if ( interpolant === null ) {
  25472. interpolant = mixer._lendControlInterpolant();
  25473. this._timeScaleInterpolant = interpolant;
  25474. }
  25475. const times = interpolant.parameterPositions,
  25476. values = interpolant.sampleValues;
  25477. times[ 0 ] = now;
  25478. times[ 1 ] = now + duration;
  25479. values[ 0 ] = startTimeScale / timeScale;
  25480. values[ 1 ] = endTimeScale / timeScale;
  25481. return this;
  25482. }
  25483. stopWarping() {
  25484. const timeScaleInterpolant = this._timeScaleInterpolant;
  25485. if ( timeScaleInterpolant !== null ) {
  25486. this._timeScaleInterpolant = null;
  25487. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25488. }
  25489. return this;
  25490. }
  25491. // Object Accessors
  25492. getMixer() {
  25493. return this._mixer;
  25494. }
  25495. getClip() {
  25496. return this._clip;
  25497. }
  25498. getRoot() {
  25499. return this._localRoot || this._mixer._root;
  25500. }
  25501. // Interna
  25502. _update( time, deltaTime, timeDirection, accuIndex ) {
  25503. // called by the mixer
  25504. if ( ! this.enabled ) {
  25505. // call ._updateWeight() to update ._effectiveWeight
  25506. this._updateWeight( time );
  25507. return;
  25508. }
  25509. const startTime = this._startTime;
  25510. if ( startTime !== null ) {
  25511. // check for scheduled start of action
  25512. const timeRunning = ( time - startTime ) * timeDirection;
  25513. if ( timeRunning < 0 || timeDirection === 0 ) {
  25514. return; // yet to come / don't decide when delta = 0
  25515. }
  25516. // start
  25517. this._startTime = null; // unschedule
  25518. deltaTime = timeDirection * timeRunning;
  25519. }
  25520. // apply time scale and advance time
  25521. deltaTime *= this._updateTimeScale( time );
  25522. const clipTime = this._updateTime( deltaTime );
  25523. // note: _updateTime may disable the action resulting in
  25524. // an effective weight of 0
  25525. const weight = this._updateWeight( time );
  25526. if ( weight > 0 ) {
  25527. const interpolants = this._interpolants;
  25528. const propertyMixers = this._propertyBindings;
  25529. switch ( this.blendMode ) {
  25530. case AdditiveAnimationBlendMode:
  25531. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  25532. interpolants[ j ].evaluate( clipTime );
  25533. propertyMixers[ j ].accumulateAdditive( weight );
  25534. }
  25535. break;
  25536. case NormalAnimationBlendMode:
  25537. default:
  25538. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  25539. interpolants[ j ].evaluate( clipTime );
  25540. propertyMixers[ j ].accumulate( accuIndex, weight );
  25541. }
  25542. }
  25543. }
  25544. }
  25545. _updateWeight( time ) {
  25546. let weight = 0;
  25547. if ( this.enabled ) {
  25548. weight = this.weight;
  25549. const interpolant = this._weightInterpolant;
  25550. if ( interpolant !== null ) {
  25551. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  25552. weight *= interpolantValue;
  25553. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25554. this.stopFading();
  25555. if ( interpolantValue === 0 ) {
  25556. // faded out, disable
  25557. this.enabled = false;
  25558. }
  25559. }
  25560. }
  25561. }
  25562. this._effectiveWeight = weight;
  25563. return weight;
  25564. }
  25565. _updateTimeScale( time ) {
  25566. let timeScale = 0;
  25567. if ( ! this.paused ) {
  25568. timeScale = this.timeScale;
  25569. const interpolant = this._timeScaleInterpolant;
  25570. if ( interpolant !== null ) {
  25571. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  25572. timeScale *= interpolantValue;
  25573. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25574. this.stopWarping();
  25575. if ( timeScale === 0 ) {
  25576. // motion has halted, pause
  25577. this.paused = true;
  25578. } else {
  25579. // warp done - apply final time scale
  25580. this.timeScale = timeScale;
  25581. }
  25582. }
  25583. }
  25584. }
  25585. this._effectiveTimeScale = timeScale;
  25586. return timeScale;
  25587. }
  25588. _updateTime( deltaTime ) {
  25589. const duration = this._clip.duration;
  25590. const loop = this.loop;
  25591. let time = this.time + deltaTime;
  25592. let loopCount = this._loopCount;
  25593. const pingPong = ( loop === LoopPingPong );
  25594. if ( deltaTime === 0 ) {
  25595. if ( loopCount === - 1 ) return time;
  25596. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25597. }
  25598. if ( loop === LoopOnce ) {
  25599. if ( loopCount === - 1 ) {
  25600. // just started
  25601. this._loopCount = 0;
  25602. this._setEndings( true, true, false );
  25603. }
  25604. handle_stop: {
  25605. if ( time >= duration ) {
  25606. time = duration;
  25607. } else if ( time < 0 ) {
  25608. time = 0;
  25609. } else {
  25610. this.time = time;
  25611. break handle_stop;
  25612. }
  25613. if ( this.clampWhenFinished ) this.paused = true;
  25614. else this.enabled = false;
  25615. this.time = time;
  25616. this._mixer.dispatchEvent( {
  25617. type: 'finished', action: this,
  25618. direction: deltaTime < 0 ? - 1 : 1
  25619. } );
  25620. }
  25621. } else { // repetitive Repeat or PingPong
  25622. if ( loopCount === - 1 ) {
  25623. // just started
  25624. if ( deltaTime >= 0 ) {
  25625. loopCount = 0;
  25626. this._setEndings( true, this.repetitions === 0, pingPong );
  25627. } else {
  25628. // when looping in reverse direction, the initial
  25629. // transition through zero counts as a repetition,
  25630. // so leave loopCount at -1
  25631. this._setEndings( this.repetitions === 0, true, pingPong );
  25632. }
  25633. }
  25634. if ( time >= duration || time < 0 ) {
  25635. // wrap around
  25636. const loopDelta = Math.floor( time / duration ); // signed
  25637. time -= duration * loopDelta;
  25638. loopCount += Math.abs( loopDelta );
  25639. const pending = this.repetitions - loopCount;
  25640. if ( pending <= 0 ) {
  25641. // have to stop (switch state, clamp time, fire event)
  25642. if ( this.clampWhenFinished ) this.paused = true;
  25643. else this.enabled = false;
  25644. time = deltaTime > 0 ? duration : 0;
  25645. this.time = time;
  25646. this._mixer.dispatchEvent( {
  25647. type: 'finished', action: this,
  25648. direction: deltaTime > 0 ? 1 : - 1
  25649. } );
  25650. } else {
  25651. // keep running
  25652. if ( pending === 1 ) {
  25653. // entering the last round
  25654. const atStart = deltaTime < 0;
  25655. this._setEndings( atStart, ! atStart, pingPong );
  25656. } else {
  25657. this._setEndings( false, false, pingPong );
  25658. }
  25659. this._loopCount = loopCount;
  25660. this.time = time;
  25661. this._mixer.dispatchEvent( {
  25662. type: 'loop', action: this, loopDelta: loopDelta
  25663. } );
  25664. }
  25665. } else {
  25666. this.time = time;
  25667. }
  25668. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25669. // invert time for the "pong round"
  25670. return duration - time;
  25671. }
  25672. }
  25673. return time;
  25674. }
  25675. _setEndings( atStart, atEnd, pingPong ) {
  25676. const settings = this._interpolantSettings;
  25677. if ( pingPong ) {
  25678. settings.endingStart = ZeroSlopeEnding;
  25679. settings.endingEnd = ZeroSlopeEnding;
  25680. } else {
  25681. // assuming for LoopOnce atStart == atEnd == true
  25682. if ( atStart ) {
  25683. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25684. } else {
  25685. settings.endingStart = WrapAroundEnding;
  25686. }
  25687. if ( atEnd ) {
  25688. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25689. } else {
  25690. settings.endingEnd = WrapAroundEnding;
  25691. }
  25692. }
  25693. }
  25694. _scheduleFading( duration, weightNow, weightThen ) {
  25695. const mixer = this._mixer, now = mixer.time;
  25696. let interpolant = this._weightInterpolant;
  25697. if ( interpolant === null ) {
  25698. interpolant = mixer._lendControlInterpolant();
  25699. this._weightInterpolant = interpolant;
  25700. }
  25701. const times = interpolant.parameterPositions,
  25702. values = interpolant.sampleValues;
  25703. times[ 0 ] = now;
  25704. values[ 0 ] = weightNow;
  25705. times[ 1 ] = now + duration;
  25706. values[ 1 ] = weightThen;
  25707. return this;
  25708. }
  25709. }
  25710. class AnimationMixer extends EventDispatcher {
  25711. constructor( root ) {
  25712. super();
  25713. this._root = root;
  25714. this._initMemoryManager();
  25715. this._accuIndex = 0;
  25716. this.time = 0;
  25717. this.timeScale = 1.0;
  25718. }
  25719. _bindAction( action, prototypeAction ) {
  25720. const root = action._localRoot || this._root,
  25721. tracks = action._clip.tracks,
  25722. nTracks = tracks.length,
  25723. bindings = action._propertyBindings,
  25724. interpolants = action._interpolants,
  25725. rootUuid = root.uuid,
  25726. bindingsByRoot = this._bindingsByRootAndName;
  25727. let bindingsByName = bindingsByRoot[ rootUuid ];
  25728. if ( bindingsByName === undefined ) {
  25729. bindingsByName = {};
  25730. bindingsByRoot[ rootUuid ] = bindingsByName;
  25731. }
  25732. for ( let i = 0; i !== nTracks; ++ i ) {
  25733. const track = tracks[ i ],
  25734. trackName = track.name;
  25735. let binding = bindingsByName[ trackName ];
  25736. if ( binding !== undefined ) {
  25737. bindings[ i ] = binding;
  25738. } else {
  25739. binding = bindings[ i ];
  25740. if ( binding !== undefined ) {
  25741. // existing binding, make sure the cache knows
  25742. if ( binding._cacheIndex === null ) {
  25743. ++ binding.referenceCount;
  25744. this._addInactiveBinding( binding, rootUuid, trackName );
  25745. }
  25746. continue;
  25747. }
  25748. const path = prototypeAction && prototypeAction.
  25749. _propertyBindings[ i ].binding.parsedPath;
  25750. binding = new PropertyMixer(
  25751. PropertyBinding.create( root, trackName, path ),
  25752. track.ValueTypeName, track.getValueSize() );
  25753. ++ binding.referenceCount;
  25754. this._addInactiveBinding( binding, rootUuid, trackName );
  25755. bindings[ i ] = binding;
  25756. }
  25757. interpolants[ i ].resultBuffer = binding.buffer;
  25758. }
  25759. }
  25760. _activateAction( action ) {
  25761. if ( ! this._isActiveAction( action ) ) {
  25762. if ( action._cacheIndex === null ) {
  25763. // this action has been forgotten by the cache, but the user
  25764. // appears to be still using it -> rebind
  25765. const rootUuid = ( action._localRoot || this._root ).uuid,
  25766. clipUuid = action._clip.uuid,
  25767. actionsForClip = this._actionsByClip[ clipUuid ];
  25768. this._bindAction( action,
  25769. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25770. this._addInactiveAction( action, clipUuid, rootUuid );
  25771. }
  25772. const bindings = action._propertyBindings;
  25773. // increment reference counts / sort out state
  25774. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  25775. const binding = bindings[ i ];
  25776. if ( binding.useCount ++ === 0 ) {
  25777. this._lendBinding( binding );
  25778. binding.saveOriginalState();
  25779. }
  25780. }
  25781. this._lendAction( action );
  25782. }
  25783. }
  25784. _deactivateAction( action ) {
  25785. if ( this._isActiveAction( action ) ) {
  25786. const bindings = action._propertyBindings;
  25787. // decrement reference counts / sort out state
  25788. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  25789. const binding = bindings[ i ];
  25790. if ( -- binding.useCount === 0 ) {
  25791. binding.restoreOriginalState();
  25792. this._takeBackBinding( binding );
  25793. }
  25794. }
  25795. this._takeBackAction( action );
  25796. }
  25797. }
  25798. // Memory manager
  25799. _initMemoryManager() {
  25800. this._actions = []; // 'nActiveActions' followed by inactive ones
  25801. this._nActiveActions = 0;
  25802. this._actionsByClip = {};
  25803. // inside:
  25804. // {
  25805. // knownActions: Array< AnimationAction > - used as prototypes
  25806. // actionByRoot: AnimationAction - lookup
  25807. // }
  25808. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25809. this._nActiveBindings = 0;
  25810. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25811. this._controlInterpolants = []; // same game as above
  25812. this._nActiveControlInterpolants = 0;
  25813. const scope = this;
  25814. this.stats = {
  25815. actions: {
  25816. get total() {
  25817. return scope._actions.length;
  25818. },
  25819. get inUse() {
  25820. return scope._nActiveActions;
  25821. }
  25822. },
  25823. bindings: {
  25824. get total() {
  25825. return scope._bindings.length;
  25826. },
  25827. get inUse() {
  25828. return scope._nActiveBindings;
  25829. }
  25830. },
  25831. controlInterpolants: {
  25832. get total() {
  25833. return scope._controlInterpolants.length;
  25834. },
  25835. get inUse() {
  25836. return scope._nActiveControlInterpolants;
  25837. }
  25838. }
  25839. };
  25840. }
  25841. // Memory management for AnimationAction objects
  25842. _isActiveAction( action ) {
  25843. const index = action._cacheIndex;
  25844. return index !== null && index < this._nActiveActions;
  25845. }
  25846. _addInactiveAction( action, clipUuid, rootUuid ) {
  25847. const actions = this._actions,
  25848. actionsByClip = this._actionsByClip;
  25849. let actionsForClip = actionsByClip[ clipUuid ];
  25850. if ( actionsForClip === undefined ) {
  25851. actionsForClip = {
  25852. knownActions: [ action ],
  25853. actionByRoot: {}
  25854. };
  25855. action._byClipCacheIndex = 0;
  25856. actionsByClip[ clipUuid ] = actionsForClip;
  25857. } else {
  25858. const knownActions = actionsForClip.knownActions;
  25859. action._byClipCacheIndex = knownActions.length;
  25860. knownActions.push( action );
  25861. }
  25862. action._cacheIndex = actions.length;
  25863. actions.push( action );
  25864. actionsForClip.actionByRoot[ rootUuid ] = action;
  25865. }
  25866. _removeInactiveAction( action ) {
  25867. const actions = this._actions,
  25868. lastInactiveAction = actions[ actions.length - 1 ],
  25869. cacheIndex = action._cacheIndex;
  25870. lastInactiveAction._cacheIndex = cacheIndex;
  25871. actions[ cacheIndex ] = lastInactiveAction;
  25872. actions.pop();
  25873. action._cacheIndex = null;
  25874. const clipUuid = action._clip.uuid,
  25875. actionsByClip = this._actionsByClip,
  25876. actionsForClip = actionsByClip[ clipUuid ],
  25877. knownActionsForClip = actionsForClip.knownActions,
  25878. lastKnownAction =
  25879. knownActionsForClip[ knownActionsForClip.length - 1 ],
  25880. byClipCacheIndex = action._byClipCacheIndex;
  25881. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  25882. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  25883. knownActionsForClip.pop();
  25884. action._byClipCacheIndex = null;
  25885. const actionByRoot = actionsForClip.actionByRoot,
  25886. rootUuid = ( action._localRoot || this._root ).uuid;
  25887. delete actionByRoot[ rootUuid ];
  25888. if ( knownActionsForClip.length === 0 ) {
  25889. delete actionsByClip[ clipUuid ];
  25890. }
  25891. this._removeInactiveBindingsForAction( action );
  25892. }
  25893. _removeInactiveBindingsForAction( action ) {
  25894. const bindings = action._propertyBindings;
  25895. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  25896. const binding = bindings[ i ];
  25897. if ( -- binding.referenceCount === 0 ) {
  25898. this._removeInactiveBinding( binding );
  25899. }
  25900. }
  25901. }
  25902. _lendAction( action ) {
  25903. // [ active actions | inactive actions ]
  25904. // [ active actions >| inactive actions ]
  25905. // s a
  25906. // <-swap->
  25907. // a s
  25908. const actions = this._actions,
  25909. prevIndex = action._cacheIndex,
  25910. lastActiveIndex = this._nActiveActions ++,
  25911. firstInactiveAction = actions[ lastActiveIndex ];
  25912. action._cacheIndex = lastActiveIndex;
  25913. actions[ lastActiveIndex ] = action;
  25914. firstInactiveAction._cacheIndex = prevIndex;
  25915. actions[ prevIndex ] = firstInactiveAction;
  25916. }
  25917. _takeBackAction( action ) {
  25918. // [ active actions | inactive actions ]
  25919. // [ active actions |< inactive actions ]
  25920. // a s
  25921. // <-swap->
  25922. // s a
  25923. const actions = this._actions,
  25924. prevIndex = action._cacheIndex,
  25925. firstInactiveIndex = -- this._nActiveActions,
  25926. lastActiveAction = actions[ firstInactiveIndex ];
  25927. action._cacheIndex = firstInactiveIndex;
  25928. actions[ firstInactiveIndex ] = action;
  25929. lastActiveAction._cacheIndex = prevIndex;
  25930. actions[ prevIndex ] = lastActiveAction;
  25931. }
  25932. // Memory management for PropertyMixer objects
  25933. _addInactiveBinding( binding, rootUuid, trackName ) {
  25934. const bindingsByRoot = this._bindingsByRootAndName,
  25935. bindings = this._bindings;
  25936. let bindingByName = bindingsByRoot[ rootUuid ];
  25937. if ( bindingByName === undefined ) {
  25938. bindingByName = {};
  25939. bindingsByRoot[ rootUuid ] = bindingByName;
  25940. }
  25941. bindingByName[ trackName ] = binding;
  25942. binding._cacheIndex = bindings.length;
  25943. bindings.push( binding );
  25944. }
  25945. _removeInactiveBinding( binding ) {
  25946. const bindings = this._bindings,
  25947. propBinding = binding.binding,
  25948. rootUuid = propBinding.rootNode.uuid,
  25949. trackName = propBinding.path,
  25950. bindingsByRoot = this._bindingsByRootAndName,
  25951. bindingByName = bindingsByRoot[ rootUuid ],
  25952. lastInactiveBinding = bindings[ bindings.length - 1 ],
  25953. cacheIndex = binding._cacheIndex;
  25954. lastInactiveBinding._cacheIndex = cacheIndex;
  25955. bindings[ cacheIndex ] = lastInactiveBinding;
  25956. bindings.pop();
  25957. delete bindingByName[ trackName ];
  25958. if ( Object.keys( bindingByName ).length === 0 ) {
  25959. delete bindingsByRoot[ rootUuid ];
  25960. }
  25961. }
  25962. _lendBinding( binding ) {
  25963. const bindings = this._bindings,
  25964. prevIndex = binding._cacheIndex,
  25965. lastActiveIndex = this._nActiveBindings ++,
  25966. firstInactiveBinding = bindings[ lastActiveIndex ];
  25967. binding._cacheIndex = lastActiveIndex;
  25968. bindings[ lastActiveIndex ] = binding;
  25969. firstInactiveBinding._cacheIndex = prevIndex;
  25970. bindings[ prevIndex ] = firstInactiveBinding;
  25971. }
  25972. _takeBackBinding( binding ) {
  25973. const bindings = this._bindings,
  25974. prevIndex = binding._cacheIndex,
  25975. firstInactiveIndex = -- this._nActiveBindings,
  25976. lastActiveBinding = bindings[ firstInactiveIndex ];
  25977. binding._cacheIndex = firstInactiveIndex;
  25978. bindings[ firstInactiveIndex ] = binding;
  25979. lastActiveBinding._cacheIndex = prevIndex;
  25980. bindings[ prevIndex ] = lastActiveBinding;
  25981. }
  25982. // Memory management of Interpolants for weight and time scale
  25983. _lendControlInterpolant() {
  25984. const interpolants = this._controlInterpolants,
  25985. lastActiveIndex = this._nActiveControlInterpolants ++;
  25986. let interpolant = interpolants[ lastActiveIndex ];
  25987. if ( interpolant === undefined ) {
  25988. interpolant = new LinearInterpolant(
  25989. new Float32Array( 2 ), new Float32Array( 2 ),
  25990. 1, this._controlInterpolantsResultBuffer );
  25991. interpolant.__cacheIndex = lastActiveIndex;
  25992. interpolants[ lastActiveIndex ] = interpolant;
  25993. }
  25994. return interpolant;
  25995. }
  25996. _takeBackControlInterpolant( interpolant ) {
  25997. const interpolants = this._controlInterpolants,
  25998. prevIndex = interpolant.__cacheIndex,
  25999. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26000. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26001. interpolant.__cacheIndex = firstInactiveIndex;
  26002. interpolants[ firstInactiveIndex ] = interpolant;
  26003. lastActiveInterpolant.__cacheIndex = prevIndex;
  26004. interpolants[ prevIndex ] = lastActiveInterpolant;
  26005. }
  26006. // return an action for a clip optionally using a custom root target
  26007. // object (this method allocates a lot of dynamic memory in case a
  26008. // previously unknown clip/root combination is specified)
  26009. clipAction( clip, optionalRoot, blendMode ) {
  26010. const root = optionalRoot || this._root,
  26011. rootUuid = root.uuid;
  26012. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  26013. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26014. const actionsForClip = this._actionsByClip[ clipUuid ];
  26015. let prototypeAction = null;
  26016. if ( blendMode === undefined ) {
  26017. if ( clipObject !== null ) {
  26018. blendMode = clipObject.blendMode;
  26019. } else {
  26020. blendMode = NormalAnimationBlendMode;
  26021. }
  26022. }
  26023. if ( actionsForClip !== undefined ) {
  26024. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  26025. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  26026. return existingAction;
  26027. }
  26028. // we know the clip, so we don't have to parse all
  26029. // the bindings again but can just copy
  26030. prototypeAction = actionsForClip.knownActions[ 0 ];
  26031. // also, take the clip from the prototype action
  26032. if ( clipObject === null )
  26033. clipObject = prototypeAction._clip;
  26034. }
  26035. // clip must be known when specified via string
  26036. if ( clipObject === null ) return null;
  26037. // allocate all resources required to run it
  26038. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  26039. this._bindAction( newAction, prototypeAction );
  26040. // and make the action known to the memory manager
  26041. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26042. return newAction;
  26043. }
  26044. // get an existing action
  26045. existingAction( clip, optionalRoot ) {
  26046. const root = optionalRoot || this._root,
  26047. rootUuid = root.uuid,
  26048. clipObject = typeof clip === 'string' ?
  26049. AnimationClip.findByName( root, clip ) : clip,
  26050. clipUuid = clipObject ? clipObject.uuid : clip,
  26051. actionsForClip = this._actionsByClip[ clipUuid ];
  26052. if ( actionsForClip !== undefined ) {
  26053. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26054. }
  26055. return null;
  26056. }
  26057. // deactivates all previously scheduled actions
  26058. stopAllAction() {
  26059. const actions = this._actions,
  26060. nActions = this._nActiveActions;
  26061. for ( let i = nActions - 1; i >= 0; -- i ) {
  26062. actions[ i ].stop();
  26063. }
  26064. return this;
  26065. }
  26066. // advance the time and update apply the animation
  26067. update( deltaTime ) {
  26068. deltaTime *= this.timeScale;
  26069. const actions = this._actions,
  26070. nActions = this._nActiveActions,
  26071. time = this.time += deltaTime,
  26072. timeDirection = Math.sign( deltaTime ),
  26073. accuIndex = this._accuIndex ^= 1;
  26074. // run active actions
  26075. for ( let i = 0; i !== nActions; ++ i ) {
  26076. const action = actions[ i ];
  26077. action._update( time, deltaTime, timeDirection, accuIndex );
  26078. }
  26079. // update scene graph
  26080. const bindings = this._bindings,
  26081. nBindings = this._nActiveBindings;
  26082. for ( let i = 0; i !== nBindings; ++ i ) {
  26083. bindings[ i ].apply( accuIndex );
  26084. }
  26085. return this;
  26086. }
  26087. // Allows you to seek to a specific time in an animation.
  26088. setTime( timeInSeconds ) {
  26089. this.time = 0; // Zero out time attribute for AnimationMixer object;
  26090. for ( let i = 0; i < this._actions.length; i ++ ) {
  26091. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  26092. }
  26093. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  26094. }
  26095. // return this mixer's root target object
  26096. getRoot() {
  26097. return this._root;
  26098. }
  26099. // free all resources specific to a particular clip
  26100. uncacheClip( clip ) {
  26101. const actions = this._actions,
  26102. clipUuid = clip.uuid,
  26103. actionsByClip = this._actionsByClip,
  26104. actionsForClip = actionsByClip[ clipUuid ];
  26105. if ( actionsForClip !== undefined ) {
  26106. // note: just calling _removeInactiveAction would mess up the
  26107. // iteration state and also require updating the state we can
  26108. // just throw away
  26109. const actionsToRemove = actionsForClip.knownActions;
  26110. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26111. const action = actionsToRemove[ i ];
  26112. this._deactivateAction( action );
  26113. const cacheIndex = action._cacheIndex,
  26114. lastInactiveAction = actions[ actions.length - 1 ];
  26115. action._cacheIndex = null;
  26116. action._byClipCacheIndex = null;
  26117. lastInactiveAction._cacheIndex = cacheIndex;
  26118. actions[ cacheIndex ] = lastInactiveAction;
  26119. actions.pop();
  26120. this._removeInactiveBindingsForAction( action );
  26121. }
  26122. delete actionsByClip[ clipUuid ];
  26123. }
  26124. }
  26125. // free all resources specific to a particular root target object
  26126. uncacheRoot( root ) {
  26127. const rootUuid = root.uuid,
  26128. actionsByClip = this._actionsByClip;
  26129. for ( const clipUuid in actionsByClip ) {
  26130. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26131. action = actionByRoot[ rootUuid ];
  26132. if ( action !== undefined ) {
  26133. this._deactivateAction( action );
  26134. this._removeInactiveAction( action );
  26135. }
  26136. }
  26137. const bindingsByRoot = this._bindingsByRootAndName,
  26138. bindingByName = bindingsByRoot[ rootUuid ];
  26139. if ( bindingByName !== undefined ) {
  26140. for ( const trackName in bindingByName ) {
  26141. const binding = bindingByName[ trackName ];
  26142. binding.restoreOriginalState();
  26143. this._removeInactiveBinding( binding );
  26144. }
  26145. }
  26146. }
  26147. // remove a targeted clip from the cache
  26148. uncacheAction( clip, optionalRoot ) {
  26149. const action = this.existingAction( clip, optionalRoot );
  26150. if ( action !== null ) {
  26151. this._deactivateAction( action );
  26152. this._removeInactiveAction( action );
  26153. }
  26154. }
  26155. }
  26156. AnimationMixer.prototype._controlInterpolantsResultBuffer = new Float32Array( 1 );
  26157. class Uniform {
  26158. constructor( value ) {
  26159. if ( typeof value === 'string' ) {
  26160. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26161. value = arguments[ 1 ];
  26162. }
  26163. this.value = value;
  26164. }
  26165. clone() {
  26166. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26167. }
  26168. }
  26169. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26170. InterleavedBuffer.call( this, array, stride );
  26171. this.meshPerAttribute = meshPerAttribute || 1;
  26172. }
  26173. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26174. constructor: InstancedInterleavedBuffer,
  26175. isInstancedInterleavedBuffer: true,
  26176. copy: function ( source ) {
  26177. InterleavedBuffer.prototype.copy.call( this, source );
  26178. this.meshPerAttribute = source.meshPerAttribute;
  26179. return this;
  26180. },
  26181. clone: function ( data ) {
  26182. const ib = InterleavedBuffer.prototype.clone.call( this, data );
  26183. ib.meshPerAttribute = this.meshPerAttribute;
  26184. return ib;
  26185. },
  26186. toJSON: function ( data ) {
  26187. const json = InterleavedBuffer.prototype.toJSON.call( this, data );
  26188. json.isInstancedInterleavedBuffer = true;
  26189. json.meshPerAttribute = this.meshPerAttribute;
  26190. return json;
  26191. }
  26192. } );
  26193. function GLBufferAttribute( buffer, type, itemSize, elementSize, count ) {
  26194. this.buffer = buffer;
  26195. this.type = type;
  26196. this.itemSize = itemSize;
  26197. this.elementSize = elementSize;
  26198. this.count = count;
  26199. this.version = 0;
  26200. }
  26201. Object.defineProperty( GLBufferAttribute.prototype, 'needsUpdate', {
  26202. set: function ( value ) {
  26203. if ( value === true ) this.version ++;
  26204. }
  26205. } );
  26206. Object.assign( GLBufferAttribute.prototype, {
  26207. isGLBufferAttribute: true,
  26208. setBuffer: function ( buffer ) {
  26209. this.buffer = buffer;
  26210. return this;
  26211. },
  26212. setType: function ( type, elementSize ) {
  26213. this.type = type;
  26214. this.elementSize = elementSize;
  26215. return this;
  26216. },
  26217. setItemSize: function ( itemSize ) {
  26218. this.itemSize = itemSize;
  26219. return this;
  26220. },
  26221. setCount: function ( count ) {
  26222. this.count = count;
  26223. return this;
  26224. },
  26225. } );
  26226. function Raycaster( origin, direction, near = 0, far = Infinity ) {
  26227. this.ray = new Ray( origin, direction );
  26228. // direction is assumed to be normalized (for accurate distance calculations)
  26229. this.near = near;
  26230. this.far = far;
  26231. this.camera = null;
  26232. this.layers = new Layers();
  26233. this.params = {
  26234. Mesh: {},
  26235. Line: { threshold: 1 },
  26236. LOD: {},
  26237. Points: { threshold: 1 },
  26238. Sprite: {}
  26239. };
  26240. Object.defineProperties( this.params, {
  26241. PointCloud: {
  26242. get: function () {
  26243. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26244. return this.Points;
  26245. }
  26246. }
  26247. } );
  26248. }
  26249. function ascSort( a, b ) {
  26250. return a.distance - b.distance;
  26251. }
  26252. function intersectObject( object, raycaster, intersects, recursive ) {
  26253. if ( object.layers.test( raycaster.layers ) ) {
  26254. object.raycast( raycaster, intersects );
  26255. }
  26256. if ( recursive === true ) {
  26257. const children = object.children;
  26258. for ( let i = 0, l = children.length; i < l; i ++ ) {
  26259. intersectObject( children[ i ], raycaster, intersects, true );
  26260. }
  26261. }
  26262. }
  26263. Object.assign( Raycaster.prototype, {
  26264. set: function ( origin, direction ) {
  26265. // direction is assumed to be normalized (for accurate distance calculations)
  26266. this.ray.set( origin, direction );
  26267. },
  26268. setFromCamera: function ( coords, camera ) {
  26269. if ( camera && camera.isPerspectiveCamera ) {
  26270. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26271. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26272. this.camera = camera;
  26273. } else if ( camera && camera.isOrthographicCamera ) {
  26274. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26275. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26276. this.camera = camera;
  26277. } else {
  26278. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  26279. }
  26280. },
  26281. intersectObject: function ( object, recursive = false, intersects = [] ) {
  26282. intersectObject( object, this, intersects, recursive );
  26283. intersects.sort( ascSort );
  26284. return intersects;
  26285. },
  26286. intersectObjects: function ( objects, recursive = false, intersects = [] ) {
  26287. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  26288. intersectObject( objects[ i ], this, intersects, recursive );
  26289. }
  26290. intersects.sort( ascSort );
  26291. return intersects;
  26292. }
  26293. } );
  26294. /**
  26295. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26296. *
  26297. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26298. * The azimuthal angle (theta) is measured from the positive z-axis.
  26299. */
  26300. class Spherical {
  26301. constructor( radius = 1, phi = 0, theta = 0 ) {
  26302. this.radius = radius;
  26303. this.phi = phi; // polar angle
  26304. this.theta = theta; // azimuthal angle
  26305. return this;
  26306. }
  26307. set( radius, phi, theta ) {
  26308. this.radius = radius;
  26309. this.phi = phi;
  26310. this.theta = theta;
  26311. return this;
  26312. }
  26313. copy( other ) {
  26314. this.radius = other.radius;
  26315. this.phi = other.phi;
  26316. this.theta = other.theta;
  26317. return this;
  26318. }
  26319. // restrict phi to be betwee EPS and PI-EPS
  26320. makeSafe() {
  26321. const EPS = 0.000001;
  26322. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26323. return this;
  26324. }
  26325. setFromVector3( v ) {
  26326. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26327. }
  26328. setFromCartesianCoords( x, y, z ) {
  26329. this.radius = Math.sqrt( x * x + y * y + z * z );
  26330. if ( this.radius === 0 ) {
  26331. this.theta = 0;
  26332. this.phi = 0;
  26333. } else {
  26334. this.theta = Math.atan2( x, z );
  26335. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  26336. }
  26337. return this;
  26338. }
  26339. clone() {
  26340. return new this.constructor().copy( this );
  26341. }
  26342. }
  26343. /**
  26344. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26345. */
  26346. class Cylindrical {
  26347. constructor( radius = 1, theta = 0, y = 0 ) {
  26348. this.radius = radius; // distance from the origin to a point in the x-z plane
  26349. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26350. this.y = y; // height above the x-z plane
  26351. return this;
  26352. }
  26353. set( radius, theta, y ) {
  26354. this.radius = radius;
  26355. this.theta = theta;
  26356. this.y = y;
  26357. return this;
  26358. }
  26359. copy( other ) {
  26360. this.radius = other.radius;
  26361. this.theta = other.theta;
  26362. this.y = other.y;
  26363. return this;
  26364. }
  26365. setFromVector3( v ) {
  26366. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26367. }
  26368. setFromCartesianCoords( x, y, z ) {
  26369. this.radius = Math.sqrt( x * x + z * z );
  26370. this.theta = Math.atan2( x, z );
  26371. this.y = y;
  26372. return this;
  26373. }
  26374. clone() {
  26375. return new this.constructor().copy( this );
  26376. }
  26377. }
  26378. const _vector$8 = /*@__PURE__*/ new Vector2();
  26379. class Box2 {
  26380. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  26381. this.min = min;
  26382. this.max = max;
  26383. }
  26384. set( min, max ) {
  26385. this.min.copy( min );
  26386. this.max.copy( max );
  26387. return this;
  26388. }
  26389. setFromPoints( points ) {
  26390. this.makeEmpty();
  26391. for ( let i = 0, il = points.length; i < il; i ++ ) {
  26392. this.expandByPoint( points[ i ] );
  26393. }
  26394. return this;
  26395. }
  26396. setFromCenterAndSize( center, size ) {
  26397. const halfSize = _vector$8.copy( size ).multiplyScalar( 0.5 );
  26398. this.min.copy( center ).sub( halfSize );
  26399. this.max.copy( center ).add( halfSize );
  26400. return this;
  26401. }
  26402. clone() {
  26403. return new this.constructor().copy( this );
  26404. }
  26405. copy( box ) {
  26406. this.min.copy( box.min );
  26407. this.max.copy( box.max );
  26408. return this;
  26409. }
  26410. makeEmpty() {
  26411. this.min.x = this.min.y = + Infinity;
  26412. this.max.x = this.max.y = - Infinity;
  26413. return this;
  26414. }
  26415. isEmpty() {
  26416. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26417. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26418. }
  26419. getCenter( target ) {
  26420. if ( target === undefined ) {
  26421. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26422. target = new Vector2();
  26423. }
  26424. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26425. }
  26426. getSize( target ) {
  26427. if ( target === undefined ) {
  26428. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26429. target = new Vector2();
  26430. }
  26431. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26432. }
  26433. expandByPoint( point ) {
  26434. this.min.min( point );
  26435. this.max.max( point );
  26436. return this;
  26437. }
  26438. expandByVector( vector ) {
  26439. this.min.sub( vector );
  26440. this.max.add( vector );
  26441. return this;
  26442. }
  26443. expandByScalar( scalar ) {
  26444. this.min.addScalar( - scalar );
  26445. this.max.addScalar( scalar );
  26446. return this;
  26447. }
  26448. containsPoint( point ) {
  26449. return point.x < this.min.x || point.x > this.max.x ||
  26450. point.y < this.min.y || point.y > this.max.y ? false : true;
  26451. }
  26452. containsBox( box ) {
  26453. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26454. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26455. }
  26456. getParameter( point, target ) {
  26457. // This can potentially have a divide by zero if the box
  26458. // has a size dimension of 0.
  26459. if ( target === undefined ) {
  26460. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26461. target = new Vector2();
  26462. }
  26463. return target.set(
  26464. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26465. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26466. );
  26467. }
  26468. intersectsBox( box ) {
  26469. // using 4 splitting planes to rule out intersections
  26470. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26471. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26472. }
  26473. clampPoint( point, target ) {
  26474. if ( target === undefined ) {
  26475. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26476. target = new Vector2();
  26477. }
  26478. return target.copy( point ).clamp( this.min, this.max );
  26479. }
  26480. distanceToPoint( point ) {
  26481. const clampedPoint = _vector$8.copy( point ).clamp( this.min, this.max );
  26482. return clampedPoint.sub( point ).length();
  26483. }
  26484. intersect( box ) {
  26485. this.min.max( box.min );
  26486. this.max.min( box.max );
  26487. return this;
  26488. }
  26489. union( box ) {
  26490. this.min.min( box.min );
  26491. this.max.max( box.max );
  26492. return this;
  26493. }
  26494. translate( offset ) {
  26495. this.min.add( offset );
  26496. this.max.add( offset );
  26497. return this;
  26498. }
  26499. equals( box ) {
  26500. return box.min.equals( this.min ) && box.max.equals( this.max );
  26501. }
  26502. }
  26503. Box2.prototype.isBox2 = true;
  26504. const _startP = /*@__PURE__*/ new Vector3();
  26505. const _startEnd = /*@__PURE__*/ new Vector3();
  26506. class Line3 {
  26507. constructor( start = new Vector3(), end = new Vector3() ) {
  26508. this.start = start;
  26509. this.end = end;
  26510. }
  26511. set( start, end ) {
  26512. this.start.copy( start );
  26513. this.end.copy( end );
  26514. return this;
  26515. }
  26516. copy( line ) {
  26517. this.start.copy( line.start );
  26518. this.end.copy( line.end );
  26519. return this;
  26520. }
  26521. getCenter( target ) {
  26522. if ( target === undefined ) {
  26523. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26524. target = new Vector3();
  26525. }
  26526. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26527. }
  26528. delta( target ) {
  26529. if ( target === undefined ) {
  26530. console.warn( 'THREE.Line3: .delta() target is now required' );
  26531. target = new Vector3();
  26532. }
  26533. return target.subVectors( this.end, this.start );
  26534. }
  26535. distanceSq() {
  26536. return this.start.distanceToSquared( this.end );
  26537. }
  26538. distance() {
  26539. return this.start.distanceTo( this.end );
  26540. }
  26541. at( t, target ) {
  26542. if ( target === undefined ) {
  26543. console.warn( 'THREE.Line3: .at() target is now required' );
  26544. target = new Vector3();
  26545. }
  26546. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26547. }
  26548. closestPointToPointParameter( point, clampToLine ) {
  26549. _startP.subVectors( point, this.start );
  26550. _startEnd.subVectors( this.end, this.start );
  26551. const startEnd2 = _startEnd.dot( _startEnd );
  26552. const startEnd_startP = _startEnd.dot( _startP );
  26553. let t = startEnd_startP / startEnd2;
  26554. if ( clampToLine ) {
  26555. t = MathUtils.clamp( t, 0, 1 );
  26556. }
  26557. return t;
  26558. }
  26559. closestPointToPoint( point, clampToLine, target ) {
  26560. const t = this.closestPointToPointParameter( point, clampToLine );
  26561. if ( target === undefined ) {
  26562. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26563. target = new Vector3();
  26564. }
  26565. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26566. }
  26567. applyMatrix4( matrix ) {
  26568. this.start.applyMatrix4( matrix );
  26569. this.end.applyMatrix4( matrix );
  26570. return this;
  26571. }
  26572. equals( line ) {
  26573. return line.start.equals( this.start ) && line.end.equals( this.end );
  26574. }
  26575. clone() {
  26576. return new this.constructor().copy( this );
  26577. }
  26578. }
  26579. function ImmediateRenderObject( material ) {
  26580. Object3D.call( this );
  26581. this.material = material;
  26582. this.render = function ( /* renderCallback */ ) {};
  26583. this.hasPositions = false;
  26584. this.hasNormals = false;
  26585. this.hasColors = false;
  26586. this.hasUvs = false;
  26587. this.positionArray = null;
  26588. this.normalArray = null;
  26589. this.colorArray = null;
  26590. this.uvArray = null;
  26591. this.count = 0;
  26592. }
  26593. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26594. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26595. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26596. const _vector$9 = /*@__PURE__*/ new Vector3();
  26597. class SpotLightHelper extends Object3D {
  26598. constructor( light, color ) {
  26599. super();
  26600. this.light = light;
  26601. this.light.updateMatrixWorld();
  26602. this.matrix = light.matrixWorld;
  26603. this.matrixAutoUpdate = false;
  26604. this.color = color;
  26605. const geometry = new BufferGeometry();
  26606. const positions = [
  26607. 0, 0, 0, 0, 0, 1,
  26608. 0, 0, 0, 1, 0, 1,
  26609. 0, 0, 0, - 1, 0, 1,
  26610. 0, 0, 0, 0, 1, 1,
  26611. 0, 0, 0, 0, - 1, 1
  26612. ];
  26613. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26614. const p1 = ( i / l ) * Math.PI * 2;
  26615. const p2 = ( j / l ) * Math.PI * 2;
  26616. positions.push(
  26617. Math.cos( p1 ), Math.sin( p1 ), 1,
  26618. Math.cos( p2 ), Math.sin( p2 ), 1
  26619. );
  26620. }
  26621. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26622. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  26623. this.cone = new LineSegments( geometry, material );
  26624. this.add( this.cone );
  26625. this.update();
  26626. }
  26627. dispose() {
  26628. this.cone.geometry.dispose();
  26629. this.cone.material.dispose();
  26630. }
  26631. update() {
  26632. this.light.updateMatrixWorld();
  26633. const coneLength = this.light.distance ? this.light.distance : 1000;
  26634. const coneWidth = coneLength * Math.tan( this.light.angle );
  26635. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26636. _vector$9.setFromMatrixPosition( this.light.target.matrixWorld );
  26637. this.cone.lookAt( _vector$9 );
  26638. if ( this.color !== undefined ) {
  26639. this.cone.material.color.set( this.color );
  26640. } else {
  26641. this.cone.material.color.copy( this.light.color );
  26642. }
  26643. }
  26644. }
  26645. const _vector$a = /*@__PURE__*/ new Vector3();
  26646. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  26647. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  26648. class SkeletonHelper extends LineSegments {
  26649. constructor( object ) {
  26650. const bones = getBoneList( object );
  26651. const geometry = new BufferGeometry();
  26652. const vertices = [];
  26653. const colors = [];
  26654. const color1 = new Color( 0, 0, 1 );
  26655. const color2 = new Color( 0, 1, 0 );
  26656. for ( let i = 0; i < bones.length; i ++ ) {
  26657. const bone = bones[ i ];
  26658. if ( bone.parent && bone.parent.isBone ) {
  26659. vertices.push( 0, 0, 0 );
  26660. vertices.push( 0, 0, 0 );
  26661. colors.push( color1.r, color1.g, color1.b );
  26662. colors.push( color2.r, color2.g, color2.b );
  26663. }
  26664. }
  26665. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26666. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26667. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  26668. super( geometry, material );
  26669. this.type = 'SkeletonHelper';
  26670. this.isSkeletonHelper = true;
  26671. this.root = object;
  26672. this.bones = bones;
  26673. this.matrix = object.matrixWorld;
  26674. this.matrixAutoUpdate = false;
  26675. }
  26676. updateMatrixWorld( force ) {
  26677. const bones = this.bones;
  26678. const geometry = this.geometry;
  26679. const position = geometry.getAttribute( 'position' );
  26680. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  26681. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  26682. const bone = bones[ i ];
  26683. if ( bone.parent && bone.parent.isBone ) {
  26684. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  26685. _vector$a.setFromMatrixPosition( _boneMatrix );
  26686. position.setXYZ( j, _vector$a.x, _vector$a.y, _vector$a.z );
  26687. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  26688. _vector$a.setFromMatrixPosition( _boneMatrix );
  26689. position.setXYZ( j + 1, _vector$a.x, _vector$a.y, _vector$a.z );
  26690. j += 2;
  26691. }
  26692. }
  26693. geometry.getAttribute( 'position' ).needsUpdate = true;
  26694. super.updateMatrixWorld( force );
  26695. }
  26696. }
  26697. function getBoneList( object ) {
  26698. const boneList = [];
  26699. if ( object && object.isBone ) {
  26700. boneList.push( object );
  26701. }
  26702. for ( let i = 0; i < object.children.length; i ++ ) {
  26703. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26704. }
  26705. return boneList;
  26706. }
  26707. class PointLightHelper extends Mesh {
  26708. constructor( light, sphereSize, color ) {
  26709. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  26710. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  26711. super( geometry, material );
  26712. this.light = light;
  26713. this.light.updateMatrixWorld();
  26714. this.color = color;
  26715. this.type = 'PointLightHelper';
  26716. this.matrix = this.light.matrixWorld;
  26717. this.matrixAutoUpdate = false;
  26718. this.update();
  26719. /*
  26720. // TODO: delete this comment?
  26721. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  26722. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  26723. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  26724. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  26725. const d = light.distance;
  26726. if ( d === 0.0 ) {
  26727. this.lightDistance.visible = false;
  26728. } else {
  26729. this.lightDistance.scale.set( d, d, d );
  26730. }
  26731. this.add( this.lightDistance );
  26732. */
  26733. }
  26734. dispose() {
  26735. this.geometry.dispose();
  26736. this.material.dispose();
  26737. }
  26738. update() {
  26739. if ( this.color !== undefined ) {
  26740. this.material.color.set( this.color );
  26741. } else {
  26742. this.material.color.copy( this.light.color );
  26743. }
  26744. /*
  26745. const d = this.light.distance;
  26746. if ( d === 0.0 ) {
  26747. this.lightDistance.visible = false;
  26748. } else {
  26749. this.lightDistance.visible = true;
  26750. this.lightDistance.scale.set( d, d, d );
  26751. }
  26752. */
  26753. }
  26754. }
  26755. const _vector$b = /*@__PURE__*/ new Vector3();
  26756. const _color1 = /*@__PURE__*/ new Color();
  26757. const _color2 = /*@__PURE__*/ new Color();
  26758. class HemisphereLightHelper extends Object3D {
  26759. constructor( light, size, color ) {
  26760. super();
  26761. this.light = light;
  26762. this.light.updateMatrixWorld();
  26763. this.matrix = light.matrixWorld;
  26764. this.matrixAutoUpdate = false;
  26765. this.color = color;
  26766. const geometry = new OctahedronGeometry( size );
  26767. geometry.rotateY( Math.PI * 0.5 );
  26768. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  26769. if ( this.color === undefined ) this.material.vertexColors = true;
  26770. const position = geometry.getAttribute( 'position' );
  26771. const colors = new Float32Array( position.count * 3 );
  26772. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  26773. this.add( new Mesh( geometry, this.material ) );
  26774. this.update();
  26775. }
  26776. dispose() {
  26777. this.children[ 0 ].geometry.dispose();
  26778. this.children[ 0 ].material.dispose();
  26779. }
  26780. update() {
  26781. const mesh = this.children[ 0 ];
  26782. if ( this.color !== undefined ) {
  26783. this.material.color.set( this.color );
  26784. } else {
  26785. const colors = mesh.geometry.getAttribute( 'color' );
  26786. _color1.copy( this.light.color );
  26787. _color2.copy( this.light.groundColor );
  26788. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  26789. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  26790. colors.setXYZ( i, color.r, color.g, color.b );
  26791. }
  26792. colors.needsUpdate = true;
  26793. }
  26794. mesh.lookAt( _vector$b.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  26795. }
  26796. }
  26797. class GridHelper extends LineSegments {
  26798. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  26799. color1 = new Color( color1 );
  26800. color2 = new Color( color2 );
  26801. const center = divisions / 2;
  26802. const step = size / divisions;
  26803. const halfSize = size / 2;
  26804. const vertices = [], colors = [];
  26805. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26806. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26807. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26808. const color = i === center ? color1 : color2;
  26809. color.toArray( colors, j ); j += 3;
  26810. color.toArray( colors, j ); j += 3;
  26811. color.toArray( colors, j ); j += 3;
  26812. color.toArray( colors, j ); j += 3;
  26813. }
  26814. const geometry = new BufferGeometry();
  26815. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26816. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26817. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  26818. super( geometry, material );
  26819. this.type = 'GridHelper';
  26820. }
  26821. }
  26822. class PolarGridHelper extends LineSegments {
  26823. constructor( radius = 10, radials = 16, circles = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  26824. color1 = new Color( color1 );
  26825. color2 = new Color( color2 );
  26826. const vertices = [];
  26827. const colors = [];
  26828. // create the radials
  26829. for ( let i = 0; i <= radials; i ++ ) {
  26830. const v = ( i / radials ) * ( Math.PI * 2 );
  26831. const x = Math.sin( v ) * radius;
  26832. const z = Math.cos( v ) * radius;
  26833. vertices.push( 0, 0, 0 );
  26834. vertices.push( x, 0, z );
  26835. const color = ( i & 1 ) ? color1 : color2;
  26836. colors.push( color.r, color.g, color.b );
  26837. colors.push( color.r, color.g, color.b );
  26838. }
  26839. // create the circles
  26840. for ( let i = 0; i <= circles; i ++ ) {
  26841. const color = ( i & 1 ) ? color1 : color2;
  26842. const r = radius - ( radius / circles * i );
  26843. for ( let j = 0; j < divisions; j ++ ) {
  26844. // first vertex
  26845. let v = ( j / divisions ) * ( Math.PI * 2 );
  26846. let x = Math.sin( v ) * r;
  26847. let z = Math.cos( v ) * r;
  26848. vertices.push( x, 0, z );
  26849. colors.push( color.r, color.g, color.b );
  26850. // second vertex
  26851. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26852. x = Math.sin( v ) * r;
  26853. z = Math.cos( v ) * r;
  26854. vertices.push( x, 0, z );
  26855. colors.push( color.r, color.g, color.b );
  26856. }
  26857. }
  26858. const geometry = new BufferGeometry();
  26859. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26860. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26861. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  26862. super( geometry, material );
  26863. this.type = 'PolarGridHelper';
  26864. }
  26865. }
  26866. const _v1$6 = /*@__PURE__*/ new Vector3();
  26867. const _v2$3 = /*@__PURE__*/ new Vector3();
  26868. const _v3$1 = /*@__PURE__*/ new Vector3();
  26869. class DirectionalLightHelper extends Object3D {
  26870. constructor( light, size, color ) {
  26871. super();
  26872. this.light = light;
  26873. this.light.updateMatrixWorld();
  26874. this.matrix = light.matrixWorld;
  26875. this.matrixAutoUpdate = false;
  26876. this.color = color;
  26877. if ( size === undefined ) size = 1;
  26878. let geometry = new BufferGeometry();
  26879. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  26880. - size, size, 0,
  26881. size, size, 0,
  26882. size, - size, 0,
  26883. - size, - size, 0,
  26884. - size, size, 0
  26885. ], 3 ) );
  26886. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  26887. this.lightPlane = new Line( geometry, material );
  26888. this.add( this.lightPlane );
  26889. geometry = new BufferGeometry();
  26890. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  26891. this.targetLine = new Line( geometry, material );
  26892. this.add( this.targetLine );
  26893. this.update();
  26894. }
  26895. dispose() {
  26896. this.lightPlane.geometry.dispose();
  26897. this.lightPlane.material.dispose();
  26898. this.targetLine.geometry.dispose();
  26899. this.targetLine.material.dispose();
  26900. }
  26901. update() {
  26902. _v1$6.setFromMatrixPosition( this.light.matrixWorld );
  26903. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  26904. _v3$1.subVectors( _v2$3, _v1$6 );
  26905. this.lightPlane.lookAt( _v2$3 );
  26906. if ( this.color !== undefined ) {
  26907. this.lightPlane.material.color.set( this.color );
  26908. this.targetLine.material.color.set( this.color );
  26909. } else {
  26910. this.lightPlane.material.color.copy( this.light.color );
  26911. this.targetLine.material.color.copy( this.light.color );
  26912. }
  26913. this.targetLine.lookAt( _v2$3 );
  26914. this.targetLine.scale.z = _v3$1.length();
  26915. }
  26916. }
  26917. const _vector$c = /*@__PURE__*/ new Vector3();
  26918. const _camera = /*@__PURE__*/ new Camera();
  26919. /**
  26920. * - shows frustum, line of sight and up of the camera
  26921. * - suitable for fast updates
  26922. * - based on frustum visualization in lightgl.js shadowmap example
  26923. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  26924. */
  26925. class CameraHelper extends LineSegments {
  26926. constructor( camera ) {
  26927. const geometry = new BufferGeometry();
  26928. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  26929. const vertices = [];
  26930. const colors = [];
  26931. const pointMap = {};
  26932. // colors
  26933. const colorFrustum = new Color( 0xffaa00 );
  26934. const colorCone = new Color( 0xff0000 );
  26935. const colorUp = new Color( 0x00aaff );
  26936. const colorTarget = new Color( 0xffffff );
  26937. const colorCross = new Color( 0x333333 );
  26938. // near
  26939. addLine( 'n1', 'n2', colorFrustum );
  26940. addLine( 'n2', 'n4', colorFrustum );
  26941. addLine( 'n4', 'n3', colorFrustum );
  26942. addLine( 'n3', 'n1', colorFrustum );
  26943. // far
  26944. addLine( 'f1', 'f2', colorFrustum );
  26945. addLine( 'f2', 'f4', colorFrustum );
  26946. addLine( 'f4', 'f3', colorFrustum );
  26947. addLine( 'f3', 'f1', colorFrustum );
  26948. // sides
  26949. addLine( 'n1', 'f1', colorFrustum );
  26950. addLine( 'n2', 'f2', colorFrustum );
  26951. addLine( 'n3', 'f3', colorFrustum );
  26952. addLine( 'n4', 'f4', colorFrustum );
  26953. // cone
  26954. addLine( 'p', 'n1', colorCone );
  26955. addLine( 'p', 'n2', colorCone );
  26956. addLine( 'p', 'n3', colorCone );
  26957. addLine( 'p', 'n4', colorCone );
  26958. // up
  26959. addLine( 'u1', 'u2', colorUp );
  26960. addLine( 'u2', 'u3', colorUp );
  26961. addLine( 'u3', 'u1', colorUp );
  26962. // target
  26963. addLine( 'c', 't', colorTarget );
  26964. addLine( 'p', 'c', colorCross );
  26965. // cross
  26966. addLine( 'cn1', 'cn2', colorCross );
  26967. addLine( 'cn3', 'cn4', colorCross );
  26968. addLine( 'cf1', 'cf2', colorCross );
  26969. addLine( 'cf3', 'cf4', colorCross );
  26970. function addLine( a, b, color ) {
  26971. addPoint( a, color );
  26972. addPoint( b, color );
  26973. }
  26974. function addPoint( id, color ) {
  26975. vertices.push( 0, 0, 0 );
  26976. colors.push( color.r, color.g, color.b );
  26977. if ( pointMap[ id ] === undefined ) {
  26978. pointMap[ id ] = [];
  26979. }
  26980. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  26981. }
  26982. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26983. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26984. super( geometry, material );
  26985. this.type = 'CameraHelper';
  26986. this.camera = camera;
  26987. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  26988. this.matrix = camera.matrixWorld;
  26989. this.matrixAutoUpdate = false;
  26990. this.pointMap = pointMap;
  26991. this.update();
  26992. }
  26993. update() {
  26994. const geometry = this.geometry;
  26995. const pointMap = this.pointMap;
  26996. const w = 1, h = 1;
  26997. // we need just camera projection matrix inverse
  26998. // world matrix must be identity
  26999. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27000. // center / target
  27001. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  27002. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  27003. // near
  27004. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  27005. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  27006. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  27007. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  27008. // far
  27009. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  27010. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  27011. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  27012. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  27013. // up
  27014. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  27015. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  27016. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  27017. // cross
  27018. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  27019. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  27020. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  27021. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  27022. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  27023. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  27024. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  27025. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  27026. geometry.getAttribute( 'position' ).needsUpdate = true;
  27027. }
  27028. }
  27029. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  27030. _vector$c.set( x, y, z ).unproject( camera );
  27031. const points = pointMap[ point ];
  27032. if ( points !== undefined ) {
  27033. const position = geometry.getAttribute( 'position' );
  27034. for ( let i = 0, l = points.length; i < l; i ++ ) {
  27035. position.setXYZ( points[ i ], _vector$c.x, _vector$c.y, _vector$c.z );
  27036. }
  27037. }
  27038. }
  27039. const _box$3 = /*@__PURE__*/ new Box3();
  27040. class BoxHelper extends LineSegments {
  27041. constructor( object, color = 0xffff00 ) {
  27042. 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 ] );
  27043. const positions = new Float32Array( 8 * 3 );
  27044. const geometry = new BufferGeometry();
  27045. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27046. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27047. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  27048. this.object = object;
  27049. this.type = 'BoxHelper';
  27050. this.matrixAutoUpdate = false;
  27051. this.update();
  27052. }
  27053. update( object ) {
  27054. if ( object !== undefined ) {
  27055. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27056. }
  27057. if ( this.object !== undefined ) {
  27058. _box$3.setFromObject( this.object );
  27059. }
  27060. if ( _box$3.isEmpty() ) return;
  27061. const min = _box$3.min;
  27062. const max = _box$3.max;
  27063. /*
  27064. 5____4
  27065. 1/___0/|
  27066. | 6__|_7
  27067. 2/___3/
  27068. 0: max.x, max.y, max.z
  27069. 1: min.x, max.y, max.z
  27070. 2: min.x, min.y, max.z
  27071. 3: max.x, min.y, max.z
  27072. 4: max.x, max.y, min.z
  27073. 5: min.x, max.y, min.z
  27074. 6: min.x, min.y, min.z
  27075. 7: max.x, min.y, min.z
  27076. */
  27077. const position = this.geometry.attributes.position;
  27078. const array = position.array;
  27079. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27080. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27081. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27082. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27083. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27084. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27085. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27086. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27087. position.needsUpdate = true;
  27088. this.geometry.computeBoundingSphere();
  27089. }
  27090. setFromObject( object ) {
  27091. this.object = object;
  27092. this.update();
  27093. return this;
  27094. }
  27095. copy( source ) {
  27096. LineSegments.prototype.copy.call( this, source );
  27097. this.object = source.object;
  27098. return this;
  27099. }
  27100. }
  27101. class Box3Helper extends LineSegments {
  27102. constructor( box, color = 0xffff00 ) {
  27103. 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 ] );
  27104. 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 ];
  27105. const geometry = new BufferGeometry();
  27106. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27107. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27108. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  27109. this.box = box;
  27110. this.type = 'Box3Helper';
  27111. this.geometry.computeBoundingSphere();
  27112. }
  27113. updateMatrixWorld( force ) {
  27114. const box = this.box;
  27115. if ( box.isEmpty() ) return;
  27116. box.getCenter( this.position );
  27117. box.getSize( this.scale );
  27118. this.scale.multiplyScalar( 0.5 );
  27119. super.updateMatrixWorld( force );
  27120. }
  27121. }
  27122. class PlaneHelper extends Line {
  27123. constructor( plane, size = 1, hex = 0xffff00 ) {
  27124. const color = hex;
  27125. 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 ];
  27126. const geometry = new BufferGeometry();
  27127. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27128. geometry.computeBoundingSphere();
  27129. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  27130. this.type = 'PlaneHelper';
  27131. this.plane = plane;
  27132. this.size = size;
  27133. const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27134. const geometry2 = new BufferGeometry();
  27135. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27136. geometry2.computeBoundingSphere();
  27137. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  27138. }
  27139. updateMatrixWorld( force ) {
  27140. let scale = - this.plane.constant;
  27141. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27142. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27143. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27144. this.lookAt( this.plane.normal );
  27145. super.updateMatrixWorld( force );
  27146. }
  27147. }
  27148. const _axis = /*@__PURE__*/ new Vector3();
  27149. let _lineGeometry, _coneGeometry;
  27150. class ArrowHelper extends Object3D {
  27151. // dir is assumed to be normalized
  27152. 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 ) {
  27153. super();
  27154. this.type = 'ArrowHelper';
  27155. if ( _lineGeometry === undefined ) {
  27156. _lineGeometry = new BufferGeometry();
  27157. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27158. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  27159. _coneGeometry.translate( 0, - 0.5, 0 );
  27160. }
  27161. this.position.copy( origin );
  27162. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  27163. this.line.matrixAutoUpdate = false;
  27164. this.add( this.line );
  27165. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  27166. this.cone.matrixAutoUpdate = false;
  27167. this.add( this.cone );
  27168. this.setDirection( dir );
  27169. this.setLength( length, headLength, headWidth );
  27170. }
  27171. setDirection( dir ) {
  27172. // dir is assumed to be normalized
  27173. if ( dir.y > 0.99999 ) {
  27174. this.quaternion.set( 0, 0, 0, 1 );
  27175. } else if ( dir.y < - 0.99999 ) {
  27176. this.quaternion.set( 1, 0, 0, 0 );
  27177. } else {
  27178. _axis.set( dir.z, 0, - dir.x ).normalize();
  27179. const radians = Math.acos( dir.y );
  27180. this.quaternion.setFromAxisAngle( _axis, radians );
  27181. }
  27182. }
  27183. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  27184. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  27185. this.line.updateMatrix();
  27186. this.cone.scale.set( headWidth, headLength, headWidth );
  27187. this.cone.position.y = length;
  27188. this.cone.updateMatrix();
  27189. }
  27190. setColor( color ) {
  27191. this.line.material.color.set( color );
  27192. this.cone.material.color.set( color );
  27193. }
  27194. copy( source ) {
  27195. super.copy( source, false );
  27196. this.line.copy( source.line );
  27197. this.cone.copy( source.cone );
  27198. return this;
  27199. }
  27200. }
  27201. class AxesHelper extends LineSegments {
  27202. constructor( size = 1 ) {
  27203. const vertices = [
  27204. 0, 0, 0, size, 0, 0,
  27205. 0, 0, 0, 0, size, 0,
  27206. 0, 0, 0, 0, 0, size
  27207. ];
  27208. const colors = [
  27209. 1, 0, 0, 1, 0.6, 0,
  27210. 0, 1, 0, 0.6, 1, 0,
  27211. 0, 0, 1, 0, 0.6, 1
  27212. ];
  27213. const geometry = new BufferGeometry();
  27214. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27215. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27216. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  27217. super( geometry, material );
  27218. this.type = 'AxesHelper';
  27219. }
  27220. }
  27221. const _floatView = new Float32Array( 1 );
  27222. const _int32View = new Int32Array( _floatView.buffer );
  27223. const DataUtils = {
  27224. // Converts float32 to float16 (stored as uint16 value).
  27225. toHalfFloat: function ( val ) {
  27226. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  27227. /* This method is faster than the OpenEXR implementation (very often
  27228. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  27229. * by James Tursa?s half-precision code. */
  27230. _floatView[ 0 ] = val;
  27231. const x = _int32View[ 0 ];
  27232. let bits = ( x >> 16 ) & 0x8000; /* Get the sign */
  27233. let m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
  27234. const e = ( x >> 23 ) & 0xff; /* Using int is faster here */
  27235. /* If zero, or denormal, or exponent underflows too much for a denormal
  27236. * half, return signed zero. */
  27237. if ( e < 103 ) return bits;
  27238. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  27239. if ( e > 142 ) {
  27240. bits |= 0x7c00;
  27241. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  27242. * not Inf, so make sure we set one mantissa bit too. */
  27243. bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
  27244. return bits;
  27245. }
  27246. /* If exponent underflows but not too much, return a denormal */
  27247. if ( e < 113 ) {
  27248. m |= 0x0800;
  27249. /* Extra rounding may overflow and set mantissa to 0 and exponent
  27250. * to 1, which is OK. */
  27251. bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
  27252. return bits;
  27253. }
  27254. bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
  27255. /* Extra rounding. An overflow will set mantissa to 0 and increment
  27256. * the exponent, which is OK. */
  27257. bits += m & 1;
  27258. return bits;
  27259. }
  27260. };
  27261. const LOD_MIN = 4;
  27262. const LOD_MAX = 8;
  27263. const SIZE_MAX = Math.pow( 2, LOD_MAX );
  27264. // The standard deviations (radians) associated with the extra mips. These are
  27265. // chosen to approximate a Trowbridge-Reitz distribution function times the
  27266. // geometric shadowing function. These sigma values squared must match the
  27267. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  27268. const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  27269. const TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  27270. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  27271. // samples and exit early, but not recompile the shader.
  27272. const MAX_SAMPLES = 20;
  27273. const ENCODINGS = {
  27274. [ LinearEncoding ]: 0,
  27275. [ sRGBEncoding ]: 1,
  27276. [ RGBEEncoding ]: 2,
  27277. [ RGBM7Encoding ]: 3,
  27278. [ RGBM16Encoding ]: 4,
  27279. [ RGBDEncoding ]: 5,
  27280. [ GammaEncoding ]: 6
  27281. };
  27282. const backgroundMaterial = new MeshBasicMaterial( {
  27283. side: BackSide,
  27284. depthWrite: false,
  27285. depthTest: false,
  27286. } );
  27287. const backgroundBox = new Mesh( new BoxGeometry(), backgroundMaterial );
  27288. const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
  27289. const { _lodPlanes, _sizeLods, _sigmas } = /*@__PURE__*/ _createPlanes();
  27290. const _clearColor = /*@__PURE__*/ new Color();
  27291. let _oldTarget = null;
  27292. // Golden Ratio
  27293. const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  27294. const INV_PHI = 1 / PHI;
  27295. // Vertices of a dodecahedron (except the opposites, which represent the
  27296. // same axis), used as axis directions evenly spread on a sphere.
  27297. const _axisDirections = [
  27298. /*@__PURE__*/ new Vector3( 1, 1, 1 ),
  27299. /*@__PURE__*/ new Vector3( - 1, 1, 1 ),
  27300. /*@__PURE__*/ new Vector3( 1, 1, - 1 ),
  27301. /*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
  27302. /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
  27303. /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
  27304. /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
  27305. /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
  27306. /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
  27307. /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ) ];
  27308. /**
  27309. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  27310. * (PMREM) from a cubeMap environment texture. This allows different levels of
  27311. * blur to be quickly accessed based on material roughness. It is packed into a
  27312. * special CubeUV format that allows us to perform custom interpolation so that
  27313. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  27314. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  27315. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  27316. * higher roughness levels. In this way we maintain resolution to smoothly
  27317. * interpolate diffuse lighting while limiting sampling computation.
  27318. */
  27319. function convertLinearToRGBE( color ) {
  27320. const maxComponent = Math.max( color.r, color.g, color.b );
  27321. const fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  27322. color.multiplyScalar( Math.pow( 2.0, - fExp ) );
  27323. const alpha = ( fExp + 128.0 ) / 255.0;
  27324. return alpha;
  27325. }
  27326. class PMREMGenerator {
  27327. constructor( renderer ) {
  27328. this._renderer = renderer;
  27329. this._pingPongRenderTarget = null;
  27330. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  27331. this._equirectShader = null;
  27332. this._cubemapShader = null;
  27333. this._compileMaterial( this._blurMaterial );
  27334. }
  27335. /**
  27336. * Generates a PMREM from a supplied Scene, which can be faster than using an
  27337. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  27338. * in radians to be applied to the scene before PMREM generation. Optional near
  27339. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  27340. * is placed at the origin).
  27341. */
  27342. fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
  27343. _oldTarget = this._renderer.getRenderTarget();
  27344. const cubeUVRenderTarget = this._allocateTargets();
  27345. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  27346. if ( sigma > 0 ) {
  27347. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  27348. }
  27349. this._applyPMREM( cubeUVRenderTarget );
  27350. this._cleanup( cubeUVRenderTarget );
  27351. return cubeUVRenderTarget;
  27352. }
  27353. /**
  27354. * Generates a PMREM from an equirectangular texture, which can be either LDR
  27355. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  27356. * as this matches best with the 256 x 256 cubemap output.
  27357. */
  27358. fromEquirectangular( equirectangular ) {
  27359. return this._fromTexture( equirectangular );
  27360. }
  27361. /**
  27362. * Generates a PMREM from an cubemap texture, which can be either LDR
  27363. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  27364. * as this matches best with the 256 x 256 cubemap output.
  27365. */
  27366. fromCubemap( cubemap ) {
  27367. return this._fromTexture( cubemap );
  27368. }
  27369. /**
  27370. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  27371. * your texture's network fetch for increased concurrency.
  27372. */
  27373. compileCubemapShader() {
  27374. if ( this._cubemapShader === null ) {
  27375. this._cubemapShader = _getCubemapShader();
  27376. this._compileMaterial( this._cubemapShader );
  27377. }
  27378. }
  27379. /**
  27380. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  27381. * your texture's network fetch for increased concurrency.
  27382. */
  27383. compileEquirectangularShader() {
  27384. if ( this._equirectShader === null ) {
  27385. this._equirectShader = _getEquirectShader();
  27386. this._compileMaterial( this._equirectShader );
  27387. }
  27388. }
  27389. /**
  27390. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  27391. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  27392. * one of them will cause any others to also become unusable.
  27393. */
  27394. dispose() {
  27395. this._blurMaterial.dispose();
  27396. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  27397. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  27398. for ( let i = 0; i < _lodPlanes.length; i ++ ) {
  27399. _lodPlanes[ i ].dispose();
  27400. }
  27401. }
  27402. // private interface
  27403. _cleanup( outputTarget ) {
  27404. this._pingPongRenderTarget.dispose();
  27405. this._renderer.setRenderTarget( _oldTarget );
  27406. outputTarget.scissorTest = false;
  27407. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  27408. }
  27409. _fromTexture( texture ) {
  27410. _oldTarget = this._renderer.getRenderTarget();
  27411. const cubeUVRenderTarget = this._allocateTargets( texture );
  27412. this._textureToCubeUV( texture, cubeUVRenderTarget );
  27413. this._applyPMREM( cubeUVRenderTarget );
  27414. this._cleanup( cubeUVRenderTarget );
  27415. return cubeUVRenderTarget;
  27416. }
  27417. _allocateTargets( texture ) { // warning: null texture is valid
  27418. const params = {
  27419. magFilter: NearestFilter,
  27420. minFilter: NearestFilter,
  27421. generateMipmaps: false,
  27422. type: UnsignedByteType,
  27423. format: RGBEFormat,
  27424. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  27425. depthBuffer: false
  27426. };
  27427. const cubeUVRenderTarget = _createRenderTarget( params );
  27428. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  27429. this._pingPongRenderTarget = _createRenderTarget( params );
  27430. return cubeUVRenderTarget;
  27431. }
  27432. _compileMaterial( material ) {
  27433. const tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  27434. this._renderer.compile( tmpMesh, _flatCamera );
  27435. }
  27436. _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
  27437. const fov = 90;
  27438. const aspect = 1;
  27439. const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  27440. const upSign = [ 1, - 1, 1, 1, 1, 1 ];
  27441. const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  27442. const renderer = this._renderer;
  27443. const originalAutoClear = renderer.autoClear;
  27444. const outputEncoding = renderer.outputEncoding;
  27445. const toneMapping = renderer.toneMapping;
  27446. renderer.getClearColor( _clearColor );
  27447. renderer.toneMapping = NoToneMapping;
  27448. renderer.outputEncoding = LinearEncoding;
  27449. renderer.autoClear = false;
  27450. let useSolidColor = false;
  27451. const background = scene.background;
  27452. if ( background ) {
  27453. if ( background.isColor ) {
  27454. backgroundMaterial.color.copy( background ).convertSRGBToLinear();
  27455. scene.background = null;
  27456. const alpha = convertLinearToRGBE( backgroundMaterial.color );
  27457. backgroundMaterial.opacity = alpha;
  27458. useSolidColor = true;
  27459. }
  27460. } else {
  27461. backgroundMaterial.color.copy( _clearColor ).convertSRGBToLinear();
  27462. const alpha = convertLinearToRGBE( backgroundMaterial.color );
  27463. backgroundMaterial.opacity = alpha;
  27464. useSolidColor = true;
  27465. }
  27466. for ( let i = 0; i < 6; i ++ ) {
  27467. const col = i % 3;
  27468. if ( col == 0 ) {
  27469. cubeCamera.up.set( 0, upSign[ i ], 0 );
  27470. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  27471. } else if ( col == 1 ) {
  27472. cubeCamera.up.set( 0, 0, upSign[ i ] );
  27473. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  27474. } else {
  27475. cubeCamera.up.set( 0, upSign[ i ], 0 );
  27476. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  27477. }
  27478. _setViewport( cubeUVRenderTarget,
  27479. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  27480. renderer.setRenderTarget( cubeUVRenderTarget );
  27481. if ( useSolidColor ) {
  27482. renderer.render( backgroundBox, cubeCamera );
  27483. }
  27484. renderer.render( scene, cubeCamera );
  27485. }
  27486. renderer.toneMapping = toneMapping;
  27487. renderer.outputEncoding = outputEncoding;
  27488. renderer.autoClear = originalAutoClear;
  27489. }
  27490. _textureToCubeUV( texture, cubeUVRenderTarget ) {
  27491. const renderer = this._renderer;
  27492. if ( texture.isCubeTexture ) {
  27493. if ( this._cubemapShader == null ) {
  27494. this._cubemapShader = _getCubemapShader();
  27495. }
  27496. } else {
  27497. if ( this._equirectShader == null ) {
  27498. this._equirectShader = _getEquirectShader();
  27499. }
  27500. }
  27501. const material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  27502. const mesh = new Mesh( _lodPlanes[ 0 ], material );
  27503. const uniforms = material.uniforms;
  27504. uniforms[ 'envMap' ].value = texture;
  27505. if ( ! texture.isCubeTexture ) {
  27506. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  27507. }
  27508. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  27509. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  27510. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  27511. renderer.setRenderTarget( cubeUVRenderTarget );
  27512. renderer.render( mesh, _flatCamera );
  27513. }
  27514. _applyPMREM( cubeUVRenderTarget ) {
  27515. const renderer = this._renderer;
  27516. const autoClear = renderer.autoClear;
  27517. renderer.autoClear = false;
  27518. for ( let i = 1; i < TOTAL_LODS; i ++ ) {
  27519. const sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  27520. const poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  27521. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  27522. }
  27523. renderer.autoClear = autoClear;
  27524. }
  27525. /**
  27526. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  27527. * vertically and horizontally, but this breaks down on a cube. Here we apply
  27528. * the blur latitudinally (around the poles), and then longitudinally (towards
  27529. * the poles) to approximate the orthogonally-separable blur. It is least
  27530. * accurate at the poles, but still does a decent job.
  27531. */
  27532. _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  27533. const pingPongRenderTarget = this._pingPongRenderTarget;
  27534. this._halfBlur(
  27535. cubeUVRenderTarget,
  27536. pingPongRenderTarget,
  27537. lodIn,
  27538. lodOut,
  27539. sigma,
  27540. 'latitudinal',
  27541. poleAxis );
  27542. this._halfBlur(
  27543. pingPongRenderTarget,
  27544. cubeUVRenderTarget,
  27545. lodOut,
  27546. lodOut,
  27547. sigma,
  27548. 'longitudinal',
  27549. poleAxis );
  27550. }
  27551. _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  27552. const renderer = this._renderer;
  27553. const blurMaterial = this._blurMaterial;
  27554. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  27555. console.error(
  27556. 'blur direction must be either latitudinal or longitudinal!' );
  27557. }
  27558. // Number of standard deviations at which to cut off the discrete approximation.
  27559. const STANDARD_DEVIATIONS = 3;
  27560. const blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  27561. const blurUniforms = blurMaterial.uniforms;
  27562. const pixels = _sizeLods[ lodIn ] - 1;
  27563. const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  27564. const sigmaPixels = sigmaRadians / radiansPerPixel;
  27565. const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  27566. if ( samples > MAX_SAMPLES ) {
  27567. console.warn( `sigmaRadians, ${
  27568. sigmaRadians}, is too large and will clip, as it requested ${
  27569. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  27570. }
  27571. const weights = [];
  27572. let sum = 0;
  27573. for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
  27574. const x = i / sigmaPixels;
  27575. const weight = Math.exp( - x * x / 2 );
  27576. weights.push( weight );
  27577. if ( i == 0 ) {
  27578. sum += weight;
  27579. } else if ( i < samples ) {
  27580. sum += 2 * weight;
  27581. }
  27582. }
  27583. for ( let i = 0; i < weights.length; i ++ ) {
  27584. weights[ i ] = weights[ i ] / sum;
  27585. }
  27586. blurUniforms[ 'envMap' ].value = targetIn.texture;
  27587. blurUniforms[ 'samples' ].value = samples;
  27588. blurUniforms[ 'weights' ].value = weights;
  27589. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  27590. if ( poleAxis ) {
  27591. blurUniforms[ 'poleAxis' ].value = poleAxis;
  27592. }
  27593. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  27594. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  27595. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  27596. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  27597. const outputSize = _sizeLods[ lodOut ];
  27598. const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  27599. const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  27600. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  27601. renderer.setRenderTarget( targetOut );
  27602. renderer.render( blurMesh, _flatCamera );
  27603. }
  27604. }
  27605. function _isLDR( texture ) {
  27606. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  27607. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  27608. }
  27609. function _createPlanes() {
  27610. const _lodPlanes = [];
  27611. const _sizeLods = [];
  27612. const _sigmas = [];
  27613. let lod = LOD_MAX;
  27614. for ( let i = 0; i < TOTAL_LODS; i ++ ) {
  27615. const sizeLod = Math.pow( 2, lod );
  27616. _sizeLods.push( sizeLod );
  27617. let sigma = 1.0 / sizeLod;
  27618. if ( i > LOD_MAX - LOD_MIN ) {
  27619. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  27620. } else if ( i == 0 ) {
  27621. sigma = 0;
  27622. }
  27623. _sigmas.push( sigma );
  27624. const texelSize = 1.0 / ( sizeLod - 1 );
  27625. const min = - texelSize / 2;
  27626. const max = 1 + texelSize / 2;
  27627. const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  27628. const cubeFaces = 6;
  27629. const vertices = 6;
  27630. const positionSize = 3;
  27631. const uvSize = 2;
  27632. const faceIndexSize = 1;
  27633. const position = new Float32Array( positionSize * vertices * cubeFaces );
  27634. const uv = new Float32Array( uvSize * vertices * cubeFaces );
  27635. const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  27636. for ( let face = 0; face < cubeFaces; face ++ ) {
  27637. const x = ( face % 3 ) * 2 / 3 - 1;
  27638. const y = face > 2 ? 0 : - 1;
  27639. const coordinates = [
  27640. x, y, 0,
  27641. x + 2 / 3, y, 0,
  27642. x + 2 / 3, y + 1, 0,
  27643. x, y, 0,
  27644. x + 2 / 3, y + 1, 0,
  27645. x, y + 1, 0
  27646. ];
  27647. position.set( coordinates, positionSize * vertices * face );
  27648. uv.set( uv1, uvSize * vertices * face );
  27649. const fill = [ face, face, face, face, face, face ];
  27650. faceIndex.set( fill, faceIndexSize * vertices * face );
  27651. }
  27652. const planes = new BufferGeometry();
  27653. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  27654. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  27655. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  27656. _lodPlanes.push( planes );
  27657. if ( lod > LOD_MIN ) {
  27658. lod --;
  27659. }
  27660. }
  27661. return { _lodPlanes, _sizeLods, _sigmas };
  27662. }
  27663. function _createRenderTarget( params ) {
  27664. const cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  27665. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  27666. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  27667. cubeUVRenderTarget.scissorTest = true;
  27668. return cubeUVRenderTarget;
  27669. }
  27670. function _setViewport( target, x, y, width, height ) {
  27671. target.viewport.set( x, y, width, height );
  27672. target.scissor.set( x, y, width, height );
  27673. }
  27674. function _getBlurShader( maxSamples ) {
  27675. const weights = new Float32Array( maxSamples );
  27676. const poleAxis = new Vector3( 0, 1, 0 );
  27677. const shaderMaterial = new RawShaderMaterial( {
  27678. name: 'SphericalGaussianBlur',
  27679. defines: { 'n': maxSamples },
  27680. uniforms: {
  27681. 'envMap': { value: null },
  27682. 'samples': { value: 1 },
  27683. 'weights': { value: weights },
  27684. 'latitudinal': { value: false },
  27685. 'dTheta': { value: 0 },
  27686. 'mipInt': { value: 0 },
  27687. 'poleAxis': { value: poleAxis },
  27688. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  27689. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  27690. },
  27691. vertexShader: _getCommonVertexShader(),
  27692. fragmentShader: /* glsl */`
  27693. precision mediump float;
  27694. precision mediump int;
  27695. varying vec3 vOutputDirection;
  27696. uniform sampler2D envMap;
  27697. uniform int samples;
  27698. uniform float weights[ n ];
  27699. uniform bool latitudinal;
  27700. uniform float dTheta;
  27701. uniform float mipInt;
  27702. uniform vec3 poleAxis;
  27703. ${ _getEncodings() }
  27704. #define ENVMAP_TYPE_CUBE_UV
  27705. #include <cube_uv_reflection_fragment>
  27706. vec3 getSample( float theta, vec3 axis ) {
  27707. float cosTheta = cos( theta );
  27708. // Rodrigues' axis-angle rotation
  27709. vec3 sampleDirection = vOutputDirection * cosTheta
  27710. + cross( axis, vOutputDirection ) * sin( theta )
  27711. + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
  27712. return bilinearCubeUV( envMap, sampleDirection, mipInt );
  27713. }
  27714. void main() {
  27715. vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
  27716. if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
  27717. axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
  27718. }
  27719. axis = normalize( axis );
  27720. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  27721. gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
  27722. for ( int i = 1; i < n; i++ ) {
  27723. if ( i >= samples ) {
  27724. break;
  27725. }
  27726. float theta = dTheta * float( i );
  27727. gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
  27728. gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
  27729. }
  27730. gl_FragColor = linearToOutputTexel( gl_FragColor );
  27731. }
  27732. `,
  27733. blending: NoBlending,
  27734. depthTest: false,
  27735. depthWrite: false
  27736. } );
  27737. return shaderMaterial;
  27738. }
  27739. function _getEquirectShader() {
  27740. const texelSize = new Vector2( 1, 1 );
  27741. const shaderMaterial = new RawShaderMaterial( {
  27742. name: 'EquirectangularToCubeUV',
  27743. uniforms: {
  27744. 'envMap': { value: null },
  27745. 'texelSize': { value: texelSize },
  27746. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  27747. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  27748. },
  27749. vertexShader: _getCommonVertexShader(),
  27750. fragmentShader: /* glsl */`
  27751. precision mediump float;
  27752. precision mediump int;
  27753. varying vec3 vOutputDirection;
  27754. uniform sampler2D envMap;
  27755. uniform vec2 texelSize;
  27756. ${ _getEncodings() }
  27757. #include <common>
  27758. void main() {
  27759. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  27760. vec3 outputDirection = normalize( vOutputDirection );
  27761. vec2 uv = equirectUv( outputDirection );
  27762. vec2 f = fract( uv / texelSize - 0.5 );
  27763. uv -= f * texelSize;
  27764. vec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  27765. uv.x += texelSize.x;
  27766. vec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  27767. uv.y += texelSize.y;
  27768. vec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  27769. uv.x -= texelSize.x;
  27770. vec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  27771. vec3 tm = mix( tl, tr, f.x );
  27772. vec3 bm = mix( bl, br, f.x );
  27773. gl_FragColor.rgb = mix( tm, bm, f.y );
  27774. gl_FragColor = linearToOutputTexel( gl_FragColor );
  27775. }
  27776. `,
  27777. blending: NoBlending,
  27778. depthTest: false,
  27779. depthWrite: false
  27780. } );
  27781. return shaderMaterial;
  27782. }
  27783. function _getCubemapShader() {
  27784. const shaderMaterial = new RawShaderMaterial( {
  27785. name: 'CubemapToCubeUV',
  27786. uniforms: {
  27787. 'envMap': { value: null },
  27788. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  27789. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  27790. },
  27791. vertexShader: _getCommonVertexShader(),
  27792. fragmentShader: /* glsl */`
  27793. precision mediump float;
  27794. precision mediump int;
  27795. varying vec3 vOutputDirection;
  27796. uniform samplerCube envMap;
  27797. ${ _getEncodings() }
  27798. void main() {
  27799. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  27800. gl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;
  27801. gl_FragColor = linearToOutputTexel( gl_FragColor );
  27802. }
  27803. `,
  27804. blending: NoBlending,
  27805. depthTest: false,
  27806. depthWrite: false
  27807. } );
  27808. return shaderMaterial;
  27809. }
  27810. function _getCommonVertexShader() {
  27811. return /* glsl */`
  27812. precision mediump float;
  27813. precision mediump int;
  27814. attribute vec3 position;
  27815. attribute vec2 uv;
  27816. attribute float faceIndex;
  27817. varying vec3 vOutputDirection;
  27818. // RH coordinate system; PMREM face-indexing convention
  27819. vec3 getDirection( vec2 uv, float face ) {
  27820. uv = 2.0 * uv - 1.0;
  27821. vec3 direction = vec3( uv, 1.0 );
  27822. if ( face == 0.0 ) {
  27823. direction = direction.zyx; // ( 1, v, u ) pos x
  27824. } else if ( face == 1.0 ) {
  27825. direction = direction.xzy;
  27826. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  27827. } else if ( face == 2.0 ) {
  27828. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  27829. } else if ( face == 3.0 ) {
  27830. direction = direction.zyx;
  27831. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  27832. } else if ( face == 4.0 ) {
  27833. direction = direction.xzy;
  27834. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  27835. } else if ( face == 5.0 ) {
  27836. direction.z *= -1.0; // ( u, v, -1 ) neg z
  27837. }
  27838. return direction;
  27839. }
  27840. void main() {
  27841. vOutputDirection = getDirection( uv, faceIndex );
  27842. gl_Position = vec4( position, 1.0 );
  27843. }
  27844. `;
  27845. }
  27846. function _getEncodings() {
  27847. return /* glsl */`
  27848. uniform int inputEncoding;
  27849. uniform int outputEncoding;
  27850. #include <encodings_pars_fragment>
  27851. vec4 inputTexelToLinear( vec4 value ) {
  27852. if ( inputEncoding == 0 ) {
  27853. return value;
  27854. } else if ( inputEncoding == 1 ) {
  27855. return sRGBToLinear( value );
  27856. } else if ( inputEncoding == 2 ) {
  27857. return RGBEToLinear( value );
  27858. } else if ( inputEncoding == 3 ) {
  27859. return RGBMToLinear( value, 7.0 );
  27860. } else if ( inputEncoding == 4 ) {
  27861. return RGBMToLinear( value, 16.0 );
  27862. } else if ( inputEncoding == 5 ) {
  27863. return RGBDToLinear( value, 256.0 );
  27864. } else {
  27865. return GammaToLinear( value, 2.2 );
  27866. }
  27867. }
  27868. vec4 linearToOutputTexel( vec4 value ) {
  27869. if ( outputEncoding == 0 ) {
  27870. return value;
  27871. } else if ( outputEncoding == 1 ) {
  27872. return LinearTosRGB( value );
  27873. } else if ( outputEncoding == 2 ) {
  27874. return LinearToRGBE( value );
  27875. } else if ( outputEncoding == 3 ) {
  27876. return LinearToRGBM( value, 7.0 );
  27877. } else if ( outputEncoding == 4 ) {
  27878. return LinearToRGBM( value, 16.0 );
  27879. } else if ( outputEncoding == 5 ) {
  27880. return LinearToRGBD( value, 256.0 );
  27881. } else {
  27882. return LinearToGamma( value, 2.2 );
  27883. }
  27884. }
  27885. vec4 envMapTexelToLinear( vec4 color ) {
  27886. return inputTexelToLinear( color );
  27887. }
  27888. `;
  27889. }
  27890. const LineStrip = 0;
  27891. const LinePieces = 1;
  27892. const NoColors = 0;
  27893. const FaceColors = 1;
  27894. const VertexColors = 2;
  27895. function MeshFaceMaterial( materials ) {
  27896. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27897. return materials;
  27898. }
  27899. function MultiMaterial( materials = [] ) {
  27900. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27901. materials.isMultiMaterial = true;
  27902. materials.materials = materials;
  27903. materials.clone = function () {
  27904. return materials.slice();
  27905. };
  27906. return materials;
  27907. }
  27908. function PointCloud( geometry, material ) {
  27909. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27910. return new Points( geometry, material );
  27911. }
  27912. function Particle( material ) {
  27913. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27914. return new Sprite( material );
  27915. }
  27916. function ParticleSystem( geometry, material ) {
  27917. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27918. return new Points( geometry, material );
  27919. }
  27920. function PointCloudMaterial( parameters ) {
  27921. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27922. return new PointsMaterial( parameters );
  27923. }
  27924. function ParticleBasicMaterial( parameters ) {
  27925. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27926. return new PointsMaterial( parameters );
  27927. }
  27928. function ParticleSystemMaterial( parameters ) {
  27929. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27930. return new PointsMaterial( parameters );
  27931. }
  27932. function Vertex( x, y, z ) {
  27933. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27934. return new Vector3( x, y, z );
  27935. }
  27936. //
  27937. function DynamicBufferAttribute( array, itemSize ) {
  27938. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  27939. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  27940. }
  27941. function Int8Attribute( array, itemSize ) {
  27942. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27943. return new Int8BufferAttribute( array, itemSize );
  27944. }
  27945. function Uint8Attribute( array, itemSize ) {
  27946. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27947. return new Uint8BufferAttribute( array, itemSize );
  27948. }
  27949. function Uint8ClampedAttribute( array, itemSize ) {
  27950. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27951. return new Uint8ClampedBufferAttribute( array, itemSize );
  27952. }
  27953. function Int16Attribute( array, itemSize ) {
  27954. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27955. return new Int16BufferAttribute( array, itemSize );
  27956. }
  27957. function Uint16Attribute( array, itemSize ) {
  27958. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27959. return new Uint16BufferAttribute( array, itemSize );
  27960. }
  27961. function Int32Attribute( array, itemSize ) {
  27962. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27963. return new Int32BufferAttribute( array, itemSize );
  27964. }
  27965. function Uint32Attribute( array, itemSize ) {
  27966. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27967. return new Uint32BufferAttribute( array, itemSize );
  27968. }
  27969. function Float32Attribute( array, itemSize ) {
  27970. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27971. return new Float32BufferAttribute( array, itemSize );
  27972. }
  27973. function Float64Attribute( array, itemSize ) {
  27974. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27975. return new Float64BufferAttribute( array, itemSize );
  27976. }
  27977. //
  27978. Curve.create = function ( construct, getPoint ) {
  27979. console.log( 'THREE.Curve.create() has been deprecated' );
  27980. construct.prototype = Object.create( Curve.prototype );
  27981. construct.prototype.constructor = construct;
  27982. construct.prototype.getPoint = getPoint;
  27983. return construct;
  27984. };
  27985. //
  27986. Path.prototype.fromPoints = function ( points ) {
  27987. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27988. return this.setFromPoints( points );
  27989. };
  27990. //
  27991. function AxisHelper( size ) {
  27992. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27993. return new AxesHelper( size );
  27994. }
  27995. function BoundingBoxHelper( object, color ) {
  27996. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27997. return new BoxHelper( object, color );
  27998. }
  27999. function EdgesHelper( object, hex ) {
  28000. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28001. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28002. }
  28003. GridHelper.prototype.setColors = function () {
  28004. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28005. };
  28006. SkeletonHelper.prototype.update = function () {
  28007. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28008. };
  28009. function WireframeHelper( object, hex ) {
  28010. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28011. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28012. }
  28013. //
  28014. Loader.prototype.extractUrlBase = function ( url ) {
  28015. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28016. return LoaderUtils.extractUrlBase( url );
  28017. };
  28018. Loader.Handlers = {
  28019. add: function ( /* regex, loader */ ) {
  28020. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  28021. },
  28022. get: function ( /* file */ ) {
  28023. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  28024. }
  28025. };
  28026. function XHRLoader( manager ) {
  28027. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28028. return new FileLoader( manager );
  28029. }
  28030. function BinaryTextureLoader( manager ) {
  28031. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28032. return new DataTextureLoader( manager );
  28033. }
  28034. //
  28035. Box2.prototype.center = function ( optionalTarget ) {
  28036. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28037. return this.getCenter( optionalTarget );
  28038. };
  28039. Box2.prototype.empty = function () {
  28040. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28041. return this.isEmpty();
  28042. };
  28043. Box2.prototype.isIntersectionBox = function ( box ) {
  28044. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28045. return this.intersectsBox( box );
  28046. };
  28047. Box2.prototype.size = function ( optionalTarget ) {
  28048. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28049. return this.getSize( optionalTarget );
  28050. };
  28051. //
  28052. Box3.prototype.center = function ( optionalTarget ) {
  28053. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28054. return this.getCenter( optionalTarget );
  28055. };
  28056. Box3.prototype.empty = function () {
  28057. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28058. return this.isEmpty();
  28059. };
  28060. Box3.prototype.isIntersectionBox = function ( box ) {
  28061. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28062. return this.intersectsBox( box );
  28063. };
  28064. Box3.prototype.isIntersectionSphere = function ( sphere ) {
  28065. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28066. return this.intersectsSphere( sphere );
  28067. };
  28068. Box3.prototype.size = function ( optionalTarget ) {
  28069. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28070. return this.getSize( optionalTarget );
  28071. };
  28072. //
  28073. Sphere.prototype.empty = function () {
  28074. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  28075. return this.isEmpty();
  28076. };
  28077. //
  28078. Frustum.prototype.setFromMatrix = function ( m ) {
  28079. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  28080. return this.setFromProjectionMatrix( m );
  28081. };
  28082. //
  28083. Line3.prototype.center = function ( optionalTarget ) {
  28084. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28085. return this.getCenter( optionalTarget );
  28086. };
  28087. //
  28088. MathUtils.random16 = function () {
  28089. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28090. return Math.random();
  28091. };
  28092. MathUtils.nearestPowerOfTwo = function ( value ) {
  28093. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28094. return MathUtils.floorPowerOfTwo( value );
  28095. };
  28096. MathUtils.nextPowerOfTwo = function ( value ) {
  28097. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28098. return MathUtils.ceilPowerOfTwo( value );
  28099. };
  28100. //
  28101. Matrix3.prototype.flattenToArrayOffset = function ( array, offset ) {
  28102. console.warn( 'THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  28103. return this.toArray( array, offset );
  28104. };
  28105. Matrix3.prototype.multiplyVector3 = function ( vector ) {
  28106. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28107. return vector.applyMatrix3( this );
  28108. };
  28109. Matrix3.prototype.multiplyVector3Array = function ( /* a */ ) {
  28110. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28111. };
  28112. Matrix3.prototype.applyToBufferAttribute = function ( attribute ) {
  28113. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  28114. return attribute.applyMatrix3( this );
  28115. };
  28116. Matrix3.prototype.applyToVector3Array = function ( /* array, offset, length */ ) {
  28117. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28118. };
  28119. Matrix3.prototype.getInverse = function ( matrix ) {
  28120. console.warn( 'THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  28121. return this.copy( matrix ).invert();
  28122. };
  28123. //
  28124. Matrix4.prototype.extractPosition = function ( m ) {
  28125. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28126. return this.copyPosition( m );
  28127. };
  28128. Matrix4.prototype.flattenToArrayOffset = function ( array, offset ) {
  28129. console.warn( 'THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  28130. return this.toArray( array, offset );
  28131. };
  28132. Matrix4.prototype.getPosition = function () {
  28133. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28134. return new Vector3().setFromMatrixColumn( this, 3 );
  28135. };
  28136. Matrix4.prototype.setRotationFromQuaternion = function ( q ) {
  28137. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28138. return this.makeRotationFromQuaternion( q );
  28139. };
  28140. Matrix4.prototype.multiplyToArray = function () {
  28141. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28142. };
  28143. Matrix4.prototype.multiplyVector3 = function ( vector ) {
  28144. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28145. return vector.applyMatrix4( this );
  28146. };
  28147. Matrix4.prototype.multiplyVector4 = function ( vector ) {
  28148. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28149. return vector.applyMatrix4( this );
  28150. };
  28151. Matrix4.prototype.multiplyVector3Array = function ( /* a */ ) {
  28152. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28153. };
  28154. Matrix4.prototype.rotateAxis = function ( v ) {
  28155. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28156. v.transformDirection( this );
  28157. };
  28158. Matrix4.prototype.crossVector = function ( vector ) {
  28159. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28160. return vector.applyMatrix4( this );
  28161. };
  28162. Matrix4.prototype.translate = function () {
  28163. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28164. };
  28165. Matrix4.prototype.rotateX = function () {
  28166. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28167. };
  28168. Matrix4.prototype.rotateY = function () {
  28169. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28170. };
  28171. Matrix4.prototype.rotateZ = function () {
  28172. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28173. };
  28174. Matrix4.prototype.rotateByAxis = function () {
  28175. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28176. };
  28177. Matrix4.prototype.applyToBufferAttribute = function ( attribute ) {
  28178. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  28179. return attribute.applyMatrix4( this );
  28180. };
  28181. Matrix4.prototype.applyToVector3Array = function ( /* array, offset, length */ ) {
  28182. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28183. };
  28184. Matrix4.prototype.makeFrustum = function ( left, right, bottom, top, near, far ) {
  28185. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28186. return this.makePerspective( left, right, top, bottom, near, far );
  28187. };
  28188. Matrix4.prototype.getInverse = function ( matrix ) {
  28189. console.warn( 'THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  28190. return this.copy( matrix ).invert();
  28191. };
  28192. //
  28193. Plane.prototype.isIntersectionLine = function ( line ) {
  28194. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28195. return this.intersectsLine( line );
  28196. };
  28197. //
  28198. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28199. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28200. return vector.applyQuaternion( this );
  28201. };
  28202. Quaternion.prototype.inverse = function ( ) {
  28203. console.warn( 'THREE.Quaternion: .inverse() has been renamed to invert().' );
  28204. return this.invert();
  28205. };
  28206. //
  28207. Ray.prototype.isIntersectionBox = function ( box ) {
  28208. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28209. return this.intersectsBox( box );
  28210. };
  28211. Ray.prototype.isIntersectionPlane = function ( plane ) {
  28212. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28213. return this.intersectsPlane( plane );
  28214. };
  28215. Ray.prototype.isIntersectionSphere = function ( sphere ) {
  28216. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28217. return this.intersectsSphere( sphere );
  28218. };
  28219. //
  28220. Triangle.prototype.area = function () {
  28221. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28222. return this.getArea();
  28223. };
  28224. Triangle.prototype.barycoordFromPoint = function ( point, target ) {
  28225. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28226. return this.getBarycoord( point, target );
  28227. };
  28228. Triangle.prototype.midpoint = function ( target ) {
  28229. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28230. return this.getMidpoint( target );
  28231. };
  28232. Triangle.prototypenormal = function ( target ) {
  28233. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28234. return this.getNormal( target );
  28235. };
  28236. Triangle.prototype.plane = function ( target ) {
  28237. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28238. return this.getPlane( target );
  28239. };
  28240. Triangle.barycoordFromPoint = function ( point, a, b, c, target ) {
  28241. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28242. return Triangle.getBarycoord( point, a, b, c, target );
  28243. };
  28244. Triangle.normal = function ( a, b, c, target ) {
  28245. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28246. return Triangle.getNormal( a, b, c, target );
  28247. };
  28248. //
  28249. Shape.prototype.extractAllPoints = function ( divisions ) {
  28250. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28251. return this.extractPoints( divisions );
  28252. };
  28253. Shape.prototype.extrude = function ( options ) {
  28254. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28255. return new ExtrudeGeometry( this, options );
  28256. };
  28257. Shape.prototype.makeGeometry = function ( options ) {
  28258. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28259. return new ShapeGeometry( this, options );
  28260. };
  28261. //
  28262. Vector2.prototype.fromAttribute = function ( attribute, index, offset ) {
  28263. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28264. return this.fromBufferAttribute( attribute, index, offset );
  28265. };
  28266. Vector2.prototype.distanceToManhattan = function ( v ) {
  28267. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28268. return this.manhattanDistanceTo( v );
  28269. };
  28270. Vector2.prototype.lengthManhattan = function () {
  28271. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28272. return this.manhattanLength();
  28273. };
  28274. //
  28275. Vector3.prototype.setEulerFromRotationMatrix = function () {
  28276. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28277. };
  28278. Vector3.prototype.setEulerFromQuaternion = function () {
  28279. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28280. };
  28281. Vector3.prototype.getPositionFromMatrix = function ( m ) {
  28282. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28283. return this.setFromMatrixPosition( m );
  28284. };
  28285. Vector3.prototype.getScaleFromMatrix = function ( m ) {
  28286. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28287. return this.setFromMatrixScale( m );
  28288. };
  28289. Vector3.prototype.getColumnFromMatrix = function ( index, matrix ) {
  28290. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28291. return this.setFromMatrixColumn( matrix, index );
  28292. };
  28293. Vector3.prototype.applyProjection = function ( m ) {
  28294. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28295. return this.applyMatrix4( m );
  28296. };
  28297. Vector3.prototype.fromAttribute = function ( attribute, index, offset ) {
  28298. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28299. return this.fromBufferAttribute( attribute, index, offset );
  28300. };
  28301. Vector3.prototype.distanceToManhattan = function ( v ) {
  28302. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28303. return this.manhattanDistanceTo( v );
  28304. };
  28305. Vector3.prototype.lengthManhattan = function () {
  28306. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28307. return this.manhattanLength();
  28308. };
  28309. //
  28310. Vector4.prototype.fromAttribute = function ( attribute, index, offset ) {
  28311. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28312. return this.fromBufferAttribute( attribute, index, offset );
  28313. };
  28314. Vector4.prototype.lengthManhattan = function () {
  28315. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28316. return this.manhattanLength();
  28317. };
  28318. //
  28319. Object3D.prototype.getChildByName = function ( name ) {
  28320. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28321. return this.getObjectByName( name );
  28322. };
  28323. Object3D.prototype.renderDepth = function () {
  28324. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28325. };
  28326. Object3D.prototype.translate = function ( distance, axis ) {
  28327. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28328. return this.translateOnAxis( axis, distance );
  28329. };
  28330. Object3D.prototype.getWorldRotation = function () {
  28331. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28332. };
  28333. Object3D.prototype.applyMatrix = function ( matrix ) {
  28334. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  28335. return this.applyMatrix4( matrix );
  28336. };
  28337. Object.defineProperties( Object3D.prototype, {
  28338. eulerOrder: {
  28339. get: function () {
  28340. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28341. return this.rotation.order;
  28342. },
  28343. set: function ( value ) {
  28344. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28345. this.rotation.order = value;
  28346. }
  28347. },
  28348. useQuaternion: {
  28349. get: function () {
  28350. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28351. },
  28352. set: function () {
  28353. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28354. }
  28355. }
  28356. } );
  28357. Mesh.prototype.setDrawMode = function () {
  28358. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  28359. };
  28360. Object.defineProperties( Mesh.prototype, {
  28361. drawMode: {
  28362. get: function () {
  28363. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  28364. return TrianglesDrawMode;
  28365. },
  28366. set: function () {
  28367. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  28368. }
  28369. }
  28370. } );
  28371. Object.defineProperties( LOD.prototype, {
  28372. objects: {
  28373. get: function () {
  28374. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28375. return this.levels;
  28376. }
  28377. }
  28378. } );
  28379. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28380. get: function () {
  28381. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28382. },
  28383. set: function () {
  28384. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28385. }
  28386. } );
  28387. SkinnedMesh.prototype.initBones = function () {
  28388. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28389. };
  28390. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28391. get: function () {
  28392. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28393. return this.arcLengthDivisions;
  28394. },
  28395. set: function ( value ) {
  28396. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28397. this.arcLengthDivisions = value;
  28398. }
  28399. } );
  28400. //
  28401. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28402. console.warn( 'THREE.PerspectiveCamera.setLens is deprecated. ' +
  28403. 'Use .setFocalLength and .filmGauge for a photographic setup.' );
  28404. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28405. this.setFocalLength( focalLength );
  28406. };
  28407. //
  28408. Object.defineProperties( Light.prototype, {
  28409. onlyShadow: {
  28410. set: function () {
  28411. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28412. }
  28413. },
  28414. shadowCameraFov: {
  28415. set: function ( value ) {
  28416. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28417. this.shadow.camera.fov = value;
  28418. }
  28419. },
  28420. shadowCameraLeft: {
  28421. set: function ( value ) {
  28422. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28423. this.shadow.camera.left = value;
  28424. }
  28425. },
  28426. shadowCameraRight: {
  28427. set: function ( value ) {
  28428. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28429. this.shadow.camera.right = value;
  28430. }
  28431. },
  28432. shadowCameraTop: {
  28433. set: function ( value ) {
  28434. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28435. this.shadow.camera.top = value;
  28436. }
  28437. },
  28438. shadowCameraBottom: {
  28439. set: function ( value ) {
  28440. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28441. this.shadow.camera.bottom = value;
  28442. }
  28443. },
  28444. shadowCameraNear: {
  28445. set: function ( value ) {
  28446. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28447. this.shadow.camera.near = value;
  28448. }
  28449. },
  28450. shadowCameraFar: {
  28451. set: function ( value ) {
  28452. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28453. this.shadow.camera.far = value;
  28454. }
  28455. },
  28456. shadowCameraVisible: {
  28457. set: function () {
  28458. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28459. }
  28460. },
  28461. shadowBias: {
  28462. set: function ( value ) {
  28463. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28464. this.shadow.bias = value;
  28465. }
  28466. },
  28467. shadowDarkness: {
  28468. set: function () {
  28469. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28470. }
  28471. },
  28472. shadowMapWidth: {
  28473. set: function ( value ) {
  28474. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28475. this.shadow.mapSize.width = value;
  28476. }
  28477. },
  28478. shadowMapHeight: {
  28479. set: function ( value ) {
  28480. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28481. this.shadow.mapSize.height = value;
  28482. }
  28483. }
  28484. } );
  28485. //
  28486. Object.defineProperties( BufferAttribute.prototype, {
  28487. length: {
  28488. get: function () {
  28489. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28490. return this.array.length;
  28491. }
  28492. },
  28493. dynamic: {
  28494. get: function () {
  28495. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  28496. return this.usage === DynamicDrawUsage;
  28497. },
  28498. set: function ( /* value */ ) {
  28499. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  28500. this.setUsage( DynamicDrawUsage );
  28501. }
  28502. }
  28503. } );
  28504. BufferAttribute.prototype.setDynamic = function ( value ) {
  28505. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  28506. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  28507. return this;
  28508. };
  28509. BufferAttribute.prototype.copyIndicesArray = function ( /* indices */ ) {
  28510. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28511. },
  28512. BufferAttribute.prototype.setArray = function ( /* array */ ) {
  28513. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  28514. };
  28515. //
  28516. BufferGeometry.prototype.addIndex = function ( index ) {
  28517. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28518. this.setIndex( index );
  28519. };
  28520. BufferGeometry.prototype.addAttribute = function ( name, attribute ) {
  28521. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  28522. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  28523. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  28524. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  28525. }
  28526. if ( name === 'index' ) {
  28527. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  28528. this.setIndex( attribute );
  28529. return this;
  28530. }
  28531. return this.setAttribute( name, attribute );
  28532. };
  28533. BufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset ) {
  28534. if ( indexOffset !== undefined ) {
  28535. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28536. }
  28537. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28538. this.addGroup( start, count );
  28539. };
  28540. BufferGeometry.prototype.clearDrawCalls = function () {
  28541. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28542. this.clearGroups();
  28543. };
  28544. BufferGeometry.prototype.computeOffsets = function () {
  28545. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28546. };
  28547. BufferGeometry.prototype.removeAttribute = function ( name ) {
  28548. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  28549. return this.deleteAttribute( name );
  28550. };
  28551. BufferGeometry.prototype.applyMatrix = function ( matrix ) {
  28552. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  28553. return this.applyMatrix4( matrix );
  28554. };
  28555. Object.defineProperties( BufferGeometry.prototype, {
  28556. drawcalls: {
  28557. get: function () {
  28558. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28559. return this.groups;
  28560. }
  28561. },
  28562. offsets: {
  28563. get: function () {
  28564. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28565. return this.groups;
  28566. }
  28567. }
  28568. } );
  28569. Object.defineProperties( InstancedBufferGeometry.prototype, {
  28570. maxInstancedCount: {
  28571. get: function () {
  28572. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  28573. return this.instanceCount;
  28574. },
  28575. set: function ( value ) {
  28576. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  28577. this.instanceCount = value;
  28578. }
  28579. }
  28580. } );
  28581. Object.defineProperties( Raycaster.prototype, {
  28582. linePrecision: {
  28583. get: function () {
  28584. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  28585. return this.params.Line.threshold;
  28586. },
  28587. set: function ( value ) {
  28588. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  28589. this.params.Line.threshold = value;
  28590. }
  28591. }
  28592. } );
  28593. Object.defineProperties( InterleavedBuffer.prototype, {
  28594. dynamic: {
  28595. get: function () {
  28596. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  28597. return this.usage === DynamicDrawUsage;
  28598. },
  28599. set: function ( value ) {
  28600. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  28601. this.setUsage( value );
  28602. }
  28603. }
  28604. } );
  28605. InterleavedBuffer.prototype.setDynamic = function ( value ) {
  28606. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  28607. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  28608. return this;
  28609. };
  28610. InterleavedBuffer.prototype.setArray = function ( /* array */ ) {
  28611. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  28612. };
  28613. //
  28614. ExtrudeGeometry.prototype.getArrays = function () {
  28615. console.error( 'THREE.ExtrudeGeometry: .getArrays() has been removed.' );
  28616. };
  28617. ExtrudeGeometry.prototype.addShapeList = function () {
  28618. console.error( 'THREE.ExtrudeGeometry: .addShapeList() has been removed.' );
  28619. };
  28620. ExtrudeGeometry.prototype.addShape = function () {
  28621. console.error( 'THREE.ExtrudeGeometry: .addShape() has been removed.' );
  28622. };
  28623. //
  28624. Scene.prototype.dispose = function () {
  28625. console.error( 'THREE.Scene: .dispose() has been removed.' );
  28626. };
  28627. //
  28628. Object.defineProperties( Uniform.prototype, {
  28629. dynamic: {
  28630. set: function () {
  28631. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28632. }
  28633. },
  28634. onUpdate: {
  28635. value: function () {
  28636. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28637. return this;
  28638. }
  28639. }
  28640. } );
  28641. //
  28642. Object.defineProperties( Material.prototype, {
  28643. wrapAround: {
  28644. get: function () {
  28645. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28646. },
  28647. set: function () {
  28648. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28649. }
  28650. },
  28651. overdraw: {
  28652. get: function () {
  28653. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28654. },
  28655. set: function () {
  28656. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28657. }
  28658. },
  28659. wrapRGB: {
  28660. get: function () {
  28661. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28662. return new Color();
  28663. }
  28664. },
  28665. shading: {
  28666. get: function () {
  28667. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28668. },
  28669. set: function ( value ) {
  28670. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28671. this.flatShading = ( value === FlatShading );
  28672. }
  28673. },
  28674. stencilMask: {
  28675. get: function () {
  28676. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  28677. return this.stencilFuncMask;
  28678. },
  28679. set: function ( value ) {
  28680. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  28681. this.stencilFuncMask = value;
  28682. }
  28683. }
  28684. } );
  28685. Object.defineProperties( MeshPhongMaterial.prototype, {
  28686. metal: {
  28687. get: function () {
  28688. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28689. return false;
  28690. },
  28691. set: function () {
  28692. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28693. }
  28694. }
  28695. } );
  28696. Object.defineProperties( MeshPhysicalMaterial.prototype, {
  28697. transparency: {
  28698. get: function () {
  28699. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  28700. return this.transmission;
  28701. },
  28702. set: function ( value ) {
  28703. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  28704. this.transmission = value;
  28705. }
  28706. }
  28707. } );
  28708. Object.defineProperties( ShaderMaterial.prototype, {
  28709. derivatives: {
  28710. get: function () {
  28711. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28712. return this.extensions.derivatives;
  28713. },
  28714. set: function ( value ) {
  28715. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28716. this.extensions.derivatives = value;
  28717. }
  28718. }
  28719. } );
  28720. //
  28721. WebGLRenderer.prototype.clearTarget = function ( renderTarget, color, depth, stencil ) {
  28722. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28723. this.setRenderTarget( renderTarget );
  28724. this.clear( color, depth, stencil );
  28725. };
  28726. WebGLRenderer.prototype.animate = function ( callback ) {
  28727. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28728. this.setAnimationLoop( callback );
  28729. };
  28730. WebGLRenderer.prototype.getCurrentRenderTarget = function () {
  28731. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28732. return this.getRenderTarget();
  28733. };
  28734. WebGLRenderer.prototype.getMaxAnisotropy = function () {
  28735. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28736. return this.capabilities.getMaxAnisotropy();
  28737. };
  28738. WebGLRenderer.prototype.getPrecision = function () {
  28739. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28740. return this.capabilities.precision;
  28741. };
  28742. WebGLRenderer.prototype.resetGLState = function () {
  28743. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28744. return this.state.reset();
  28745. };
  28746. WebGLRenderer.prototype.supportsFloatTextures = function () {
  28747. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28748. return this.extensions.get( 'OES_texture_float' );
  28749. };
  28750. WebGLRenderer.prototype.supportsHalfFloatTextures = function () {
  28751. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28752. return this.extensions.get( 'OES_texture_half_float' );
  28753. };
  28754. WebGLRenderer.prototype.supportsStandardDerivatives = function () {
  28755. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28756. return this.extensions.get( 'OES_standard_derivatives' );
  28757. };
  28758. WebGLRenderer.prototype.supportsCompressedTextureS3TC = function () {
  28759. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28760. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28761. };
  28762. WebGLRenderer.prototype.supportsCompressedTexturePVRTC = function () {
  28763. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28764. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28765. };
  28766. WebGLRenderer.prototype.supportsBlendMinMax = function () {
  28767. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28768. return this.extensions.get( 'EXT_blend_minmax' );
  28769. };
  28770. WebGLRenderer.prototype.supportsVertexTextures = function () {
  28771. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28772. return this.capabilities.vertexTextures;
  28773. };
  28774. WebGLRenderer.prototype.supportsInstancedArrays = function () {
  28775. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28776. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28777. };
  28778. WebGLRenderer.prototype.enableScissorTest = function ( boolean ) {
  28779. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28780. this.setScissorTest( boolean );
  28781. };
  28782. WebGLRenderer.prototype.initMaterial = function () {
  28783. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28784. };
  28785. WebGLRenderer.prototype.addPrePlugin = function () {
  28786. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28787. };
  28788. WebGLRenderer.prototype.addPostPlugin = function () {
  28789. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28790. };
  28791. WebGLRenderer.prototype.updateShadowMap = function () {
  28792. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28793. };
  28794. WebGLRenderer.prototype.setFaceCulling = function () {
  28795. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28796. };
  28797. WebGLRenderer.prototype.allocTextureUnit = function () {
  28798. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28799. };
  28800. WebGLRenderer.prototype.setTexture = function () {
  28801. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28802. };
  28803. WebGLRenderer.prototype.setTexture2D = function () {
  28804. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28805. };
  28806. WebGLRenderer.prototype.setTextureCube = function () {
  28807. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28808. };
  28809. WebGLRenderer.prototype.getActiveMipMapLevel = function () {
  28810. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  28811. return this.getActiveMipmapLevel();
  28812. };
  28813. Object.defineProperties( WebGLRenderer.prototype, {
  28814. shadowMapEnabled: {
  28815. get: function () {
  28816. return this.shadowMap.enabled;
  28817. },
  28818. set: function ( value ) {
  28819. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28820. this.shadowMap.enabled = value;
  28821. }
  28822. },
  28823. shadowMapType: {
  28824. get: function () {
  28825. return this.shadowMap.type;
  28826. },
  28827. set: function ( value ) {
  28828. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28829. this.shadowMap.type = value;
  28830. }
  28831. },
  28832. shadowMapCullFace: {
  28833. get: function () {
  28834. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28835. return undefined;
  28836. },
  28837. set: function ( /* value */ ) {
  28838. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28839. }
  28840. },
  28841. context: {
  28842. get: function () {
  28843. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  28844. return this.getContext();
  28845. }
  28846. },
  28847. vr: {
  28848. get: function () {
  28849. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  28850. return this.xr;
  28851. }
  28852. },
  28853. gammaInput: {
  28854. get: function () {
  28855. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  28856. return false;
  28857. },
  28858. set: function () {
  28859. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  28860. }
  28861. },
  28862. gammaOutput: {
  28863. get: function () {
  28864. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  28865. return false;
  28866. },
  28867. set: function ( value ) {
  28868. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  28869. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  28870. }
  28871. },
  28872. toneMappingWhitePoint: {
  28873. get: function () {
  28874. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  28875. return 1.0;
  28876. },
  28877. set: function () {
  28878. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  28879. }
  28880. },
  28881. } );
  28882. Object.defineProperties( WebGLShadowMap.prototype, {
  28883. cullFace: {
  28884. get: function () {
  28885. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28886. return undefined;
  28887. },
  28888. set: function ( /* cullFace */ ) {
  28889. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28890. }
  28891. },
  28892. renderReverseSided: {
  28893. get: function () {
  28894. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28895. return undefined;
  28896. },
  28897. set: function () {
  28898. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28899. }
  28900. },
  28901. renderSingleSided: {
  28902. get: function () {
  28903. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28904. return undefined;
  28905. },
  28906. set: function () {
  28907. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28908. }
  28909. }
  28910. } );
  28911. function WebGLRenderTargetCube( width, height, options ) {
  28912. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  28913. return new WebGLCubeRenderTarget( width, options );
  28914. }
  28915. //
  28916. Object.defineProperties( WebGLRenderTarget.prototype, {
  28917. wrapS: {
  28918. get: function () {
  28919. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28920. return this.texture.wrapS;
  28921. },
  28922. set: function ( value ) {
  28923. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28924. this.texture.wrapS = value;
  28925. }
  28926. },
  28927. wrapT: {
  28928. get: function () {
  28929. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28930. return this.texture.wrapT;
  28931. },
  28932. set: function ( value ) {
  28933. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28934. this.texture.wrapT = value;
  28935. }
  28936. },
  28937. magFilter: {
  28938. get: function () {
  28939. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28940. return this.texture.magFilter;
  28941. },
  28942. set: function ( value ) {
  28943. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28944. this.texture.magFilter = value;
  28945. }
  28946. },
  28947. minFilter: {
  28948. get: function () {
  28949. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28950. return this.texture.minFilter;
  28951. },
  28952. set: function ( value ) {
  28953. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28954. this.texture.minFilter = value;
  28955. }
  28956. },
  28957. anisotropy: {
  28958. get: function () {
  28959. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28960. return this.texture.anisotropy;
  28961. },
  28962. set: function ( value ) {
  28963. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28964. this.texture.anisotropy = value;
  28965. }
  28966. },
  28967. offset: {
  28968. get: function () {
  28969. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28970. return this.texture.offset;
  28971. },
  28972. set: function ( value ) {
  28973. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28974. this.texture.offset = value;
  28975. }
  28976. },
  28977. repeat: {
  28978. get: function () {
  28979. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28980. return this.texture.repeat;
  28981. },
  28982. set: function ( value ) {
  28983. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28984. this.texture.repeat = value;
  28985. }
  28986. },
  28987. format: {
  28988. get: function () {
  28989. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28990. return this.texture.format;
  28991. },
  28992. set: function ( value ) {
  28993. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28994. this.texture.format = value;
  28995. }
  28996. },
  28997. type: {
  28998. get: function () {
  28999. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29000. return this.texture.type;
  29001. },
  29002. set: function ( value ) {
  29003. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29004. this.texture.type = value;
  29005. }
  29006. },
  29007. generateMipmaps: {
  29008. get: function () {
  29009. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29010. return this.texture.generateMipmaps;
  29011. },
  29012. set: function ( value ) {
  29013. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29014. this.texture.generateMipmaps = value;
  29015. }
  29016. }
  29017. } );
  29018. //
  29019. Object.defineProperties( Audio.prototype, {
  29020. load: {
  29021. value: function ( file ) {
  29022. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29023. const scope = this;
  29024. const audioLoader = new AudioLoader();
  29025. audioLoader.load( file, function ( buffer ) {
  29026. scope.setBuffer( buffer );
  29027. } );
  29028. return this;
  29029. }
  29030. },
  29031. startTime: {
  29032. set: function () {
  29033. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  29034. }
  29035. }
  29036. } );
  29037. AudioAnalyser.prototype.getData = function () {
  29038. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29039. return this.getFrequencyData();
  29040. };
  29041. //
  29042. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29043. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29044. return this.update( renderer, scene );
  29045. };
  29046. CubeCamera.prototype.clear = function ( renderer, color, depth, stencil ) {
  29047. console.warn( 'THREE.CubeCamera: .clear() is now .renderTarget.clear().' );
  29048. return this.renderTarget.clear( renderer, color, depth, stencil );
  29049. };
  29050. ImageUtils.crossOrigin = undefined;
  29051. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29052. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29053. const loader = new TextureLoader();
  29054. loader.setCrossOrigin( this.crossOrigin );
  29055. const texture = loader.load( url, onLoad, undefined, onError );
  29056. if ( mapping ) texture.mapping = mapping;
  29057. return texture;
  29058. };
  29059. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29060. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29061. const loader = new CubeTextureLoader();
  29062. loader.setCrossOrigin( this.crossOrigin );
  29063. const texture = loader.load( urls, onLoad, undefined, onError );
  29064. if ( mapping ) texture.mapping = mapping;
  29065. return texture;
  29066. };
  29067. ImageUtils.loadCompressedTexture = function () {
  29068. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29069. };
  29070. ImageUtils.loadCompressedTextureCube = function () {
  29071. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29072. };
  29073. //
  29074. function CanvasRenderer() {
  29075. console.error( 'THREE.CanvasRenderer has been removed' );
  29076. }
  29077. //
  29078. function JSONLoader() {
  29079. console.error( 'THREE.JSONLoader has been removed.' );
  29080. }
  29081. //
  29082. const SceneUtils = {
  29083. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29084. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29085. },
  29086. detach: function ( /* child, parent, scene */ ) {
  29087. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29088. },
  29089. attach: function ( /* child, scene, parent */ ) {
  29090. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  29091. }
  29092. };
  29093. //
  29094. function LensFlare() {
  29095. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  29096. }
  29097. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  29098. /* eslint-disable no-undef */
  29099. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  29100. revision: REVISION,
  29101. } } ) );
  29102. /* eslint-enable no-undef */
  29103. }
  29104. if ( typeof window !== 'undefined' ) {
  29105. if ( window.__THREE__ ) {
  29106. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  29107. } else {
  29108. window.__THREE__ = REVISION;
  29109. }
  29110. }
  29111. 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, WebGLMultisampleRenderTarget, WebGLRenderTarget, WebGLRenderTargetCube, WebGLRenderer, WebGLUtils, WireframeGeometry, WireframeHelper, WrapAroundEnding, XHRLoader, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, sRGBEncoding };