three.module.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831
  1. // threejs.org/license
  2. const REVISION = '125dev';
  3. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  4. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  5. const CullFaceNone = 0;
  6. const CullFaceBack = 1;
  7. const CullFaceFront = 2;
  8. const CullFaceFrontBack = 3;
  9. const BasicShadowMap = 0;
  10. const PCFShadowMap = 1;
  11. const PCFSoftShadowMap = 2;
  12. const VSMShadowMap = 3;
  13. const FrontSide = 0;
  14. const BackSide = 1;
  15. const DoubleSide = 2;
  16. const FlatShading = 1;
  17. const SmoothShading = 2;
  18. const NoBlending = 0;
  19. const NormalBlending = 1;
  20. const AdditiveBlending = 2;
  21. const SubtractiveBlending = 3;
  22. const MultiplyBlending = 4;
  23. const CustomBlending = 5;
  24. const AddEquation = 100;
  25. const SubtractEquation = 101;
  26. const ReverseSubtractEquation = 102;
  27. const MinEquation = 103;
  28. const MaxEquation = 104;
  29. const ZeroFactor = 200;
  30. const OneFactor = 201;
  31. const SrcColorFactor = 202;
  32. const OneMinusSrcColorFactor = 203;
  33. const SrcAlphaFactor = 204;
  34. const OneMinusSrcAlphaFactor = 205;
  35. const DstAlphaFactor = 206;
  36. const OneMinusDstAlphaFactor = 207;
  37. const DstColorFactor = 208;
  38. const OneMinusDstColorFactor = 209;
  39. const SrcAlphaSaturateFactor = 210;
  40. const NeverDepth = 0;
  41. const AlwaysDepth = 1;
  42. const LessDepth = 2;
  43. const LessEqualDepth = 3;
  44. const EqualDepth = 4;
  45. const GreaterEqualDepth = 5;
  46. const GreaterDepth = 6;
  47. const NotEqualDepth = 7;
  48. const MultiplyOperation = 0;
  49. const MixOperation = 1;
  50. const AddOperation = 2;
  51. const NoToneMapping = 0;
  52. const LinearToneMapping = 1;
  53. const ReinhardToneMapping = 2;
  54. const CineonToneMapping = 3;
  55. const ACESFilmicToneMapping = 4;
  56. const CustomToneMapping = 5;
  57. const UVMapping = 300;
  58. const CubeReflectionMapping = 301;
  59. const CubeRefractionMapping = 302;
  60. const EquirectangularReflectionMapping = 303;
  61. const EquirectangularRefractionMapping = 304;
  62. const CubeUVReflectionMapping = 306;
  63. const CubeUVRefractionMapping = 307;
  64. const RepeatWrapping = 1000;
  65. const ClampToEdgeWrapping = 1001;
  66. const MirroredRepeatWrapping = 1002;
  67. const NearestFilter = 1003;
  68. const NearestMipmapNearestFilter = 1004;
  69. const NearestMipMapNearestFilter = 1004;
  70. const NearestMipmapLinearFilter = 1005;
  71. const NearestMipMapLinearFilter = 1005;
  72. const LinearFilter = 1006;
  73. const LinearMipmapNearestFilter = 1007;
  74. const LinearMipMapNearestFilter = 1007;
  75. const LinearMipmapLinearFilter = 1008;
  76. const LinearMipMapLinearFilter = 1008;
  77. const UnsignedByteType = 1009;
  78. const ByteType = 1010;
  79. const ShortType = 1011;
  80. const UnsignedShortType = 1012;
  81. const IntType = 1013;
  82. const UnsignedIntType = 1014;
  83. const FloatType = 1015;
  84. const HalfFloatType = 1016;
  85. const UnsignedShort4444Type = 1017;
  86. const UnsignedShort5551Type = 1018;
  87. const UnsignedShort565Type = 1019;
  88. const UnsignedInt248Type = 1020;
  89. const AlphaFormat = 1021;
  90. const RGBFormat = 1022;
  91. const RGBAFormat = 1023;
  92. const LuminanceFormat = 1024;
  93. const LuminanceAlphaFormat = 1025;
  94. const RGBEFormat = RGBAFormat;
  95. const DepthFormat = 1026;
  96. const DepthStencilFormat = 1027;
  97. const RedFormat = 1028;
  98. const RedIntegerFormat = 1029;
  99. const RGFormat = 1030;
  100. const RGIntegerFormat = 1031;
  101. const RGBIntegerFormat = 1032;
  102. const RGBAIntegerFormat = 1033;
  103. const RGB_S3TC_DXT1_Format = 33776;
  104. const RGBA_S3TC_DXT1_Format = 33777;
  105. const RGBA_S3TC_DXT3_Format = 33778;
  106. const RGBA_S3TC_DXT5_Format = 33779;
  107. const RGB_PVRTC_4BPPV1_Format = 35840;
  108. const RGB_PVRTC_2BPPV1_Format = 35841;
  109. const RGBA_PVRTC_4BPPV1_Format = 35842;
  110. const RGBA_PVRTC_2BPPV1_Format = 35843;
  111. const RGB_ETC1_Format = 36196;
  112. const RGB_ETC2_Format = 37492;
  113. const RGBA_ETC2_EAC_Format = 37496;
  114. const RGBA_ASTC_4x4_Format = 37808;
  115. const RGBA_ASTC_5x4_Format = 37809;
  116. const RGBA_ASTC_5x5_Format = 37810;
  117. const RGBA_ASTC_6x5_Format = 37811;
  118. const RGBA_ASTC_6x6_Format = 37812;
  119. const RGBA_ASTC_8x5_Format = 37813;
  120. const RGBA_ASTC_8x6_Format = 37814;
  121. const RGBA_ASTC_8x8_Format = 37815;
  122. const RGBA_ASTC_10x5_Format = 37816;
  123. const RGBA_ASTC_10x6_Format = 37817;
  124. const RGBA_ASTC_10x8_Format = 37818;
  125. const RGBA_ASTC_10x10_Format = 37819;
  126. const RGBA_ASTC_12x10_Format = 37820;
  127. const RGBA_ASTC_12x12_Format = 37821;
  128. const RGBA_BPTC_Format = 36492;
  129. const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  130. const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  131. const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  132. const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  133. const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  134. const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  135. const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  136. const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  137. const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  138. const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  139. const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  140. const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  141. const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  142. const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  143. const LoopOnce = 2200;
  144. const LoopRepeat = 2201;
  145. const LoopPingPong = 2202;
  146. const InterpolateDiscrete = 2300;
  147. const InterpolateLinear = 2301;
  148. const InterpolateSmooth = 2302;
  149. const ZeroCurvatureEnding = 2400;
  150. const ZeroSlopeEnding = 2401;
  151. const WrapAroundEnding = 2402;
  152. const NormalAnimationBlendMode = 2500;
  153. const AdditiveAnimationBlendMode = 2501;
  154. const TrianglesDrawMode = 0;
  155. const TriangleStripDrawMode = 1;
  156. const TriangleFanDrawMode = 2;
  157. const LinearEncoding = 3000;
  158. const sRGBEncoding = 3001;
  159. const GammaEncoding = 3007;
  160. const RGBEEncoding = 3002;
  161. const LogLuvEncoding = 3003;
  162. const RGBM7Encoding = 3004;
  163. const RGBM16Encoding = 3005;
  164. const RGBDEncoding = 3006;
  165. const BasicDepthPacking = 3200;
  166. const RGBADepthPacking = 3201;
  167. const TangentSpaceNormalMap = 0;
  168. const ObjectSpaceNormalMap = 1;
  169. const ZeroStencilOp = 0;
  170. const KeepStencilOp = 7680;
  171. const ReplaceStencilOp = 7681;
  172. const IncrementStencilOp = 7682;
  173. const DecrementStencilOp = 7683;
  174. const IncrementWrapStencilOp = 34055;
  175. const DecrementWrapStencilOp = 34056;
  176. const InvertStencilOp = 5386;
  177. const NeverStencilFunc = 512;
  178. const LessStencilFunc = 513;
  179. const EqualStencilFunc = 514;
  180. const LessEqualStencilFunc = 515;
  181. const GreaterStencilFunc = 516;
  182. const NotEqualStencilFunc = 517;
  183. const GreaterEqualStencilFunc = 518;
  184. const AlwaysStencilFunc = 519;
  185. const StaticDrawUsage = 35044;
  186. const DynamicDrawUsage = 35048;
  187. const StreamDrawUsage = 35040;
  188. const StaticReadUsage = 35045;
  189. const DynamicReadUsage = 35049;
  190. const StreamReadUsage = 35041;
  191. const StaticCopyUsage = 35046;
  192. const DynamicCopyUsage = 35050;
  193. const StreamCopyUsage = 35042;
  194. const GLSL1 = '100';
  195. const GLSL3 = '300 es';
  196. /**
  197. * https://github.com/mrdoob/eventdispatcher.js/
  198. */
  199. function EventDispatcher() {}
  200. Object.assign( EventDispatcher.prototype, {
  201. addEventListener: function ( type, listener ) {
  202. if ( this._listeners === undefined ) this._listeners = {};
  203. const listeners = this._listeners;
  204. if ( listeners[ type ] === undefined ) {
  205. listeners[ type ] = [];
  206. }
  207. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  208. listeners[ type ].push( listener );
  209. }
  210. },
  211. hasEventListener: function ( type, listener ) {
  212. if ( this._listeners === undefined ) return false;
  213. const listeners = this._listeners;
  214. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  215. },
  216. removeEventListener: function ( type, listener ) {
  217. if ( this._listeners === undefined ) return;
  218. const listeners = this._listeners;
  219. const listenerArray = listeners[ type ];
  220. if ( listenerArray !== undefined ) {
  221. const index = listenerArray.indexOf( listener );
  222. if ( index !== - 1 ) {
  223. listenerArray.splice( index, 1 );
  224. }
  225. }
  226. },
  227. dispatchEvent: function ( event ) {
  228. if ( this._listeners === undefined ) return;
  229. const listeners = this._listeners;
  230. const listenerArray = listeners[ event.type ];
  231. if ( listenerArray !== undefined ) {
  232. event.target = this;
  233. // Make a copy, in case listeners are removed while iterating.
  234. const array = listenerArray.slice( 0 );
  235. for ( let i = 0, l = array.length; i < l; i ++ ) {
  236. array[ i ].call( this, event );
  237. }
  238. }
  239. }
  240. } );
  241. const _lut = [];
  242. for ( let i = 0; i < 256; i ++ ) {
  243. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  244. }
  245. let _seed = 1234567;
  246. const MathUtils = {
  247. DEG2RAD: Math.PI / 180,
  248. RAD2DEG: 180 / Math.PI,
  249. generateUUID: function () {
  250. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  251. const d0 = Math.random() * 0xffffffff | 0;
  252. const d1 = Math.random() * 0xffffffff | 0;
  253. const d2 = Math.random() * 0xffffffff | 0;
  254. const d3 = Math.random() * 0xffffffff | 0;
  255. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  256. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  257. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  258. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  259. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  260. return uuid.toUpperCase();
  261. },
  262. clamp: function ( value, min, max ) {
  263. return Math.max( min, Math.min( max, value ) );
  264. },
  265. // compute euclidian modulo of m % n
  266. // https://en.wikipedia.org/wiki/Modulo_operation
  267. euclideanModulo: function ( n, m ) {
  268. return ( ( n % m ) + m ) % m;
  269. },
  270. // Linear mapping from range <a1, a2> to range <b1, b2>
  271. mapLinear: function ( x, a1, a2, b1, b2 ) {
  272. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  273. },
  274. // https://en.wikipedia.org/wiki/Linear_interpolation
  275. lerp: function ( x, y, t ) {
  276. return ( 1 - t ) * x + t * y;
  277. },
  278. // http://en.wikipedia.org/wiki/Smoothstep
  279. smoothstep: function ( x, min, max ) {
  280. if ( x <= min ) return 0;
  281. if ( x >= max ) return 1;
  282. x = ( x - min ) / ( max - min );
  283. return x * x * ( 3 - 2 * x );
  284. },
  285. smootherstep: function ( x, min, max ) {
  286. if ( x <= min ) return 0;
  287. if ( x >= max ) return 1;
  288. x = ( x - min ) / ( max - min );
  289. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  290. },
  291. // Random integer from <low, high> interval
  292. randInt: function ( low, high ) {
  293. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  294. },
  295. // Random float from <low, high> interval
  296. randFloat: function ( low, high ) {
  297. return low + Math.random() * ( high - low );
  298. },
  299. // Random float from <-range/2, range/2> interval
  300. randFloatSpread: function ( range ) {
  301. return range * ( 0.5 - Math.random() );
  302. },
  303. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  304. seededRandom: function ( s ) {
  305. if ( s !== undefined ) _seed = s % 2147483647;
  306. // Park-Miller algorithm
  307. _seed = _seed * 16807 % 2147483647;
  308. return ( _seed - 1 ) / 2147483646;
  309. },
  310. degToRad: function ( degrees ) {
  311. return degrees * MathUtils.DEG2RAD;
  312. },
  313. radToDeg: function ( radians ) {
  314. return radians * MathUtils.RAD2DEG;
  315. },
  316. isPowerOfTwo: function ( value ) {
  317. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  318. },
  319. ceilPowerOfTwo: function ( value ) {
  320. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  321. },
  322. floorPowerOfTwo: function ( value ) {
  323. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  324. },
  325. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  326. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  327. // rotations are applied to the axes in the order specified by 'order'
  328. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  329. // angles are in radians
  330. const cos = Math.cos;
  331. const sin = Math.sin;
  332. const c2 = cos( b / 2 );
  333. const s2 = sin( b / 2 );
  334. const c13 = cos( ( a + c ) / 2 );
  335. const s13 = sin( ( a + c ) / 2 );
  336. const c1_3 = cos( ( a - c ) / 2 );
  337. const s1_3 = sin( ( a - c ) / 2 );
  338. const c3_1 = cos( ( c - a ) / 2 );
  339. const s3_1 = sin( ( c - a ) / 2 );
  340. switch ( order ) {
  341. case 'XYX':
  342. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  343. break;
  344. case 'YZY':
  345. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  346. break;
  347. case 'ZXZ':
  348. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  349. break;
  350. case 'XZX':
  351. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  352. break;
  353. case 'YXY':
  354. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  355. break;
  356. case 'ZYZ':
  357. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  358. break;
  359. default:
  360. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  361. }
  362. }
  363. };
  364. class Vector2 {
  365. constructor( x = 0, y = 0 ) {
  366. Object.defineProperty( this, 'isVector2', { value: true } );
  367. this.x = x;
  368. this.y = y;
  369. }
  370. get width() {
  371. return this.x;
  372. }
  373. set width( value ) {
  374. this.x = value;
  375. }
  376. get height() {
  377. return this.y;
  378. }
  379. set height( value ) {
  380. this.y = value;
  381. }
  382. set( x, y ) {
  383. this.x = x;
  384. this.y = y;
  385. return this;
  386. }
  387. setScalar( scalar ) {
  388. this.x = scalar;
  389. this.y = scalar;
  390. return this;
  391. }
  392. setX( x ) {
  393. this.x = x;
  394. return this;
  395. }
  396. setY( y ) {
  397. this.y = y;
  398. return this;
  399. }
  400. setComponent( index, value ) {
  401. switch ( index ) {
  402. case 0: this.x = value; break;
  403. case 1: this.y = value; break;
  404. default: throw new Error( 'index is out of range: ' + index );
  405. }
  406. return this;
  407. }
  408. getComponent( index ) {
  409. switch ( index ) {
  410. case 0: return this.x;
  411. case 1: return this.y;
  412. default: throw new Error( 'index is out of range: ' + index );
  413. }
  414. }
  415. clone() {
  416. return new this.constructor( this.x, this.y );
  417. }
  418. copy( v ) {
  419. this.x = v.x;
  420. this.y = v.y;
  421. return this;
  422. }
  423. add( v, w ) {
  424. if ( w !== undefined ) {
  425. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  426. return this.addVectors( v, w );
  427. }
  428. this.x += v.x;
  429. this.y += v.y;
  430. return this;
  431. }
  432. addScalar( s ) {
  433. this.x += s;
  434. this.y += s;
  435. return this;
  436. }
  437. addVectors( a, b ) {
  438. this.x = a.x + b.x;
  439. this.y = a.y + b.y;
  440. return this;
  441. }
  442. addScaledVector( v, s ) {
  443. this.x += v.x * s;
  444. this.y += v.y * s;
  445. return this;
  446. }
  447. sub( v, w ) {
  448. if ( w !== undefined ) {
  449. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  450. return this.subVectors( v, w );
  451. }
  452. this.x -= v.x;
  453. this.y -= v.y;
  454. return this;
  455. }
  456. subScalar( s ) {
  457. this.x -= s;
  458. this.y -= s;
  459. return this;
  460. }
  461. subVectors( a, b ) {
  462. this.x = a.x - b.x;
  463. this.y = a.y - b.y;
  464. return this;
  465. }
  466. multiply( v ) {
  467. this.x *= v.x;
  468. this.y *= v.y;
  469. return this;
  470. }
  471. multiplyScalar( scalar ) {
  472. this.x *= scalar;
  473. this.y *= scalar;
  474. return this;
  475. }
  476. divide( v ) {
  477. this.x /= v.x;
  478. this.y /= v.y;
  479. return this;
  480. }
  481. divideScalar( scalar ) {
  482. return this.multiplyScalar( 1 / scalar );
  483. }
  484. applyMatrix3( m ) {
  485. const x = this.x, y = this.y;
  486. const e = m.elements;
  487. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  488. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  489. return this;
  490. }
  491. min( v ) {
  492. this.x = Math.min( this.x, v.x );
  493. this.y = Math.min( this.y, v.y );
  494. return this;
  495. }
  496. max( v ) {
  497. this.x = Math.max( this.x, v.x );
  498. this.y = Math.max( this.y, v.y );
  499. return this;
  500. }
  501. clamp( min, max ) {
  502. // assumes min < max, componentwise
  503. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  504. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  505. return this;
  506. }
  507. clampScalar( minVal, maxVal ) {
  508. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  509. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  510. return this;
  511. }
  512. clampLength( min, max ) {
  513. const length = this.length();
  514. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  515. }
  516. floor() {
  517. this.x = Math.floor( this.x );
  518. this.y = Math.floor( this.y );
  519. return this;
  520. }
  521. ceil() {
  522. this.x = Math.ceil( this.x );
  523. this.y = Math.ceil( this.y );
  524. return this;
  525. }
  526. round() {
  527. this.x = Math.round( this.x );
  528. this.y = Math.round( this.y );
  529. return this;
  530. }
  531. roundToZero() {
  532. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  533. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  534. return this;
  535. }
  536. negate() {
  537. this.x = - this.x;
  538. this.y = - this.y;
  539. return this;
  540. }
  541. dot( v ) {
  542. return this.x * v.x + this.y * v.y;
  543. }
  544. cross( v ) {
  545. return this.x * v.y - this.y * v.x;
  546. }
  547. lengthSq() {
  548. return this.x * this.x + this.y * this.y;
  549. }
  550. length() {
  551. return Math.sqrt( this.x * this.x + this.y * this.y );
  552. }
  553. manhattanLength() {
  554. return Math.abs( this.x ) + Math.abs( this.y );
  555. }
  556. normalize() {
  557. return this.divideScalar( this.length() || 1 );
  558. }
  559. angle() {
  560. // computes the angle in radians with respect to the positive x-axis
  561. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  562. return angle;
  563. }
  564. distanceTo( v ) {
  565. return Math.sqrt( this.distanceToSquared( v ) );
  566. }
  567. distanceToSquared( v ) {
  568. const dx = this.x - v.x, dy = this.y - v.y;
  569. return dx * dx + dy * dy;
  570. }
  571. manhattanDistanceTo( v ) {
  572. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  573. }
  574. setLength( length ) {
  575. return this.normalize().multiplyScalar( length );
  576. }
  577. lerp( v, alpha ) {
  578. this.x += ( v.x - this.x ) * alpha;
  579. this.y += ( v.y - this.y ) * alpha;
  580. return this;
  581. }
  582. lerpVectors( v1, v2, alpha ) {
  583. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  584. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  585. return this;
  586. }
  587. equals( v ) {
  588. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  589. }
  590. fromArray( array, offset = 0 ) {
  591. this.x = array[ offset ];
  592. this.y = array[ offset + 1 ];
  593. return this;
  594. }
  595. toArray( array = [], offset = 0 ) {
  596. array[ offset ] = this.x;
  597. array[ offset + 1 ] = this.y;
  598. return array;
  599. }
  600. fromBufferAttribute( attribute, index, offset ) {
  601. if ( offset !== undefined ) {
  602. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  603. }
  604. this.x = attribute.getX( index );
  605. this.y = attribute.getY( index );
  606. return this;
  607. }
  608. rotateAround( center, angle ) {
  609. const c = Math.cos( angle ), s = Math.sin( angle );
  610. const x = this.x - center.x;
  611. const y = this.y - center.y;
  612. this.x = x * c - y * s + center.x;
  613. this.y = x * s + y * c + center.y;
  614. return this;
  615. }
  616. random() {
  617. this.x = Math.random();
  618. this.y = Math.random();
  619. return this;
  620. }
  621. }
  622. class Matrix3 {
  623. constructor() {
  624. Object.defineProperty( this, 'isMatrix3', { value: true } );
  625. this.elements = [
  626. 1, 0, 0,
  627. 0, 1, 0,
  628. 0, 0, 1
  629. ];
  630. if ( arguments.length > 0 ) {
  631. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  632. }
  633. }
  634. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  635. const te = this.elements;
  636. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  637. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  638. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  639. return this;
  640. }
  641. identity() {
  642. this.set(
  643. 1, 0, 0,
  644. 0, 1, 0,
  645. 0, 0, 1
  646. );
  647. return this;
  648. }
  649. clone() {
  650. return new this.constructor().fromArray( this.elements );
  651. }
  652. copy( m ) {
  653. const te = this.elements;
  654. const me = m.elements;
  655. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  656. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  657. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  658. return this;
  659. }
  660. extractBasis( xAxis, yAxis, zAxis ) {
  661. xAxis.setFromMatrix3Column( this, 0 );
  662. yAxis.setFromMatrix3Column( this, 1 );
  663. zAxis.setFromMatrix3Column( this, 2 );
  664. return this;
  665. }
  666. setFromMatrix4( m ) {
  667. const me = m.elements;
  668. this.set(
  669. me[ 0 ], me[ 4 ], me[ 8 ],
  670. me[ 1 ], me[ 5 ], me[ 9 ],
  671. me[ 2 ], me[ 6 ], me[ 10 ]
  672. );
  673. return this;
  674. }
  675. multiply( m ) {
  676. return this.multiplyMatrices( this, m );
  677. }
  678. premultiply( m ) {
  679. return this.multiplyMatrices( m, this );
  680. }
  681. multiplyMatrices( a, b ) {
  682. const ae = a.elements;
  683. const be = b.elements;
  684. const te = this.elements;
  685. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  686. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  687. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  688. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  689. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  690. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  691. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  692. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  693. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  694. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  695. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  696. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  697. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  698. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  699. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  700. return this;
  701. }
  702. multiplyScalar( s ) {
  703. const te = this.elements;
  704. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  705. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  706. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  707. return this;
  708. }
  709. determinant() {
  710. const te = this.elements;
  711. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  712. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  713. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  714. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  715. }
  716. invert() {
  717. const te = this.elements,
  718. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  719. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  720. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  721. t11 = n33 * n22 - n32 * n23,
  722. t12 = n32 * n13 - n33 * n12,
  723. t13 = n23 * n12 - n22 * n13,
  724. det = n11 * t11 + n21 * t12 + n31 * t13;
  725. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  726. const detInv = 1 / det;
  727. te[ 0 ] = t11 * detInv;
  728. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  729. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  730. te[ 3 ] = t12 * detInv;
  731. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  732. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  733. te[ 6 ] = t13 * detInv;
  734. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  735. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  736. return this;
  737. }
  738. transpose() {
  739. let tmp;
  740. const m = this.elements;
  741. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  742. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  743. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  744. return this;
  745. }
  746. getNormalMatrix( matrix4 ) {
  747. return this.setFromMatrix4( matrix4 ).copy( this ).invert().transpose();
  748. }
  749. transposeIntoArray( r ) {
  750. const m = this.elements;
  751. r[ 0 ] = m[ 0 ];
  752. r[ 1 ] = m[ 3 ];
  753. r[ 2 ] = m[ 6 ];
  754. r[ 3 ] = m[ 1 ];
  755. r[ 4 ] = m[ 4 ];
  756. r[ 5 ] = m[ 7 ];
  757. r[ 6 ] = m[ 2 ];
  758. r[ 7 ] = m[ 5 ];
  759. r[ 8 ] = m[ 8 ];
  760. return this;
  761. }
  762. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  763. const c = Math.cos( rotation );
  764. const s = Math.sin( rotation );
  765. this.set(
  766. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  767. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  768. 0, 0, 1
  769. );
  770. return this;
  771. }
  772. scale( sx, sy ) {
  773. const te = this.elements;
  774. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  775. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  776. return this;
  777. }
  778. rotate( theta ) {
  779. const c = Math.cos( theta );
  780. const s = Math.sin( theta );
  781. const te = this.elements;
  782. const a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  783. const a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  784. te[ 0 ] = c * a11 + s * a21;
  785. te[ 3 ] = c * a12 + s * a22;
  786. te[ 6 ] = c * a13 + s * a23;
  787. te[ 1 ] = - s * a11 + c * a21;
  788. te[ 4 ] = - s * a12 + c * a22;
  789. te[ 7 ] = - s * a13 + c * a23;
  790. return this;
  791. }
  792. translate( tx, ty ) {
  793. const te = this.elements;
  794. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  795. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  796. return this;
  797. }
  798. equals( matrix ) {
  799. const te = this.elements;
  800. const me = matrix.elements;
  801. for ( let i = 0; i < 9; i ++ ) {
  802. if ( te[ i ] !== me[ i ] ) return false;
  803. }
  804. return true;
  805. }
  806. fromArray( array, offset = 0 ) {
  807. for ( let i = 0; i < 9; i ++ ) {
  808. this.elements[ i ] = array[ i + offset ];
  809. }
  810. return this;
  811. }
  812. toArray( array = [], offset = 0 ) {
  813. const te = this.elements;
  814. array[ offset ] = te[ 0 ];
  815. array[ offset + 1 ] = te[ 1 ];
  816. array[ offset + 2 ] = te[ 2 ];
  817. array[ offset + 3 ] = te[ 3 ];
  818. array[ offset + 4 ] = te[ 4 ];
  819. array[ offset + 5 ] = te[ 5 ];
  820. array[ offset + 6 ] = te[ 6 ];
  821. array[ offset + 7 ] = te[ 7 ];
  822. array[ offset + 8 ] = te[ 8 ];
  823. return array;
  824. }
  825. }
  826. let _canvas;
  827. const ImageUtils = {
  828. getDataURL: function ( image ) {
  829. if ( /^data:/i.test( image.src ) ) {
  830. return image.src;
  831. }
  832. if ( typeof HTMLCanvasElement == 'undefined' ) {
  833. return image.src;
  834. }
  835. let canvas;
  836. if ( image instanceof HTMLCanvasElement ) {
  837. canvas = image;
  838. } else {
  839. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  840. _canvas.width = image.width;
  841. _canvas.height = image.height;
  842. const context = _canvas.getContext( '2d' );
  843. if ( image instanceof ImageData ) {
  844. context.putImageData( image, 0, 0 );
  845. } else {
  846. context.drawImage( image, 0, 0, image.width, image.height );
  847. }
  848. canvas = _canvas;
  849. }
  850. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  851. return canvas.toDataURL( 'image/jpeg', 0.6 );
  852. } else {
  853. return canvas.toDataURL( 'image/png' );
  854. }
  855. }
  856. };
  857. let textureId = 0;
  858. function Texture( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1, encoding = LinearEncoding ) {
  859. Object.defineProperty( this, 'id', { value: textureId ++ } );
  860. this.uuid = MathUtils.generateUUID();
  861. this.name = '';
  862. this.image = image;
  863. this.mipmaps = [];
  864. this.mapping = mapping;
  865. this.wrapS = wrapS;
  866. this.wrapT = wrapT;
  867. this.magFilter = magFilter;
  868. this.minFilter = minFilter;
  869. this.anisotropy = anisotropy;
  870. this.format = format;
  871. this.internalFormat = null;
  872. this.type = type;
  873. this.offset = new Vector2( 0, 0 );
  874. this.repeat = new Vector2( 1, 1 );
  875. this.center = new Vector2( 0, 0 );
  876. this.rotation = 0;
  877. this.matrixAutoUpdate = true;
  878. this.matrix = new Matrix3();
  879. this.generateMipmaps = true;
  880. this.premultiplyAlpha = false;
  881. this.flipY = true;
  882. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  883. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  884. //
  885. // Also changing the encoding after already used by a Material will not automatically make the Material
  886. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  887. this.encoding = encoding;
  888. this.version = 0;
  889. this.onUpdate = null;
  890. }
  891. Texture.DEFAULT_IMAGE = undefined;
  892. Texture.DEFAULT_MAPPING = UVMapping;
  893. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  894. constructor: Texture,
  895. isTexture: true,
  896. updateMatrix: function () {
  897. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  898. },
  899. clone: function () {
  900. return new this.constructor().copy( this );
  901. },
  902. copy: function ( source ) {
  903. this.name = source.name;
  904. this.image = source.image;
  905. this.mipmaps = source.mipmaps.slice( 0 );
  906. this.mapping = source.mapping;
  907. this.wrapS = source.wrapS;
  908. this.wrapT = source.wrapT;
  909. this.magFilter = source.magFilter;
  910. this.minFilter = source.minFilter;
  911. this.anisotropy = source.anisotropy;
  912. this.format = source.format;
  913. this.internalFormat = source.internalFormat;
  914. this.type = source.type;
  915. this.offset.copy( source.offset );
  916. this.repeat.copy( source.repeat );
  917. this.center.copy( source.center );
  918. this.rotation = source.rotation;
  919. this.matrixAutoUpdate = source.matrixAutoUpdate;
  920. this.matrix.copy( source.matrix );
  921. this.generateMipmaps = source.generateMipmaps;
  922. this.premultiplyAlpha = source.premultiplyAlpha;
  923. this.flipY = source.flipY;
  924. this.unpackAlignment = source.unpackAlignment;
  925. this.encoding = source.encoding;
  926. return this;
  927. },
  928. toJSON: function ( meta ) {
  929. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  930. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  931. return meta.textures[ this.uuid ];
  932. }
  933. const output = {
  934. metadata: {
  935. version: 4.5,
  936. type: 'Texture',
  937. generator: 'Texture.toJSON'
  938. },
  939. uuid: this.uuid,
  940. name: this.name,
  941. mapping: this.mapping,
  942. repeat: [ this.repeat.x, this.repeat.y ],
  943. offset: [ this.offset.x, this.offset.y ],
  944. center: [ this.center.x, this.center.y ],
  945. rotation: this.rotation,
  946. wrap: [ this.wrapS, this.wrapT ],
  947. format: this.format,
  948. type: this.type,
  949. encoding: this.encoding,
  950. minFilter: this.minFilter,
  951. magFilter: this.magFilter,
  952. anisotropy: this.anisotropy,
  953. flipY: this.flipY,
  954. premultiplyAlpha: this.premultiplyAlpha,
  955. unpackAlignment: this.unpackAlignment
  956. };
  957. if ( this.image !== undefined ) {
  958. // TODO: Move to THREE.Image
  959. const image = this.image;
  960. if ( image.uuid === undefined ) {
  961. image.uuid = MathUtils.generateUUID(); // UGH
  962. }
  963. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  964. let url;
  965. if ( Array.isArray( image ) ) {
  966. // process array of images e.g. CubeTexture
  967. url = [];
  968. for ( let i = 0, l = image.length; i < l; i ++ ) {
  969. // check cube texture with data textures
  970. if ( image[ i ].isDataTexture ) {
  971. url.push( serializeImage( image[ i ].image ) );
  972. } else {
  973. url.push( serializeImage( image[ i ] ) );
  974. }
  975. }
  976. } else {
  977. // process single image
  978. url = serializeImage( image );
  979. }
  980. meta.images[ image.uuid ] = {
  981. uuid: image.uuid,
  982. url: url
  983. };
  984. }
  985. output.image = image.uuid;
  986. }
  987. if ( ! isRootObject ) {
  988. meta.textures[ this.uuid ] = output;
  989. }
  990. return output;
  991. },
  992. dispose: function () {
  993. this.dispatchEvent( { type: 'dispose' } );
  994. },
  995. transformUv: function ( uv ) {
  996. if ( this.mapping !== UVMapping ) return uv;
  997. uv.applyMatrix3( this.matrix );
  998. if ( uv.x < 0 || uv.x > 1 ) {
  999. switch ( this.wrapS ) {
  1000. case RepeatWrapping:
  1001. uv.x = uv.x - Math.floor( uv.x );
  1002. break;
  1003. case ClampToEdgeWrapping:
  1004. uv.x = uv.x < 0 ? 0 : 1;
  1005. break;
  1006. case MirroredRepeatWrapping:
  1007. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1008. uv.x = Math.ceil( uv.x ) - uv.x;
  1009. } else {
  1010. uv.x = uv.x - Math.floor( uv.x );
  1011. }
  1012. break;
  1013. }
  1014. }
  1015. if ( uv.y < 0 || uv.y > 1 ) {
  1016. switch ( this.wrapT ) {
  1017. case RepeatWrapping:
  1018. uv.y = uv.y - Math.floor( uv.y );
  1019. break;
  1020. case ClampToEdgeWrapping:
  1021. uv.y = uv.y < 0 ? 0 : 1;
  1022. break;
  1023. case MirroredRepeatWrapping:
  1024. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1025. uv.y = Math.ceil( uv.y ) - uv.y;
  1026. } else {
  1027. uv.y = uv.y - Math.floor( uv.y );
  1028. }
  1029. break;
  1030. }
  1031. }
  1032. if ( this.flipY ) {
  1033. uv.y = 1 - uv.y;
  1034. }
  1035. return uv;
  1036. }
  1037. } );
  1038. Object.defineProperty( Texture.prototype, 'needsUpdate', {
  1039. set: function ( value ) {
  1040. if ( value === true ) this.version ++;
  1041. }
  1042. } );
  1043. function serializeImage( image ) {
  1044. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1045. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1046. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1047. // default images
  1048. return ImageUtils.getDataURL( image );
  1049. } else {
  1050. if ( image.data ) {
  1051. // images of DataTexture
  1052. return {
  1053. data: Array.prototype.slice.call( image.data ),
  1054. width: image.width,
  1055. height: image.height,
  1056. type: image.data.constructor.name
  1057. };
  1058. } else {
  1059. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1060. return {};
  1061. }
  1062. }
  1063. }
  1064. class Vector4 {
  1065. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1066. Object.defineProperty( this, 'isVector4', { value: true } );
  1067. this.x = x;
  1068. this.y = y;
  1069. this.z = z;
  1070. this.w = w;
  1071. }
  1072. get width() {
  1073. return this.z;
  1074. }
  1075. set width( value ) {
  1076. this.z = value;
  1077. }
  1078. get height() {
  1079. return this.w;
  1080. }
  1081. set height( value ) {
  1082. this.w = value;
  1083. }
  1084. set( x, y, z, w ) {
  1085. this.x = x;
  1086. this.y = y;
  1087. this.z = z;
  1088. this.w = w;
  1089. return this;
  1090. }
  1091. setScalar( scalar ) {
  1092. this.x = scalar;
  1093. this.y = scalar;
  1094. this.z = scalar;
  1095. this.w = scalar;
  1096. return this;
  1097. }
  1098. setX( x ) {
  1099. this.x = x;
  1100. return this;
  1101. }
  1102. setY( y ) {
  1103. this.y = y;
  1104. return this;
  1105. }
  1106. setZ( z ) {
  1107. this.z = z;
  1108. return this;
  1109. }
  1110. setW( w ) {
  1111. this.w = w;
  1112. return this;
  1113. }
  1114. setComponent( index, value ) {
  1115. switch ( index ) {
  1116. case 0: this.x = value; break;
  1117. case 1: this.y = value; break;
  1118. case 2: this.z = value; break;
  1119. case 3: this.w = value; break;
  1120. default: throw new Error( 'index is out of range: ' + index );
  1121. }
  1122. return this;
  1123. }
  1124. getComponent( index ) {
  1125. switch ( index ) {
  1126. case 0: return this.x;
  1127. case 1: return this.y;
  1128. case 2: return this.z;
  1129. case 3: return this.w;
  1130. default: throw new Error( 'index is out of range: ' + index );
  1131. }
  1132. }
  1133. clone() {
  1134. return new this.constructor( this.x, this.y, this.z, this.w );
  1135. }
  1136. copy( v ) {
  1137. this.x = v.x;
  1138. this.y = v.y;
  1139. this.z = v.z;
  1140. this.w = ( v.w !== undefined ) ? v.w : 1;
  1141. return this;
  1142. }
  1143. add( v, w ) {
  1144. if ( w !== undefined ) {
  1145. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1146. return this.addVectors( v, w );
  1147. }
  1148. this.x += v.x;
  1149. this.y += v.y;
  1150. this.z += v.z;
  1151. this.w += v.w;
  1152. return this;
  1153. }
  1154. addScalar( s ) {
  1155. this.x += s;
  1156. this.y += s;
  1157. this.z += s;
  1158. this.w += s;
  1159. return this;
  1160. }
  1161. addVectors( a, b ) {
  1162. this.x = a.x + b.x;
  1163. this.y = a.y + b.y;
  1164. this.z = a.z + b.z;
  1165. this.w = a.w + b.w;
  1166. return this;
  1167. }
  1168. addScaledVector( v, s ) {
  1169. this.x += v.x * s;
  1170. this.y += v.y * s;
  1171. this.z += v.z * s;
  1172. this.w += v.w * s;
  1173. return this;
  1174. }
  1175. sub( v, w ) {
  1176. if ( w !== undefined ) {
  1177. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1178. return this.subVectors( v, w );
  1179. }
  1180. this.x -= v.x;
  1181. this.y -= v.y;
  1182. this.z -= v.z;
  1183. this.w -= v.w;
  1184. return this;
  1185. }
  1186. subScalar( s ) {
  1187. this.x -= s;
  1188. this.y -= s;
  1189. this.z -= s;
  1190. this.w -= s;
  1191. return this;
  1192. }
  1193. subVectors( a, b ) {
  1194. this.x = a.x - b.x;
  1195. this.y = a.y - b.y;
  1196. this.z = a.z - b.z;
  1197. this.w = a.w - b.w;
  1198. return this;
  1199. }
  1200. multiply( v ) {
  1201. this.x *= v.x;
  1202. this.y *= v.y;
  1203. this.z *= v.z;
  1204. this.w *= v.w;
  1205. return this;
  1206. }
  1207. multiplyScalar( scalar ) {
  1208. this.x *= scalar;
  1209. this.y *= scalar;
  1210. this.z *= scalar;
  1211. this.w *= scalar;
  1212. return this;
  1213. }
  1214. applyMatrix4( m ) {
  1215. const x = this.x, y = this.y, z = this.z, w = this.w;
  1216. const e = m.elements;
  1217. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1218. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1219. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1220. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1221. return this;
  1222. }
  1223. divideScalar( scalar ) {
  1224. return this.multiplyScalar( 1 / scalar );
  1225. }
  1226. setAxisAngleFromQuaternion( q ) {
  1227. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1228. // q is assumed to be normalized
  1229. this.w = 2 * Math.acos( q.w );
  1230. const s = Math.sqrt( 1 - q.w * q.w );
  1231. if ( s < 0.0001 ) {
  1232. this.x = 1;
  1233. this.y = 0;
  1234. this.z = 0;
  1235. } else {
  1236. this.x = q.x / s;
  1237. this.y = q.y / s;
  1238. this.z = q.z / s;
  1239. }
  1240. return this;
  1241. }
  1242. setAxisAngleFromRotationMatrix( m ) {
  1243. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1244. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1245. let angle, x, y, z; // variables for result
  1246. const epsilon = 0.01, // margin to allow for rounding errors
  1247. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1248. te = m.elements,
  1249. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1250. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1251. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1252. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1253. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1254. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1255. // singularity found
  1256. // first check for identity matrix which must have +1 for all terms
  1257. // in leading diagonal and zero in other terms
  1258. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1259. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1260. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1261. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1262. // this singularity is identity matrix so angle = 0
  1263. this.set( 1, 0, 0, 0 );
  1264. return this; // zero angle, arbitrary axis
  1265. }
  1266. // otherwise this singularity is angle = 180
  1267. angle = Math.PI;
  1268. const xx = ( m11 + 1 ) / 2;
  1269. const yy = ( m22 + 1 ) / 2;
  1270. const zz = ( m33 + 1 ) / 2;
  1271. const xy = ( m12 + m21 ) / 4;
  1272. const xz = ( m13 + m31 ) / 4;
  1273. const yz = ( m23 + m32 ) / 4;
  1274. if ( ( xx > yy ) && ( xx > zz ) ) {
  1275. // m11 is the largest diagonal term
  1276. if ( xx < epsilon ) {
  1277. x = 0;
  1278. y = 0.707106781;
  1279. z = 0.707106781;
  1280. } else {
  1281. x = Math.sqrt( xx );
  1282. y = xy / x;
  1283. z = xz / x;
  1284. }
  1285. } else if ( yy > zz ) {
  1286. // m22 is the largest diagonal term
  1287. if ( yy < epsilon ) {
  1288. x = 0.707106781;
  1289. y = 0;
  1290. z = 0.707106781;
  1291. } else {
  1292. y = Math.sqrt( yy );
  1293. x = xy / y;
  1294. z = yz / y;
  1295. }
  1296. } else {
  1297. // m33 is the largest diagonal term so base result on this
  1298. if ( zz < epsilon ) {
  1299. x = 0.707106781;
  1300. y = 0.707106781;
  1301. z = 0;
  1302. } else {
  1303. z = Math.sqrt( zz );
  1304. x = xz / z;
  1305. y = yz / z;
  1306. }
  1307. }
  1308. this.set( x, y, z, angle );
  1309. return this; // return 180 deg rotation
  1310. }
  1311. // as we have reached here there are no singularities so we can handle normally
  1312. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1313. ( m13 - m31 ) * ( m13 - m31 ) +
  1314. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1315. if ( Math.abs( s ) < 0.001 ) s = 1;
  1316. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1317. // caught by singularity test above, but I've left it in just in case
  1318. this.x = ( m32 - m23 ) / s;
  1319. this.y = ( m13 - m31 ) / s;
  1320. this.z = ( m21 - m12 ) / s;
  1321. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1322. return this;
  1323. }
  1324. min( v ) {
  1325. this.x = Math.min( this.x, v.x );
  1326. this.y = Math.min( this.y, v.y );
  1327. this.z = Math.min( this.z, v.z );
  1328. this.w = Math.min( this.w, v.w );
  1329. return this;
  1330. }
  1331. max( v ) {
  1332. this.x = Math.max( this.x, v.x );
  1333. this.y = Math.max( this.y, v.y );
  1334. this.z = Math.max( this.z, v.z );
  1335. this.w = Math.max( this.w, v.w );
  1336. return this;
  1337. }
  1338. clamp( min, max ) {
  1339. // assumes min < max, componentwise
  1340. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1341. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1342. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1343. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1344. return this;
  1345. }
  1346. clampScalar( minVal, maxVal ) {
  1347. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1348. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1349. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1350. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1351. return this;
  1352. }
  1353. clampLength( min, max ) {
  1354. const length = this.length();
  1355. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1356. }
  1357. floor() {
  1358. this.x = Math.floor( this.x );
  1359. this.y = Math.floor( this.y );
  1360. this.z = Math.floor( this.z );
  1361. this.w = Math.floor( this.w );
  1362. return this;
  1363. }
  1364. ceil() {
  1365. this.x = Math.ceil( this.x );
  1366. this.y = Math.ceil( this.y );
  1367. this.z = Math.ceil( this.z );
  1368. this.w = Math.ceil( this.w );
  1369. return this;
  1370. }
  1371. round() {
  1372. this.x = Math.round( this.x );
  1373. this.y = Math.round( this.y );
  1374. this.z = Math.round( this.z );
  1375. this.w = Math.round( this.w );
  1376. return this;
  1377. }
  1378. roundToZero() {
  1379. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1380. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1381. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1382. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1383. return this;
  1384. }
  1385. negate() {
  1386. this.x = - this.x;
  1387. this.y = - this.y;
  1388. this.z = - this.z;
  1389. this.w = - this.w;
  1390. return this;
  1391. }
  1392. dot( v ) {
  1393. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1394. }
  1395. lengthSq() {
  1396. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1397. }
  1398. length() {
  1399. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1400. }
  1401. manhattanLength() {
  1402. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1403. }
  1404. normalize() {
  1405. return this.divideScalar( this.length() || 1 );
  1406. }
  1407. setLength( length ) {
  1408. return this.normalize().multiplyScalar( length );
  1409. }
  1410. lerp( v, alpha ) {
  1411. this.x += ( v.x - this.x ) * alpha;
  1412. this.y += ( v.y - this.y ) * alpha;
  1413. this.z += ( v.z - this.z ) * alpha;
  1414. this.w += ( v.w - this.w ) * alpha;
  1415. return this;
  1416. }
  1417. lerpVectors( v1, v2, alpha ) {
  1418. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1419. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1420. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1421. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1422. return this;
  1423. }
  1424. equals( v ) {
  1425. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1426. }
  1427. fromArray( array, offset = 0 ) {
  1428. this.x = array[ offset ];
  1429. this.y = array[ offset + 1 ];
  1430. this.z = array[ offset + 2 ];
  1431. this.w = array[ offset + 3 ];
  1432. return this;
  1433. }
  1434. toArray( array = [], offset = 0 ) {
  1435. array[ offset ] = this.x;
  1436. array[ offset + 1 ] = this.y;
  1437. array[ offset + 2 ] = this.z;
  1438. array[ offset + 3 ] = this.w;
  1439. return array;
  1440. }
  1441. fromBufferAttribute( attribute, index, offset ) {
  1442. if ( offset !== undefined ) {
  1443. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1444. }
  1445. this.x = attribute.getX( index );
  1446. this.y = attribute.getY( index );
  1447. this.z = attribute.getZ( index );
  1448. this.w = attribute.getW( index );
  1449. return this;
  1450. }
  1451. random() {
  1452. this.x = Math.random();
  1453. this.y = Math.random();
  1454. this.z = Math.random();
  1455. this.w = Math.random();
  1456. return this;
  1457. }
  1458. }
  1459. /*
  1460. In options, we can specify:
  1461. * Texture parameters for an auto-generated target texture
  1462. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1463. */
  1464. class WebGLRenderTarget extends EventDispatcher {
  1465. constructor( width, height, options ) {
  1466. super();
  1467. Object.defineProperty( this, 'isWebGLRenderTarget', { value: true } );
  1468. this.width = width;
  1469. this.height = height;
  1470. this.scissor = new Vector4( 0, 0, width, height );
  1471. this.scissorTest = false;
  1472. this.viewport = new Vector4( 0, 0, width, height );
  1473. options = options || {};
  1474. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1475. this.texture.image = {};
  1476. this.texture.image.width = width;
  1477. this.texture.image.height = height;
  1478. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1479. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1480. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1481. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1482. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1483. }
  1484. setSize( width, height ) {
  1485. if ( this.width !== width || this.height !== height ) {
  1486. this.width = width;
  1487. this.height = height;
  1488. this.texture.image.width = width;
  1489. this.texture.image.height = height;
  1490. this.dispose();
  1491. }
  1492. this.viewport.set( 0, 0, width, height );
  1493. this.scissor.set( 0, 0, width, height );
  1494. }
  1495. clone() {
  1496. return new this.constructor().copy( this );
  1497. }
  1498. copy( source ) {
  1499. this.width = source.width;
  1500. this.height = source.height;
  1501. this.viewport.copy( source.viewport );
  1502. this.texture = source.texture.clone();
  1503. this.depthBuffer = source.depthBuffer;
  1504. this.stencilBuffer = source.stencilBuffer;
  1505. this.depthTexture = source.depthTexture;
  1506. return this;
  1507. }
  1508. dispose() {
  1509. this.dispatchEvent( { type: 'dispose' } );
  1510. }
  1511. }
  1512. class WebGLMultisampleRenderTarget extends WebGLRenderTarget {
  1513. constructor( width, height, options ) {
  1514. super( width, height, options );
  1515. Object.defineProperty( this, 'isWebGLMultisampleRenderTarget', { value: true } );
  1516. this.samples = 4;
  1517. }
  1518. copy( source ) {
  1519. super.copy.call( this, source );
  1520. this.samples = source.samples;
  1521. return this;
  1522. }
  1523. }
  1524. class Quaternion {
  1525. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1526. Object.defineProperty( this, 'isQuaternion', { value: true } );
  1527. this._x = x;
  1528. this._y = y;
  1529. this._z = z;
  1530. this._w = w;
  1531. }
  1532. static slerp( qa, qb, qm, t ) {
  1533. return qm.copy( qa ).slerp( qb, t );
  1534. }
  1535. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1536. // fuzz-free, array-based Quaternion SLERP operation
  1537. let x0 = src0[ srcOffset0 + 0 ],
  1538. y0 = src0[ srcOffset0 + 1 ],
  1539. z0 = src0[ srcOffset0 + 2 ],
  1540. w0 = src0[ srcOffset0 + 3 ];
  1541. const x1 = src1[ srcOffset1 + 0 ],
  1542. y1 = src1[ srcOffset1 + 1 ],
  1543. z1 = src1[ srcOffset1 + 2 ],
  1544. w1 = src1[ srcOffset1 + 3 ];
  1545. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1546. let s = 1 - t;
  1547. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1548. dir = ( cos >= 0 ? 1 : - 1 ),
  1549. sqrSin = 1 - cos * cos;
  1550. // Skip the Slerp for tiny steps to avoid numeric problems:
  1551. if ( sqrSin > Number.EPSILON ) {
  1552. const sin = Math.sqrt( sqrSin ),
  1553. len = Math.atan2( sin, cos * dir );
  1554. s = Math.sin( s * len ) / sin;
  1555. t = Math.sin( t * len ) / sin;
  1556. }
  1557. const tDir = t * dir;
  1558. x0 = x0 * s + x1 * tDir;
  1559. y0 = y0 * s + y1 * tDir;
  1560. z0 = z0 * s + z1 * tDir;
  1561. w0 = w0 * s + w1 * tDir;
  1562. // Normalize in case we just did a lerp:
  1563. if ( s === 1 - t ) {
  1564. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1565. x0 *= f;
  1566. y0 *= f;
  1567. z0 *= f;
  1568. w0 *= f;
  1569. }
  1570. }
  1571. dst[ dstOffset ] = x0;
  1572. dst[ dstOffset + 1 ] = y0;
  1573. dst[ dstOffset + 2 ] = z0;
  1574. dst[ dstOffset + 3 ] = w0;
  1575. }
  1576. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1577. const x0 = src0[ srcOffset0 ];
  1578. const y0 = src0[ srcOffset0 + 1 ];
  1579. const z0 = src0[ srcOffset0 + 2 ];
  1580. const w0 = src0[ srcOffset0 + 3 ];
  1581. const x1 = src1[ srcOffset1 ];
  1582. const y1 = src1[ srcOffset1 + 1 ];
  1583. const z1 = src1[ srcOffset1 + 2 ];
  1584. const w1 = src1[ srcOffset1 + 3 ];
  1585. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1586. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1587. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1588. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1589. return dst;
  1590. }
  1591. get x() {
  1592. return this._x;
  1593. }
  1594. set x( value ) {
  1595. this._x = value;
  1596. this._onChangeCallback();
  1597. }
  1598. get y() {
  1599. return this._y;
  1600. }
  1601. set y( value ) {
  1602. this._y = value;
  1603. this._onChangeCallback();
  1604. }
  1605. get z() {
  1606. return this._z;
  1607. }
  1608. set z( value ) {
  1609. this._z = value;
  1610. this._onChangeCallback();
  1611. }
  1612. get w() {
  1613. return this._w;
  1614. }
  1615. set w( value ) {
  1616. this._w = value;
  1617. this._onChangeCallback();
  1618. }
  1619. set( x, y, z, w ) {
  1620. this._x = x;
  1621. this._y = y;
  1622. this._z = z;
  1623. this._w = w;
  1624. this._onChangeCallback();
  1625. return this;
  1626. }
  1627. clone() {
  1628. return new this.constructor( this._x, this._y, this._z, this._w );
  1629. }
  1630. copy( quaternion ) {
  1631. this._x = quaternion.x;
  1632. this._y = quaternion.y;
  1633. this._z = quaternion.z;
  1634. this._w = quaternion.w;
  1635. this._onChangeCallback();
  1636. return this;
  1637. }
  1638. setFromEuler( euler, update ) {
  1639. if ( ! ( euler && euler.isEuler ) ) {
  1640. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1641. }
  1642. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  1643. // http://www.mathworks.com/matlabcentral/fileexchange/
  1644. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1645. // content/SpinCalc.m
  1646. const cos = Math.cos;
  1647. const sin = Math.sin;
  1648. const c1 = cos( x / 2 );
  1649. const c2 = cos( y / 2 );
  1650. const c3 = cos( z / 2 );
  1651. const s1 = sin( x / 2 );
  1652. const s2 = sin( y / 2 );
  1653. const s3 = sin( z / 2 );
  1654. switch ( order ) {
  1655. case 'XYZ':
  1656. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1657. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1658. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1659. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1660. break;
  1661. case 'YXZ':
  1662. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1663. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1664. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1665. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1666. break;
  1667. case 'ZXY':
  1668. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1669. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1670. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1671. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1672. break;
  1673. case 'ZYX':
  1674. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1675. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1676. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1677. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1678. break;
  1679. case 'YZX':
  1680. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1681. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1682. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1683. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1684. break;
  1685. case 'XZY':
  1686. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1687. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1688. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1689. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1690. break;
  1691. default:
  1692. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1693. }
  1694. if ( update !== false ) this._onChangeCallback();
  1695. return this;
  1696. }
  1697. setFromAxisAngle( axis, angle ) {
  1698. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1699. // assumes axis is normalized
  1700. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  1701. this._x = axis.x * s;
  1702. this._y = axis.y * s;
  1703. this._z = axis.z * s;
  1704. this._w = Math.cos( halfAngle );
  1705. this._onChangeCallback();
  1706. return this;
  1707. }
  1708. setFromRotationMatrix( m ) {
  1709. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1710. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1711. const te = m.elements,
  1712. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1713. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1714. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1715. trace = m11 + m22 + m33;
  1716. if ( trace > 0 ) {
  1717. const s = 0.5 / Math.sqrt( trace + 1.0 );
  1718. this._w = 0.25 / s;
  1719. this._x = ( m32 - m23 ) * s;
  1720. this._y = ( m13 - m31 ) * s;
  1721. this._z = ( m21 - m12 ) * s;
  1722. } else if ( m11 > m22 && m11 > m33 ) {
  1723. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1724. this._w = ( m32 - m23 ) / s;
  1725. this._x = 0.25 * s;
  1726. this._y = ( m12 + m21 ) / s;
  1727. this._z = ( m13 + m31 ) / s;
  1728. } else if ( m22 > m33 ) {
  1729. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1730. this._w = ( m13 - m31 ) / s;
  1731. this._x = ( m12 + m21 ) / s;
  1732. this._y = 0.25 * s;
  1733. this._z = ( m23 + m32 ) / s;
  1734. } else {
  1735. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1736. this._w = ( m21 - m12 ) / s;
  1737. this._x = ( m13 + m31 ) / s;
  1738. this._y = ( m23 + m32 ) / s;
  1739. this._z = 0.25 * s;
  1740. }
  1741. this._onChangeCallback();
  1742. return this;
  1743. }
  1744. setFromUnitVectors( vFrom, vTo ) {
  1745. // assumes direction vectors vFrom and vTo are normalized
  1746. const EPS = 0.000001;
  1747. let r = vFrom.dot( vTo ) + 1;
  1748. if ( r < EPS ) {
  1749. r = 0;
  1750. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1751. this._x = - vFrom.y;
  1752. this._y = vFrom.x;
  1753. this._z = 0;
  1754. this._w = r;
  1755. } else {
  1756. this._x = 0;
  1757. this._y = - vFrom.z;
  1758. this._z = vFrom.y;
  1759. this._w = r;
  1760. }
  1761. } else {
  1762. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1763. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1764. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1765. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1766. this._w = r;
  1767. }
  1768. return this.normalize();
  1769. }
  1770. angleTo( q ) {
  1771. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1772. }
  1773. rotateTowards( q, step ) {
  1774. const angle = this.angleTo( q );
  1775. if ( angle === 0 ) return this;
  1776. const t = Math.min( 1, step / angle );
  1777. this.slerp( q, t );
  1778. return this;
  1779. }
  1780. identity() {
  1781. return this.set( 0, 0, 0, 1 );
  1782. }
  1783. invert() {
  1784. // quaternion is assumed to have unit length
  1785. return this.conjugate();
  1786. }
  1787. conjugate() {
  1788. this._x *= - 1;
  1789. this._y *= - 1;
  1790. this._z *= - 1;
  1791. this._onChangeCallback();
  1792. return this;
  1793. }
  1794. dot( v ) {
  1795. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1796. }
  1797. lengthSq() {
  1798. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1799. }
  1800. length() {
  1801. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1802. }
  1803. normalize() {
  1804. let l = this.length();
  1805. if ( l === 0 ) {
  1806. this._x = 0;
  1807. this._y = 0;
  1808. this._z = 0;
  1809. this._w = 1;
  1810. } else {
  1811. l = 1 / l;
  1812. this._x = this._x * l;
  1813. this._y = this._y * l;
  1814. this._z = this._z * l;
  1815. this._w = this._w * l;
  1816. }
  1817. this._onChangeCallback();
  1818. return this;
  1819. }
  1820. multiply( q, p ) {
  1821. if ( p !== undefined ) {
  1822. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1823. return this.multiplyQuaternions( q, p );
  1824. }
  1825. return this.multiplyQuaternions( this, q );
  1826. }
  1827. premultiply( q ) {
  1828. return this.multiplyQuaternions( q, this );
  1829. }
  1830. multiplyQuaternions( a, b ) {
  1831. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1832. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1833. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1834. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1835. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1836. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1837. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1838. this._onChangeCallback();
  1839. return this;
  1840. }
  1841. slerp( qb, t ) {
  1842. if ( t === 0 ) return this;
  1843. if ( t === 1 ) return this.copy( qb );
  1844. const x = this._x, y = this._y, z = this._z, w = this._w;
  1845. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1846. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1847. if ( cosHalfTheta < 0 ) {
  1848. this._w = - qb._w;
  1849. this._x = - qb._x;
  1850. this._y = - qb._y;
  1851. this._z = - qb._z;
  1852. cosHalfTheta = - cosHalfTheta;
  1853. } else {
  1854. this.copy( qb );
  1855. }
  1856. if ( cosHalfTheta >= 1.0 ) {
  1857. this._w = w;
  1858. this._x = x;
  1859. this._y = y;
  1860. this._z = z;
  1861. return this;
  1862. }
  1863. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1864. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1865. const s = 1 - t;
  1866. this._w = s * w + t * this._w;
  1867. this._x = s * x + t * this._x;
  1868. this._y = s * y + t * this._y;
  1869. this._z = s * z + t * this._z;
  1870. this.normalize();
  1871. this._onChangeCallback();
  1872. return this;
  1873. }
  1874. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1875. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1876. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1877. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1878. this._w = ( w * ratioA + this._w * ratioB );
  1879. this._x = ( x * ratioA + this._x * ratioB );
  1880. this._y = ( y * ratioA + this._y * ratioB );
  1881. this._z = ( z * ratioA + this._z * ratioB );
  1882. this._onChangeCallback();
  1883. return this;
  1884. }
  1885. equals( quaternion ) {
  1886. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1887. }
  1888. fromArray( array, offset = 0 ) {
  1889. this._x = array[ offset ];
  1890. this._y = array[ offset + 1 ];
  1891. this._z = array[ offset + 2 ];
  1892. this._w = array[ offset + 3 ];
  1893. this._onChangeCallback();
  1894. return this;
  1895. }
  1896. toArray( array = [], offset = 0 ) {
  1897. array[ offset ] = this._x;
  1898. array[ offset + 1 ] = this._y;
  1899. array[ offset + 2 ] = this._z;
  1900. array[ offset + 3 ] = this._w;
  1901. return array;
  1902. }
  1903. fromBufferAttribute( attribute, index ) {
  1904. this._x = attribute.getX( index );
  1905. this._y = attribute.getY( index );
  1906. this._z = attribute.getZ( index );
  1907. this._w = attribute.getW( index );
  1908. return this;
  1909. }
  1910. _onChange( callback ) {
  1911. this._onChangeCallback = callback;
  1912. return this;
  1913. }
  1914. _onChangeCallback() {}
  1915. }
  1916. class Vector3 {
  1917. constructor( x = 0, y = 0, z = 0 ) {
  1918. Object.defineProperty( this, 'isVector3', { value: true } );
  1919. this.x = x;
  1920. this.y = y;
  1921. this.z = z;
  1922. }
  1923. set( x, y, z ) {
  1924. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  1925. this.x = x;
  1926. this.y = y;
  1927. this.z = z;
  1928. return this;
  1929. }
  1930. setScalar( scalar ) {
  1931. this.x = scalar;
  1932. this.y = scalar;
  1933. this.z = scalar;
  1934. return this;
  1935. }
  1936. setX( x ) {
  1937. this.x = x;
  1938. return this;
  1939. }
  1940. setY( y ) {
  1941. this.y = y;
  1942. return this;
  1943. }
  1944. setZ( z ) {
  1945. this.z = z;
  1946. return this;
  1947. }
  1948. setComponent( index, value ) {
  1949. switch ( index ) {
  1950. case 0: this.x = value; break;
  1951. case 1: this.y = value; break;
  1952. case 2: this.z = value; break;
  1953. default: throw new Error( 'index is out of range: ' + index );
  1954. }
  1955. return this;
  1956. }
  1957. getComponent( index ) {
  1958. switch ( index ) {
  1959. case 0: return this.x;
  1960. case 1: return this.y;
  1961. case 2: return this.z;
  1962. default: throw new Error( 'index is out of range: ' + index );
  1963. }
  1964. }
  1965. clone() {
  1966. return new this.constructor( this.x, this.y, this.z );
  1967. }
  1968. copy( v ) {
  1969. this.x = v.x;
  1970. this.y = v.y;
  1971. this.z = v.z;
  1972. return this;
  1973. }
  1974. add( v, w ) {
  1975. if ( w !== undefined ) {
  1976. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1977. return this.addVectors( v, w );
  1978. }
  1979. this.x += v.x;
  1980. this.y += v.y;
  1981. this.z += v.z;
  1982. return this;
  1983. }
  1984. addScalar( s ) {
  1985. this.x += s;
  1986. this.y += s;
  1987. this.z += s;
  1988. return this;
  1989. }
  1990. addVectors( a, b ) {
  1991. this.x = a.x + b.x;
  1992. this.y = a.y + b.y;
  1993. this.z = a.z + b.z;
  1994. return this;
  1995. }
  1996. addScaledVector( v, s ) {
  1997. this.x += v.x * s;
  1998. this.y += v.y * s;
  1999. this.z += v.z * s;
  2000. return this;
  2001. }
  2002. sub( v, w ) {
  2003. if ( w !== undefined ) {
  2004. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2005. return this.subVectors( v, w );
  2006. }
  2007. this.x -= v.x;
  2008. this.y -= v.y;
  2009. this.z -= v.z;
  2010. return this;
  2011. }
  2012. subScalar( s ) {
  2013. this.x -= s;
  2014. this.y -= s;
  2015. this.z -= s;
  2016. return this;
  2017. }
  2018. subVectors( a, b ) {
  2019. this.x = a.x - b.x;
  2020. this.y = a.y - b.y;
  2021. this.z = a.z - b.z;
  2022. return this;
  2023. }
  2024. multiply( v, w ) {
  2025. if ( w !== undefined ) {
  2026. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2027. return this.multiplyVectors( v, w );
  2028. }
  2029. this.x *= v.x;
  2030. this.y *= v.y;
  2031. this.z *= v.z;
  2032. return this;
  2033. }
  2034. multiplyScalar( scalar ) {
  2035. this.x *= scalar;
  2036. this.y *= scalar;
  2037. this.z *= scalar;
  2038. return this;
  2039. }
  2040. multiplyVectors( a, b ) {
  2041. this.x = a.x * b.x;
  2042. this.y = a.y * b.y;
  2043. this.z = a.z * b.z;
  2044. return this;
  2045. }
  2046. applyEuler( euler ) {
  2047. if ( ! ( euler && euler.isEuler ) ) {
  2048. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2049. }
  2050. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2051. }
  2052. applyAxisAngle( axis, angle ) {
  2053. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2054. }
  2055. applyMatrix3( m ) {
  2056. const x = this.x, y = this.y, z = this.z;
  2057. const e = m.elements;
  2058. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2059. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2060. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2061. return this;
  2062. }
  2063. applyNormalMatrix( m ) {
  2064. return this.applyMatrix3( m ).normalize();
  2065. }
  2066. applyMatrix4( m ) {
  2067. const x = this.x, y = this.y, z = this.z;
  2068. const e = m.elements;
  2069. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2070. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2071. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2072. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2073. return this;
  2074. }
  2075. applyQuaternion( q ) {
  2076. const x = this.x, y = this.y, z = this.z;
  2077. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2078. // calculate quat * vector
  2079. const ix = qw * x + qy * z - qz * y;
  2080. const iy = qw * y + qz * x - qx * z;
  2081. const iz = qw * z + qx * y - qy * x;
  2082. const iw = - qx * x - qy * y - qz * z;
  2083. // calculate result * inverse quat
  2084. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2085. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2086. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2087. return this;
  2088. }
  2089. project( camera ) {
  2090. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2091. }
  2092. unproject( camera ) {
  2093. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2094. }
  2095. transformDirection( m ) {
  2096. // input: THREE.Matrix4 affine matrix
  2097. // vector interpreted as a direction
  2098. const x = this.x, y = this.y, z = this.z;
  2099. const e = m.elements;
  2100. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2101. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2102. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2103. return this.normalize();
  2104. }
  2105. divide( v ) {
  2106. this.x /= v.x;
  2107. this.y /= v.y;
  2108. this.z /= v.z;
  2109. return this;
  2110. }
  2111. divideScalar( scalar ) {
  2112. return this.multiplyScalar( 1 / scalar );
  2113. }
  2114. min( v ) {
  2115. this.x = Math.min( this.x, v.x );
  2116. this.y = Math.min( this.y, v.y );
  2117. this.z = Math.min( this.z, v.z );
  2118. return this;
  2119. }
  2120. max( v ) {
  2121. this.x = Math.max( this.x, v.x );
  2122. this.y = Math.max( this.y, v.y );
  2123. this.z = Math.max( this.z, v.z );
  2124. return this;
  2125. }
  2126. clamp( min, max ) {
  2127. // assumes min < max, componentwise
  2128. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2129. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2130. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2131. return this;
  2132. }
  2133. clampScalar( minVal, maxVal ) {
  2134. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2135. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2136. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2137. return this;
  2138. }
  2139. clampLength( min, max ) {
  2140. const length = this.length();
  2141. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2142. }
  2143. floor() {
  2144. this.x = Math.floor( this.x );
  2145. this.y = Math.floor( this.y );
  2146. this.z = Math.floor( this.z );
  2147. return this;
  2148. }
  2149. ceil() {
  2150. this.x = Math.ceil( this.x );
  2151. this.y = Math.ceil( this.y );
  2152. this.z = Math.ceil( this.z );
  2153. return this;
  2154. }
  2155. round() {
  2156. this.x = Math.round( this.x );
  2157. this.y = Math.round( this.y );
  2158. this.z = Math.round( this.z );
  2159. return this;
  2160. }
  2161. roundToZero() {
  2162. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2163. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2164. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2165. return this;
  2166. }
  2167. negate() {
  2168. this.x = - this.x;
  2169. this.y = - this.y;
  2170. this.z = - this.z;
  2171. return this;
  2172. }
  2173. dot( v ) {
  2174. return this.x * v.x + this.y * v.y + this.z * v.z;
  2175. }
  2176. // TODO lengthSquared?
  2177. lengthSq() {
  2178. return this.x * this.x + this.y * this.y + this.z * this.z;
  2179. }
  2180. length() {
  2181. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2182. }
  2183. manhattanLength() {
  2184. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2185. }
  2186. normalize() {
  2187. return this.divideScalar( this.length() || 1 );
  2188. }
  2189. setLength( length ) {
  2190. return this.normalize().multiplyScalar( length );
  2191. }
  2192. lerp( v, alpha ) {
  2193. this.x += ( v.x - this.x ) * alpha;
  2194. this.y += ( v.y - this.y ) * alpha;
  2195. this.z += ( v.z - this.z ) * alpha;
  2196. return this;
  2197. }
  2198. lerpVectors( v1, v2, alpha ) {
  2199. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2200. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2201. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2202. return this;
  2203. }
  2204. cross( v, w ) {
  2205. if ( w !== undefined ) {
  2206. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2207. return this.crossVectors( v, w );
  2208. }
  2209. return this.crossVectors( this, v );
  2210. }
  2211. crossVectors( a, b ) {
  2212. const ax = a.x, ay = a.y, az = a.z;
  2213. const bx = b.x, by = b.y, bz = b.z;
  2214. this.x = ay * bz - az * by;
  2215. this.y = az * bx - ax * bz;
  2216. this.z = ax * by - ay * bx;
  2217. return this;
  2218. }
  2219. projectOnVector( v ) {
  2220. const denominator = v.lengthSq();
  2221. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2222. const scalar = v.dot( this ) / denominator;
  2223. return this.copy( v ).multiplyScalar( scalar );
  2224. }
  2225. projectOnPlane( planeNormal ) {
  2226. _vector.copy( this ).projectOnVector( planeNormal );
  2227. return this.sub( _vector );
  2228. }
  2229. reflect( normal ) {
  2230. // reflect incident vector off plane orthogonal to normal
  2231. // normal is assumed to have unit length
  2232. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2233. }
  2234. angleTo( v ) {
  2235. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2236. if ( denominator === 0 ) return Math.PI / 2;
  2237. const theta = this.dot( v ) / denominator;
  2238. // clamp, to handle numerical problems
  2239. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2240. }
  2241. distanceTo( v ) {
  2242. return Math.sqrt( this.distanceToSquared( v ) );
  2243. }
  2244. distanceToSquared( v ) {
  2245. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2246. return dx * dx + dy * dy + dz * dz;
  2247. }
  2248. manhattanDistanceTo( v ) {
  2249. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2250. }
  2251. setFromSpherical( s ) {
  2252. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2253. }
  2254. setFromSphericalCoords( radius, phi, theta ) {
  2255. const sinPhiRadius = Math.sin( phi ) * radius;
  2256. this.x = sinPhiRadius * Math.sin( theta );
  2257. this.y = Math.cos( phi ) * radius;
  2258. this.z = sinPhiRadius * Math.cos( theta );
  2259. return this;
  2260. }
  2261. setFromCylindrical( c ) {
  2262. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2263. }
  2264. setFromCylindricalCoords( radius, theta, y ) {
  2265. this.x = radius * Math.sin( theta );
  2266. this.y = y;
  2267. this.z = radius * Math.cos( theta );
  2268. return this;
  2269. }
  2270. setFromMatrixPosition( m ) {
  2271. const e = m.elements;
  2272. this.x = e[ 12 ];
  2273. this.y = e[ 13 ];
  2274. this.z = e[ 14 ];
  2275. return this;
  2276. }
  2277. setFromMatrixScale( m ) {
  2278. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2279. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2280. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2281. this.x = sx;
  2282. this.y = sy;
  2283. this.z = sz;
  2284. return this;
  2285. }
  2286. setFromMatrixColumn( m, index ) {
  2287. return this.fromArray( m.elements, index * 4 );
  2288. }
  2289. setFromMatrix3Column( m, index ) {
  2290. return this.fromArray( m.elements, index * 3 );
  2291. }
  2292. equals( v ) {
  2293. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2294. }
  2295. fromArray( array, offset = 0 ) {
  2296. this.x = array[ offset ];
  2297. this.y = array[ offset + 1 ];
  2298. this.z = array[ offset + 2 ];
  2299. return this;
  2300. }
  2301. toArray( array = [], offset = 0 ) {
  2302. array[ offset ] = this.x;
  2303. array[ offset + 1 ] = this.y;
  2304. array[ offset + 2 ] = this.z;
  2305. return array;
  2306. }
  2307. fromBufferAttribute( attribute, index, offset ) {
  2308. if ( offset !== undefined ) {
  2309. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2310. }
  2311. this.x = attribute.getX( index );
  2312. this.y = attribute.getY( index );
  2313. this.z = attribute.getZ( index );
  2314. return this;
  2315. }
  2316. random() {
  2317. this.x = Math.random();
  2318. this.y = Math.random();
  2319. this.z = Math.random();
  2320. return this;
  2321. }
  2322. }
  2323. const _vector = /*@__PURE__*/ new Vector3();
  2324. const _quaternion = /*@__PURE__*/ new Quaternion();
  2325. class Box3 {
  2326. constructor( min, max ) {
  2327. Object.defineProperty( this, 'isBox3', { value: true } );
  2328. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2329. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2330. }
  2331. set( min, max ) {
  2332. this.min.copy( min );
  2333. this.max.copy( max );
  2334. return this;
  2335. }
  2336. setFromArray( array ) {
  2337. let minX = + Infinity;
  2338. let minY = + Infinity;
  2339. let minZ = + Infinity;
  2340. let maxX = - Infinity;
  2341. let maxY = - Infinity;
  2342. let maxZ = - Infinity;
  2343. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  2344. const x = array[ i ];
  2345. const y = array[ i + 1 ];
  2346. const z = array[ i + 2 ];
  2347. if ( x < minX ) minX = x;
  2348. if ( y < minY ) minY = y;
  2349. if ( z < minZ ) minZ = z;
  2350. if ( x > maxX ) maxX = x;
  2351. if ( y > maxY ) maxY = y;
  2352. if ( z > maxZ ) maxZ = z;
  2353. }
  2354. this.min.set( minX, minY, minZ );
  2355. this.max.set( maxX, maxY, maxZ );
  2356. return this;
  2357. }
  2358. setFromBufferAttribute( attribute ) {
  2359. let minX = + Infinity;
  2360. let minY = + Infinity;
  2361. let minZ = + Infinity;
  2362. let maxX = - Infinity;
  2363. let maxY = - Infinity;
  2364. let maxZ = - Infinity;
  2365. for ( let i = 0, l = attribute.count; i < l; i ++ ) {
  2366. const x = attribute.getX( i );
  2367. const y = attribute.getY( i );
  2368. const z = attribute.getZ( i );
  2369. if ( x < minX ) minX = x;
  2370. if ( y < minY ) minY = y;
  2371. if ( z < minZ ) minZ = z;
  2372. if ( x > maxX ) maxX = x;
  2373. if ( y > maxY ) maxY = y;
  2374. if ( z > maxZ ) maxZ = z;
  2375. }
  2376. this.min.set( minX, minY, minZ );
  2377. this.max.set( maxX, maxY, maxZ );
  2378. return this;
  2379. }
  2380. setFromPoints( points ) {
  2381. this.makeEmpty();
  2382. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2383. this.expandByPoint( points[ i ] );
  2384. }
  2385. return this;
  2386. }
  2387. setFromCenterAndSize( center, size ) {
  2388. const halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  2389. this.min.copy( center ).sub( halfSize );
  2390. this.max.copy( center ).add( halfSize );
  2391. return this;
  2392. }
  2393. setFromObject( object ) {
  2394. this.makeEmpty();
  2395. return this.expandByObject( object );
  2396. }
  2397. clone() {
  2398. return new this.constructor().copy( this );
  2399. }
  2400. copy( box ) {
  2401. this.min.copy( box.min );
  2402. this.max.copy( box.max );
  2403. return this;
  2404. }
  2405. makeEmpty() {
  2406. this.min.x = this.min.y = this.min.z = + Infinity;
  2407. this.max.x = this.max.y = this.max.z = - Infinity;
  2408. return this;
  2409. }
  2410. isEmpty() {
  2411. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2412. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2413. }
  2414. getCenter( target ) {
  2415. if ( target === undefined ) {
  2416. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2417. target = new Vector3();
  2418. }
  2419. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2420. }
  2421. getSize( target ) {
  2422. if ( target === undefined ) {
  2423. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2424. target = new Vector3();
  2425. }
  2426. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2427. }
  2428. expandByPoint( point ) {
  2429. this.min.min( point );
  2430. this.max.max( point );
  2431. return this;
  2432. }
  2433. expandByVector( vector ) {
  2434. this.min.sub( vector );
  2435. this.max.add( vector );
  2436. return this;
  2437. }
  2438. expandByScalar( scalar ) {
  2439. this.min.addScalar( - scalar );
  2440. this.max.addScalar( scalar );
  2441. return this;
  2442. }
  2443. expandByObject( object ) {
  2444. // Computes the world-axis-aligned bounding box of an object (including its children),
  2445. // accounting for both the object's, and children's, world transforms
  2446. object.updateWorldMatrix( false, false );
  2447. const geometry = object.geometry;
  2448. if ( geometry !== undefined ) {
  2449. if ( geometry.boundingBox === null ) {
  2450. geometry.computeBoundingBox();
  2451. }
  2452. _box.copy( geometry.boundingBox );
  2453. _box.applyMatrix4( object.matrixWorld );
  2454. this.union( _box );
  2455. }
  2456. const children = object.children;
  2457. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2458. this.expandByObject( children[ i ] );
  2459. }
  2460. return this;
  2461. }
  2462. containsPoint( point ) {
  2463. return point.x < this.min.x || point.x > this.max.x ||
  2464. point.y < this.min.y || point.y > this.max.y ||
  2465. point.z < this.min.z || point.z > this.max.z ? false : true;
  2466. }
  2467. containsBox( box ) {
  2468. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2469. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2470. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2471. }
  2472. getParameter( point, target ) {
  2473. // This can potentially have a divide by zero if the box
  2474. // has a size dimension of 0.
  2475. if ( target === undefined ) {
  2476. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2477. target = new Vector3();
  2478. }
  2479. return target.set(
  2480. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2481. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2482. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2483. );
  2484. }
  2485. intersectsBox( box ) {
  2486. // using 6 splitting planes to rule out intersections.
  2487. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2488. box.max.y < this.min.y || box.min.y > this.max.y ||
  2489. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2490. }
  2491. intersectsSphere( sphere ) {
  2492. // Find the point on the AABB closest to the sphere center.
  2493. this.clampPoint( sphere.center, _vector$1 );
  2494. // If that point is inside the sphere, the AABB and sphere intersect.
  2495. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2496. }
  2497. intersectsPlane( plane ) {
  2498. // We compute the minimum and maximum dot product values. If those values
  2499. // are on the same side (back or front) of the plane, then there is no intersection.
  2500. let min, max;
  2501. if ( plane.normal.x > 0 ) {
  2502. min = plane.normal.x * this.min.x;
  2503. max = plane.normal.x * this.max.x;
  2504. } else {
  2505. min = plane.normal.x * this.max.x;
  2506. max = plane.normal.x * this.min.x;
  2507. }
  2508. if ( plane.normal.y > 0 ) {
  2509. min += plane.normal.y * this.min.y;
  2510. max += plane.normal.y * this.max.y;
  2511. } else {
  2512. min += plane.normal.y * this.max.y;
  2513. max += plane.normal.y * this.min.y;
  2514. }
  2515. if ( plane.normal.z > 0 ) {
  2516. min += plane.normal.z * this.min.z;
  2517. max += plane.normal.z * this.max.z;
  2518. } else {
  2519. min += plane.normal.z * this.max.z;
  2520. max += plane.normal.z * this.min.z;
  2521. }
  2522. return ( min <= - plane.constant && max >= - plane.constant );
  2523. }
  2524. intersectsTriangle( triangle ) {
  2525. if ( this.isEmpty() ) {
  2526. return false;
  2527. }
  2528. // compute box center and extents
  2529. this.getCenter( _center );
  2530. _extents.subVectors( this.max, _center );
  2531. // translate triangle to aabb origin
  2532. _v0.subVectors( triangle.a, _center );
  2533. _v1.subVectors( triangle.b, _center );
  2534. _v2.subVectors( triangle.c, _center );
  2535. // compute edge vectors for triangle
  2536. _f0.subVectors( _v1, _v0 );
  2537. _f1.subVectors( _v2, _v1 );
  2538. _f2.subVectors( _v0, _v2 );
  2539. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2540. // 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
  2541. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2542. let axes = [
  2543. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  2544. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  2545. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  2546. ];
  2547. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2548. return false;
  2549. }
  2550. // test 3 face normals from the aabb
  2551. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2552. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2553. return false;
  2554. }
  2555. // finally testing the face normal of the triangle
  2556. // use already existing triangle edge vectors here
  2557. _triangleNormal.crossVectors( _f0, _f1 );
  2558. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  2559. return satForAxes( axes, _v0, _v1, _v2, _extents );
  2560. }
  2561. clampPoint( point, target ) {
  2562. if ( target === undefined ) {
  2563. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2564. target = new Vector3();
  2565. }
  2566. return target.copy( point ).clamp( this.min, this.max );
  2567. }
  2568. distanceToPoint( point ) {
  2569. const clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  2570. return clampedPoint.sub( point ).length();
  2571. }
  2572. getBoundingSphere( target ) {
  2573. if ( target === undefined ) {
  2574. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2575. //target = new Sphere(); // removed to avoid cyclic dependency
  2576. }
  2577. this.getCenter( target.center );
  2578. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  2579. return target;
  2580. }
  2581. intersect( box ) {
  2582. this.min.max( box.min );
  2583. this.max.min( box.max );
  2584. // 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.
  2585. if ( this.isEmpty() ) this.makeEmpty();
  2586. return this;
  2587. }
  2588. union( box ) {
  2589. this.min.min( box.min );
  2590. this.max.max( box.max );
  2591. return this;
  2592. }
  2593. applyMatrix4( matrix ) {
  2594. // transform of empty box is an empty box.
  2595. if ( this.isEmpty() ) return this;
  2596. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2597. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2598. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2599. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2600. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2601. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2602. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2603. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2604. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2605. this.setFromPoints( _points );
  2606. return this;
  2607. }
  2608. translate( offset ) {
  2609. this.min.add( offset );
  2610. this.max.add( offset );
  2611. return this;
  2612. }
  2613. equals( box ) {
  2614. return box.min.equals( this.min ) && box.max.equals( this.max );
  2615. }
  2616. }
  2617. function satForAxes( axes, v0, v1, v2, extents ) {
  2618. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2619. _testAxis.fromArray( axes, i );
  2620. // project the aabb onto the seperating axis
  2621. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  2622. // project all 3 vertices of the triangle onto the seperating axis
  2623. const p0 = v0.dot( _testAxis );
  2624. const p1 = v1.dot( _testAxis );
  2625. const p2 = v2.dot( _testAxis );
  2626. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2627. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2628. // points of the projected triangle are outside the projected half-length of the aabb
  2629. // the axis is seperating and we can exit
  2630. return false;
  2631. }
  2632. }
  2633. return true;
  2634. }
  2635. const _points = [
  2636. /*@__PURE__*/ new Vector3(),
  2637. /*@__PURE__*/ new Vector3(),
  2638. /*@__PURE__*/ new Vector3(),
  2639. /*@__PURE__*/ new Vector3(),
  2640. /*@__PURE__*/ new Vector3(),
  2641. /*@__PURE__*/ new Vector3(),
  2642. /*@__PURE__*/ new Vector3(),
  2643. /*@__PURE__*/ new Vector3()
  2644. ];
  2645. const _vector$1 = /*@__PURE__*/ new Vector3();
  2646. const _box = /*@__PURE__*/ new Box3();
  2647. // triangle centered vertices
  2648. const _v0 = /*@__PURE__*/ new Vector3();
  2649. const _v1 = /*@__PURE__*/ new Vector3();
  2650. const _v2 = /*@__PURE__*/ new Vector3();
  2651. // triangle edge vectors
  2652. const _f0 = /*@__PURE__*/ new Vector3();
  2653. const _f1 = /*@__PURE__*/ new Vector3();
  2654. const _f2 = /*@__PURE__*/ new Vector3();
  2655. const _center = /*@__PURE__*/ new Vector3();
  2656. const _extents = /*@__PURE__*/ new Vector3();
  2657. const _triangleNormal = /*@__PURE__*/ new Vector3();
  2658. const _testAxis = /*@__PURE__*/ new Vector3();
  2659. const _box$1 = /*@__PURE__*/ new Box3();
  2660. class Sphere {
  2661. constructor( center, radius ) {
  2662. this.center = ( center !== undefined ) ? center : new Vector3();
  2663. this.radius = ( radius !== undefined ) ? radius : - 1;
  2664. }
  2665. set( center, radius ) {
  2666. this.center.copy( center );
  2667. this.radius = radius;
  2668. return this;
  2669. }
  2670. setFromPoints( points, optionalCenter ) {
  2671. const center = this.center;
  2672. if ( optionalCenter !== undefined ) {
  2673. center.copy( optionalCenter );
  2674. } else {
  2675. _box$1.setFromPoints( points ).getCenter( center );
  2676. }
  2677. let maxRadiusSq = 0;
  2678. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2679. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2680. }
  2681. this.radius = Math.sqrt( maxRadiusSq );
  2682. return this;
  2683. }
  2684. clone() {
  2685. return new this.constructor().copy( this );
  2686. }
  2687. copy( sphere ) {
  2688. this.center.copy( sphere.center );
  2689. this.radius = sphere.radius;
  2690. return this;
  2691. }
  2692. isEmpty() {
  2693. return ( this.radius < 0 );
  2694. }
  2695. makeEmpty() {
  2696. this.center.set( 0, 0, 0 );
  2697. this.radius = - 1;
  2698. return this;
  2699. }
  2700. containsPoint( point ) {
  2701. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2702. }
  2703. distanceToPoint( point ) {
  2704. return ( point.distanceTo( this.center ) - this.radius );
  2705. }
  2706. intersectsSphere( sphere ) {
  2707. const radiusSum = this.radius + sphere.radius;
  2708. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2709. }
  2710. intersectsBox( box ) {
  2711. return box.intersectsSphere( this );
  2712. }
  2713. intersectsPlane( plane ) {
  2714. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2715. }
  2716. clampPoint( point, target ) {
  2717. const deltaLengthSq = this.center.distanceToSquared( point );
  2718. if ( target === undefined ) {
  2719. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2720. target = new Vector3();
  2721. }
  2722. target.copy( point );
  2723. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2724. target.sub( this.center ).normalize();
  2725. target.multiplyScalar( this.radius ).add( this.center );
  2726. }
  2727. return target;
  2728. }
  2729. getBoundingBox( target ) {
  2730. if ( target === undefined ) {
  2731. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2732. target = new Box3();
  2733. }
  2734. if ( this.isEmpty() ) {
  2735. // Empty sphere produces empty bounding box
  2736. target.makeEmpty();
  2737. return target;
  2738. }
  2739. target.set( this.center, this.center );
  2740. target.expandByScalar( this.radius );
  2741. return target;
  2742. }
  2743. applyMatrix4( matrix ) {
  2744. this.center.applyMatrix4( matrix );
  2745. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2746. return this;
  2747. }
  2748. translate( offset ) {
  2749. this.center.add( offset );
  2750. return this;
  2751. }
  2752. equals( sphere ) {
  2753. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2754. }
  2755. }
  2756. const _vector$2 = /*@__PURE__*/ new Vector3();
  2757. const _segCenter = /*@__PURE__*/ new Vector3();
  2758. const _segDir = /*@__PURE__*/ new Vector3();
  2759. const _diff = /*@__PURE__*/ new Vector3();
  2760. const _edge1 = /*@__PURE__*/ new Vector3();
  2761. const _edge2 = /*@__PURE__*/ new Vector3();
  2762. const _normal = /*@__PURE__*/ new Vector3();
  2763. class Ray {
  2764. constructor( origin, direction ) {
  2765. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  2766. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  2767. }
  2768. set( origin, direction ) {
  2769. this.origin.copy( origin );
  2770. this.direction.copy( direction );
  2771. return this;
  2772. }
  2773. clone() {
  2774. return new this.constructor().copy( this );
  2775. }
  2776. copy( ray ) {
  2777. this.origin.copy( ray.origin );
  2778. this.direction.copy( ray.direction );
  2779. return this;
  2780. }
  2781. at( t, target ) {
  2782. if ( target === undefined ) {
  2783. console.warn( 'THREE.Ray: .at() target is now required' );
  2784. target = new Vector3();
  2785. }
  2786. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  2787. }
  2788. lookAt( v ) {
  2789. this.direction.copy( v ).sub( this.origin ).normalize();
  2790. return this;
  2791. }
  2792. recast( t ) {
  2793. this.origin.copy( this.at( t, _vector$2 ) );
  2794. return this;
  2795. }
  2796. closestPointToPoint( point, target ) {
  2797. if ( target === undefined ) {
  2798. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  2799. target = new Vector3();
  2800. }
  2801. target.subVectors( point, this.origin );
  2802. const directionDistance = target.dot( this.direction );
  2803. if ( directionDistance < 0 ) {
  2804. return target.copy( this.origin );
  2805. }
  2806. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2807. }
  2808. distanceToPoint( point ) {
  2809. return Math.sqrt( this.distanceSqToPoint( point ) );
  2810. }
  2811. distanceSqToPoint( point ) {
  2812. const directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  2813. // point behind the ray
  2814. if ( directionDistance < 0 ) {
  2815. return this.origin.distanceToSquared( point );
  2816. }
  2817. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2818. return _vector$2.distanceToSquared( point );
  2819. }
  2820. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  2821. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  2822. // It returns the min distance between the ray and the segment
  2823. // defined by v0 and v1
  2824. // It can also set two optional targets :
  2825. // - The closest point on the ray
  2826. // - The closest point on the segment
  2827. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  2828. _segDir.copy( v1 ).sub( v0 ).normalize();
  2829. _diff.copy( this.origin ).sub( _segCenter );
  2830. const segExtent = v0.distanceTo( v1 ) * 0.5;
  2831. const a01 = - this.direction.dot( _segDir );
  2832. const b0 = _diff.dot( this.direction );
  2833. const b1 = - _diff.dot( _segDir );
  2834. const c = _diff.lengthSq();
  2835. const det = Math.abs( 1 - a01 * a01 );
  2836. let s0, s1, sqrDist, extDet;
  2837. if ( det > 0 ) {
  2838. // The ray and segment are not parallel.
  2839. s0 = a01 * b1 - b0;
  2840. s1 = a01 * b0 - b1;
  2841. extDet = segExtent * det;
  2842. if ( s0 >= 0 ) {
  2843. if ( s1 >= - extDet ) {
  2844. if ( s1 <= extDet ) {
  2845. // region 0
  2846. // Minimum at interior points of ray and segment.
  2847. const invDet = 1 / det;
  2848. s0 *= invDet;
  2849. s1 *= invDet;
  2850. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  2851. } else {
  2852. // region 1
  2853. s1 = segExtent;
  2854. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2855. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2856. }
  2857. } else {
  2858. // region 5
  2859. s1 = - segExtent;
  2860. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2861. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2862. }
  2863. } else {
  2864. if ( s1 <= - extDet ) {
  2865. // region 4
  2866. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  2867. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2868. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2869. } else if ( s1 <= extDet ) {
  2870. // region 3
  2871. s0 = 0;
  2872. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2873. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  2874. } else {
  2875. // region 2
  2876. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  2877. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2878. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2879. }
  2880. }
  2881. } else {
  2882. // Ray and segment are parallel.
  2883. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  2884. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2885. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2886. }
  2887. if ( optionalPointOnRay ) {
  2888. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  2889. }
  2890. if ( optionalPointOnSegment ) {
  2891. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  2892. }
  2893. return sqrDist;
  2894. }
  2895. intersectSphere( sphere, target ) {
  2896. _vector$2.subVectors( sphere.center, this.origin );
  2897. const tca = _vector$2.dot( this.direction );
  2898. const d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  2899. const radius2 = sphere.radius * sphere.radius;
  2900. if ( d2 > radius2 ) return null;
  2901. const thc = Math.sqrt( radius2 - d2 );
  2902. // t0 = first intersect point - entrance on front of sphere
  2903. const t0 = tca - thc;
  2904. // t1 = second intersect point - exit point on back of sphere
  2905. const t1 = tca + thc;
  2906. // test to see if both t0 and t1 are behind the ray - if so, return null
  2907. if ( t0 < 0 && t1 < 0 ) return null;
  2908. // test to see if t0 is behind the ray:
  2909. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  2910. // in order to always return an intersect point that is in front of the ray.
  2911. if ( t0 < 0 ) return this.at( t1, target );
  2912. // else t0 is in front of the ray, so return the first collision point scaled by t0
  2913. return this.at( t0, target );
  2914. }
  2915. intersectsSphere( sphere ) {
  2916. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  2917. }
  2918. distanceToPlane( plane ) {
  2919. const denominator = plane.normal.dot( this.direction );
  2920. if ( denominator === 0 ) {
  2921. // line is coplanar, return origin
  2922. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  2923. return 0;
  2924. }
  2925. // Null is preferable to undefined since undefined means.... it is undefined
  2926. return null;
  2927. }
  2928. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  2929. // Return if the ray never intersects the plane
  2930. return t >= 0 ? t : null;
  2931. }
  2932. intersectPlane( plane, target ) {
  2933. const t = this.distanceToPlane( plane );
  2934. if ( t === null ) {
  2935. return null;
  2936. }
  2937. return this.at( t, target );
  2938. }
  2939. intersectsPlane( plane ) {
  2940. // check if the ray lies on the plane first
  2941. const distToPoint = plane.distanceToPoint( this.origin );
  2942. if ( distToPoint === 0 ) {
  2943. return true;
  2944. }
  2945. const denominator = plane.normal.dot( this.direction );
  2946. if ( denominator * distToPoint < 0 ) {
  2947. return true;
  2948. }
  2949. // ray origin is behind the plane (and is pointing behind it)
  2950. return false;
  2951. }
  2952. intersectBox( box, target ) {
  2953. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  2954. const invdirx = 1 / this.direction.x,
  2955. invdiry = 1 / this.direction.y,
  2956. invdirz = 1 / this.direction.z;
  2957. const origin = this.origin;
  2958. if ( invdirx >= 0 ) {
  2959. tmin = ( box.min.x - origin.x ) * invdirx;
  2960. tmax = ( box.max.x - origin.x ) * invdirx;
  2961. } else {
  2962. tmin = ( box.max.x - origin.x ) * invdirx;
  2963. tmax = ( box.min.x - origin.x ) * invdirx;
  2964. }
  2965. if ( invdiry >= 0 ) {
  2966. tymin = ( box.min.y - origin.y ) * invdiry;
  2967. tymax = ( box.max.y - origin.y ) * invdiry;
  2968. } else {
  2969. tymin = ( box.max.y - origin.y ) * invdiry;
  2970. tymax = ( box.min.y - origin.y ) * invdiry;
  2971. }
  2972. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  2973. // These lines also handle the case where tmin or tmax is NaN
  2974. // (result of 0 * Infinity). x !== x returns true if x is NaN
  2975. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  2976. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  2977. if ( invdirz >= 0 ) {
  2978. tzmin = ( box.min.z - origin.z ) * invdirz;
  2979. tzmax = ( box.max.z - origin.z ) * invdirz;
  2980. } else {
  2981. tzmin = ( box.max.z - origin.z ) * invdirz;
  2982. tzmax = ( box.min.z - origin.z ) * invdirz;
  2983. }
  2984. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  2985. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  2986. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  2987. //return point closest to the ray (positive side)
  2988. if ( tmax < 0 ) return null;
  2989. return this.at( tmin >= 0 ? tmin : tmax, target );
  2990. }
  2991. intersectsBox( box ) {
  2992. return this.intersectBox( box, _vector$2 ) !== null;
  2993. }
  2994. intersectTriangle( a, b, c, backfaceCulling, target ) {
  2995. // Compute the offset origin, edges, and normal.
  2996. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  2997. _edge1.subVectors( b, a );
  2998. _edge2.subVectors( c, a );
  2999. _normal.crossVectors( _edge1, _edge2 );
  3000. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3001. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3002. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3003. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3004. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3005. let DdN = this.direction.dot( _normal );
  3006. let sign;
  3007. if ( DdN > 0 ) {
  3008. if ( backfaceCulling ) return null;
  3009. sign = 1;
  3010. } else if ( DdN < 0 ) {
  3011. sign = - 1;
  3012. DdN = - DdN;
  3013. } else {
  3014. return null;
  3015. }
  3016. _diff.subVectors( this.origin, a );
  3017. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3018. // b1 < 0, no intersection
  3019. if ( DdQxE2 < 0 ) {
  3020. return null;
  3021. }
  3022. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3023. // b2 < 0, no intersection
  3024. if ( DdE1xQ < 0 ) {
  3025. return null;
  3026. }
  3027. // b1+b2 > 1, no intersection
  3028. if ( DdQxE2 + DdE1xQ > DdN ) {
  3029. return null;
  3030. }
  3031. // Line intersects triangle, check if ray does.
  3032. const QdN = - sign * _diff.dot( _normal );
  3033. // t < 0, no intersection
  3034. if ( QdN < 0 ) {
  3035. return null;
  3036. }
  3037. // Ray intersects triangle.
  3038. return this.at( QdN / DdN, target );
  3039. }
  3040. applyMatrix4( matrix4 ) {
  3041. this.origin.applyMatrix4( matrix4 );
  3042. this.direction.transformDirection( matrix4 );
  3043. return this;
  3044. }
  3045. equals( ray ) {
  3046. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3047. }
  3048. }
  3049. class Matrix4 {
  3050. constructor() {
  3051. Object.defineProperty( this, 'isMatrix4', { value: true } );
  3052. this.elements = [
  3053. 1, 0, 0, 0,
  3054. 0, 1, 0, 0,
  3055. 0, 0, 1, 0,
  3056. 0, 0, 0, 1
  3057. ];
  3058. if ( arguments.length > 0 ) {
  3059. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3060. }
  3061. }
  3062. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3063. const te = this.elements;
  3064. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3065. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3066. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3067. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3068. return this;
  3069. }
  3070. identity() {
  3071. this.set(
  3072. 1, 0, 0, 0,
  3073. 0, 1, 0, 0,
  3074. 0, 0, 1, 0,
  3075. 0, 0, 0, 1
  3076. );
  3077. return this;
  3078. }
  3079. clone() {
  3080. return new Matrix4().fromArray( this.elements );
  3081. }
  3082. copy( m ) {
  3083. const te = this.elements;
  3084. const me = m.elements;
  3085. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3086. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3087. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3088. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3089. return this;
  3090. }
  3091. copyPosition( m ) {
  3092. const te = this.elements, me = m.elements;
  3093. te[ 12 ] = me[ 12 ];
  3094. te[ 13 ] = me[ 13 ];
  3095. te[ 14 ] = me[ 14 ];
  3096. return this;
  3097. }
  3098. setFromMatrix3( m ) {
  3099. const me = m.elements;
  3100. this.set(
  3101. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3102. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3103. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3104. 0, 0, 0, 1
  3105. );
  3106. return this;
  3107. }
  3108. extractBasis( xAxis, yAxis, zAxis ) {
  3109. xAxis.setFromMatrixColumn( this, 0 );
  3110. yAxis.setFromMatrixColumn( this, 1 );
  3111. zAxis.setFromMatrixColumn( this, 2 );
  3112. return this;
  3113. }
  3114. makeBasis( xAxis, yAxis, zAxis ) {
  3115. this.set(
  3116. xAxis.x, yAxis.x, zAxis.x, 0,
  3117. xAxis.y, yAxis.y, zAxis.y, 0,
  3118. xAxis.z, yAxis.z, zAxis.z, 0,
  3119. 0, 0, 0, 1
  3120. );
  3121. return this;
  3122. }
  3123. extractRotation( m ) {
  3124. // this method does not support reflection matrices
  3125. const te = this.elements;
  3126. const me = m.elements;
  3127. const scaleX = 1 / _v1$1.setFromMatrixColumn( m, 0 ).length();
  3128. const scaleY = 1 / _v1$1.setFromMatrixColumn( m, 1 ).length();
  3129. const scaleZ = 1 / _v1$1.setFromMatrixColumn( m, 2 ).length();
  3130. te[ 0 ] = me[ 0 ] * scaleX;
  3131. te[ 1 ] = me[ 1 ] * scaleX;
  3132. te[ 2 ] = me[ 2 ] * scaleX;
  3133. te[ 3 ] = 0;
  3134. te[ 4 ] = me[ 4 ] * scaleY;
  3135. te[ 5 ] = me[ 5 ] * scaleY;
  3136. te[ 6 ] = me[ 6 ] * scaleY;
  3137. te[ 7 ] = 0;
  3138. te[ 8 ] = me[ 8 ] * scaleZ;
  3139. te[ 9 ] = me[ 9 ] * scaleZ;
  3140. te[ 10 ] = me[ 10 ] * scaleZ;
  3141. te[ 11 ] = 0;
  3142. te[ 12 ] = 0;
  3143. te[ 13 ] = 0;
  3144. te[ 14 ] = 0;
  3145. te[ 15 ] = 1;
  3146. return this;
  3147. }
  3148. makeRotationFromEuler( euler ) {
  3149. if ( ! ( euler && euler.isEuler ) ) {
  3150. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3151. }
  3152. const te = this.elements;
  3153. const x = euler.x, y = euler.y, z = euler.z;
  3154. const a = Math.cos( x ), b = Math.sin( x );
  3155. const c = Math.cos( y ), d = Math.sin( y );
  3156. const e = Math.cos( z ), f = Math.sin( z );
  3157. if ( euler.order === 'XYZ' ) {
  3158. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3159. te[ 0 ] = c * e;
  3160. te[ 4 ] = - c * f;
  3161. te[ 8 ] = d;
  3162. te[ 1 ] = af + be * d;
  3163. te[ 5 ] = ae - bf * d;
  3164. te[ 9 ] = - b * c;
  3165. te[ 2 ] = bf - ae * d;
  3166. te[ 6 ] = be + af * d;
  3167. te[ 10 ] = a * c;
  3168. } else if ( euler.order === 'YXZ' ) {
  3169. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3170. te[ 0 ] = ce + df * b;
  3171. te[ 4 ] = de * b - cf;
  3172. te[ 8 ] = a * d;
  3173. te[ 1 ] = a * f;
  3174. te[ 5 ] = a * e;
  3175. te[ 9 ] = - b;
  3176. te[ 2 ] = cf * b - de;
  3177. te[ 6 ] = df + ce * b;
  3178. te[ 10 ] = a * c;
  3179. } else if ( euler.order === 'ZXY' ) {
  3180. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3181. te[ 0 ] = ce - df * b;
  3182. te[ 4 ] = - a * f;
  3183. te[ 8 ] = de + cf * b;
  3184. te[ 1 ] = cf + de * b;
  3185. te[ 5 ] = a * e;
  3186. te[ 9 ] = df - ce * b;
  3187. te[ 2 ] = - a * d;
  3188. te[ 6 ] = b;
  3189. te[ 10 ] = a * c;
  3190. } else if ( euler.order === 'ZYX' ) {
  3191. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3192. te[ 0 ] = c * e;
  3193. te[ 4 ] = be * d - af;
  3194. te[ 8 ] = ae * d + bf;
  3195. te[ 1 ] = c * f;
  3196. te[ 5 ] = bf * d + ae;
  3197. te[ 9 ] = af * d - be;
  3198. te[ 2 ] = - d;
  3199. te[ 6 ] = b * c;
  3200. te[ 10 ] = a * c;
  3201. } else if ( euler.order === 'YZX' ) {
  3202. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3203. te[ 0 ] = c * e;
  3204. te[ 4 ] = bd - ac * f;
  3205. te[ 8 ] = bc * f + ad;
  3206. te[ 1 ] = f;
  3207. te[ 5 ] = a * e;
  3208. te[ 9 ] = - b * e;
  3209. te[ 2 ] = - d * e;
  3210. te[ 6 ] = ad * f + bc;
  3211. te[ 10 ] = ac - bd * f;
  3212. } else if ( euler.order === 'XZY' ) {
  3213. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3214. te[ 0 ] = c * e;
  3215. te[ 4 ] = - f;
  3216. te[ 8 ] = d * e;
  3217. te[ 1 ] = ac * f + bd;
  3218. te[ 5 ] = a * e;
  3219. te[ 9 ] = ad * f - bc;
  3220. te[ 2 ] = bc * f - ad;
  3221. te[ 6 ] = b * e;
  3222. te[ 10 ] = bd * f + ac;
  3223. }
  3224. // bottom row
  3225. te[ 3 ] = 0;
  3226. te[ 7 ] = 0;
  3227. te[ 11 ] = 0;
  3228. // last column
  3229. te[ 12 ] = 0;
  3230. te[ 13 ] = 0;
  3231. te[ 14 ] = 0;
  3232. te[ 15 ] = 1;
  3233. return this;
  3234. }
  3235. makeRotationFromQuaternion( q ) {
  3236. return this.compose( _zero, q, _one );
  3237. }
  3238. lookAt( eye, target, up ) {
  3239. const te = this.elements;
  3240. _z.subVectors( eye, target );
  3241. if ( _z.lengthSq() === 0 ) {
  3242. // eye and target are in the same position
  3243. _z.z = 1;
  3244. }
  3245. _z.normalize();
  3246. _x.crossVectors( up, _z );
  3247. if ( _x.lengthSq() === 0 ) {
  3248. // up and z are parallel
  3249. if ( Math.abs( up.z ) === 1 ) {
  3250. _z.x += 0.0001;
  3251. } else {
  3252. _z.z += 0.0001;
  3253. }
  3254. _z.normalize();
  3255. _x.crossVectors( up, _z );
  3256. }
  3257. _x.normalize();
  3258. _y.crossVectors( _z, _x );
  3259. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3260. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3261. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3262. return this;
  3263. }
  3264. multiply( m, n ) {
  3265. if ( n !== undefined ) {
  3266. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3267. return this.multiplyMatrices( m, n );
  3268. }
  3269. return this.multiplyMatrices( this, m );
  3270. }
  3271. premultiply( m ) {
  3272. return this.multiplyMatrices( m, this );
  3273. }
  3274. multiplyMatrices( a, b ) {
  3275. const ae = a.elements;
  3276. const be = b.elements;
  3277. const te = this.elements;
  3278. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3279. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3280. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3281. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3282. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3283. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3284. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3285. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3286. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3287. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3288. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3289. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3290. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3291. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3292. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3293. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3294. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3295. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3296. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3297. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3298. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3299. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3300. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3301. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3302. return this;
  3303. }
  3304. multiplyScalar( s ) {
  3305. const te = this.elements;
  3306. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3307. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3308. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3309. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3310. return this;
  3311. }
  3312. determinant() {
  3313. const te = this.elements;
  3314. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3315. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3316. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3317. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3318. //TODO: make this more efficient
  3319. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3320. return (
  3321. n41 * (
  3322. + n14 * n23 * n32
  3323. - n13 * n24 * n32
  3324. - n14 * n22 * n33
  3325. + n12 * n24 * n33
  3326. + n13 * n22 * n34
  3327. - n12 * n23 * n34
  3328. ) +
  3329. n42 * (
  3330. + n11 * n23 * n34
  3331. - n11 * n24 * n33
  3332. + n14 * n21 * n33
  3333. - n13 * n21 * n34
  3334. + n13 * n24 * n31
  3335. - n14 * n23 * n31
  3336. ) +
  3337. n43 * (
  3338. + n11 * n24 * n32
  3339. - n11 * n22 * n34
  3340. - n14 * n21 * n32
  3341. + n12 * n21 * n34
  3342. + n14 * n22 * n31
  3343. - n12 * n24 * n31
  3344. ) +
  3345. n44 * (
  3346. - n13 * n22 * n31
  3347. - n11 * n23 * n32
  3348. + n11 * n22 * n33
  3349. + n13 * n21 * n32
  3350. - n12 * n21 * n33
  3351. + n12 * n23 * n31
  3352. )
  3353. );
  3354. }
  3355. transpose() {
  3356. const te = this.elements;
  3357. let tmp;
  3358. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3359. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3360. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3361. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3362. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3363. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3364. return this;
  3365. }
  3366. setPosition( x, y, z ) {
  3367. const te = this.elements;
  3368. if ( x.isVector3 ) {
  3369. te[ 12 ] = x.x;
  3370. te[ 13 ] = x.y;
  3371. te[ 14 ] = x.z;
  3372. } else {
  3373. te[ 12 ] = x;
  3374. te[ 13 ] = y;
  3375. te[ 14 ] = z;
  3376. }
  3377. return this;
  3378. }
  3379. invert() {
  3380. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3381. const te = this.elements,
  3382. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3383. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3384. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3385. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3386. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3387. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3388. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3389. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3390. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3391. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3392. const detInv = 1 / det;
  3393. te[ 0 ] = t11 * detInv;
  3394. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3395. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3396. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3397. te[ 4 ] = t12 * detInv;
  3398. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3399. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3400. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3401. te[ 8 ] = t13 * detInv;
  3402. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3403. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3404. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3405. te[ 12 ] = t14 * detInv;
  3406. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3407. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3408. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3409. return this;
  3410. }
  3411. scale( v ) {
  3412. const te = this.elements;
  3413. const x = v.x, y = v.y, z = v.z;
  3414. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3415. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3416. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3417. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3418. return this;
  3419. }
  3420. getMaxScaleOnAxis() {
  3421. const te = this.elements;
  3422. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3423. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3424. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3425. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3426. }
  3427. makeTranslation( x, y, z ) {
  3428. this.set(
  3429. 1, 0, 0, x,
  3430. 0, 1, 0, y,
  3431. 0, 0, 1, z,
  3432. 0, 0, 0, 1
  3433. );
  3434. return this;
  3435. }
  3436. makeRotationX( theta ) {
  3437. const c = Math.cos( theta ), s = Math.sin( theta );
  3438. this.set(
  3439. 1, 0, 0, 0,
  3440. 0, c, - s, 0,
  3441. 0, s, c, 0,
  3442. 0, 0, 0, 1
  3443. );
  3444. return this;
  3445. }
  3446. makeRotationY( theta ) {
  3447. const c = Math.cos( theta ), s = Math.sin( theta );
  3448. this.set(
  3449. c, 0, s, 0,
  3450. 0, 1, 0, 0,
  3451. - s, 0, c, 0,
  3452. 0, 0, 0, 1
  3453. );
  3454. return this;
  3455. }
  3456. makeRotationZ( theta ) {
  3457. const c = Math.cos( theta ), s = Math.sin( theta );
  3458. this.set(
  3459. c, - s, 0, 0,
  3460. s, c, 0, 0,
  3461. 0, 0, 1, 0,
  3462. 0, 0, 0, 1
  3463. );
  3464. return this;
  3465. }
  3466. makeRotationAxis( axis, angle ) {
  3467. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3468. const c = Math.cos( angle );
  3469. const s = Math.sin( angle );
  3470. const t = 1 - c;
  3471. const x = axis.x, y = axis.y, z = axis.z;
  3472. const tx = t * x, ty = t * y;
  3473. this.set(
  3474. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3475. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3476. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3477. 0, 0, 0, 1
  3478. );
  3479. return this;
  3480. }
  3481. makeScale( x, y, z ) {
  3482. this.set(
  3483. x, 0, 0, 0,
  3484. 0, y, 0, 0,
  3485. 0, 0, z, 0,
  3486. 0, 0, 0, 1
  3487. );
  3488. return this;
  3489. }
  3490. makeShear( x, y, z ) {
  3491. this.set(
  3492. 1, y, z, 0,
  3493. x, 1, z, 0,
  3494. x, y, 1, 0,
  3495. 0, 0, 0, 1
  3496. );
  3497. return this;
  3498. }
  3499. compose( position, quaternion, scale ) {
  3500. const te = this.elements;
  3501. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3502. const x2 = x + x, y2 = y + y, z2 = z + z;
  3503. const xx = x * x2, xy = x * y2, xz = x * z2;
  3504. const yy = y * y2, yz = y * z2, zz = z * z2;
  3505. const wx = w * x2, wy = w * y2, wz = w * z2;
  3506. const sx = scale.x, sy = scale.y, sz = scale.z;
  3507. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3508. te[ 1 ] = ( xy + wz ) * sx;
  3509. te[ 2 ] = ( xz - wy ) * sx;
  3510. te[ 3 ] = 0;
  3511. te[ 4 ] = ( xy - wz ) * sy;
  3512. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3513. te[ 6 ] = ( yz + wx ) * sy;
  3514. te[ 7 ] = 0;
  3515. te[ 8 ] = ( xz + wy ) * sz;
  3516. te[ 9 ] = ( yz - wx ) * sz;
  3517. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3518. te[ 11 ] = 0;
  3519. te[ 12 ] = position.x;
  3520. te[ 13 ] = position.y;
  3521. te[ 14 ] = position.z;
  3522. te[ 15 ] = 1;
  3523. return this;
  3524. }
  3525. decompose( position, quaternion, scale ) {
  3526. const te = this.elements;
  3527. let sx = _v1$1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3528. const sy = _v1$1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3529. const sz = _v1$1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3530. // if determine is negative, we need to invert one scale
  3531. const det = this.determinant();
  3532. if ( det < 0 ) sx = - sx;
  3533. position.x = te[ 12 ];
  3534. position.y = te[ 13 ];
  3535. position.z = te[ 14 ];
  3536. // scale the rotation part
  3537. _m1.copy( this );
  3538. const invSX = 1 / sx;
  3539. const invSY = 1 / sy;
  3540. const invSZ = 1 / sz;
  3541. _m1.elements[ 0 ] *= invSX;
  3542. _m1.elements[ 1 ] *= invSX;
  3543. _m1.elements[ 2 ] *= invSX;
  3544. _m1.elements[ 4 ] *= invSY;
  3545. _m1.elements[ 5 ] *= invSY;
  3546. _m1.elements[ 6 ] *= invSY;
  3547. _m1.elements[ 8 ] *= invSZ;
  3548. _m1.elements[ 9 ] *= invSZ;
  3549. _m1.elements[ 10 ] *= invSZ;
  3550. quaternion.setFromRotationMatrix( _m1 );
  3551. scale.x = sx;
  3552. scale.y = sy;
  3553. scale.z = sz;
  3554. return this;
  3555. }
  3556. makePerspective( left, right, top, bottom, near, far ) {
  3557. if ( far === undefined ) {
  3558. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3559. }
  3560. const te = this.elements;
  3561. const x = 2 * near / ( right - left );
  3562. const y = 2 * near / ( top - bottom );
  3563. const a = ( right + left ) / ( right - left );
  3564. const b = ( top + bottom ) / ( top - bottom );
  3565. const c = - ( far + near ) / ( far - near );
  3566. const d = - 2 * far * near / ( far - near );
  3567. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3568. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3569. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3570. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3571. return this;
  3572. }
  3573. makeOrthographic( left, right, top, bottom, near, far ) {
  3574. const te = this.elements;
  3575. const w = 1.0 / ( right - left );
  3576. const h = 1.0 / ( top - bottom );
  3577. const p = 1.0 / ( far - near );
  3578. const x = ( right + left ) * w;
  3579. const y = ( top + bottom ) * h;
  3580. const z = ( far + near ) * p;
  3581. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3582. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3583. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3584. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3585. return this;
  3586. }
  3587. equals( matrix ) {
  3588. const te = this.elements;
  3589. const me = matrix.elements;
  3590. for ( let i = 0; i < 16; i ++ ) {
  3591. if ( te[ i ] !== me[ i ] ) return false;
  3592. }
  3593. return true;
  3594. }
  3595. fromArray( array, offset = 0 ) {
  3596. for ( let i = 0; i < 16; i ++ ) {
  3597. this.elements[ i ] = array[ i + offset ];
  3598. }
  3599. return this;
  3600. }
  3601. toArray( array = [], offset = 0 ) {
  3602. const te = this.elements;
  3603. array[ offset ] = te[ 0 ];
  3604. array[ offset + 1 ] = te[ 1 ];
  3605. array[ offset + 2 ] = te[ 2 ];
  3606. array[ offset + 3 ] = te[ 3 ];
  3607. array[ offset + 4 ] = te[ 4 ];
  3608. array[ offset + 5 ] = te[ 5 ];
  3609. array[ offset + 6 ] = te[ 6 ];
  3610. array[ offset + 7 ] = te[ 7 ];
  3611. array[ offset + 8 ] = te[ 8 ];
  3612. array[ offset + 9 ] = te[ 9 ];
  3613. array[ offset + 10 ] = te[ 10 ];
  3614. array[ offset + 11 ] = te[ 11 ];
  3615. array[ offset + 12 ] = te[ 12 ];
  3616. array[ offset + 13 ] = te[ 13 ];
  3617. array[ offset + 14 ] = te[ 14 ];
  3618. array[ offset + 15 ] = te[ 15 ];
  3619. return array;
  3620. }
  3621. }
  3622. const _v1$1 = /*@__PURE__*/ new Vector3();
  3623. const _m1 = /*@__PURE__*/ new Matrix4();
  3624. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  3625. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  3626. const _x = /*@__PURE__*/ new Vector3();
  3627. const _y = /*@__PURE__*/ new Vector3();
  3628. const _z = /*@__PURE__*/ new Vector3();
  3629. class Euler {
  3630. constructor( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
  3631. Object.defineProperty( this, 'isEuler', { value: true } );
  3632. this._x = x;
  3633. this._y = y;
  3634. this._z = z;
  3635. this._order = order;
  3636. }
  3637. get x() {
  3638. return this._x;
  3639. }
  3640. set x( value ) {
  3641. this._x = value;
  3642. this._onChangeCallback();
  3643. }
  3644. get y() {
  3645. return this._y;
  3646. }
  3647. set y( value ) {
  3648. this._y = value;
  3649. this._onChangeCallback();
  3650. }
  3651. get z() {
  3652. return this._z;
  3653. }
  3654. set z( value ) {
  3655. this._z = value;
  3656. this._onChangeCallback();
  3657. }
  3658. get order() {
  3659. return this._order;
  3660. }
  3661. set order( value ) {
  3662. this._order = value;
  3663. this._onChangeCallback();
  3664. }
  3665. set( x, y, z, order ) {
  3666. this._x = x;
  3667. this._y = y;
  3668. this._z = z;
  3669. this._order = order || this._order;
  3670. this._onChangeCallback();
  3671. return this;
  3672. }
  3673. clone() {
  3674. return new this.constructor( this._x, this._y, this._z, this._order );
  3675. }
  3676. copy( euler ) {
  3677. this._x = euler._x;
  3678. this._y = euler._y;
  3679. this._z = euler._z;
  3680. this._order = euler._order;
  3681. this._onChangeCallback();
  3682. return this;
  3683. }
  3684. setFromRotationMatrix( m, order, update ) {
  3685. const clamp = MathUtils.clamp;
  3686. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3687. const te = m.elements;
  3688. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3689. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3690. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3691. order = order || this._order;
  3692. switch ( order ) {
  3693. case 'XYZ':
  3694. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3695. if ( Math.abs( m13 ) < 0.9999999 ) {
  3696. this._x = Math.atan2( - m23, m33 );
  3697. this._z = Math.atan2( - m12, m11 );
  3698. } else {
  3699. this._x = Math.atan2( m32, m22 );
  3700. this._z = 0;
  3701. }
  3702. break;
  3703. case 'YXZ':
  3704. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3705. if ( Math.abs( m23 ) < 0.9999999 ) {
  3706. this._y = Math.atan2( m13, m33 );
  3707. this._z = Math.atan2( m21, m22 );
  3708. } else {
  3709. this._y = Math.atan2( - m31, m11 );
  3710. this._z = 0;
  3711. }
  3712. break;
  3713. case 'ZXY':
  3714. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3715. if ( Math.abs( m32 ) < 0.9999999 ) {
  3716. this._y = Math.atan2( - m31, m33 );
  3717. this._z = Math.atan2( - m12, m22 );
  3718. } else {
  3719. this._y = 0;
  3720. this._z = Math.atan2( m21, m11 );
  3721. }
  3722. break;
  3723. case 'ZYX':
  3724. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3725. if ( Math.abs( m31 ) < 0.9999999 ) {
  3726. this._x = Math.atan2( m32, m33 );
  3727. this._z = Math.atan2( m21, m11 );
  3728. } else {
  3729. this._x = 0;
  3730. this._z = Math.atan2( - m12, m22 );
  3731. }
  3732. break;
  3733. case 'YZX':
  3734. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3735. if ( Math.abs( m21 ) < 0.9999999 ) {
  3736. this._x = Math.atan2( - m23, m22 );
  3737. this._y = Math.atan2( - m31, m11 );
  3738. } else {
  3739. this._x = 0;
  3740. this._y = Math.atan2( m13, m33 );
  3741. }
  3742. break;
  3743. case 'XZY':
  3744. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3745. if ( Math.abs( m12 ) < 0.9999999 ) {
  3746. this._x = Math.atan2( m32, m22 );
  3747. this._y = Math.atan2( m13, m11 );
  3748. } else {
  3749. this._x = Math.atan2( - m23, m33 );
  3750. this._y = 0;
  3751. }
  3752. break;
  3753. default:
  3754. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3755. }
  3756. this._order = order;
  3757. if ( update !== false ) this._onChangeCallback();
  3758. return this;
  3759. }
  3760. setFromQuaternion( q, order, update ) {
  3761. _matrix.makeRotationFromQuaternion( q );
  3762. return this.setFromRotationMatrix( _matrix, order, update );
  3763. }
  3764. setFromVector3( v, order ) {
  3765. return this.set( v.x, v.y, v.z, order || this._order );
  3766. }
  3767. reorder( newOrder ) {
  3768. // WARNING: this discards revolution information -bhouston
  3769. _quaternion$1.setFromEuler( this );
  3770. return this.setFromQuaternion( _quaternion$1, newOrder );
  3771. }
  3772. equals( euler ) {
  3773. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3774. }
  3775. fromArray( array ) {
  3776. this._x = array[ 0 ];
  3777. this._y = array[ 1 ];
  3778. this._z = array[ 2 ];
  3779. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3780. this._onChangeCallback();
  3781. return this;
  3782. }
  3783. toArray( array = [], offset = 0 ) {
  3784. array[ offset ] = this._x;
  3785. array[ offset + 1 ] = this._y;
  3786. array[ offset + 2 ] = this._z;
  3787. array[ offset + 3 ] = this._order;
  3788. return array;
  3789. }
  3790. toVector3( optionalResult ) {
  3791. if ( optionalResult ) {
  3792. return optionalResult.set( this._x, this._y, this._z );
  3793. } else {
  3794. return new Vector3( this._x, this._y, this._z );
  3795. }
  3796. }
  3797. _onChange( callback ) {
  3798. this._onChangeCallback = callback;
  3799. return this;
  3800. }
  3801. _onChangeCallback() {}
  3802. }
  3803. Euler.DefaultOrder = 'XYZ';
  3804. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3805. const _matrix = /*@__PURE__*/ new Matrix4();
  3806. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  3807. class Layers {
  3808. constructor() {
  3809. this.mask = 1 | 0;
  3810. }
  3811. set( channel ) {
  3812. this.mask = 1 << channel | 0;
  3813. }
  3814. enable( channel ) {
  3815. this.mask |= 1 << channel | 0;
  3816. }
  3817. enableAll() {
  3818. this.mask = 0xffffffff | 0;
  3819. }
  3820. toggle( channel ) {
  3821. this.mask ^= 1 << channel | 0;
  3822. }
  3823. disable( channel ) {
  3824. this.mask &= ~ ( 1 << channel | 0 );
  3825. }
  3826. disableAll() {
  3827. this.mask = 0;
  3828. }
  3829. test( layers ) {
  3830. return ( this.mask & layers.mask ) !== 0;
  3831. }
  3832. }
  3833. let _object3DId = 0;
  3834. const _v1$2 = new Vector3();
  3835. const _q1 = new Quaternion();
  3836. const _m1$1 = new Matrix4();
  3837. const _target = new Vector3();
  3838. const _position = new Vector3();
  3839. const _scale = new Vector3();
  3840. const _quaternion$2 = new Quaternion();
  3841. const _xAxis = new Vector3( 1, 0, 0 );
  3842. const _yAxis = new Vector3( 0, 1, 0 );
  3843. const _zAxis = new Vector3( 0, 0, 1 );
  3844. const _addedEvent = { type: 'added' };
  3845. const _removedEvent = { type: 'removed' };
  3846. function Object3D() {
  3847. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3848. this.uuid = MathUtils.generateUUID();
  3849. this.name = '';
  3850. this.type = 'Object3D';
  3851. this.parent = null;
  3852. this.children = [];
  3853. this.up = Object3D.DefaultUp.clone();
  3854. const position = new Vector3();
  3855. const rotation = new Euler();
  3856. const quaternion = new Quaternion();
  3857. const scale = new Vector3( 1, 1, 1 );
  3858. function onRotationChange() {
  3859. quaternion.setFromEuler( rotation, false );
  3860. }
  3861. function onQuaternionChange() {
  3862. rotation.setFromQuaternion( quaternion, undefined, false );
  3863. }
  3864. rotation._onChange( onRotationChange );
  3865. quaternion._onChange( onQuaternionChange );
  3866. Object.defineProperties( this, {
  3867. position: {
  3868. configurable: true,
  3869. enumerable: true,
  3870. value: position
  3871. },
  3872. rotation: {
  3873. configurable: true,
  3874. enumerable: true,
  3875. value: rotation
  3876. },
  3877. quaternion: {
  3878. configurable: true,
  3879. enumerable: true,
  3880. value: quaternion
  3881. },
  3882. scale: {
  3883. configurable: true,
  3884. enumerable: true,
  3885. value: scale
  3886. },
  3887. modelViewMatrix: {
  3888. value: new Matrix4()
  3889. },
  3890. normalMatrix: {
  3891. value: new Matrix3()
  3892. }
  3893. } );
  3894. this.matrix = new Matrix4();
  3895. this.matrixWorld = new Matrix4();
  3896. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3897. this.matrixWorldNeedsUpdate = false;
  3898. this.layers = new Layers();
  3899. this.visible = true;
  3900. this.castShadow = false;
  3901. this.receiveShadow = false;
  3902. this.frustumCulled = true;
  3903. this.renderOrder = 0;
  3904. this.animations = [];
  3905. this.userData = {};
  3906. }
  3907. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3908. Object3D.DefaultMatrixAutoUpdate = true;
  3909. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3910. constructor: Object3D,
  3911. isObject3D: true,
  3912. onBeforeRender: function () {},
  3913. onAfterRender: function () {},
  3914. applyMatrix4: function ( matrix ) {
  3915. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3916. this.matrix.premultiply( matrix );
  3917. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3918. },
  3919. applyQuaternion: function ( q ) {
  3920. this.quaternion.premultiply( q );
  3921. return this;
  3922. },
  3923. setRotationFromAxisAngle: function ( axis, angle ) {
  3924. // assumes axis is normalized
  3925. this.quaternion.setFromAxisAngle( axis, angle );
  3926. },
  3927. setRotationFromEuler: function ( euler ) {
  3928. this.quaternion.setFromEuler( euler, true );
  3929. },
  3930. setRotationFromMatrix: function ( m ) {
  3931. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3932. this.quaternion.setFromRotationMatrix( m );
  3933. },
  3934. setRotationFromQuaternion: function ( q ) {
  3935. // assumes q is normalized
  3936. this.quaternion.copy( q );
  3937. },
  3938. rotateOnAxis: function ( axis, angle ) {
  3939. // rotate object on axis in object space
  3940. // axis is assumed to be normalized
  3941. _q1.setFromAxisAngle( axis, angle );
  3942. this.quaternion.multiply( _q1 );
  3943. return this;
  3944. },
  3945. rotateOnWorldAxis: function ( axis, angle ) {
  3946. // rotate object on axis in world space
  3947. // axis is assumed to be normalized
  3948. // method assumes no rotated parent
  3949. _q1.setFromAxisAngle( axis, angle );
  3950. this.quaternion.premultiply( _q1 );
  3951. return this;
  3952. },
  3953. rotateX: function ( angle ) {
  3954. return this.rotateOnAxis( _xAxis, angle );
  3955. },
  3956. rotateY: function ( angle ) {
  3957. return this.rotateOnAxis( _yAxis, angle );
  3958. },
  3959. rotateZ: function ( angle ) {
  3960. return this.rotateOnAxis( _zAxis, angle );
  3961. },
  3962. translateOnAxis: function ( axis, distance ) {
  3963. // translate object by distance along axis in object space
  3964. // axis is assumed to be normalized
  3965. _v1$2.copy( axis ).applyQuaternion( this.quaternion );
  3966. this.position.add( _v1$2.multiplyScalar( distance ) );
  3967. return this;
  3968. },
  3969. translateX: function ( distance ) {
  3970. return this.translateOnAxis( _xAxis, distance );
  3971. },
  3972. translateY: function ( distance ) {
  3973. return this.translateOnAxis( _yAxis, distance );
  3974. },
  3975. translateZ: function ( distance ) {
  3976. return this.translateOnAxis( _zAxis, distance );
  3977. },
  3978. localToWorld: function ( vector ) {
  3979. return vector.applyMatrix4( this.matrixWorld );
  3980. },
  3981. worldToLocal: function ( vector ) {
  3982. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  3983. },
  3984. lookAt: function ( x, y, z ) {
  3985. // This method does not support objects having non-uniformly-scaled parent(s)
  3986. if ( x.isVector3 ) {
  3987. _target.copy( x );
  3988. } else {
  3989. _target.set( x, y, z );
  3990. }
  3991. const parent = this.parent;
  3992. this.updateWorldMatrix( true, false );
  3993. _position.setFromMatrixPosition( this.matrixWorld );
  3994. if ( this.isCamera || this.isLight ) {
  3995. _m1$1.lookAt( _position, _target, this.up );
  3996. } else {
  3997. _m1$1.lookAt( _target, _position, this.up );
  3998. }
  3999. this.quaternion.setFromRotationMatrix( _m1$1 );
  4000. if ( parent ) {
  4001. _m1$1.extractRotation( parent.matrixWorld );
  4002. _q1.setFromRotationMatrix( _m1$1 );
  4003. this.quaternion.premultiply( _q1.invert() );
  4004. }
  4005. },
  4006. add: function ( object ) {
  4007. if ( arguments.length > 1 ) {
  4008. for ( let i = 0; i < arguments.length; i ++ ) {
  4009. this.add( arguments[ i ] );
  4010. }
  4011. return this;
  4012. }
  4013. if ( object === this ) {
  4014. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4015. return this;
  4016. }
  4017. if ( object && object.isObject3D ) {
  4018. if ( object.parent !== null ) {
  4019. object.parent.remove( object );
  4020. }
  4021. object.parent = this;
  4022. this.children.push( object );
  4023. object.dispatchEvent( _addedEvent );
  4024. } else {
  4025. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4026. }
  4027. return this;
  4028. },
  4029. remove: function ( object ) {
  4030. if ( arguments.length > 1 ) {
  4031. for ( let i = 0; i < arguments.length; i ++ ) {
  4032. this.remove( arguments[ i ] );
  4033. }
  4034. return this;
  4035. }
  4036. const index = this.children.indexOf( object );
  4037. if ( index !== - 1 ) {
  4038. object.parent = null;
  4039. this.children.splice( index, 1 );
  4040. object.dispatchEvent( _removedEvent );
  4041. }
  4042. return this;
  4043. },
  4044. clear: function () {
  4045. for ( let i = 0; i < this.children.length; i ++ ) {
  4046. const object = this.children[ i ];
  4047. object.parent = null;
  4048. object.dispatchEvent( _removedEvent );
  4049. }
  4050. this.children.length = 0;
  4051. return this;
  4052. },
  4053. attach: function ( object ) {
  4054. // adds object as a child of this, while maintaining the object's world transform
  4055. this.updateWorldMatrix( true, false );
  4056. _m1$1.copy( this.matrixWorld ).invert();
  4057. if ( object.parent !== null ) {
  4058. object.parent.updateWorldMatrix( true, false );
  4059. _m1$1.multiply( object.parent.matrixWorld );
  4060. }
  4061. object.applyMatrix4( _m1$1 );
  4062. object.updateWorldMatrix( false, false );
  4063. this.add( object );
  4064. return this;
  4065. },
  4066. getObjectById: function ( id ) {
  4067. return this.getObjectByProperty( 'id', id );
  4068. },
  4069. getObjectByName: function ( name ) {
  4070. return this.getObjectByProperty( 'name', name );
  4071. },
  4072. getObjectByProperty: function ( name, value ) {
  4073. if ( this[ name ] === value ) return this;
  4074. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4075. const child = this.children[ i ];
  4076. const object = child.getObjectByProperty( name, value );
  4077. if ( object !== undefined ) {
  4078. return object;
  4079. }
  4080. }
  4081. return undefined;
  4082. },
  4083. getWorldPosition: function ( target ) {
  4084. if ( target === undefined ) {
  4085. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4086. target = new Vector3();
  4087. }
  4088. this.updateWorldMatrix( true, false );
  4089. return target.setFromMatrixPosition( this.matrixWorld );
  4090. },
  4091. getWorldQuaternion: function ( target ) {
  4092. if ( target === undefined ) {
  4093. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  4094. target = new Quaternion();
  4095. }
  4096. this.updateWorldMatrix( true, false );
  4097. this.matrixWorld.decompose( _position, target, _scale );
  4098. return target;
  4099. },
  4100. getWorldScale: function ( target ) {
  4101. if ( target === undefined ) {
  4102. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  4103. target = new Vector3();
  4104. }
  4105. this.updateWorldMatrix( true, false );
  4106. this.matrixWorld.decompose( _position, _quaternion$2, target );
  4107. return target;
  4108. },
  4109. getWorldDirection: function ( target ) {
  4110. if ( target === undefined ) {
  4111. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  4112. target = new Vector3();
  4113. }
  4114. this.updateWorldMatrix( true, false );
  4115. const e = this.matrixWorld.elements;
  4116. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4117. },
  4118. raycast: function () {},
  4119. traverse: function ( callback ) {
  4120. callback( this );
  4121. const children = this.children;
  4122. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4123. children[ i ].traverse( callback );
  4124. }
  4125. },
  4126. traverseVisible: function ( callback ) {
  4127. if ( this.visible === false ) return;
  4128. callback( this );
  4129. const children = this.children;
  4130. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4131. children[ i ].traverseVisible( callback );
  4132. }
  4133. },
  4134. traverseAncestors: function ( callback ) {
  4135. const parent = this.parent;
  4136. if ( parent !== null ) {
  4137. callback( parent );
  4138. parent.traverseAncestors( callback );
  4139. }
  4140. },
  4141. updateMatrix: function () {
  4142. this.matrix.compose( this.position, this.quaternion, this.scale );
  4143. this.matrixWorldNeedsUpdate = true;
  4144. },
  4145. updateMatrixWorld: function ( force ) {
  4146. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4147. if ( this.matrixWorldNeedsUpdate || force ) {
  4148. if ( this.parent === null ) {
  4149. this.matrixWorld.copy( this.matrix );
  4150. } else {
  4151. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4152. }
  4153. this.matrixWorldNeedsUpdate = false;
  4154. force = true;
  4155. }
  4156. // update children
  4157. const children = this.children;
  4158. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4159. children[ i ].updateMatrixWorld( force );
  4160. }
  4161. },
  4162. updateWorldMatrix: function ( updateParents, updateChildren ) {
  4163. const parent = this.parent;
  4164. if ( updateParents === true && parent !== null ) {
  4165. parent.updateWorldMatrix( true, false );
  4166. }
  4167. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4168. if ( this.parent === null ) {
  4169. this.matrixWorld.copy( this.matrix );
  4170. } else {
  4171. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4172. }
  4173. // update children
  4174. if ( updateChildren === true ) {
  4175. const children = this.children;
  4176. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4177. children[ i ].updateWorldMatrix( false, true );
  4178. }
  4179. }
  4180. },
  4181. toJSON: function ( meta ) {
  4182. // meta is a string when called from JSON.stringify
  4183. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4184. const output = {};
  4185. // meta is a hash used to collect geometries, materials.
  4186. // not providing it implies that this is the root object
  4187. // being serialized.
  4188. if ( isRootObject ) {
  4189. // initialize meta obj
  4190. meta = {
  4191. geometries: {},
  4192. materials: {},
  4193. textures: {},
  4194. images: {},
  4195. shapes: {},
  4196. skeletons: {},
  4197. animations: {}
  4198. };
  4199. output.metadata = {
  4200. version: 4.5,
  4201. type: 'Object',
  4202. generator: 'Object3D.toJSON'
  4203. };
  4204. }
  4205. // standard Object3D serialization
  4206. const object = {};
  4207. object.uuid = this.uuid;
  4208. object.type = this.type;
  4209. if ( this.name !== '' ) object.name = this.name;
  4210. if ( this.castShadow === true ) object.castShadow = true;
  4211. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4212. if ( this.visible === false ) object.visible = false;
  4213. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4214. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4215. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4216. object.layers = this.layers.mask;
  4217. object.matrix = this.matrix.toArray();
  4218. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4219. // object specific properties
  4220. if ( this.isInstancedMesh ) {
  4221. object.type = 'InstancedMesh';
  4222. object.count = this.count;
  4223. object.instanceMatrix = this.instanceMatrix.toJSON();
  4224. }
  4225. //
  4226. function serialize( library, element ) {
  4227. if ( library[ element.uuid ] === undefined ) {
  4228. library[ element.uuid ] = element.toJSON( meta );
  4229. }
  4230. return element.uuid;
  4231. }
  4232. if ( this.isMesh || this.isLine || this.isPoints ) {
  4233. object.geometry = serialize( meta.geometries, this.geometry );
  4234. const parameters = this.geometry.parameters;
  4235. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4236. const shapes = parameters.shapes;
  4237. if ( Array.isArray( shapes ) ) {
  4238. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4239. const shape = shapes[ i ];
  4240. serialize( meta.shapes, shape );
  4241. }
  4242. } else {
  4243. serialize( meta.shapes, shapes );
  4244. }
  4245. }
  4246. }
  4247. if ( this.isSkinnedMesh ) {
  4248. object.bindMode = this.bindMode;
  4249. object.bindMatrix = this.bindMatrix.toArray();
  4250. if ( this.skeleton !== undefined ) {
  4251. serialize( meta.skeletons, this.skeleton );
  4252. object.skeleton = this.skeleton.uuid;
  4253. }
  4254. }
  4255. if ( this.material !== undefined ) {
  4256. if ( Array.isArray( this.material ) ) {
  4257. const uuids = [];
  4258. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4259. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4260. }
  4261. object.material = uuids;
  4262. } else {
  4263. object.material = serialize( meta.materials, this.material );
  4264. }
  4265. }
  4266. //
  4267. if ( this.children.length > 0 ) {
  4268. object.children = [];
  4269. for ( let i = 0; i < this.children.length; i ++ ) {
  4270. object.children.push( this.children[ i ].toJSON( meta ).object );
  4271. }
  4272. }
  4273. //
  4274. if ( this.animations.length > 0 ) {
  4275. object.animations = [];
  4276. for ( let i = 0; i < this.animations.length; i ++ ) {
  4277. const animation = this.animations[ i ];
  4278. object.animations.push( serialize( meta.animations, animation ) );
  4279. }
  4280. }
  4281. if ( isRootObject ) {
  4282. const geometries = extractFromCache( meta.geometries );
  4283. const materials = extractFromCache( meta.materials );
  4284. const textures = extractFromCache( meta.textures );
  4285. const images = extractFromCache( meta.images );
  4286. const shapes = extractFromCache( meta.shapes );
  4287. const skeletons = extractFromCache( meta.skeletons );
  4288. const animations = extractFromCache( meta.animations );
  4289. if ( geometries.length > 0 ) output.geometries = geometries;
  4290. if ( materials.length > 0 ) output.materials = materials;
  4291. if ( textures.length > 0 ) output.textures = textures;
  4292. if ( images.length > 0 ) output.images = images;
  4293. if ( shapes.length > 0 ) output.shapes = shapes;
  4294. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4295. if ( animations.length > 0 ) output.animations = animations;
  4296. }
  4297. output.object = object;
  4298. return output;
  4299. // extract data from the cache hash
  4300. // remove metadata on each item
  4301. // and return as array
  4302. function extractFromCache( cache ) {
  4303. const values = [];
  4304. for ( const key in cache ) {
  4305. const data = cache[ key ];
  4306. delete data.metadata;
  4307. values.push( data );
  4308. }
  4309. return values;
  4310. }
  4311. },
  4312. clone: function ( recursive ) {
  4313. return new this.constructor().copy( this, recursive );
  4314. },
  4315. copy: function ( source, recursive = true ) {
  4316. this.name = source.name;
  4317. this.up.copy( source.up );
  4318. this.position.copy( source.position );
  4319. this.rotation.order = source.rotation.order;
  4320. this.quaternion.copy( source.quaternion );
  4321. this.scale.copy( source.scale );
  4322. this.matrix.copy( source.matrix );
  4323. this.matrixWorld.copy( source.matrixWorld );
  4324. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4325. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4326. this.layers.mask = source.layers.mask;
  4327. this.visible = source.visible;
  4328. this.castShadow = source.castShadow;
  4329. this.receiveShadow = source.receiveShadow;
  4330. this.frustumCulled = source.frustumCulled;
  4331. this.renderOrder = source.renderOrder;
  4332. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4333. if ( recursive === true ) {
  4334. for ( let i = 0; i < source.children.length; i ++ ) {
  4335. const child = source.children[ i ];
  4336. this.add( child.clone() );
  4337. }
  4338. }
  4339. return this;
  4340. }
  4341. } );
  4342. const _vector1 = /*@__PURE__*/ new Vector3();
  4343. const _vector2 = /*@__PURE__*/ new Vector3();
  4344. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  4345. class Plane {
  4346. constructor( normal, constant ) {
  4347. Object.defineProperty( this, 'isPlane', { value: true } );
  4348. // normal is assumed to be normalized
  4349. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4350. this.constant = ( constant !== undefined ) ? constant : 0;
  4351. }
  4352. set( normal, constant ) {
  4353. this.normal.copy( normal );
  4354. this.constant = constant;
  4355. return this;
  4356. }
  4357. setComponents( x, y, z, w ) {
  4358. this.normal.set( x, y, z );
  4359. this.constant = w;
  4360. return this;
  4361. }
  4362. setFromNormalAndCoplanarPoint( normal, point ) {
  4363. this.normal.copy( normal );
  4364. this.constant = - point.dot( this.normal );
  4365. return this;
  4366. }
  4367. setFromCoplanarPoints( a, b, c ) {
  4368. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4369. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4370. this.setFromNormalAndCoplanarPoint( normal, a );
  4371. return this;
  4372. }
  4373. clone() {
  4374. return new this.constructor().copy( this );
  4375. }
  4376. copy( plane ) {
  4377. this.normal.copy( plane.normal );
  4378. this.constant = plane.constant;
  4379. return this;
  4380. }
  4381. normalize() {
  4382. // Note: will lead to a divide by zero if the plane is invalid.
  4383. const inverseNormalLength = 1.0 / this.normal.length();
  4384. this.normal.multiplyScalar( inverseNormalLength );
  4385. this.constant *= inverseNormalLength;
  4386. return this;
  4387. }
  4388. negate() {
  4389. this.constant *= - 1;
  4390. this.normal.negate();
  4391. return this;
  4392. }
  4393. distanceToPoint( point ) {
  4394. return this.normal.dot( point ) + this.constant;
  4395. }
  4396. distanceToSphere( sphere ) {
  4397. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4398. }
  4399. projectPoint( point, target ) {
  4400. if ( target === undefined ) {
  4401. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4402. target = new Vector3();
  4403. }
  4404. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4405. }
  4406. intersectLine( line, target ) {
  4407. if ( target === undefined ) {
  4408. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4409. target = new Vector3();
  4410. }
  4411. const direction = line.delta( _vector1 );
  4412. const denominator = this.normal.dot( direction );
  4413. if ( denominator === 0 ) {
  4414. // line is coplanar, return origin
  4415. if ( this.distanceToPoint( line.start ) === 0 ) {
  4416. return target.copy( line.start );
  4417. }
  4418. // Unsure if this is the correct method to handle this case.
  4419. return undefined;
  4420. }
  4421. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4422. if ( t < 0 || t > 1 ) {
  4423. return undefined;
  4424. }
  4425. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4426. }
  4427. intersectsLine( line ) {
  4428. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4429. const startSign = this.distanceToPoint( line.start );
  4430. const endSign = this.distanceToPoint( line.end );
  4431. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4432. }
  4433. intersectsBox( box ) {
  4434. return box.intersectsPlane( this );
  4435. }
  4436. intersectsSphere( sphere ) {
  4437. return sphere.intersectsPlane( this );
  4438. }
  4439. coplanarPoint( target ) {
  4440. if ( target === undefined ) {
  4441. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4442. target = new Vector3();
  4443. }
  4444. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4445. }
  4446. applyMatrix4( matrix, optionalNormalMatrix ) {
  4447. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4448. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4449. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4450. this.constant = - referencePoint.dot( normal );
  4451. return this;
  4452. }
  4453. translate( offset ) {
  4454. this.constant -= offset.dot( this.normal );
  4455. return this;
  4456. }
  4457. equals( plane ) {
  4458. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4459. }
  4460. }
  4461. const _v0$1 = /*@__PURE__*/ new Vector3();
  4462. const _v1$3 = /*@__PURE__*/ new Vector3();
  4463. const _v2$1 = /*@__PURE__*/ new Vector3();
  4464. const _v3 = /*@__PURE__*/ new Vector3();
  4465. const _vab = /*@__PURE__*/ new Vector3();
  4466. const _vac = /*@__PURE__*/ new Vector3();
  4467. const _vbc = /*@__PURE__*/ new Vector3();
  4468. const _vap = /*@__PURE__*/ new Vector3();
  4469. const _vbp = /*@__PURE__*/ new Vector3();
  4470. const _vcp = /*@__PURE__*/ new Vector3();
  4471. class Triangle {
  4472. constructor( a, b, c ) {
  4473. this.a = ( a !== undefined ) ? a : new Vector3();
  4474. this.b = ( b !== undefined ) ? b : new Vector3();
  4475. this.c = ( c !== undefined ) ? c : new Vector3();
  4476. }
  4477. static getNormal( a, b, c, target ) {
  4478. if ( target === undefined ) {
  4479. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4480. target = new Vector3();
  4481. }
  4482. target.subVectors( c, b );
  4483. _v0$1.subVectors( a, b );
  4484. target.cross( _v0$1 );
  4485. const targetLengthSq = target.lengthSq();
  4486. if ( targetLengthSq > 0 ) {
  4487. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4488. }
  4489. return target.set( 0, 0, 0 );
  4490. }
  4491. // static/instance method to calculate barycentric coordinates
  4492. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4493. static getBarycoord( point, a, b, c, target ) {
  4494. _v0$1.subVectors( c, a );
  4495. _v1$3.subVectors( b, a );
  4496. _v2$1.subVectors( point, a );
  4497. const dot00 = _v0$1.dot( _v0$1 );
  4498. const dot01 = _v0$1.dot( _v1$3 );
  4499. const dot02 = _v0$1.dot( _v2$1 );
  4500. const dot11 = _v1$3.dot( _v1$3 );
  4501. const dot12 = _v1$3.dot( _v2$1 );
  4502. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4503. if ( target === undefined ) {
  4504. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4505. target = new Vector3();
  4506. }
  4507. // collinear or singular triangle
  4508. if ( denom === 0 ) {
  4509. // arbitrary location outside of triangle?
  4510. // not sure if this is the best idea, maybe should be returning undefined
  4511. return target.set( - 2, - 1, - 1 );
  4512. }
  4513. const invDenom = 1 / denom;
  4514. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4515. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4516. // barycentric coordinates must always sum to 1
  4517. return target.set( 1 - u - v, v, u );
  4518. }
  4519. static containsPoint( point, a, b, c ) {
  4520. this.getBarycoord( point, a, b, c, _v3 );
  4521. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4522. }
  4523. static getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4524. this.getBarycoord( point, p1, p2, p3, _v3 );
  4525. target.set( 0, 0 );
  4526. target.addScaledVector( uv1, _v3.x );
  4527. target.addScaledVector( uv2, _v3.y );
  4528. target.addScaledVector( uv3, _v3.z );
  4529. return target;
  4530. }
  4531. static isFrontFacing( a, b, c, direction ) {
  4532. _v0$1.subVectors( c, b );
  4533. _v1$3.subVectors( a, b );
  4534. // strictly front facing
  4535. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4536. }
  4537. set( a, b, c ) {
  4538. this.a.copy( a );
  4539. this.b.copy( b );
  4540. this.c.copy( c );
  4541. return this;
  4542. }
  4543. setFromPointsAndIndices( points, i0, i1, i2 ) {
  4544. this.a.copy( points[ i0 ] );
  4545. this.b.copy( points[ i1 ] );
  4546. this.c.copy( points[ i2 ] );
  4547. return this;
  4548. }
  4549. clone() {
  4550. return new this.constructor().copy( this );
  4551. }
  4552. copy( triangle ) {
  4553. this.a.copy( triangle.a );
  4554. this.b.copy( triangle.b );
  4555. this.c.copy( triangle.c );
  4556. return this;
  4557. }
  4558. getArea() {
  4559. _v0$1.subVectors( this.c, this.b );
  4560. _v1$3.subVectors( this.a, this.b );
  4561. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4562. }
  4563. getMidpoint( target ) {
  4564. if ( target === undefined ) {
  4565. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4566. target = new Vector3();
  4567. }
  4568. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4569. }
  4570. getNormal( target ) {
  4571. return Triangle.getNormal( this.a, this.b, this.c, target );
  4572. }
  4573. getPlane( target ) {
  4574. if ( target === undefined ) {
  4575. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4576. target = new Plane();
  4577. }
  4578. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4579. }
  4580. getBarycoord( point, target ) {
  4581. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4582. }
  4583. getUV( point, uv1, uv2, uv3, target ) {
  4584. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4585. }
  4586. containsPoint( point ) {
  4587. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4588. }
  4589. isFrontFacing( direction ) {
  4590. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4591. }
  4592. intersectsBox( box ) {
  4593. return box.intersectsTriangle( this );
  4594. }
  4595. closestPointToPoint( p, target ) {
  4596. if ( target === undefined ) {
  4597. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4598. target = new Vector3();
  4599. }
  4600. const a = this.a, b = this.b, c = this.c;
  4601. let v, w;
  4602. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4603. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4604. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4605. // basically, we're distinguishing which of the voronoi regions of the triangle
  4606. // the point lies in with the minimum amount of redundant computation.
  4607. _vab.subVectors( b, a );
  4608. _vac.subVectors( c, a );
  4609. _vap.subVectors( p, a );
  4610. const d1 = _vab.dot( _vap );
  4611. const d2 = _vac.dot( _vap );
  4612. if ( d1 <= 0 && d2 <= 0 ) {
  4613. // vertex region of A; barycentric coords (1, 0, 0)
  4614. return target.copy( a );
  4615. }
  4616. _vbp.subVectors( p, b );
  4617. const d3 = _vab.dot( _vbp );
  4618. const d4 = _vac.dot( _vbp );
  4619. if ( d3 >= 0 && d4 <= d3 ) {
  4620. // vertex region of B; barycentric coords (0, 1, 0)
  4621. return target.copy( b );
  4622. }
  4623. const vc = d1 * d4 - d3 * d2;
  4624. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4625. v = d1 / ( d1 - d3 );
  4626. // edge region of AB; barycentric coords (1-v, v, 0)
  4627. return target.copy( a ).addScaledVector( _vab, v );
  4628. }
  4629. _vcp.subVectors( p, c );
  4630. const d5 = _vab.dot( _vcp );
  4631. const d6 = _vac.dot( _vcp );
  4632. if ( d6 >= 0 && d5 <= d6 ) {
  4633. // vertex region of C; barycentric coords (0, 0, 1)
  4634. return target.copy( c );
  4635. }
  4636. const vb = d5 * d2 - d1 * d6;
  4637. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4638. w = d2 / ( d2 - d6 );
  4639. // edge region of AC; barycentric coords (1-w, 0, w)
  4640. return target.copy( a ).addScaledVector( _vac, w );
  4641. }
  4642. const va = d3 * d6 - d5 * d4;
  4643. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4644. _vbc.subVectors( c, b );
  4645. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4646. // edge region of BC; barycentric coords (0, 1-w, w)
  4647. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4648. }
  4649. // face region
  4650. const denom = 1 / ( va + vb + vc );
  4651. // u = va * denom
  4652. v = vb * denom;
  4653. w = vc * denom;
  4654. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4655. }
  4656. equals( triangle ) {
  4657. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4658. }
  4659. }
  4660. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4661. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4662. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4663. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4664. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4665. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4666. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4667. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4668. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4669. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4670. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4671. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4672. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4673. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4674. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4675. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4676. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4677. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4678. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4679. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4680. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4681. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4682. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4683. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4684. const _hslA = { h: 0, s: 0, l: 0 };
  4685. const _hslB = { h: 0, s: 0, l: 0 };
  4686. function hue2rgb( p, q, t ) {
  4687. if ( t < 0 ) t += 1;
  4688. if ( t > 1 ) t -= 1;
  4689. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4690. if ( t < 1 / 2 ) return q;
  4691. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4692. return p;
  4693. }
  4694. function SRGBToLinear( c ) {
  4695. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4696. }
  4697. function LinearToSRGB( c ) {
  4698. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4699. }
  4700. class Color {
  4701. constructor( r, g, b ) {
  4702. Object.defineProperty( this, 'isColor', { value: true } );
  4703. if ( g === undefined && b === undefined ) {
  4704. // r is THREE.Color, hex or string
  4705. return this.set( r );
  4706. }
  4707. return this.setRGB( r, g, b );
  4708. }
  4709. set( value ) {
  4710. if ( value && value.isColor ) {
  4711. this.copy( value );
  4712. } else if ( typeof value === 'number' ) {
  4713. this.setHex( value );
  4714. } else if ( typeof value === 'string' ) {
  4715. this.setStyle( value );
  4716. }
  4717. return this;
  4718. }
  4719. setScalar( scalar ) {
  4720. this.r = scalar;
  4721. this.g = scalar;
  4722. this.b = scalar;
  4723. return this;
  4724. }
  4725. setHex( hex ) {
  4726. hex = Math.floor( hex );
  4727. this.r = ( hex >> 16 & 255 ) / 255;
  4728. this.g = ( hex >> 8 & 255 ) / 255;
  4729. this.b = ( hex & 255 ) / 255;
  4730. return this;
  4731. }
  4732. setRGB( r, g, b ) {
  4733. this.r = r;
  4734. this.g = g;
  4735. this.b = b;
  4736. return this;
  4737. }
  4738. setHSL( h, s, l ) {
  4739. // h,s,l ranges are in 0.0 - 1.0
  4740. h = MathUtils.euclideanModulo( h, 1 );
  4741. s = MathUtils.clamp( s, 0, 1 );
  4742. l = MathUtils.clamp( l, 0, 1 );
  4743. if ( s === 0 ) {
  4744. this.r = this.g = this.b = l;
  4745. } else {
  4746. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4747. const q = ( 2 * l ) - p;
  4748. this.r = hue2rgb( q, p, h + 1 / 3 );
  4749. this.g = hue2rgb( q, p, h );
  4750. this.b = hue2rgb( q, p, h - 1 / 3 );
  4751. }
  4752. return this;
  4753. }
  4754. setStyle( style ) {
  4755. function handleAlpha( string ) {
  4756. if ( string === undefined ) return;
  4757. if ( parseFloat( string ) < 1 ) {
  4758. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4759. }
  4760. }
  4761. let m;
  4762. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4763. // rgb / hsl
  4764. let color;
  4765. const name = m[ 1 ];
  4766. const components = m[ 2 ];
  4767. switch ( name ) {
  4768. case 'rgb':
  4769. case 'rgba':
  4770. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4771. // rgb(255,0,0) rgba(255,0,0,0.5)
  4772. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4773. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4774. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4775. handleAlpha( color[ 4 ] );
  4776. return this;
  4777. }
  4778. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4779. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4780. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4781. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4782. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4783. handleAlpha( color[ 4 ] );
  4784. return this;
  4785. }
  4786. break;
  4787. case 'hsl':
  4788. case 'hsla':
  4789. if ( color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4790. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4791. const h = parseFloat( color[ 1 ] ) / 360;
  4792. const s = parseInt( color[ 2 ], 10 ) / 100;
  4793. const l = parseInt( color[ 3 ], 10 ) / 100;
  4794. handleAlpha( color[ 4 ] );
  4795. return this.setHSL( h, s, l );
  4796. }
  4797. break;
  4798. }
  4799. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  4800. // hex color
  4801. const hex = m[ 1 ];
  4802. const size = hex.length;
  4803. if ( size === 3 ) {
  4804. // #ff0
  4805. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4806. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4807. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4808. return this;
  4809. } else if ( size === 6 ) {
  4810. // #ff0000
  4811. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4812. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4813. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4814. return this;
  4815. }
  4816. }
  4817. if ( style && style.length > 0 ) {
  4818. return this.setColorName( style );
  4819. }
  4820. return this;
  4821. }
  4822. setColorName( style ) {
  4823. // color keywords
  4824. const hex = _colorKeywords[ style ];
  4825. if ( hex !== undefined ) {
  4826. // red
  4827. this.setHex( hex );
  4828. } else {
  4829. // unknown color
  4830. console.warn( 'THREE.Color: Unknown color ' + style );
  4831. }
  4832. return this;
  4833. }
  4834. clone() {
  4835. return new this.constructor( this.r, this.g, this.b );
  4836. }
  4837. copy( color ) {
  4838. this.r = color.r;
  4839. this.g = color.g;
  4840. this.b = color.b;
  4841. return this;
  4842. }
  4843. copyGammaToLinear( color, gammaFactor = 2.0 ) {
  4844. this.r = Math.pow( color.r, gammaFactor );
  4845. this.g = Math.pow( color.g, gammaFactor );
  4846. this.b = Math.pow( color.b, gammaFactor );
  4847. return this;
  4848. }
  4849. copyLinearToGamma( color, gammaFactor = 2.0 ) {
  4850. const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4851. this.r = Math.pow( color.r, safeInverse );
  4852. this.g = Math.pow( color.g, safeInverse );
  4853. this.b = Math.pow( color.b, safeInverse );
  4854. return this;
  4855. }
  4856. convertGammaToLinear( gammaFactor ) {
  4857. this.copyGammaToLinear( this, gammaFactor );
  4858. return this;
  4859. }
  4860. convertLinearToGamma( gammaFactor ) {
  4861. this.copyLinearToGamma( this, gammaFactor );
  4862. return this;
  4863. }
  4864. copySRGBToLinear( color ) {
  4865. this.r = SRGBToLinear( color.r );
  4866. this.g = SRGBToLinear( color.g );
  4867. this.b = SRGBToLinear( color.b );
  4868. return this;
  4869. }
  4870. copyLinearToSRGB( color ) {
  4871. this.r = LinearToSRGB( color.r );
  4872. this.g = LinearToSRGB( color.g );
  4873. this.b = LinearToSRGB( color.b );
  4874. return this;
  4875. }
  4876. convertSRGBToLinear() {
  4877. this.copySRGBToLinear( this );
  4878. return this;
  4879. }
  4880. convertLinearToSRGB() {
  4881. this.copyLinearToSRGB( this );
  4882. return this;
  4883. }
  4884. getHex() {
  4885. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4886. }
  4887. getHexString() {
  4888. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4889. }
  4890. getHSL( target ) {
  4891. // h,s,l ranges are in 0.0 - 1.0
  4892. if ( target === undefined ) {
  4893. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4894. target = { h: 0, s: 0, l: 0 };
  4895. }
  4896. const r = this.r, g = this.g, b = this.b;
  4897. const max = Math.max( r, g, b );
  4898. const min = Math.min( r, g, b );
  4899. let hue, saturation;
  4900. const lightness = ( min + max ) / 2.0;
  4901. if ( min === max ) {
  4902. hue = 0;
  4903. saturation = 0;
  4904. } else {
  4905. const delta = max - min;
  4906. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4907. switch ( max ) {
  4908. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4909. case g: hue = ( b - r ) / delta + 2; break;
  4910. case b: hue = ( r - g ) / delta + 4; break;
  4911. }
  4912. hue /= 6;
  4913. }
  4914. target.h = hue;
  4915. target.s = saturation;
  4916. target.l = lightness;
  4917. return target;
  4918. }
  4919. getStyle() {
  4920. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4921. }
  4922. offsetHSL( h, s, l ) {
  4923. this.getHSL( _hslA );
  4924. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  4925. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  4926. return this;
  4927. }
  4928. add( color ) {
  4929. this.r += color.r;
  4930. this.g += color.g;
  4931. this.b += color.b;
  4932. return this;
  4933. }
  4934. addColors( color1, color2 ) {
  4935. this.r = color1.r + color2.r;
  4936. this.g = color1.g + color2.g;
  4937. this.b = color1.b + color2.b;
  4938. return this;
  4939. }
  4940. addScalar( s ) {
  4941. this.r += s;
  4942. this.g += s;
  4943. this.b += s;
  4944. return this;
  4945. }
  4946. sub( color ) {
  4947. this.r = Math.max( 0, this.r - color.r );
  4948. this.g = Math.max( 0, this.g - color.g );
  4949. this.b = Math.max( 0, this.b - color.b );
  4950. return this;
  4951. }
  4952. multiply( color ) {
  4953. this.r *= color.r;
  4954. this.g *= color.g;
  4955. this.b *= color.b;
  4956. return this;
  4957. }
  4958. multiplyScalar( s ) {
  4959. this.r *= s;
  4960. this.g *= s;
  4961. this.b *= s;
  4962. return this;
  4963. }
  4964. lerp( color, alpha ) {
  4965. this.r += ( color.r - this.r ) * alpha;
  4966. this.g += ( color.g - this.g ) * alpha;
  4967. this.b += ( color.b - this.b ) * alpha;
  4968. return this;
  4969. }
  4970. lerpColors( color1, color2, alpha ) {
  4971. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  4972. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  4973. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  4974. return this;
  4975. }
  4976. lerpHSL( color, alpha ) {
  4977. this.getHSL( _hslA );
  4978. color.getHSL( _hslB );
  4979. const h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  4980. const s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  4981. const l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  4982. this.setHSL( h, s, l );
  4983. return this;
  4984. }
  4985. equals( c ) {
  4986. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4987. }
  4988. fromArray( array, offset = 0 ) {
  4989. this.r = array[ offset ];
  4990. this.g = array[ offset + 1 ];
  4991. this.b = array[ offset + 2 ];
  4992. return this;
  4993. }
  4994. toArray( array = [], offset = 0 ) {
  4995. array[ offset ] = this.r;
  4996. array[ offset + 1 ] = this.g;
  4997. array[ offset + 2 ] = this.b;
  4998. return array;
  4999. }
  5000. fromBufferAttribute( attribute, index ) {
  5001. this.r = attribute.getX( index );
  5002. this.g = attribute.getY( index );
  5003. this.b = attribute.getZ( index );
  5004. if ( attribute.normalized === true ) {
  5005. // assuming Uint8Array
  5006. this.r /= 255;
  5007. this.g /= 255;
  5008. this.b /= 255;
  5009. }
  5010. return this;
  5011. }
  5012. toJSON() {
  5013. return this.getHex();
  5014. }
  5015. }
  5016. Color.NAMES = _colorKeywords;
  5017. Color.prototype.r = 1;
  5018. Color.prototype.g = 1;
  5019. Color.prototype.b = 1;
  5020. class Face3 {
  5021. constructor( a, b, c, normal, color, materialIndex = 0 ) {
  5022. this.a = a;
  5023. this.b = b;
  5024. this.c = c;
  5025. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5026. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5027. this.color = ( color && color.isColor ) ? color : new Color();
  5028. this.vertexColors = Array.isArray( color ) ? color : [];
  5029. this.materialIndex = materialIndex;
  5030. }
  5031. clone() {
  5032. return new this.constructor().copy( this );
  5033. }
  5034. copy( source ) {
  5035. this.a = source.a;
  5036. this.b = source.b;
  5037. this.c = source.c;
  5038. this.normal.copy( source.normal );
  5039. this.color.copy( source.color );
  5040. this.materialIndex = source.materialIndex;
  5041. for ( let i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5042. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5043. }
  5044. for ( let i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5045. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5046. }
  5047. return this;
  5048. }
  5049. }
  5050. let materialId = 0;
  5051. function Material() {
  5052. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5053. this.uuid = MathUtils.generateUUID();
  5054. this.name = '';
  5055. this.type = 'Material';
  5056. this.fog = true;
  5057. this.blending = NormalBlending;
  5058. this.side = FrontSide;
  5059. this.flatShading = false;
  5060. this.vertexColors = false;
  5061. this.opacity = 1;
  5062. this.transparent = false;
  5063. this.blendSrc = SrcAlphaFactor;
  5064. this.blendDst = OneMinusSrcAlphaFactor;
  5065. this.blendEquation = AddEquation;
  5066. this.blendSrcAlpha = null;
  5067. this.blendDstAlpha = null;
  5068. this.blendEquationAlpha = null;
  5069. this.depthFunc = LessEqualDepth;
  5070. this.depthTest = true;
  5071. this.depthWrite = true;
  5072. this.stencilWriteMask = 0xff;
  5073. this.stencilFunc = AlwaysStencilFunc;
  5074. this.stencilRef = 0;
  5075. this.stencilFuncMask = 0xff;
  5076. this.stencilFail = KeepStencilOp;
  5077. this.stencilZFail = KeepStencilOp;
  5078. this.stencilZPass = KeepStencilOp;
  5079. this.stencilWrite = false;
  5080. this.clippingPlanes = null;
  5081. this.clipIntersection = false;
  5082. this.clipShadows = false;
  5083. this.shadowSide = null;
  5084. this.colorWrite = true;
  5085. this.precision = null; // override the renderer's default precision for this material
  5086. this.polygonOffset = false;
  5087. this.polygonOffsetFactor = 0;
  5088. this.polygonOffsetUnits = 0;
  5089. this.dithering = false;
  5090. this.alphaTest = 0;
  5091. this.premultipliedAlpha = false;
  5092. this.visible = true;
  5093. this.toneMapped = true;
  5094. this.userData = {};
  5095. this.version = 0;
  5096. }
  5097. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5098. constructor: Material,
  5099. isMaterial: true,
  5100. onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
  5101. customProgramCacheKey: function () {
  5102. return this.onBeforeCompile.toString();
  5103. },
  5104. setValues: function ( values ) {
  5105. if ( values === undefined ) return;
  5106. for ( const key in values ) {
  5107. const newValue = values[ key ];
  5108. if ( newValue === undefined ) {
  5109. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  5110. continue;
  5111. }
  5112. // for backward compatability if shading is set in the constructor
  5113. if ( key === 'shading' ) {
  5114. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5115. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5116. continue;
  5117. }
  5118. const currentValue = this[ key ];
  5119. if ( currentValue === undefined ) {
  5120. console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  5121. continue;
  5122. }
  5123. if ( currentValue && currentValue.isColor ) {
  5124. currentValue.set( newValue );
  5125. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5126. currentValue.copy( newValue );
  5127. } else {
  5128. this[ key ] = newValue;
  5129. }
  5130. }
  5131. },
  5132. toJSON: function ( meta ) {
  5133. const isRoot = ( meta === undefined || typeof meta === 'string' );
  5134. if ( isRoot ) {
  5135. meta = {
  5136. textures: {},
  5137. images: {}
  5138. };
  5139. }
  5140. const data = {
  5141. metadata: {
  5142. version: 4.5,
  5143. type: 'Material',
  5144. generator: 'Material.toJSON'
  5145. }
  5146. };
  5147. // standard Material serialization
  5148. data.uuid = this.uuid;
  5149. data.type = this.type;
  5150. if ( this.name !== '' ) data.name = this.name;
  5151. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5152. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5153. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5154. if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  5155. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5156. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5157. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5158. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5159. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5160. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5161. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5162. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5163. }
  5164. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5165. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5166. }
  5167. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5168. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5169. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5170. }
  5171. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5172. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5173. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5174. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5175. if ( this.aoMap && this.aoMap.isTexture ) {
  5176. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5177. data.aoMapIntensity = this.aoMapIntensity;
  5178. }
  5179. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5180. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5181. data.bumpScale = this.bumpScale;
  5182. }
  5183. if ( this.normalMap && this.normalMap.isTexture ) {
  5184. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5185. data.normalMapType = this.normalMapType;
  5186. data.normalScale = this.normalScale.toArray();
  5187. }
  5188. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5189. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5190. data.displacementScale = this.displacementScale;
  5191. data.displacementBias = this.displacementBias;
  5192. }
  5193. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5194. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5195. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5196. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5197. if ( this.envMap && this.envMap.isTexture ) {
  5198. data.envMap = this.envMap.toJSON( meta ).uuid;
  5199. data.reflectivity = this.reflectivity; // Scale behind envMap
  5200. data.refractionRatio = this.refractionRatio;
  5201. if ( this.combine !== undefined ) data.combine = this.combine;
  5202. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5203. }
  5204. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5205. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5206. }
  5207. if ( this.size !== undefined ) data.size = this.size;
  5208. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5209. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5210. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5211. if ( this.side !== FrontSide ) data.side = this.side;
  5212. if ( this.vertexColors ) data.vertexColors = true;
  5213. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5214. if ( this.transparent === true ) data.transparent = this.transparent;
  5215. data.depthFunc = this.depthFunc;
  5216. data.depthTest = this.depthTest;
  5217. data.depthWrite = this.depthWrite;
  5218. data.stencilWrite = this.stencilWrite;
  5219. data.stencilWriteMask = this.stencilWriteMask;
  5220. data.stencilFunc = this.stencilFunc;
  5221. data.stencilRef = this.stencilRef;
  5222. data.stencilFuncMask = this.stencilFuncMask;
  5223. data.stencilFail = this.stencilFail;
  5224. data.stencilZFail = this.stencilZFail;
  5225. data.stencilZPass = this.stencilZPass;
  5226. // rotation (SpriteMaterial)
  5227. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5228. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5229. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5230. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5231. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5232. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5233. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5234. if ( this.scale !== undefined ) data.scale = this.scale;
  5235. if ( this.dithering === true ) data.dithering = true;
  5236. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5237. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5238. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5239. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5240. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5241. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5242. if ( this.morphTargets === true ) data.morphTargets = true;
  5243. if ( this.morphNormals === true ) data.morphNormals = true;
  5244. if ( this.skinning === true ) data.skinning = true;
  5245. if ( this.visible === false ) data.visible = false;
  5246. if ( this.toneMapped === false ) data.toneMapped = false;
  5247. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5248. // TODO: Copied from Object3D.toJSON
  5249. function extractFromCache( cache ) {
  5250. const values = [];
  5251. for ( const key in cache ) {
  5252. const data = cache[ key ];
  5253. delete data.metadata;
  5254. values.push( data );
  5255. }
  5256. return values;
  5257. }
  5258. if ( isRoot ) {
  5259. const textures = extractFromCache( meta.textures );
  5260. const images = extractFromCache( meta.images );
  5261. if ( textures.length > 0 ) data.textures = textures;
  5262. if ( images.length > 0 ) data.images = images;
  5263. }
  5264. return data;
  5265. },
  5266. clone: function () {
  5267. return new this.constructor().copy( this );
  5268. },
  5269. copy: function ( source ) {
  5270. this.name = source.name;
  5271. this.fog = source.fog;
  5272. this.blending = source.blending;
  5273. this.side = source.side;
  5274. this.flatShading = source.flatShading;
  5275. this.vertexColors = source.vertexColors;
  5276. this.opacity = source.opacity;
  5277. this.transparent = source.transparent;
  5278. this.blendSrc = source.blendSrc;
  5279. this.blendDst = source.blendDst;
  5280. this.blendEquation = source.blendEquation;
  5281. this.blendSrcAlpha = source.blendSrcAlpha;
  5282. this.blendDstAlpha = source.blendDstAlpha;
  5283. this.blendEquationAlpha = source.blendEquationAlpha;
  5284. this.depthFunc = source.depthFunc;
  5285. this.depthTest = source.depthTest;
  5286. this.depthWrite = source.depthWrite;
  5287. this.stencilWriteMask = source.stencilWriteMask;
  5288. this.stencilFunc = source.stencilFunc;
  5289. this.stencilRef = source.stencilRef;
  5290. this.stencilFuncMask = source.stencilFuncMask;
  5291. this.stencilFail = source.stencilFail;
  5292. this.stencilZFail = source.stencilZFail;
  5293. this.stencilZPass = source.stencilZPass;
  5294. this.stencilWrite = source.stencilWrite;
  5295. const srcPlanes = source.clippingPlanes;
  5296. let dstPlanes = null;
  5297. if ( srcPlanes !== null ) {
  5298. const n = srcPlanes.length;
  5299. dstPlanes = new Array( n );
  5300. for ( let i = 0; i !== n; ++ i ) {
  5301. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5302. }
  5303. }
  5304. this.clippingPlanes = dstPlanes;
  5305. this.clipIntersection = source.clipIntersection;
  5306. this.clipShadows = source.clipShadows;
  5307. this.shadowSide = source.shadowSide;
  5308. this.colorWrite = source.colorWrite;
  5309. this.precision = source.precision;
  5310. this.polygonOffset = source.polygonOffset;
  5311. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5312. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5313. this.dithering = source.dithering;
  5314. this.alphaTest = source.alphaTest;
  5315. this.premultipliedAlpha = source.premultipliedAlpha;
  5316. this.visible = source.visible;
  5317. this.toneMapped = source.toneMapped;
  5318. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5319. return this;
  5320. },
  5321. dispose: function () {
  5322. this.dispatchEvent( { type: 'dispose' } );
  5323. }
  5324. } );
  5325. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5326. set: function ( value ) {
  5327. if ( value === true ) this.version ++;
  5328. }
  5329. } );
  5330. /**
  5331. * parameters = {
  5332. * color: <hex>,
  5333. * opacity: <float>,
  5334. * map: new THREE.Texture( <Image> ),
  5335. *
  5336. * lightMap: new THREE.Texture( <Image> ),
  5337. * lightMapIntensity: <float>
  5338. *
  5339. * aoMap: new THREE.Texture( <Image> ),
  5340. * aoMapIntensity: <float>
  5341. *
  5342. * specularMap: new THREE.Texture( <Image> ),
  5343. *
  5344. * alphaMap: new THREE.Texture( <Image> ),
  5345. *
  5346. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5347. * combine: THREE.Multiply,
  5348. * reflectivity: <float>,
  5349. * refractionRatio: <float>,
  5350. *
  5351. * depthTest: <bool>,
  5352. * depthWrite: <bool>,
  5353. *
  5354. * wireframe: <boolean>,
  5355. * wireframeLinewidth: <float>,
  5356. *
  5357. * skinning: <bool>,
  5358. * morphTargets: <bool>
  5359. * }
  5360. */
  5361. function MeshBasicMaterial( parameters ) {
  5362. Material.call( this );
  5363. this.type = 'MeshBasicMaterial';
  5364. this.color = new Color( 0xffffff ); // emissive
  5365. this.map = null;
  5366. this.lightMap = null;
  5367. this.lightMapIntensity = 1.0;
  5368. this.aoMap = null;
  5369. this.aoMapIntensity = 1.0;
  5370. this.specularMap = null;
  5371. this.alphaMap = null;
  5372. this.envMap = null;
  5373. this.combine = MultiplyOperation;
  5374. this.reflectivity = 1;
  5375. this.refractionRatio = 0.98;
  5376. this.wireframe = false;
  5377. this.wireframeLinewidth = 1;
  5378. this.wireframeLinecap = 'round';
  5379. this.wireframeLinejoin = 'round';
  5380. this.skinning = false;
  5381. this.morphTargets = false;
  5382. this.setValues( parameters );
  5383. }
  5384. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5385. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5386. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5387. MeshBasicMaterial.prototype.copy = function ( source ) {
  5388. Material.prototype.copy.call( this, source );
  5389. this.color.copy( source.color );
  5390. this.map = source.map;
  5391. this.lightMap = source.lightMap;
  5392. this.lightMapIntensity = source.lightMapIntensity;
  5393. this.aoMap = source.aoMap;
  5394. this.aoMapIntensity = source.aoMapIntensity;
  5395. this.specularMap = source.specularMap;
  5396. this.alphaMap = source.alphaMap;
  5397. this.envMap = source.envMap;
  5398. this.combine = source.combine;
  5399. this.reflectivity = source.reflectivity;
  5400. this.refractionRatio = source.refractionRatio;
  5401. this.wireframe = source.wireframe;
  5402. this.wireframeLinewidth = source.wireframeLinewidth;
  5403. this.wireframeLinecap = source.wireframeLinecap;
  5404. this.wireframeLinejoin = source.wireframeLinejoin;
  5405. this.skinning = source.skinning;
  5406. this.morphTargets = source.morphTargets;
  5407. return this;
  5408. };
  5409. const _vector$3 = new Vector3();
  5410. const _vector2$1 = new Vector2();
  5411. function BufferAttribute( array, itemSize, normalized ) {
  5412. if ( Array.isArray( array ) ) {
  5413. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5414. }
  5415. this.name = '';
  5416. this.array = array;
  5417. this.itemSize = itemSize;
  5418. this.count = array !== undefined ? array.length / itemSize : 0;
  5419. this.normalized = normalized === true;
  5420. this.usage = StaticDrawUsage;
  5421. this.updateRange = { offset: 0, count: - 1 };
  5422. this.version = 0;
  5423. }
  5424. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5425. set: function ( value ) {
  5426. if ( value === true ) this.version ++;
  5427. }
  5428. } );
  5429. Object.assign( BufferAttribute.prototype, {
  5430. isBufferAttribute: true,
  5431. onUploadCallback: function () {},
  5432. setUsage: function ( value ) {
  5433. this.usage = value;
  5434. return this;
  5435. },
  5436. copy: function ( source ) {
  5437. this.name = source.name;
  5438. this.array = new source.array.constructor( source.array );
  5439. this.itemSize = source.itemSize;
  5440. this.count = source.count;
  5441. this.normalized = source.normalized;
  5442. this.usage = source.usage;
  5443. return this;
  5444. },
  5445. copyAt: function ( index1, attribute, index2 ) {
  5446. index1 *= this.itemSize;
  5447. index2 *= attribute.itemSize;
  5448. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  5449. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5450. }
  5451. return this;
  5452. },
  5453. copyArray: function ( array ) {
  5454. this.array.set( array );
  5455. return this;
  5456. },
  5457. copyColorsArray: function ( colors ) {
  5458. const array = this.array;
  5459. let offset = 0;
  5460. for ( let i = 0, l = colors.length; i < l; i ++ ) {
  5461. let color = colors[ i ];
  5462. if ( color === undefined ) {
  5463. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5464. color = new Color();
  5465. }
  5466. array[ offset ++ ] = color.r;
  5467. array[ offset ++ ] = color.g;
  5468. array[ offset ++ ] = color.b;
  5469. }
  5470. return this;
  5471. },
  5472. copyVector2sArray: function ( vectors ) {
  5473. const array = this.array;
  5474. let offset = 0;
  5475. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5476. let vector = vectors[ i ];
  5477. if ( vector === undefined ) {
  5478. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5479. vector = new Vector2();
  5480. }
  5481. array[ offset ++ ] = vector.x;
  5482. array[ offset ++ ] = vector.y;
  5483. }
  5484. return this;
  5485. },
  5486. copyVector3sArray: function ( vectors ) {
  5487. const array = this.array;
  5488. let offset = 0;
  5489. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5490. let vector = vectors[ i ];
  5491. if ( vector === undefined ) {
  5492. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5493. vector = new Vector3();
  5494. }
  5495. array[ offset ++ ] = vector.x;
  5496. array[ offset ++ ] = vector.y;
  5497. array[ offset ++ ] = vector.z;
  5498. }
  5499. return this;
  5500. },
  5501. copyVector4sArray: function ( vectors ) {
  5502. const array = this.array;
  5503. let offset = 0;
  5504. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5505. let vector = vectors[ i ];
  5506. if ( vector === undefined ) {
  5507. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5508. vector = new Vector4();
  5509. }
  5510. array[ offset ++ ] = vector.x;
  5511. array[ offset ++ ] = vector.y;
  5512. array[ offset ++ ] = vector.z;
  5513. array[ offset ++ ] = vector.w;
  5514. }
  5515. return this;
  5516. },
  5517. applyMatrix3: function ( m ) {
  5518. if ( this.itemSize === 2 ) {
  5519. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5520. _vector2$1.fromBufferAttribute( this, i );
  5521. _vector2$1.applyMatrix3( m );
  5522. this.setXY( i, _vector2$1.x, _vector2$1.y );
  5523. }
  5524. } else if ( this.itemSize === 3 ) {
  5525. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5526. _vector$3.fromBufferAttribute( this, i );
  5527. _vector$3.applyMatrix3( m );
  5528. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5529. }
  5530. }
  5531. return this;
  5532. },
  5533. applyMatrix4: function ( m ) {
  5534. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5535. _vector$3.x = this.getX( i );
  5536. _vector$3.y = this.getY( i );
  5537. _vector$3.z = this.getZ( i );
  5538. _vector$3.applyMatrix4( m );
  5539. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5540. }
  5541. return this;
  5542. },
  5543. applyNormalMatrix: function ( m ) {
  5544. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5545. _vector$3.x = this.getX( i );
  5546. _vector$3.y = this.getY( i );
  5547. _vector$3.z = this.getZ( i );
  5548. _vector$3.applyNormalMatrix( m );
  5549. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5550. }
  5551. return this;
  5552. },
  5553. transformDirection: function ( m ) {
  5554. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5555. _vector$3.x = this.getX( i );
  5556. _vector$3.y = this.getY( i );
  5557. _vector$3.z = this.getZ( i );
  5558. _vector$3.transformDirection( m );
  5559. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5560. }
  5561. return this;
  5562. },
  5563. set: function ( value, offset = 0 ) {
  5564. this.array.set( value, offset );
  5565. return this;
  5566. },
  5567. getX: function ( index ) {
  5568. return this.array[ index * this.itemSize ];
  5569. },
  5570. setX: function ( index, x ) {
  5571. this.array[ index * this.itemSize ] = x;
  5572. return this;
  5573. },
  5574. getY: function ( index ) {
  5575. return this.array[ index * this.itemSize + 1 ];
  5576. },
  5577. setY: function ( index, y ) {
  5578. this.array[ index * this.itemSize + 1 ] = y;
  5579. return this;
  5580. },
  5581. getZ: function ( index ) {
  5582. return this.array[ index * this.itemSize + 2 ];
  5583. },
  5584. setZ: function ( index, z ) {
  5585. this.array[ index * this.itemSize + 2 ] = z;
  5586. return this;
  5587. },
  5588. getW: function ( index ) {
  5589. return this.array[ index * this.itemSize + 3 ];
  5590. },
  5591. setW: function ( index, w ) {
  5592. this.array[ index * this.itemSize + 3 ] = w;
  5593. return this;
  5594. },
  5595. setXY: function ( index, x, y ) {
  5596. index *= this.itemSize;
  5597. this.array[ index + 0 ] = x;
  5598. this.array[ index + 1 ] = y;
  5599. return this;
  5600. },
  5601. setXYZ: function ( index, x, y, z ) {
  5602. index *= this.itemSize;
  5603. this.array[ index + 0 ] = x;
  5604. this.array[ index + 1 ] = y;
  5605. this.array[ index + 2 ] = z;
  5606. return this;
  5607. },
  5608. setXYZW: function ( index, x, y, z, w ) {
  5609. index *= this.itemSize;
  5610. this.array[ index + 0 ] = x;
  5611. this.array[ index + 1 ] = y;
  5612. this.array[ index + 2 ] = z;
  5613. this.array[ index + 3 ] = w;
  5614. return this;
  5615. },
  5616. onUpload: function ( callback ) {
  5617. this.onUploadCallback = callback;
  5618. return this;
  5619. },
  5620. clone: function () {
  5621. return new this.constructor( this.array, this.itemSize ).copy( this );
  5622. },
  5623. toJSON: function () {
  5624. return {
  5625. itemSize: this.itemSize,
  5626. type: this.array.constructor.name,
  5627. array: Array.prototype.slice.call( this.array ),
  5628. normalized: this.normalized
  5629. };
  5630. }
  5631. } );
  5632. //
  5633. function Int8BufferAttribute( array, itemSize, normalized ) {
  5634. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5635. }
  5636. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5637. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5638. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5639. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5640. }
  5641. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5642. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5643. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5644. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5645. }
  5646. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5647. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5648. function Int16BufferAttribute( array, itemSize, normalized ) {
  5649. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5650. }
  5651. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5652. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5653. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5654. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5655. }
  5656. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5657. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5658. function Int32BufferAttribute( array, itemSize, normalized ) {
  5659. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5660. }
  5661. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5662. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5663. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5664. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5665. }
  5666. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5667. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5668. function Float16BufferAttribute( array, itemSize, normalized ) {
  5669. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5670. }
  5671. Float16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5672. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  5673. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  5674. function Float32BufferAttribute( array, itemSize, normalized ) {
  5675. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5676. }
  5677. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5678. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5679. function Float64BufferAttribute( array, itemSize, normalized ) {
  5680. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5681. }
  5682. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5683. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5684. class DirectGeometry {
  5685. constructor() {
  5686. this.vertices = [];
  5687. this.normals = [];
  5688. this.colors = [];
  5689. this.uvs = [];
  5690. this.uvs2 = [];
  5691. this.groups = [];
  5692. this.morphTargets = {};
  5693. this.skinWeights = [];
  5694. this.skinIndices = [];
  5695. // this.lineDistances = [];
  5696. this.boundingBox = null;
  5697. this.boundingSphere = null;
  5698. // update flags
  5699. this.verticesNeedUpdate = false;
  5700. this.normalsNeedUpdate = false;
  5701. this.colorsNeedUpdate = false;
  5702. this.uvsNeedUpdate = false;
  5703. this.groupsNeedUpdate = false;
  5704. }
  5705. computeGroups( geometry ) {
  5706. const groups = [];
  5707. let group, i;
  5708. let materialIndex = undefined;
  5709. const faces = geometry.faces;
  5710. for ( i = 0; i < faces.length; i ++ ) {
  5711. const face = faces[ i ];
  5712. // materials
  5713. if ( face.materialIndex !== materialIndex ) {
  5714. materialIndex = face.materialIndex;
  5715. if ( group !== undefined ) {
  5716. group.count = ( i * 3 ) - group.start;
  5717. groups.push( group );
  5718. }
  5719. group = {
  5720. start: i * 3,
  5721. materialIndex: materialIndex
  5722. };
  5723. }
  5724. }
  5725. if ( group !== undefined ) {
  5726. group.count = ( i * 3 ) - group.start;
  5727. groups.push( group );
  5728. }
  5729. this.groups = groups;
  5730. }
  5731. fromGeometry( geometry ) {
  5732. const faces = geometry.faces;
  5733. const vertices = geometry.vertices;
  5734. const faceVertexUvs = geometry.faceVertexUvs;
  5735. const hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5736. const hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5737. // morphs
  5738. const morphTargets = geometry.morphTargets;
  5739. const morphTargetsLength = morphTargets.length;
  5740. let morphTargetsPosition;
  5741. if ( morphTargetsLength > 0 ) {
  5742. morphTargetsPosition = [];
  5743. for ( let i = 0; i < morphTargetsLength; i ++ ) {
  5744. morphTargetsPosition[ i ] = {
  5745. name: morphTargets[ i ].name,
  5746. data: []
  5747. };
  5748. }
  5749. this.morphTargets.position = morphTargetsPosition;
  5750. }
  5751. const morphNormals = geometry.morphNormals;
  5752. const morphNormalsLength = morphNormals.length;
  5753. let morphTargetsNormal;
  5754. if ( morphNormalsLength > 0 ) {
  5755. morphTargetsNormal = [];
  5756. for ( let i = 0; i < morphNormalsLength; i ++ ) {
  5757. morphTargetsNormal[ i ] = {
  5758. name: morphNormals[ i ].name,
  5759. data: []
  5760. };
  5761. }
  5762. this.morphTargets.normal = morphTargetsNormal;
  5763. }
  5764. // skins
  5765. const skinIndices = geometry.skinIndices;
  5766. const skinWeights = geometry.skinWeights;
  5767. const hasSkinIndices = skinIndices.length === vertices.length;
  5768. const hasSkinWeights = skinWeights.length === vertices.length;
  5769. //
  5770. if ( vertices.length > 0 && faces.length === 0 ) {
  5771. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5772. }
  5773. for ( let i = 0; i < faces.length; i ++ ) {
  5774. const face = faces[ i ];
  5775. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5776. const vertexNormals = face.vertexNormals;
  5777. if ( vertexNormals.length === 3 ) {
  5778. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5779. } else {
  5780. const normal = face.normal;
  5781. this.normals.push( normal, normal, normal );
  5782. }
  5783. const vertexColors = face.vertexColors;
  5784. if ( vertexColors.length === 3 ) {
  5785. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5786. } else {
  5787. const color = face.color;
  5788. this.colors.push( color, color, color );
  5789. }
  5790. if ( hasFaceVertexUv === true ) {
  5791. const vertexUvs = faceVertexUvs[ 0 ][ i ];
  5792. if ( vertexUvs !== undefined ) {
  5793. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5794. } else {
  5795. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5796. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5797. }
  5798. }
  5799. if ( hasFaceVertexUv2 === true ) {
  5800. const vertexUvs = faceVertexUvs[ 1 ][ i ];
  5801. if ( vertexUvs !== undefined ) {
  5802. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5803. } else {
  5804. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5805. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5806. }
  5807. }
  5808. // morphs
  5809. for ( let j = 0; j < morphTargetsLength; j ++ ) {
  5810. const morphTarget = morphTargets[ j ].vertices;
  5811. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5812. }
  5813. for ( let j = 0; j < morphNormalsLength; j ++ ) {
  5814. const morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5815. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5816. }
  5817. // skins
  5818. if ( hasSkinIndices ) {
  5819. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5820. }
  5821. if ( hasSkinWeights ) {
  5822. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5823. }
  5824. }
  5825. this.computeGroups( geometry );
  5826. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5827. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5828. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5829. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5830. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5831. if ( geometry.boundingSphere !== null ) {
  5832. this.boundingSphere = geometry.boundingSphere.clone();
  5833. }
  5834. if ( geometry.boundingBox !== null ) {
  5835. this.boundingBox = geometry.boundingBox.clone();
  5836. }
  5837. return this;
  5838. }
  5839. }
  5840. function arrayMax( array ) {
  5841. if ( array.length === 0 ) return - Infinity;
  5842. let max = array[ 0 ];
  5843. for ( let i = 1, l = array.length; i < l; ++ i ) {
  5844. if ( array[ i ] > max ) max = array[ i ];
  5845. }
  5846. return max;
  5847. }
  5848. const TYPED_ARRAYS = {
  5849. Int8Array: Int8Array,
  5850. Uint8Array: Uint8Array,
  5851. // Workaround for IE11 pre KB2929437. See #11440
  5852. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  5853. Int16Array: Int16Array,
  5854. Uint16Array: Uint16Array,
  5855. Int32Array: Int32Array,
  5856. Uint32Array: Uint32Array,
  5857. Float32Array: Float32Array,
  5858. Float64Array: Float64Array
  5859. };
  5860. function getTypedArray( type, buffer ) {
  5861. return new TYPED_ARRAYS[ type ]( buffer );
  5862. }
  5863. let _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5864. const _m1$2 = new Matrix4();
  5865. const _obj = new Object3D();
  5866. const _offset = new Vector3();
  5867. const _box$2 = new Box3();
  5868. const _boxMorphTargets = new Box3();
  5869. const _vector$4 = new Vector3();
  5870. function BufferGeometry() {
  5871. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  5872. this.uuid = MathUtils.generateUUID();
  5873. this.name = '';
  5874. this.type = 'BufferGeometry';
  5875. this.index = null;
  5876. this.attributes = {};
  5877. this.morphAttributes = {};
  5878. this.morphTargetsRelative = false;
  5879. this.groups = [];
  5880. this.boundingBox = null;
  5881. this.boundingSphere = null;
  5882. this.drawRange = { start: 0, count: Infinity };
  5883. this.userData = {};
  5884. }
  5885. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5886. constructor: BufferGeometry,
  5887. isBufferGeometry: true,
  5888. getIndex: function () {
  5889. return this.index;
  5890. },
  5891. setIndex: function ( index ) {
  5892. if ( Array.isArray( index ) ) {
  5893. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5894. } else {
  5895. this.index = index;
  5896. }
  5897. return this;
  5898. },
  5899. getAttribute: function ( name ) {
  5900. return this.attributes[ name ];
  5901. },
  5902. setAttribute: function ( name, attribute ) {
  5903. this.attributes[ name ] = attribute;
  5904. return this;
  5905. },
  5906. deleteAttribute: function ( name ) {
  5907. delete this.attributes[ name ];
  5908. return this;
  5909. },
  5910. hasAttribute: function ( name ) {
  5911. return this.attributes[ name ] !== undefined;
  5912. },
  5913. addGroup: function ( start, count, materialIndex = 0 ) {
  5914. this.groups.push( {
  5915. start: start,
  5916. count: count,
  5917. materialIndex: materialIndex
  5918. } );
  5919. },
  5920. clearGroups: function () {
  5921. this.groups = [];
  5922. },
  5923. setDrawRange: function ( start, count ) {
  5924. this.drawRange.start = start;
  5925. this.drawRange.count = count;
  5926. },
  5927. applyMatrix4: function ( matrix ) {
  5928. const position = this.attributes.position;
  5929. if ( position !== undefined ) {
  5930. position.applyMatrix4( matrix );
  5931. position.needsUpdate = true;
  5932. }
  5933. const normal = this.attributes.normal;
  5934. if ( normal !== undefined ) {
  5935. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5936. normal.applyNormalMatrix( normalMatrix );
  5937. normal.needsUpdate = true;
  5938. }
  5939. const tangent = this.attributes.tangent;
  5940. if ( tangent !== undefined ) {
  5941. tangent.transformDirection( matrix );
  5942. tangent.needsUpdate = true;
  5943. }
  5944. if ( this.boundingBox !== null ) {
  5945. this.computeBoundingBox();
  5946. }
  5947. if ( this.boundingSphere !== null ) {
  5948. this.computeBoundingSphere();
  5949. }
  5950. return this;
  5951. },
  5952. rotateX: function ( angle ) {
  5953. // rotate geometry around world x-axis
  5954. _m1$2.makeRotationX( angle );
  5955. this.applyMatrix4( _m1$2 );
  5956. return this;
  5957. },
  5958. rotateY: function ( angle ) {
  5959. // rotate geometry around world y-axis
  5960. _m1$2.makeRotationY( angle );
  5961. this.applyMatrix4( _m1$2 );
  5962. return this;
  5963. },
  5964. rotateZ: function ( angle ) {
  5965. // rotate geometry around world z-axis
  5966. _m1$2.makeRotationZ( angle );
  5967. this.applyMatrix4( _m1$2 );
  5968. return this;
  5969. },
  5970. translate: function ( x, y, z ) {
  5971. // translate geometry
  5972. _m1$2.makeTranslation( x, y, z );
  5973. this.applyMatrix4( _m1$2 );
  5974. return this;
  5975. },
  5976. scale: function ( x, y, z ) {
  5977. // scale geometry
  5978. _m1$2.makeScale( x, y, z );
  5979. this.applyMatrix4( _m1$2 );
  5980. return this;
  5981. },
  5982. lookAt: function ( vector ) {
  5983. _obj.lookAt( vector );
  5984. _obj.updateMatrix();
  5985. this.applyMatrix4( _obj.matrix );
  5986. return this;
  5987. },
  5988. center: function () {
  5989. this.computeBoundingBox();
  5990. this.boundingBox.getCenter( _offset ).negate();
  5991. this.translate( _offset.x, _offset.y, _offset.z );
  5992. return this;
  5993. },
  5994. setFromObject: function ( object ) {
  5995. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5996. const geometry = object.geometry;
  5997. if ( object.isPoints || object.isLine ) {
  5998. const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5999. const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6000. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6001. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6002. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6003. const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6004. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6005. }
  6006. if ( geometry.boundingSphere !== null ) {
  6007. this.boundingSphere = geometry.boundingSphere.clone();
  6008. }
  6009. if ( geometry.boundingBox !== null ) {
  6010. this.boundingBox = geometry.boundingBox.clone();
  6011. }
  6012. } else if ( object.isMesh ) {
  6013. if ( geometry && geometry.isGeometry ) {
  6014. this.fromGeometry( geometry );
  6015. }
  6016. }
  6017. return this;
  6018. },
  6019. setFromPoints: function ( points ) {
  6020. const position = [];
  6021. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6022. const point = points[ i ];
  6023. position.push( point.x, point.y, point.z || 0 );
  6024. }
  6025. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6026. return this;
  6027. },
  6028. updateFromObject: function ( object ) {
  6029. let geometry = object.geometry;
  6030. if ( object.isMesh ) {
  6031. let direct = geometry.__directGeometry;
  6032. if ( geometry.elementsNeedUpdate === true ) {
  6033. direct = undefined;
  6034. geometry.elementsNeedUpdate = false;
  6035. }
  6036. if ( direct === undefined ) {
  6037. return this.fromGeometry( geometry );
  6038. }
  6039. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6040. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6041. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6042. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6043. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6044. geometry.verticesNeedUpdate = false;
  6045. geometry.normalsNeedUpdate = false;
  6046. geometry.colorsNeedUpdate = false;
  6047. geometry.uvsNeedUpdate = false;
  6048. geometry.groupsNeedUpdate = false;
  6049. geometry = direct;
  6050. }
  6051. if ( geometry.verticesNeedUpdate === true ) {
  6052. const attribute = this.attributes.position;
  6053. if ( attribute !== undefined ) {
  6054. attribute.copyVector3sArray( geometry.vertices );
  6055. attribute.needsUpdate = true;
  6056. }
  6057. geometry.verticesNeedUpdate = false;
  6058. }
  6059. if ( geometry.normalsNeedUpdate === true ) {
  6060. const attribute = this.attributes.normal;
  6061. if ( attribute !== undefined ) {
  6062. attribute.copyVector3sArray( geometry.normals );
  6063. attribute.needsUpdate = true;
  6064. }
  6065. geometry.normalsNeedUpdate = false;
  6066. }
  6067. if ( geometry.colorsNeedUpdate === true ) {
  6068. const attribute = this.attributes.color;
  6069. if ( attribute !== undefined ) {
  6070. attribute.copyColorsArray( geometry.colors );
  6071. attribute.needsUpdate = true;
  6072. }
  6073. geometry.colorsNeedUpdate = false;
  6074. }
  6075. if ( geometry.uvsNeedUpdate ) {
  6076. const attribute = this.attributes.uv;
  6077. if ( attribute !== undefined ) {
  6078. attribute.copyVector2sArray( geometry.uvs );
  6079. attribute.needsUpdate = true;
  6080. }
  6081. geometry.uvsNeedUpdate = false;
  6082. }
  6083. if ( geometry.lineDistancesNeedUpdate ) {
  6084. const attribute = this.attributes.lineDistance;
  6085. if ( attribute !== undefined ) {
  6086. attribute.copyArray( geometry.lineDistances );
  6087. attribute.needsUpdate = true;
  6088. }
  6089. geometry.lineDistancesNeedUpdate = false;
  6090. }
  6091. if ( geometry.groupsNeedUpdate ) {
  6092. geometry.computeGroups( object.geometry );
  6093. this.groups = geometry.groups;
  6094. geometry.groupsNeedUpdate = false;
  6095. }
  6096. return this;
  6097. },
  6098. fromGeometry: function ( geometry ) {
  6099. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6100. return this.fromDirectGeometry( geometry.__directGeometry );
  6101. },
  6102. fromDirectGeometry: function ( geometry ) {
  6103. const positions = new Float32Array( geometry.vertices.length * 3 );
  6104. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6105. if ( geometry.normals.length > 0 ) {
  6106. const normals = new Float32Array( geometry.normals.length * 3 );
  6107. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6108. }
  6109. if ( geometry.colors.length > 0 ) {
  6110. const colors = new Float32Array( geometry.colors.length * 3 );
  6111. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6112. }
  6113. if ( geometry.uvs.length > 0 ) {
  6114. const uvs = new Float32Array( geometry.uvs.length * 2 );
  6115. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6116. }
  6117. if ( geometry.uvs2.length > 0 ) {
  6118. const uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6119. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6120. }
  6121. // groups
  6122. this.groups = geometry.groups;
  6123. // morphs
  6124. for ( const name in geometry.morphTargets ) {
  6125. const array = [];
  6126. const morphTargets = geometry.morphTargets[ name ];
  6127. for ( let i = 0, l = morphTargets.length; i < l; i ++ ) {
  6128. const morphTarget = morphTargets[ i ];
  6129. const attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6130. attribute.name = morphTarget.name;
  6131. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6132. }
  6133. this.morphAttributes[ name ] = array;
  6134. }
  6135. // skinning
  6136. if ( geometry.skinIndices.length > 0 ) {
  6137. const skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6138. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6139. }
  6140. if ( geometry.skinWeights.length > 0 ) {
  6141. const skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6142. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6143. }
  6144. //
  6145. if ( geometry.boundingSphere !== null ) {
  6146. this.boundingSphere = geometry.boundingSphere.clone();
  6147. }
  6148. if ( geometry.boundingBox !== null ) {
  6149. this.boundingBox = geometry.boundingBox.clone();
  6150. }
  6151. return this;
  6152. },
  6153. computeBoundingBox: function () {
  6154. if ( this.boundingBox === null ) {
  6155. this.boundingBox = new Box3();
  6156. }
  6157. const position = this.attributes.position;
  6158. const morphAttributesPosition = this.morphAttributes.position;
  6159. if ( position && position.isGLBufferAttribute ) {
  6160. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this );
  6161. this.boundingBox.set(
  6162. new Vector3( - Infinity, - Infinity, - Infinity ),
  6163. new Vector3( + Infinity, + Infinity, + Infinity )
  6164. );
  6165. return;
  6166. }
  6167. if ( position !== undefined ) {
  6168. this.boundingBox.setFromBufferAttribute( position );
  6169. // process morph attributes if present
  6170. if ( morphAttributesPosition ) {
  6171. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6172. const morphAttribute = morphAttributesPosition[ i ];
  6173. _box$2.setFromBufferAttribute( morphAttribute );
  6174. if ( this.morphTargetsRelative ) {
  6175. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6176. this.boundingBox.expandByPoint( _vector$4 );
  6177. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6178. this.boundingBox.expandByPoint( _vector$4 );
  6179. } else {
  6180. this.boundingBox.expandByPoint( _box$2.min );
  6181. this.boundingBox.expandByPoint( _box$2.max );
  6182. }
  6183. }
  6184. }
  6185. } else {
  6186. this.boundingBox.makeEmpty();
  6187. }
  6188. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6189. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6190. }
  6191. },
  6192. computeBoundingSphere: function () {
  6193. if ( this.boundingSphere === null ) {
  6194. this.boundingSphere = new Sphere();
  6195. }
  6196. const position = this.attributes.position;
  6197. const morphAttributesPosition = this.morphAttributes.position;
  6198. if ( position && position.isGLBufferAttribute ) {
  6199. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this );
  6200. this.boundingSphere.set( new Vector3(), Infinity );
  6201. return;
  6202. }
  6203. if ( position ) {
  6204. // first, find the center of the bounding sphere
  6205. const center = this.boundingSphere.center;
  6206. _box$2.setFromBufferAttribute( position );
  6207. // process morph attributes if present
  6208. if ( morphAttributesPosition ) {
  6209. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6210. const morphAttribute = morphAttributesPosition[ i ];
  6211. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6212. if ( this.morphTargetsRelative ) {
  6213. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6214. _box$2.expandByPoint( _vector$4 );
  6215. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6216. _box$2.expandByPoint( _vector$4 );
  6217. } else {
  6218. _box$2.expandByPoint( _boxMorphTargets.min );
  6219. _box$2.expandByPoint( _boxMorphTargets.max );
  6220. }
  6221. }
  6222. }
  6223. _box$2.getCenter( center );
  6224. // second, try to find a boundingSphere with a radius smaller than the
  6225. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6226. let maxRadiusSq = 0;
  6227. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6228. _vector$4.fromBufferAttribute( position, i );
  6229. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6230. }
  6231. // process morph attributes if present
  6232. if ( morphAttributesPosition ) {
  6233. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6234. const morphAttribute = morphAttributesPosition[ i ];
  6235. const morphTargetsRelative = this.morphTargetsRelative;
  6236. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6237. _vector$4.fromBufferAttribute( morphAttribute, j );
  6238. if ( morphTargetsRelative ) {
  6239. _offset.fromBufferAttribute( position, j );
  6240. _vector$4.add( _offset );
  6241. }
  6242. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6243. }
  6244. }
  6245. }
  6246. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6247. if ( isNaN( this.boundingSphere.radius ) ) {
  6248. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6249. }
  6250. }
  6251. },
  6252. computeFaceNormals: function () {
  6253. // backwards compatibility
  6254. },
  6255. computeVertexNormals: function () {
  6256. const index = this.index;
  6257. const positionAttribute = this.getAttribute( 'position' );
  6258. if ( positionAttribute !== undefined ) {
  6259. let normalAttribute = this.getAttribute( 'normal' );
  6260. if ( normalAttribute === undefined ) {
  6261. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6262. this.setAttribute( 'normal', normalAttribute );
  6263. } else {
  6264. // reset existing normals to zero
  6265. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6266. normalAttribute.setXYZ( i, 0, 0, 0 );
  6267. }
  6268. }
  6269. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6270. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6271. const cb = new Vector3(), ab = new Vector3();
  6272. // indexed elements
  6273. if ( index ) {
  6274. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6275. const vA = index.getX( i + 0 );
  6276. const vB = index.getX( i + 1 );
  6277. const vC = index.getX( i + 2 );
  6278. pA.fromBufferAttribute( positionAttribute, vA );
  6279. pB.fromBufferAttribute( positionAttribute, vB );
  6280. pC.fromBufferAttribute( positionAttribute, vC );
  6281. cb.subVectors( pC, pB );
  6282. ab.subVectors( pA, pB );
  6283. cb.cross( ab );
  6284. nA.fromBufferAttribute( normalAttribute, vA );
  6285. nB.fromBufferAttribute( normalAttribute, vB );
  6286. nC.fromBufferAttribute( normalAttribute, vC );
  6287. nA.add( cb );
  6288. nB.add( cb );
  6289. nC.add( cb );
  6290. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6291. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6292. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6293. }
  6294. } else {
  6295. // non-indexed elements (unconnected triangle soup)
  6296. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6297. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6298. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6299. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6300. cb.subVectors( pC, pB );
  6301. ab.subVectors( pA, pB );
  6302. cb.cross( ab );
  6303. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6304. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6305. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6306. }
  6307. }
  6308. this.normalizeNormals();
  6309. normalAttribute.needsUpdate = true;
  6310. }
  6311. },
  6312. merge: function ( geometry, offset ) {
  6313. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6314. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6315. return;
  6316. }
  6317. if ( offset === undefined ) {
  6318. offset = 0;
  6319. console.warn(
  6320. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6321. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6322. );
  6323. }
  6324. const attributes = this.attributes;
  6325. for ( const key in attributes ) {
  6326. if ( geometry.attributes[ key ] === undefined ) continue;
  6327. const attribute1 = attributes[ key ];
  6328. const attributeArray1 = attribute1.array;
  6329. const attribute2 = geometry.attributes[ key ];
  6330. const attributeArray2 = attribute2.array;
  6331. const attributeOffset = attribute2.itemSize * offset;
  6332. const length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6333. for ( let i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6334. attributeArray1[ j ] = attributeArray2[ i ];
  6335. }
  6336. }
  6337. return this;
  6338. },
  6339. normalizeNormals: function () {
  6340. const normals = this.attributes.normal;
  6341. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6342. _vector$4.fromBufferAttribute( normals, i );
  6343. _vector$4.normalize();
  6344. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6345. }
  6346. },
  6347. toNonIndexed: function () {
  6348. function convertBufferAttribute( attribute, indices ) {
  6349. const array = attribute.array;
  6350. const itemSize = attribute.itemSize;
  6351. const normalized = attribute.normalized;
  6352. const array2 = new array.constructor( indices.length * itemSize );
  6353. let index = 0, index2 = 0;
  6354. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6355. index = indices[ i ] * itemSize;
  6356. for ( let j = 0; j < itemSize; j ++ ) {
  6357. array2[ index2 ++ ] = array[ index ++ ];
  6358. }
  6359. }
  6360. return new BufferAttribute( array2, itemSize, normalized );
  6361. }
  6362. //
  6363. if ( this.index === null ) {
  6364. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6365. return this;
  6366. }
  6367. const geometry2 = new BufferGeometry();
  6368. const indices = this.index.array;
  6369. const attributes = this.attributes;
  6370. // attributes
  6371. for ( const name in attributes ) {
  6372. const attribute = attributes[ name ];
  6373. const newAttribute = convertBufferAttribute( attribute, indices );
  6374. geometry2.setAttribute( name, newAttribute );
  6375. }
  6376. // morph attributes
  6377. const morphAttributes = this.morphAttributes;
  6378. for ( const name in morphAttributes ) {
  6379. const morphArray = [];
  6380. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6381. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6382. const attribute = morphAttribute[ i ];
  6383. const newAttribute = convertBufferAttribute( attribute, indices );
  6384. morphArray.push( newAttribute );
  6385. }
  6386. geometry2.morphAttributes[ name ] = morphArray;
  6387. }
  6388. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6389. // groups
  6390. const groups = this.groups;
  6391. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6392. const group = groups[ i ];
  6393. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6394. }
  6395. return geometry2;
  6396. },
  6397. toJSON: function () {
  6398. const data = {
  6399. metadata: {
  6400. version: 4.5,
  6401. type: 'BufferGeometry',
  6402. generator: 'BufferGeometry.toJSON'
  6403. }
  6404. };
  6405. // standard BufferGeometry serialization
  6406. data.uuid = this.uuid;
  6407. data.type = this.type;
  6408. if ( this.name !== '' ) data.name = this.name;
  6409. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6410. if ( this.parameters !== undefined ) {
  6411. const parameters = this.parameters;
  6412. for ( const key in parameters ) {
  6413. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6414. }
  6415. return data;
  6416. }
  6417. data.data = { attributes: {} };
  6418. const index = this.index;
  6419. if ( index !== null ) {
  6420. data.data.index = {
  6421. type: index.array.constructor.name,
  6422. array: Array.prototype.slice.call( index.array )
  6423. };
  6424. }
  6425. const attributes = this.attributes;
  6426. for ( const key in attributes ) {
  6427. const attribute = attributes[ key ];
  6428. const attributeData = attribute.toJSON( data.data );
  6429. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6430. data.data.attributes[ key ] = attributeData;
  6431. }
  6432. const morphAttributes = {};
  6433. let hasMorphAttributes = false;
  6434. for ( const key in this.morphAttributes ) {
  6435. const attributeArray = this.morphAttributes[ key ];
  6436. const array = [];
  6437. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6438. const attribute = attributeArray[ i ];
  6439. const attributeData = attribute.toJSON( data.data );
  6440. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6441. array.push( attributeData );
  6442. }
  6443. if ( array.length > 0 ) {
  6444. morphAttributes[ key ] = array;
  6445. hasMorphAttributes = true;
  6446. }
  6447. }
  6448. if ( hasMorphAttributes ) {
  6449. data.data.morphAttributes = morphAttributes;
  6450. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6451. }
  6452. const groups = this.groups;
  6453. if ( groups.length > 0 ) {
  6454. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6455. }
  6456. const boundingSphere = this.boundingSphere;
  6457. if ( boundingSphere !== null ) {
  6458. data.data.boundingSphere = {
  6459. center: boundingSphere.center.toArray(),
  6460. radius: boundingSphere.radius
  6461. };
  6462. }
  6463. return data;
  6464. },
  6465. clone: function () {
  6466. /*
  6467. // Handle primitives
  6468. const parameters = this.parameters;
  6469. if ( parameters !== undefined ) {
  6470. const values = [];
  6471. for ( const key in parameters ) {
  6472. values.push( parameters[ key ] );
  6473. }
  6474. const geometry = Object.create( this.constructor.prototype );
  6475. this.constructor.apply( geometry, values );
  6476. return geometry;
  6477. }
  6478. return new this.constructor().copy( this );
  6479. */
  6480. return new BufferGeometry().copy( this );
  6481. },
  6482. copy: function ( source ) {
  6483. // reset
  6484. this.index = null;
  6485. this.attributes = {};
  6486. this.morphAttributes = {};
  6487. this.groups = [];
  6488. this.boundingBox = null;
  6489. this.boundingSphere = null;
  6490. // used for storing cloned, shared data
  6491. const data = {};
  6492. // name
  6493. this.name = source.name;
  6494. // index
  6495. const index = source.index;
  6496. if ( index !== null ) {
  6497. this.setIndex( index.clone( data ) );
  6498. }
  6499. // attributes
  6500. const attributes = source.attributes;
  6501. for ( const name in attributes ) {
  6502. const attribute = attributes[ name ];
  6503. this.setAttribute( name, attribute.clone( data ) );
  6504. }
  6505. // morph attributes
  6506. const morphAttributes = source.morphAttributes;
  6507. for ( const name in morphAttributes ) {
  6508. const array = [];
  6509. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6510. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6511. array.push( morphAttribute[ i ].clone( data ) );
  6512. }
  6513. this.morphAttributes[ name ] = array;
  6514. }
  6515. this.morphTargetsRelative = source.morphTargetsRelative;
  6516. // groups
  6517. const groups = source.groups;
  6518. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6519. const group = groups[ i ];
  6520. this.addGroup( group.start, group.count, group.materialIndex );
  6521. }
  6522. // bounding box
  6523. const boundingBox = source.boundingBox;
  6524. if ( boundingBox !== null ) {
  6525. this.boundingBox = boundingBox.clone();
  6526. }
  6527. // bounding sphere
  6528. const boundingSphere = source.boundingSphere;
  6529. if ( boundingSphere !== null ) {
  6530. this.boundingSphere = boundingSphere.clone();
  6531. }
  6532. // draw range
  6533. this.drawRange.start = source.drawRange.start;
  6534. this.drawRange.count = source.drawRange.count;
  6535. // user data
  6536. this.userData = source.userData;
  6537. return this;
  6538. },
  6539. dispose: function () {
  6540. this.dispatchEvent( { type: 'dispose' } );
  6541. }
  6542. } );
  6543. const _inverseMatrix = new Matrix4();
  6544. const _ray = new Ray();
  6545. const _sphere = new Sphere();
  6546. const _vA = new Vector3();
  6547. const _vB = new Vector3();
  6548. const _vC = new Vector3();
  6549. const _tempA = new Vector3();
  6550. const _tempB = new Vector3();
  6551. const _tempC = new Vector3();
  6552. const _morphA = new Vector3();
  6553. const _morphB = new Vector3();
  6554. const _morphC = new Vector3();
  6555. const _uvA = new Vector2();
  6556. const _uvB = new Vector2();
  6557. const _uvC = new Vector2();
  6558. const _intersectionPoint = new Vector3();
  6559. const _intersectionPointWorld = new Vector3();
  6560. function Mesh( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6561. Object3D.call( this );
  6562. this.type = 'Mesh';
  6563. this.geometry = geometry;
  6564. this.material = material;
  6565. this.updateMorphTargets();
  6566. }
  6567. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6568. constructor: Mesh,
  6569. isMesh: true,
  6570. copy: function ( source ) {
  6571. Object3D.prototype.copy.call( this, source );
  6572. if ( source.morphTargetInfluences !== undefined ) {
  6573. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6574. }
  6575. if ( source.morphTargetDictionary !== undefined ) {
  6576. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6577. }
  6578. this.material = source.material;
  6579. this.geometry = source.geometry;
  6580. return this;
  6581. },
  6582. updateMorphTargets: function () {
  6583. const geometry = this.geometry;
  6584. if ( geometry.isBufferGeometry ) {
  6585. const morphAttributes = geometry.morphAttributes;
  6586. const keys = Object.keys( morphAttributes );
  6587. if ( keys.length > 0 ) {
  6588. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6589. if ( morphAttribute !== undefined ) {
  6590. this.morphTargetInfluences = [];
  6591. this.morphTargetDictionary = {};
  6592. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6593. const name = morphAttribute[ m ].name || String( m );
  6594. this.morphTargetInfluences.push( 0 );
  6595. this.morphTargetDictionary[ name ] = m;
  6596. }
  6597. }
  6598. }
  6599. } else {
  6600. const morphTargets = geometry.morphTargets;
  6601. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6602. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6603. }
  6604. }
  6605. },
  6606. raycast: function ( raycaster, intersects ) {
  6607. const geometry = this.geometry;
  6608. const material = this.material;
  6609. const matrixWorld = this.matrixWorld;
  6610. if ( material === undefined ) return;
  6611. // Checking boundingSphere distance to ray
  6612. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6613. _sphere.copy( geometry.boundingSphere );
  6614. _sphere.applyMatrix4( matrixWorld );
  6615. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6616. //
  6617. _inverseMatrix.copy( matrixWorld ).invert();
  6618. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6619. // Check boundingBox before continuing
  6620. if ( geometry.boundingBox !== null ) {
  6621. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6622. }
  6623. let intersection;
  6624. if ( geometry.isBufferGeometry ) {
  6625. const index = geometry.index;
  6626. const position = geometry.attributes.position;
  6627. const morphPosition = geometry.morphAttributes.position;
  6628. const morphTargetsRelative = geometry.morphTargetsRelative;
  6629. const uv = geometry.attributes.uv;
  6630. const uv2 = geometry.attributes.uv2;
  6631. const groups = geometry.groups;
  6632. const drawRange = geometry.drawRange;
  6633. if ( index !== null ) {
  6634. // indexed buffer geometry
  6635. if ( Array.isArray( material ) ) {
  6636. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6637. const group = groups[ i ];
  6638. const groupMaterial = material[ group.materialIndex ];
  6639. const start = Math.max( group.start, drawRange.start );
  6640. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6641. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6642. const a = index.getX( j );
  6643. const b = index.getX( j + 1 );
  6644. const c = index.getX( j + 2 );
  6645. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6646. if ( intersection ) {
  6647. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6648. intersection.face.materialIndex = group.materialIndex;
  6649. intersects.push( intersection );
  6650. }
  6651. }
  6652. }
  6653. } else {
  6654. const start = Math.max( 0, drawRange.start );
  6655. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6656. for ( let i = start, il = end; i < il; i += 3 ) {
  6657. const a = index.getX( i );
  6658. const b = index.getX( i + 1 );
  6659. const c = index.getX( i + 2 );
  6660. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6661. if ( intersection ) {
  6662. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6663. intersects.push( intersection );
  6664. }
  6665. }
  6666. }
  6667. } else if ( position !== undefined ) {
  6668. // non-indexed buffer geometry
  6669. if ( Array.isArray( material ) ) {
  6670. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6671. const group = groups[ i ];
  6672. const groupMaterial = material[ group.materialIndex ];
  6673. const start = Math.max( group.start, drawRange.start );
  6674. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6675. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6676. const a = j;
  6677. const b = j + 1;
  6678. const c = j + 2;
  6679. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6680. if ( intersection ) {
  6681. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6682. intersection.face.materialIndex = group.materialIndex;
  6683. intersects.push( intersection );
  6684. }
  6685. }
  6686. }
  6687. } else {
  6688. const start = Math.max( 0, drawRange.start );
  6689. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6690. for ( let i = start, il = end; i < il; i += 3 ) {
  6691. const a = i;
  6692. const b = i + 1;
  6693. const c = i + 2;
  6694. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6695. if ( intersection ) {
  6696. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6697. intersects.push( intersection );
  6698. }
  6699. }
  6700. }
  6701. }
  6702. } else if ( geometry.isGeometry ) {
  6703. console.error( 'THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6704. }
  6705. }
  6706. } );
  6707. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6708. let intersect;
  6709. if ( material.side === BackSide ) {
  6710. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6711. } else {
  6712. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6713. }
  6714. if ( intersect === null ) return null;
  6715. _intersectionPointWorld.copy( point );
  6716. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6717. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6718. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6719. return {
  6720. distance: distance,
  6721. point: _intersectionPointWorld.clone(),
  6722. object: object
  6723. };
  6724. }
  6725. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6726. _vA.fromBufferAttribute( position, a );
  6727. _vB.fromBufferAttribute( position, b );
  6728. _vC.fromBufferAttribute( position, c );
  6729. const morphInfluences = object.morphTargetInfluences;
  6730. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6731. _morphA.set( 0, 0, 0 );
  6732. _morphB.set( 0, 0, 0 );
  6733. _morphC.set( 0, 0, 0 );
  6734. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  6735. const influence = morphInfluences[ i ];
  6736. const morphAttribute = morphPosition[ i ];
  6737. if ( influence === 0 ) continue;
  6738. _tempA.fromBufferAttribute( morphAttribute, a );
  6739. _tempB.fromBufferAttribute( morphAttribute, b );
  6740. _tempC.fromBufferAttribute( morphAttribute, c );
  6741. if ( morphTargetsRelative ) {
  6742. _morphA.addScaledVector( _tempA, influence );
  6743. _morphB.addScaledVector( _tempB, influence );
  6744. _morphC.addScaledVector( _tempC, influence );
  6745. } else {
  6746. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6747. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6748. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6749. }
  6750. }
  6751. _vA.add( _morphA );
  6752. _vB.add( _morphB );
  6753. _vC.add( _morphC );
  6754. }
  6755. if ( object.isSkinnedMesh ) {
  6756. object.boneTransform( a, _vA );
  6757. object.boneTransform( b, _vB );
  6758. object.boneTransform( c, _vC );
  6759. }
  6760. const intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6761. if ( intersection ) {
  6762. if ( uv ) {
  6763. _uvA.fromBufferAttribute( uv, a );
  6764. _uvB.fromBufferAttribute( uv, b );
  6765. _uvC.fromBufferAttribute( uv, c );
  6766. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6767. }
  6768. if ( uv2 ) {
  6769. _uvA.fromBufferAttribute( uv2, a );
  6770. _uvB.fromBufferAttribute( uv2, b );
  6771. _uvC.fromBufferAttribute( uv2, c );
  6772. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6773. }
  6774. const face = new Face3( a, b, c );
  6775. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6776. intersection.face = face;
  6777. }
  6778. return intersection;
  6779. }
  6780. class BoxGeometry extends BufferGeometry {
  6781. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  6782. super();
  6783. this.type = 'BoxGeometry';
  6784. this.parameters = {
  6785. width: width,
  6786. height: height,
  6787. depth: depth,
  6788. widthSegments: widthSegments,
  6789. heightSegments: heightSegments,
  6790. depthSegments: depthSegments
  6791. };
  6792. const scope = this;
  6793. // segments
  6794. widthSegments = Math.floor( widthSegments );
  6795. heightSegments = Math.floor( heightSegments );
  6796. depthSegments = Math.floor( depthSegments );
  6797. // buffers
  6798. const indices = [];
  6799. const vertices = [];
  6800. const normals = [];
  6801. const uvs = [];
  6802. // helper variables
  6803. let numberOfVertices = 0;
  6804. let groupStart = 0;
  6805. // build each side of the box geometry
  6806. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  6807. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  6808. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  6809. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  6810. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  6811. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  6812. // build geometry
  6813. this.setIndex( indices );
  6814. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  6815. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  6816. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  6817. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  6818. const segmentWidth = width / gridX;
  6819. const segmentHeight = height / gridY;
  6820. const widthHalf = width / 2;
  6821. const heightHalf = height / 2;
  6822. const depthHalf = depth / 2;
  6823. const gridX1 = gridX + 1;
  6824. const gridY1 = gridY + 1;
  6825. let vertexCounter = 0;
  6826. let groupCount = 0;
  6827. const vector = new Vector3();
  6828. // generate vertices, normals and uvs
  6829. for ( let iy = 0; iy < gridY1; iy ++ ) {
  6830. const y = iy * segmentHeight - heightHalf;
  6831. for ( let ix = 0; ix < gridX1; ix ++ ) {
  6832. const x = ix * segmentWidth - widthHalf;
  6833. // set values to correct vector component
  6834. vector[ u ] = x * udir;
  6835. vector[ v ] = y * vdir;
  6836. vector[ w ] = depthHalf;
  6837. // now apply vector to vertex buffer
  6838. vertices.push( vector.x, vector.y, vector.z );
  6839. // set values to correct vector component
  6840. vector[ u ] = 0;
  6841. vector[ v ] = 0;
  6842. vector[ w ] = depth > 0 ? 1 : - 1;
  6843. // now apply vector to normal buffer
  6844. normals.push( vector.x, vector.y, vector.z );
  6845. // uvs
  6846. uvs.push( ix / gridX );
  6847. uvs.push( 1 - ( iy / gridY ) );
  6848. // counters
  6849. vertexCounter += 1;
  6850. }
  6851. }
  6852. // indices
  6853. // 1. you need three indices to draw a single face
  6854. // 2. a single segment consists of two faces
  6855. // 3. so we need to generate six (2*3) indices per segment
  6856. for ( let iy = 0; iy < gridY; iy ++ ) {
  6857. for ( let ix = 0; ix < gridX; ix ++ ) {
  6858. const a = numberOfVertices + ix + gridX1 * iy;
  6859. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  6860. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  6861. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  6862. // faces
  6863. indices.push( a, b, d );
  6864. indices.push( b, c, d );
  6865. // increase counter
  6866. groupCount += 6;
  6867. }
  6868. }
  6869. // add a group to the geometry. this will ensure multi material support
  6870. scope.addGroup( groupStart, groupCount, materialIndex );
  6871. // calculate new start value for groups
  6872. groupStart += groupCount;
  6873. // update total number of vertices
  6874. numberOfVertices += vertexCounter;
  6875. }
  6876. }
  6877. }
  6878. /**
  6879. * Uniform Utilities
  6880. */
  6881. function cloneUniforms( src ) {
  6882. const dst = {};
  6883. for ( const u in src ) {
  6884. dst[ u ] = {};
  6885. for ( const p in src[ u ] ) {
  6886. const property = src[ u ][ p ];
  6887. if ( property && ( property.isColor ||
  6888. property.isMatrix3 || property.isMatrix4 ||
  6889. property.isVector2 || property.isVector3 || property.isVector4 ||
  6890. property.isTexture ) ) {
  6891. dst[ u ][ p ] = property.clone();
  6892. } else if ( Array.isArray( property ) ) {
  6893. dst[ u ][ p ] = property.slice();
  6894. } else {
  6895. dst[ u ][ p ] = property;
  6896. }
  6897. }
  6898. }
  6899. return dst;
  6900. }
  6901. function mergeUniforms( uniforms ) {
  6902. const merged = {};
  6903. for ( let u = 0; u < uniforms.length; u ++ ) {
  6904. const tmp = cloneUniforms( uniforms[ u ] );
  6905. for ( const p in tmp ) {
  6906. merged[ p ] = tmp[ p ];
  6907. }
  6908. }
  6909. return merged;
  6910. }
  6911. // Legacy
  6912. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  6913. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  6914. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  6915. /**
  6916. * parameters = {
  6917. * defines: { "label" : "value" },
  6918. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  6919. *
  6920. * fragmentShader: <string>,
  6921. * vertexShader: <string>,
  6922. *
  6923. * wireframe: <boolean>,
  6924. * wireframeLinewidth: <float>,
  6925. *
  6926. * lights: <bool>,
  6927. *
  6928. * skinning: <bool>,
  6929. * morphTargets: <bool>,
  6930. * morphNormals: <bool>
  6931. * }
  6932. */
  6933. function ShaderMaterial( parameters ) {
  6934. Material.call( this );
  6935. this.type = 'ShaderMaterial';
  6936. this.defines = {};
  6937. this.uniforms = {};
  6938. this.vertexShader = default_vertex;
  6939. this.fragmentShader = default_fragment;
  6940. this.linewidth = 1;
  6941. this.wireframe = false;
  6942. this.wireframeLinewidth = 1;
  6943. this.fog = false; // set to use scene fog
  6944. this.lights = false; // set to use scene lights
  6945. this.clipping = false; // set to use user-defined clipping planes
  6946. this.skinning = false; // set to use skinning attribute streams
  6947. this.morphTargets = false; // set to use morph targets
  6948. this.morphNormals = false; // set to use morph normals
  6949. this.extensions = {
  6950. derivatives: false, // set to use derivatives
  6951. fragDepth: false, // set to use fragment depth values
  6952. drawBuffers: false, // set to use draw buffers
  6953. shaderTextureLOD: false // set to use shader texture LOD
  6954. };
  6955. // When rendered geometry doesn't include these attributes but the material does,
  6956. // use these default values in WebGL. This avoids errors when buffer data is missing.
  6957. this.defaultAttributeValues = {
  6958. 'color': [ 1, 1, 1 ],
  6959. 'uv': [ 0, 0 ],
  6960. 'uv2': [ 0, 0 ]
  6961. };
  6962. this.index0AttributeName = undefined;
  6963. this.uniformsNeedUpdate = false;
  6964. this.glslVersion = null;
  6965. if ( parameters !== undefined ) {
  6966. if ( parameters.attributes !== undefined ) {
  6967. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  6968. }
  6969. this.setValues( parameters );
  6970. }
  6971. }
  6972. ShaderMaterial.prototype = Object.create( Material.prototype );
  6973. ShaderMaterial.prototype.constructor = ShaderMaterial;
  6974. ShaderMaterial.prototype.isShaderMaterial = true;
  6975. ShaderMaterial.prototype.copy = function ( source ) {
  6976. Material.prototype.copy.call( this, source );
  6977. this.fragmentShader = source.fragmentShader;
  6978. this.vertexShader = source.vertexShader;
  6979. this.uniforms = cloneUniforms( source.uniforms );
  6980. this.defines = Object.assign( {}, source.defines );
  6981. this.wireframe = source.wireframe;
  6982. this.wireframeLinewidth = source.wireframeLinewidth;
  6983. this.lights = source.lights;
  6984. this.clipping = source.clipping;
  6985. this.skinning = source.skinning;
  6986. this.morphTargets = source.morphTargets;
  6987. this.morphNormals = source.morphNormals;
  6988. this.extensions = Object.assign( {}, source.extensions );
  6989. this.glslVersion = source.glslVersion;
  6990. return this;
  6991. };
  6992. ShaderMaterial.prototype.toJSON = function ( meta ) {
  6993. const data = Material.prototype.toJSON.call( this, meta );
  6994. data.glslVersion = this.glslVersion;
  6995. data.uniforms = {};
  6996. for ( const name in this.uniforms ) {
  6997. const uniform = this.uniforms[ name ];
  6998. const value = uniform.value;
  6999. if ( value && value.isTexture ) {
  7000. data.uniforms[ name ] = {
  7001. type: 't',
  7002. value: value.toJSON( meta ).uuid
  7003. };
  7004. } else if ( value && value.isColor ) {
  7005. data.uniforms[ name ] = {
  7006. type: 'c',
  7007. value: value.getHex()
  7008. };
  7009. } else if ( value && value.isVector2 ) {
  7010. data.uniforms[ name ] = {
  7011. type: 'v2',
  7012. value: value.toArray()
  7013. };
  7014. } else if ( value && value.isVector3 ) {
  7015. data.uniforms[ name ] = {
  7016. type: 'v3',
  7017. value: value.toArray()
  7018. };
  7019. } else if ( value && value.isVector4 ) {
  7020. data.uniforms[ name ] = {
  7021. type: 'v4',
  7022. value: value.toArray()
  7023. };
  7024. } else if ( value && value.isMatrix3 ) {
  7025. data.uniforms[ name ] = {
  7026. type: 'm3',
  7027. value: value.toArray()
  7028. };
  7029. } else if ( value && value.isMatrix4 ) {
  7030. data.uniforms[ name ] = {
  7031. type: 'm4',
  7032. value: value.toArray()
  7033. };
  7034. } else {
  7035. data.uniforms[ name ] = {
  7036. value: value
  7037. };
  7038. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7039. }
  7040. }
  7041. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7042. data.vertexShader = this.vertexShader;
  7043. data.fragmentShader = this.fragmentShader;
  7044. const extensions = {};
  7045. for ( const key in this.extensions ) {
  7046. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7047. }
  7048. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7049. return data;
  7050. };
  7051. function Camera() {
  7052. Object3D.call( this );
  7053. this.type = 'Camera';
  7054. this.matrixWorldInverse = new Matrix4();
  7055. this.projectionMatrix = new Matrix4();
  7056. this.projectionMatrixInverse = new Matrix4();
  7057. }
  7058. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7059. constructor: Camera,
  7060. isCamera: true,
  7061. copy: function ( source, recursive ) {
  7062. Object3D.prototype.copy.call( this, source, recursive );
  7063. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7064. this.projectionMatrix.copy( source.projectionMatrix );
  7065. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7066. return this;
  7067. },
  7068. getWorldDirection: function ( target ) {
  7069. if ( target === undefined ) {
  7070. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7071. target = new Vector3();
  7072. }
  7073. this.updateWorldMatrix( true, false );
  7074. const e = this.matrixWorld.elements;
  7075. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7076. },
  7077. updateMatrixWorld: function ( force ) {
  7078. Object3D.prototype.updateMatrixWorld.call( this, force );
  7079. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7080. },
  7081. updateWorldMatrix: function ( updateParents, updateChildren ) {
  7082. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  7083. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7084. },
  7085. clone: function () {
  7086. return new this.constructor().copy( this );
  7087. }
  7088. } );
  7089. function PerspectiveCamera( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7090. Camera.call( this );
  7091. this.type = 'PerspectiveCamera';
  7092. this.fov = fov;
  7093. this.zoom = 1;
  7094. this.near = near;
  7095. this.far = far;
  7096. this.focus = 10;
  7097. this.aspect = aspect;
  7098. this.view = null;
  7099. this.filmGauge = 35; // width of the film (default in millimeters)
  7100. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7101. this.updateProjectionMatrix();
  7102. }
  7103. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7104. constructor: PerspectiveCamera,
  7105. isPerspectiveCamera: true,
  7106. copy: function ( source, recursive ) {
  7107. Camera.prototype.copy.call( this, source, recursive );
  7108. this.fov = source.fov;
  7109. this.zoom = source.zoom;
  7110. this.near = source.near;
  7111. this.far = source.far;
  7112. this.focus = source.focus;
  7113. this.aspect = source.aspect;
  7114. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7115. this.filmGauge = source.filmGauge;
  7116. this.filmOffset = source.filmOffset;
  7117. return this;
  7118. },
  7119. /**
  7120. * Sets the FOV by focal length in respect to the current .filmGauge.
  7121. *
  7122. * The default film gauge is 35, so that the focal length can be specified for
  7123. * a 35mm (full frame) camera.
  7124. *
  7125. * Values for focal length and film gauge must have the same unit.
  7126. */
  7127. setFocalLength: function ( focalLength ) {
  7128. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7129. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7130. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7131. this.updateProjectionMatrix();
  7132. },
  7133. /**
  7134. * Calculates the focal length from the current .fov and .filmGauge.
  7135. */
  7136. getFocalLength: function () {
  7137. const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  7138. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7139. },
  7140. getEffectiveFOV: function () {
  7141. return MathUtils.RAD2DEG * 2 * Math.atan(
  7142. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7143. },
  7144. getFilmWidth: function () {
  7145. // film not completely covered in portrait format (aspect < 1)
  7146. return this.filmGauge * Math.min( this.aspect, 1 );
  7147. },
  7148. getFilmHeight: function () {
  7149. // film not completely covered in landscape format (aspect > 1)
  7150. return this.filmGauge / Math.max( this.aspect, 1 );
  7151. },
  7152. /**
  7153. * Sets an offset in a larger frustum. This is useful for multi-window or
  7154. * multi-monitor/multi-machine setups.
  7155. *
  7156. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7157. * the monitors are in grid like this
  7158. *
  7159. * +---+---+---+
  7160. * | A | B | C |
  7161. * +---+---+---+
  7162. * | D | E | F |
  7163. * +---+---+---+
  7164. *
  7165. * then for each monitor you would call it like this
  7166. *
  7167. * const w = 1920;
  7168. * const h = 1080;
  7169. * const fullWidth = w * 3;
  7170. * const fullHeight = h * 2;
  7171. *
  7172. * --A--
  7173. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7174. * --B--
  7175. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7176. * --C--
  7177. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7178. * --D--
  7179. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7180. * --E--
  7181. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7182. * --F--
  7183. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7184. *
  7185. * Note there is no reason monitors have to be the same size or in a grid.
  7186. */
  7187. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  7188. this.aspect = fullWidth / fullHeight;
  7189. if ( this.view === null ) {
  7190. this.view = {
  7191. enabled: true,
  7192. fullWidth: 1,
  7193. fullHeight: 1,
  7194. offsetX: 0,
  7195. offsetY: 0,
  7196. width: 1,
  7197. height: 1
  7198. };
  7199. }
  7200. this.view.enabled = true;
  7201. this.view.fullWidth = fullWidth;
  7202. this.view.fullHeight = fullHeight;
  7203. this.view.offsetX = x;
  7204. this.view.offsetY = y;
  7205. this.view.width = width;
  7206. this.view.height = height;
  7207. this.updateProjectionMatrix();
  7208. },
  7209. clearViewOffset: function () {
  7210. if ( this.view !== null ) {
  7211. this.view.enabled = false;
  7212. }
  7213. this.updateProjectionMatrix();
  7214. },
  7215. updateProjectionMatrix: function () {
  7216. const near = this.near;
  7217. let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7218. let height = 2 * top;
  7219. let width = this.aspect * height;
  7220. let left = - 0.5 * width;
  7221. const view = this.view;
  7222. if ( this.view !== null && this.view.enabled ) {
  7223. const fullWidth = view.fullWidth,
  7224. fullHeight = view.fullHeight;
  7225. left += view.offsetX * width / fullWidth;
  7226. top -= view.offsetY * height / fullHeight;
  7227. width *= view.width / fullWidth;
  7228. height *= view.height / fullHeight;
  7229. }
  7230. const skew = this.filmOffset;
  7231. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7232. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  7233. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7234. },
  7235. toJSON: function ( meta ) {
  7236. const data = Object3D.prototype.toJSON.call( this, meta );
  7237. data.object.fov = this.fov;
  7238. data.object.zoom = this.zoom;
  7239. data.object.near = this.near;
  7240. data.object.far = this.far;
  7241. data.object.focus = this.focus;
  7242. data.object.aspect = this.aspect;
  7243. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7244. data.object.filmGauge = this.filmGauge;
  7245. data.object.filmOffset = this.filmOffset;
  7246. return data;
  7247. }
  7248. } );
  7249. const fov = 90, aspect = 1;
  7250. function CubeCamera( near, far, renderTarget ) {
  7251. Object3D.call( this );
  7252. this.type = 'CubeCamera';
  7253. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  7254. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  7255. return;
  7256. }
  7257. this.renderTarget = renderTarget;
  7258. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7259. cameraPX.layers = this.layers;
  7260. cameraPX.up.set( 0, - 1, 0 );
  7261. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  7262. this.add( cameraPX );
  7263. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7264. cameraNX.layers = this.layers;
  7265. cameraNX.up.set( 0, - 1, 0 );
  7266. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  7267. this.add( cameraNX );
  7268. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7269. cameraPY.layers = this.layers;
  7270. cameraPY.up.set( 0, 0, 1 );
  7271. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  7272. this.add( cameraPY );
  7273. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7274. cameraNY.layers = this.layers;
  7275. cameraNY.up.set( 0, 0, - 1 );
  7276. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  7277. this.add( cameraNY );
  7278. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7279. cameraPZ.layers = this.layers;
  7280. cameraPZ.up.set( 0, - 1, 0 );
  7281. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  7282. this.add( cameraPZ );
  7283. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7284. cameraNZ.layers = this.layers;
  7285. cameraNZ.up.set( 0, - 1, 0 );
  7286. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  7287. this.add( cameraNZ );
  7288. this.update = function ( renderer, scene ) {
  7289. if ( this.parent === null ) this.updateMatrixWorld();
  7290. const currentXrEnabled = renderer.xr.enabled;
  7291. const currentRenderTarget = renderer.getRenderTarget();
  7292. renderer.xr.enabled = false;
  7293. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7294. renderTarget.texture.generateMipmaps = false;
  7295. renderer.setRenderTarget( renderTarget, 0 );
  7296. renderer.render( scene, cameraPX );
  7297. renderer.setRenderTarget( renderTarget, 1 );
  7298. renderer.render( scene, cameraNX );
  7299. renderer.setRenderTarget( renderTarget, 2 );
  7300. renderer.render( scene, cameraPY );
  7301. renderer.setRenderTarget( renderTarget, 3 );
  7302. renderer.render( scene, cameraNY );
  7303. renderer.setRenderTarget( renderTarget, 4 );
  7304. renderer.render( scene, cameraPZ );
  7305. renderTarget.texture.generateMipmaps = generateMipmaps;
  7306. renderer.setRenderTarget( renderTarget, 5 );
  7307. renderer.render( scene, cameraNZ );
  7308. renderer.setRenderTarget( currentRenderTarget );
  7309. renderer.xr.enabled = currentXrEnabled;
  7310. };
  7311. }
  7312. CubeCamera.prototype = Object.create( Object3D.prototype );
  7313. CubeCamera.prototype.constructor = CubeCamera;
  7314. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  7315. images = images !== undefined ? images : [];
  7316. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7317. format = format !== undefined ? format : RGBFormat;
  7318. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7319. this.flipY = false;
  7320. // Why CubeTexture._needsFlipEnvMap is necessary:
  7321. //
  7322. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7323. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7324. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7325. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7326. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7327. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7328. this._needsFlipEnvMap = true;
  7329. }
  7330. CubeTexture.prototype = Object.create( Texture.prototype );
  7331. CubeTexture.prototype.constructor = CubeTexture;
  7332. CubeTexture.prototype.isCubeTexture = true;
  7333. Object.defineProperty( CubeTexture.prototype, 'images', {
  7334. get: function () {
  7335. return this.image;
  7336. },
  7337. set: function ( value ) {
  7338. this.image = value;
  7339. }
  7340. } );
  7341. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7342. constructor( size, options, dummy ) {
  7343. if ( Number.isInteger( options ) ) {
  7344. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  7345. options = dummy;
  7346. }
  7347. super( size, size, options );
  7348. Object.defineProperty( this, 'isWebGLCubeRenderTarget', { value: true } );
  7349. options = options || {};
  7350. this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  7351. this.texture._needsFlipEnvMap = false;
  7352. }
  7353. fromEquirectangularTexture( renderer, texture ) {
  7354. this.texture.type = texture.type;
  7355. this.texture.format = RGBAFormat; // see #18859
  7356. this.texture.encoding = texture.encoding;
  7357. this.texture.generateMipmaps = texture.generateMipmaps;
  7358. this.texture.minFilter = texture.minFilter;
  7359. this.texture.magFilter = texture.magFilter;
  7360. const shader = {
  7361. uniforms: {
  7362. tEquirect: { value: null },
  7363. },
  7364. vertexShader: /* glsl */`
  7365. varying vec3 vWorldDirection;
  7366. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7367. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7368. }
  7369. void main() {
  7370. vWorldDirection = transformDirection( position, modelMatrix );
  7371. #include <begin_vertex>
  7372. #include <project_vertex>
  7373. }
  7374. `,
  7375. fragmentShader: /* glsl */`
  7376. uniform sampler2D tEquirect;
  7377. varying vec3 vWorldDirection;
  7378. #include <common>
  7379. void main() {
  7380. vec3 direction = normalize( vWorldDirection );
  7381. vec2 sampleUV = equirectUv( direction );
  7382. gl_FragColor = texture2D( tEquirect, sampleUV );
  7383. }
  7384. `
  7385. };
  7386. const geometry = new BoxGeometry( 5, 5, 5 );
  7387. const material = new ShaderMaterial( {
  7388. name: 'CubemapFromEquirect',
  7389. uniforms: cloneUniforms( shader.uniforms ),
  7390. vertexShader: shader.vertexShader,
  7391. fragmentShader: shader.fragmentShader,
  7392. side: BackSide,
  7393. blending: NoBlending
  7394. } );
  7395. material.uniforms.tEquirect.value = texture;
  7396. const mesh = new Mesh( geometry, material );
  7397. const currentMinFilter = texture.minFilter;
  7398. // Avoid blurred poles
  7399. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7400. const camera = new CubeCamera( 1, 10, this );
  7401. camera.update( renderer, mesh );
  7402. texture.minFilter = currentMinFilter;
  7403. mesh.geometry.dispose();
  7404. mesh.material.dispose();
  7405. return this;
  7406. }
  7407. clear( renderer, color, depth, stencil ) {
  7408. const currentRenderTarget = renderer.getRenderTarget();
  7409. for ( let i = 0; i < 6; i ++ ) {
  7410. renderer.setRenderTarget( this, i );
  7411. renderer.clear( color, depth, stencil );
  7412. }
  7413. renderer.setRenderTarget( currentRenderTarget );
  7414. }
  7415. }
  7416. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  7417. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7418. this.image = { data: data || null, width: width || 1, height: height || 1 };
  7419. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7420. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7421. this.generateMipmaps = false;
  7422. this.flipY = false;
  7423. this.unpackAlignment = 1;
  7424. this.needsUpdate = true;
  7425. }
  7426. DataTexture.prototype = Object.create( Texture.prototype );
  7427. DataTexture.prototype.constructor = DataTexture;
  7428. DataTexture.prototype.isDataTexture = true;
  7429. const _sphere$1 = /*@__PURE__*/ new Sphere();
  7430. const _vector$5 = /*@__PURE__*/ new Vector3();
  7431. class Frustum {
  7432. constructor( p0, p1, p2, p3, p4, p5 ) {
  7433. this.planes = [
  7434. ( p0 !== undefined ) ? p0 : new Plane(),
  7435. ( p1 !== undefined ) ? p1 : new Plane(),
  7436. ( p2 !== undefined ) ? p2 : new Plane(),
  7437. ( p3 !== undefined ) ? p3 : new Plane(),
  7438. ( p4 !== undefined ) ? p4 : new Plane(),
  7439. ( p5 !== undefined ) ? p5 : new Plane()
  7440. ];
  7441. }
  7442. set( p0, p1, p2, p3, p4, p5 ) {
  7443. const planes = this.planes;
  7444. planes[ 0 ].copy( p0 );
  7445. planes[ 1 ].copy( p1 );
  7446. planes[ 2 ].copy( p2 );
  7447. planes[ 3 ].copy( p3 );
  7448. planes[ 4 ].copy( p4 );
  7449. planes[ 5 ].copy( p5 );
  7450. return this;
  7451. }
  7452. clone() {
  7453. return new this.constructor().copy( this );
  7454. }
  7455. copy( frustum ) {
  7456. const planes = this.planes;
  7457. for ( let i = 0; i < 6; i ++ ) {
  7458. planes[ i ].copy( frustum.planes[ i ] );
  7459. }
  7460. return this;
  7461. }
  7462. setFromProjectionMatrix( m ) {
  7463. const planes = this.planes;
  7464. const me = m.elements;
  7465. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  7466. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  7467. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  7468. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  7469. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  7470. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  7471. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  7472. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  7473. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  7474. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  7475. return this;
  7476. }
  7477. intersectsObject( object ) {
  7478. const geometry = object.geometry;
  7479. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7480. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  7481. return this.intersectsSphere( _sphere$1 );
  7482. }
  7483. intersectsSprite( sprite ) {
  7484. _sphere$1.center.set( 0, 0, 0 );
  7485. _sphere$1.radius = 0.7071067811865476;
  7486. _sphere$1.applyMatrix4( sprite.matrixWorld );
  7487. return this.intersectsSphere( _sphere$1 );
  7488. }
  7489. intersectsSphere( sphere ) {
  7490. const planes = this.planes;
  7491. const center = sphere.center;
  7492. const negRadius = - sphere.radius;
  7493. for ( let i = 0; i < 6; i ++ ) {
  7494. const distance = planes[ i ].distanceToPoint( center );
  7495. if ( distance < negRadius ) {
  7496. return false;
  7497. }
  7498. }
  7499. return true;
  7500. }
  7501. intersectsBox( box ) {
  7502. const planes = this.planes;
  7503. for ( let i = 0; i < 6; i ++ ) {
  7504. const plane = planes[ i ];
  7505. // corner at max distance
  7506. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7507. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7508. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7509. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  7510. return false;
  7511. }
  7512. }
  7513. return true;
  7514. }
  7515. containsPoint( point ) {
  7516. const planes = this.planes;
  7517. for ( let i = 0; i < 6; i ++ ) {
  7518. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  7519. return false;
  7520. }
  7521. }
  7522. return true;
  7523. }
  7524. }
  7525. function WebGLAnimation() {
  7526. let context = null;
  7527. let isAnimating = false;
  7528. let animationLoop = null;
  7529. let requestId = null;
  7530. function onAnimationFrame( time, frame ) {
  7531. animationLoop( time, frame );
  7532. requestId = context.requestAnimationFrame( onAnimationFrame );
  7533. }
  7534. return {
  7535. start: function () {
  7536. if ( isAnimating === true ) return;
  7537. if ( animationLoop === null ) return;
  7538. requestId = context.requestAnimationFrame( onAnimationFrame );
  7539. isAnimating = true;
  7540. },
  7541. stop: function () {
  7542. context.cancelAnimationFrame( requestId );
  7543. isAnimating = false;
  7544. },
  7545. setAnimationLoop: function ( callback ) {
  7546. animationLoop = callback;
  7547. },
  7548. setContext: function ( value ) {
  7549. context = value;
  7550. }
  7551. };
  7552. }
  7553. function WebGLAttributes( gl, capabilities ) {
  7554. const isWebGL2 = capabilities.isWebGL2;
  7555. const buffers = new WeakMap();
  7556. function createBuffer( attribute, bufferType ) {
  7557. const array = attribute.array;
  7558. const usage = attribute.usage;
  7559. const buffer = gl.createBuffer();
  7560. gl.bindBuffer( bufferType, buffer );
  7561. gl.bufferData( bufferType, array, usage );
  7562. attribute.onUploadCallback();
  7563. let type = 5126;
  7564. if ( array instanceof Float32Array ) {
  7565. type = 5126;
  7566. } else if ( array instanceof Float64Array ) {
  7567. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  7568. } else if ( array instanceof Uint16Array ) {
  7569. if ( attribute.isFloat16BufferAttribute ) {
  7570. if ( isWebGL2 ) {
  7571. type = 5131;
  7572. } else {
  7573. console.warn( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
  7574. }
  7575. } else {
  7576. type = 5123;
  7577. }
  7578. } else if ( array instanceof Int16Array ) {
  7579. type = 5122;
  7580. } else if ( array instanceof Uint32Array ) {
  7581. type = 5125;
  7582. } else if ( array instanceof Int32Array ) {
  7583. type = 5124;
  7584. } else if ( array instanceof Int8Array ) {
  7585. type = 5120;
  7586. } else if ( array instanceof Uint8Array ) {
  7587. type = 5121;
  7588. }
  7589. return {
  7590. buffer: buffer,
  7591. type: type,
  7592. bytesPerElement: array.BYTES_PER_ELEMENT,
  7593. version: attribute.version
  7594. };
  7595. }
  7596. function updateBuffer( buffer, attribute, bufferType ) {
  7597. const array = attribute.array;
  7598. const updateRange = attribute.updateRange;
  7599. gl.bindBuffer( bufferType, buffer );
  7600. if ( updateRange.count === - 1 ) {
  7601. // Not using update ranges
  7602. gl.bufferSubData( bufferType, 0, array );
  7603. } else {
  7604. if ( isWebGL2 ) {
  7605. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7606. array, updateRange.offset, updateRange.count );
  7607. } else {
  7608. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7609. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  7610. }
  7611. updateRange.count = - 1; // reset range
  7612. }
  7613. }
  7614. //
  7615. function get( attribute ) {
  7616. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7617. return buffers.get( attribute );
  7618. }
  7619. function remove( attribute ) {
  7620. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7621. const data = buffers.get( attribute );
  7622. if ( data ) {
  7623. gl.deleteBuffer( data.buffer );
  7624. buffers.delete( attribute );
  7625. }
  7626. }
  7627. function update( attribute, bufferType ) {
  7628. if ( attribute.isGLBufferAttribute ) {
  7629. const cached = buffers.get( attribute );
  7630. if ( ! cached || cached.version < attribute.version ) {
  7631. buffers.set( attribute, {
  7632. buffer: attribute.buffer,
  7633. type: attribute.type,
  7634. bytesPerElement: attribute.elementSize,
  7635. version: attribute.version
  7636. } );
  7637. }
  7638. return;
  7639. }
  7640. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7641. const data = buffers.get( attribute );
  7642. if ( data === undefined ) {
  7643. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  7644. } else if ( data.version < attribute.version ) {
  7645. updateBuffer( data.buffer, attribute, bufferType );
  7646. data.version = attribute.version;
  7647. }
  7648. }
  7649. return {
  7650. get: get,
  7651. remove: remove,
  7652. update: update
  7653. };
  7654. }
  7655. class PlaneGeometry extends BufferGeometry {
  7656. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  7657. super();
  7658. this.type = 'PlaneGeometry';
  7659. this.parameters = {
  7660. width: width,
  7661. height: height,
  7662. widthSegments: widthSegments,
  7663. heightSegments: heightSegments
  7664. };
  7665. const width_half = width / 2;
  7666. const height_half = height / 2;
  7667. const gridX = Math.floor( widthSegments );
  7668. const gridY = Math.floor( heightSegments );
  7669. const gridX1 = gridX + 1;
  7670. const gridY1 = gridY + 1;
  7671. const segment_width = width / gridX;
  7672. const segment_height = height / gridY;
  7673. //
  7674. const indices = [];
  7675. const vertices = [];
  7676. const normals = [];
  7677. const uvs = [];
  7678. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7679. const y = iy * segment_height - height_half;
  7680. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7681. const x = ix * segment_width - width_half;
  7682. vertices.push( x, - y, 0 );
  7683. normals.push( 0, 0, 1 );
  7684. uvs.push( ix / gridX );
  7685. uvs.push( 1 - ( iy / gridY ) );
  7686. }
  7687. }
  7688. for ( let iy = 0; iy < gridY; iy ++ ) {
  7689. for ( let ix = 0; ix < gridX; ix ++ ) {
  7690. const a = ix + gridX1 * iy;
  7691. const b = ix + gridX1 * ( iy + 1 );
  7692. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7693. const d = ( ix + 1 ) + gridX1 * iy;
  7694. indices.push( a, b, d );
  7695. indices.push( b, c, d );
  7696. }
  7697. }
  7698. this.setIndex( indices );
  7699. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7700. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7701. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7702. }
  7703. }
  7704. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  7705. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  7706. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  7707. 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";
  7708. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  7709. var begin_vertex = "vec3 transformed = vec3( position );";
  7710. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  7711. 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";
  7712. 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 ) {\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 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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";
  7713. 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";
  7714. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  7715. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  7716. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  7717. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  7718. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  7719. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  7720. 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";
  7721. 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}";
  7722. 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";
  7723. 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";
  7724. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  7725. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  7726. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  7727. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  7728. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  7729. 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}";
  7730. 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";
  7731. 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";
  7732. 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";
  7733. 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";
  7734. 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";
  7735. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  7736. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  7737. 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";
  7738. 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";
  7739. 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}";
  7740. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  7741. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  7742. 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";
  7743. 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";
  7744. 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";
  7745. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  7746. 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)";
  7747. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  7748. 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)";
  7749. 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";
  7750. 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}";
  7751. 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";
  7752. 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";
  7753. 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";
  7754. 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";
  7755. 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";
  7756. 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";
  7757. 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";
  7758. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  7759. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  7760. 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";
  7761. 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";
  7762. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  7763. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  7764. 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";
  7765. 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";
  7766. 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";
  7767. var normal_fragment_begin = "#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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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;";
  7768. 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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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 );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  7769. 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 ) {\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\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  7770. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  7771. 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 );\n\t#endif\n#endif";
  7772. 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";
  7773. 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}";
  7774. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  7775. 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;";
  7776. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  7777. 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";
  7778. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  7779. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  7780. 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";
  7781. 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";
  7782. 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";
  7783. 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}";
  7784. 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";
  7785. 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";
  7786. 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";
  7787. 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";
  7788. 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";
  7789. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  7790. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  7791. 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; }";
  7792. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  7793. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  7794. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  7795. 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";
  7796. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  7797. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  7798. 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";
  7799. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  7800. 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";
  7801. 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}";
  7802. 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}";
  7803. 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}";
  7804. 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}";
  7805. 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}";
  7806. 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}";
  7807. 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}";
  7808. 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}";
  7809. 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}";
  7810. 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}";
  7811. 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}";
  7812. 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}";
  7813. 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}";
  7814. 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}";
  7815. 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}";
  7816. 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}";
  7817. 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}";
  7818. 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}";
  7819. 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}";
  7820. 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}";
  7821. 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}";
  7822. 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}";
  7823. 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}";
  7824. 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}";
  7825. 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}";
  7826. 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}";
  7827. 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}";
  7828. 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}";
  7829. 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}";
  7830. 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}";
  7831. 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}";
  7832. 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}";
  7833. const ShaderChunk = {
  7834. alphamap_fragment: alphamap_fragment,
  7835. alphamap_pars_fragment: alphamap_pars_fragment,
  7836. alphatest_fragment: alphatest_fragment,
  7837. aomap_fragment: aomap_fragment,
  7838. aomap_pars_fragment: aomap_pars_fragment,
  7839. begin_vertex: begin_vertex,
  7840. beginnormal_vertex: beginnormal_vertex,
  7841. bsdfs: bsdfs,
  7842. bumpmap_pars_fragment: bumpmap_pars_fragment,
  7843. clipping_planes_fragment: clipping_planes_fragment,
  7844. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  7845. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  7846. clipping_planes_vertex: clipping_planes_vertex,
  7847. color_fragment: color_fragment,
  7848. color_pars_fragment: color_pars_fragment,
  7849. color_pars_vertex: color_pars_vertex,
  7850. color_vertex: color_vertex,
  7851. common: common,
  7852. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  7853. defaultnormal_vertex: defaultnormal_vertex,
  7854. displacementmap_pars_vertex: displacementmap_pars_vertex,
  7855. displacementmap_vertex: displacementmap_vertex,
  7856. emissivemap_fragment: emissivemap_fragment,
  7857. emissivemap_pars_fragment: emissivemap_pars_fragment,
  7858. encodings_fragment: encodings_fragment,
  7859. encodings_pars_fragment: encodings_pars_fragment,
  7860. envmap_fragment: envmap_fragment,
  7861. envmap_common_pars_fragment: envmap_common_pars_fragment,
  7862. envmap_pars_fragment: envmap_pars_fragment,
  7863. envmap_pars_vertex: envmap_pars_vertex,
  7864. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  7865. envmap_vertex: envmap_vertex,
  7866. fog_vertex: fog_vertex,
  7867. fog_pars_vertex: fog_pars_vertex,
  7868. fog_fragment: fog_fragment,
  7869. fog_pars_fragment: fog_pars_fragment,
  7870. gradientmap_pars_fragment: gradientmap_pars_fragment,
  7871. lightmap_fragment: lightmap_fragment,
  7872. lightmap_pars_fragment: lightmap_pars_fragment,
  7873. lights_lambert_vertex: lights_lambert_vertex,
  7874. lights_pars_begin: lights_pars_begin,
  7875. lights_toon_fragment: lights_toon_fragment,
  7876. lights_toon_pars_fragment: lights_toon_pars_fragment,
  7877. lights_phong_fragment: lights_phong_fragment,
  7878. lights_phong_pars_fragment: lights_phong_pars_fragment,
  7879. lights_physical_fragment: lights_physical_fragment,
  7880. lights_physical_pars_fragment: lights_physical_pars_fragment,
  7881. lights_fragment_begin: lights_fragment_begin,
  7882. lights_fragment_maps: lights_fragment_maps,
  7883. lights_fragment_end: lights_fragment_end,
  7884. logdepthbuf_fragment: logdepthbuf_fragment,
  7885. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  7886. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  7887. logdepthbuf_vertex: logdepthbuf_vertex,
  7888. map_fragment: map_fragment,
  7889. map_pars_fragment: map_pars_fragment,
  7890. map_particle_fragment: map_particle_fragment,
  7891. map_particle_pars_fragment: map_particle_pars_fragment,
  7892. metalnessmap_fragment: metalnessmap_fragment,
  7893. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  7894. morphnormal_vertex: morphnormal_vertex,
  7895. morphtarget_pars_vertex: morphtarget_pars_vertex,
  7896. morphtarget_vertex: morphtarget_vertex,
  7897. normal_fragment_begin: normal_fragment_begin,
  7898. normal_fragment_maps: normal_fragment_maps,
  7899. normalmap_pars_fragment: normalmap_pars_fragment,
  7900. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  7901. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  7902. clearcoat_pars_fragment: clearcoat_pars_fragment,
  7903. packing: packing,
  7904. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  7905. project_vertex: project_vertex,
  7906. dithering_fragment: dithering_fragment,
  7907. dithering_pars_fragment: dithering_pars_fragment,
  7908. roughnessmap_fragment: roughnessmap_fragment,
  7909. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  7910. shadowmap_pars_fragment: shadowmap_pars_fragment,
  7911. shadowmap_pars_vertex: shadowmap_pars_vertex,
  7912. shadowmap_vertex: shadowmap_vertex,
  7913. shadowmask_pars_fragment: shadowmask_pars_fragment,
  7914. skinbase_vertex: skinbase_vertex,
  7915. skinning_pars_vertex: skinning_pars_vertex,
  7916. skinning_vertex: skinning_vertex,
  7917. skinnormal_vertex: skinnormal_vertex,
  7918. specularmap_fragment: specularmap_fragment,
  7919. specularmap_pars_fragment: specularmap_pars_fragment,
  7920. tonemapping_fragment: tonemapping_fragment,
  7921. tonemapping_pars_fragment: tonemapping_pars_fragment,
  7922. transmissionmap_fragment: transmissionmap_fragment,
  7923. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  7924. uv_pars_fragment: uv_pars_fragment,
  7925. uv_pars_vertex: uv_pars_vertex,
  7926. uv_vertex: uv_vertex,
  7927. uv2_pars_fragment: uv2_pars_fragment,
  7928. uv2_pars_vertex: uv2_pars_vertex,
  7929. uv2_vertex: uv2_vertex,
  7930. worldpos_vertex: worldpos_vertex,
  7931. background_frag: background_frag,
  7932. background_vert: background_vert,
  7933. cube_frag: cube_frag,
  7934. cube_vert: cube_vert,
  7935. depth_frag: depth_frag,
  7936. depth_vert: depth_vert,
  7937. distanceRGBA_frag: distanceRGBA_frag,
  7938. distanceRGBA_vert: distanceRGBA_vert,
  7939. equirect_frag: equirect_frag,
  7940. equirect_vert: equirect_vert,
  7941. linedashed_frag: linedashed_frag,
  7942. linedashed_vert: linedashed_vert,
  7943. meshbasic_frag: meshbasic_frag,
  7944. meshbasic_vert: meshbasic_vert,
  7945. meshlambert_frag: meshlambert_frag,
  7946. meshlambert_vert: meshlambert_vert,
  7947. meshmatcap_frag: meshmatcap_frag,
  7948. meshmatcap_vert: meshmatcap_vert,
  7949. meshtoon_frag: meshtoon_frag,
  7950. meshtoon_vert: meshtoon_vert,
  7951. meshphong_frag: meshphong_frag,
  7952. meshphong_vert: meshphong_vert,
  7953. meshphysical_frag: meshphysical_frag,
  7954. meshphysical_vert: meshphysical_vert,
  7955. normal_frag: normal_frag,
  7956. normal_vert: normal_vert,
  7957. points_frag: points_frag,
  7958. points_vert: points_vert,
  7959. shadow_frag: shadow_frag,
  7960. shadow_vert: shadow_vert,
  7961. sprite_frag: sprite_frag,
  7962. sprite_vert: sprite_vert
  7963. };
  7964. /**
  7965. * Uniforms library for shared webgl shaders
  7966. */
  7967. const UniformsLib = {
  7968. common: {
  7969. diffuse: { value: new Color( 0xeeeeee ) },
  7970. opacity: { value: 1.0 },
  7971. map: { value: null },
  7972. uvTransform: { value: new Matrix3() },
  7973. uv2Transform: { value: new Matrix3() },
  7974. alphaMap: { value: null },
  7975. },
  7976. specularmap: {
  7977. specularMap: { value: null },
  7978. },
  7979. envmap: {
  7980. envMap: { value: null },
  7981. flipEnvMap: { value: - 1 },
  7982. reflectivity: { value: 1.0 },
  7983. refractionRatio: { value: 0.98 },
  7984. maxMipLevel: { value: 0 }
  7985. },
  7986. aomap: {
  7987. aoMap: { value: null },
  7988. aoMapIntensity: { value: 1 }
  7989. },
  7990. lightmap: {
  7991. lightMap: { value: null },
  7992. lightMapIntensity: { value: 1 }
  7993. },
  7994. emissivemap: {
  7995. emissiveMap: { value: null }
  7996. },
  7997. bumpmap: {
  7998. bumpMap: { value: null },
  7999. bumpScale: { value: 1 }
  8000. },
  8001. normalmap: {
  8002. normalMap: { value: null },
  8003. normalScale: { value: new Vector2( 1, 1 ) }
  8004. },
  8005. displacementmap: {
  8006. displacementMap: { value: null },
  8007. displacementScale: { value: 1 },
  8008. displacementBias: { value: 0 }
  8009. },
  8010. roughnessmap: {
  8011. roughnessMap: { value: null }
  8012. },
  8013. metalnessmap: {
  8014. metalnessMap: { value: null }
  8015. },
  8016. gradientmap: {
  8017. gradientMap: { value: null }
  8018. },
  8019. fog: {
  8020. fogDensity: { value: 0.00025 },
  8021. fogNear: { value: 1 },
  8022. fogFar: { value: 2000 },
  8023. fogColor: { value: new Color( 0xffffff ) }
  8024. },
  8025. lights: {
  8026. ambientLightColor: { value: [] },
  8027. lightProbe: { value: [] },
  8028. directionalLights: { value: [], properties: {
  8029. direction: {},
  8030. color: {}
  8031. } },
  8032. directionalLightShadows: { value: [], properties: {
  8033. shadowBias: {},
  8034. shadowNormalBias: {},
  8035. shadowRadius: {},
  8036. shadowMapSize: {}
  8037. } },
  8038. directionalShadowMap: { value: [] },
  8039. directionalShadowMatrix: { value: [] },
  8040. spotLights: { value: [], properties: {
  8041. color: {},
  8042. position: {},
  8043. direction: {},
  8044. distance: {},
  8045. coneCos: {},
  8046. penumbraCos: {},
  8047. decay: {}
  8048. } },
  8049. spotLightShadows: { value: [], properties: {
  8050. shadowBias: {},
  8051. shadowNormalBias: {},
  8052. shadowRadius: {},
  8053. shadowMapSize: {}
  8054. } },
  8055. spotShadowMap: { value: [] },
  8056. spotShadowMatrix: { value: [] },
  8057. pointLights: { value: [], properties: {
  8058. color: {},
  8059. position: {},
  8060. decay: {},
  8061. distance: {}
  8062. } },
  8063. pointLightShadows: { value: [], properties: {
  8064. shadowBias: {},
  8065. shadowNormalBias: {},
  8066. shadowRadius: {},
  8067. shadowMapSize: {},
  8068. shadowCameraNear: {},
  8069. shadowCameraFar: {}
  8070. } },
  8071. pointShadowMap: { value: [] },
  8072. pointShadowMatrix: { value: [] },
  8073. hemisphereLights: { value: [], properties: {
  8074. direction: {},
  8075. skyColor: {},
  8076. groundColor: {}
  8077. } },
  8078. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8079. rectAreaLights: { value: [], properties: {
  8080. color: {},
  8081. position: {},
  8082. width: {},
  8083. height: {}
  8084. } },
  8085. ltc_1: { value: null },
  8086. ltc_2: { value: null }
  8087. },
  8088. points: {
  8089. diffuse: { value: new Color( 0xeeeeee ) },
  8090. opacity: { value: 1.0 },
  8091. size: { value: 1.0 },
  8092. scale: { value: 1.0 },
  8093. map: { value: null },
  8094. alphaMap: { value: null },
  8095. uvTransform: { value: new Matrix3() }
  8096. },
  8097. sprite: {
  8098. diffuse: { value: new Color( 0xeeeeee ) },
  8099. opacity: { value: 1.0 },
  8100. center: { value: new Vector2( 0.5, 0.5 ) },
  8101. rotation: { value: 0.0 },
  8102. map: { value: null },
  8103. alphaMap: { value: null },
  8104. uvTransform: { value: new Matrix3() }
  8105. }
  8106. };
  8107. const ShaderLib = {
  8108. basic: {
  8109. uniforms: mergeUniforms( [
  8110. UniformsLib.common,
  8111. UniformsLib.specularmap,
  8112. UniformsLib.envmap,
  8113. UniformsLib.aomap,
  8114. UniformsLib.lightmap,
  8115. UniformsLib.fog
  8116. ] ),
  8117. vertexShader: ShaderChunk.meshbasic_vert,
  8118. fragmentShader: ShaderChunk.meshbasic_frag
  8119. },
  8120. lambert: {
  8121. uniforms: mergeUniforms( [
  8122. UniformsLib.common,
  8123. UniformsLib.specularmap,
  8124. UniformsLib.envmap,
  8125. UniformsLib.aomap,
  8126. UniformsLib.lightmap,
  8127. UniformsLib.emissivemap,
  8128. UniformsLib.fog,
  8129. UniformsLib.lights,
  8130. {
  8131. emissive: { value: new Color( 0x000000 ) }
  8132. }
  8133. ] ),
  8134. vertexShader: ShaderChunk.meshlambert_vert,
  8135. fragmentShader: ShaderChunk.meshlambert_frag
  8136. },
  8137. phong: {
  8138. uniforms: mergeUniforms( [
  8139. UniformsLib.common,
  8140. UniformsLib.specularmap,
  8141. UniformsLib.envmap,
  8142. UniformsLib.aomap,
  8143. UniformsLib.lightmap,
  8144. UniformsLib.emissivemap,
  8145. UniformsLib.bumpmap,
  8146. UniformsLib.normalmap,
  8147. UniformsLib.displacementmap,
  8148. UniformsLib.fog,
  8149. UniformsLib.lights,
  8150. {
  8151. emissive: { value: new Color( 0x000000 ) },
  8152. specular: { value: new Color( 0x111111 ) },
  8153. shininess: { value: 30 }
  8154. }
  8155. ] ),
  8156. vertexShader: ShaderChunk.meshphong_vert,
  8157. fragmentShader: ShaderChunk.meshphong_frag
  8158. },
  8159. standard: {
  8160. uniforms: mergeUniforms( [
  8161. UniformsLib.common,
  8162. UniformsLib.envmap,
  8163. UniformsLib.aomap,
  8164. UniformsLib.lightmap,
  8165. UniformsLib.emissivemap,
  8166. UniformsLib.bumpmap,
  8167. UniformsLib.normalmap,
  8168. UniformsLib.displacementmap,
  8169. UniformsLib.roughnessmap,
  8170. UniformsLib.metalnessmap,
  8171. UniformsLib.fog,
  8172. UniformsLib.lights,
  8173. {
  8174. emissive: { value: new Color( 0x000000 ) },
  8175. roughness: { value: 1.0 },
  8176. metalness: { value: 0.0 },
  8177. envMapIntensity: { value: 1 } // temporary
  8178. }
  8179. ] ),
  8180. vertexShader: ShaderChunk.meshphysical_vert,
  8181. fragmentShader: ShaderChunk.meshphysical_frag
  8182. },
  8183. toon: {
  8184. uniforms: mergeUniforms( [
  8185. UniformsLib.common,
  8186. UniformsLib.aomap,
  8187. UniformsLib.lightmap,
  8188. UniformsLib.emissivemap,
  8189. UniformsLib.bumpmap,
  8190. UniformsLib.normalmap,
  8191. UniformsLib.displacementmap,
  8192. UniformsLib.gradientmap,
  8193. UniformsLib.fog,
  8194. UniformsLib.lights,
  8195. {
  8196. emissive: { value: new Color( 0x000000 ) }
  8197. }
  8198. ] ),
  8199. vertexShader: ShaderChunk.meshtoon_vert,
  8200. fragmentShader: ShaderChunk.meshtoon_frag
  8201. },
  8202. matcap: {
  8203. uniforms: mergeUniforms( [
  8204. UniformsLib.common,
  8205. UniformsLib.bumpmap,
  8206. UniformsLib.normalmap,
  8207. UniformsLib.displacementmap,
  8208. UniformsLib.fog,
  8209. {
  8210. matcap: { value: null }
  8211. }
  8212. ] ),
  8213. vertexShader: ShaderChunk.meshmatcap_vert,
  8214. fragmentShader: ShaderChunk.meshmatcap_frag
  8215. },
  8216. points: {
  8217. uniforms: mergeUniforms( [
  8218. UniformsLib.points,
  8219. UniformsLib.fog
  8220. ] ),
  8221. vertexShader: ShaderChunk.points_vert,
  8222. fragmentShader: ShaderChunk.points_frag
  8223. },
  8224. dashed: {
  8225. uniforms: mergeUniforms( [
  8226. UniformsLib.common,
  8227. UniformsLib.fog,
  8228. {
  8229. scale: { value: 1 },
  8230. dashSize: { value: 1 },
  8231. totalSize: { value: 2 }
  8232. }
  8233. ] ),
  8234. vertexShader: ShaderChunk.linedashed_vert,
  8235. fragmentShader: ShaderChunk.linedashed_frag
  8236. },
  8237. depth: {
  8238. uniforms: mergeUniforms( [
  8239. UniformsLib.common,
  8240. UniformsLib.displacementmap
  8241. ] ),
  8242. vertexShader: ShaderChunk.depth_vert,
  8243. fragmentShader: ShaderChunk.depth_frag
  8244. },
  8245. normal: {
  8246. uniforms: mergeUniforms( [
  8247. UniformsLib.common,
  8248. UniformsLib.bumpmap,
  8249. UniformsLib.normalmap,
  8250. UniformsLib.displacementmap,
  8251. {
  8252. opacity: { value: 1.0 }
  8253. }
  8254. ] ),
  8255. vertexShader: ShaderChunk.normal_vert,
  8256. fragmentShader: ShaderChunk.normal_frag
  8257. },
  8258. sprite: {
  8259. uniforms: mergeUniforms( [
  8260. UniformsLib.sprite,
  8261. UniformsLib.fog
  8262. ] ),
  8263. vertexShader: ShaderChunk.sprite_vert,
  8264. fragmentShader: ShaderChunk.sprite_frag
  8265. },
  8266. background: {
  8267. uniforms: {
  8268. uvTransform: { value: new Matrix3() },
  8269. t2D: { value: null },
  8270. },
  8271. vertexShader: ShaderChunk.background_vert,
  8272. fragmentShader: ShaderChunk.background_frag
  8273. },
  8274. /* -------------------------------------------------------------------------
  8275. // Cube map shader
  8276. ------------------------------------------------------------------------- */
  8277. cube: {
  8278. uniforms: mergeUniforms( [
  8279. UniformsLib.envmap,
  8280. {
  8281. opacity: { value: 1.0 }
  8282. }
  8283. ] ),
  8284. vertexShader: ShaderChunk.cube_vert,
  8285. fragmentShader: ShaderChunk.cube_frag
  8286. },
  8287. equirect: {
  8288. uniforms: {
  8289. tEquirect: { value: null },
  8290. },
  8291. vertexShader: ShaderChunk.equirect_vert,
  8292. fragmentShader: ShaderChunk.equirect_frag
  8293. },
  8294. distanceRGBA: {
  8295. uniforms: mergeUniforms( [
  8296. UniformsLib.common,
  8297. UniformsLib.displacementmap,
  8298. {
  8299. referencePosition: { value: new Vector3() },
  8300. nearDistance: { value: 1 },
  8301. farDistance: { value: 1000 }
  8302. }
  8303. ] ),
  8304. vertexShader: ShaderChunk.distanceRGBA_vert,
  8305. fragmentShader: ShaderChunk.distanceRGBA_frag
  8306. },
  8307. shadow: {
  8308. uniforms: mergeUniforms( [
  8309. UniformsLib.lights,
  8310. UniformsLib.fog,
  8311. {
  8312. color: { value: new Color( 0x00000 ) },
  8313. opacity: { value: 1.0 }
  8314. },
  8315. ] ),
  8316. vertexShader: ShaderChunk.shadow_vert,
  8317. fragmentShader: ShaderChunk.shadow_frag
  8318. }
  8319. };
  8320. ShaderLib.physical = {
  8321. uniforms: mergeUniforms( [
  8322. ShaderLib.standard.uniforms,
  8323. {
  8324. clearcoat: { value: 0 },
  8325. clearcoatMap: { value: null },
  8326. clearcoatRoughness: { value: 0 },
  8327. clearcoatRoughnessMap: { value: null },
  8328. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  8329. clearcoatNormalMap: { value: null },
  8330. sheen: { value: new Color( 0x000000 ) },
  8331. transmission: { value: 0 },
  8332. transmissionMap: { value: null },
  8333. }
  8334. ] ),
  8335. vertexShader: ShaderChunk.meshphysical_vert,
  8336. fragmentShader: ShaderChunk.meshphysical_frag
  8337. };
  8338. function WebGLBackground( renderer, cubemaps, state, objects, premultipliedAlpha ) {
  8339. const clearColor = new Color( 0x000000 );
  8340. let clearAlpha = 0;
  8341. let planeMesh;
  8342. let boxMesh;
  8343. let currentBackground = null;
  8344. let currentBackgroundVersion = 0;
  8345. let currentTonemapping = null;
  8346. function render( renderList, scene, camera, forceClear ) {
  8347. let background = scene.isScene === true ? scene.background : null;
  8348. if ( background && background.isTexture ) {
  8349. background = cubemaps.get( background );
  8350. }
  8351. // Ignore background in AR
  8352. // TODO: Reconsider this.
  8353. const xr = renderer.xr;
  8354. const session = xr.getSession && xr.getSession();
  8355. if ( session && session.environmentBlendMode === 'additive' ) {
  8356. background = null;
  8357. }
  8358. if ( background === null ) {
  8359. setClear( clearColor, clearAlpha );
  8360. } else if ( background && background.isColor ) {
  8361. setClear( background, 1 );
  8362. forceClear = true;
  8363. }
  8364. if ( renderer.autoClear || forceClear ) {
  8365. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8366. }
  8367. if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) {
  8368. if ( boxMesh === undefined ) {
  8369. boxMesh = new Mesh(
  8370. new BoxGeometry( 1, 1, 1 ),
  8371. new ShaderMaterial( {
  8372. name: 'BackgroundCubeMaterial',
  8373. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8374. vertexShader: ShaderLib.cube.vertexShader,
  8375. fragmentShader: ShaderLib.cube.fragmentShader,
  8376. side: BackSide,
  8377. depthTest: false,
  8378. depthWrite: false,
  8379. fog: false
  8380. } )
  8381. );
  8382. boxMesh.geometry.deleteAttribute( 'normal' );
  8383. boxMesh.geometry.deleteAttribute( 'uv' );
  8384. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8385. this.matrixWorld.copyPosition( camera.matrixWorld );
  8386. };
  8387. // enable code injection for non-built-in material
  8388. Object.defineProperty( boxMesh.material, 'envMap', {
  8389. get: function () {
  8390. return this.uniforms.envMap.value;
  8391. }
  8392. } );
  8393. objects.update( boxMesh );
  8394. }
  8395. if ( background.isWebGLCubeRenderTarget ) {
  8396. // TODO Deprecate
  8397. background = background.texture;
  8398. }
  8399. boxMesh.material.uniforms.envMap.value = background;
  8400. boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background._needsFlipEnvMap ) ? - 1 : 1;
  8401. if ( currentBackground !== background ||
  8402. currentBackgroundVersion !== background.version ||
  8403. currentTonemapping !== renderer.toneMapping ) {
  8404. boxMesh.material.needsUpdate = true;
  8405. currentBackground = background;
  8406. currentBackgroundVersion = background.version;
  8407. currentTonemapping = renderer.toneMapping;
  8408. }
  8409. // push to the pre-sorted opaque render list
  8410. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8411. } else if ( background && background.isTexture ) {
  8412. if ( planeMesh === undefined ) {
  8413. planeMesh = new Mesh(
  8414. new PlaneGeometry( 2, 2 ),
  8415. new ShaderMaterial( {
  8416. name: 'BackgroundMaterial',
  8417. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8418. vertexShader: ShaderLib.background.vertexShader,
  8419. fragmentShader: ShaderLib.background.fragmentShader,
  8420. side: FrontSide,
  8421. depthTest: false,
  8422. depthWrite: false,
  8423. fog: false
  8424. } )
  8425. );
  8426. planeMesh.geometry.deleteAttribute( 'normal' );
  8427. // enable code injection for non-built-in material
  8428. Object.defineProperty( planeMesh.material, 'map', {
  8429. get: function () {
  8430. return this.uniforms.t2D.value;
  8431. }
  8432. } );
  8433. objects.update( planeMesh );
  8434. }
  8435. planeMesh.material.uniforms.t2D.value = background;
  8436. if ( background.matrixAutoUpdate === true ) {
  8437. background.updateMatrix();
  8438. }
  8439. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8440. if ( currentBackground !== background ||
  8441. currentBackgroundVersion !== background.version ||
  8442. currentTonemapping !== renderer.toneMapping ) {
  8443. planeMesh.material.needsUpdate = true;
  8444. currentBackground = background;
  8445. currentBackgroundVersion = background.version;
  8446. currentTonemapping = renderer.toneMapping;
  8447. }
  8448. // push to the pre-sorted opaque render list
  8449. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8450. }
  8451. }
  8452. function setClear( color, alpha ) {
  8453. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8454. }
  8455. return {
  8456. getClearColor: function () {
  8457. return clearColor;
  8458. },
  8459. setClearColor: function ( color, alpha = 1 ) {
  8460. clearColor.set( color );
  8461. clearAlpha = alpha;
  8462. setClear( clearColor, clearAlpha );
  8463. },
  8464. getClearAlpha: function () {
  8465. return clearAlpha;
  8466. },
  8467. setClearAlpha: function ( alpha ) {
  8468. clearAlpha = alpha;
  8469. setClear( clearColor, clearAlpha );
  8470. },
  8471. render: render
  8472. };
  8473. }
  8474. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  8475. const maxVertexAttributes = gl.getParameter( 34921 );
  8476. const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  8477. const vaoAvailable = capabilities.isWebGL2 || extension !== null;
  8478. const bindingStates = {};
  8479. const defaultState = createBindingState( null );
  8480. let currentState = defaultState;
  8481. function setup( object, material, program, geometry, index ) {
  8482. let updateBuffers = false;
  8483. if ( vaoAvailable ) {
  8484. const state = getBindingState( geometry, program, material );
  8485. if ( currentState !== state ) {
  8486. currentState = state;
  8487. bindVertexArrayObject( currentState.object );
  8488. }
  8489. updateBuffers = needsUpdate( geometry, index );
  8490. if ( updateBuffers ) saveCache( geometry, index );
  8491. } else {
  8492. const wireframe = ( material.wireframe === true );
  8493. if ( currentState.geometry !== geometry.id ||
  8494. currentState.program !== program.id ||
  8495. currentState.wireframe !== wireframe ) {
  8496. currentState.geometry = geometry.id;
  8497. currentState.program = program.id;
  8498. currentState.wireframe = wireframe;
  8499. updateBuffers = true;
  8500. }
  8501. }
  8502. if ( object.isInstancedMesh === true ) {
  8503. updateBuffers = true;
  8504. }
  8505. if ( index !== null ) {
  8506. attributes.update( index, 34963 );
  8507. }
  8508. if ( updateBuffers ) {
  8509. setupVertexAttributes( object, material, program, geometry );
  8510. if ( index !== null ) {
  8511. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  8512. }
  8513. }
  8514. }
  8515. function createVertexArrayObject() {
  8516. if ( capabilities.isWebGL2 ) return gl.createVertexArray();
  8517. return extension.createVertexArrayOES();
  8518. }
  8519. function bindVertexArrayObject( vao ) {
  8520. if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
  8521. return extension.bindVertexArrayOES( vao );
  8522. }
  8523. function deleteVertexArrayObject( vao ) {
  8524. if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
  8525. return extension.deleteVertexArrayOES( vao );
  8526. }
  8527. function getBindingState( geometry, program, material ) {
  8528. const wireframe = ( material.wireframe === true );
  8529. let programMap = bindingStates[ geometry.id ];
  8530. if ( programMap === undefined ) {
  8531. programMap = {};
  8532. bindingStates[ geometry.id ] = programMap;
  8533. }
  8534. let stateMap = programMap[ program.id ];
  8535. if ( stateMap === undefined ) {
  8536. stateMap = {};
  8537. programMap[ program.id ] = stateMap;
  8538. }
  8539. let state = stateMap[ wireframe ];
  8540. if ( state === undefined ) {
  8541. state = createBindingState( createVertexArrayObject() );
  8542. stateMap[ wireframe ] = state;
  8543. }
  8544. return state;
  8545. }
  8546. function createBindingState( vao ) {
  8547. const newAttributes = [];
  8548. const enabledAttributes = [];
  8549. const attributeDivisors = [];
  8550. for ( let i = 0; i < maxVertexAttributes; i ++ ) {
  8551. newAttributes[ i ] = 0;
  8552. enabledAttributes[ i ] = 0;
  8553. attributeDivisors[ i ] = 0;
  8554. }
  8555. return {
  8556. // for backward compatibility on non-VAO support browser
  8557. geometry: null,
  8558. program: null,
  8559. wireframe: false,
  8560. newAttributes: newAttributes,
  8561. enabledAttributes: enabledAttributes,
  8562. attributeDivisors: attributeDivisors,
  8563. object: vao,
  8564. attributes: {},
  8565. index: null
  8566. };
  8567. }
  8568. function needsUpdate( geometry, index ) {
  8569. const cachedAttributes = currentState.attributes;
  8570. const geometryAttributes = geometry.attributes;
  8571. let attributesNum = 0;
  8572. for ( const key in geometryAttributes ) {
  8573. const cachedAttribute = cachedAttributes[ key ];
  8574. const geometryAttribute = geometryAttributes[ key ];
  8575. if ( cachedAttribute === undefined ) return true;
  8576. if ( cachedAttribute.attribute !== geometryAttribute ) return true;
  8577. if ( cachedAttribute.data !== geometryAttribute.data ) return true;
  8578. attributesNum ++;
  8579. }
  8580. if ( currentState.attributesNum !== attributesNum ) return true;
  8581. if ( currentState.index !== index ) return true;
  8582. return false;
  8583. }
  8584. function saveCache( geometry, index ) {
  8585. const cache = {};
  8586. const attributes = geometry.attributes;
  8587. let attributesNum = 0;
  8588. for ( const key in attributes ) {
  8589. const attribute = attributes[ key ];
  8590. const data = {};
  8591. data.attribute = attribute;
  8592. if ( attribute.data ) {
  8593. data.data = attribute.data;
  8594. }
  8595. cache[ key ] = data;
  8596. attributesNum ++;
  8597. }
  8598. currentState.attributes = cache;
  8599. currentState.attributesNum = attributesNum;
  8600. currentState.index = index;
  8601. }
  8602. function initAttributes() {
  8603. const newAttributes = currentState.newAttributes;
  8604. for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {
  8605. newAttributes[ i ] = 0;
  8606. }
  8607. }
  8608. function enableAttribute( attribute ) {
  8609. enableAttributeAndDivisor( attribute, 0 );
  8610. }
  8611. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  8612. const newAttributes = currentState.newAttributes;
  8613. const enabledAttributes = currentState.enabledAttributes;
  8614. const attributeDivisors = currentState.attributeDivisors;
  8615. newAttributes[ attribute ] = 1;
  8616. if ( enabledAttributes[ attribute ] === 0 ) {
  8617. gl.enableVertexAttribArray( attribute );
  8618. enabledAttributes[ attribute ] = 1;
  8619. }
  8620. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  8621. const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  8622. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  8623. attributeDivisors[ attribute ] = meshPerAttribute;
  8624. }
  8625. }
  8626. function disableUnusedAttributes() {
  8627. const newAttributes = currentState.newAttributes;
  8628. const enabledAttributes = currentState.enabledAttributes;
  8629. for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  8630. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  8631. gl.disableVertexAttribArray( i );
  8632. enabledAttributes[ i ] = 0;
  8633. }
  8634. }
  8635. }
  8636. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  8637. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  8638. gl.vertexAttribIPointer( index, size, type, stride, offset );
  8639. } else {
  8640. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  8641. }
  8642. }
  8643. function setupVertexAttributes( object, material, program, geometry ) {
  8644. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  8645. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  8646. }
  8647. initAttributes();
  8648. const geometryAttributes = geometry.attributes;
  8649. const programAttributes = program.getAttributes();
  8650. const materialDefaultAttributeValues = material.defaultAttributeValues;
  8651. for ( const name in programAttributes ) {
  8652. const programAttribute = programAttributes[ name ];
  8653. if ( programAttribute >= 0 ) {
  8654. const geometryAttribute = geometryAttributes[ name ];
  8655. if ( geometryAttribute !== undefined ) {
  8656. const normalized = geometryAttribute.normalized;
  8657. const size = geometryAttribute.itemSize;
  8658. const attribute = attributes.get( geometryAttribute );
  8659. // TODO Attribute may not be available on context restore
  8660. if ( attribute === undefined ) continue;
  8661. const buffer = attribute.buffer;
  8662. const type = attribute.type;
  8663. const bytesPerElement = attribute.bytesPerElement;
  8664. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  8665. const data = geometryAttribute.data;
  8666. const stride = data.stride;
  8667. const offset = geometryAttribute.offset;
  8668. if ( data && data.isInstancedInterleavedBuffer ) {
  8669. enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  8670. if ( geometry._maxInstanceCount === undefined ) {
  8671. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  8672. }
  8673. } else {
  8674. enableAttribute( programAttribute );
  8675. }
  8676. gl.bindBuffer( 34962, buffer );
  8677. vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  8678. } else {
  8679. if ( geometryAttribute.isInstancedBufferAttribute ) {
  8680. enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  8681. if ( geometry._maxInstanceCount === undefined ) {
  8682. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  8683. }
  8684. } else {
  8685. enableAttribute( programAttribute );
  8686. }
  8687. gl.bindBuffer( 34962, buffer );
  8688. vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  8689. }
  8690. } else if ( name === 'instanceMatrix' ) {
  8691. const attribute = attributes.get( object.instanceMatrix );
  8692. // TODO Attribute may not be available on context restore
  8693. if ( attribute === undefined ) continue;
  8694. const buffer = attribute.buffer;
  8695. const type = attribute.type;
  8696. enableAttributeAndDivisor( programAttribute + 0, 1 );
  8697. enableAttributeAndDivisor( programAttribute + 1, 1 );
  8698. enableAttributeAndDivisor( programAttribute + 2, 1 );
  8699. enableAttributeAndDivisor( programAttribute + 3, 1 );
  8700. gl.bindBuffer( 34962, buffer );
  8701. gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  8702. gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  8703. gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  8704. gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  8705. } else if ( name === 'instanceColor' ) {
  8706. const attribute = attributes.get( object.instanceColor );
  8707. // TODO Attribute may not be available on context restore
  8708. if ( attribute === undefined ) continue;
  8709. const buffer = attribute.buffer;
  8710. const type = attribute.type;
  8711. enableAttributeAndDivisor( programAttribute, 1 );
  8712. gl.bindBuffer( 34962, buffer );
  8713. gl.vertexAttribPointer( programAttribute, 3, type, false, 12, 0 );
  8714. } else if ( materialDefaultAttributeValues !== undefined ) {
  8715. const value = materialDefaultAttributeValues[ name ];
  8716. if ( value !== undefined ) {
  8717. switch ( value.length ) {
  8718. case 2:
  8719. gl.vertexAttrib2fv( programAttribute, value );
  8720. break;
  8721. case 3:
  8722. gl.vertexAttrib3fv( programAttribute, value );
  8723. break;
  8724. case 4:
  8725. gl.vertexAttrib4fv( programAttribute, value );
  8726. break;
  8727. default:
  8728. gl.vertexAttrib1fv( programAttribute, value );
  8729. }
  8730. }
  8731. }
  8732. }
  8733. }
  8734. disableUnusedAttributes();
  8735. }
  8736. function dispose() {
  8737. reset();
  8738. for ( const geometryId in bindingStates ) {
  8739. const programMap = bindingStates[ geometryId ];
  8740. for ( const programId in programMap ) {
  8741. const stateMap = programMap[ programId ];
  8742. for ( const wireframe in stateMap ) {
  8743. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8744. delete stateMap[ wireframe ];
  8745. }
  8746. delete programMap[ programId ];
  8747. }
  8748. delete bindingStates[ geometryId ];
  8749. }
  8750. }
  8751. function releaseStatesOfGeometry( geometry ) {
  8752. if ( bindingStates[ geometry.id ] === undefined ) return;
  8753. const programMap = bindingStates[ geometry.id ];
  8754. for ( const programId in programMap ) {
  8755. const stateMap = programMap[ programId ];
  8756. for ( const wireframe in stateMap ) {
  8757. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8758. delete stateMap[ wireframe ];
  8759. }
  8760. delete programMap[ programId ];
  8761. }
  8762. delete bindingStates[ geometry.id ];
  8763. }
  8764. function releaseStatesOfProgram( program ) {
  8765. for ( const geometryId in bindingStates ) {
  8766. const programMap = bindingStates[ geometryId ];
  8767. if ( programMap[ program.id ] === undefined ) continue;
  8768. const stateMap = programMap[ program.id ];
  8769. for ( const wireframe in stateMap ) {
  8770. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8771. delete stateMap[ wireframe ];
  8772. }
  8773. delete programMap[ program.id ];
  8774. }
  8775. }
  8776. function reset() {
  8777. resetDefaultState();
  8778. if ( currentState === defaultState ) return;
  8779. currentState = defaultState;
  8780. bindVertexArrayObject( currentState.object );
  8781. }
  8782. // for backward-compatilibity
  8783. function resetDefaultState() {
  8784. defaultState.geometry = null;
  8785. defaultState.program = null;
  8786. defaultState.wireframe = false;
  8787. }
  8788. return {
  8789. setup: setup,
  8790. reset: reset,
  8791. resetDefaultState: resetDefaultState,
  8792. dispose: dispose,
  8793. releaseStatesOfGeometry: releaseStatesOfGeometry,
  8794. releaseStatesOfProgram: releaseStatesOfProgram,
  8795. initAttributes: initAttributes,
  8796. enableAttribute: enableAttribute,
  8797. disableUnusedAttributes: disableUnusedAttributes
  8798. };
  8799. }
  8800. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8801. const isWebGL2 = capabilities.isWebGL2;
  8802. let mode;
  8803. function setMode( value ) {
  8804. mode = value;
  8805. }
  8806. function render( start, count ) {
  8807. gl.drawArrays( mode, start, count );
  8808. info.update( count, mode, 1 );
  8809. }
  8810. function renderInstances( start, count, primcount ) {
  8811. if ( primcount === 0 ) return;
  8812. let extension, methodName;
  8813. if ( isWebGL2 ) {
  8814. extension = gl;
  8815. methodName = 'drawArraysInstanced';
  8816. } else {
  8817. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8818. methodName = 'drawArraysInstancedANGLE';
  8819. if ( extension === null ) {
  8820. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8821. return;
  8822. }
  8823. }
  8824. extension[ methodName ]( mode, start, count, primcount );
  8825. info.update( count, mode, primcount );
  8826. }
  8827. //
  8828. this.setMode = setMode;
  8829. this.render = render;
  8830. this.renderInstances = renderInstances;
  8831. }
  8832. function WebGLCapabilities( gl, extensions, parameters ) {
  8833. let maxAnisotropy;
  8834. function getMaxAnisotropy() {
  8835. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8836. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8837. if ( extension !== null ) {
  8838. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8839. } else {
  8840. maxAnisotropy = 0;
  8841. }
  8842. return maxAnisotropy;
  8843. }
  8844. function getMaxPrecision( precision ) {
  8845. if ( precision === 'highp' ) {
  8846. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8847. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8848. return 'highp';
  8849. }
  8850. precision = 'mediump';
  8851. }
  8852. if ( precision === 'mediump' ) {
  8853. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8854. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8855. return 'mediump';
  8856. }
  8857. }
  8858. return 'lowp';
  8859. }
  8860. /* eslint-disable no-undef */
  8861. const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  8862. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  8863. /* eslint-enable no-undef */
  8864. let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8865. const maxPrecision = getMaxPrecision( precision );
  8866. if ( maxPrecision !== precision ) {
  8867. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8868. precision = maxPrecision;
  8869. }
  8870. const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8871. const maxTextures = gl.getParameter( 34930 );
  8872. const maxVertexTextures = gl.getParameter( 35660 );
  8873. const maxTextureSize = gl.getParameter( 3379 );
  8874. const maxCubemapSize = gl.getParameter( 34076 );
  8875. const maxAttributes = gl.getParameter( 34921 );
  8876. const maxVertexUniforms = gl.getParameter( 36347 );
  8877. const maxVaryings = gl.getParameter( 36348 );
  8878. const maxFragmentUniforms = gl.getParameter( 36349 );
  8879. const vertexTextures = maxVertexTextures > 0;
  8880. const floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8881. const floatVertexTextures = vertexTextures && floatFragmentTextures;
  8882. const maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8883. return {
  8884. isWebGL2: isWebGL2,
  8885. getMaxAnisotropy: getMaxAnisotropy,
  8886. getMaxPrecision: getMaxPrecision,
  8887. precision: precision,
  8888. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8889. maxTextures: maxTextures,
  8890. maxVertexTextures: maxVertexTextures,
  8891. maxTextureSize: maxTextureSize,
  8892. maxCubemapSize: maxCubemapSize,
  8893. maxAttributes: maxAttributes,
  8894. maxVertexUniforms: maxVertexUniforms,
  8895. maxVaryings: maxVaryings,
  8896. maxFragmentUniforms: maxFragmentUniforms,
  8897. vertexTextures: vertexTextures,
  8898. floatFragmentTextures: floatFragmentTextures,
  8899. floatVertexTextures: floatVertexTextures,
  8900. maxSamples: maxSamples
  8901. };
  8902. }
  8903. function WebGLClipping( properties ) {
  8904. const scope = this;
  8905. let globalState = null,
  8906. numGlobalPlanes = 0,
  8907. localClippingEnabled = false,
  8908. renderingShadows = false;
  8909. const plane = new Plane(),
  8910. viewNormalMatrix = new Matrix3(),
  8911. uniform = { value: null, needsUpdate: false };
  8912. this.uniform = uniform;
  8913. this.numPlanes = 0;
  8914. this.numIntersection = 0;
  8915. this.init = function ( planes, enableLocalClipping, camera ) {
  8916. const enabled =
  8917. planes.length !== 0 ||
  8918. enableLocalClipping ||
  8919. // enable state of previous frame - the clipping code has to
  8920. // run another frame in order to reset the state:
  8921. numGlobalPlanes !== 0 ||
  8922. localClippingEnabled;
  8923. localClippingEnabled = enableLocalClipping;
  8924. globalState = projectPlanes( planes, camera, 0 );
  8925. numGlobalPlanes = planes.length;
  8926. return enabled;
  8927. };
  8928. this.beginShadows = function () {
  8929. renderingShadows = true;
  8930. projectPlanes( null );
  8931. };
  8932. this.endShadows = function () {
  8933. renderingShadows = false;
  8934. resetGlobalState();
  8935. };
  8936. this.setState = function ( material, camera, useCache ) {
  8937. const planes = material.clippingPlanes,
  8938. clipIntersection = material.clipIntersection,
  8939. clipShadows = material.clipShadows;
  8940. const materialProperties = properties.get( material );
  8941. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8942. // there's no local clipping
  8943. if ( renderingShadows ) {
  8944. // there's no global clipping
  8945. projectPlanes( null );
  8946. } else {
  8947. resetGlobalState();
  8948. }
  8949. } else {
  8950. const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8951. lGlobal = nGlobal * 4;
  8952. let dstArray = materialProperties.clippingState || null;
  8953. uniform.value = dstArray; // ensure unique state
  8954. dstArray = projectPlanes( planes, camera, lGlobal, useCache );
  8955. for ( let i = 0; i !== lGlobal; ++ i ) {
  8956. dstArray[ i ] = globalState[ i ];
  8957. }
  8958. materialProperties.clippingState = dstArray;
  8959. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8960. this.numPlanes += nGlobal;
  8961. }
  8962. };
  8963. function resetGlobalState() {
  8964. if ( uniform.value !== globalState ) {
  8965. uniform.value = globalState;
  8966. uniform.needsUpdate = numGlobalPlanes > 0;
  8967. }
  8968. scope.numPlanes = numGlobalPlanes;
  8969. scope.numIntersection = 0;
  8970. }
  8971. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8972. const nPlanes = planes !== null ? planes.length : 0;
  8973. let dstArray = null;
  8974. if ( nPlanes !== 0 ) {
  8975. dstArray = uniform.value;
  8976. if ( skipTransform !== true || dstArray === null ) {
  8977. const flatSize = dstOffset + nPlanes * 4,
  8978. viewMatrix = camera.matrixWorldInverse;
  8979. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8980. if ( dstArray === null || dstArray.length < flatSize ) {
  8981. dstArray = new Float32Array( flatSize );
  8982. }
  8983. for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8984. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8985. plane.normal.toArray( dstArray, i4 );
  8986. dstArray[ i4 + 3 ] = plane.constant;
  8987. }
  8988. }
  8989. uniform.value = dstArray;
  8990. uniform.needsUpdate = true;
  8991. }
  8992. scope.numPlanes = nPlanes;
  8993. scope.numIntersection = 0;
  8994. return dstArray;
  8995. }
  8996. }
  8997. function WebGLCubeMaps( renderer ) {
  8998. let cubemaps = new WeakMap();
  8999. function mapTextureMapping( texture, mapping ) {
  9000. if ( mapping === EquirectangularReflectionMapping ) {
  9001. texture.mapping = CubeReflectionMapping;
  9002. } else if ( mapping === EquirectangularRefractionMapping ) {
  9003. texture.mapping = CubeRefractionMapping;
  9004. }
  9005. return texture;
  9006. }
  9007. function get( texture ) {
  9008. if ( texture && texture.isTexture ) {
  9009. const mapping = texture.mapping;
  9010. if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
  9011. if ( cubemaps.has( texture ) ) {
  9012. const cubemap = cubemaps.get( texture ).texture;
  9013. return mapTextureMapping( cubemap, texture.mapping );
  9014. } else {
  9015. const image = texture.image;
  9016. if ( image && image.height > 0 ) {
  9017. const currentRenderList = renderer.getRenderList();
  9018. const currentRenderTarget = renderer.getRenderTarget();
  9019. const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
  9020. renderTarget.fromEquirectangularTexture( renderer, texture );
  9021. cubemaps.set( texture, renderTarget );
  9022. renderer.setRenderTarget( currentRenderTarget );
  9023. renderer.setRenderList( currentRenderList );
  9024. texture.addEventListener( 'dispose', onTextureDispose );
  9025. return mapTextureMapping( renderTarget.texture, texture.mapping );
  9026. } else {
  9027. // image not yet ready. try the conversion next frame
  9028. return null;
  9029. }
  9030. }
  9031. }
  9032. }
  9033. return texture;
  9034. }
  9035. function onTextureDispose( event ) {
  9036. const texture = event.target;
  9037. texture.removeEventListener( 'dispose', onTextureDispose );
  9038. const cubemap = cubemaps.get( texture );
  9039. if ( cubemap !== undefined ) {
  9040. cubemaps.delete( texture );
  9041. cubemap.dispose();
  9042. }
  9043. }
  9044. function dispose() {
  9045. cubemaps = new WeakMap();
  9046. }
  9047. return {
  9048. get: get,
  9049. dispose: dispose
  9050. };
  9051. }
  9052. function WebGLExtensions( gl ) {
  9053. const extensions = {};
  9054. return {
  9055. has: function ( name ) {
  9056. if ( extensions[ name ] !== undefined ) {
  9057. return extensions[ name ] !== null;
  9058. }
  9059. let extension;
  9060. switch ( name ) {
  9061. case 'WEBGL_depth_texture':
  9062. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9063. break;
  9064. case 'EXT_texture_filter_anisotropic':
  9065. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9066. break;
  9067. case 'WEBGL_compressed_texture_s3tc':
  9068. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9069. break;
  9070. case 'WEBGL_compressed_texture_pvrtc':
  9071. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9072. break;
  9073. default:
  9074. extension = gl.getExtension( name );
  9075. }
  9076. extensions[ name ] = extension;
  9077. return extension !== null;
  9078. },
  9079. get: function ( name ) {
  9080. if ( ! this.has( name ) ) {
  9081. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9082. }
  9083. return extensions[ name ];
  9084. }
  9085. };
  9086. }
  9087. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  9088. const geometries = new WeakMap();
  9089. const wireframeAttributes = new WeakMap();
  9090. function onGeometryDispose( event ) {
  9091. const geometry = event.target;
  9092. const buffergeometry = geometries.get( geometry );
  9093. if ( buffergeometry.index !== null ) {
  9094. attributes.remove( buffergeometry.index );
  9095. }
  9096. for ( const name in buffergeometry.attributes ) {
  9097. attributes.remove( buffergeometry.attributes[ name ] );
  9098. }
  9099. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9100. geometries.delete( geometry );
  9101. const attribute = wireframeAttributes.get( buffergeometry );
  9102. if ( attribute ) {
  9103. attributes.remove( attribute );
  9104. wireframeAttributes.delete( buffergeometry );
  9105. }
  9106. bindingStates.releaseStatesOfGeometry( buffergeometry );
  9107. if ( geometry.isInstancedBufferGeometry === true ) {
  9108. delete geometry._maxInstanceCount;
  9109. }
  9110. //
  9111. info.memory.geometries --;
  9112. }
  9113. function get( object, geometry ) {
  9114. let buffergeometry = geometries.get( geometry );
  9115. if ( buffergeometry ) return buffergeometry;
  9116. geometry.addEventListener( 'dispose', onGeometryDispose );
  9117. if ( geometry.isBufferGeometry ) {
  9118. buffergeometry = geometry;
  9119. } else if ( geometry.isGeometry ) {
  9120. if ( geometry._bufferGeometry === undefined ) {
  9121. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9122. }
  9123. buffergeometry = geometry._bufferGeometry;
  9124. }
  9125. geometries.set( geometry, buffergeometry );
  9126. info.memory.geometries ++;
  9127. return buffergeometry;
  9128. }
  9129. function update( geometry ) {
  9130. const geometryAttributes = geometry.attributes;
  9131. // Updating index buffer in VAO now. See WebGLBindingStates.
  9132. for ( const name in geometryAttributes ) {
  9133. attributes.update( geometryAttributes[ name ], 34962 );
  9134. }
  9135. // morph targets
  9136. const morphAttributes = geometry.morphAttributes;
  9137. for ( const name in morphAttributes ) {
  9138. const array = morphAttributes[ name ];
  9139. for ( let i = 0, l = array.length; i < l; i ++ ) {
  9140. attributes.update( array[ i ], 34962 );
  9141. }
  9142. }
  9143. }
  9144. function updateWireframeAttribute( geometry ) {
  9145. const indices = [];
  9146. const geometryIndex = geometry.index;
  9147. const geometryPosition = geometry.attributes.position;
  9148. let version = 0;
  9149. if ( geometryIndex !== null ) {
  9150. const array = geometryIndex.array;
  9151. version = geometryIndex.version;
  9152. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  9153. const a = array[ i + 0 ];
  9154. const b = array[ i + 1 ];
  9155. const c = array[ i + 2 ];
  9156. indices.push( a, b, b, c, c, a );
  9157. }
  9158. } else {
  9159. const array = geometryPosition.array;
  9160. version = geometryPosition.version;
  9161. for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9162. const a = i + 0;
  9163. const b = i + 1;
  9164. const c = i + 2;
  9165. indices.push( a, b, b, c, c, a );
  9166. }
  9167. }
  9168. const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9169. attribute.version = version;
  9170. // Updating index buffer in VAO now. See WebGLBindingStates
  9171. //
  9172. const previousAttribute = wireframeAttributes.get( geometry );
  9173. if ( previousAttribute ) attributes.remove( previousAttribute );
  9174. //
  9175. wireframeAttributes.set( geometry, attribute );
  9176. }
  9177. function getWireframeAttribute( geometry ) {
  9178. const currentAttribute = wireframeAttributes.get( geometry );
  9179. if ( currentAttribute ) {
  9180. const geometryIndex = geometry.index;
  9181. if ( geometryIndex !== null ) {
  9182. // if the attribute is obsolete, create a new one
  9183. if ( currentAttribute.version < geometryIndex.version ) {
  9184. updateWireframeAttribute( geometry );
  9185. }
  9186. }
  9187. } else {
  9188. updateWireframeAttribute( geometry );
  9189. }
  9190. return wireframeAttributes.get( geometry );
  9191. }
  9192. return {
  9193. get: get,
  9194. update: update,
  9195. getWireframeAttribute: getWireframeAttribute
  9196. };
  9197. }
  9198. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9199. const isWebGL2 = capabilities.isWebGL2;
  9200. let mode;
  9201. function setMode( value ) {
  9202. mode = value;
  9203. }
  9204. let type, bytesPerElement;
  9205. function setIndex( value ) {
  9206. type = value.type;
  9207. bytesPerElement = value.bytesPerElement;
  9208. }
  9209. function render( start, count ) {
  9210. gl.drawElements( mode, count, type, start * bytesPerElement );
  9211. info.update( count, mode, 1 );
  9212. }
  9213. function renderInstances( start, count, primcount ) {
  9214. if ( primcount === 0 ) return;
  9215. let extension, methodName;
  9216. if ( isWebGL2 ) {
  9217. extension = gl;
  9218. methodName = 'drawElementsInstanced';
  9219. } else {
  9220. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9221. methodName = 'drawElementsInstancedANGLE';
  9222. if ( extension === null ) {
  9223. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9224. return;
  9225. }
  9226. }
  9227. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9228. info.update( count, mode, primcount );
  9229. }
  9230. //
  9231. this.setMode = setMode;
  9232. this.setIndex = setIndex;
  9233. this.render = render;
  9234. this.renderInstances = renderInstances;
  9235. }
  9236. function WebGLInfo( gl ) {
  9237. const memory = {
  9238. geometries: 0,
  9239. textures: 0
  9240. };
  9241. const render = {
  9242. frame: 0,
  9243. calls: 0,
  9244. triangles: 0,
  9245. points: 0,
  9246. lines: 0
  9247. };
  9248. function update( count, mode, instanceCount ) {
  9249. render.calls ++;
  9250. switch ( mode ) {
  9251. case 4:
  9252. render.triangles += instanceCount * ( count / 3 );
  9253. break;
  9254. case 1:
  9255. render.lines += instanceCount * ( count / 2 );
  9256. break;
  9257. case 3:
  9258. render.lines += instanceCount * ( count - 1 );
  9259. break;
  9260. case 2:
  9261. render.lines += instanceCount * count;
  9262. break;
  9263. case 0:
  9264. render.points += instanceCount * count;
  9265. break;
  9266. default:
  9267. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9268. break;
  9269. }
  9270. }
  9271. function reset() {
  9272. render.frame ++;
  9273. render.calls = 0;
  9274. render.triangles = 0;
  9275. render.points = 0;
  9276. render.lines = 0;
  9277. }
  9278. return {
  9279. memory: memory,
  9280. render: render,
  9281. programs: null,
  9282. autoReset: true,
  9283. reset: reset,
  9284. update: update
  9285. };
  9286. }
  9287. function numericalSort( a, b ) {
  9288. return a[ 0 ] - b[ 0 ];
  9289. }
  9290. function absNumericalSort( a, b ) {
  9291. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9292. }
  9293. function WebGLMorphtargets( gl ) {
  9294. const influencesList = {};
  9295. const morphInfluences = new Float32Array( 8 );
  9296. const workInfluences = [];
  9297. for ( let i = 0; i < 8; i ++ ) {
  9298. workInfluences[ i ] = [ i, 0 ];
  9299. }
  9300. function update( object, geometry, material, program ) {
  9301. const objectInfluences = object.morphTargetInfluences;
  9302. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9303. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9304. const length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9305. let influences = influencesList[ geometry.id ];
  9306. if ( influences === undefined ) {
  9307. // initialise list
  9308. influences = [];
  9309. for ( let i = 0; i < length; i ++ ) {
  9310. influences[ i ] = [ i, 0 ];
  9311. }
  9312. influencesList[ geometry.id ] = influences;
  9313. }
  9314. // Collect influences
  9315. for ( let i = 0; i < length; i ++ ) {
  9316. const influence = influences[ i ];
  9317. influence[ 0 ] = i;
  9318. influence[ 1 ] = objectInfluences[ i ];
  9319. }
  9320. influences.sort( absNumericalSort );
  9321. for ( let i = 0; i < 8; i ++ ) {
  9322. if ( i < length && influences[ i ][ 1 ] ) {
  9323. workInfluences[ i ][ 0 ] = influences[ i ][ 0 ];
  9324. workInfluences[ i ][ 1 ] = influences[ i ][ 1 ];
  9325. } else {
  9326. workInfluences[ i ][ 0 ] = Number.MAX_SAFE_INTEGER;
  9327. workInfluences[ i ][ 1 ] = 0;
  9328. }
  9329. }
  9330. workInfluences.sort( numericalSort );
  9331. const morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9332. const morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9333. let morphInfluencesSum = 0;
  9334. for ( let i = 0; i < 8; i ++ ) {
  9335. const influence = workInfluences[ i ];
  9336. const index = influence[ 0 ];
  9337. const value = influence[ 1 ];
  9338. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  9339. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== morphTargets[ index ] ) {
  9340. geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9341. }
  9342. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== morphNormals[ index ] ) {
  9343. geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9344. }
  9345. morphInfluences[ i ] = value;
  9346. morphInfluencesSum += value;
  9347. } else {
  9348. if ( morphTargets && geometry.hasAttribute( 'morphTarget' + i ) === true ) {
  9349. geometry.deleteAttribute( 'morphTarget' + i );
  9350. }
  9351. if ( morphNormals && geometry.hasAttribute( 'morphNormal' + i ) === true ) {
  9352. geometry.deleteAttribute( 'morphNormal' + i );
  9353. }
  9354. morphInfluences[ i ] = 0;
  9355. }
  9356. }
  9357. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9358. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9359. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9360. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9361. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  9362. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9363. }
  9364. return {
  9365. update: update
  9366. };
  9367. }
  9368. function WebGLObjects( gl, geometries, attributes, info ) {
  9369. let updateMap = new WeakMap();
  9370. function update( object ) {
  9371. const frame = info.render.frame;
  9372. const geometry = object.geometry;
  9373. const buffergeometry = geometries.get( object, geometry );
  9374. // Update once per frame
  9375. if ( updateMap.get( buffergeometry ) !== frame ) {
  9376. if ( geometry.isGeometry ) {
  9377. buffergeometry.updateFromObject( object );
  9378. }
  9379. geometries.update( buffergeometry );
  9380. updateMap.set( buffergeometry, frame );
  9381. }
  9382. if ( object.isInstancedMesh ) {
  9383. if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {
  9384. object.addEventListener( 'dispose', onInstancedMeshDispose );
  9385. }
  9386. attributes.update( object.instanceMatrix, 34962 );
  9387. if ( object.instanceColor !== null ) {
  9388. attributes.update( object.instanceColor, 34962 );
  9389. }
  9390. }
  9391. return buffergeometry;
  9392. }
  9393. function dispose() {
  9394. updateMap = new WeakMap();
  9395. }
  9396. function onInstancedMeshDispose( event ) {
  9397. const instancedMesh = event.target;
  9398. instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
  9399. attributes.remove( instancedMesh.instanceMatrix );
  9400. if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
  9401. }
  9402. return {
  9403. update: update,
  9404. dispose: dispose
  9405. };
  9406. }
  9407. function DataTexture2DArray( data = null, width = 1, height = 1, depth = 1 ) {
  9408. Texture.call( this, null );
  9409. this.image = { data, width, height, depth };
  9410. this.magFilter = NearestFilter;
  9411. this.minFilter = NearestFilter;
  9412. this.wrapR = ClampToEdgeWrapping;
  9413. this.generateMipmaps = false;
  9414. this.flipY = false;
  9415. this.needsUpdate = true;
  9416. }
  9417. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9418. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9419. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9420. function DataTexture3D( data = null, width = 1, height = 1, depth = 1 ) {
  9421. // We're going to add .setXXX() methods for setting properties later.
  9422. // Users can still set in DataTexture3D directly.
  9423. //
  9424. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9425. // texture.anisotropy = 16;
  9426. //
  9427. // See #14839
  9428. Texture.call( this, null );
  9429. this.image = { data, width, height, depth };
  9430. this.magFilter = NearestFilter;
  9431. this.minFilter = NearestFilter;
  9432. this.wrapR = ClampToEdgeWrapping;
  9433. this.generateMipmaps = false;
  9434. this.flipY = false;
  9435. this.needsUpdate = true;
  9436. }
  9437. DataTexture3D.prototype = Object.create( Texture.prototype );
  9438. DataTexture3D.prototype.constructor = DataTexture3D;
  9439. DataTexture3D.prototype.isDataTexture3D = true;
  9440. /**
  9441. * Uniforms of a program.
  9442. * Those form a tree structure with a special top-level container for the root,
  9443. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9444. *
  9445. *
  9446. * Properties of inner nodes including the top-level container:
  9447. *
  9448. * .seq - array of nested uniforms
  9449. * .map - nested uniforms by name
  9450. *
  9451. *
  9452. * Methods of all nodes except the top-level container:
  9453. *
  9454. * .setValue( gl, value, [textures] )
  9455. *
  9456. * uploads a uniform value(s)
  9457. * the 'textures' parameter is needed for sampler uniforms
  9458. *
  9459. *
  9460. * Static methods of the top-level container (textures factorizations):
  9461. *
  9462. * .upload( gl, seq, values, textures )
  9463. *
  9464. * sets uniforms in 'seq' to 'values[id].value'
  9465. *
  9466. * .seqWithValue( seq, values ) : filteredSeq
  9467. *
  9468. * filters 'seq' entries with corresponding entry in values
  9469. *
  9470. *
  9471. * Methods of the top-level container (textures factorizations):
  9472. *
  9473. * .setValue( gl, name, value, textures )
  9474. *
  9475. * sets uniform with name 'name' to 'value'
  9476. *
  9477. * .setOptional( gl, obj, prop )
  9478. *
  9479. * like .set for an optional property of the object
  9480. *
  9481. */
  9482. const emptyTexture = new Texture();
  9483. const emptyTexture2dArray = new DataTexture2DArray();
  9484. const emptyTexture3d = new DataTexture3D();
  9485. const emptyCubeTexture = new CubeTexture();
  9486. // --- Utilities ---
  9487. // Array Caches (provide typed arrays for temporary by size)
  9488. const arrayCacheF32 = [];
  9489. const arrayCacheI32 = [];
  9490. // Float32Array caches used for uploading Matrix uniforms
  9491. const mat4array = new Float32Array( 16 );
  9492. const mat3array = new Float32Array( 9 );
  9493. const mat2array = new Float32Array( 4 );
  9494. // Flattening for arrays of vectors and matrices
  9495. function flatten( array, nBlocks, blockSize ) {
  9496. const firstElem = array[ 0 ];
  9497. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9498. // unoptimized: ! isNaN( firstElem )
  9499. // see http://jacksondunstan.com/articles/983
  9500. const n = nBlocks * blockSize;
  9501. let r = arrayCacheF32[ n ];
  9502. if ( r === undefined ) {
  9503. r = new Float32Array( n );
  9504. arrayCacheF32[ n ] = r;
  9505. }
  9506. if ( nBlocks !== 0 ) {
  9507. firstElem.toArray( r, 0 );
  9508. for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9509. offset += blockSize;
  9510. array[ i ].toArray( r, offset );
  9511. }
  9512. }
  9513. return r;
  9514. }
  9515. function arraysEqual( a, b ) {
  9516. if ( a.length !== b.length ) return false;
  9517. for ( let i = 0, l = a.length; i < l; i ++ ) {
  9518. if ( a[ i ] !== b[ i ] ) return false;
  9519. }
  9520. return true;
  9521. }
  9522. function copyArray( a, b ) {
  9523. for ( let i = 0, l = b.length; i < l; i ++ ) {
  9524. a[ i ] = b[ i ];
  9525. }
  9526. }
  9527. // Texture unit allocation
  9528. function allocTexUnits( textures, n ) {
  9529. let r = arrayCacheI32[ n ];
  9530. if ( r === undefined ) {
  9531. r = new Int32Array( n );
  9532. arrayCacheI32[ n ] = r;
  9533. }
  9534. for ( let i = 0; i !== n; ++ i ) {
  9535. r[ i ] = textures.allocateTextureUnit();
  9536. }
  9537. return r;
  9538. }
  9539. // --- Setters ---
  9540. // Note: Defining these methods externally, because they come in a bunch
  9541. // and this way their names minify.
  9542. // Single scalar
  9543. function setValueV1f( gl, v ) {
  9544. const cache = this.cache;
  9545. if ( cache[ 0 ] === v ) return;
  9546. gl.uniform1f( this.addr, v );
  9547. cache[ 0 ] = v;
  9548. }
  9549. // Single float vector (from flat array or THREE.VectorN)
  9550. function setValueV2f( gl, v ) {
  9551. const cache = this.cache;
  9552. if ( v.x !== undefined ) {
  9553. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9554. gl.uniform2f( this.addr, v.x, v.y );
  9555. cache[ 0 ] = v.x;
  9556. cache[ 1 ] = v.y;
  9557. }
  9558. } else {
  9559. if ( arraysEqual( cache, v ) ) return;
  9560. gl.uniform2fv( this.addr, v );
  9561. copyArray( cache, v );
  9562. }
  9563. }
  9564. function setValueV3f( gl, v ) {
  9565. const cache = this.cache;
  9566. if ( v.x !== undefined ) {
  9567. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9568. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9569. cache[ 0 ] = v.x;
  9570. cache[ 1 ] = v.y;
  9571. cache[ 2 ] = v.z;
  9572. }
  9573. } else if ( v.r !== undefined ) {
  9574. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9575. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9576. cache[ 0 ] = v.r;
  9577. cache[ 1 ] = v.g;
  9578. cache[ 2 ] = v.b;
  9579. }
  9580. } else {
  9581. if ( arraysEqual( cache, v ) ) return;
  9582. gl.uniform3fv( this.addr, v );
  9583. copyArray( cache, v );
  9584. }
  9585. }
  9586. function setValueV4f( gl, v ) {
  9587. const cache = this.cache;
  9588. if ( v.x !== undefined ) {
  9589. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9590. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9591. cache[ 0 ] = v.x;
  9592. cache[ 1 ] = v.y;
  9593. cache[ 2 ] = v.z;
  9594. cache[ 3 ] = v.w;
  9595. }
  9596. } else {
  9597. if ( arraysEqual( cache, v ) ) return;
  9598. gl.uniform4fv( this.addr, v );
  9599. copyArray( cache, v );
  9600. }
  9601. }
  9602. // Single matrix (from flat array or MatrixN)
  9603. function setValueM2( gl, v ) {
  9604. const cache = this.cache;
  9605. const elements = v.elements;
  9606. if ( elements === undefined ) {
  9607. if ( arraysEqual( cache, v ) ) return;
  9608. gl.uniformMatrix2fv( this.addr, false, v );
  9609. copyArray( cache, v );
  9610. } else {
  9611. if ( arraysEqual( cache, elements ) ) return;
  9612. mat2array.set( elements );
  9613. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9614. copyArray( cache, elements );
  9615. }
  9616. }
  9617. function setValueM3( gl, v ) {
  9618. const cache = this.cache;
  9619. const elements = v.elements;
  9620. if ( elements === undefined ) {
  9621. if ( arraysEqual( cache, v ) ) return;
  9622. gl.uniformMatrix3fv( this.addr, false, v );
  9623. copyArray( cache, v );
  9624. } else {
  9625. if ( arraysEqual( cache, elements ) ) return;
  9626. mat3array.set( elements );
  9627. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9628. copyArray( cache, elements );
  9629. }
  9630. }
  9631. function setValueM4( gl, v ) {
  9632. const cache = this.cache;
  9633. const elements = v.elements;
  9634. if ( elements === undefined ) {
  9635. if ( arraysEqual( cache, v ) ) return;
  9636. gl.uniformMatrix4fv( this.addr, false, v );
  9637. copyArray( cache, v );
  9638. } else {
  9639. if ( arraysEqual( cache, elements ) ) return;
  9640. mat4array.set( elements );
  9641. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9642. copyArray( cache, elements );
  9643. }
  9644. }
  9645. // Single texture (2D / Cube)
  9646. function setValueT1( gl, v, textures ) {
  9647. const cache = this.cache;
  9648. const unit = textures.allocateTextureUnit();
  9649. if ( cache[ 0 ] !== unit ) {
  9650. gl.uniform1i( this.addr, unit );
  9651. cache[ 0 ] = unit;
  9652. }
  9653. textures.safeSetTexture2D( v || emptyTexture, unit );
  9654. }
  9655. function setValueT2DArray1( gl, v, textures ) {
  9656. const cache = this.cache;
  9657. const unit = textures.allocateTextureUnit();
  9658. if ( cache[ 0 ] !== unit ) {
  9659. gl.uniform1i( this.addr, unit );
  9660. cache[ 0 ] = unit;
  9661. }
  9662. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9663. }
  9664. function setValueT3D1( gl, v, textures ) {
  9665. const cache = this.cache;
  9666. const unit = textures.allocateTextureUnit();
  9667. if ( cache[ 0 ] !== unit ) {
  9668. gl.uniform1i( this.addr, unit );
  9669. cache[ 0 ] = unit;
  9670. }
  9671. textures.setTexture3D( v || emptyTexture3d, unit );
  9672. }
  9673. function setValueT6( gl, v, textures ) {
  9674. const cache = this.cache;
  9675. const unit = textures.allocateTextureUnit();
  9676. if ( cache[ 0 ] !== unit ) {
  9677. gl.uniform1i( this.addr, unit );
  9678. cache[ 0 ] = unit;
  9679. }
  9680. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9681. }
  9682. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9683. function setValueV1i( gl, v ) {
  9684. const cache = this.cache;
  9685. if ( cache[ 0 ] === v ) return;
  9686. gl.uniform1i( this.addr, v );
  9687. cache[ 0 ] = v;
  9688. }
  9689. function setValueV2i( gl, v ) {
  9690. const cache = this.cache;
  9691. if ( arraysEqual( cache, v ) ) return;
  9692. gl.uniform2iv( this.addr, v );
  9693. copyArray( cache, v );
  9694. }
  9695. function setValueV3i( gl, v ) {
  9696. const cache = this.cache;
  9697. if ( arraysEqual( cache, v ) ) return;
  9698. gl.uniform3iv( this.addr, v );
  9699. copyArray( cache, v );
  9700. }
  9701. function setValueV4i( gl, v ) {
  9702. const cache = this.cache;
  9703. if ( arraysEqual( cache, v ) ) return;
  9704. gl.uniform4iv( this.addr, v );
  9705. copyArray( cache, v );
  9706. }
  9707. // uint
  9708. function setValueV1ui( gl, v ) {
  9709. const cache = this.cache;
  9710. if ( cache[ 0 ] === v ) return;
  9711. gl.uniform1ui( this.addr, v );
  9712. cache[ 0 ] = v;
  9713. }
  9714. // Helper to pick the right setter for the singular case
  9715. function getSingularSetter( type ) {
  9716. switch ( type ) {
  9717. case 0x1406: return setValueV1f; // FLOAT
  9718. case 0x8b50: return setValueV2f; // _VEC2
  9719. case 0x8b51: return setValueV3f; // _VEC3
  9720. case 0x8b52: return setValueV4f; // _VEC4
  9721. case 0x8b5a: return setValueM2; // _MAT2
  9722. case 0x8b5b: return setValueM3; // _MAT3
  9723. case 0x8b5c: return setValueM4; // _MAT4
  9724. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  9725. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  9726. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  9727. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  9728. case 0x1405: return setValueV1ui; // UINT
  9729. case 0x8b5e: // SAMPLER_2D
  9730. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9731. case 0x8dca: // INT_SAMPLER_2D
  9732. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9733. case 0x8b62: // SAMPLER_2D_SHADOW
  9734. return setValueT1;
  9735. case 0x8b5f: // SAMPLER_3D
  9736. case 0x8dcb: // INT_SAMPLER_3D
  9737. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  9738. return setValueT3D1;
  9739. case 0x8b60: // SAMPLER_CUBE
  9740. case 0x8dcc: // INT_SAMPLER_CUBE
  9741. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9742. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9743. return setValueT6;
  9744. case 0x8dc1: // SAMPLER_2D_ARRAY
  9745. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  9746. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  9747. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  9748. return setValueT2DArray1;
  9749. }
  9750. }
  9751. // Array of scalars
  9752. function setValueV1fArray( gl, v ) {
  9753. gl.uniform1fv( this.addr, v );
  9754. }
  9755. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9756. function setValueV1iArray( gl, v ) {
  9757. gl.uniform1iv( this.addr, v );
  9758. }
  9759. function setValueV2iArray( gl, v ) {
  9760. gl.uniform2iv( this.addr, v );
  9761. }
  9762. function setValueV3iArray( gl, v ) {
  9763. gl.uniform3iv( this.addr, v );
  9764. }
  9765. function setValueV4iArray( gl, v ) {
  9766. gl.uniform4iv( this.addr, v );
  9767. }
  9768. // Array of vectors (flat or from THREE classes)
  9769. function setValueV2fArray( gl, v ) {
  9770. const data = flatten( v, this.size, 2 );
  9771. gl.uniform2fv( this.addr, data );
  9772. }
  9773. function setValueV3fArray( gl, v ) {
  9774. const data = flatten( v, this.size, 3 );
  9775. gl.uniform3fv( this.addr, data );
  9776. }
  9777. function setValueV4fArray( gl, v ) {
  9778. const data = flatten( v, this.size, 4 );
  9779. gl.uniform4fv( this.addr, data );
  9780. }
  9781. // Array of matrices (flat or from THREE clases)
  9782. function setValueM2Array( gl, v ) {
  9783. const data = flatten( v, this.size, 4 );
  9784. gl.uniformMatrix2fv( this.addr, false, data );
  9785. }
  9786. function setValueM3Array( gl, v ) {
  9787. const data = flatten( v, this.size, 9 );
  9788. gl.uniformMatrix3fv( this.addr, false, data );
  9789. }
  9790. function setValueM4Array( gl, v ) {
  9791. const data = flatten( v, this.size, 16 );
  9792. gl.uniformMatrix4fv( this.addr, false, data );
  9793. }
  9794. // Array of textures (2D / Cube)
  9795. function setValueT1Array( gl, v, textures ) {
  9796. const n = v.length;
  9797. const units = allocTexUnits( textures, n );
  9798. gl.uniform1iv( this.addr, units );
  9799. for ( let i = 0; i !== n; ++ i ) {
  9800. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9801. }
  9802. }
  9803. function setValueT6Array( gl, v, textures ) {
  9804. const n = v.length;
  9805. const units = allocTexUnits( textures, n );
  9806. gl.uniform1iv( this.addr, units );
  9807. for ( let i = 0; i !== n; ++ i ) {
  9808. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9809. }
  9810. }
  9811. // Helper to pick the right setter for a pure (bottom-level) array
  9812. function getPureArraySetter( type ) {
  9813. switch ( type ) {
  9814. case 0x1406: return setValueV1fArray; // FLOAT
  9815. case 0x8b50: return setValueV2fArray; // _VEC2
  9816. case 0x8b51: return setValueV3fArray; // _VEC3
  9817. case 0x8b52: return setValueV4fArray; // _VEC4
  9818. case 0x8b5a: return setValueM2Array; // _MAT2
  9819. case 0x8b5b: return setValueM3Array; // _MAT3
  9820. case 0x8b5c: return setValueM4Array; // _MAT4
  9821. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  9822. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  9823. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  9824. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  9825. case 0x8b5e: // SAMPLER_2D
  9826. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9827. case 0x8dca: // INT_SAMPLER_2D
  9828. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9829. case 0x8b62: // SAMPLER_2D_SHADOW
  9830. return setValueT1Array;
  9831. case 0x8b60: // SAMPLER_CUBE
  9832. case 0x8dcc: // INT_SAMPLER_CUBE
  9833. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9834. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9835. return setValueT6Array;
  9836. }
  9837. }
  9838. // --- Uniform Classes ---
  9839. function SingleUniform( id, activeInfo, addr ) {
  9840. this.id = id;
  9841. this.addr = addr;
  9842. this.cache = [];
  9843. this.setValue = getSingularSetter( activeInfo.type );
  9844. // this.path = activeInfo.name; // DEBUG
  9845. }
  9846. function PureArrayUniform( id, activeInfo, addr ) {
  9847. this.id = id;
  9848. this.addr = addr;
  9849. this.cache = [];
  9850. this.size = activeInfo.size;
  9851. this.setValue = getPureArraySetter( activeInfo.type );
  9852. // this.path = activeInfo.name; // DEBUG
  9853. }
  9854. PureArrayUniform.prototype.updateCache = function ( data ) {
  9855. const cache = this.cache;
  9856. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9857. this.cache = new Float32Array( data.length );
  9858. }
  9859. copyArray( cache, data );
  9860. };
  9861. function StructuredUniform( id ) {
  9862. this.id = id;
  9863. this.seq = [];
  9864. this.map = {};
  9865. }
  9866. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9867. const seq = this.seq;
  9868. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9869. const u = seq[ i ];
  9870. u.setValue( gl, value[ u.id ], textures );
  9871. }
  9872. };
  9873. // --- Top-level ---
  9874. // Parser - builds up the property tree from the path strings
  9875. const RePathPart = /(\w+)(\])?(\[|\.)?/g;
  9876. // extracts
  9877. // - the identifier (member name or array index)
  9878. // - followed by an optional right bracket (found when array index)
  9879. // - followed by an optional left bracket or dot (type of subscript)
  9880. //
  9881. // Note: These portions can be read in a non-overlapping fashion and
  9882. // allow straightforward parsing of the hierarchy that WebGL encodes
  9883. // in the uniform names.
  9884. function addUniform( container, uniformObject ) {
  9885. container.seq.push( uniformObject );
  9886. container.map[ uniformObject.id ] = uniformObject;
  9887. }
  9888. function parseUniform( activeInfo, addr, container ) {
  9889. const path = activeInfo.name,
  9890. pathLength = path.length;
  9891. // reset RegExp object, because of the early exit of a previous run
  9892. RePathPart.lastIndex = 0;
  9893. while ( true ) {
  9894. const match = RePathPart.exec( path ),
  9895. matchEnd = RePathPart.lastIndex;
  9896. let id = match[ 1 ];
  9897. const idIsIndex = match[ 2 ] === ']',
  9898. subscript = match[ 3 ];
  9899. if ( idIsIndex ) id = id | 0; // convert to integer
  9900. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9901. // bare name or "pure" bottom-level array "[0]" suffix
  9902. addUniform( container, subscript === undefined ?
  9903. new SingleUniform( id, activeInfo, addr ) :
  9904. new PureArrayUniform( id, activeInfo, addr ) );
  9905. break;
  9906. } else {
  9907. // step into inner node / create it in case it doesn't exist
  9908. const map = container.map;
  9909. let next = map[ id ];
  9910. if ( next === undefined ) {
  9911. next = new StructuredUniform( id );
  9912. addUniform( container, next );
  9913. }
  9914. container = next;
  9915. }
  9916. }
  9917. }
  9918. // Root Container
  9919. function WebGLUniforms( gl, program ) {
  9920. this.seq = [];
  9921. this.map = {};
  9922. const n = gl.getProgramParameter( program, 35718 );
  9923. for ( let i = 0; i < n; ++ i ) {
  9924. const info = gl.getActiveUniform( program, i ),
  9925. addr = gl.getUniformLocation( program, info.name );
  9926. parseUniform( info, addr, this );
  9927. }
  9928. }
  9929. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9930. const u = this.map[ name ];
  9931. if ( u !== undefined ) u.setValue( gl, value, textures );
  9932. };
  9933. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9934. const v = object[ name ];
  9935. if ( v !== undefined ) this.setValue( gl, name, v );
  9936. };
  9937. // Static interface
  9938. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9939. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9940. const u = seq[ i ],
  9941. v = values[ u.id ];
  9942. if ( v.needsUpdate !== false ) {
  9943. // note: always updating when .needsUpdate is undefined
  9944. u.setValue( gl, v.value, textures );
  9945. }
  9946. }
  9947. };
  9948. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9949. const r = [];
  9950. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9951. const u = seq[ i ];
  9952. if ( u.id in values ) r.push( u );
  9953. }
  9954. return r;
  9955. };
  9956. function WebGLShader( gl, type, string ) {
  9957. const shader = gl.createShader( type );
  9958. gl.shaderSource( shader, string );
  9959. gl.compileShader( shader );
  9960. return shader;
  9961. }
  9962. let programIdCount = 0;
  9963. function addLineNumbers( string ) {
  9964. const lines = string.split( '\n' );
  9965. for ( let i = 0; i < lines.length; i ++ ) {
  9966. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9967. }
  9968. return lines.join( '\n' );
  9969. }
  9970. function getEncodingComponents( encoding ) {
  9971. switch ( encoding ) {
  9972. case LinearEncoding:
  9973. return [ 'Linear', '( value )' ];
  9974. case sRGBEncoding:
  9975. return [ 'sRGB', '( value )' ];
  9976. case RGBEEncoding:
  9977. return [ 'RGBE', '( value )' ];
  9978. case RGBM7Encoding:
  9979. return [ 'RGBM', '( value, 7.0 )' ];
  9980. case RGBM16Encoding:
  9981. return [ 'RGBM', '( value, 16.0 )' ];
  9982. case RGBDEncoding:
  9983. return [ 'RGBD', '( value, 256.0 )' ];
  9984. case GammaEncoding:
  9985. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9986. case LogLuvEncoding:
  9987. return [ 'LogLuv', '( value )' ];
  9988. default:
  9989. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  9990. return [ 'Linear', '( value )' ];
  9991. }
  9992. }
  9993. function getShaderErrors( gl, shader, type ) {
  9994. const status = gl.getShaderParameter( shader, 35713 );
  9995. const log = gl.getShaderInfoLog( shader ).trim();
  9996. if ( status && log === '' ) return '';
  9997. // --enable-privileged-webgl-extension
  9998. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9999. const source = gl.getShaderSource( shader );
  10000. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10001. }
  10002. function getTexelDecodingFunction( functionName, encoding ) {
  10003. const components = getEncodingComponents( encoding );
  10004. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10005. }
  10006. function getTexelEncodingFunction( functionName, encoding ) {
  10007. const components = getEncodingComponents( encoding );
  10008. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10009. }
  10010. function getToneMappingFunction( functionName, toneMapping ) {
  10011. let toneMappingName;
  10012. switch ( toneMapping ) {
  10013. case LinearToneMapping:
  10014. toneMappingName = 'Linear';
  10015. break;
  10016. case ReinhardToneMapping:
  10017. toneMappingName = 'Reinhard';
  10018. break;
  10019. case CineonToneMapping:
  10020. toneMappingName = 'OptimizedCineon';
  10021. break;
  10022. case ACESFilmicToneMapping:
  10023. toneMappingName = 'ACESFilmic';
  10024. break;
  10025. case CustomToneMapping:
  10026. toneMappingName = 'Custom';
  10027. break;
  10028. default:
  10029. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  10030. toneMappingName = 'Linear';
  10031. }
  10032. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10033. }
  10034. function generateExtensions( parameters ) {
  10035. const chunks = [
  10036. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10037. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  10038. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10039. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10040. ];
  10041. return chunks.filter( filterEmptyLine ).join( '\n' );
  10042. }
  10043. function generateDefines( defines ) {
  10044. const chunks = [];
  10045. for ( const name in defines ) {
  10046. const value = defines[ name ];
  10047. if ( value === false ) continue;
  10048. chunks.push( '#define ' + name + ' ' + value );
  10049. }
  10050. return chunks.join( '\n' );
  10051. }
  10052. function fetchAttributeLocations( gl, program ) {
  10053. const attributes = {};
  10054. const n = gl.getProgramParameter( program, 35721 );
  10055. for ( let i = 0; i < n; i ++ ) {
  10056. const info = gl.getActiveAttrib( program, i );
  10057. const name = info.name;
  10058. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10059. attributes[ name ] = gl.getAttribLocation( program, name );
  10060. }
  10061. return attributes;
  10062. }
  10063. function filterEmptyLine( string ) {
  10064. return string !== '';
  10065. }
  10066. function replaceLightNums( string, parameters ) {
  10067. return string
  10068. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10069. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10070. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10071. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10072. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10073. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10074. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10075. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10076. }
  10077. function replaceClippingPlaneNums( string, parameters ) {
  10078. return string
  10079. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10080. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10081. }
  10082. // Resolve Includes
  10083. const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10084. function resolveIncludes( string ) {
  10085. return string.replace( includePattern, includeReplacer );
  10086. }
  10087. function includeReplacer( match, include ) {
  10088. const string = ShaderChunk[ include ];
  10089. if ( string === undefined ) {
  10090. throw new Error( 'Can not resolve #include <' + include + '>' );
  10091. }
  10092. return resolveIncludes( string );
  10093. }
  10094. // Unroll Loops
  10095. const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10096. 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;
  10097. function unrollLoops( string ) {
  10098. return string
  10099. .replace( unrollLoopPattern, loopReplacer )
  10100. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  10101. }
  10102. function deprecatedLoopReplacer( match, start, end, snippet ) {
  10103. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  10104. return loopReplacer( match, start, end, snippet );
  10105. }
  10106. function loopReplacer( match, start, end, snippet ) {
  10107. let string = '';
  10108. for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10109. string += snippet
  10110. .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )
  10111. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10112. }
  10113. return string;
  10114. }
  10115. //
  10116. function generatePrecision( parameters ) {
  10117. let precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10118. if ( parameters.precision === 'highp' ) {
  10119. precisionstring += '\n#define HIGH_PRECISION';
  10120. } else if ( parameters.precision === 'mediump' ) {
  10121. precisionstring += '\n#define MEDIUM_PRECISION';
  10122. } else if ( parameters.precision === 'lowp' ) {
  10123. precisionstring += '\n#define LOW_PRECISION';
  10124. }
  10125. return precisionstring;
  10126. }
  10127. function generateShadowMapTypeDefine( parameters ) {
  10128. let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10129. if ( parameters.shadowMapType === PCFShadowMap ) {
  10130. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10131. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10132. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10133. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  10134. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10135. }
  10136. return shadowMapTypeDefine;
  10137. }
  10138. function generateEnvMapTypeDefine( parameters ) {
  10139. let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10140. if ( parameters.envMap ) {
  10141. switch ( parameters.envMapMode ) {
  10142. case CubeReflectionMapping:
  10143. case CubeRefractionMapping:
  10144. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10145. break;
  10146. case CubeUVReflectionMapping:
  10147. case CubeUVRefractionMapping:
  10148. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10149. break;
  10150. }
  10151. }
  10152. return envMapTypeDefine;
  10153. }
  10154. function generateEnvMapModeDefine( parameters ) {
  10155. let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10156. if ( parameters.envMap ) {
  10157. switch ( parameters.envMapMode ) {
  10158. case CubeRefractionMapping:
  10159. case CubeUVRefractionMapping:
  10160. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10161. break;
  10162. }
  10163. }
  10164. return envMapModeDefine;
  10165. }
  10166. function generateEnvMapBlendingDefine( parameters ) {
  10167. let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10168. if ( parameters.envMap ) {
  10169. switch ( parameters.combine ) {
  10170. case MultiplyOperation:
  10171. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10172. break;
  10173. case MixOperation:
  10174. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10175. break;
  10176. case AddOperation:
  10177. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10178. break;
  10179. }
  10180. }
  10181. return envMapBlendingDefine;
  10182. }
  10183. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  10184. const gl = renderer.getContext();
  10185. const defines = parameters.defines;
  10186. let vertexShader = parameters.vertexShader;
  10187. let fragmentShader = parameters.fragmentShader;
  10188. const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  10189. const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  10190. const envMapModeDefine = generateEnvMapModeDefine( parameters );
  10191. const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  10192. const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10193. const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  10194. const customDefines = generateDefines( defines );
  10195. const program = gl.createProgram();
  10196. let prefixVertex, prefixFragment;
  10197. let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10198. if ( parameters.isRawShaderMaterial ) {
  10199. prefixVertex = [
  10200. customDefines
  10201. ].filter( filterEmptyLine ).join( '\n' );
  10202. if ( prefixVertex.length > 0 ) {
  10203. prefixVertex += '\n';
  10204. }
  10205. prefixFragment = [
  10206. customExtensions,
  10207. customDefines
  10208. ].filter( filterEmptyLine ).join( '\n' );
  10209. if ( prefixFragment.length > 0 ) {
  10210. prefixFragment += '\n';
  10211. }
  10212. } else {
  10213. prefixVertex = [
  10214. generatePrecision( parameters ),
  10215. '#define SHADER_NAME ' + parameters.shaderName,
  10216. customDefines,
  10217. parameters.instancing ? '#define USE_INSTANCING' : '',
  10218. parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
  10219. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10220. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10221. '#define MAX_BONES ' + parameters.maxBones,
  10222. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10223. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10224. parameters.map ? '#define USE_MAP' : '',
  10225. parameters.envMap ? '#define USE_ENVMAP' : '',
  10226. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10227. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10228. parameters.aoMap ? '#define USE_AOMAP' : '',
  10229. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10230. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10231. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10232. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10233. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10234. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10235. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10236. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10237. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10238. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10239. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10240. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10241. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10242. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10243. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10244. parameters.vertexColors ? '#define USE_COLOR' : '',
  10245. parameters.vertexUvs ? '#define USE_UV' : '',
  10246. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10247. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10248. parameters.skinning ? '#define USE_SKINNING' : '',
  10249. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10250. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10251. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10252. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10253. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10254. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10255. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10256. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10257. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10258. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10259. 'uniform mat4 modelMatrix;',
  10260. 'uniform mat4 modelViewMatrix;',
  10261. 'uniform mat4 projectionMatrix;',
  10262. 'uniform mat4 viewMatrix;',
  10263. 'uniform mat3 normalMatrix;',
  10264. 'uniform vec3 cameraPosition;',
  10265. 'uniform bool isOrthographic;',
  10266. '#ifdef USE_INSTANCING',
  10267. ' attribute mat4 instanceMatrix;',
  10268. '#endif',
  10269. '#ifdef USE_INSTANCING_COLOR',
  10270. ' attribute vec3 instanceColor;',
  10271. '#endif',
  10272. 'attribute vec3 position;',
  10273. 'attribute vec3 normal;',
  10274. 'attribute vec2 uv;',
  10275. '#ifdef USE_TANGENT',
  10276. ' attribute vec4 tangent;',
  10277. '#endif',
  10278. '#ifdef USE_COLOR',
  10279. ' attribute vec3 color;',
  10280. '#endif',
  10281. '#ifdef USE_MORPHTARGETS',
  10282. ' attribute vec3 morphTarget0;',
  10283. ' attribute vec3 morphTarget1;',
  10284. ' attribute vec3 morphTarget2;',
  10285. ' attribute vec3 morphTarget3;',
  10286. ' #ifdef USE_MORPHNORMALS',
  10287. ' attribute vec3 morphNormal0;',
  10288. ' attribute vec3 morphNormal1;',
  10289. ' attribute vec3 morphNormal2;',
  10290. ' attribute vec3 morphNormal3;',
  10291. ' #else',
  10292. ' attribute vec3 morphTarget4;',
  10293. ' attribute vec3 morphTarget5;',
  10294. ' attribute vec3 morphTarget6;',
  10295. ' attribute vec3 morphTarget7;',
  10296. ' #endif',
  10297. '#endif',
  10298. '#ifdef USE_SKINNING',
  10299. ' attribute vec4 skinIndex;',
  10300. ' attribute vec4 skinWeight;',
  10301. '#endif',
  10302. '\n'
  10303. ].filter( filterEmptyLine ).join( '\n' );
  10304. prefixFragment = [
  10305. customExtensions,
  10306. generatePrecision( parameters ),
  10307. '#define SHADER_NAME ' + parameters.shaderName,
  10308. customDefines,
  10309. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10310. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10311. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10312. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10313. parameters.map ? '#define USE_MAP' : '',
  10314. parameters.matcap ? '#define USE_MATCAP' : '',
  10315. parameters.envMap ? '#define USE_ENVMAP' : '',
  10316. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10317. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10318. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10319. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10320. parameters.aoMap ? '#define USE_AOMAP' : '',
  10321. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10322. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10323. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10324. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10325. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10326. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10327. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10328. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10329. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10330. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10331. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10332. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10333. parameters.sheen ? '#define USE_SHEEN' : '',
  10334. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10335. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10336. parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
  10337. parameters.vertexUvs ? '#define USE_UV' : '',
  10338. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10339. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10340. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10341. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10342. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10343. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10344. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10345. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10346. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10347. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10348. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10349. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  10350. 'uniform mat4 viewMatrix;',
  10351. 'uniform vec3 cameraPosition;',
  10352. 'uniform bool isOrthographic;',
  10353. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10354. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10355. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10356. parameters.dithering ? '#define DITHERING' : '',
  10357. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  10358. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10359. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10360. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10361. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10362. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  10363. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  10364. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  10365. '\n'
  10366. ].filter( filterEmptyLine ).join( '\n' );
  10367. }
  10368. vertexShader = resolveIncludes( vertexShader );
  10369. vertexShader = replaceLightNums( vertexShader, parameters );
  10370. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10371. fragmentShader = resolveIncludes( fragmentShader );
  10372. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10373. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10374. vertexShader = unrollLoops( vertexShader );
  10375. fragmentShader = unrollLoops( fragmentShader );
  10376. if ( parameters.isWebGL2 && parameters.isRawShaderMaterial !== true ) {
  10377. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10378. versionString = '#version 300 es\n';
  10379. prefixVertex = [
  10380. '#define attribute in',
  10381. '#define varying out',
  10382. '#define texture2D texture'
  10383. ].join( '\n' ) + '\n' + prefixVertex;
  10384. prefixFragment = [
  10385. '#define varying in',
  10386. ( parameters.glslVersion === GLSL3 ) ? '' : 'out highp vec4 pc_fragColor;',
  10387. ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor',
  10388. '#define gl_FragDepthEXT gl_FragDepth',
  10389. '#define texture2D texture',
  10390. '#define textureCube texture',
  10391. '#define texture2DProj textureProj',
  10392. '#define texture2DLodEXT textureLod',
  10393. '#define texture2DProjLodEXT textureProjLod',
  10394. '#define textureCubeLodEXT textureLod',
  10395. '#define texture2DGradEXT textureGrad',
  10396. '#define texture2DProjGradEXT textureProjGrad',
  10397. '#define textureCubeGradEXT textureGrad'
  10398. ].join( '\n' ) + '\n' + prefixFragment;
  10399. }
  10400. const vertexGlsl = versionString + prefixVertex + vertexShader;
  10401. const fragmentGlsl = versionString + prefixFragment + fragmentShader;
  10402. // console.log( '*VERTEX*', vertexGlsl );
  10403. // console.log( '*FRAGMENT*', fragmentGlsl );
  10404. const glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10405. const glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10406. gl.attachShader( program, glVertexShader );
  10407. gl.attachShader( program, glFragmentShader );
  10408. // Force a particular attribute to index 0.
  10409. if ( parameters.index0AttributeName !== undefined ) {
  10410. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  10411. } else if ( parameters.morphTargets === true ) {
  10412. // programs with morphTargets displace position out of attribute 0
  10413. gl.bindAttribLocation( program, 0, 'position' );
  10414. }
  10415. gl.linkProgram( program );
  10416. // check for link errors
  10417. if ( renderer.debug.checkShaderErrors ) {
  10418. const programLog = gl.getProgramInfoLog( program ).trim();
  10419. const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10420. const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10421. let runnable = true;
  10422. let haveDiagnostics = true;
  10423. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10424. runnable = false;
  10425. const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10426. const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10427. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10428. } else if ( programLog !== '' ) {
  10429. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10430. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10431. haveDiagnostics = false;
  10432. }
  10433. if ( haveDiagnostics ) {
  10434. this.diagnostics = {
  10435. runnable: runnable,
  10436. programLog: programLog,
  10437. vertexShader: {
  10438. log: vertexLog,
  10439. prefix: prefixVertex
  10440. },
  10441. fragmentShader: {
  10442. log: fragmentLog,
  10443. prefix: prefixFragment
  10444. }
  10445. };
  10446. }
  10447. }
  10448. // Clean up
  10449. // Crashes in iOS9 and iOS10. #18402
  10450. // gl.detachShader( program, glVertexShader );
  10451. // gl.detachShader( program, glFragmentShader );
  10452. gl.deleteShader( glVertexShader );
  10453. gl.deleteShader( glFragmentShader );
  10454. // set up caching for uniform locations
  10455. let cachedUniforms;
  10456. this.getUniforms = function () {
  10457. if ( cachedUniforms === undefined ) {
  10458. cachedUniforms = new WebGLUniforms( gl, program );
  10459. }
  10460. return cachedUniforms;
  10461. };
  10462. // set up caching for attribute locations
  10463. let cachedAttributes;
  10464. this.getAttributes = function () {
  10465. if ( cachedAttributes === undefined ) {
  10466. cachedAttributes = fetchAttributeLocations( gl, program );
  10467. }
  10468. return cachedAttributes;
  10469. };
  10470. // free resource
  10471. this.destroy = function () {
  10472. bindingStates.releaseStatesOfProgram( this );
  10473. gl.deleteProgram( program );
  10474. this.program = undefined;
  10475. };
  10476. //
  10477. this.name = parameters.shaderName;
  10478. this.id = programIdCount ++;
  10479. this.cacheKey = cacheKey;
  10480. this.usedTimes = 1;
  10481. this.program = program;
  10482. this.vertexShader = glVertexShader;
  10483. this.fragmentShader = glFragmentShader;
  10484. return this;
  10485. }
  10486. function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingStates, clipping ) {
  10487. const programs = [];
  10488. const isWebGL2 = capabilities.isWebGL2;
  10489. const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10490. const floatVertexTextures = capabilities.floatVertexTextures;
  10491. const maxVertexUniforms = capabilities.maxVertexUniforms;
  10492. const vertexTextures = capabilities.vertexTextures;
  10493. let precision = capabilities.precision;
  10494. const shaderIDs = {
  10495. MeshDepthMaterial: 'depth',
  10496. MeshDistanceMaterial: 'distanceRGBA',
  10497. MeshNormalMaterial: 'normal',
  10498. MeshBasicMaterial: 'basic',
  10499. MeshLambertMaterial: 'lambert',
  10500. MeshPhongMaterial: 'phong',
  10501. MeshToonMaterial: 'toon',
  10502. MeshStandardMaterial: 'physical',
  10503. MeshPhysicalMaterial: 'physical',
  10504. MeshMatcapMaterial: 'matcap',
  10505. LineBasicMaterial: 'basic',
  10506. LineDashedMaterial: 'dashed',
  10507. PointsMaterial: 'points',
  10508. ShadowMaterial: 'shadow',
  10509. SpriteMaterial: 'sprite'
  10510. };
  10511. const parameterNames = [
  10512. 'precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor',
  10513. 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV',
  10514. 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap',
  10515. 'roughnessMap', 'metalnessMap', 'gradientMap',
  10516. 'alphaMap', 'combine', 'vertexColors', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2',
  10517. 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning',
  10518. 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals',
  10519. 'maxMorphTargets', 'maxMorphNormals', 'premultipliedAlpha',
  10520. 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
  10521. 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
  10522. 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
  10523. 'alphaTest', 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering',
  10524. 'sheen', 'transmissionMap'
  10525. ];
  10526. function getMaxBones( object ) {
  10527. const skeleton = object.skeleton;
  10528. const bones = skeleton.bones;
  10529. if ( floatVertexTextures ) {
  10530. return 1024;
  10531. } else {
  10532. // default for when object is not specified
  10533. // ( for example when prebuilding shader to be used with multiple objects )
  10534. //
  10535. // - leave some extra space for other uniforms
  10536. // - limit here is ANGLE's 254 max uniform vectors
  10537. // (up to 54 should be safe)
  10538. const nVertexUniforms = maxVertexUniforms;
  10539. const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10540. const maxBones = Math.min( nVertexMatrices, bones.length );
  10541. if ( maxBones < bones.length ) {
  10542. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10543. return 0;
  10544. }
  10545. return maxBones;
  10546. }
  10547. }
  10548. function getTextureEncodingFromMap( map ) {
  10549. let encoding;
  10550. if ( map && map.isTexture ) {
  10551. encoding = map.encoding;
  10552. } else if ( map && map.isWebGLRenderTarget ) {
  10553. console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' );
  10554. encoding = map.texture.encoding;
  10555. } else {
  10556. encoding = LinearEncoding;
  10557. }
  10558. return encoding;
  10559. }
  10560. function getParameters( material, lights, shadows, scene, object ) {
  10561. const fog = scene.fog;
  10562. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  10563. const envMap = cubemaps.get( material.envMap || environment );
  10564. const shaderID = shaderIDs[ material.type ];
  10565. // heuristics to create shader parameters according to lights in the scene
  10566. // (not to blow over maxLights budget)
  10567. const maxBones = object.isSkinnedMesh ? getMaxBones( object ) : 0;
  10568. if ( material.precision !== null ) {
  10569. precision = capabilities.getMaxPrecision( material.precision );
  10570. if ( precision !== material.precision ) {
  10571. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10572. }
  10573. }
  10574. let vertexShader, fragmentShader;
  10575. if ( shaderID ) {
  10576. const shader = ShaderLib[ shaderID ];
  10577. vertexShader = shader.vertexShader;
  10578. fragmentShader = shader.fragmentShader;
  10579. } else {
  10580. vertexShader = material.vertexShader;
  10581. fragmentShader = material.fragmentShader;
  10582. }
  10583. const currentRenderTarget = renderer.getRenderTarget();
  10584. const parameters = {
  10585. isWebGL2: isWebGL2,
  10586. shaderID: shaderID,
  10587. shaderName: material.type,
  10588. vertexShader: vertexShader,
  10589. fragmentShader: fragmentShader,
  10590. defines: material.defines,
  10591. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10592. glslVersion: material.glslVersion,
  10593. precision: precision,
  10594. instancing: object.isInstancedMesh === true,
  10595. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10596. supportsVertexTextures: vertexTextures,
  10597. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  10598. map: !! material.map,
  10599. mapEncoding: getTextureEncodingFromMap( material.map ),
  10600. matcap: !! material.matcap,
  10601. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  10602. envMap: !! envMap,
  10603. envMapMode: envMap && envMap.mapping,
  10604. envMapEncoding: getTextureEncodingFromMap( envMap ),
  10605. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  10606. lightMap: !! material.lightMap,
  10607. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  10608. aoMap: !! material.aoMap,
  10609. emissiveMap: !! material.emissiveMap,
  10610. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  10611. bumpMap: !! material.bumpMap,
  10612. normalMap: !! material.normalMap,
  10613. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10614. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10615. clearcoatMap: !! material.clearcoatMap,
  10616. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  10617. clearcoatNormalMap: !! material.clearcoatNormalMap,
  10618. displacementMap: !! material.displacementMap,
  10619. roughnessMap: !! material.roughnessMap,
  10620. metalnessMap: !! material.metalnessMap,
  10621. specularMap: !! material.specularMap,
  10622. alphaMap: !! material.alphaMap,
  10623. gradientMap: !! material.gradientMap,
  10624. sheen: !! material.sheen,
  10625. transmissionMap: !! material.transmissionMap,
  10626. combine: material.combine,
  10627. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10628. vertexColors: material.vertexColors,
  10629. 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,
  10630. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.transmissionMap ) && !! material.displacementMap,
  10631. fog: !! fog,
  10632. useFog: material.fog,
  10633. fogExp2: ( fog && fog.isFogExp2 ),
  10634. flatShading: material.flatShading,
  10635. sizeAttenuation: material.sizeAttenuation,
  10636. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10637. skinning: material.skinning && maxBones > 0,
  10638. maxBones: maxBones,
  10639. useVertexTexture: floatVertexTextures,
  10640. morphTargets: material.morphTargets,
  10641. morphNormals: material.morphNormals,
  10642. maxMorphTargets: renderer.maxMorphTargets,
  10643. maxMorphNormals: renderer.maxMorphNormals,
  10644. numDirLights: lights.directional.length,
  10645. numPointLights: lights.point.length,
  10646. numSpotLights: lights.spot.length,
  10647. numRectAreaLights: lights.rectArea.length,
  10648. numHemiLights: lights.hemi.length,
  10649. numDirLightShadows: lights.directionalShadowMap.length,
  10650. numPointLightShadows: lights.pointShadowMap.length,
  10651. numSpotLightShadows: lights.spotShadowMap.length,
  10652. numClippingPlanes: clipping.numPlanes,
  10653. numClipIntersection: clipping.numIntersection,
  10654. dithering: material.dithering,
  10655. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  10656. shadowMapType: renderer.shadowMap.type,
  10657. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  10658. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10659. premultipliedAlpha: material.premultipliedAlpha,
  10660. alphaTest: material.alphaTest,
  10661. doubleSided: material.side === DoubleSide,
  10662. flipSided: material.side === BackSide,
  10663. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  10664. index0AttributeName: material.index0AttributeName,
  10665. extensionDerivatives: material.extensions && material.extensions.derivatives,
  10666. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  10667. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  10668. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  10669. rendererExtensionFragDepth: isWebGL2 || extensions.has( 'EXT_frag_depth' ),
  10670. rendererExtensionDrawBuffers: isWebGL2 || extensions.has( 'WEBGL_draw_buffers' ),
  10671. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has( 'EXT_shader_texture_lod' ),
  10672. customProgramCacheKey: material.customProgramCacheKey()
  10673. };
  10674. return parameters;
  10675. }
  10676. function getProgramCacheKey( parameters ) {
  10677. const array = [];
  10678. if ( parameters.shaderID ) {
  10679. array.push( parameters.shaderID );
  10680. } else {
  10681. array.push( parameters.fragmentShader );
  10682. array.push( parameters.vertexShader );
  10683. }
  10684. if ( parameters.defines !== undefined ) {
  10685. for ( const name in parameters.defines ) {
  10686. array.push( name );
  10687. array.push( parameters.defines[ name ] );
  10688. }
  10689. }
  10690. if ( parameters.isRawShaderMaterial === false ) {
  10691. for ( let i = 0; i < parameterNames.length; i ++ ) {
  10692. array.push( parameters[ parameterNames[ i ] ] );
  10693. }
  10694. array.push( renderer.outputEncoding );
  10695. array.push( renderer.gammaFactor );
  10696. }
  10697. array.push( parameters.customProgramCacheKey );
  10698. return array.join();
  10699. }
  10700. function getUniforms( material ) {
  10701. const shaderID = shaderIDs[ material.type ];
  10702. let uniforms;
  10703. if ( shaderID ) {
  10704. const shader = ShaderLib[ shaderID ];
  10705. uniforms = UniformsUtils.clone( shader.uniforms );
  10706. } else {
  10707. uniforms = material.uniforms;
  10708. }
  10709. return uniforms;
  10710. }
  10711. function acquireProgram( parameters, cacheKey ) {
  10712. let program;
  10713. // Check if code has been already compiled
  10714. for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
  10715. const preexistingProgram = programs[ p ];
  10716. if ( preexistingProgram.cacheKey === cacheKey ) {
  10717. program = preexistingProgram;
  10718. ++ program.usedTimes;
  10719. break;
  10720. }
  10721. }
  10722. if ( program === undefined ) {
  10723. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  10724. programs.push( program );
  10725. }
  10726. return program;
  10727. }
  10728. function releaseProgram( program ) {
  10729. if ( -- program.usedTimes === 0 ) {
  10730. // Remove from unordered set
  10731. const i = programs.indexOf( program );
  10732. programs[ i ] = programs[ programs.length - 1 ];
  10733. programs.pop();
  10734. // Free WebGL resources
  10735. program.destroy();
  10736. }
  10737. }
  10738. return {
  10739. getParameters: getParameters,
  10740. getProgramCacheKey: getProgramCacheKey,
  10741. getUniforms: getUniforms,
  10742. acquireProgram: acquireProgram,
  10743. releaseProgram: releaseProgram,
  10744. // Exposed for resource monitoring & error feedback via renderer.info:
  10745. programs: programs
  10746. };
  10747. }
  10748. function WebGLProperties() {
  10749. let properties = new WeakMap();
  10750. function get( object ) {
  10751. let map = properties.get( object );
  10752. if ( map === undefined ) {
  10753. map = {};
  10754. properties.set( object, map );
  10755. }
  10756. return map;
  10757. }
  10758. function remove( object ) {
  10759. properties.delete( object );
  10760. }
  10761. function update( object, key, value ) {
  10762. properties.get( object )[ key ] = value;
  10763. }
  10764. function dispose() {
  10765. properties = new WeakMap();
  10766. }
  10767. return {
  10768. get: get,
  10769. remove: remove,
  10770. update: update,
  10771. dispose: dispose
  10772. };
  10773. }
  10774. function painterSortStable( a, b ) {
  10775. if ( a.groupOrder !== b.groupOrder ) {
  10776. return a.groupOrder - b.groupOrder;
  10777. } else if ( a.renderOrder !== b.renderOrder ) {
  10778. return a.renderOrder - b.renderOrder;
  10779. } else if ( a.program !== b.program ) {
  10780. return a.program.id - b.program.id;
  10781. } else if ( a.material.id !== b.material.id ) {
  10782. return a.material.id - b.material.id;
  10783. } else if ( a.z !== b.z ) {
  10784. return a.z - b.z;
  10785. } else {
  10786. return a.id - b.id;
  10787. }
  10788. }
  10789. function reversePainterSortStable( a, b ) {
  10790. if ( a.groupOrder !== b.groupOrder ) {
  10791. return a.groupOrder - b.groupOrder;
  10792. } else if ( a.renderOrder !== b.renderOrder ) {
  10793. return a.renderOrder - b.renderOrder;
  10794. } else if ( a.z !== b.z ) {
  10795. return b.z - a.z;
  10796. } else {
  10797. return a.id - b.id;
  10798. }
  10799. }
  10800. function WebGLRenderList( properties ) {
  10801. const renderItems = [];
  10802. let renderItemsIndex = 0;
  10803. const opaque = [];
  10804. const transparent = [];
  10805. const defaultProgram = { id: - 1 };
  10806. function init() {
  10807. renderItemsIndex = 0;
  10808. opaque.length = 0;
  10809. transparent.length = 0;
  10810. }
  10811. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10812. let renderItem = renderItems[ renderItemsIndex ];
  10813. const materialProperties = properties.get( material );
  10814. if ( renderItem === undefined ) {
  10815. renderItem = {
  10816. id: object.id,
  10817. object: object,
  10818. geometry: geometry,
  10819. material: material,
  10820. program: materialProperties.program || defaultProgram,
  10821. groupOrder: groupOrder,
  10822. renderOrder: object.renderOrder,
  10823. z: z,
  10824. group: group
  10825. };
  10826. renderItems[ renderItemsIndex ] = renderItem;
  10827. } else {
  10828. renderItem.id = object.id;
  10829. renderItem.object = object;
  10830. renderItem.geometry = geometry;
  10831. renderItem.material = material;
  10832. renderItem.program = materialProperties.program || defaultProgram;
  10833. renderItem.groupOrder = groupOrder;
  10834. renderItem.renderOrder = object.renderOrder;
  10835. renderItem.z = z;
  10836. renderItem.group = group;
  10837. }
  10838. renderItemsIndex ++;
  10839. return renderItem;
  10840. }
  10841. function push( object, geometry, material, groupOrder, z, group ) {
  10842. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10843. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10844. }
  10845. function unshift( object, geometry, material, groupOrder, z, group ) {
  10846. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10847. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10848. }
  10849. function sort( customOpaqueSort, customTransparentSort ) {
  10850. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  10851. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  10852. }
  10853. function finish() {
  10854. // Clear references from inactive renderItems in the list
  10855. for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  10856. const renderItem = renderItems[ i ];
  10857. if ( renderItem.id === null ) break;
  10858. renderItem.id = null;
  10859. renderItem.object = null;
  10860. renderItem.geometry = null;
  10861. renderItem.material = null;
  10862. renderItem.program = null;
  10863. renderItem.group = null;
  10864. }
  10865. }
  10866. return {
  10867. opaque: opaque,
  10868. transparent: transparent,
  10869. init: init,
  10870. push: push,
  10871. unshift: unshift,
  10872. finish: finish,
  10873. sort: sort
  10874. };
  10875. }
  10876. function WebGLRenderLists( properties ) {
  10877. let lists = new WeakMap();
  10878. function get( scene, camera ) {
  10879. const cameras = lists.get( scene );
  10880. let list;
  10881. if ( cameras === undefined ) {
  10882. list = new WebGLRenderList( properties );
  10883. lists.set( scene, new WeakMap() );
  10884. lists.get( scene ).set( camera, list );
  10885. } else {
  10886. list = cameras.get( camera );
  10887. if ( list === undefined ) {
  10888. list = new WebGLRenderList( properties );
  10889. cameras.set( camera, list );
  10890. }
  10891. }
  10892. return list;
  10893. }
  10894. function dispose() {
  10895. lists = new WeakMap();
  10896. }
  10897. return {
  10898. get: get,
  10899. dispose: dispose
  10900. };
  10901. }
  10902. function UniformsCache() {
  10903. const lights = {};
  10904. return {
  10905. get: function ( light ) {
  10906. if ( lights[ light.id ] !== undefined ) {
  10907. return lights[ light.id ];
  10908. }
  10909. let uniforms;
  10910. switch ( light.type ) {
  10911. case 'DirectionalLight':
  10912. uniforms = {
  10913. direction: new Vector3(),
  10914. color: new Color()
  10915. };
  10916. break;
  10917. case 'SpotLight':
  10918. uniforms = {
  10919. position: new Vector3(),
  10920. direction: new Vector3(),
  10921. color: new Color(),
  10922. distance: 0,
  10923. coneCos: 0,
  10924. penumbraCos: 0,
  10925. decay: 0
  10926. };
  10927. break;
  10928. case 'PointLight':
  10929. uniforms = {
  10930. position: new Vector3(),
  10931. color: new Color(),
  10932. distance: 0,
  10933. decay: 0
  10934. };
  10935. break;
  10936. case 'HemisphereLight':
  10937. uniforms = {
  10938. direction: new Vector3(),
  10939. skyColor: new Color(),
  10940. groundColor: new Color()
  10941. };
  10942. break;
  10943. case 'RectAreaLight':
  10944. uniforms = {
  10945. color: new Color(),
  10946. position: new Vector3(),
  10947. halfWidth: new Vector3(),
  10948. halfHeight: new Vector3()
  10949. };
  10950. break;
  10951. }
  10952. lights[ light.id ] = uniforms;
  10953. return uniforms;
  10954. }
  10955. };
  10956. }
  10957. function ShadowUniformsCache() {
  10958. const lights = {};
  10959. return {
  10960. get: function ( light ) {
  10961. if ( lights[ light.id ] !== undefined ) {
  10962. return lights[ light.id ];
  10963. }
  10964. let uniforms;
  10965. switch ( light.type ) {
  10966. case 'DirectionalLight':
  10967. uniforms = {
  10968. shadowBias: 0,
  10969. shadowNormalBias: 0,
  10970. shadowRadius: 1,
  10971. shadowMapSize: new Vector2()
  10972. };
  10973. break;
  10974. case 'SpotLight':
  10975. uniforms = {
  10976. shadowBias: 0,
  10977. shadowNormalBias: 0,
  10978. shadowRadius: 1,
  10979. shadowMapSize: new Vector2()
  10980. };
  10981. break;
  10982. case 'PointLight':
  10983. uniforms = {
  10984. shadowBias: 0,
  10985. shadowNormalBias: 0,
  10986. shadowRadius: 1,
  10987. shadowMapSize: new Vector2(),
  10988. shadowCameraNear: 1,
  10989. shadowCameraFar: 1000
  10990. };
  10991. break;
  10992. // TODO (abelnation): set RectAreaLight shadow uniforms
  10993. }
  10994. lights[ light.id ] = uniforms;
  10995. return uniforms;
  10996. }
  10997. };
  10998. }
  10999. let nextVersion = 0;
  11000. function shadowCastingLightsFirst( lightA, lightB ) {
  11001. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11002. }
  11003. function WebGLLights( extensions, capabilities ) {
  11004. const cache = new UniformsCache();
  11005. const shadowCache = ShadowUniformsCache();
  11006. const state = {
  11007. version: 0,
  11008. hash: {
  11009. directionalLength: - 1,
  11010. pointLength: - 1,
  11011. spotLength: - 1,
  11012. rectAreaLength: - 1,
  11013. hemiLength: - 1,
  11014. numDirectionalShadows: - 1,
  11015. numPointShadows: - 1,
  11016. numSpotShadows: - 1
  11017. },
  11018. ambient: [ 0, 0, 0 ],
  11019. probe: [],
  11020. directional: [],
  11021. directionalShadow: [],
  11022. directionalShadowMap: [],
  11023. directionalShadowMatrix: [],
  11024. spot: [],
  11025. spotShadow: [],
  11026. spotShadowMap: [],
  11027. spotShadowMatrix: [],
  11028. rectArea: [],
  11029. rectAreaLTC1: null,
  11030. rectAreaLTC2: null,
  11031. point: [],
  11032. pointShadow: [],
  11033. pointShadowMap: [],
  11034. pointShadowMatrix: [],
  11035. hemi: []
  11036. };
  11037. for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11038. const vector3 = new Vector3();
  11039. const matrix4 = new Matrix4();
  11040. const matrix42 = new Matrix4();
  11041. function setup( lights ) {
  11042. let r = 0, g = 0, b = 0;
  11043. for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11044. let directionalLength = 0;
  11045. let pointLength = 0;
  11046. let spotLength = 0;
  11047. let rectAreaLength = 0;
  11048. let hemiLength = 0;
  11049. let numDirectionalShadows = 0;
  11050. let numPointShadows = 0;
  11051. let numSpotShadows = 0;
  11052. lights.sort( shadowCastingLightsFirst );
  11053. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11054. const light = lights[ i ];
  11055. const color = light.color;
  11056. const intensity = light.intensity;
  11057. const distance = light.distance;
  11058. const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11059. if ( light.isAmbientLight ) {
  11060. r += color.r * intensity;
  11061. g += color.g * intensity;
  11062. b += color.b * intensity;
  11063. } else if ( light.isLightProbe ) {
  11064. for ( let j = 0; j < 9; j ++ ) {
  11065. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11066. }
  11067. } else if ( light.isDirectionalLight ) {
  11068. const uniforms = cache.get( light );
  11069. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11070. if ( light.castShadow ) {
  11071. const shadow = light.shadow;
  11072. const shadowUniforms = shadowCache.get( light );
  11073. shadowUniforms.shadowBias = shadow.bias;
  11074. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11075. shadowUniforms.shadowRadius = shadow.radius;
  11076. shadowUniforms.shadowMapSize = shadow.mapSize;
  11077. state.directionalShadow[ directionalLength ] = shadowUniforms;
  11078. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11079. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11080. numDirectionalShadows ++;
  11081. }
  11082. state.directional[ directionalLength ] = uniforms;
  11083. directionalLength ++;
  11084. } else if ( light.isSpotLight ) {
  11085. const uniforms = cache.get( light );
  11086. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11087. uniforms.color.copy( color ).multiplyScalar( intensity );
  11088. uniforms.distance = distance;
  11089. uniforms.coneCos = Math.cos( light.angle );
  11090. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11091. uniforms.decay = light.decay;
  11092. if ( light.castShadow ) {
  11093. const shadow = light.shadow;
  11094. const shadowUniforms = shadowCache.get( light );
  11095. shadowUniforms.shadowBias = shadow.bias;
  11096. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11097. shadowUniforms.shadowRadius = shadow.radius;
  11098. shadowUniforms.shadowMapSize = shadow.mapSize;
  11099. state.spotShadow[ spotLength ] = shadowUniforms;
  11100. state.spotShadowMap[ spotLength ] = shadowMap;
  11101. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11102. numSpotShadows ++;
  11103. }
  11104. state.spot[ spotLength ] = uniforms;
  11105. spotLength ++;
  11106. } else if ( light.isRectAreaLight ) {
  11107. const uniforms = cache.get( light );
  11108. // (a) intensity is the total visible light emitted
  11109. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11110. // (b) intensity is the brightness of the light
  11111. uniforms.color.copy( color ).multiplyScalar( intensity );
  11112. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11113. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11114. state.rectArea[ rectAreaLength ] = uniforms;
  11115. rectAreaLength ++;
  11116. } else if ( light.isPointLight ) {
  11117. const uniforms = cache.get( light );
  11118. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11119. uniforms.distance = light.distance;
  11120. uniforms.decay = light.decay;
  11121. if ( light.castShadow ) {
  11122. const shadow = light.shadow;
  11123. const shadowUniforms = shadowCache.get( light );
  11124. shadowUniforms.shadowBias = shadow.bias;
  11125. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11126. shadowUniforms.shadowRadius = shadow.radius;
  11127. shadowUniforms.shadowMapSize = shadow.mapSize;
  11128. shadowUniforms.shadowCameraNear = shadow.camera.near;
  11129. shadowUniforms.shadowCameraFar = shadow.camera.far;
  11130. state.pointShadow[ pointLength ] = shadowUniforms;
  11131. state.pointShadowMap[ pointLength ] = shadowMap;
  11132. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11133. numPointShadows ++;
  11134. }
  11135. state.point[ pointLength ] = uniforms;
  11136. pointLength ++;
  11137. } else if ( light.isHemisphereLight ) {
  11138. const uniforms = cache.get( light );
  11139. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11140. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11141. state.hemi[ hemiLength ] = uniforms;
  11142. hemiLength ++;
  11143. }
  11144. }
  11145. if ( rectAreaLength > 0 ) {
  11146. if ( capabilities.isWebGL2 ) {
  11147. // WebGL 2
  11148. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11149. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11150. } else {
  11151. // WebGL 1
  11152. if ( extensions.has( 'OES_texture_float_linear' ) === true ) {
  11153. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11154. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11155. } else if ( extensions.has( 'OES_texture_half_float_linear' ) === true ) {
  11156. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11157. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11158. } else {
  11159. console.error( 'THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.' );
  11160. }
  11161. }
  11162. }
  11163. state.ambient[ 0 ] = r;
  11164. state.ambient[ 1 ] = g;
  11165. state.ambient[ 2 ] = b;
  11166. const hash = state.hash;
  11167. if ( hash.directionalLength !== directionalLength ||
  11168. hash.pointLength !== pointLength ||
  11169. hash.spotLength !== spotLength ||
  11170. hash.rectAreaLength !== rectAreaLength ||
  11171. hash.hemiLength !== hemiLength ||
  11172. hash.numDirectionalShadows !== numDirectionalShadows ||
  11173. hash.numPointShadows !== numPointShadows ||
  11174. hash.numSpotShadows !== numSpotShadows ) {
  11175. state.directional.length = directionalLength;
  11176. state.spot.length = spotLength;
  11177. state.rectArea.length = rectAreaLength;
  11178. state.point.length = pointLength;
  11179. state.hemi.length = hemiLength;
  11180. state.directionalShadow.length = numDirectionalShadows;
  11181. state.directionalShadowMap.length = numDirectionalShadows;
  11182. state.pointShadow.length = numPointShadows;
  11183. state.pointShadowMap.length = numPointShadows;
  11184. state.spotShadow.length = numSpotShadows;
  11185. state.spotShadowMap.length = numSpotShadows;
  11186. state.directionalShadowMatrix.length = numDirectionalShadows;
  11187. state.pointShadowMatrix.length = numPointShadows;
  11188. state.spotShadowMatrix.length = numSpotShadows;
  11189. hash.directionalLength = directionalLength;
  11190. hash.pointLength = pointLength;
  11191. hash.spotLength = spotLength;
  11192. hash.rectAreaLength = rectAreaLength;
  11193. hash.hemiLength = hemiLength;
  11194. hash.numDirectionalShadows = numDirectionalShadows;
  11195. hash.numPointShadows = numPointShadows;
  11196. hash.numSpotShadows = numSpotShadows;
  11197. state.version = nextVersion ++;
  11198. }
  11199. }
  11200. function setupView( lights, camera ) {
  11201. let directionalLength = 0;
  11202. let pointLength = 0;
  11203. let spotLength = 0;
  11204. let rectAreaLength = 0;
  11205. let hemiLength = 0;
  11206. const viewMatrix = camera.matrixWorldInverse;
  11207. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11208. const light = lights[ i ];
  11209. if ( light.isDirectionalLight ) {
  11210. const uniforms = state.directional[ directionalLength ];
  11211. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11212. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11213. uniforms.direction.sub( vector3 );
  11214. uniforms.direction.transformDirection( viewMatrix );
  11215. directionalLength ++;
  11216. } else if ( light.isSpotLight ) {
  11217. const uniforms = state.spot[ spotLength ];
  11218. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11219. uniforms.position.applyMatrix4( viewMatrix );
  11220. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11221. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11222. uniforms.direction.sub( vector3 );
  11223. uniforms.direction.transformDirection( viewMatrix );
  11224. spotLength ++;
  11225. } else if ( light.isRectAreaLight ) {
  11226. const uniforms = state.rectArea[ rectAreaLength ];
  11227. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11228. uniforms.position.applyMatrix4( viewMatrix );
  11229. // extract local rotation of light to derive width/height half vectors
  11230. matrix42.identity();
  11231. matrix4.copy( light.matrixWorld );
  11232. matrix4.premultiply( viewMatrix );
  11233. matrix42.extractRotation( matrix4 );
  11234. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11235. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11236. uniforms.halfWidth.applyMatrix4( matrix42 );
  11237. uniforms.halfHeight.applyMatrix4( matrix42 );
  11238. rectAreaLength ++;
  11239. } else if ( light.isPointLight ) {
  11240. const uniforms = state.point[ pointLength ];
  11241. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11242. uniforms.position.applyMatrix4( viewMatrix );
  11243. pointLength ++;
  11244. } else if ( light.isHemisphereLight ) {
  11245. const uniforms = state.hemi[ hemiLength ];
  11246. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11247. uniforms.direction.transformDirection( viewMatrix );
  11248. uniforms.direction.normalize();
  11249. hemiLength ++;
  11250. }
  11251. }
  11252. }
  11253. return {
  11254. setup: setup,
  11255. setupView: setupView,
  11256. state: state
  11257. };
  11258. }
  11259. function WebGLRenderState( extensions, capabilities ) {
  11260. const lights = new WebGLLights( extensions, capabilities );
  11261. const lightsArray = [];
  11262. const shadowsArray = [];
  11263. function init() {
  11264. lightsArray.length = 0;
  11265. shadowsArray.length = 0;
  11266. }
  11267. function pushLight( light ) {
  11268. lightsArray.push( light );
  11269. }
  11270. function pushShadow( shadowLight ) {
  11271. shadowsArray.push( shadowLight );
  11272. }
  11273. function setupLights() {
  11274. lights.setup( lightsArray );
  11275. }
  11276. function setupLightsView( camera ) {
  11277. lights.setupView( lightsArray, camera );
  11278. }
  11279. const state = {
  11280. lightsArray: lightsArray,
  11281. shadowsArray: shadowsArray,
  11282. lights: lights
  11283. };
  11284. return {
  11285. init: init,
  11286. state: state,
  11287. setupLights: setupLights,
  11288. setupLightsView: setupLightsView,
  11289. pushLight: pushLight,
  11290. pushShadow: pushShadow
  11291. };
  11292. }
  11293. function WebGLRenderStates( extensions, capabilities ) {
  11294. let renderStates = new WeakMap();
  11295. function get( scene, renderCallDepth = 0 ) {
  11296. let renderState;
  11297. if ( renderStates.has( scene ) === false ) {
  11298. renderState = new WebGLRenderState( extensions, capabilities );
  11299. renderStates.set( scene, [] );
  11300. renderStates.get( scene ).push( renderState );
  11301. } else {
  11302. if ( renderCallDepth >= renderStates.get( scene ).length ) {
  11303. renderState = new WebGLRenderState( extensions, capabilities );
  11304. renderStates.get( scene ).push( renderState );
  11305. } else {
  11306. renderState = renderStates.get( scene )[ renderCallDepth ];
  11307. }
  11308. }
  11309. return renderState;
  11310. }
  11311. function dispose() {
  11312. renderStates = new WeakMap();
  11313. }
  11314. return {
  11315. get: get,
  11316. dispose: dispose
  11317. };
  11318. }
  11319. /**
  11320. * parameters = {
  11321. *
  11322. * opacity: <float>,
  11323. *
  11324. * map: new THREE.Texture( <Image> ),
  11325. *
  11326. * alphaMap: new THREE.Texture( <Image> ),
  11327. *
  11328. * displacementMap: new THREE.Texture( <Image> ),
  11329. * displacementScale: <float>,
  11330. * displacementBias: <float>,
  11331. *
  11332. * wireframe: <boolean>,
  11333. * wireframeLinewidth: <float>
  11334. * }
  11335. */
  11336. function MeshDepthMaterial( parameters ) {
  11337. Material.call( this );
  11338. this.type = 'MeshDepthMaterial';
  11339. this.depthPacking = BasicDepthPacking;
  11340. this.skinning = false;
  11341. this.morphTargets = false;
  11342. this.map = null;
  11343. this.alphaMap = null;
  11344. this.displacementMap = null;
  11345. this.displacementScale = 1;
  11346. this.displacementBias = 0;
  11347. this.wireframe = false;
  11348. this.wireframeLinewidth = 1;
  11349. this.fog = false;
  11350. this.setValues( parameters );
  11351. }
  11352. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11353. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11354. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11355. MeshDepthMaterial.prototype.copy = function ( source ) {
  11356. Material.prototype.copy.call( this, source );
  11357. this.depthPacking = source.depthPacking;
  11358. this.skinning = source.skinning;
  11359. this.morphTargets = source.morphTargets;
  11360. this.map = source.map;
  11361. this.alphaMap = source.alphaMap;
  11362. this.displacementMap = source.displacementMap;
  11363. this.displacementScale = source.displacementScale;
  11364. this.displacementBias = source.displacementBias;
  11365. this.wireframe = source.wireframe;
  11366. this.wireframeLinewidth = source.wireframeLinewidth;
  11367. return this;
  11368. };
  11369. /**
  11370. * parameters = {
  11371. *
  11372. * referencePosition: <float>,
  11373. * nearDistance: <float>,
  11374. * farDistance: <float>,
  11375. *
  11376. * skinning: <bool>,
  11377. * morphTargets: <bool>,
  11378. *
  11379. * map: new THREE.Texture( <Image> ),
  11380. *
  11381. * alphaMap: new THREE.Texture( <Image> ),
  11382. *
  11383. * displacementMap: new THREE.Texture( <Image> ),
  11384. * displacementScale: <float>,
  11385. * displacementBias: <float>
  11386. *
  11387. * }
  11388. */
  11389. function MeshDistanceMaterial( parameters ) {
  11390. Material.call( this );
  11391. this.type = 'MeshDistanceMaterial';
  11392. this.referencePosition = new Vector3();
  11393. this.nearDistance = 1;
  11394. this.farDistance = 1000;
  11395. this.skinning = false;
  11396. this.morphTargets = false;
  11397. this.map = null;
  11398. this.alphaMap = null;
  11399. this.displacementMap = null;
  11400. this.displacementScale = 1;
  11401. this.displacementBias = 0;
  11402. this.fog = false;
  11403. this.setValues( parameters );
  11404. }
  11405. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11406. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11407. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11408. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11409. Material.prototype.copy.call( this, source );
  11410. this.referencePosition.copy( source.referencePosition );
  11411. this.nearDistance = source.nearDistance;
  11412. this.farDistance = source.farDistance;
  11413. this.skinning = source.skinning;
  11414. this.morphTargets = source.morphTargets;
  11415. this.map = source.map;
  11416. this.alphaMap = source.alphaMap;
  11417. this.displacementMap = source.displacementMap;
  11418. this.displacementScale = source.displacementScale;
  11419. this.displacementBias = source.displacementBias;
  11420. return this;
  11421. };
  11422. 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}";
  11423. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11424. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11425. let _frustum = new Frustum();
  11426. const _shadowMapSize = new Vector2(),
  11427. _viewportSize = new Vector2(),
  11428. _viewport = new Vector4(),
  11429. _depthMaterials = [],
  11430. _distanceMaterials = [],
  11431. _materialCache = {};
  11432. const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11433. const shadowMaterialVertical = new ShaderMaterial( {
  11434. defines: {
  11435. SAMPLE_RATE: 2.0 / 8.0,
  11436. HALF_SAMPLE_RATE: 1.0 / 8.0
  11437. },
  11438. uniforms: {
  11439. shadow_pass: { value: null },
  11440. resolution: { value: new Vector2() },
  11441. radius: { value: 4.0 }
  11442. },
  11443. vertexShader: vsm_vert,
  11444. fragmentShader: vsm_frag
  11445. } );
  11446. const shadowMaterialHorizontal = shadowMaterialVertical.clone();
  11447. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  11448. const fullScreenTri = new BufferGeometry();
  11449. fullScreenTri.setAttribute(
  11450. 'position',
  11451. new BufferAttribute(
  11452. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  11453. 3
  11454. )
  11455. );
  11456. const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  11457. const scope = this;
  11458. this.enabled = false;
  11459. this.autoUpdate = true;
  11460. this.needsUpdate = false;
  11461. this.type = PCFShadowMap;
  11462. this.render = function ( lights, scene, camera ) {
  11463. if ( scope.enabled === false ) return;
  11464. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11465. if ( lights.length === 0 ) return;
  11466. const currentRenderTarget = _renderer.getRenderTarget();
  11467. const activeCubeFace = _renderer.getActiveCubeFace();
  11468. const activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11469. const _state = _renderer.state;
  11470. // Set GL state for depth map.
  11471. _state.setBlending( NoBlending );
  11472. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11473. _state.buffers.depth.setTest( true );
  11474. _state.setScissorTest( false );
  11475. // render depth map
  11476. for ( let i = 0, il = lights.length; i < il; i ++ ) {
  11477. const light = lights[ i ];
  11478. const shadow = light.shadow;
  11479. if ( shadow === undefined ) {
  11480. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11481. continue;
  11482. }
  11483. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;
  11484. _shadowMapSize.copy( shadow.mapSize );
  11485. const shadowFrameExtents = shadow.getFrameExtents();
  11486. _shadowMapSize.multiply( shadowFrameExtents );
  11487. _viewportSize.copy( shadow.mapSize );
  11488. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  11489. if ( _shadowMapSize.x > maxTextureSize ) {
  11490. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  11491. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11492. shadow.mapSize.x = _viewportSize.x;
  11493. }
  11494. if ( _shadowMapSize.y > maxTextureSize ) {
  11495. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  11496. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11497. shadow.mapSize.y = _viewportSize.y;
  11498. }
  11499. }
  11500. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11501. const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  11502. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11503. shadow.map.texture.name = light.name + '.shadowMap';
  11504. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11505. shadow.camera.updateProjectionMatrix();
  11506. }
  11507. if ( shadow.map === null ) {
  11508. const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11509. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11510. shadow.map.texture.name = light.name + '.shadowMap';
  11511. shadow.camera.updateProjectionMatrix();
  11512. }
  11513. _renderer.setRenderTarget( shadow.map );
  11514. _renderer.clear();
  11515. const viewportCount = shadow.getViewportCount();
  11516. for ( let vp = 0; vp < viewportCount; vp ++ ) {
  11517. const viewport = shadow.getViewport( vp );
  11518. _viewport.set(
  11519. _viewportSize.x * viewport.x,
  11520. _viewportSize.y * viewport.y,
  11521. _viewportSize.x * viewport.z,
  11522. _viewportSize.y * viewport.w
  11523. );
  11524. _state.viewport( _viewport );
  11525. shadow.updateMatrices( light, vp );
  11526. _frustum = shadow.getFrustum();
  11527. renderObject( scene, camera, shadow.camera, light, this.type );
  11528. }
  11529. // do blur pass for VSM
  11530. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11531. VSMPass( shadow, camera );
  11532. }
  11533. shadow.needsUpdate = false;
  11534. }
  11535. scope.needsUpdate = false;
  11536. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11537. };
  11538. function VSMPass( shadow, camera ) {
  11539. const geometry = _objects.update( fullScreenMesh );
  11540. // vertical pass
  11541. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11542. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11543. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11544. _renderer.setRenderTarget( shadow.mapPass );
  11545. _renderer.clear();
  11546. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  11547. // horizontal pass
  11548. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11549. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  11550. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  11551. _renderer.setRenderTarget( shadow.map );
  11552. _renderer.clear();
  11553. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );
  11554. }
  11555. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11556. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11557. let material = _depthMaterials[ index ];
  11558. if ( material === undefined ) {
  11559. material = new MeshDepthMaterial( {
  11560. depthPacking: RGBADepthPacking,
  11561. morphTargets: useMorphing,
  11562. skinning: useSkinning
  11563. } );
  11564. _depthMaterials[ index ] = material;
  11565. }
  11566. return material;
  11567. }
  11568. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11569. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11570. let material = _distanceMaterials[ index ];
  11571. if ( material === undefined ) {
  11572. material = new MeshDistanceMaterial( {
  11573. morphTargets: useMorphing,
  11574. skinning: useSkinning
  11575. } );
  11576. _distanceMaterials[ index ] = material;
  11577. }
  11578. return material;
  11579. }
  11580. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  11581. let result = null;
  11582. let getMaterialVariant = getDepthMaterialVariant;
  11583. let customMaterial = object.customDepthMaterial;
  11584. if ( light.isPointLight === true ) {
  11585. getMaterialVariant = getDistanceMaterialVariant;
  11586. customMaterial = object.customDistanceMaterial;
  11587. }
  11588. if ( customMaterial === undefined ) {
  11589. let useMorphing = false;
  11590. if ( material.morphTargets === true ) {
  11591. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11592. }
  11593. let useSkinning = false;
  11594. if ( object.isSkinnedMesh === true ) {
  11595. if ( material.skinning === true ) {
  11596. useSkinning = true;
  11597. } else {
  11598. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11599. }
  11600. }
  11601. const useInstancing = object.isInstancedMesh === true;
  11602. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  11603. } else {
  11604. result = customMaterial;
  11605. }
  11606. if ( _renderer.localClippingEnabled &&
  11607. material.clipShadows === true &&
  11608. material.clippingPlanes.length !== 0 ) {
  11609. // in this case we need a unique material instance reflecting the
  11610. // appropriate state
  11611. const keyA = result.uuid, keyB = material.uuid;
  11612. let materialsForVariant = _materialCache[ keyA ];
  11613. if ( materialsForVariant === undefined ) {
  11614. materialsForVariant = {};
  11615. _materialCache[ keyA ] = materialsForVariant;
  11616. }
  11617. let cachedMaterial = materialsForVariant[ keyB ];
  11618. if ( cachedMaterial === undefined ) {
  11619. cachedMaterial = result.clone();
  11620. materialsForVariant[ keyB ] = cachedMaterial;
  11621. }
  11622. result = cachedMaterial;
  11623. }
  11624. result.visible = material.visible;
  11625. result.wireframe = material.wireframe;
  11626. if ( type === VSMShadowMap ) {
  11627. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  11628. } else {
  11629. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  11630. }
  11631. result.clipShadows = material.clipShadows;
  11632. result.clippingPlanes = material.clippingPlanes;
  11633. result.clipIntersection = material.clipIntersection;
  11634. result.wireframeLinewidth = material.wireframeLinewidth;
  11635. result.linewidth = material.linewidth;
  11636. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  11637. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  11638. result.nearDistance = shadowCameraNear;
  11639. result.farDistance = shadowCameraFar;
  11640. }
  11641. return result;
  11642. }
  11643. function renderObject( object, camera, shadowCamera, light, type ) {
  11644. if ( object.visible === false ) return;
  11645. const visible = object.layers.test( camera.layers );
  11646. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11647. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11648. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11649. const geometry = _objects.update( object );
  11650. const material = object.material;
  11651. if ( Array.isArray( material ) ) {
  11652. const groups = geometry.groups;
  11653. for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
  11654. const group = groups[ k ];
  11655. const groupMaterial = material[ group.materialIndex ];
  11656. if ( groupMaterial && groupMaterial.visible ) {
  11657. const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  11658. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11659. }
  11660. }
  11661. } else if ( material.visible ) {
  11662. const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  11663. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11664. }
  11665. }
  11666. }
  11667. const children = object.children;
  11668. for ( let i = 0, l = children.length; i < l; i ++ ) {
  11669. renderObject( children[ i ], camera, shadowCamera, light, type );
  11670. }
  11671. }
  11672. }
  11673. function WebGLState( gl, extensions, capabilities ) {
  11674. const isWebGL2 = capabilities.isWebGL2;
  11675. function ColorBuffer() {
  11676. let locked = false;
  11677. const color = new Vector4();
  11678. let currentColorMask = null;
  11679. const currentColorClear = new Vector4( 0, 0, 0, 0 );
  11680. return {
  11681. setMask: function ( colorMask ) {
  11682. if ( currentColorMask !== colorMask && ! locked ) {
  11683. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11684. currentColorMask = colorMask;
  11685. }
  11686. },
  11687. setLocked: function ( lock ) {
  11688. locked = lock;
  11689. },
  11690. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11691. if ( premultipliedAlpha === true ) {
  11692. r *= a; g *= a; b *= a;
  11693. }
  11694. color.set( r, g, b, a );
  11695. if ( currentColorClear.equals( color ) === false ) {
  11696. gl.clearColor( r, g, b, a );
  11697. currentColorClear.copy( color );
  11698. }
  11699. },
  11700. reset: function () {
  11701. locked = false;
  11702. currentColorMask = null;
  11703. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11704. }
  11705. };
  11706. }
  11707. function DepthBuffer() {
  11708. let locked = false;
  11709. let currentDepthMask = null;
  11710. let currentDepthFunc = null;
  11711. let currentDepthClear = null;
  11712. return {
  11713. setTest: function ( depthTest ) {
  11714. if ( depthTest ) {
  11715. enable( 2929 );
  11716. } else {
  11717. disable( 2929 );
  11718. }
  11719. },
  11720. setMask: function ( depthMask ) {
  11721. if ( currentDepthMask !== depthMask && ! locked ) {
  11722. gl.depthMask( depthMask );
  11723. currentDepthMask = depthMask;
  11724. }
  11725. },
  11726. setFunc: function ( depthFunc ) {
  11727. if ( currentDepthFunc !== depthFunc ) {
  11728. if ( depthFunc ) {
  11729. switch ( depthFunc ) {
  11730. case NeverDepth:
  11731. gl.depthFunc( 512 );
  11732. break;
  11733. case AlwaysDepth:
  11734. gl.depthFunc( 519 );
  11735. break;
  11736. case LessDepth:
  11737. gl.depthFunc( 513 );
  11738. break;
  11739. case LessEqualDepth:
  11740. gl.depthFunc( 515 );
  11741. break;
  11742. case EqualDepth:
  11743. gl.depthFunc( 514 );
  11744. break;
  11745. case GreaterEqualDepth:
  11746. gl.depthFunc( 518 );
  11747. break;
  11748. case GreaterDepth:
  11749. gl.depthFunc( 516 );
  11750. break;
  11751. case NotEqualDepth:
  11752. gl.depthFunc( 517 );
  11753. break;
  11754. default:
  11755. gl.depthFunc( 515 );
  11756. }
  11757. } else {
  11758. gl.depthFunc( 515 );
  11759. }
  11760. currentDepthFunc = depthFunc;
  11761. }
  11762. },
  11763. setLocked: function ( lock ) {
  11764. locked = lock;
  11765. },
  11766. setClear: function ( depth ) {
  11767. if ( currentDepthClear !== depth ) {
  11768. gl.clearDepth( depth );
  11769. currentDepthClear = depth;
  11770. }
  11771. },
  11772. reset: function () {
  11773. locked = false;
  11774. currentDepthMask = null;
  11775. currentDepthFunc = null;
  11776. currentDepthClear = null;
  11777. }
  11778. };
  11779. }
  11780. function StencilBuffer() {
  11781. let locked = false;
  11782. let currentStencilMask = null;
  11783. let currentStencilFunc = null;
  11784. let currentStencilRef = null;
  11785. let currentStencilFuncMask = null;
  11786. let currentStencilFail = null;
  11787. let currentStencilZFail = null;
  11788. let currentStencilZPass = null;
  11789. let currentStencilClear = null;
  11790. return {
  11791. setTest: function ( stencilTest ) {
  11792. if ( ! locked ) {
  11793. if ( stencilTest ) {
  11794. enable( 2960 );
  11795. } else {
  11796. disable( 2960 );
  11797. }
  11798. }
  11799. },
  11800. setMask: function ( stencilMask ) {
  11801. if ( currentStencilMask !== stencilMask && ! locked ) {
  11802. gl.stencilMask( stencilMask );
  11803. currentStencilMask = stencilMask;
  11804. }
  11805. },
  11806. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11807. if ( currentStencilFunc !== stencilFunc ||
  11808. currentStencilRef !== stencilRef ||
  11809. currentStencilFuncMask !== stencilMask ) {
  11810. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11811. currentStencilFunc = stencilFunc;
  11812. currentStencilRef = stencilRef;
  11813. currentStencilFuncMask = stencilMask;
  11814. }
  11815. },
  11816. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11817. if ( currentStencilFail !== stencilFail ||
  11818. currentStencilZFail !== stencilZFail ||
  11819. currentStencilZPass !== stencilZPass ) {
  11820. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11821. currentStencilFail = stencilFail;
  11822. currentStencilZFail = stencilZFail;
  11823. currentStencilZPass = stencilZPass;
  11824. }
  11825. },
  11826. setLocked: function ( lock ) {
  11827. locked = lock;
  11828. },
  11829. setClear: function ( stencil ) {
  11830. if ( currentStencilClear !== stencil ) {
  11831. gl.clearStencil( stencil );
  11832. currentStencilClear = stencil;
  11833. }
  11834. },
  11835. reset: function () {
  11836. locked = false;
  11837. currentStencilMask = null;
  11838. currentStencilFunc = null;
  11839. currentStencilRef = null;
  11840. currentStencilFuncMask = null;
  11841. currentStencilFail = null;
  11842. currentStencilZFail = null;
  11843. currentStencilZPass = null;
  11844. currentStencilClear = null;
  11845. }
  11846. };
  11847. }
  11848. //
  11849. const colorBuffer = new ColorBuffer();
  11850. const depthBuffer = new DepthBuffer();
  11851. const stencilBuffer = new StencilBuffer();
  11852. let enabledCapabilities = {};
  11853. let currentProgram = null;
  11854. let currentBlendingEnabled = null;
  11855. let currentBlending = null;
  11856. let currentBlendEquation = null;
  11857. let currentBlendSrc = null;
  11858. let currentBlendDst = null;
  11859. let currentBlendEquationAlpha = null;
  11860. let currentBlendSrcAlpha = null;
  11861. let currentBlendDstAlpha = null;
  11862. let currentPremultipledAlpha = false;
  11863. let currentFlipSided = null;
  11864. let currentCullFace = null;
  11865. let currentLineWidth = null;
  11866. let currentPolygonOffsetFactor = null;
  11867. let currentPolygonOffsetUnits = null;
  11868. const maxTextures = gl.getParameter( 35661 );
  11869. let lineWidthAvailable = false;
  11870. let version = 0;
  11871. const glVersion = gl.getParameter( 7938 );
  11872. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11873. version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] );
  11874. lineWidthAvailable = ( version >= 1.0 );
  11875. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11876. version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] );
  11877. lineWidthAvailable = ( version >= 2.0 );
  11878. }
  11879. let currentTextureSlot = null;
  11880. let currentBoundTextures = {};
  11881. const currentScissor = new Vector4();
  11882. const currentViewport = new Vector4();
  11883. function createTexture( type, target, count ) {
  11884. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11885. const texture = gl.createTexture();
  11886. gl.bindTexture( type, texture );
  11887. gl.texParameteri( type, 10241, 9728 );
  11888. gl.texParameteri( type, 10240, 9728 );
  11889. for ( let i = 0; i < count; i ++ ) {
  11890. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11891. }
  11892. return texture;
  11893. }
  11894. const emptyTextures = {};
  11895. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11896. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11897. // init
  11898. colorBuffer.setClear( 0, 0, 0, 1 );
  11899. depthBuffer.setClear( 1 );
  11900. stencilBuffer.setClear( 0 );
  11901. enable( 2929 );
  11902. depthBuffer.setFunc( LessEqualDepth );
  11903. setFlipSided( false );
  11904. setCullFace( CullFaceBack );
  11905. enable( 2884 );
  11906. setBlending( NoBlending );
  11907. //
  11908. function enable( id ) {
  11909. if ( enabledCapabilities[ id ] !== true ) {
  11910. gl.enable( id );
  11911. enabledCapabilities[ id ] = true;
  11912. }
  11913. }
  11914. function disable( id ) {
  11915. if ( enabledCapabilities[ id ] !== false ) {
  11916. gl.disable( id );
  11917. enabledCapabilities[ id ] = false;
  11918. }
  11919. }
  11920. function useProgram( program ) {
  11921. if ( currentProgram !== program ) {
  11922. gl.useProgram( program );
  11923. currentProgram = program;
  11924. return true;
  11925. }
  11926. return false;
  11927. }
  11928. const equationToGL = {
  11929. [ AddEquation ]: 32774,
  11930. [ SubtractEquation ]: 32778,
  11931. [ ReverseSubtractEquation ]: 32779
  11932. };
  11933. if ( isWebGL2 ) {
  11934. equationToGL[ MinEquation ] = 32775;
  11935. equationToGL[ MaxEquation ] = 32776;
  11936. } else {
  11937. const extension = extensions.get( 'EXT_blend_minmax' );
  11938. if ( extension !== null ) {
  11939. equationToGL[ MinEquation ] = extension.MIN_EXT;
  11940. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  11941. }
  11942. }
  11943. const factorToGL = {
  11944. [ ZeroFactor ]: 0,
  11945. [ OneFactor ]: 1,
  11946. [ SrcColorFactor ]: 768,
  11947. [ SrcAlphaFactor ]: 770,
  11948. [ SrcAlphaSaturateFactor ]: 776,
  11949. [ DstColorFactor ]: 774,
  11950. [ DstAlphaFactor ]: 772,
  11951. [ OneMinusSrcColorFactor ]: 769,
  11952. [ OneMinusSrcAlphaFactor ]: 771,
  11953. [ OneMinusDstColorFactor ]: 775,
  11954. [ OneMinusDstAlphaFactor ]: 773
  11955. };
  11956. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11957. if ( blending === NoBlending ) {
  11958. if ( currentBlendingEnabled ) {
  11959. disable( 3042 );
  11960. currentBlendingEnabled = false;
  11961. }
  11962. return;
  11963. }
  11964. if ( ! currentBlendingEnabled ) {
  11965. enable( 3042 );
  11966. currentBlendingEnabled = true;
  11967. }
  11968. if ( blending !== CustomBlending ) {
  11969. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11970. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11971. gl.blendEquation( 32774 );
  11972. currentBlendEquation = AddEquation;
  11973. currentBlendEquationAlpha = AddEquation;
  11974. }
  11975. if ( premultipliedAlpha ) {
  11976. switch ( blending ) {
  11977. case NormalBlending:
  11978. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11979. break;
  11980. case AdditiveBlending:
  11981. gl.blendFunc( 1, 1 );
  11982. break;
  11983. case SubtractiveBlending:
  11984. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11985. break;
  11986. case MultiplyBlending:
  11987. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11988. break;
  11989. default:
  11990. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11991. break;
  11992. }
  11993. } else {
  11994. switch ( blending ) {
  11995. case NormalBlending:
  11996. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11997. break;
  11998. case AdditiveBlending:
  11999. gl.blendFunc( 770, 1 );
  12000. break;
  12001. case SubtractiveBlending:
  12002. gl.blendFunc( 0, 769 );
  12003. break;
  12004. case MultiplyBlending:
  12005. gl.blendFunc( 0, 768 );
  12006. break;
  12007. default:
  12008. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12009. break;
  12010. }
  12011. }
  12012. currentBlendSrc = null;
  12013. currentBlendDst = null;
  12014. currentBlendSrcAlpha = null;
  12015. currentBlendDstAlpha = null;
  12016. currentBlending = blending;
  12017. currentPremultipledAlpha = premultipliedAlpha;
  12018. }
  12019. return;
  12020. }
  12021. // custom blending
  12022. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12023. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12024. blendDstAlpha = blendDstAlpha || blendDst;
  12025. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12026. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12027. currentBlendEquation = blendEquation;
  12028. currentBlendEquationAlpha = blendEquationAlpha;
  12029. }
  12030. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12031. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  12032. currentBlendSrc = blendSrc;
  12033. currentBlendDst = blendDst;
  12034. currentBlendSrcAlpha = blendSrcAlpha;
  12035. currentBlendDstAlpha = blendDstAlpha;
  12036. }
  12037. currentBlending = blending;
  12038. currentPremultipledAlpha = null;
  12039. }
  12040. function setMaterial( material, frontFaceCW ) {
  12041. material.side === DoubleSide
  12042. ? disable( 2884 )
  12043. : enable( 2884 );
  12044. let flipSided = ( material.side === BackSide );
  12045. if ( frontFaceCW ) flipSided = ! flipSided;
  12046. setFlipSided( flipSided );
  12047. ( material.blending === NormalBlending && material.transparent === false )
  12048. ? setBlending( NoBlending )
  12049. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12050. depthBuffer.setFunc( material.depthFunc );
  12051. depthBuffer.setTest( material.depthTest );
  12052. depthBuffer.setMask( material.depthWrite );
  12053. colorBuffer.setMask( material.colorWrite );
  12054. const stencilWrite = material.stencilWrite;
  12055. stencilBuffer.setTest( stencilWrite );
  12056. if ( stencilWrite ) {
  12057. stencilBuffer.setMask( material.stencilWriteMask );
  12058. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  12059. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12060. }
  12061. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12062. }
  12063. //
  12064. function setFlipSided( flipSided ) {
  12065. if ( currentFlipSided !== flipSided ) {
  12066. if ( flipSided ) {
  12067. gl.frontFace( 2304 );
  12068. } else {
  12069. gl.frontFace( 2305 );
  12070. }
  12071. currentFlipSided = flipSided;
  12072. }
  12073. }
  12074. function setCullFace( cullFace ) {
  12075. if ( cullFace !== CullFaceNone ) {
  12076. enable( 2884 );
  12077. if ( cullFace !== currentCullFace ) {
  12078. if ( cullFace === CullFaceBack ) {
  12079. gl.cullFace( 1029 );
  12080. } else if ( cullFace === CullFaceFront ) {
  12081. gl.cullFace( 1028 );
  12082. } else {
  12083. gl.cullFace( 1032 );
  12084. }
  12085. }
  12086. } else {
  12087. disable( 2884 );
  12088. }
  12089. currentCullFace = cullFace;
  12090. }
  12091. function setLineWidth( width ) {
  12092. if ( width !== currentLineWidth ) {
  12093. if ( lineWidthAvailable ) gl.lineWidth( width );
  12094. currentLineWidth = width;
  12095. }
  12096. }
  12097. function setPolygonOffset( polygonOffset, factor, units ) {
  12098. if ( polygonOffset ) {
  12099. enable( 32823 );
  12100. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12101. gl.polygonOffset( factor, units );
  12102. currentPolygonOffsetFactor = factor;
  12103. currentPolygonOffsetUnits = units;
  12104. }
  12105. } else {
  12106. disable( 32823 );
  12107. }
  12108. }
  12109. function setScissorTest( scissorTest ) {
  12110. if ( scissorTest ) {
  12111. enable( 3089 );
  12112. } else {
  12113. disable( 3089 );
  12114. }
  12115. }
  12116. // texture
  12117. function activeTexture( webglSlot ) {
  12118. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12119. if ( currentTextureSlot !== webglSlot ) {
  12120. gl.activeTexture( webglSlot );
  12121. currentTextureSlot = webglSlot;
  12122. }
  12123. }
  12124. function bindTexture( webglType, webglTexture ) {
  12125. if ( currentTextureSlot === null ) {
  12126. activeTexture();
  12127. }
  12128. let boundTexture = currentBoundTextures[ currentTextureSlot ];
  12129. if ( boundTexture === undefined ) {
  12130. boundTexture = { type: undefined, texture: undefined };
  12131. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12132. }
  12133. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12134. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12135. boundTexture.type = webglType;
  12136. boundTexture.texture = webglTexture;
  12137. }
  12138. }
  12139. function unbindTexture() {
  12140. const boundTexture = currentBoundTextures[ currentTextureSlot ];
  12141. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  12142. gl.bindTexture( boundTexture.type, null );
  12143. boundTexture.type = undefined;
  12144. boundTexture.texture = undefined;
  12145. }
  12146. }
  12147. function compressedTexImage2D() {
  12148. try {
  12149. gl.compressedTexImage2D.apply( gl, arguments );
  12150. } catch ( error ) {
  12151. console.error( 'THREE.WebGLState:', error );
  12152. }
  12153. }
  12154. function texImage2D() {
  12155. try {
  12156. gl.texImage2D.apply( gl, arguments );
  12157. } catch ( error ) {
  12158. console.error( 'THREE.WebGLState:', error );
  12159. }
  12160. }
  12161. function texImage3D() {
  12162. try {
  12163. gl.texImage3D.apply( gl, arguments );
  12164. } catch ( error ) {
  12165. console.error( 'THREE.WebGLState:', error );
  12166. }
  12167. }
  12168. //
  12169. function scissor( scissor ) {
  12170. if ( currentScissor.equals( scissor ) === false ) {
  12171. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12172. currentScissor.copy( scissor );
  12173. }
  12174. }
  12175. function viewport( viewport ) {
  12176. if ( currentViewport.equals( viewport ) === false ) {
  12177. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12178. currentViewport.copy( viewport );
  12179. }
  12180. }
  12181. //
  12182. function reset() {
  12183. enabledCapabilities = {};
  12184. currentTextureSlot = null;
  12185. currentBoundTextures = {};
  12186. currentProgram = null;
  12187. currentBlendingEnabled = null;
  12188. currentBlending = null;
  12189. currentBlendEquation = null;
  12190. currentBlendSrc = null;
  12191. currentBlendDst = null;
  12192. currentBlendEquationAlpha = null;
  12193. currentBlendSrcAlpha = null;
  12194. currentBlendDstAlpha = null;
  12195. currentPremultipledAlpha = false;
  12196. currentFlipSided = null;
  12197. currentCullFace = null;
  12198. currentLineWidth = null;
  12199. currentPolygonOffsetFactor = null;
  12200. currentPolygonOffsetUnits = null;
  12201. colorBuffer.reset();
  12202. depthBuffer.reset();
  12203. stencilBuffer.reset();
  12204. }
  12205. return {
  12206. buffers: {
  12207. color: colorBuffer,
  12208. depth: depthBuffer,
  12209. stencil: stencilBuffer
  12210. },
  12211. enable: enable,
  12212. disable: disable,
  12213. useProgram: useProgram,
  12214. setBlending: setBlending,
  12215. setMaterial: setMaterial,
  12216. setFlipSided: setFlipSided,
  12217. setCullFace: setCullFace,
  12218. setLineWidth: setLineWidth,
  12219. setPolygonOffset: setPolygonOffset,
  12220. setScissorTest: setScissorTest,
  12221. activeTexture: activeTexture,
  12222. bindTexture: bindTexture,
  12223. unbindTexture: unbindTexture,
  12224. compressedTexImage2D: compressedTexImage2D,
  12225. texImage2D: texImage2D,
  12226. texImage3D: texImage3D,
  12227. scissor: scissor,
  12228. viewport: viewport,
  12229. reset: reset
  12230. };
  12231. }
  12232. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12233. const isWebGL2 = capabilities.isWebGL2;
  12234. const maxTextures = capabilities.maxTextures;
  12235. const maxCubemapSize = capabilities.maxCubemapSize;
  12236. const maxTextureSize = capabilities.maxTextureSize;
  12237. const maxSamples = capabilities.maxSamples;
  12238. const _videoTextures = new WeakMap();
  12239. let _canvas;
  12240. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12241. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12242. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12243. let useOffscreenCanvas = false;
  12244. try {
  12245. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  12246. && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;
  12247. } catch ( err ) {
  12248. // Ignore any errors
  12249. }
  12250. function createCanvas( width, height ) {
  12251. // Use OffscreenCanvas when available. Specially needed in web workers
  12252. return useOffscreenCanvas ?
  12253. new OffscreenCanvas( width, height ) :
  12254. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12255. }
  12256. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12257. let scale = 1;
  12258. // handle case if texture exceeds max size
  12259. if ( image.width > maxSize || image.height > maxSize ) {
  12260. scale = maxSize / Math.max( image.width, image.height );
  12261. }
  12262. // only perform resize if necessary
  12263. if ( scale < 1 || needsPowerOfTwo === true ) {
  12264. // only perform resize for certain image types
  12265. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12266. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12267. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12268. const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12269. const width = floor( scale * image.width );
  12270. const height = floor( scale * image.height );
  12271. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12272. // cube textures can't reuse the same canvas
  12273. const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12274. canvas.width = width;
  12275. canvas.height = height;
  12276. const context = canvas.getContext( '2d' );
  12277. context.drawImage( image, 0, 0, width, height );
  12278. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12279. return canvas;
  12280. } else {
  12281. if ( 'data' in image ) {
  12282. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12283. }
  12284. return image;
  12285. }
  12286. }
  12287. return image;
  12288. }
  12289. function isPowerOfTwo( image ) {
  12290. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  12291. }
  12292. function textureNeedsPowerOfTwo( texture ) {
  12293. if ( isWebGL2 ) return false;
  12294. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12295. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12296. }
  12297. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12298. return texture.generateMipmaps && supportsMips &&
  12299. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12300. }
  12301. function generateMipmap( target, texture, width, height ) {
  12302. _gl.generateMipmap( target );
  12303. const textureProperties = properties.get( texture );
  12304. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12305. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12306. }
  12307. function getInternalFormat( internalFormatName, glFormat, glType ) {
  12308. if ( isWebGL2 === false ) return glFormat;
  12309. if ( internalFormatName !== null ) {
  12310. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  12311. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  12312. }
  12313. let internalFormat = glFormat;
  12314. if ( glFormat === 6403 ) {
  12315. if ( glType === 5126 ) internalFormat = 33326;
  12316. if ( glType === 5131 ) internalFormat = 33325;
  12317. if ( glType === 5121 ) internalFormat = 33321;
  12318. }
  12319. if ( glFormat === 6407 ) {
  12320. if ( glType === 5126 ) internalFormat = 34837;
  12321. if ( glType === 5131 ) internalFormat = 34843;
  12322. if ( glType === 5121 ) internalFormat = 32849;
  12323. }
  12324. if ( glFormat === 6408 ) {
  12325. if ( glType === 5126 ) internalFormat = 34836;
  12326. if ( glType === 5131 ) internalFormat = 34842;
  12327. if ( glType === 5121 ) internalFormat = 32856;
  12328. }
  12329. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12330. internalFormat === 34842 || internalFormat === 34836 ) {
  12331. extensions.get( 'EXT_color_buffer_float' );
  12332. }
  12333. return internalFormat;
  12334. }
  12335. // Fallback filters for non-power-of-2 textures
  12336. function filterFallback( f ) {
  12337. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12338. return 9728;
  12339. }
  12340. return 9729;
  12341. }
  12342. //
  12343. function onTextureDispose( event ) {
  12344. const texture = event.target;
  12345. texture.removeEventListener( 'dispose', onTextureDispose );
  12346. deallocateTexture( texture );
  12347. if ( texture.isVideoTexture ) {
  12348. _videoTextures.delete( texture );
  12349. }
  12350. info.memory.textures --;
  12351. }
  12352. function onRenderTargetDispose( event ) {
  12353. const renderTarget = event.target;
  12354. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12355. deallocateRenderTarget( renderTarget );
  12356. info.memory.textures --;
  12357. }
  12358. //
  12359. function deallocateTexture( texture ) {
  12360. const textureProperties = properties.get( texture );
  12361. if ( textureProperties.__webglInit === undefined ) return;
  12362. _gl.deleteTexture( textureProperties.__webglTexture );
  12363. properties.remove( texture );
  12364. }
  12365. function deallocateRenderTarget( renderTarget ) {
  12366. const renderTargetProperties = properties.get( renderTarget );
  12367. const textureProperties = properties.get( renderTarget.texture );
  12368. if ( ! renderTarget ) return;
  12369. if ( textureProperties.__webglTexture !== undefined ) {
  12370. _gl.deleteTexture( textureProperties.__webglTexture );
  12371. }
  12372. if ( renderTarget.depthTexture ) {
  12373. renderTarget.depthTexture.dispose();
  12374. }
  12375. if ( renderTarget.isWebGLCubeRenderTarget ) {
  12376. for ( let i = 0; i < 6; i ++ ) {
  12377. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12378. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12379. }
  12380. } else {
  12381. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12382. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12383. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  12384. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  12385. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  12386. }
  12387. properties.remove( renderTarget.texture );
  12388. properties.remove( renderTarget );
  12389. }
  12390. //
  12391. let textureUnits = 0;
  12392. function resetTextureUnits() {
  12393. textureUnits = 0;
  12394. }
  12395. function allocateTextureUnit() {
  12396. const textureUnit = textureUnits;
  12397. if ( textureUnit >= maxTextures ) {
  12398. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  12399. }
  12400. textureUnits += 1;
  12401. return textureUnit;
  12402. }
  12403. //
  12404. function setTexture2D( texture, slot ) {
  12405. const textureProperties = properties.get( texture );
  12406. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12407. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12408. const image = texture.image;
  12409. if ( image === undefined ) {
  12410. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12411. } else if ( image.complete === false ) {
  12412. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12413. } else {
  12414. uploadTexture( textureProperties, texture, slot );
  12415. return;
  12416. }
  12417. }
  12418. state.activeTexture( 33984 + slot );
  12419. state.bindTexture( 3553, textureProperties.__webglTexture );
  12420. }
  12421. function setTexture2DArray( texture, slot ) {
  12422. const textureProperties = properties.get( texture );
  12423. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12424. uploadTexture( textureProperties, texture, slot );
  12425. return;
  12426. }
  12427. state.activeTexture( 33984 + slot );
  12428. state.bindTexture( 35866, textureProperties.__webglTexture );
  12429. }
  12430. function setTexture3D( texture, slot ) {
  12431. const textureProperties = properties.get( texture );
  12432. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12433. uploadTexture( textureProperties, texture, slot );
  12434. return;
  12435. }
  12436. state.activeTexture( 33984 + slot );
  12437. state.bindTexture( 32879, textureProperties.__webglTexture );
  12438. }
  12439. function setTextureCube( texture, slot ) {
  12440. const textureProperties = properties.get( texture );
  12441. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12442. uploadCubeTexture( textureProperties, texture, slot );
  12443. return;
  12444. }
  12445. state.activeTexture( 33984 + slot );
  12446. state.bindTexture( 34067, textureProperties.__webglTexture );
  12447. }
  12448. const wrappingToGL = {
  12449. [ RepeatWrapping ]: 10497,
  12450. [ ClampToEdgeWrapping ]: 33071,
  12451. [ MirroredRepeatWrapping ]: 33648
  12452. };
  12453. const filterToGL = {
  12454. [ NearestFilter ]: 9728,
  12455. [ NearestMipmapNearestFilter ]: 9984,
  12456. [ NearestMipmapLinearFilter ]: 9986,
  12457. [ LinearFilter ]: 9729,
  12458. [ LinearMipmapNearestFilter ]: 9985,
  12459. [ LinearMipmapLinearFilter ]: 9987
  12460. };
  12461. function setTextureParameters( textureType, texture, supportsMips ) {
  12462. if ( supportsMips ) {
  12463. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  12464. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  12465. if ( textureType === 32879 || textureType === 35866 ) {
  12466. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  12467. }
  12468. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  12469. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  12470. } else {
  12471. _gl.texParameteri( textureType, 10242, 33071 );
  12472. _gl.texParameteri( textureType, 10243, 33071 );
  12473. if ( textureType === 32879 || textureType === 35866 ) {
  12474. _gl.texParameteri( textureType, 32882, 33071 );
  12475. }
  12476. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12477. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12478. }
  12479. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12480. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12481. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12482. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12483. }
  12484. }
  12485. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12486. if ( extension ) {
  12487. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12488. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12489. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12490. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12491. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12492. }
  12493. }
  12494. }
  12495. function initTexture( textureProperties, texture ) {
  12496. if ( textureProperties.__webglInit === undefined ) {
  12497. textureProperties.__webglInit = true;
  12498. texture.addEventListener( 'dispose', onTextureDispose );
  12499. textureProperties.__webglTexture = _gl.createTexture();
  12500. info.memory.textures ++;
  12501. }
  12502. }
  12503. function uploadTexture( textureProperties, texture, slot ) {
  12504. let textureType = 3553;
  12505. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12506. if ( texture.isDataTexture3D ) textureType = 32879;
  12507. initTexture( textureProperties, texture );
  12508. state.activeTexture( 33984 + slot );
  12509. state.bindTexture( textureType, textureProperties.__webglTexture );
  12510. _gl.pixelStorei( 37440, texture.flipY );
  12511. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12512. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12513. const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12514. const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  12515. const supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12516. glFormat = utils.convert( texture.format );
  12517. let glType = utils.convert( texture.type ),
  12518. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12519. setTextureParameters( textureType, texture, supportsMips );
  12520. let mipmap;
  12521. const mipmaps = texture.mipmaps;
  12522. if ( texture.isDepthTexture ) {
  12523. // populate depth texture with dummy data
  12524. glInternalFormat = 6402;
  12525. if ( isWebGL2 ) {
  12526. if ( texture.type === FloatType ) {
  12527. glInternalFormat = 36012;
  12528. } else if ( texture.type === UnsignedIntType ) {
  12529. glInternalFormat = 33190;
  12530. } else if ( texture.type === UnsignedInt248Type ) {
  12531. glInternalFormat = 35056;
  12532. } else {
  12533. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12534. }
  12535. } else {
  12536. if ( texture.type === FloatType ) {
  12537. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  12538. }
  12539. }
  12540. // validation checks for WebGL 1
  12541. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12542. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12543. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12544. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12545. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12546. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12547. texture.type = UnsignedShortType;
  12548. glType = utils.convert( texture.type );
  12549. }
  12550. }
  12551. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  12552. // Depth stencil textures need the DEPTH_STENCIL internal format
  12553. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12554. glInternalFormat = 34041;
  12555. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12556. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12557. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12558. if ( texture.type !== UnsignedInt248Type ) {
  12559. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12560. texture.type = UnsignedInt248Type;
  12561. glType = utils.convert( texture.type );
  12562. }
  12563. }
  12564. //
  12565. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12566. } else if ( texture.isDataTexture ) {
  12567. // use manually created mipmaps if available
  12568. // if there are no manual mipmaps
  12569. // set 0 level mipmap and then use GL to generate other mipmap levels
  12570. if ( mipmaps.length > 0 && supportsMips ) {
  12571. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12572. mipmap = mipmaps[ i ];
  12573. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12574. }
  12575. texture.generateMipmaps = false;
  12576. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12577. } else {
  12578. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12579. textureProperties.__maxMipLevel = 0;
  12580. }
  12581. } else if ( texture.isCompressedTexture ) {
  12582. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12583. mipmap = mipmaps[ i ];
  12584. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12585. if ( glFormat !== null ) {
  12586. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12587. } else {
  12588. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12589. }
  12590. } else {
  12591. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12592. }
  12593. }
  12594. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12595. } else if ( texture.isDataTexture2DArray ) {
  12596. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12597. textureProperties.__maxMipLevel = 0;
  12598. } else if ( texture.isDataTexture3D ) {
  12599. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12600. textureProperties.__maxMipLevel = 0;
  12601. } else {
  12602. // regular Texture (image, video, canvas)
  12603. // use manually created mipmaps if available
  12604. // if there are no manual mipmaps
  12605. // set 0 level mipmap and then use GL to generate other mipmap levels
  12606. if ( mipmaps.length > 0 && supportsMips ) {
  12607. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12608. mipmap = mipmaps[ i ];
  12609. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12610. }
  12611. texture.generateMipmaps = false;
  12612. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12613. } else {
  12614. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12615. textureProperties.__maxMipLevel = 0;
  12616. }
  12617. }
  12618. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12619. generateMipmap( textureType, texture, image.width, image.height );
  12620. }
  12621. textureProperties.__version = texture.version;
  12622. if ( texture.onUpdate ) texture.onUpdate( texture );
  12623. }
  12624. function uploadCubeTexture( textureProperties, texture, slot ) {
  12625. if ( texture.image.length !== 6 ) return;
  12626. initTexture( textureProperties, texture );
  12627. state.activeTexture( 33984 + slot );
  12628. state.bindTexture( 34067, textureProperties.__webglTexture );
  12629. _gl.pixelStorei( 37440, texture.flipY );
  12630. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12631. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12632. const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  12633. const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12634. const cubeImage = [];
  12635. for ( let i = 0; i < 6; i ++ ) {
  12636. if ( ! isCompressed && ! isDataTexture ) {
  12637. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  12638. } else {
  12639. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12640. }
  12641. }
  12642. const image = cubeImage[ 0 ],
  12643. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12644. glFormat = utils.convert( texture.format ),
  12645. glType = utils.convert( texture.type ),
  12646. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12647. setTextureParameters( 34067, texture, supportsMips );
  12648. let mipmaps;
  12649. if ( isCompressed ) {
  12650. for ( let i = 0; i < 6; i ++ ) {
  12651. mipmaps = cubeImage[ i ].mipmaps;
  12652. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12653. const mipmap = mipmaps[ j ];
  12654. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12655. if ( glFormat !== null ) {
  12656. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12657. } else {
  12658. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12659. }
  12660. } else {
  12661. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12662. }
  12663. }
  12664. }
  12665. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12666. } else {
  12667. mipmaps = texture.mipmaps;
  12668. for ( let i = 0; i < 6; i ++ ) {
  12669. if ( isDataTexture ) {
  12670. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12671. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12672. const mipmap = mipmaps[ j ];
  12673. const mipmapImage = mipmap.image[ i ].image;
  12674. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  12675. }
  12676. } else {
  12677. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12678. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12679. const mipmap = mipmaps[ j ];
  12680. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12681. }
  12682. }
  12683. }
  12684. textureProperties.__maxMipLevel = mipmaps.length;
  12685. }
  12686. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12687. // We assume images for cube map have the same size.
  12688. generateMipmap( 34067, texture, image.width, image.height );
  12689. }
  12690. textureProperties.__version = texture.version;
  12691. if ( texture.onUpdate ) texture.onUpdate( texture );
  12692. }
  12693. // Render targets
  12694. // Setup storage for target texture and bind it to correct framebuffer
  12695. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12696. const glFormat = utils.convert( renderTarget.texture.format );
  12697. const glType = utils.convert( renderTarget.texture.type );
  12698. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12699. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12700. _gl.bindFramebuffer( 36160, framebuffer );
  12701. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12702. _gl.bindFramebuffer( 36160, null );
  12703. }
  12704. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12705. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12706. _gl.bindRenderbuffer( 36161, renderbuffer );
  12707. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12708. let glInternalFormat = 33189;
  12709. if ( isMultisample ) {
  12710. const depthTexture = renderTarget.depthTexture;
  12711. if ( depthTexture && depthTexture.isDepthTexture ) {
  12712. if ( depthTexture.type === FloatType ) {
  12713. glInternalFormat = 36012;
  12714. } else if ( depthTexture.type === UnsignedIntType ) {
  12715. glInternalFormat = 33190;
  12716. }
  12717. }
  12718. const samples = getRenderTargetSamples( renderTarget );
  12719. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12720. } else {
  12721. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12722. }
  12723. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12724. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12725. if ( isMultisample ) {
  12726. const samples = getRenderTargetSamples( renderTarget );
  12727. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12728. } else {
  12729. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12730. }
  12731. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12732. } else {
  12733. const glFormat = utils.convert( renderTarget.texture.format );
  12734. const glType = utils.convert( renderTarget.texture.type );
  12735. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12736. if ( isMultisample ) {
  12737. const samples = getRenderTargetSamples( renderTarget );
  12738. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12739. } else {
  12740. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12741. }
  12742. }
  12743. _gl.bindRenderbuffer( 36161, null );
  12744. }
  12745. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12746. function setupDepthTexture( framebuffer, renderTarget ) {
  12747. const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  12748. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12749. _gl.bindFramebuffer( 36160, framebuffer );
  12750. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12751. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12752. }
  12753. // upload an empty depth texture with framebuffer size
  12754. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12755. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12756. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12757. renderTarget.depthTexture.image.width = renderTarget.width;
  12758. renderTarget.depthTexture.image.height = renderTarget.height;
  12759. renderTarget.depthTexture.needsUpdate = true;
  12760. }
  12761. setTexture2D( renderTarget.depthTexture, 0 );
  12762. const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12763. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12764. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12765. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12766. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12767. } else {
  12768. throw new Error( 'Unknown depthTexture format' );
  12769. }
  12770. }
  12771. // Setup GL resources for a non-texture depth buffer
  12772. function setupDepthRenderbuffer( renderTarget ) {
  12773. const renderTargetProperties = properties.get( renderTarget );
  12774. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12775. if ( renderTarget.depthTexture ) {
  12776. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12777. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12778. } else {
  12779. if ( isCube ) {
  12780. renderTargetProperties.__webglDepthbuffer = [];
  12781. for ( let i = 0; i < 6; i ++ ) {
  12782. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12783. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12784. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  12785. }
  12786. } else {
  12787. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12788. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12789. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  12790. }
  12791. }
  12792. _gl.bindFramebuffer( 36160, null );
  12793. }
  12794. // Set up GL resources for the render target
  12795. function setupRenderTarget( renderTarget ) {
  12796. const renderTargetProperties = properties.get( renderTarget );
  12797. const textureProperties = properties.get( renderTarget.texture );
  12798. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12799. textureProperties.__webglTexture = _gl.createTexture();
  12800. info.memory.textures ++;
  12801. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12802. const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12803. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12804. // Handles WebGL2 RGBFormat fallback - #18858
  12805. if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) {
  12806. renderTarget.texture.format = RGBAFormat;
  12807. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  12808. }
  12809. // Setup framebuffer
  12810. if ( isCube ) {
  12811. renderTargetProperties.__webglFramebuffer = [];
  12812. for ( let i = 0; i < 6; i ++ ) {
  12813. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12814. }
  12815. } else {
  12816. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12817. if ( isMultisample ) {
  12818. if ( isWebGL2 ) {
  12819. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12820. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12821. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12822. const glFormat = utils.convert( renderTarget.texture.format );
  12823. const glType = utils.convert( renderTarget.texture.type );
  12824. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12825. const samples = getRenderTargetSamples( renderTarget );
  12826. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12827. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12828. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12829. _gl.bindRenderbuffer( 36161, null );
  12830. if ( renderTarget.depthBuffer ) {
  12831. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12832. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12833. }
  12834. _gl.bindFramebuffer( 36160, null );
  12835. } else {
  12836. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12837. }
  12838. }
  12839. }
  12840. // Setup color buffer
  12841. if ( isCube ) {
  12842. state.bindTexture( 34067, textureProperties.__webglTexture );
  12843. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12844. for ( let i = 0; i < 6; i ++ ) {
  12845. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12846. }
  12847. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12848. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12849. }
  12850. state.bindTexture( 34067, null );
  12851. } else {
  12852. state.bindTexture( 3553, textureProperties.__webglTexture );
  12853. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12854. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12855. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12856. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12857. }
  12858. state.bindTexture( 3553, null );
  12859. }
  12860. // Setup depth and stencil buffers
  12861. if ( renderTarget.depthBuffer ) {
  12862. setupDepthRenderbuffer( renderTarget );
  12863. }
  12864. }
  12865. function updateRenderTargetMipmap( renderTarget ) {
  12866. const texture = renderTarget.texture;
  12867. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12868. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12869. const target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  12870. const webglTexture = properties.get( texture ).__webglTexture;
  12871. state.bindTexture( target, webglTexture );
  12872. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12873. state.bindTexture( target, null );
  12874. }
  12875. }
  12876. function updateMultisampleRenderTarget( renderTarget ) {
  12877. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12878. if ( isWebGL2 ) {
  12879. const renderTargetProperties = properties.get( renderTarget );
  12880. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12881. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12882. const width = renderTarget.width;
  12883. const height = renderTarget.height;
  12884. let mask = 16384;
  12885. if ( renderTarget.depthBuffer ) mask |= 256;
  12886. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12887. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12888. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  12889. } else {
  12890. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12891. }
  12892. }
  12893. }
  12894. function getRenderTargetSamples( renderTarget ) {
  12895. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12896. Math.min( maxSamples, renderTarget.samples ) : 0;
  12897. }
  12898. function updateVideoTexture( texture ) {
  12899. const frame = info.render.frame;
  12900. // Check the last frame we updated the VideoTexture
  12901. if ( _videoTextures.get( texture ) !== frame ) {
  12902. _videoTextures.set( texture, frame );
  12903. texture.update();
  12904. }
  12905. }
  12906. // backwards compatibility
  12907. let warnedTexture2D = false;
  12908. let warnedTextureCube = false;
  12909. function safeSetTexture2D( texture, slot ) {
  12910. if ( texture && texture.isWebGLRenderTarget ) {
  12911. if ( warnedTexture2D === false ) {
  12912. console.warn( 'THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.' );
  12913. warnedTexture2D = true;
  12914. }
  12915. texture = texture.texture;
  12916. }
  12917. setTexture2D( texture, slot );
  12918. }
  12919. function safeSetTextureCube( texture, slot ) {
  12920. if ( texture && texture.isWebGLCubeRenderTarget ) {
  12921. if ( warnedTextureCube === false ) {
  12922. console.warn( 'THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.' );
  12923. warnedTextureCube = true;
  12924. }
  12925. texture = texture.texture;
  12926. }
  12927. setTextureCube( texture, slot );
  12928. }
  12929. //
  12930. this.allocateTextureUnit = allocateTextureUnit;
  12931. this.resetTextureUnits = resetTextureUnits;
  12932. this.setTexture2D = setTexture2D;
  12933. this.setTexture2DArray = setTexture2DArray;
  12934. this.setTexture3D = setTexture3D;
  12935. this.setTextureCube = setTextureCube;
  12936. this.setupRenderTarget = setupRenderTarget;
  12937. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12938. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12939. this.safeSetTexture2D = safeSetTexture2D;
  12940. this.safeSetTextureCube = safeSetTextureCube;
  12941. }
  12942. function WebGLUtils( gl, extensions, capabilities ) {
  12943. const isWebGL2 = capabilities.isWebGL2;
  12944. function convert( p ) {
  12945. let extension;
  12946. if ( p === UnsignedByteType ) return 5121;
  12947. if ( p === UnsignedShort4444Type ) return 32819;
  12948. if ( p === UnsignedShort5551Type ) return 32820;
  12949. if ( p === UnsignedShort565Type ) return 33635;
  12950. if ( p === ByteType ) return 5120;
  12951. if ( p === ShortType ) return 5122;
  12952. if ( p === UnsignedShortType ) return 5123;
  12953. if ( p === IntType ) return 5124;
  12954. if ( p === UnsignedIntType ) return 5125;
  12955. if ( p === FloatType ) return 5126;
  12956. if ( p === HalfFloatType ) {
  12957. if ( isWebGL2 ) return 5131;
  12958. extension = extensions.get( 'OES_texture_half_float' );
  12959. if ( extension !== null ) {
  12960. return extension.HALF_FLOAT_OES;
  12961. } else {
  12962. return null;
  12963. }
  12964. }
  12965. if ( p === AlphaFormat ) return 6406;
  12966. if ( p === RGBFormat ) return 6407;
  12967. if ( p === RGBAFormat ) return 6408;
  12968. if ( p === LuminanceFormat ) return 6409;
  12969. if ( p === LuminanceAlphaFormat ) return 6410;
  12970. if ( p === DepthFormat ) return 6402;
  12971. if ( p === DepthStencilFormat ) return 34041;
  12972. if ( p === RedFormat ) return 6403;
  12973. // WebGL2 formats.
  12974. if ( p === RedIntegerFormat ) return 36244;
  12975. if ( p === RGFormat ) return 33319;
  12976. if ( p === RGIntegerFormat ) return 33320;
  12977. if ( p === RGBIntegerFormat ) return 36248;
  12978. if ( p === RGBAIntegerFormat ) return 36249;
  12979. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12980. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12981. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12982. if ( extension !== null ) {
  12983. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12984. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12985. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12986. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12987. } else {
  12988. return null;
  12989. }
  12990. }
  12991. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12992. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12993. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12994. if ( extension !== null ) {
  12995. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12996. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12997. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12998. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12999. } else {
  13000. return null;
  13001. }
  13002. }
  13003. if ( p === RGB_ETC1_Format ) {
  13004. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13005. if ( extension !== null ) {
  13006. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13007. } else {
  13008. return null;
  13009. }
  13010. }
  13011. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  13012. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  13013. if ( extension !== null ) {
  13014. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  13015. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13016. }
  13017. }
  13018. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13019. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13020. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13021. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13022. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  13023. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  13024. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  13025. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  13026. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  13027. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  13028. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13029. if ( extension !== null ) {
  13030. // TODO Complete?
  13031. return p;
  13032. } else {
  13033. return null;
  13034. }
  13035. }
  13036. if ( p === RGBA_BPTC_Format ) {
  13037. extension = extensions.get( 'EXT_texture_compression_bptc' );
  13038. if ( extension !== null ) {
  13039. // TODO Complete?
  13040. return p;
  13041. } else {
  13042. return null;
  13043. }
  13044. }
  13045. if ( p === UnsignedInt248Type ) {
  13046. if ( isWebGL2 ) return 34042;
  13047. extension = extensions.get( 'WEBGL_depth_texture' );
  13048. if ( extension !== null ) {
  13049. return extension.UNSIGNED_INT_24_8_WEBGL;
  13050. } else {
  13051. return null;
  13052. }
  13053. }
  13054. }
  13055. return { convert: convert };
  13056. }
  13057. function ArrayCamera( array = [] ) {
  13058. PerspectiveCamera.call( this );
  13059. this.cameras = array;
  13060. }
  13061. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13062. constructor: ArrayCamera,
  13063. isArrayCamera: true
  13064. } );
  13065. function Group() {
  13066. Object3D.call( this );
  13067. this.type = 'Group';
  13068. }
  13069. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13070. constructor: Group,
  13071. isGroup: true
  13072. } );
  13073. function WebXRController() {
  13074. this._targetRay = null;
  13075. this._grip = null;
  13076. this._hand = null;
  13077. }
  13078. Object.assign( WebXRController.prototype, {
  13079. constructor: WebXRController,
  13080. getHandSpace: function () {
  13081. if ( this._hand === null ) {
  13082. this._hand = new Group();
  13083. this._hand.matrixAutoUpdate = false;
  13084. this._hand.visible = false;
  13085. this._hand.joints = [];
  13086. this._hand.inputState = { pinching: false };
  13087. if ( window.XRHand ) {
  13088. for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
  13089. // The transform of this joint will be updated with the joint pose on each frame
  13090. const joint = new Group();
  13091. joint.matrixAutoUpdate = false;
  13092. joint.visible = false;
  13093. this._hand.joints.push( joint );
  13094. // ??
  13095. this._hand.add( joint );
  13096. }
  13097. }
  13098. }
  13099. return this._hand;
  13100. },
  13101. getTargetRaySpace: function () {
  13102. if ( this._targetRay === null ) {
  13103. this._targetRay = new Group();
  13104. this._targetRay.matrixAutoUpdate = false;
  13105. this._targetRay.visible = false;
  13106. }
  13107. return this._targetRay;
  13108. },
  13109. getGripSpace: function () {
  13110. if ( this._grip === null ) {
  13111. this._grip = new Group();
  13112. this._grip.matrixAutoUpdate = false;
  13113. this._grip.visible = false;
  13114. }
  13115. return this._grip;
  13116. },
  13117. dispatchEvent: function ( event ) {
  13118. if ( this._targetRay !== null ) {
  13119. this._targetRay.dispatchEvent( event );
  13120. }
  13121. if ( this._grip !== null ) {
  13122. this._grip.dispatchEvent( event );
  13123. }
  13124. if ( this._hand !== null ) {
  13125. this._hand.dispatchEvent( event );
  13126. }
  13127. return this;
  13128. },
  13129. disconnect: function ( inputSource ) {
  13130. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13131. if ( this._targetRay !== null ) {
  13132. this._targetRay.visible = false;
  13133. }
  13134. if ( this._grip !== null ) {
  13135. this._grip.visible = false;
  13136. }
  13137. if ( this._hand !== null ) {
  13138. this._hand.visible = false;
  13139. }
  13140. return this;
  13141. },
  13142. update: function ( inputSource, frame, referenceSpace ) {
  13143. let inputPose = null;
  13144. let gripPose = null;
  13145. let handPose = null;
  13146. const targetRay = this._targetRay;
  13147. const grip = this._grip;
  13148. const hand = this._hand;
  13149. if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) {
  13150. if ( hand && inputSource.hand ) {
  13151. handPose = true;
  13152. for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
  13153. if ( inputSource.hand[ i ] ) {
  13154. // Update the joints groups with the XRJoint poses
  13155. const jointPose = frame.getJointPose( inputSource.hand[ i ], referenceSpace );
  13156. const joint = hand.joints[ i ];
  13157. if ( jointPose !== null ) {
  13158. joint.matrix.fromArray( jointPose.transform.matrix );
  13159. joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
  13160. joint.jointRadius = jointPose.radius;
  13161. }
  13162. joint.visible = jointPose !== null;
  13163. // Custom events
  13164. // Check pinch
  13165. const indexTip = hand.joints[ window.XRHand.INDEX_PHALANX_TIP ];
  13166. const thumbTip = hand.joints[ window.XRHand.THUMB_PHALANX_TIP ];
  13167. const distance = indexTip.position.distanceTo( thumbTip.position );
  13168. const distanceToPinch = 0.02;
  13169. const threshold = 0.005;
  13170. if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
  13171. hand.inputState.pinching = false;
  13172. this.dispatchEvent( {
  13173. type: 'pinchend',
  13174. handedness: inputSource.handedness,
  13175. target: this
  13176. } );
  13177. } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
  13178. hand.inputState.pinching = true;
  13179. this.dispatchEvent( {
  13180. type: 'pinchstart',
  13181. handedness: inputSource.handedness,
  13182. target: this
  13183. } );
  13184. }
  13185. }
  13186. }
  13187. } else {
  13188. if ( targetRay !== null ) {
  13189. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13190. if ( inputPose !== null ) {
  13191. targetRay.matrix.fromArray( inputPose.transform.matrix );
  13192. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  13193. }
  13194. }
  13195. if ( grip !== null && inputSource.gripSpace ) {
  13196. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  13197. if ( gripPose !== null ) {
  13198. grip.matrix.fromArray( gripPose.transform.matrix );
  13199. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  13200. }
  13201. }
  13202. }
  13203. }
  13204. if ( targetRay !== null ) {
  13205. targetRay.visible = ( inputPose !== null );
  13206. }
  13207. if ( grip !== null ) {
  13208. grip.visible = ( gripPose !== null );
  13209. }
  13210. if ( hand !== null ) {
  13211. hand.visible = ( handPose !== null );
  13212. }
  13213. return this;
  13214. }
  13215. } );
  13216. function WebXRManager( renderer, gl ) {
  13217. const scope = this;
  13218. let session = null;
  13219. let framebufferScaleFactor = 1.0;
  13220. let referenceSpace = null;
  13221. let referenceSpaceType = 'local-floor';
  13222. let pose = null;
  13223. const controllers = [];
  13224. const inputSourcesMap = new Map();
  13225. //
  13226. const cameraL = new PerspectiveCamera();
  13227. cameraL.layers.enable( 1 );
  13228. cameraL.viewport = new Vector4();
  13229. const cameraR = new PerspectiveCamera();
  13230. cameraR.layers.enable( 2 );
  13231. cameraR.viewport = new Vector4();
  13232. const cameras = [ cameraL, cameraR ];
  13233. const cameraVR = new ArrayCamera();
  13234. cameraVR.layers.enable( 1 );
  13235. cameraVR.layers.enable( 2 );
  13236. let _currentDepthNear = null;
  13237. let _currentDepthFar = null;
  13238. //
  13239. this.enabled = false;
  13240. this.isPresenting = false;
  13241. this.getController = function ( index ) {
  13242. let controller = controllers[ index ];
  13243. if ( controller === undefined ) {
  13244. controller = new WebXRController();
  13245. controllers[ index ] = controller;
  13246. }
  13247. return controller.getTargetRaySpace();
  13248. };
  13249. this.getControllerGrip = function ( index ) {
  13250. let controller = controllers[ index ];
  13251. if ( controller === undefined ) {
  13252. controller = new WebXRController();
  13253. controllers[ index ] = controller;
  13254. }
  13255. return controller.getGripSpace();
  13256. };
  13257. this.getHand = function ( index ) {
  13258. let controller = controllers[ index ];
  13259. if ( controller === undefined ) {
  13260. controller = new WebXRController();
  13261. controllers[ index ] = controller;
  13262. }
  13263. return controller.getHandSpace();
  13264. };
  13265. //
  13266. function onSessionEvent( event ) {
  13267. const controller = inputSourcesMap.get( event.inputSource );
  13268. if ( controller ) {
  13269. controller.dispatchEvent( { type: event.type, data: event.inputSource } );
  13270. }
  13271. }
  13272. function onSessionEnd() {
  13273. inputSourcesMap.forEach( function ( controller, inputSource ) {
  13274. controller.disconnect( inputSource );
  13275. } );
  13276. inputSourcesMap.clear();
  13277. //
  13278. renderer.setFramebuffer( null );
  13279. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13280. animation.stop();
  13281. scope.isPresenting = false;
  13282. scope.dispatchEvent( { type: 'sessionend' } );
  13283. }
  13284. function onRequestReferenceSpace( value ) {
  13285. referenceSpace = value;
  13286. animation.setContext( session );
  13287. animation.start();
  13288. scope.isPresenting = true;
  13289. scope.dispatchEvent( { type: 'sessionstart' } );
  13290. }
  13291. this.setFramebufferScaleFactor = function ( value ) {
  13292. framebufferScaleFactor = value;
  13293. if ( scope.isPresenting === true ) {
  13294. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  13295. }
  13296. };
  13297. this.setReferenceSpaceType = function ( value ) {
  13298. referenceSpaceType = value;
  13299. if ( scope.isPresenting === true ) {
  13300. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  13301. }
  13302. };
  13303. this.getReferenceSpace = function () {
  13304. return referenceSpace;
  13305. };
  13306. this.getSession = function () {
  13307. return session;
  13308. };
  13309. this.setSession = function ( value ) {
  13310. session = value;
  13311. if ( session !== null ) {
  13312. session.addEventListener( 'select', onSessionEvent );
  13313. session.addEventListener( 'selectstart', onSessionEvent );
  13314. session.addEventListener( 'selectend', onSessionEvent );
  13315. session.addEventListener( 'squeeze', onSessionEvent );
  13316. session.addEventListener( 'squeezestart', onSessionEvent );
  13317. session.addEventListener( 'squeezeend', onSessionEvent );
  13318. session.addEventListener( 'end', onSessionEnd );
  13319. const attributes = gl.getContextAttributes();
  13320. if ( attributes.xrCompatible !== true ) {
  13321. gl.makeXRCompatible();
  13322. }
  13323. const layerInit = {
  13324. antialias: attributes.antialias,
  13325. alpha: attributes.alpha,
  13326. depth: attributes.depth,
  13327. stencil: attributes.stencil,
  13328. framebufferScaleFactor: framebufferScaleFactor
  13329. };
  13330. // eslint-disable-next-line no-undef
  13331. const baseLayer = new XRWebGLLayer( session, gl, layerInit );
  13332. session.updateRenderState( { baseLayer: baseLayer } );
  13333. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13334. //
  13335. session.addEventListener( 'inputsourceschange', updateInputSources );
  13336. }
  13337. };
  13338. function updateInputSources( event ) {
  13339. const inputSources = session.inputSources;
  13340. // Assign inputSources to available controllers
  13341. for ( let i = 0; i < controllers.length; i ++ ) {
  13342. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  13343. }
  13344. // Notify disconnected
  13345. for ( let i = 0; i < event.removed.length; i ++ ) {
  13346. const inputSource = event.removed[ i ];
  13347. const controller = inputSourcesMap.get( inputSource );
  13348. if ( controller ) {
  13349. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13350. inputSourcesMap.delete( inputSource );
  13351. }
  13352. }
  13353. // Notify connected
  13354. for ( let i = 0; i < event.added.length; i ++ ) {
  13355. const inputSource = event.added[ i ];
  13356. const controller = inputSourcesMap.get( inputSource );
  13357. if ( controller ) {
  13358. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  13359. }
  13360. }
  13361. }
  13362. //
  13363. const cameraLPos = new Vector3();
  13364. const cameraRPos = new Vector3();
  13365. /**
  13366. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13367. * the cameras' projection and world matrices have already been set.
  13368. * And that near and far planes are identical for both cameras.
  13369. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13370. */
  13371. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13372. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13373. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13374. const ipd = cameraLPos.distanceTo( cameraRPos );
  13375. const projL = cameraL.projectionMatrix.elements;
  13376. const projR = cameraR.projectionMatrix.elements;
  13377. // VR systems will have identical far and near planes, and
  13378. // most likely identical top and bottom frustum extents.
  13379. // Use the left camera for these values.
  13380. const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13381. const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13382. const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13383. const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13384. const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13385. const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13386. const left = near * leftFov;
  13387. const right = near * rightFov;
  13388. // Calculate the new camera's position offset from the
  13389. // left camera. xOffset should be roughly half `ipd`.
  13390. const zOffset = ipd / ( - leftFov + rightFov );
  13391. const xOffset = zOffset * - leftFov;
  13392. // TODO: Better way to apply this offset?
  13393. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13394. camera.translateX( xOffset );
  13395. camera.translateZ( zOffset );
  13396. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13397. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13398. // Find the union of the frustum values of the cameras and scale
  13399. // the values so that the near plane's position does not change in world space,
  13400. // although must now be relative to the new union camera.
  13401. const near2 = near + zOffset;
  13402. const far2 = far + zOffset;
  13403. const left2 = left - xOffset;
  13404. const right2 = right + ( ipd - xOffset );
  13405. const top2 = topFov * far / far2 * near2;
  13406. const bottom2 = bottomFov * far / far2 * near2;
  13407. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13408. }
  13409. function updateCamera( camera, parent ) {
  13410. if ( parent === null ) {
  13411. camera.matrixWorld.copy( camera.matrix );
  13412. } else {
  13413. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13414. }
  13415. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13416. }
  13417. this.getCamera = function ( camera ) {
  13418. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13419. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13420. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  13421. // Note that the new renderState won't apply until the next frame. See #18320
  13422. session.updateRenderState( {
  13423. depthNear: cameraVR.near,
  13424. depthFar: cameraVR.far
  13425. } );
  13426. _currentDepthNear = cameraVR.near;
  13427. _currentDepthFar = cameraVR.far;
  13428. }
  13429. const parent = camera.parent;
  13430. const cameras = cameraVR.cameras;
  13431. updateCamera( cameraVR, parent );
  13432. for ( let i = 0; i < cameras.length; i ++ ) {
  13433. updateCamera( cameras[ i ], parent );
  13434. }
  13435. // update camera and its children
  13436. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13437. const children = camera.children;
  13438. for ( let i = 0, l = children.length; i < l; i ++ ) {
  13439. children[ i ].updateMatrixWorld( true );
  13440. }
  13441. // update projection matrix for proper view frustum culling
  13442. if ( cameras.length === 2 ) {
  13443. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13444. } else {
  13445. // assume single camera setup (AR)
  13446. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  13447. }
  13448. return cameraVR;
  13449. };
  13450. // Animation Loop
  13451. let onAnimationFrameCallback = null;
  13452. function onAnimationFrame( time, frame ) {
  13453. pose = frame.getViewerPose( referenceSpace );
  13454. if ( pose !== null ) {
  13455. const views = pose.views;
  13456. const baseLayer = session.renderState.baseLayer;
  13457. renderer.setFramebuffer( baseLayer.framebuffer );
  13458. let cameraVRNeedsUpdate = false;
  13459. // check if it's necessary to rebuild cameraVR's camera list
  13460. if ( views.length !== cameraVR.cameras.length ) {
  13461. cameraVR.cameras.length = 0;
  13462. cameraVRNeedsUpdate = true;
  13463. }
  13464. for ( let i = 0; i < views.length; i ++ ) {
  13465. const view = views[ i ];
  13466. const viewport = baseLayer.getViewport( view );
  13467. const camera = cameras[ i ];
  13468. camera.matrix.fromArray( view.transform.matrix );
  13469. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13470. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13471. if ( i === 0 ) {
  13472. cameraVR.matrix.copy( camera.matrix );
  13473. }
  13474. if ( cameraVRNeedsUpdate === true ) {
  13475. cameraVR.cameras.push( camera );
  13476. }
  13477. }
  13478. }
  13479. //
  13480. const inputSources = session.inputSources;
  13481. for ( let i = 0; i < controllers.length; i ++ ) {
  13482. const controller = controllers[ i ];
  13483. const inputSource = inputSources[ i ];
  13484. controller.update( inputSource, frame, referenceSpace );
  13485. }
  13486. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  13487. }
  13488. const animation = new WebGLAnimation();
  13489. animation.setAnimationLoop( onAnimationFrame );
  13490. this.setAnimationLoop = function ( callback ) {
  13491. onAnimationFrameCallback = callback;
  13492. };
  13493. this.dispose = function () {};
  13494. }
  13495. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13496. function WebGLMaterials( properties ) {
  13497. function refreshFogUniforms( uniforms, fog ) {
  13498. uniforms.fogColor.value.copy( fog.color );
  13499. if ( fog.isFog ) {
  13500. uniforms.fogNear.value = fog.near;
  13501. uniforms.fogFar.value = fog.far;
  13502. } else if ( fog.isFogExp2 ) {
  13503. uniforms.fogDensity.value = fog.density;
  13504. }
  13505. }
  13506. function refreshMaterialUniforms( uniforms, material, pixelRatio, height ) {
  13507. if ( material.isMeshBasicMaterial ) {
  13508. refreshUniformsCommon( uniforms, material );
  13509. } else if ( material.isMeshLambertMaterial ) {
  13510. refreshUniformsCommon( uniforms, material );
  13511. refreshUniformsLambert( uniforms, material );
  13512. } else if ( material.isMeshToonMaterial ) {
  13513. refreshUniformsCommon( uniforms, material );
  13514. refreshUniformsToon( uniforms, material );
  13515. } else if ( material.isMeshPhongMaterial ) {
  13516. refreshUniformsCommon( uniforms, material );
  13517. refreshUniformsPhong( uniforms, material );
  13518. } else if ( material.isMeshStandardMaterial ) {
  13519. refreshUniformsCommon( uniforms, material );
  13520. if ( material.isMeshPhysicalMaterial ) {
  13521. refreshUniformsPhysical( uniforms, material );
  13522. } else {
  13523. refreshUniformsStandard( uniforms, material );
  13524. }
  13525. } else if ( material.isMeshMatcapMaterial ) {
  13526. refreshUniformsCommon( uniforms, material );
  13527. refreshUniformsMatcap( uniforms, material );
  13528. } else if ( material.isMeshDepthMaterial ) {
  13529. refreshUniformsCommon( uniforms, material );
  13530. refreshUniformsDepth( uniforms, material );
  13531. } else if ( material.isMeshDistanceMaterial ) {
  13532. refreshUniformsCommon( uniforms, material );
  13533. refreshUniformsDistance( uniforms, material );
  13534. } else if ( material.isMeshNormalMaterial ) {
  13535. refreshUniformsCommon( uniforms, material );
  13536. refreshUniformsNormal( uniforms, material );
  13537. } else if ( material.isLineBasicMaterial ) {
  13538. refreshUniformsLine( uniforms, material );
  13539. if ( material.isLineDashedMaterial ) {
  13540. refreshUniformsDash( uniforms, material );
  13541. }
  13542. } else if ( material.isPointsMaterial ) {
  13543. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  13544. } else if ( material.isSpriteMaterial ) {
  13545. refreshUniformsSprites( uniforms, material );
  13546. } else if ( material.isShadowMaterial ) {
  13547. uniforms.color.value.copy( material.color );
  13548. uniforms.opacity.value = material.opacity;
  13549. } else if ( material.isShaderMaterial ) {
  13550. material.uniformsNeedUpdate = false; // #15581
  13551. }
  13552. }
  13553. function refreshUniformsCommon( uniforms, material ) {
  13554. uniforms.opacity.value = material.opacity;
  13555. if ( material.color ) {
  13556. uniforms.diffuse.value.copy( material.color );
  13557. }
  13558. if ( material.emissive ) {
  13559. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13560. }
  13561. if ( material.map ) {
  13562. uniforms.map.value = material.map;
  13563. }
  13564. if ( material.alphaMap ) {
  13565. uniforms.alphaMap.value = material.alphaMap;
  13566. }
  13567. if ( material.specularMap ) {
  13568. uniforms.specularMap.value = material.specularMap;
  13569. }
  13570. const envMap = properties.get( material ).envMap;
  13571. if ( envMap ) {
  13572. uniforms.envMap.value = envMap;
  13573. uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap._needsFlipEnvMap ) ? - 1 : 1;
  13574. uniforms.reflectivity.value = material.reflectivity;
  13575. uniforms.refractionRatio.value = material.refractionRatio;
  13576. const maxMipLevel = properties.get( envMap ).__maxMipLevel;
  13577. if ( maxMipLevel !== undefined ) {
  13578. uniforms.maxMipLevel.value = maxMipLevel;
  13579. }
  13580. }
  13581. if ( material.lightMap ) {
  13582. uniforms.lightMap.value = material.lightMap;
  13583. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13584. }
  13585. if ( material.aoMap ) {
  13586. uniforms.aoMap.value = material.aoMap;
  13587. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13588. }
  13589. // uv repeat and offset setting priorities
  13590. // 1. color map
  13591. // 2. specular map
  13592. // 3. displacementMap map
  13593. // 4. normal map
  13594. // 5. bump map
  13595. // 6. roughnessMap map
  13596. // 7. metalnessMap map
  13597. // 8. alphaMap map
  13598. // 9. emissiveMap map
  13599. // 10. clearcoat map
  13600. // 11. clearcoat normal map
  13601. // 12. clearcoat roughnessMap map
  13602. let uvScaleMap;
  13603. if ( material.map ) {
  13604. uvScaleMap = material.map;
  13605. } else if ( material.specularMap ) {
  13606. uvScaleMap = material.specularMap;
  13607. } else if ( material.displacementMap ) {
  13608. uvScaleMap = material.displacementMap;
  13609. } else if ( material.normalMap ) {
  13610. uvScaleMap = material.normalMap;
  13611. } else if ( material.bumpMap ) {
  13612. uvScaleMap = material.bumpMap;
  13613. } else if ( material.roughnessMap ) {
  13614. uvScaleMap = material.roughnessMap;
  13615. } else if ( material.metalnessMap ) {
  13616. uvScaleMap = material.metalnessMap;
  13617. } else if ( material.alphaMap ) {
  13618. uvScaleMap = material.alphaMap;
  13619. } else if ( material.emissiveMap ) {
  13620. uvScaleMap = material.emissiveMap;
  13621. } else if ( material.clearcoatMap ) {
  13622. uvScaleMap = material.clearcoatMap;
  13623. } else if ( material.clearcoatNormalMap ) {
  13624. uvScaleMap = material.clearcoatNormalMap;
  13625. } else if ( material.clearcoatRoughnessMap ) {
  13626. uvScaleMap = material.clearcoatRoughnessMap;
  13627. }
  13628. if ( uvScaleMap !== undefined ) {
  13629. // backwards compatibility
  13630. if ( uvScaleMap.isWebGLRenderTarget ) {
  13631. uvScaleMap = uvScaleMap.texture;
  13632. }
  13633. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13634. uvScaleMap.updateMatrix();
  13635. }
  13636. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13637. }
  13638. // uv repeat and offset setting priorities for uv2
  13639. // 1. ao map
  13640. // 2. light map
  13641. let uv2ScaleMap;
  13642. if ( material.aoMap ) {
  13643. uv2ScaleMap = material.aoMap;
  13644. } else if ( material.lightMap ) {
  13645. uv2ScaleMap = material.lightMap;
  13646. }
  13647. if ( uv2ScaleMap !== undefined ) {
  13648. // backwards compatibility
  13649. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  13650. uv2ScaleMap = uv2ScaleMap.texture;
  13651. }
  13652. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  13653. uv2ScaleMap.updateMatrix();
  13654. }
  13655. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  13656. }
  13657. }
  13658. function refreshUniformsLine( uniforms, material ) {
  13659. uniforms.diffuse.value.copy( material.color );
  13660. uniforms.opacity.value = material.opacity;
  13661. }
  13662. function refreshUniformsDash( uniforms, material ) {
  13663. uniforms.dashSize.value = material.dashSize;
  13664. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13665. uniforms.scale.value = material.scale;
  13666. }
  13667. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  13668. uniforms.diffuse.value.copy( material.color );
  13669. uniforms.opacity.value = material.opacity;
  13670. uniforms.size.value = material.size * pixelRatio;
  13671. uniforms.scale.value = height * 0.5;
  13672. if ( material.map ) {
  13673. uniforms.map.value = material.map;
  13674. }
  13675. if ( material.alphaMap ) {
  13676. uniforms.alphaMap.value = material.alphaMap;
  13677. }
  13678. // uv repeat and offset setting priorities
  13679. // 1. color map
  13680. // 2. alpha map
  13681. let uvScaleMap;
  13682. if ( material.map ) {
  13683. uvScaleMap = material.map;
  13684. } else if ( material.alphaMap ) {
  13685. uvScaleMap = material.alphaMap;
  13686. }
  13687. if ( uvScaleMap !== undefined ) {
  13688. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13689. uvScaleMap.updateMatrix();
  13690. }
  13691. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13692. }
  13693. }
  13694. function refreshUniformsSprites( uniforms, material ) {
  13695. uniforms.diffuse.value.copy( material.color );
  13696. uniforms.opacity.value = material.opacity;
  13697. uniforms.rotation.value = material.rotation;
  13698. if ( material.map ) {
  13699. uniforms.map.value = material.map;
  13700. }
  13701. if ( material.alphaMap ) {
  13702. uniforms.alphaMap.value = material.alphaMap;
  13703. }
  13704. // uv repeat and offset setting priorities
  13705. // 1. color map
  13706. // 2. alpha map
  13707. let uvScaleMap;
  13708. if ( material.map ) {
  13709. uvScaleMap = material.map;
  13710. } else if ( material.alphaMap ) {
  13711. uvScaleMap = material.alphaMap;
  13712. }
  13713. if ( uvScaleMap !== undefined ) {
  13714. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13715. uvScaleMap.updateMatrix();
  13716. }
  13717. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13718. }
  13719. }
  13720. function refreshUniformsLambert( uniforms, material ) {
  13721. if ( material.emissiveMap ) {
  13722. uniforms.emissiveMap.value = material.emissiveMap;
  13723. }
  13724. }
  13725. function refreshUniformsPhong( uniforms, material ) {
  13726. uniforms.specular.value.copy( material.specular );
  13727. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13728. if ( material.emissiveMap ) {
  13729. uniforms.emissiveMap.value = material.emissiveMap;
  13730. }
  13731. if ( material.bumpMap ) {
  13732. uniforms.bumpMap.value = material.bumpMap;
  13733. uniforms.bumpScale.value = material.bumpScale;
  13734. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13735. }
  13736. if ( material.normalMap ) {
  13737. uniforms.normalMap.value = material.normalMap;
  13738. uniforms.normalScale.value.copy( material.normalScale );
  13739. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13740. }
  13741. if ( material.displacementMap ) {
  13742. uniforms.displacementMap.value = material.displacementMap;
  13743. uniforms.displacementScale.value = material.displacementScale;
  13744. uniforms.displacementBias.value = material.displacementBias;
  13745. }
  13746. }
  13747. function refreshUniformsToon( uniforms, material ) {
  13748. if ( material.gradientMap ) {
  13749. uniforms.gradientMap.value = material.gradientMap;
  13750. }
  13751. if ( material.emissiveMap ) {
  13752. uniforms.emissiveMap.value = material.emissiveMap;
  13753. }
  13754. if ( material.bumpMap ) {
  13755. uniforms.bumpMap.value = material.bumpMap;
  13756. uniforms.bumpScale.value = material.bumpScale;
  13757. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13758. }
  13759. if ( material.normalMap ) {
  13760. uniforms.normalMap.value = material.normalMap;
  13761. uniforms.normalScale.value.copy( material.normalScale );
  13762. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13763. }
  13764. if ( material.displacementMap ) {
  13765. uniforms.displacementMap.value = material.displacementMap;
  13766. uniforms.displacementScale.value = material.displacementScale;
  13767. uniforms.displacementBias.value = material.displacementBias;
  13768. }
  13769. }
  13770. function refreshUniformsStandard( uniforms, material ) {
  13771. uniforms.roughness.value = material.roughness;
  13772. uniforms.metalness.value = material.metalness;
  13773. if ( material.roughnessMap ) {
  13774. uniforms.roughnessMap.value = material.roughnessMap;
  13775. }
  13776. if ( material.metalnessMap ) {
  13777. uniforms.metalnessMap.value = material.metalnessMap;
  13778. }
  13779. if ( material.emissiveMap ) {
  13780. uniforms.emissiveMap.value = material.emissiveMap;
  13781. }
  13782. if ( material.bumpMap ) {
  13783. uniforms.bumpMap.value = material.bumpMap;
  13784. uniforms.bumpScale.value = material.bumpScale;
  13785. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13786. }
  13787. if ( material.normalMap ) {
  13788. uniforms.normalMap.value = material.normalMap;
  13789. uniforms.normalScale.value.copy( material.normalScale );
  13790. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13791. }
  13792. if ( material.displacementMap ) {
  13793. uniforms.displacementMap.value = material.displacementMap;
  13794. uniforms.displacementScale.value = material.displacementScale;
  13795. uniforms.displacementBias.value = material.displacementBias;
  13796. }
  13797. const envMap = properties.get( material ).envMap;
  13798. if ( envMap ) {
  13799. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13800. uniforms.envMapIntensity.value = material.envMapIntensity;
  13801. }
  13802. }
  13803. function refreshUniformsPhysical( uniforms, material ) {
  13804. refreshUniformsStandard( uniforms, material );
  13805. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  13806. uniforms.clearcoat.value = material.clearcoat;
  13807. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  13808. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  13809. if ( material.clearcoatMap ) {
  13810. uniforms.clearcoatMap.value = material.clearcoatMap;
  13811. }
  13812. if ( material.clearcoatRoughnessMap ) {
  13813. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  13814. }
  13815. if ( material.clearcoatNormalMap ) {
  13816. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  13817. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  13818. if ( material.side === BackSide ) {
  13819. uniforms.clearcoatNormalScale.value.negate();
  13820. }
  13821. }
  13822. uniforms.transmission.value = material.transmission;
  13823. if ( material.transmissionMap ) {
  13824. uniforms.transmissionMap.value = material.transmissionMap;
  13825. }
  13826. }
  13827. function refreshUniformsMatcap( uniforms, material ) {
  13828. if ( material.matcap ) {
  13829. uniforms.matcap.value = material.matcap;
  13830. }
  13831. if ( material.bumpMap ) {
  13832. uniforms.bumpMap.value = material.bumpMap;
  13833. uniforms.bumpScale.value = material.bumpScale;
  13834. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13835. }
  13836. if ( material.normalMap ) {
  13837. uniforms.normalMap.value = material.normalMap;
  13838. uniforms.normalScale.value.copy( material.normalScale );
  13839. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13840. }
  13841. if ( material.displacementMap ) {
  13842. uniforms.displacementMap.value = material.displacementMap;
  13843. uniforms.displacementScale.value = material.displacementScale;
  13844. uniforms.displacementBias.value = material.displacementBias;
  13845. }
  13846. }
  13847. function refreshUniformsDepth( uniforms, material ) {
  13848. if ( material.displacementMap ) {
  13849. uniforms.displacementMap.value = material.displacementMap;
  13850. uniforms.displacementScale.value = material.displacementScale;
  13851. uniforms.displacementBias.value = material.displacementBias;
  13852. }
  13853. }
  13854. function refreshUniformsDistance( uniforms, material ) {
  13855. if ( material.displacementMap ) {
  13856. uniforms.displacementMap.value = material.displacementMap;
  13857. uniforms.displacementScale.value = material.displacementScale;
  13858. uniforms.displacementBias.value = material.displacementBias;
  13859. }
  13860. uniforms.referencePosition.value.copy( material.referencePosition );
  13861. uniforms.nearDistance.value = material.nearDistance;
  13862. uniforms.farDistance.value = material.farDistance;
  13863. }
  13864. function refreshUniformsNormal( uniforms, material ) {
  13865. if ( material.bumpMap ) {
  13866. uniforms.bumpMap.value = material.bumpMap;
  13867. uniforms.bumpScale.value = material.bumpScale;
  13868. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13869. }
  13870. if ( material.normalMap ) {
  13871. uniforms.normalMap.value = material.normalMap;
  13872. uniforms.normalScale.value.copy( material.normalScale );
  13873. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13874. }
  13875. if ( material.displacementMap ) {
  13876. uniforms.displacementMap.value = material.displacementMap;
  13877. uniforms.displacementScale.value = material.displacementScale;
  13878. uniforms.displacementBias.value = material.displacementBias;
  13879. }
  13880. }
  13881. return {
  13882. refreshFogUniforms: refreshFogUniforms,
  13883. refreshMaterialUniforms: refreshMaterialUniforms
  13884. };
  13885. }
  13886. function createCanvasElement() {
  13887. const canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13888. canvas.style.display = 'block';
  13889. return canvas;
  13890. }
  13891. function WebGLRenderer( parameters ) {
  13892. parameters = parameters || {};
  13893. const _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  13894. _context = parameters.context !== undefined ? parameters.context : null,
  13895. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13896. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13897. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13898. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13899. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13900. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13901. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13902. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13903. let currentRenderList = null;
  13904. let currentRenderState = null;
  13905. // render() can be called from within a callback triggered by another render.
  13906. // We track this so that the nested render call gets its state isolated from the parent render call.
  13907. const renderStateStack = [];
  13908. // public properties
  13909. this.domElement = _canvas;
  13910. // Debug configuration container
  13911. this.debug = {
  13912. /**
  13913. * Enables error checking and reporting when shader programs are being compiled
  13914. * @type {boolean}
  13915. */
  13916. checkShaderErrors: true
  13917. };
  13918. // clearing
  13919. this.autoClear = true;
  13920. this.autoClearColor = true;
  13921. this.autoClearDepth = true;
  13922. this.autoClearStencil = true;
  13923. // scene graph
  13924. this.sortObjects = true;
  13925. // user-defined clipping
  13926. this.clippingPlanes = [];
  13927. this.localClippingEnabled = false;
  13928. // physically based shading
  13929. this.gammaFactor = 2.0; // for backwards compatibility
  13930. this.outputEncoding = LinearEncoding;
  13931. // physical lights
  13932. this.physicallyCorrectLights = false;
  13933. // tone mapping
  13934. this.toneMapping = NoToneMapping;
  13935. this.toneMappingExposure = 1.0;
  13936. // morphs
  13937. this.maxMorphTargets = 8;
  13938. this.maxMorphNormals = 4;
  13939. // internal properties
  13940. const _this = this;
  13941. let _isContextLost = false;
  13942. // internal state cache
  13943. let _framebuffer = null;
  13944. let _currentActiveCubeFace = 0;
  13945. let _currentActiveMipmapLevel = 0;
  13946. let _currentRenderTarget = null;
  13947. let _currentFramebuffer = null;
  13948. let _currentMaterialId = - 1;
  13949. let _currentCamera = null;
  13950. const _currentViewport = new Vector4();
  13951. const _currentScissor = new Vector4();
  13952. let _currentScissorTest = null;
  13953. //
  13954. let _width = _canvas.width;
  13955. let _height = _canvas.height;
  13956. let _pixelRatio = 1;
  13957. let _opaqueSort = null;
  13958. let _transparentSort = null;
  13959. const _viewport = new Vector4( 0, 0, _width, _height );
  13960. const _scissor = new Vector4( 0, 0, _width, _height );
  13961. let _scissorTest = false;
  13962. // frustum
  13963. const _frustum = new Frustum();
  13964. // clipping
  13965. let _clippingEnabled = false;
  13966. let _localClippingEnabled = false;
  13967. // camera matrices cache
  13968. const _projScreenMatrix = new Matrix4();
  13969. const _vector3 = new Vector3();
  13970. const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  13971. function getTargetPixelRatio() {
  13972. return _currentRenderTarget === null ? _pixelRatio : 1;
  13973. }
  13974. // initialize
  13975. let _gl = _context;
  13976. function getContext( contextNames, contextAttributes ) {
  13977. for ( let i = 0; i < contextNames.length; i ++ ) {
  13978. const contextName = contextNames[ i ];
  13979. const context = _canvas.getContext( contextName, contextAttributes );
  13980. if ( context !== null ) return context;
  13981. }
  13982. return null;
  13983. }
  13984. try {
  13985. const contextAttributes = {
  13986. alpha: _alpha,
  13987. depth: _depth,
  13988. stencil: _stencil,
  13989. antialias: _antialias,
  13990. premultipliedAlpha: _premultipliedAlpha,
  13991. preserveDrawingBuffer: _preserveDrawingBuffer,
  13992. powerPreference: _powerPreference,
  13993. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  13994. };
  13995. // event listeners must be registered before WebGL context is created, see #12753
  13996. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13997. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13998. if ( _gl === null ) {
  13999. const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  14000. if ( _this.isWebGL1Renderer === true ) {
  14001. contextNames.shift();
  14002. }
  14003. _gl = getContext( contextNames, contextAttributes );
  14004. if ( _gl === null ) {
  14005. if ( getContext( contextNames ) ) {
  14006. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14007. } else {
  14008. throw new Error( 'Error creating WebGL context.' );
  14009. }
  14010. }
  14011. }
  14012. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14013. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14014. _gl.getShaderPrecisionFormat = function () {
  14015. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14016. };
  14017. }
  14018. } catch ( error ) {
  14019. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14020. throw error;
  14021. }
  14022. let extensions, capabilities, state, info;
  14023. let properties, textures, cubemaps, attributes, geometries, objects;
  14024. let programCache, materials, renderLists, renderStates, clipping;
  14025. let background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14026. let utils, bindingStates;
  14027. function initGLContext() {
  14028. extensions = new WebGLExtensions( _gl );
  14029. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14030. if ( capabilities.isWebGL2 ) {
  14031. extensions.get( 'EXT_color_buffer_float' );
  14032. } else {
  14033. extensions.get( 'WEBGL_depth_texture' );
  14034. extensions.get( 'OES_texture_float' );
  14035. extensions.get( 'OES_texture_half_float' );
  14036. extensions.get( 'OES_texture_half_float_linear' );
  14037. extensions.get( 'OES_standard_derivatives' );
  14038. extensions.get( 'OES_element_index_uint' );
  14039. extensions.get( 'OES_vertex_array_object' );
  14040. extensions.get( 'ANGLE_instanced_arrays' );
  14041. }
  14042. extensions.get( 'OES_texture_float_linear' );
  14043. extensions.get( 'EXT_color_buffer_half_float' );
  14044. utils = new WebGLUtils( _gl, extensions, capabilities );
  14045. state = new WebGLState( _gl, extensions, capabilities );
  14046. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14047. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14048. info = new WebGLInfo( _gl );
  14049. properties = new WebGLProperties();
  14050. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14051. cubemaps = new WebGLCubeMaps( _this );
  14052. attributes = new WebGLAttributes( _gl, capabilities );
  14053. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  14054. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  14055. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14056. morphtargets = new WebGLMorphtargets( _gl );
  14057. clipping = new WebGLClipping( properties );
  14058. programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates, clipping );
  14059. materials = new WebGLMaterials( properties );
  14060. renderLists = new WebGLRenderLists( properties );
  14061. renderStates = new WebGLRenderStates( extensions, capabilities );
  14062. background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
  14063. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14064. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14065. info.programs = programCache.programs;
  14066. _this.capabilities = capabilities;
  14067. _this.extensions = extensions;
  14068. _this.properties = properties;
  14069. _this.renderLists = renderLists;
  14070. _this.state = state;
  14071. _this.info = info;
  14072. }
  14073. initGLContext();
  14074. // xr
  14075. const xr = new WebXRManager( _this, _gl );
  14076. this.xr = xr;
  14077. // shadow map
  14078. const shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14079. this.shadowMap = shadowMap;
  14080. // API
  14081. this.getContext = function () {
  14082. return _gl;
  14083. };
  14084. this.getContextAttributes = function () {
  14085. return _gl.getContextAttributes();
  14086. };
  14087. this.forceContextLoss = function () {
  14088. const extension = extensions.get( 'WEBGL_lose_context' );
  14089. if ( extension ) extension.loseContext();
  14090. };
  14091. this.forceContextRestore = function () {
  14092. const extension = extensions.get( 'WEBGL_lose_context' );
  14093. if ( extension ) extension.restoreContext();
  14094. };
  14095. this.getPixelRatio = function () {
  14096. return _pixelRatio;
  14097. };
  14098. this.setPixelRatio = function ( value ) {
  14099. if ( value === undefined ) return;
  14100. _pixelRatio = value;
  14101. this.setSize( _width, _height, false );
  14102. };
  14103. this.getSize = function ( target ) {
  14104. if ( target === undefined ) {
  14105. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14106. target = new Vector2();
  14107. }
  14108. return target.set( _width, _height );
  14109. };
  14110. this.setSize = function ( width, height, updateStyle ) {
  14111. if ( xr.isPresenting ) {
  14112. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14113. return;
  14114. }
  14115. _width = width;
  14116. _height = height;
  14117. _canvas.width = Math.floor( width * _pixelRatio );
  14118. _canvas.height = Math.floor( height * _pixelRatio );
  14119. if ( updateStyle !== false ) {
  14120. _canvas.style.width = width + 'px';
  14121. _canvas.style.height = height + 'px';
  14122. }
  14123. this.setViewport( 0, 0, width, height );
  14124. };
  14125. this.getDrawingBufferSize = function ( target ) {
  14126. if ( target === undefined ) {
  14127. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14128. target = new Vector2();
  14129. }
  14130. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14131. };
  14132. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14133. _width = width;
  14134. _height = height;
  14135. _pixelRatio = pixelRatio;
  14136. _canvas.width = Math.floor( width * pixelRatio );
  14137. _canvas.height = Math.floor( height * pixelRatio );
  14138. this.setViewport( 0, 0, width, height );
  14139. };
  14140. this.getCurrentViewport = function ( target ) {
  14141. if ( target === undefined ) {
  14142. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14143. target = new Vector4();
  14144. }
  14145. return target.copy( _currentViewport );
  14146. };
  14147. this.getViewport = function ( target ) {
  14148. return target.copy( _viewport );
  14149. };
  14150. this.setViewport = function ( x, y, width, height ) {
  14151. if ( x.isVector4 ) {
  14152. _viewport.set( x.x, x.y, x.z, x.w );
  14153. } else {
  14154. _viewport.set( x, y, width, height );
  14155. }
  14156. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14157. };
  14158. this.getScissor = function ( target ) {
  14159. return target.copy( _scissor );
  14160. };
  14161. this.setScissor = function ( x, y, width, height ) {
  14162. if ( x.isVector4 ) {
  14163. _scissor.set( x.x, x.y, x.z, x.w );
  14164. } else {
  14165. _scissor.set( x, y, width, height );
  14166. }
  14167. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14168. };
  14169. this.getScissorTest = function () {
  14170. return _scissorTest;
  14171. };
  14172. this.setScissorTest = function ( boolean ) {
  14173. state.setScissorTest( _scissorTest = boolean );
  14174. };
  14175. this.setOpaqueSort = function ( method ) {
  14176. _opaqueSort = method;
  14177. };
  14178. this.setTransparentSort = function ( method ) {
  14179. _transparentSort = method;
  14180. };
  14181. // Clearing
  14182. this.getClearColor = function ( target ) {
  14183. if ( target === undefined ) {
  14184. console.warn( 'WebGLRenderer: .getClearColor() now requires a Color as an argument' );
  14185. target = new Color();
  14186. }
  14187. return target.copy( background.getClearColor() );
  14188. };
  14189. this.setClearColor = function () {
  14190. background.setClearColor.apply( background, arguments );
  14191. };
  14192. this.getClearAlpha = function () {
  14193. return background.getClearAlpha();
  14194. };
  14195. this.setClearAlpha = function () {
  14196. background.setClearAlpha.apply( background, arguments );
  14197. };
  14198. this.clear = function ( color, depth, stencil ) {
  14199. let bits = 0;
  14200. if ( color === undefined || color ) bits |= 16384;
  14201. if ( depth === undefined || depth ) bits |= 256;
  14202. if ( stencil === undefined || stencil ) bits |= 1024;
  14203. _gl.clear( bits );
  14204. };
  14205. this.clearColor = function () {
  14206. this.clear( true, false, false );
  14207. };
  14208. this.clearDepth = function () {
  14209. this.clear( false, true, false );
  14210. };
  14211. this.clearStencil = function () {
  14212. this.clear( false, false, true );
  14213. };
  14214. //
  14215. this.dispose = function () {
  14216. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14217. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14218. renderLists.dispose();
  14219. renderStates.dispose();
  14220. properties.dispose();
  14221. cubemaps.dispose();
  14222. objects.dispose();
  14223. bindingStates.dispose();
  14224. xr.dispose();
  14225. animation.stop();
  14226. };
  14227. // Events
  14228. function onContextLost( event ) {
  14229. event.preventDefault();
  14230. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14231. _isContextLost = true;
  14232. }
  14233. function onContextRestore( /* event */ ) {
  14234. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14235. _isContextLost = false;
  14236. initGLContext();
  14237. }
  14238. function onMaterialDispose( event ) {
  14239. const material = event.target;
  14240. material.removeEventListener( 'dispose', onMaterialDispose );
  14241. deallocateMaterial( material );
  14242. }
  14243. // Buffer deallocation
  14244. function deallocateMaterial( material ) {
  14245. releaseMaterialProgramReference( material );
  14246. properties.remove( material );
  14247. }
  14248. function releaseMaterialProgramReference( material ) {
  14249. const programInfo = properties.get( material ).program;
  14250. if ( programInfo !== undefined ) {
  14251. programCache.releaseProgram( programInfo );
  14252. }
  14253. }
  14254. // Buffer rendering
  14255. function renderObjectImmediate( object, program ) {
  14256. object.render( function ( object ) {
  14257. _this.renderBufferImmediate( object, program );
  14258. } );
  14259. }
  14260. this.renderBufferImmediate = function ( object, program ) {
  14261. bindingStates.initAttributes();
  14262. const buffers = properties.get( object );
  14263. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14264. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14265. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14266. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14267. const programAttributes = program.getAttributes();
  14268. if ( object.hasPositions ) {
  14269. _gl.bindBuffer( 34962, buffers.position );
  14270. _gl.bufferData( 34962, object.positionArray, 35048 );
  14271. bindingStates.enableAttribute( programAttributes.position );
  14272. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14273. }
  14274. if ( object.hasNormals ) {
  14275. _gl.bindBuffer( 34962, buffers.normal );
  14276. _gl.bufferData( 34962, object.normalArray, 35048 );
  14277. bindingStates.enableAttribute( programAttributes.normal );
  14278. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14279. }
  14280. if ( object.hasUvs ) {
  14281. _gl.bindBuffer( 34962, buffers.uv );
  14282. _gl.bufferData( 34962, object.uvArray, 35048 );
  14283. bindingStates.enableAttribute( programAttributes.uv );
  14284. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14285. }
  14286. if ( object.hasColors ) {
  14287. _gl.bindBuffer( 34962, buffers.color );
  14288. _gl.bufferData( 34962, object.colorArray, 35048 );
  14289. bindingStates.enableAttribute( programAttributes.color );
  14290. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14291. }
  14292. bindingStates.disableUnusedAttributes();
  14293. _gl.drawArrays( 4, 0, object.count );
  14294. object.count = 0;
  14295. };
  14296. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  14297. if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14298. const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14299. const program = setProgram( camera, scene, material, object );
  14300. state.setMaterial( material, frontFaceCW );
  14301. //
  14302. let index = geometry.index;
  14303. const position = geometry.attributes.position;
  14304. //
  14305. if ( index === null ) {
  14306. if ( position === undefined || position.count === 0 ) return;
  14307. } else if ( index.count === 0 ) {
  14308. return;
  14309. }
  14310. //
  14311. let rangeFactor = 1;
  14312. if ( material.wireframe === true ) {
  14313. index = geometries.getWireframeAttribute( geometry );
  14314. rangeFactor = 2;
  14315. }
  14316. if ( material.morphTargets || material.morphNormals ) {
  14317. morphtargets.update( object, geometry, material, program );
  14318. }
  14319. bindingStates.setup( object, material, program, geometry, index );
  14320. let attribute;
  14321. let renderer = bufferRenderer;
  14322. if ( index !== null ) {
  14323. attribute = attributes.get( index );
  14324. renderer = indexedBufferRenderer;
  14325. renderer.setIndex( attribute );
  14326. }
  14327. //
  14328. const dataCount = ( index !== null ) ? index.count : position.count;
  14329. const rangeStart = geometry.drawRange.start * rangeFactor;
  14330. const rangeCount = geometry.drawRange.count * rangeFactor;
  14331. const groupStart = group !== null ? group.start * rangeFactor : 0;
  14332. const groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14333. const drawStart = Math.max( rangeStart, groupStart );
  14334. const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14335. const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14336. if ( drawCount === 0 ) return;
  14337. //
  14338. if ( object.isMesh ) {
  14339. if ( material.wireframe === true ) {
  14340. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14341. renderer.setMode( 1 );
  14342. } else {
  14343. renderer.setMode( 4 );
  14344. }
  14345. } else if ( object.isLine ) {
  14346. let lineWidth = material.linewidth;
  14347. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14348. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14349. if ( object.isLineSegments ) {
  14350. renderer.setMode( 1 );
  14351. } else if ( object.isLineLoop ) {
  14352. renderer.setMode( 2 );
  14353. } else {
  14354. renderer.setMode( 3 );
  14355. }
  14356. } else if ( object.isPoints ) {
  14357. renderer.setMode( 0 );
  14358. } else if ( object.isSprite ) {
  14359. renderer.setMode( 4 );
  14360. }
  14361. if ( object.isInstancedMesh ) {
  14362. renderer.renderInstances( drawStart, drawCount, object.count );
  14363. } else if ( geometry.isInstancedBufferGeometry ) {
  14364. const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  14365. renderer.renderInstances( drawStart, drawCount, instanceCount );
  14366. } else {
  14367. renderer.render( drawStart, drawCount );
  14368. }
  14369. };
  14370. // Compile
  14371. this.compile = function ( scene, camera ) {
  14372. currentRenderState = renderStates.get( scene );
  14373. currentRenderState.init();
  14374. scene.traverseVisible( function ( object ) {
  14375. if ( object.isLight && object.layers.test( camera.layers ) ) {
  14376. currentRenderState.pushLight( object );
  14377. if ( object.castShadow ) {
  14378. currentRenderState.pushShadow( object );
  14379. }
  14380. }
  14381. } );
  14382. currentRenderState.setupLights();
  14383. const compiled = new WeakMap();
  14384. scene.traverse( function ( object ) {
  14385. const material = object.material;
  14386. if ( material ) {
  14387. if ( Array.isArray( material ) ) {
  14388. for ( let i = 0; i < material.length; i ++ ) {
  14389. const material2 = material[ i ];
  14390. if ( compiled.has( material2 ) === false ) {
  14391. initMaterial( material2, scene, object );
  14392. compiled.set( material2 );
  14393. }
  14394. }
  14395. } else if ( compiled.has( material ) === false ) {
  14396. initMaterial( material, scene, object );
  14397. compiled.set( material );
  14398. }
  14399. }
  14400. } );
  14401. };
  14402. // Animation Loop
  14403. let onAnimationFrameCallback = null;
  14404. function onAnimationFrame( time ) {
  14405. if ( xr.isPresenting ) return;
  14406. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14407. }
  14408. const animation = new WebGLAnimation();
  14409. animation.setAnimationLoop( onAnimationFrame );
  14410. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14411. this.setAnimationLoop = function ( callback ) {
  14412. onAnimationFrameCallback = callback;
  14413. xr.setAnimationLoop( callback );
  14414. ( callback === null ) ? animation.stop() : animation.start();
  14415. };
  14416. // Rendering
  14417. this.render = function ( scene, camera ) {
  14418. let renderTarget, forceClear;
  14419. if ( arguments[ 2 ] !== undefined ) {
  14420. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14421. renderTarget = arguments[ 2 ];
  14422. }
  14423. if ( arguments[ 3 ] !== undefined ) {
  14424. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14425. forceClear = arguments[ 3 ];
  14426. }
  14427. if ( camera !== undefined && camera.isCamera !== true ) {
  14428. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14429. return;
  14430. }
  14431. if ( _isContextLost === true ) return;
  14432. // reset caching for this frame
  14433. bindingStates.resetDefaultState();
  14434. _currentMaterialId = - 1;
  14435. _currentCamera = null;
  14436. // update scene graph
  14437. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14438. // update camera matrices and frustum
  14439. if ( camera.parent === null ) camera.updateMatrixWorld();
  14440. if ( xr.enabled === true && xr.isPresenting === true ) {
  14441. camera = xr.getCamera( camera );
  14442. }
  14443. //
  14444. if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14445. currentRenderState = renderStates.get( scene, renderStateStack.length );
  14446. currentRenderState.init();
  14447. renderStateStack.push( currentRenderState );
  14448. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14449. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  14450. _localClippingEnabled = this.localClippingEnabled;
  14451. _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14452. currentRenderList = renderLists.get( scene, camera );
  14453. currentRenderList.init();
  14454. projectObject( scene, camera, 0, _this.sortObjects );
  14455. currentRenderList.finish();
  14456. if ( _this.sortObjects === true ) {
  14457. currentRenderList.sort( _opaqueSort, _transparentSort );
  14458. }
  14459. //
  14460. if ( _clippingEnabled === true ) clipping.beginShadows();
  14461. const shadowsArray = currentRenderState.state.shadowsArray;
  14462. shadowMap.render( shadowsArray, scene, camera );
  14463. currentRenderState.setupLights();
  14464. currentRenderState.setupLightsView( camera );
  14465. if ( _clippingEnabled === true ) clipping.endShadows();
  14466. //
  14467. if ( this.info.autoReset === true ) this.info.reset();
  14468. if ( renderTarget !== undefined ) {
  14469. this.setRenderTarget( renderTarget );
  14470. }
  14471. //
  14472. background.render( currentRenderList, scene, camera, forceClear );
  14473. // render scene
  14474. const opaqueObjects = currentRenderList.opaque;
  14475. const transparentObjects = currentRenderList.transparent;
  14476. if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
  14477. if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
  14478. //
  14479. if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
  14480. //
  14481. if ( _currentRenderTarget !== null ) {
  14482. // Generate mipmap if we're using any kind of mipmap filtering
  14483. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14484. // resolve multisample renderbuffers to a single-sample texture if necessary
  14485. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14486. }
  14487. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14488. state.buffers.depth.setTest( true );
  14489. state.buffers.depth.setMask( true );
  14490. state.buffers.color.setMask( true );
  14491. state.setPolygonOffset( false );
  14492. // _gl.finish();
  14493. renderStateStack.pop();
  14494. if ( renderStateStack.length > 0 ) {
  14495. currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
  14496. } else {
  14497. currentRenderState = null;
  14498. }
  14499. currentRenderList = null;
  14500. };
  14501. function projectObject( object, camera, groupOrder, sortObjects ) {
  14502. if ( object.visible === false ) return;
  14503. const visible = object.layers.test( camera.layers );
  14504. if ( visible ) {
  14505. if ( object.isGroup ) {
  14506. groupOrder = object.renderOrder;
  14507. } else if ( object.isLOD ) {
  14508. if ( object.autoUpdate === true ) object.update( camera );
  14509. } else if ( object.isLight ) {
  14510. currentRenderState.pushLight( object );
  14511. if ( object.castShadow ) {
  14512. currentRenderState.pushShadow( object );
  14513. }
  14514. } else if ( object.isSprite ) {
  14515. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14516. if ( sortObjects ) {
  14517. _vector3.setFromMatrixPosition( object.matrixWorld )
  14518. .applyMatrix4( _projScreenMatrix );
  14519. }
  14520. const geometry = objects.update( object );
  14521. const material = object.material;
  14522. if ( material.visible ) {
  14523. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14524. }
  14525. }
  14526. } else if ( object.isImmediateRenderObject ) {
  14527. if ( sortObjects ) {
  14528. _vector3.setFromMatrixPosition( object.matrixWorld )
  14529. .applyMatrix4( _projScreenMatrix );
  14530. }
  14531. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14532. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14533. if ( object.isSkinnedMesh ) {
  14534. // update skeleton only once in a frame
  14535. if ( object.skeleton.frame !== info.render.frame ) {
  14536. object.skeleton.update();
  14537. object.skeleton.frame = info.render.frame;
  14538. }
  14539. }
  14540. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14541. if ( sortObjects ) {
  14542. _vector3.setFromMatrixPosition( object.matrixWorld )
  14543. .applyMatrix4( _projScreenMatrix );
  14544. }
  14545. const geometry = objects.update( object );
  14546. const material = object.material;
  14547. if ( Array.isArray( material ) ) {
  14548. const groups = geometry.groups;
  14549. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  14550. const group = groups[ i ];
  14551. const groupMaterial = material[ group.materialIndex ];
  14552. if ( groupMaterial && groupMaterial.visible ) {
  14553. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14554. }
  14555. }
  14556. } else if ( material.visible ) {
  14557. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14558. }
  14559. }
  14560. }
  14561. }
  14562. const children = object.children;
  14563. for ( let i = 0, l = children.length; i < l; i ++ ) {
  14564. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14565. }
  14566. }
  14567. function renderObjects( renderList, scene, camera ) {
  14568. const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14569. for ( let i = 0, l = renderList.length; i < l; i ++ ) {
  14570. const renderItem = renderList[ i ];
  14571. const object = renderItem.object;
  14572. const geometry = renderItem.geometry;
  14573. const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14574. const group = renderItem.group;
  14575. if ( camera.isArrayCamera ) {
  14576. const cameras = camera.cameras;
  14577. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  14578. const camera2 = cameras[ j ];
  14579. if ( object.layers.test( camera2.layers ) ) {
  14580. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14581. currentRenderState.setupLightsView( camera2 );
  14582. renderObject( object, scene, camera2, geometry, material, group );
  14583. }
  14584. }
  14585. } else {
  14586. renderObject( object, scene, camera, geometry, material, group );
  14587. }
  14588. }
  14589. }
  14590. function renderObject( object, scene, camera, geometry, material, group ) {
  14591. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14592. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14593. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14594. if ( object.isImmediateRenderObject ) {
  14595. const program = setProgram( camera, scene, material, object );
  14596. state.setMaterial( material );
  14597. bindingStates.reset();
  14598. renderObjectImmediate( object, program );
  14599. } else {
  14600. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  14601. }
  14602. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14603. }
  14604. function initMaterial( material, scene, object ) {
  14605. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14606. const materialProperties = properties.get( material );
  14607. const lights = currentRenderState.state.lights;
  14608. const shadowsArray = currentRenderState.state.shadowsArray;
  14609. const lightsStateVersion = lights.state.version;
  14610. const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
  14611. const programCacheKey = programCache.getProgramCacheKey( parameters );
  14612. let program = materialProperties.program;
  14613. let programChange = true;
  14614. // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  14615. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14616. materialProperties.fog = scene.fog;
  14617. materialProperties.envMap = cubemaps.get( material.envMap || materialProperties.environment );
  14618. if ( program === undefined ) {
  14619. // new material
  14620. material.addEventListener( 'dispose', onMaterialDispose );
  14621. } else if ( program.cacheKey !== programCacheKey ) {
  14622. // changed glsl or parameters
  14623. releaseMaterialProgramReference( material );
  14624. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14625. programChange = false;
  14626. } else if ( parameters.shaderID !== undefined ) {
  14627. // same glsl and uniform list
  14628. return;
  14629. } else {
  14630. // only rebuild uniform list
  14631. programChange = false;
  14632. }
  14633. if ( programChange ) {
  14634. parameters.uniforms = programCache.getUniforms( material );
  14635. material.onBeforeCompile( parameters, _this );
  14636. program = programCache.acquireProgram( parameters, programCacheKey );
  14637. materialProperties.program = program;
  14638. materialProperties.uniforms = parameters.uniforms;
  14639. materialProperties.outputEncoding = parameters.outputEncoding;
  14640. }
  14641. const uniforms = materialProperties.uniforms;
  14642. if ( ! material.isShaderMaterial &&
  14643. ! material.isRawShaderMaterial ||
  14644. material.clipping === true ) {
  14645. materialProperties.numClippingPlanes = clipping.numPlanes;
  14646. materialProperties.numIntersection = clipping.numIntersection;
  14647. uniforms.clippingPlanes = clipping.uniform;
  14648. }
  14649. // store the light setup it was created for
  14650. materialProperties.needsLights = materialNeedsLights( material );
  14651. materialProperties.lightsStateVersion = lightsStateVersion;
  14652. if ( materialProperties.needsLights ) {
  14653. // wire up the material to this renderer's lighting state
  14654. uniforms.ambientLightColor.value = lights.state.ambient;
  14655. uniforms.lightProbe.value = lights.state.probe;
  14656. uniforms.directionalLights.value = lights.state.directional;
  14657. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14658. uniforms.spotLights.value = lights.state.spot;
  14659. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14660. uniforms.rectAreaLights.value = lights.state.rectArea;
  14661. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14662. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14663. uniforms.pointLights.value = lights.state.point;
  14664. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14665. uniforms.hemisphereLights.value = lights.state.hemi;
  14666. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14667. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14668. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14669. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14670. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14671. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14672. // TODO (abelnation): add area lights shadow info to uniforms
  14673. }
  14674. const progUniforms = materialProperties.program.getUniforms();
  14675. const uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14676. materialProperties.uniformsList = uniformsList;
  14677. }
  14678. function setProgram( camera, scene, material, object ) {
  14679. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14680. textures.resetTextureUnits();
  14681. const fog = scene.fog;
  14682. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  14683. const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14684. const envMap = cubemaps.get( material.envMap || environment );
  14685. const materialProperties = properties.get( material );
  14686. const lights = currentRenderState.state.lights;
  14687. if ( _clippingEnabled === true ) {
  14688. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  14689. const useCache =
  14690. camera === _currentCamera &&
  14691. material.id === _currentMaterialId;
  14692. // we might want to call this function with some ClippingGroup
  14693. // object instead of the material, once it becomes feasible
  14694. // (#8465, #8379)
  14695. clipping.setState( material, camera, useCache );
  14696. }
  14697. }
  14698. if ( material.version === materialProperties.__version ) {
  14699. if ( material.fog && materialProperties.fog !== fog ) {
  14700. initMaterial( material, scene, object );
  14701. } else if ( materialProperties.environment !== environment ) {
  14702. initMaterial( material, scene, object );
  14703. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  14704. initMaterial( material, scene, object );
  14705. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14706. ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
  14707. materialProperties.numIntersection !== clipping.numIntersection ) ) {
  14708. initMaterial( material, scene, object );
  14709. } else if ( materialProperties.outputEncoding !== encoding ) {
  14710. initMaterial( material, scene, object );
  14711. } else if ( materialProperties.envMap !== envMap ) {
  14712. initMaterial( material, scene, object );
  14713. }
  14714. } else {
  14715. initMaterial( material, scene, object );
  14716. materialProperties.__version = material.version;
  14717. }
  14718. let refreshProgram = false;
  14719. let refreshMaterial = false;
  14720. let refreshLights = false;
  14721. const program = materialProperties.program,
  14722. p_uniforms = program.getUniforms(),
  14723. m_uniforms = materialProperties.uniforms;
  14724. if ( state.useProgram( program.program ) ) {
  14725. refreshProgram = true;
  14726. refreshMaterial = true;
  14727. refreshLights = true;
  14728. }
  14729. if ( material.id !== _currentMaterialId ) {
  14730. _currentMaterialId = material.id;
  14731. refreshMaterial = true;
  14732. }
  14733. if ( refreshProgram || _currentCamera !== camera ) {
  14734. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14735. if ( capabilities.logarithmicDepthBuffer ) {
  14736. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14737. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14738. }
  14739. if ( _currentCamera !== camera ) {
  14740. _currentCamera = camera;
  14741. // lighting uniforms depend on the camera so enforce an update
  14742. // now, in case this material supports lights - or later, when
  14743. // the next material that does gets activated:
  14744. refreshMaterial = true; // set to true on material change
  14745. refreshLights = true; // remains set until update done
  14746. }
  14747. // load material specific uniforms
  14748. // (shader material also gets them for the sake of genericity)
  14749. if ( material.isShaderMaterial ||
  14750. material.isMeshPhongMaterial ||
  14751. material.isMeshToonMaterial ||
  14752. material.isMeshStandardMaterial ||
  14753. material.envMap ) {
  14754. const uCamPos = p_uniforms.map.cameraPosition;
  14755. if ( uCamPos !== undefined ) {
  14756. uCamPos.setValue( _gl,
  14757. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14758. }
  14759. }
  14760. if ( material.isMeshPhongMaterial ||
  14761. material.isMeshToonMaterial ||
  14762. material.isMeshLambertMaterial ||
  14763. material.isMeshBasicMaterial ||
  14764. material.isMeshStandardMaterial ||
  14765. material.isShaderMaterial ) {
  14766. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  14767. }
  14768. if ( material.isMeshPhongMaterial ||
  14769. material.isMeshToonMaterial ||
  14770. material.isMeshLambertMaterial ||
  14771. material.isMeshBasicMaterial ||
  14772. material.isMeshStandardMaterial ||
  14773. material.isShaderMaterial ||
  14774. material.isShadowMaterial ||
  14775. material.skinning ) {
  14776. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14777. }
  14778. }
  14779. // skinning uniforms must be set even if material didn't change
  14780. // auto-setting of texture unit for bone texture must go before other textures
  14781. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14782. if ( material.skinning ) {
  14783. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14784. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14785. const skeleton = object.skeleton;
  14786. if ( skeleton ) {
  14787. const bones = skeleton.bones;
  14788. if ( capabilities.floatVertexTextures ) {
  14789. if ( skeleton.boneTexture === null ) {
  14790. // layout (1 matrix = 4 pixels)
  14791. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14792. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14793. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14794. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14795. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14796. let size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14797. size = MathUtils.ceilPowerOfTwo( size );
  14798. size = Math.max( size, 4 );
  14799. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14800. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14801. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14802. skeleton.boneMatrices = boneMatrices;
  14803. skeleton.boneTexture = boneTexture;
  14804. skeleton.boneTextureSize = size;
  14805. }
  14806. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14807. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14808. } else {
  14809. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14810. }
  14811. }
  14812. }
  14813. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  14814. materialProperties.receiveShadow = object.receiveShadow;
  14815. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  14816. }
  14817. if ( refreshMaterial ) {
  14818. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14819. if ( materialProperties.needsLights ) {
  14820. // the current material requires lighting info
  14821. // note: all lighting uniforms are always set correctly
  14822. // they simply reference the renderer's state for their
  14823. // values
  14824. //
  14825. // use the current material's .needsUpdate flags to set
  14826. // the GL state when required
  14827. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14828. }
  14829. // refresh uniforms common to several materials
  14830. if ( fog && material.fog ) {
  14831. materials.refreshFogUniforms( m_uniforms, fog );
  14832. }
  14833. materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height );
  14834. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14835. }
  14836. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14837. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14838. material.uniformsNeedUpdate = false;
  14839. }
  14840. if ( material.isSpriteMaterial ) {
  14841. p_uniforms.setValue( _gl, 'center', object.center );
  14842. }
  14843. // common matrices
  14844. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14845. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14846. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14847. return program;
  14848. }
  14849. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14850. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14851. uniforms.ambientLightColor.needsUpdate = value;
  14852. uniforms.lightProbe.needsUpdate = value;
  14853. uniforms.directionalLights.needsUpdate = value;
  14854. uniforms.directionalLightShadows.needsUpdate = value;
  14855. uniforms.pointLights.needsUpdate = value;
  14856. uniforms.pointLightShadows.needsUpdate = value;
  14857. uniforms.spotLights.needsUpdate = value;
  14858. uniforms.spotLightShadows.needsUpdate = value;
  14859. uniforms.rectAreaLights.needsUpdate = value;
  14860. uniforms.hemisphereLights.needsUpdate = value;
  14861. }
  14862. function materialNeedsLights( material ) {
  14863. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  14864. material.isMeshStandardMaterial || material.isShadowMaterial ||
  14865. ( material.isShaderMaterial && material.lights === true );
  14866. }
  14867. //
  14868. this.setFramebuffer = function ( value ) {
  14869. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  14870. _framebuffer = value;
  14871. };
  14872. this.getActiveCubeFace = function () {
  14873. return _currentActiveCubeFace;
  14874. };
  14875. this.getActiveMipmapLevel = function () {
  14876. return _currentActiveMipmapLevel;
  14877. };
  14878. this.getRenderList = function () {
  14879. return currentRenderList;
  14880. };
  14881. this.setRenderList = function ( renderList ) {
  14882. currentRenderList = renderList;
  14883. };
  14884. this.getRenderTarget = function () {
  14885. return _currentRenderTarget;
  14886. };
  14887. this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  14888. _currentRenderTarget = renderTarget;
  14889. _currentActiveCubeFace = activeCubeFace;
  14890. _currentActiveMipmapLevel = activeMipmapLevel;
  14891. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14892. textures.setupRenderTarget( renderTarget );
  14893. }
  14894. let framebuffer = _framebuffer;
  14895. let isCube = false;
  14896. if ( renderTarget ) {
  14897. const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14898. if ( renderTarget.isWebGLCubeRenderTarget ) {
  14899. framebuffer = __webglFramebuffer[ activeCubeFace ];
  14900. isCube = true;
  14901. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14902. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14903. } else {
  14904. framebuffer = __webglFramebuffer;
  14905. }
  14906. _currentViewport.copy( renderTarget.viewport );
  14907. _currentScissor.copy( renderTarget.scissor );
  14908. _currentScissorTest = renderTarget.scissorTest;
  14909. } else {
  14910. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  14911. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  14912. _currentScissorTest = _scissorTest;
  14913. }
  14914. if ( _currentFramebuffer !== framebuffer ) {
  14915. _gl.bindFramebuffer( 36160, framebuffer );
  14916. _currentFramebuffer = framebuffer;
  14917. }
  14918. state.viewport( _currentViewport );
  14919. state.scissor( _currentScissor );
  14920. state.setScissorTest( _currentScissorTest );
  14921. if ( isCube ) {
  14922. const textureProperties = properties.get( renderTarget.texture );
  14923. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
  14924. }
  14925. };
  14926. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  14927. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14928. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14929. return;
  14930. }
  14931. let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14932. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  14933. framebuffer = framebuffer[ activeCubeFaceIndex ];
  14934. }
  14935. if ( framebuffer ) {
  14936. let restore = false;
  14937. if ( framebuffer !== _currentFramebuffer ) {
  14938. _gl.bindFramebuffer( 36160, framebuffer );
  14939. restore = true;
  14940. }
  14941. try {
  14942. const texture = renderTarget.texture;
  14943. const textureFormat = texture.format;
  14944. const textureType = texture.type;
  14945. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14946. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14947. return;
  14948. }
  14949. const halfFloatSupportedByExt = ( textureType === HalfFloatType ) && ( extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ) );
  14950. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14951. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.has( 'OES_texture_float' ) || extensions.has( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14952. ! halfFloatSupportedByExt ) {
  14953. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14954. return;
  14955. }
  14956. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14957. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14958. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14959. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14960. }
  14961. } else {
  14962. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14963. }
  14964. } finally {
  14965. if ( restore ) {
  14966. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14967. }
  14968. }
  14969. }
  14970. };
  14971. this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
  14972. const levelScale = Math.pow( 2, - level );
  14973. const width = Math.floor( texture.image.width * levelScale );
  14974. const height = Math.floor( texture.image.height * levelScale );
  14975. const glFormat = utils.convert( texture.format );
  14976. textures.setTexture2D( texture, 0 );
  14977. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  14978. state.unbindTexture();
  14979. };
  14980. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
  14981. const width = srcTexture.image.width;
  14982. const height = srcTexture.image.height;
  14983. const glFormat = utils.convert( dstTexture.format );
  14984. const glType = utils.convert( dstTexture.type );
  14985. textures.setTexture2D( dstTexture, 0 );
  14986. // As another texture upload may have changed pixelStorei
  14987. // parameters, make sure they are correct for the dstTexture
  14988. _gl.pixelStorei( 37440, dstTexture.flipY );
  14989. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  14990. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  14991. if ( srcTexture.isDataTexture ) {
  14992. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14993. } else {
  14994. if ( srcTexture.isCompressedTexture ) {
  14995. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  14996. } else {
  14997. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  14998. }
  14999. }
  15000. // Generate mipmaps only when copying level 0
  15001. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  15002. state.unbindTexture();
  15003. };
  15004. this.initTexture = function ( texture ) {
  15005. textures.setTexture2D( texture, 0 );
  15006. state.unbindTexture();
  15007. };
  15008. this.resetState = function () {
  15009. state.reset();
  15010. bindingStates.reset();
  15011. };
  15012. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15013. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15014. }
  15015. }
  15016. function WebGL1Renderer( parameters ) {
  15017. WebGLRenderer.call( this, parameters );
  15018. }
  15019. WebGL1Renderer.prototype = Object.assign( Object.create( WebGLRenderer.prototype ), {
  15020. constructor: WebGL1Renderer,
  15021. isWebGL1Renderer: true
  15022. } );
  15023. class FogExp2 {
  15024. constructor( color, density ) {
  15025. Object.defineProperty( this, 'isFogExp2', { value: true } );
  15026. this.name = '';
  15027. this.color = new Color( color );
  15028. this.density = ( density !== undefined ) ? density : 0.00025;
  15029. }
  15030. clone() {
  15031. return new FogExp2( this.color, this.density );
  15032. }
  15033. toJSON( /* meta */ ) {
  15034. return {
  15035. type: 'FogExp2',
  15036. color: this.color.getHex(),
  15037. density: this.density
  15038. };
  15039. }
  15040. }
  15041. class Fog {
  15042. constructor( color, near, far ) {
  15043. Object.defineProperty( this, 'isFog', { value: true } );
  15044. this.name = '';
  15045. this.color = new Color( color );
  15046. this.near = ( near !== undefined ) ? near : 1;
  15047. this.far = ( far !== undefined ) ? far : 1000;
  15048. }
  15049. clone() {
  15050. return new Fog( this.color, this.near, this.far );
  15051. }
  15052. toJSON( /* meta */ ) {
  15053. return {
  15054. type: 'Fog',
  15055. color: this.color.getHex(),
  15056. near: this.near,
  15057. far: this.far
  15058. };
  15059. }
  15060. }
  15061. class Scene extends Object3D {
  15062. constructor() {
  15063. super();
  15064. Object.defineProperty( this, 'isScene', { value: true } );
  15065. this.type = 'Scene';
  15066. this.background = null;
  15067. this.environment = null;
  15068. this.fog = null;
  15069. this.overrideMaterial = null;
  15070. this.autoUpdate = true; // checked by the renderer
  15071. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15072. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15073. }
  15074. }
  15075. copy( source, recursive ) {
  15076. super.copy( source, recursive );
  15077. if ( source.background !== null ) this.background = source.background.clone();
  15078. if ( source.environment !== null ) this.environment = source.environment.clone();
  15079. if ( source.fog !== null ) this.fog = source.fog.clone();
  15080. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15081. this.autoUpdate = source.autoUpdate;
  15082. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15083. return this;
  15084. }
  15085. toJSON( meta ) {
  15086. const data = super.toJSON( meta );
  15087. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15088. if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
  15089. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15090. return data;
  15091. }
  15092. }
  15093. function InterleavedBuffer( array, stride ) {
  15094. this.array = array;
  15095. this.stride = stride;
  15096. this.count = array !== undefined ? array.length / stride : 0;
  15097. this.usage = StaticDrawUsage;
  15098. this.updateRange = { offset: 0, count: - 1 };
  15099. this.version = 0;
  15100. this.uuid = MathUtils.generateUUID();
  15101. }
  15102. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15103. set: function ( value ) {
  15104. if ( value === true ) this.version ++;
  15105. }
  15106. } );
  15107. Object.assign( InterleavedBuffer.prototype, {
  15108. isInterleavedBuffer: true,
  15109. onUploadCallback: function () {},
  15110. setUsage: function ( value ) {
  15111. this.usage = value;
  15112. return this;
  15113. },
  15114. copy: function ( source ) {
  15115. this.array = new source.array.constructor( source.array );
  15116. this.count = source.count;
  15117. this.stride = source.stride;
  15118. this.usage = source.usage;
  15119. return this;
  15120. },
  15121. copyAt: function ( index1, attribute, index2 ) {
  15122. index1 *= this.stride;
  15123. index2 *= attribute.stride;
  15124. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  15125. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15126. }
  15127. return this;
  15128. },
  15129. set: function ( value, offset = 0 ) {
  15130. this.array.set( value, offset );
  15131. return this;
  15132. },
  15133. clone: function ( data ) {
  15134. if ( data.arrayBuffers === undefined ) {
  15135. data.arrayBuffers = {};
  15136. }
  15137. if ( this.array.buffer._uuid === undefined ) {
  15138. this.array.buffer._uuid = MathUtils.generateUUID();
  15139. }
  15140. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15141. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  15142. }
  15143. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  15144. const ib = new InterleavedBuffer( array, this.stride );
  15145. ib.setUsage( this.usage );
  15146. return ib;
  15147. },
  15148. onUpload: function ( callback ) {
  15149. this.onUploadCallback = callback;
  15150. return this;
  15151. },
  15152. toJSON: function ( data ) {
  15153. if ( data.arrayBuffers === undefined ) {
  15154. data.arrayBuffers = {};
  15155. }
  15156. // generate UUID for array buffer if necessary
  15157. if ( this.array.buffer._uuid === undefined ) {
  15158. this.array.buffer._uuid = MathUtils.generateUUID();
  15159. }
  15160. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15161. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  15162. }
  15163. //
  15164. return {
  15165. uuid: this.uuid,
  15166. buffer: this.array.buffer._uuid,
  15167. type: this.array.constructor.name,
  15168. stride: this.stride
  15169. };
  15170. }
  15171. } );
  15172. const _vector$6 = new Vector3();
  15173. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15174. this.name = '';
  15175. this.data = interleavedBuffer;
  15176. this.itemSize = itemSize;
  15177. this.offset = offset;
  15178. this.normalized = normalized === true;
  15179. }
  15180. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15181. count: {
  15182. get: function () {
  15183. return this.data.count;
  15184. }
  15185. },
  15186. array: {
  15187. get: function () {
  15188. return this.data.array;
  15189. }
  15190. },
  15191. needsUpdate: {
  15192. set: function ( value ) {
  15193. this.data.needsUpdate = value;
  15194. }
  15195. }
  15196. } );
  15197. Object.assign( InterleavedBufferAttribute.prototype, {
  15198. isInterleavedBufferAttribute: true,
  15199. applyMatrix4: function ( m ) {
  15200. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  15201. _vector$6.x = this.getX( i );
  15202. _vector$6.y = this.getY( i );
  15203. _vector$6.z = this.getZ( i );
  15204. _vector$6.applyMatrix4( m );
  15205. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  15206. }
  15207. return this;
  15208. },
  15209. setX: function ( index, x ) {
  15210. this.data.array[ index * this.data.stride + this.offset ] = x;
  15211. return this;
  15212. },
  15213. setY: function ( index, y ) {
  15214. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15215. return this;
  15216. },
  15217. setZ: function ( index, z ) {
  15218. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15219. return this;
  15220. },
  15221. setW: function ( index, w ) {
  15222. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15223. return this;
  15224. },
  15225. getX: function ( index ) {
  15226. return this.data.array[ index * this.data.stride + this.offset ];
  15227. },
  15228. getY: function ( index ) {
  15229. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15230. },
  15231. getZ: function ( index ) {
  15232. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15233. },
  15234. getW: function ( index ) {
  15235. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15236. },
  15237. setXY: function ( index, x, y ) {
  15238. index = index * this.data.stride + this.offset;
  15239. this.data.array[ index + 0 ] = x;
  15240. this.data.array[ index + 1 ] = y;
  15241. return this;
  15242. },
  15243. setXYZ: function ( index, x, y, z ) {
  15244. index = index * this.data.stride + this.offset;
  15245. this.data.array[ index + 0 ] = x;
  15246. this.data.array[ index + 1 ] = y;
  15247. this.data.array[ index + 2 ] = z;
  15248. return this;
  15249. },
  15250. setXYZW: function ( index, x, y, z, w ) {
  15251. index = index * this.data.stride + this.offset;
  15252. this.data.array[ index + 0 ] = x;
  15253. this.data.array[ index + 1 ] = y;
  15254. this.data.array[ index + 2 ] = z;
  15255. this.data.array[ index + 3 ] = w;
  15256. return this;
  15257. },
  15258. clone: function ( data ) {
  15259. if ( data === undefined ) {
  15260. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  15261. const array = [];
  15262. for ( let i = 0; i < this.count; i ++ ) {
  15263. const index = i * this.data.stride + this.offset;
  15264. for ( let j = 0; j < this.itemSize; j ++ ) {
  15265. array.push( this.data.array[ index + j ] );
  15266. }
  15267. }
  15268. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  15269. } else {
  15270. if ( data.interleavedBuffers === undefined ) {
  15271. data.interleavedBuffers = {};
  15272. }
  15273. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15274. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  15275. }
  15276. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  15277. }
  15278. },
  15279. toJSON: function ( data ) {
  15280. if ( data === undefined ) {
  15281. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  15282. const array = [];
  15283. for ( let i = 0; i < this.count; i ++ ) {
  15284. const index = i * this.data.stride + this.offset;
  15285. for ( let j = 0; j < this.itemSize; j ++ ) {
  15286. array.push( this.data.array[ index + j ] );
  15287. }
  15288. }
  15289. // deinterleave data and save it as an ordinary buffer attribute for now
  15290. return {
  15291. itemSize: this.itemSize,
  15292. type: this.array.constructor.name,
  15293. array: array,
  15294. normalized: this.normalized
  15295. };
  15296. } else {
  15297. // save as true interlaved attribtue
  15298. if ( data.interleavedBuffers === undefined ) {
  15299. data.interleavedBuffers = {};
  15300. }
  15301. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15302. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  15303. }
  15304. return {
  15305. isInterleavedBufferAttribute: true,
  15306. itemSize: this.itemSize,
  15307. data: this.data.uuid,
  15308. offset: this.offset,
  15309. normalized: this.normalized
  15310. };
  15311. }
  15312. }
  15313. } );
  15314. /**
  15315. * parameters = {
  15316. * color: <hex>,
  15317. * map: new THREE.Texture( <Image> ),
  15318. * alphaMap: new THREE.Texture( <Image> ),
  15319. * rotation: <float>,
  15320. * sizeAttenuation: <bool>
  15321. * }
  15322. */
  15323. function SpriteMaterial( parameters ) {
  15324. Material.call( this );
  15325. this.type = 'SpriteMaterial';
  15326. this.color = new Color( 0xffffff );
  15327. this.map = null;
  15328. this.alphaMap = null;
  15329. this.rotation = 0;
  15330. this.sizeAttenuation = true;
  15331. this.transparent = true;
  15332. this.setValues( parameters );
  15333. }
  15334. SpriteMaterial.prototype = Object.create( Material.prototype );
  15335. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15336. SpriteMaterial.prototype.isSpriteMaterial = true;
  15337. SpriteMaterial.prototype.copy = function ( source ) {
  15338. Material.prototype.copy.call( this, source );
  15339. this.color.copy( source.color );
  15340. this.map = source.map;
  15341. this.alphaMap = source.alphaMap;
  15342. this.rotation = source.rotation;
  15343. this.sizeAttenuation = source.sizeAttenuation;
  15344. return this;
  15345. };
  15346. let _geometry;
  15347. const _intersectPoint = new Vector3();
  15348. const _worldScale = new Vector3();
  15349. const _mvPosition = new Vector3();
  15350. const _alignedPosition = new Vector2();
  15351. const _rotatedPosition = new Vector2();
  15352. const _viewWorldMatrix = new Matrix4();
  15353. const _vA$1 = new Vector3();
  15354. const _vB$1 = new Vector3();
  15355. const _vC$1 = new Vector3();
  15356. const _uvA$1 = new Vector2();
  15357. const _uvB$1 = new Vector2();
  15358. const _uvC$1 = new Vector2();
  15359. function Sprite( material ) {
  15360. Object3D.call( this );
  15361. this.type = 'Sprite';
  15362. if ( _geometry === undefined ) {
  15363. _geometry = new BufferGeometry();
  15364. const float32Array = new Float32Array( [
  15365. - 0.5, - 0.5, 0, 0, 0,
  15366. 0.5, - 0.5, 0, 1, 0,
  15367. 0.5, 0.5, 0, 1, 1,
  15368. - 0.5, 0.5, 0, 0, 1
  15369. ] );
  15370. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15371. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15372. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15373. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15374. }
  15375. this.geometry = _geometry;
  15376. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15377. this.center = new Vector2( 0.5, 0.5 );
  15378. }
  15379. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15380. constructor: Sprite,
  15381. isSprite: true,
  15382. raycast: function ( raycaster, intersects ) {
  15383. if ( raycaster.camera === null ) {
  15384. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  15385. }
  15386. _worldScale.setFromMatrixScale( this.matrixWorld );
  15387. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  15388. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  15389. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15390. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15391. _worldScale.multiplyScalar( - _mvPosition.z );
  15392. }
  15393. const rotation = this.material.rotation;
  15394. let sin, cos;
  15395. if ( rotation !== 0 ) {
  15396. cos = Math.cos( rotation );
  15397. sin = Math.sin( rotation );
  15398. }
  15399. const center = this.center;
  15400. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15401. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15402. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15403. _uvA$1.set( 0, 0 );
  15404. _uvB$1.set( 1, 0 );
  15405. _uvC$1.set( 1, 1 );
  15406. // check first triangle
  15407. let intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  15408. if ( intersect === null ) {
  15409. // check second triangle
  15410. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15411. _uvB$1.set( 0, 1 );
  15412. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  15413. if ( intersect === null ) {
  15414. return;
  15415. }
  15416. }
  15417. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  15418. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15419. intersects.push( {
  15420. distance: distance,
  15421. point: _intersectPoint.clone(),
  15422. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  15423. face: null,
  15424. object: this
  15425. } );
  15426. },
  15427. copy: function ( source ) {
  15428. Object3D.prototype.copy.call( this, source );
  15429. if ( source.center !== undefined ) this.center.copy( source.center );
  15430. this.material = source.material;
  15431. return this;
  15432. }
  15433. } );
  15434. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15435. // compute position in camera space
  15436. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15437. // to check if rotation is not zero
  15438. if ( sin !== undefined ) {
  15439. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  15440. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  15441. } else {
  15442. _rotatedPosition.copy( _alignedPosition );
  15443. }
  15444. vertexPosition.copy( mvPosition );
  15445. vertexPosition.x += _rotatedPosition.x;
  15446. vertexPosition.y += _rotatedPosition.y;
  15447. // transform to world space
  15448. vertexPosition.applyMatrix4( _viewWorldMatrix );
  15449. }
  15450. const _v1$4 = new Vector3();
  15451. const _v2$2 = new Vector3();
  15452. function LOD() {
  15453. Object3D.call( this );
  15454. this._currentLevel = 0;
  15455. this.type = 'LOD';
  15456. Object.defineProperties( this, {
  15457. levels: {
  15458. enumerable: true,
  15459. value: []
  15460. }
  15461. } );
  15462. this.autoUpdate = true;
  15463. }
  15464. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15465. constructor: LOD,
  15466. isLOD: true,
  15467. copy: function ( source ) {
  15468. Object3D.prototype.copy.call( this, source, false );
  15469. const levels = source.levels;
  15470. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15471. const level = levels[ i ];
  15472. this.addLevel( level.object.clone(), level.distance );
  15473. }
  15474. this.autoUpdate = source.autoUpdate;
  15475. return this;
  15476. },
  15477. addLevel: function ( object, distance = 0 ) {
  15478. distance = Math.abs( distance );
  15479. const levels = this.levels;
  15480. let l;
  15481. for ( l = 0; l < levels.length; l ++ ) {
  15482. if ( distance < levels[ l ].distance ) {
  15483. break;
  15484. }
  15485. }
  15486. levels.splice( l, 0, { distance: distance, object: object } );
  15487. this.add( object );
  15488. return this;
  15489. },
  15490. getCurrentLevel: function () {
  15491. return this._currentLevel;
  15492. },
  15493. getObjectForDistance: function ( distance ) {
  15494. const levels = this.levels;
  15495. if ( levels.length > 0 ) {
  15496. let i, l;
  15497. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15498. if ( distance < levels[ i ].distance ) {
  15499. break;
  15500. }
  15501. }
  15502. return levels[ i - 1 ].object;
  15503. }
  15504. return null;
  15505. },
  15506. raycast: function ( raycaster, intersects ) {
  15507. const levels = this.levels;
  15508. if ( levels.length > 0 ) {
  15509. _v1$4.setFromMatrixPosition( this.matrixWorld );
  15510. const distance = raycaster.ray.origin.distanceTo( _v1$4 );
  15511. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15512. }
  15513. },
  15514. update: function ( camera ) {
  15515. const levels = this.levels;
  15516. if ( levels.length > 1 ) {
  15517. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  15518. _v2$2.setFromMatrixPosition( this.matrixWorld );
  15519. const distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  15520. levels[ 0 ].object.visible = true;
  15521. let i, l;
  15522. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15523. if ( distance >= levels[ i ].distance ) {
  15524. levels[ i - 1 ].object.visible = false;
  15525. levels[ i ].object.visible = true;
  15526. } else {
  15527. break;
  15528. }
  15529. }
  15530. this._currentLevel = i - 1;
  15531. for ( ; i < l; i ++ ) {
  15532. levels[ i ].object.visible = false;
  15533. }
  15534. }
  15535. },
  15536. toJSON: function ( meta ) {
  15537. const data = Object3D.prototype.toJSON.call( this, meta );
  15538. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  15539. data.object.levels = [];
  15540. const levels = this.levels;
  15541. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15542. const level = levels[ i ];
  15543. data.object.levels.push( {
  15544. object: level.object.uuid,
  15545. distance: level.distance
  15546. } );
  15547. }
  15548. return data;
  15549. }
  15550. } );
  15551. const _basePosition = new Vector3();
  15552. const _skinIndex = new Vector4();
  15553. const _skinWeight = new Vector4();
  15554. const _vector$7 = new Vector3();
  15555. const _matrix$1 = new Matrix4();
  15556. function SkinnedMesh( geometry, material ) {
  15557. if ( geometry && geometry.isGeometry ) {
  15558. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15559. }
  15560. Mesh.call( this, geometry, material );
  15561. this.type = 'SkinnedMesh';
  15562. this.bindMode = 'attached';
  15563. this.bindMatrix = new Matrix4();
  15564. this.bindMatrixInverse = new Matrix4();
  15565. }
  15566. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15567. constructor: SkinnedMesh,
  15568. isSkinnedMesh: true,
  15569. copy: function ( source ) {
  15570. Mesh.prototype.copy.call( this, source );
  15571. this.bindMode = source.bindMode;
  15572. this.bindMatrix.copy( source.bindMatrix );
  15573. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  15574. this.skeleton = source.skeleton;
  15575. return this;
  15576. },
  15577. bind: function ( skeleton, bindMatrix ) {
  15578. this.skeleton = skeleton;
  15579. if ( bindMatrix === undefined ) {
  15580. this.updateMatrixWorld( true );
  15581. this.skeleton.calculateInverses();
  15582. bindMatrix = this.matrixWorld;
  15583. }
  15584. this.bindMatrix.copy( bindMatrix );
  15585. this.bindMatrixInverse.copy( bindMatrix ).invert();
  15586. },
  15587. pose: function () {
  15588. this.skeleton.pose();
  15589. },
  15590. normalizeSkinWeights: function () {
  15591. const vector = new Vector4();
  15592. const skinWeight = this.geometry.attributes.skinWeight;
  15593. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  15594. vector.x = skinWeight.getX( i );
  15595. vector.y = skinWeight.getY( i );
  15596. vector.z = skinWeight.getZ( i );
  15597. vector.w = skinWeight.getW( i );
  15598. const scale = 1.0 / vector.manhattanLength();
  15599. if ( scale !== Infinity ) {
  15600. vector.multiplyScalar( scale );
  15601. } else {
  15602. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15603. }
  15604. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15605. }
  15606. },
  15607. updateMatrixWorld: function ( force ) {
  15608. Mesh.prototype.updateMatrixWorld.call( this, force );
  15609. if ( this.bindMode === 'attached' ) {
  15610. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  15611. } else if ( this.bindMode === 'detached' ) {
  15612. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  15613. } else {
  15614. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15615. }
  15616. },
  15617. boneTransform: function ( index, target ) {
  15618. const skeleton = this.skeleton;
  15619. const geometry = this.geometry;
  15620. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  15621. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  15622. _basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  15623. target.set( 0, 0, 0 );
  15624. for ( let i = 0; i < 4; i ++ ) {
  15625. const weight = _skinWeight.getComponent( i );
  15626. if ( weight !== 0 ) {
  15627. const boneIndex = _skinIndex.getComponent( i );
  15628. _matrix$1.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  15629. target.addScaledVector( _vector$7.copy( _basePosition ).applyMatrix4( _matrix$1 ), weight );
  15630. }
  15631. }
  15632. return target.applyMatrix4( this.bindMatrixInverse );
  15633. }
  15634. } );
  15635. function Bone() {
  15636. Object3D.call( this );
  15637. this.type = 'Bone';
  15638. }
  15639. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15640. constructor: Bone,
  15641. isBone: true
  15642. } );
  15643. const _offsetMatrix = new Matrix4();
  15644. const _identityMatrix = new Matrix4();
  15645. function Skeleton( bones = [], boneInverses = [] ) {
  15646. this.uuid = MathUtils.generateUUID();
  15647. this.bones = bones.slice( 0 );
  15648. this.boneInverses = boneInverses;
  15649. this.boneMatrices = null;
  15650. this.boneTexture = null;
  15651. this.boneTextureSize = 0;
  15652. this.frame = - 1;
  15653. this.init();
  15654. }
  15655. Object.assign( Skeleton.prototype, {
  15656. init: function () {
  15657. const bones = this.bones;
  15658. const boneInverses = this.boneInverses;
  15659. this.boneMatrices = new Float32Array( bones.length * 16 );
  15660. // calculate inverse bone matrices if necessary
  15661. if ( boneInverses.length === 0 ) {
  15662. this.calculateInverses();
  15663. } else {
  15664. // handle special case
  15665. if ( bones.length !== boneInverses.length ) {
  15666. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  15667. this.boneInverses = [];
  15668. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15669. this.boneInverses.push( new Matrix4() );
  15670. }
  15671. }
  15672. }
  15673. },
  15674. calculateInverses: function () {
  15675. this.boneInverses.length = 0;
  15676. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15677. const inverse = new Matrix4();
  15678. if ( this.bones[ i ] ) {
  15679. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  15680. }
  15681. this.boneInverses.push( inverse );
  15682. }
  15683. },
  15684. pose: function () {
  15685. // recover the bind-time world matrices
  15686. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15687. const bone = this.bones[ i ];
  15688. if ( bone ) {
  15689. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  15690. }
  15691. }
  15692. // compute the local matrices, positions, rotations and scales
  15693. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15694. const bone = this.bones[ i ];
  15695. if ( bone ) {
  15696. if ( bone.parent && bone.parent.isBone ) {
  15697. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  15698. bone.matrix.multiply( bone.matrixWorld );
  15699. } else {
  15700. bone.matrix.copy( bone.matrixWorld );
  15701. }
  15702. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15703. }
  15704. }
  15705. },
  15706. update: function () {
  15707. const bones = this.bones;
  15708. const boneInverses = this.boneInverses;
  15709. const boneMatrices = this.boneMatrices;
  15710. const boneTexture = this.boneTexture;
  15711. // flatten bone matrices to array
  15712. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  15713. // compute the offset between the current and the original transform
  15714. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  15715. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15716. _offsetMatrix.toArray( boneMatrices, i * 16 );
  15717. }
  15718. if ( boneTexture !== null ) {
  15719. boneTexture.needsUpdate = true;
  15720. }
  15721. },
  15722. clone: function () {
  15723. return new Skeleton( this.bones, this.boneInverses );
  15724. },
  15725. getBoneByName: function ( name ) {
  15726. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15727. const bone = this.bones[ i ];
  15728. if ( bone.name === name ) {
  15729. return bone;
  15730. }
  15731. }
  15732. return undefined;
  15733. },
  15734. dispose: function ( ) {
  15735. if ( this.boneTexture !== null ) {
  15736. this.boneTexture.dispose();
  15737. this.boneTexture = null;
  15738. }
  15739. },
  15740. fromJSON: function ( json, bones ) {
  15741. this.uuid = json.uuid;
  15742. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  15743. const uuid = json.bones[ i ];
  15744. let bone = bones[ uuid ];
  15745. if ( bone === undefined ) {
  15746. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  15747. bone = new Bone();
  15748. }
  15749. this.bones.push( bone );
  15750. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  15751. }
  15752. this.init();
  15753. return this;
  15754. },
  15755. toJSON: function () {
  15756. const data = {
  15757. metadata: {
  15758. version: 4.5,
  15759. type: 'Skeleton',
  15760. generator: 'Skeleton.toJSON'
  15761. },
  15762. bones: [],
  15763. boneInverses: []
  15764. };
  15765. data.uuid = this.uuid;
  15766. const bones = this.bones;
  15767. const boneInverses = this.boneInverses;
  15768. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  15769. const bone = bones[ i ];
  15770. data.bones.push( bone.uuid );
  15771. const boneInverse = boneInverses[ i ];
  15772. data.boneInverses.push( boneInverse.toArray() );
  15773. }
  15774. return data;
  15775. }
  15776. } );
  15777. const _instanceLocalMatrix = new Matrix4();
  15778. const _instanceWorldMatrix = new Matrix4();
  15779. const _instanceIntersects = [];
  15780. const _mesh = new Mesh();
  15781. function InstancedMesh( geometry, material, count ) {
  15782. Mesh.call( this, geometry, material );
  15783. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  15784. this.instanceColor = null;
  15785. this.count = count;
  15786. this.frustumCulled = false;
  15787. }
  15788. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15789. constructor: InstancedMesh,
  15790. isInstancedMesh: true,
  15791. copy: function ( source ) {
  15792. Mesh.prototype.copy.call( this, source );
  15793. this.instanceMatrix.copy( source.instanceMatrix );
  15794. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  15795. this.count = source.count;
  15796. return this;
  15797. },
  15798. getColorAt: function ( index, color ) {
  15799. color.fromArray( this.instanceColor.array, index * 3 );
  15800. },
  15801. getMatrixAt: function ( index, matrix ) {
  15802. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  15803. },
  15804. raycast: function ( raycaster, intersects ) {
  15805. const matrixWorld = this.matrixWorld;
  15806. const raycastTimes = this.count;
  15807. _mesh.geometry = this.geometry;
  15808. _mesh.material = this.material;
  15809. if ( _mesh.material === undefined ) return;
  15810. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  15811. // calculate the world matrix for each instance
  15812. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  15813. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  15814. // the mesh represents this single instance
  15815. _mesh.matrixWorld = _instanceWorldMatrix;
  15816. _mesh.raycast( raycaster, _instanceIntersects );
  15817. // process the result of raycast
  15818. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  15819. const intersect = _instanceIntersects[ i ];
  15820. intersect.instanceId = instanceId;
  15821. intersect.object = this;
  15822. intersects.push( intersect );
  15823. }
  15824. _instanceIntersects.length = 0;
  15825. }
  15826. },
  15827. setColorAt: function ( index, color ) {
  15828. if ( this.instanceColor === null ) {
  15829. this.instanceColor = new BufferAttribute( new Float32Array( this.count * 3 ), 3 );
  15830. }
  15831. color.toArray( this.instanceColor.array, index * 3 );
  15832. },
  15833. setMatrixAt: function ( index, matrix ) {
  15834. matrix.toArray( this.instanceMatrix.array, index * 16 );
  15835. },
  15836. updateMorphTargets: function () {
  15837. },
  15838. dispose: function () {
  15839. this.dispatchEvent( { type: 'dispose' } );
  15840. }
  15841. } );
  15842. /**
  15843. * parameters = {
  15844. * color: <hex>,
  15845. * opacity: <float>,
  15846. *
  15847. * linewidth: <float>,
  15848. * linecap: "round",
  15849. * linejoin: "round"
  15850. * }
  15851. */
  15852. function LineBasicMaterial( parameters ) {
  15853. Material.call( this );
  15854. this.type = 'LineBasicMaterial';
  15855. this.color = new Color( 0xffffff );
  15856. this.linewidth = 1;
  15857. this.linecap = 'round';
  15858. this.linejoin = 'round';
  15859. this.morphTargets = false;
  15860. this.setValues( parameters );
  15861. }
  15862. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15863. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15864. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15865. LineBasicMaterial.prototype.copy = function ( source ) {
  15866. Material.prototype.copy.call( this, source );
  15867. this.color.copy( source.color );
  15868. this.linewidth = source.linewidth;
  15869. this.linecap = source.linecap;
  15870. this.linejoin = source.linejoin;
  15871. this.morphTargets = source.morphTargets;
  15872. return this;
  15873. };
  15874. const _start = new Vector3();
  15875. const _end = new Vector3();
  15876. const _inverseMatrix$1 = new Matrix4();
  15877. const _ray$1 = new Ray();
  15878. const _sphere$2 = new Sphere();
  15879. function Line( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  15880. Object3D.call( this );
  15881. this.type = 'Line';
  15882. this.geometry = geometry;
  15883. this.material = material;
  15884. this.updateMorphTargets();
  15885. }
  15886. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15887. constructor: Line,
  15888. isLine: true,
  15889. copy: function ( source ) {
  15890. Object3D.prototype.copy.call( this, source );
  15891. this.material = source.material;
  15892. this.geometry = source.geometry;
  15893. return this;
  15894. },
  15895. computeLineDistances: function () {
  15896. const geometry = this.geometry;
  15897. if ( geometry.isBufferGeometry ) {
  15898. // we assume non-indexed geometry
  15899. if ( geometry.index === null ) {
  15900. const positionAttribute = geometry.attributes.position;
  15901. const lineDistances = [ 0 ];
  15902. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15903. _start.fromBufferAttribute( positionAttribute, i - 1 );
  15904. _end.fromBufferAttribute( positionAttribute, i );
  15905. lineDistances[ i ] = lineDistances[ i - 1 ];
  15906. lineDistances[ i ] += _start.distanceTo( _end );
  15907. }
  15908. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15909. } else {
  15910. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15911. }
  15912. } else if ( geometry.isGeometry ) {
  15913. console.error( 'THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15914. }
  15915. return this;
  15916. },
  15917. raycast: function ( raycaster, intersects ) {
  15918. const geometry = this.geometry;
  15919. const matrixWorld = this.matrixWorld;
  15920. const threshold = raycaster.params.Line.threshold;
  15921. // Checking boundingSphere distance to ray
  15922. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15923. _sphere$2.copy( geometry.boundingSphere );
  15924. _sphere$2.applyMatrix4( matrixWorld );
  15925. _sphere$2.radius += threshold;
  15926. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  15927. //
  15928. _inverseMatrix$1.copy( matrixWorld ).invert();
  15929. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  15930. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15931. const localThresholdSq = localThreshold * localThreshold;
  15932. const vStart = new Vector3();
  15933. const vEnd = new Vector3();
  15934. const interSegment = new Vector3();
  15935. const interRay = new Vector3();
  15936. const step = this.isLineSegments ? 2 : 1;
  15937. if ( geometry.isBufferGeometry ) {
  15938. const index = geometry.index;
  15939. const attributes = geometry.attributes;
  15940. const positionAttribute = attributes.position;
  15941. if ( index !== null ) {
  15942. const indices = index.array;
  15943. for ( let i = 0, l = indices.length - 1; i < l; i += step ) {
  15944. const a = indices[ i ];
  15945. const b = indices[ i + 1 ];
  15946. vStart.fromBufferAttribute( positionAttribute, a );
  15947. vEnd.fromBufferAttribute( positionAttribute, b );
  15948. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15949. if ( distSq > localThresholdSq ) continue;
  15950. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15951. const distance = raycaster.ray.origin.distanceTo( interRay );
  15952. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15953. intersects.push( {
  15954. distance: distance,
  15955. // What do we want? intersection point on the ray or on the segment??
  15956. // point: raycaster.ray.at( distance ),
  15957. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15958. index: i,
  15959. face: null,
  15960. faceIndex: null,
  15961. object: this
  15962. } );
  15963. }
  15964. } else {
  15965. for ( let i = 0, l = positionAttribute.count - 1; i < l; i += step ) {
  15966. vStart.fromBufferAttribute( positionAttribute, i );
  15967. vEnd.fromBufferAttribute( positionAttribute, i + 1 );
  15968. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15969. if ( distSq > localThresholdSq ) continue;
  15970. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15971. const distance = raycaster.ray.origin.distanceTo( interRay );
  15972. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15973. intersects.push( {
  15974. distance: distance,
  15975. // What do we want? intersection point on the ray or on the segment??
  15976. // point: raycaster.ray.at( distance ),
  15977. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15978. index: i,
  15979. face: null,
  15980. faceIndex: null,
  15981. object: this
  15982. } );
  15983. }
  15984. }
  15985. } else if ( geometry.isGeometry ) {
  15986. console.error( 'THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15987. }
  15988. },
  15989. updateMorphTargets: function () {
  15990. const geometry = this.geometry;
  15991. if ( geometry.isBufferGeometry ) {
  15992. const morphAttributes = geometry.morphAttributes;
  15993. const keys = Object.keys( morphAttributes );
  15994. if ( keys.length > 0 ) {
  15995. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  15996. if ( morphAttribute !== undefined ) {
  15997. this.morphTargetInfluences = [];
  15998. this.morphTargetDictionary = {};
  15999. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16000. const name = morphAttribute[ m ].name || String( m );
  16001. this.morphTargetInfluences.push( 0 );
  16002. this.morphTargetDictionary[ name ] = m;
  16003. }
  16004. }
  16005. }
  16006. } else {
  16007. const morphTargets = geometry.morphTargets;
  16008. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16009. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16010. }
  16011. }
  16012. }
  16013. } );
  16014. const _start$1 = new Vector3();
  16015. const _end$1 = new Vector3();
  16016. function LineSegments( geometry, material ) {
  16017. Line.call( this, geometry, material );
  16018. this.type = 'LineSegments';
  16019. }
  16020. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16021. constructor: LineSegments,
  16022. isLineSegments: true,
  16023. computeLineDistances: function () {
  16024. const geometry = this.geometry;
  16025. if ( geometry.isBufferGeometry ) {
  16026. // we assume non-indexed geometry
  16027. if ( geometry.index === null ) {
  16028. const positionAttribute = geometry.attributes.position;
  16029. const lineDistances = [];
  16030. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16031. _start$1.fromBufferAttribute( positionAttribute, i );
  16032. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16033. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16034. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16035. }
  16036. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16037. } else {
  16038. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16039. }
  16040. } else if ( geometry.isGeometry ) {
  16041. console.error( 'THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16042. }
  16043. return this;
  16044. }
  16045. } );
  16046. function LineLoop( geometry, material ) {
  16047. Line.call( this, geometry, material );
  16048. this.type = 'LineLoop';
  16049. }
  16050. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16051. constructor: LineLoop,
  16052. isLineLoop: true,
  16053. } );
  16054. /**
  16055. * parameters = {
  16056. * color: <hex>,
  16057. * opacity: <float>,
  16058. * map: new THREE.Texture( <Image> ),
  16059. * alphaMap: new THREE.Texture( <Image> ),
  16060. *
  16061. * size: <float>,
  16062. * sizeAttenuation: <bool>
  16063. *
  16064. * morphTargets: <bool>
  16065. * }
  16066. */
  16067. function PointsMaterial( parameters ) {
  16068. Material.call( this );
  16069. this.type = 'PointsMaterial';
  16070. this.color = new Color( 0xffffff );
  16071. this.map = null;
  16072. this.alphaMap = null;
  16073. this.size = 1;
  16074. this.sizeAttenuation = true;
  16075. this.morphTargets = false;
  16076. this.setValues( parameters );
  16077. }
  16078. PointsMaterial.prototype = Object.create( Material.prototype );
  16079. PointsMaterial.prototype.constructor = PointsMaterial;
  16080. PointsMaterial.prototype.isPointsMaterial = true;
  16081. PointsMaterial.prototype.copy = function ( source ) {
  16082. Material.prototype.copy.call( this, source );
  16083. this.color.copy( source.color );
  16084. this.map = source.map;
  16085. this.alphaMap = source.alphaMap;
  16086. this.size = source.size;
  16087. this.sizeAttenuation = source.sizeAttenuation;
  16088. this.morphTargets = source.morphTargets;
  16089. return this;
  16090. };
  16091. const _inverseMatrix$2 = new Matrix4();
  16092. const _ray$2 = new Ray();
  16093. const _sphere$3 = new Sphere();
  16094. const _position$1 = new Vector3();
  16095. function Points( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  16096. Object3D.call( this );
  16097. this.type = 'Points';
  16098. this.geometry = geometry;
  16099. this.material = material;
  16100. this.updateMorphTargets();
  16101. }
  16102. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16103. constructor: Points,
  16104. isPoints: true,
  16105. copy: function ( source ) {
  16106. Object3D.prototype.copy.call( this, source );
  16107. this.material = source.material;
  16108. this.geometry = source.geometry;
  16109. return this;
  16110. },
  16111. raycast: function ( raycaster, intersects ) {
  16112. const geometry = this.geometry;
  16113. const matrixWorld = this.matrixWorld;
  16114. const threshold = raycaster.params.Points.threshold;
  16115. // Checking boundingSphere distance to ray
  16116. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16117. _sphere$3.copy( geometry.boundingSphere );
  16118. _sphere$3.applyMatrix4( matrixWorld );
  16119. _sphere$3.radius += threshold;
  16120. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16121. //
  16122. _inverseMatrix$2.copy( matrixWorld ).invert();
  16123. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16124. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16125. const localThresholdSq = localThreshold * localThreshold;
  16126. if ( geometry.isBufferGeometry ) {
  16127. const index = geometry.index;
  16128. const attributes = geometry.attributes;
  16129. const positionAttribute = attributes.position;
  16130. if ( index !== null ) {
  16131. const indices = index.array;
  16132. for ( let i = 0, il = indices.length; i < il; i ++ ) {
  16133. const a = indices[ i ];
  16134. _position$1.fromBufferAttribute( positionAttribute, a );
  16135. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16136. }
  16137. } else {
  16138. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  16139. _position$1.fromBufferAttribute( positionAttribute, i );
  16140. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16141. }
  16142. }
  16143. } else {
  16144. console.error( 'THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16145. }
  16146. },
  16147. updateMorphTargets: function () {
  16148. const geometry = this.geometry;
  16149. if ( geometry.isBufferGeometry ) {
  16150. const morphAttributes = geometry.morphAttributes;
  16151. const keys = Object.keys( morphAttributes );
  16152. if ( keys.length > 0 ) {
  16153. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  16154. if ( morphAttribute !== undefined ) {
  16155. this.morphTargetInfluences = [];
  16156. this.morphTargetDictionary = {};
  16157. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16158. const name = morphAttribute[ m ].name || String( m );
  16159. this.morphTargetInfluences.push( 0 );
  16160. this.morphTargetDictionary[ name ] = m;
  16161. }
  16162. }
  16163. }
  16164. } else {
  16165. const morphTargets = geometry.morphTargets;
  16166. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16167. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16168. }
  16169. }
  16170. }
  16171. } );
  16172. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  16173. const rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16174. if ( rayPointDistanceSq < localThresholdSq ) {
  16175. const intersectPoint = new Vector3();
  16176. _ray$2.closestPointToPoint( point, intersectPoint );
  16177. intersectPoint.applyMatrix4( matrixWorld );
  16178. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16179. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16180. intersects.push( {
  16181. distance: distance,
  16182. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16183. point: intersectPoint,
  16184. index: index,
  16185. face: null,
  16186. object: object
  16187. } );
  16188. }
  16189. }
  16190. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16191. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16192. this.format = format !== undefined ? format : RGBFormat;
  16193. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16194. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16195. this.generateMipmaps = false;
  16196. const scope = this;
  16197. function updateVideo() {
  16198. scope.needsUpdate = true;
  16199. video.requestVideoFrameCallback( updateVideo );
  16200. }
  16201. if ( 'requestVideoFrameCallback' in video ) {
  16202. video.requestVideoFrameCallback( updateVideo );
  16203. }
  16204. }
  16205. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16206. constructor: VideoTexture,
  16207. clone: function () {
  16208. return new this.constructor( this.image ).copy( this );
  16209. },
  16210. isVideoTexture: true,
  16211. update: function () {
  16212. const video = this.image;
  16213. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  16214. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  16215. this.needsUpdate = true;
  16216. }
  16217. }
  16218. } );
  16219. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16220. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16221. this.image = { width: width, height: height };
  16222. this.mipmaps = mipmaps;
  16223. // no flipping for cube textures
  16224. // (also flipping doesn't work for compressed textures )
  16225. this.flipY = false;
  16226. // can't generate mipmaps for compressed textures
  16227. // mips must be embedded in DDS files
  16228. this.generateMipmaps = false;
  16229. }
  16230. CompressedTexture.prototype = Object.create( Texture.prototype );
  16231. CompressedTexture.prototype.constructor = CompressedTexture;
  16232. CompressedTexture.prototype.isCompressedTexture = true;
  16233. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16234. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16235. this.needsUpdate = true;
  16236. }
  16237. CanvasTexture.prototype = Object.create( Texture.prototype );
  16238. CanvasTexture.prototype.constructor = CanvasTexture;
  16239. CanvasTexture.prototype.isCanvasTexture = true;
  16240. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16241. format = format !== undefined ? format : DepthFormat;
  16242. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16243. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16244. }
  16245. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16246. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16247. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16248. this.image = { width: width, height: height };
  16249. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16250. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16251. this.flipY = false;
  16252. this.generateMipmaps = false;
  16253. }
  16254. DepthTexture.prototype = Object.create( Texture.prototype );
  16255. DepthTexture.prototype.constructor = DepthTexture;
  16256. DepthTexture.prototype.isDepthTexture = true;
  16257. class CircleGeometry extends BufferGeometry {
  16258. constructor( radius = 1, segments = 8, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16259. super();
  16260. this.type = 'CircleGeometry';
  16261. this.parameters = {
  16262. radius: radius,
  16263. segments: segments,
  16264. thetaStart: thetaStart,
  16265. thetaLength: thetaLength
  16266. };
  16267. segments = Math.max( 3, segments );
  16268. // buffers
  16269. const indices = [];
  16270. const vertices = [];
  16271. const normals = [];
  16272. const uvs = [];
  16273. // helper variables
  16274. const vertex = new Vector3();
  16275. const uv = new Vector2();
  16276. // center point
  16277. vertices.push( 0, 0, 0 );
  16278. normals.push( 0, 0, 1 );
  16279. uvs.push( 0.5, 0.5 );
  16280. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  16281. const segment = thetaStart + s / segments * thetaLength;
  16282. // vertex
  16283. vertex.x = radius * Math.cos( segment );
  16284. vertex.y = radius * Math.sin( segment );
  16285. vertices.push( vertex.x, vertex.y, vertex.z );
  16286. // normal
  16287. normals.push( 0, 0, 1 );
  16288. // uvs
  16289. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  16290. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  16291. uvs.push( uv.x, uv.y );
  16292. }
  16293. // indices
  16294. for ( let i = 1; i <= segments; i ++ ) {
  16295. indices.push( i, i + 1, 0 );
  16296. }
  16297. // build geometry
  16298. this.setIndex( indices );
  16299. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16300. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16301. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16302. }
  16303. }
  16304. class CylinderGeometry extends BufferGeometry {
  16305. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16306. super();
  16307. this.type = 'CylinderGeometry';
  16308. this.parameters = {
  16309. radiusTop: radiusTop,
  16310. radiusBottom: radiusBottom,
  16311. height: height,
  16312. radialSegments: radialSegments,
  16313. heightSegments: heightSegments,
  16314. openEnded: openEnded,
  16315. thetaStart: thetaStart,
  16316. thetaLength: thetaLength
  16317. };
  16318. const scope = this;
  16319. radialSegments = Math.floor( radialSegments );
  16320. heightSegments = Math.floor( heightSegments );
  16321. // buffers
  16322. const indices = [];
  16323. const vertices = [];
  16324. const normals = [];
  16325. const uvs = [];
  16326. // helper variables
  16327. let index = 0;
  16328. const indexArray = [];
  16329. const halfHeight = height / 2;
  16330. let groupStart = 0;
  16331. // generate geometry
  16332. generateTorso();
  16333. if ( openEnded === false ) {
  16334. if ( radiusTop > 0 ) generateCap( true );
  16335. if ( radiusBottom > 0 ) generateCap( false );
  16336. }
  16337. // build geometry
  16338. this.setIndex( indices );
  16339. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16340. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16341. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16342. function generateTorso() {
  16343. const normal = new Vector3();
  16344. const vertex = new Vector3();
  16345. let groupCount = 0;
  16346. // this will be used to calculate the normal
  16347. const slope = ( radiusBottom - radiusTop ) / height;
  16348. // generate vertices, normals and uvs
  16349. for ( let y = 0; y <= heightSegments; y ++ ) {
  16350. const indexRow = [];
  16351. const v = y / heightSegments;
  16352. // calculate the radius of the current row
  16353. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  16354. for ( let x = 0; x <= radialSegments; x ++ ) {
  16355. const u = x / radialSegments;
  16356. const theta = u * thetaLength + thetaStart;
  16357. const sinTheta = Math.sin( theta );
  16358. const cosTheta = Math.cos( theta );
  16359. // vertex
  16360. vertex.x = radius * sinTheta;
  16361. vertex.y = - v * height + halfHeight;
  16362. vertex.z = radius * cosTheta;
  16363. vertices.push( vertex.x, vertex.y, vertex.z );
  16364. // normal
  16365. normal.set( sinTheta, slope, cosTheta ).normalize();
  16366. normals.push( normal.x, normal.y, normal.z );
  16367. // uv
  16368. uvs.push( u, 1 - v );
  16369. // save index of vertex in respective row
  16370. indexRow.push( index ++ );
  16371. }
  16372. // now save vertices of the row in our index array
  16373. indexArray.push( indexRow );
  16374. }
  16375. // generate indices
  16376. for ( let x = 0; x < radialSegments; x ++ ) {
  16377. for ( let y = 0; y < heightSegments; y ++ ) {
  16378. // we use the index array to access the correct indices
  16379. const a = indexArray[ y ][ x ];
  16380. const b = indexArray[ y + 1 ][ x ];
  16381. const c = indexArray[ y + 1 ][ x + 1 ];
  16382. const d = indexArray[ y ][ x + 1 ];
  16383. // faces
  16384. indices.push( a, b, d );
  16385. indices.push( b, c, d );
  16386. // update group counter
  16387. groupCount += 6;
  16388. }
  16389. }
  16390. // add a group to the geometry. this will ensure multi material support
  16391. scope.addGroup( groupStart, groupCount, 0 );
  16392. // calculate new start value for groups
  16393. groupStart += groupCount;
  16394. }
  16395. function generateCap( top ) {
  16396. // save the index of the first center vertex
  16397. const centerIndexStart = index;
  16398. const uv = new Vector2();
  16399. const vertex = new Vector3();
  16400. let groupCount = 0;
  16401. const radius = ( top === true ) ? radiusTop : radiusBottom;
  16402. const sign = ( top === true ) ? 1 : - 1;
  16403. // first we generate the center vertex data of the cap.
  16404. // because the geometry needs one set of uvs per face,
  16405. // we must generate a center vertex per face/segment
  16406. for ( let x = 1; x <= radialSegments; x ++ ) {
  16407. // vertex
  16408. vertices.push( 0, halfHeight * sign, 0 );
  16409. // normal
  16410. normals.push( 0, sign, 0 );
  16411. // uv
  16412. uvs.push( 0.5, 0.5 );
  16413. // increase index
  16414. index ++;
  16415. }
  16416. // save the index of the last center vertex
  16417. const centerIndexEnd = index;
  16418. // now we generate the surrounding vertices, normals and uvs
  16419. for ( let x = 0; x <= radialSegments; x ++ ) {
  16420. const u = x / radialSegments;
  16421. const theta = u * thetaLength + thetaStart;
  16422. const cosTheta = Math.cos( theta );
  16423. const sinTheta = Math.sin( theta );
  16424. // vertex
  16425. vertex.x = radius * sinTheta;
  16426. vertex.y = halfHeight * sign;
  16427. vertex.z = radius * cosTheta;
  16428. vertices.push( vertex.x, vertex.y, vertex.z );
  16429. // normal
  16430. normals.push( 0, sign, 0 );
  16431. // uv
  16432. uv.x = ( cosTheta * 0.5 ) + 0.5;
  16433. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  16434. uvs.push( uv.x, uv.y );
  16435. // increase index
  16436. index ++;
  16437. }
  16438. // generate indices
  16439. for ( let x = 0; x < radialSegments; x ++ ) {
  16440. const c = centerIndexStart + x;
  16441. const i = centerIndexEnd + x;
  16442. if ( top === true ) {
  16443. // face top
  16444. indices.push( i, i + 1, c );
  16445. } else {
  16446. // face bottom
  16447. indices.push( i + 1, i, c );
  16448. }
  16449. groupCount += 3;
  16450. }
  16451. // add a group to the geometry. this will ensure multi material support
  16452. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  16453. // calculate new start value for groups
  16454. groupStart += groupCount;
  16455. }
  16456. }
  16457. }
  16458. class ConeGeometry extends CylinderGeometry {
  16459. constructor( radius = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  16460. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  16461. this.type = 'ConeGeometry';
  16462. this.parameters = {
  16463. radius: radius,
  16464. height: height,
  16465. radialSegments: radialSegments,
  16466. heightSegments: heightSegments,
  16467. openEnded: openEnded,
  16468. thetaStart: thetaStart,
  16469. thetaLength: thetaLength
  16470. };
  16471. }
  16472. }
  16473. class PolyhedronGeometry extends BufferGeometry {
  16474. constructor( vertices, indices, radius = 1, detail = 0 ) {
  16475. super();
  16476. this.type = 'PolyhedronGeometry';
  16477. this.parameters = {
  16478. vertices: vertices,
  16479. indices: indices,
  16480. radius: radius,
  16481. detail: detail
  16482. };
  16483. // default buffer data
  16484. const vertexBuffer = [];
  16485. const uvBuffer = [];
  16486. // the subdivision creates the vertex buffer data
  16487. subdivide( detail );
  16488. // all vertices should lie on a conceptual sphere with a given radius
  16489. applyRadius( radius );
  16490. // finally, create the uv data
  16491. generateUVs();
  16492. // build non-indexed geometry
  16493. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16494. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16495. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16496. if ( detail === 0 ) {
  16497. this.computeVertexNormals(); // flat normals
  16498. } else {
  16499. this.normalizeNormals(); // smooth normals
  16500. }
  16501. // helper functions
  16502. function subdivide( detail ) {
  16503. const a = new Vector3();
  16504. const b = new Vector3();
  16505. const c = new Vector3();
  16506. // iterate over all faces and apply a subdivison with the given detail value
  16507. for ( let i = 0; i < indices.length; i += 3 ) {
  16508. // get the vertices of the face
  16509. getVertexByIndex( indices[ i + 0 ], a );
  16510. getVertexByIndex( indices[ i + 1 ], b );
  16511. getVertexByIndex( indices[ i + 2 ], c );
  16512. // perform subdivision
  16513. subdivideFace( a, b, c, detail );
  16514. }
  16515. }
  16516. function subdivideFace( a, b, c, detail ) {
  16517. const cols = detail + 1;
  16518. // we use this multidimensional array as a data structure for creating the subdivision
  16519. const v = [];
  16520. // construct all of the vertices for this subdivision
  16521. for ( let i = 0; i <= cols; i ++ ) {
  16522. v[ i ] = [];
  16523. const aj = a.clone().lerp( c, i / cols );
  16524. const bj = b.clone().lerp( c, i / cols );
  16525. const rows = cols - i;
  16526. for ( let j = 0; j <= rows; j ++ ) {
  16527. if ( j === 0 && i === cols ) {
  16528. v[ i ][ j ] = aj;
  16529. } else {
  16530. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16531. }
  16532. }
  16533. }
  16534. // construct all of the faces
  16535. for ( let i = 0; i < cols; i ++ ) {
  16536. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16537. const k = Math.floor( j / 2 );
  16538. if ( j % 2 === 0 ) {
  16539. pushVertex( v[ i ][ k + 1 ] );
  16540. pushVertex( v[ i + 1 ][ k ] );
  16541. pushVertex( v[ i ][ k ] );
  16542. } else {
  16543. pushVertex( v[ i ][ k + 1 ] );
  16544. pushVertex( v[ i + 1 ][ k + 1 ] );
  16545. pushVertex( v[ i + 1 ][ k ] );
  16546. }
  16547. }
  16548. }
  16549. }
  16550. function applyRadius( radius ) {
  16551. const vertex = new Vector3();
  16552. // iterate over the entire buffer and apply the radius to each vertex
  16553. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  16554. vertex.x = vertexBuffer[ i + 0 ];
  16555. vertex.y = vertexBuffer[ i + 1 ];
  16556. vertex.z = vertexBuffer[ i + 2 ];
  16557. vertex.normalize().multiplyScalar( radius );
  16558. vertexBuffer[ i + 0 ] = vertex.x;
  16559. vertexBuffer[ i + 1 ] = vertex.y;
  16560. vertexBuffer[ i + 2 ] = vertex.z;
  16561. }
  16562. }
  16563. function generateUVs() {
  16564. const vertex = new Vector3();
  16565. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  16566. vertex.x = vertexBuffer[ i + 0 ];
  16567. vertex.y = vertexBuffer[ i + 1 ];
  16568. vertex.z = vertexBuffer[ i + 2 ];
  16569. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16570. const v = inclination( vertex ) / Math.PI + 0.5;
  16571. uvBuffer.push( u, 1 - v );
  16572. }
  16573. correctUVs();
  16574. correctSeam();
  16575. }
  16576. function correctSeam() {
  16577. // handle case when face straddles the seam, see #3269
  16578. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  16579. // uv data of a single face
  16580. const x0 = uvBuffer[ i + 0 ];
  16581. const x1 = uvBuffer[ i + 2 ];
  16582. const x2 = uvBuffer[ i + 4 ];
  16583. const max = Math.max( x0, x1, x2 );
  16584. const min = Math.min( x0, x1, x2 );
  16585. // 0.9 is somewhat arbitrary
  16586. if ( max > 0.9 && min < 0.1 ) {
  16587. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16588. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16589. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16590. }
  16591. }
  16592. }
  16593. function pushVertex( vertex ) {
  16594. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16595. }
  16596. function getVertexByIndex( index, vertex ) {
  16597. const stride = index * 3;
  16598. vertex.x = vertices[ stride + 0 ];
  16599. vertex.y = vertices[ stride + 1 ];
  16600. vertex.z = vertices[ stride + 2 ];
  16601. }
  16602. function correctUVs() {
  16603. const a = new Vector3();
  16604. const b = new Vector3();
  16605. const c = new Vector3();
  16606. const centroid = new Vector3();
  16607. const uvA = new Vector2();
  16608. const uvB = new Vector2();
  16609. const uvC = new Vector2();
  16610. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16611. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16612. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16613. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16614. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16615. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16616. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16617. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16618. const azi = azimuth( centroid );
  16619. correctUV( uvA, j + 0, a, azi );
  16620. correctUV( uvB, j + 2, b, azi );
  16621. correctUV( uvC, j + 4, c, azi );
  16622. }
  16623. }
  16624. function correctUV( uv, stride, vector, azimuth ) {
  16625. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16626. uvBuffer[ stride ] = uv.x - 1;
  16627. }
  16628. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16629. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16630. }
  16631. }
  16632. // Angle around the Y axis, counter-clockwise when looking from above.
  16633. function azimuth( vector ) {
  16634. return Math.atan2( vector.z, - vector.x );
  16635. }
  16636. // Angle above the XZ plane.
  16637. function inclination( vector ) {
  16638. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16639. }
  16640. }
  16641. }
  16642. class DodecahedronGeometry extends PolyhedronGeometry {
  16643. constructor( radius = 1, detail = 0 ) {
  16644. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16645. const r = 1 / t;
  16646. const vertices = [
  16647. // (±1, ±1, ±1)
  16648. - 1, - 1, - 1, - 1, - 1, 1,
  16649. - 1, 1, - 1, - 1, 1, 1,
  16650. 1, - 1, - 1, 1, - 1, 1,
  16651. 1, 1, - 1, 1, 1, 1,
  16652. // (0, ±1/φ, ±φ)
  16653. 0, - r, - t, 0, - r, t,
  16654. 0, r, - t, 0, r, t,
  16655. // (±1/φ, ±φ, 0)
  16656. - r, - t, 0, - r, t, 0,
  16657. r, - t, 0, r, t, 0,
  16658. // (±φ, 0, ±1/φ)
  16659. - t, 0, - r, t, 0, - r,
  16660. - t, 0, r, t, 0, r
  16661. ];
  16662. const indices = [
  16663. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16664. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16665. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16666. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16667. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16668. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16669. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16670. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16671. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16672. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16673. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16674. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16675. ];
  16676. super( vertices, indices, radius, detail );
  16677. this.type = 'DodecahedronGeometry';
  16678. this.parameters = {
  16679. radius: radius,
  16680. detail: detail
  16681. };
  16682. }
  16683. }
  16684. const _v0$2 = new Vector3();
  16685. const _v1$5 = new Vector3();
  16686. const _normal$1 = new Vector3();
  16687. const _triangle = new Triangle();
  16688. class EdgesGeometry extends BufferGeometry {
  16689. constructor( geometry, thresholdAngle ) {
  16690. super();
  16691. this.type = 'EdgesGeometry';
  16692. this.parameters = {
  16693. thresholdAngle: thresholdAngle
  16694. };
  16695. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  16696. if ( geometry.isGeometry === true ) {
  16697. console.error( 'THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16698. return;
  16699. }
  16700. const precisionPoints = 4;
  16701. const precision = Math.pow( 10, precisionPoints );
  16702. const thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  16703. const indexAttr = geometry.getIndex();
  16704. const positionAttr = geometry.getAttribute( 'position' );
  16705. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  16706. const indexArr = [ 0, 0, 0 ];
  16707. const vertKeys = [ 'a', 'b', 'c' ];
  16708. const hashes = new Array( 3 );
  16709. const edgeData = {};
  16710. const vertices = [];
  16711. for ( let i = 0; i < indexCount; i += 3 ) {
  16712. if ( indexAttr ) {
  16713. indexArr[ 0 ] = indexAttr.getX( i );
  16714. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  16715. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  16716. } else {
  16717. indexArr[ 0 ] = i;
  16718. indexArr[ 1 ] = i + 1;
  16719. indexArr[ 2 ] = i + 2;
  16720. }
  16721. const { a, b, c } = _triangle;
  16722. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  16723. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  16724. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  16725. _triangle.getNormal( _normal$1 );
  16726. // create hashes for the edge from the vertices
  16727. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  16728. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  16729. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  16730. // skip degenerate triangles
  16731. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  16732. continue;
  16733. }
  16734. // iterate over every edge
  16735. for ( let j = 0; j < 3; j ++ ) {
  16736. // get the first and next vertex making up the edge
  16737. const jNext = ( j + 1 ) % 3;
  16738. const vecHash0 = hashes[ j ];
  16739. const vecHash1 = hashes[ jNext ];
  16740. const v0 = _triangle[ vertKeys[ j ] ];
  16741. const v1 = _triangle[ vertKeys[ jNext ] ];
  16742. const hash = `${ vecHash0 }_${ vecHash1 }`;
  16743. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  16744. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  16745. // if we found a sibling edge add it into the vertex array if
  16746. // it meets the angle threshold and delete the edge from the map.
  16747. if ( _normal$1.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  16748. vertices.push( v0.x, v0.y, v0.z );
  16749. vertices.push( v1.x, v1.y, v1.z );
  16750. }
  16751. edgeData[ reverseHash ] = null;
  16752. } else if ( ! ( hash in edgeData ) ) {
  16753. // if we've already got an edge here then skip adding a new one
  16754. edgeData[ hash ] = {
  16755. index0: indexArr[ j ],
  16756. index1: indexArr[ jNext ],
  16757. normal: _normal$1.clone(),
  16758. };
  16759. }
  16760. }
  16761. }
  16762. // iterate over all remaining, unmatched edges and add them to the vertex array
  16763. for ( const key in edgeData ) {
  16764. if ( edgeData[ key ] ) {
  16765. const { index0, index1 } = edgeData[ key ];
  16766. _v0$2.fromBufferAttribute( positionAttr, index0 );
  16767. _v1$5.fromBufferAttribute( positionAttr, index1 );
  16768. vertices.push( _v0$2.x, _v0$2.y, _v0$2.z );
  16769. vertices.push( _v1$5.x, _v1$5.y, _v1$5.z );
  16770. }
  16771. }
  16772. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16773. }
  16774. }
  16775. /**
  16776. * Port from https://github.com/mapbox/earcut (v2.2.2)
  16777. */
  16778. const Earcut = {
  16779. triangulate: function ( data, holeIndices, dim ) {
  16780. dim = dim || 2;
  16781. const hasHoles = holeIndices && holeIndices.length;
  16782. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  16783. let outerNode = linkedList( data, 0, outerLen, dim, true );
  16784. const triangles = [];
  16785. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  16786. let minX, minY, maxX, maxY, x, y, invSize;
  16787. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16788. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16789. if ( data.length > 80 * dim ) {
  16790. minX = maxX = data[ 0 ];
  16791. minY = maxY = data[ 1 ];
  16792. for ( let i = dim; i < outerLen; i += dim ) {
  16793. x = data[ i ];
  16794. y = data[ i + 1 ];
  16795. if ( x < minX ) minX = x;
  16796. if ( y < minY ) minY = y;
  16797. if ( x > maxX ) maxX = x;
  16798. if ( y > maxY ) maxY = y;
  16799. }
  16800. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16801. invSize = Math.max( maxX - minX, maxY - minY );
  16802. invSize = invSize !== 0 ? 1 / invSize : 0;
  16803. }
  16804. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16805. return triangles;
  16806. }
  16807. };
  16808. // create a circular doubly linked list from polygon points in the specified winding order
  16809. function linkedList( data, start, end, dim, clockwise ) {
  16810. let i, last;
  16811. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16812. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16813. } else {
  16814. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16815. }
  16816. if ( last && equals( last, last.next ) ) {
  16817. removeNode( last );
  16818. last = last.next;
  16819. }
  16820. return last;
  16821. }
  16822. // eliminate colinear or duplicate points
  16823. function filterPoints( start, end ) {
  16824. if ( ! start ) return start;
  16825. if ( ! end ) end = start;
  16826. let p = start,
  16827. again;
  16828. do {
  16829. again = false;
  16830. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16831. removeNode( p );
  16832. p = end = p.prev;
  16833. if ( p === p.next ) break;
  16834. again = true;
  16835. } else {
  16836. p = p.next;
  16837. }
  16838. } while ( again || p !== end );
  16839. return end;
  16840. }
  16841. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16842. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16843. if ( ! ear ) return;
  16844. // interlink polygon nodes in z-order
  16845. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16846. let stop = ear,
  16847. prev, next;
  16848. // iterate through ears, slicing them one by one
  16849. while ( ear.prev !== ear.next ) {
  16850. prev = ear.prev;
  16851. next = ear.next;
  16852. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16853. // cut off the triangle
  16854. triangles.push( prev.i / dim );
  16855. triangles.push( ear.i / dim );
  16856. triangles.push( next.i / dim );
  16857. removeNode( ear );
  16858. // skipping the next vertex leads to less sliver triangles
  16859. ear = next.next;
  16860. stop = next.next;
  16861. continue;
  16862. }
  16863. ear = next;
  16864. // if we looped through the whole remaining polygon and can't find any more ears
  16865. if ( ear === stop ) {
  16866. // try filtering points and slicing again
  16867. if ( ! pass ) {
  16868. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16869. // if this didn't work, try curing all small self-intersections locally
  16870. } else if ( pass === 1 ) {
  16871. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  16872. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16873. // as a last resort, try splitting the remaining polygon into two
  16874. } else if ( pass === 2 ) {
  16875. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16876. }
  16877. break;
  16878. }
  16879. }
  16880. }
  16881. // check whether a polygon node forms a valid ear with adjacent nodes
  16882. function isEar( ear ) {
  16883. const a = ear.prev,
  16884. b = ear,
  16885. c = ear.next;
  16886. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16887. // now make sure we don't have other points inside the potential ear
  16888. let p = ear.next.next;
  16889. while ( p !== ear.prev ) {
  16890. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16891. area( p.prev, p, p.next ) >= 0 ) return false;
  16892. p = p.next;
  16893. }
  16894. return true;
  16895. }
  16896. function isEarHashed( ear, minX, minY, invSize ) {
  16897. const a = ear.prev,
  16898. b = ear,
  16899. c = ear.next;
  16900. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16901. // triangle bbox; min & max are calculated like this for speed
  16902. const minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16903. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16904. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16905. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16906. // z-order range for the current triangle bbox;
  16907. const minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16908. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16909. let p = ear.prevZ,
  16910. n = ear.nextZ;
  16911. // look for points inside the triangle in both directions
  16912. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  16913. if ( p !== ear.prev && p !== ear.next &&
  16914. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16915. area( p.prev, p, p.next ) >= 0 ) return false;
  16916. p = p.prevZ;
  16917. if ( n !== ear.prev && n !== ear.next &&
  16918. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  16919. area( n.prev, n, n.next ) >= 0 ) return false;
  16920. n = n.nextZ;
  16921. }
  16922. // look for remaining points in decreasing z-order
  16923. while ( p && p.z >= minZ ) {
  16924. if ( p !== ear.prev && p !== ear.next &&
  16925. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16926. area( p.prev, p, p.next ) >= 0 ) return false;
  16927. p = p.prevZ;
  16928. }
  16929. // look for remaining points in increasing z-order
  16930. while ( n && n.z <= maxZ ) {
  16931. if ( n !== ear.prev && n !== ear.next &&
  16932. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  16933. area( n.prev, n, n.next ) >= 0 ) return false;
  16934. n = n.nextZ;
  16935. }
  16936. return true;
  16937. }
  16938. // go through all polygon nodes and cure small local self-intersections
  16939. function cureLocalIntersections( start, triangles, dim ) {
  16940. let p = start;
  16941. do {
  16942. const a = p.prev,
  16943. b = p.next.next;
  16944. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  16945. triangles.push( a.i / dim );
  16946. triangles.push( p.i / dim );
  16947. triangles.push( b.i / dim );
  16948. // remove two nodes involved
  16949. removeNode( p );
  16950. removeNode( p.next );
  16951. p = start = b;
  16952. }
  16953. p = p.next;
  16954. } while ( p !== start );
  16955. return filterPoints( p );
  16956. }
  16957. // try splitting polygon into two and triangulate them independently
  16958. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  16959. // look for a valid diagonal that divides the polygon into two
  16960. let a = start;
  16961. do {
  16962. let b = a.next.next;
  16963. while ( b !== a.prev ) {
  16964. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  16965. // split the polygon in two by the diagonal
  16966. let c = splitPolygon( a, b );
  16967. // filter colinear points around the cuts
  16968. a = filterPoints( a, a.next );
  16969. c = filterPoints( c, c.next );
  16970. // run earcut on each half
  16971. earcutLinked( a, triangles, dim, minX, minY, invSize );
  16972. earcutLinked( c, triangles, dim, minX, minY, invSize );
  16973. return;
  16974. }
  16975. b = b.next;
  16976. }
  16977. a = a.next;
  16978. } while ( a !== start );
  16979. }
  16980. // link every hole into the outer loop, producing a single-ring polygon without holes
  16981. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  16982. const queue = [];
  16983. let i, len, start, end, list;
  16984. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  16985. start = holeIndices[ i ] * dim;
  16986. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  16987. list = linkedList( data, start, end, dim, false );
  16988. if ( list === list.next ) list.steiner = true;
  16989. queue.push( getLeftmost( list ) );
  16990. }
  16991. queue.sort( compareX );
  16992. // process holes from left to right
  16993. for ( i = 0; i < queue.length; i ++ ) {
  16994. eliminateHole( queue[ i ], outerNode );
  16995. outerNode = filterPoints( outerNode, outerNode.next );
  16996. }
  16997. return outerNode;
  16998. }
  16999. function compareX( a, b ) {
  17000. return a.x - b.x;
  17001. }
  17002. // find a bridge between vertices that connects hole with an outer ring and and link it
  17003. function eliminateHole( hole, outerNode ) {
  17004. outerNode = findHoleBridge( hole, outerNode );
  17005. if ( outerNode ) {
  17006. const b = splitPolygon( outerNode, hole );
  17007. // filter collinear points around the cuts
  17008. filterPoints( outerNode, outerNode.next );
  17009. filterPoints( b, b.next );
  17010. }
  17011. }
  17012. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17013. function findHoleBridge( hole, outerNode ) {
  17014. let p = outerNode;
  17015. const hx = hole.x;
  17016. const hy = hole.y;
  17017. let qx = - Infinity, m;
  17018. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17019. // segment's endpoint with lesser x will be potential connection point
  17020. do {
  17021. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17022. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17023. if ( x <= hx && x > qx ) {
  17024. qx = x;
  17025. if ( x === hx ) {
  17026. if ( hy === p.y ) return p;
  17027. if ( hy === p.next.y ) return p.next;
  17028. }
  17029. m = p.x < p.next.x ? p : p.next;
  17030. }
  17031. }
  17032. p = p.next;
  17033. } while ( p !== outerNode );
  17034. if ( ! m ) return null;
  17035. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  17036. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17037. // if there are no points found, we have a valid connection;
  17038. // otherwise choose the point of the minimum angle with the ray as connection point
  17039. const stop = m,
  17040. mx = m.x,
  17041. my = m.y;
  17042. let tanMin = Infinity, tan;
  17043. p = m;
  17044. do {
  17045. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17046. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17047. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17048. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  17049. m = p;
  17050. tanMin = tan;
  17051. }
  17052. }
  17053. p = p.next;
  17054. } while ( p !== stop );
  17055. return m;
  17056. }
  17057. // whether sector in vertex m contains sector in vertex p in the same coordinates
  17058. function sectorContainsSector( m, p ) {
  17059. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  17060. }
  17061. // interlink polygon nodes in z-order
  17062. function indexCurve( start, minX, minY, invSize ) {
  17063. let p = start;
  17064. do {
  17065. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17066. p.prevZ = p.prev;
  17067. p.nextZ = p.next;
  17068. p = p.next;
  17069. } while ( p !== start );
  17070. p.prevZ.nextZ = null;
  17071. p.prevZ = null;
  17072. sortLinked( p );
  17073. }
  17074. // Simon Tatham's linked list merge sort algorithm
  17075. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17076. function sortLinked( list ) {
  17077. let i, p, q, e, tail, numMerges, pSize, qSize,
  17078. inSize = 1;
  17079. do {
  17080. p = list;
  17081. list = null;
  17082. tail = null;
  17083. numMerges = 0;
  17084. while ( p ) {
  17085. numMerges ++;
  17086. q = p;
  17087. pSize = 0;
  17088. for ( i = 0; i < inSize; i ++ ) {
  17089. pSize ++;
  17090. q = q.nextZ;
  17091. if ( ! q ) break;
  17092. }
  17093. qSize = inSize;
  17094. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17095. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17096. e = p;
  17097. p = p.nextZ;
  17098. pSize --;
  17099. } else {
  17100. e = q;
  17101. q = q.nextZ;
  17102. qSize --;
  17103. }
  17104. if ( tail ) tail.nextZ = e;
  17105. else list = e;
  17106. e.prevZ = tail;
  17107. tail = e;
  17108. }
  17109. p = q;
  17110. }
  17111. tail.nextZ = null;
  17112. inSize *= 2;
  17113. } while ( numMerges > 1 );
  17114. return list;
  17115. }
  17116. // z-order of a point given coords and inverse of the longer side of data bbox
  17117. function zOrder( x, y, minX, minY, invSize ) {
  17118. // coords are transformed into non-negative 15-bit integer range
  17119. x = 32767 * ( x - minX ) * invSize;
  17120. y = 32767 * ( y - minY ) * invSize;
  17121. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17122. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17123. x = ( x | ( x << 2 ) ) & 0x33333333;
  17124. x = ( x | ( x << 1 ) ) & 0x55555555;
  17125. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17126. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17127. y = ( y | ( y << 2 ) ) & 0x33333333;
  17128. y = ( y | ( y << 1 ) ) & 0x55555555;
  17129. return x | ( y << 1 );
  17130. }
  17131. // find the leftmost node of a polygon ring
  17132. function getLeftmost( start ) {
  17133. let p = start,
  17134. leftmost = start;
  17135. do {
  17136. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17137. p = p.next;
  17138. } while ( p !== start );
  17139. return leftmost;
  17140. }
  17141. // check if a point lies within a convex triangle
  17142. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17143. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17144. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17145. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17146. }
  17147. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17148. function isValidDiagonal( a, b ) {
  17149. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  17150. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  17151. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  17152. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  17153. }
  17154. // signed area of a triangle
  17155. function area( p, q, r ) {
  17156. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17157. }
  17158. // check if two points are equal
  17159. function equals( p1, p2 ) {
  17160. return p1.x === p2.x && p1.y === p2.y;
  17161. }
  17162. // check if two segments intersect
  17163. function intersects( p1, q1, p2, q2 ) {
  17164. const o1 = sign( area( p1, q1, p2 ) );
  17165. const o2 = sign( area( p1, q1, q2 ) );
  17166. const o3 = sign( area( p2, q2, p1 ) );
  17167. const o4 = sign( area( p2, q2, q1 ) );
  17168. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  17169. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  17170. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  17171. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  17172. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  17173. return false;
  17174. }
  17175. // for collinear points p, q, r, check if point q lies on segment pr
  17176. function onSegment( p, q, r ) {
  17177. 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 );
  17178. }
  17179. function sign( num ) {
  17180. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  17181. }
  17182. // check if a polygon diagonal intersects any polygon segments
  17183. function intersectsPolygon( a, b ) {
  17184. let p = a;
  17185. do {
  17186. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17187. intersects( p, p.next, a, b ) ) return true;
  17188. p = p.next;
  17189. } while ( p !== a );
  17190. return false;
  17191. }
  17192. // check if a polygon diagonal is locally inside the polygon
  17193. function locallyInside( a, b ) {
  17194. return area( a.prev, a, a.next ) < 0 ?
  17195. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17196. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17197. }
  17198. // check if the middle point of a polygon diagonal is inside the polygon
  17199. function middleInside( a, b ) {
  17200. let p = a,
  17201. inside = false;
  17202. const px = ( a.x + b.x ) / 2,
  17203. py = ( a.y + b.y ) / 2;
  17204. do {
  17205. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17206. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17207. inside = ! inside;
  17208. p = p.next;
  17209. } while ( p !== a );
  17210. return inside;
  17211. }
  17212. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17213. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17214. function splitPolygon( a, b ) {
  17215. const a2 = new Node( a.i, a.x, a.y ),
  17216. b2 = new Node( b.i, b.x, b.y ),
  17217. an = a.next,
  17218. bp = b.prev;
  17219. a.next = b;
  17220. b.prev = a;
  17221. a2.next = an;
  17222. an.prev = a2;
  17223. b2.next = a2;
  17224. a2.prev = b2;
  17225. bp.next = b2;
  17226. b2.prev = bp;
  17227. return b2;
  17228. }
  17229. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17230. function insertNode( i, x, y, last ) {
  17231. const p = new Node( i, x, y );
  17232. if ( ! last ) {
  17233. p.prev = p;
  17234. p.next = p;
  17235. } else {
  17236. p.next = last.next;
  17237. p.prev = last;
  17238. last.next.prev = p;
  17239. last.next = p;
  17240. }
  17241. return p;
  17242. }
  17243. function removeNode( p ) {
  17244. p.next.prev = p.prev;
  17245. p.prev.next = p.next;
  17246. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17247. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17248. }
  17249. function Node( i, x, y ) {
  17250. // vertex index in coordinates array
  17251. this.i = i;
  17252. // vertex coordinates
  17253. this.x = x;
  17254. this.y = y;
  17255. // previous and next vertex nodes in a polygon ring
  17256. this.prev = null;
  17257. this.next = null;
  17258. // z-order curve value
  17259. this.z = null;
  17260. // previous and next nodes in z-order
  17261. this.prevZ = null;
  17262. this.nextZ = null;
  17263. // indicates whether this is a steiner point
  17264. this.steiner = false;
  17265. }
  17266. function signedArea( data, start, end, dim ) {
  17267. let sum = 0;
  17268. for ( let i = start, j = end - dim; i < end; i += dim ) {
  17269. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17270. j = i;
  17271. }
  17272. return sum;
  17273. }
  17274. const ShapeUtils = {
  17275. // calculate area of the contour polygon
  17276. area: function ( contour ) {
  17277. const n = contour.length;
  17278. let a = 0.0;
  17279. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  17280. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17281. }
  17282. return a * 0.5;
  17283. },
  17284. isClockWise: function ( pts ) {
  17285. return ShapeUtils.area( pts ) < 0;
  17286. },
  17287. triangulateShape: function ( contour, holes ) {
  17288. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17289. const holeIndices = []; // array of hole indices
  17290. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17291. removeDupEndPts( contour );
  17292. addContour( vertices, contour );
  17293. //
  17294. let holeIndex = contour.length;
  17295. holes.forEach( removeDupEndPts );
  17296. for ( let i = 0; i < holes.length; i ++ ) {
  17297. holeIndices.push( holeIndex );
  17298. holeIndex += holes[ i ].length;
  17299. addContour( vertices, holes[ i ] );
  17300. }
  17301. //
  17302. const triangles = Earcut.triangulate( vertices, holeIndices );
  17303. //
  17304. for ( let i = 0; i < triangles.length; i += 3 ) {
  17305. faces.push( triangles.slice( i, i + 3 ) );
  17306. }
  17307. return faces;
  17308. }
  17309. };
  17310. function removeDupEndPts( points ) {
  17311. const l = points.length;
  17312. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17313. points.pop();
  17314. }
  17315. }
  17316. function addContour( vertices, contour ) {
  17317. for ( let i = 0; i < contour.length; i ++ ) {
  17318. vertices.push( contour[ i ].x );
  17319. vertices.push( contour[ i ].y );
  17320. }
  17321. }
  17322. /**
  17323. * Creates extruded geometry from a path shape.
  17324. *
  17325. * parameters = {
  17326. *
  17327. * curveSegments: <int>, // number of points on the curves
  17328. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17329. * depth: <float>, // Depth to extrude the shape
  17330. *
  17331. * bevelEnabled: <bool>, // turn on bevel
  17332. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17333. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17334. * bevelOffset: <float>, // how far from shape outline does bevel start
  17335. * bevelSegments: <int>, // number of bevel layers
  17336. *
  17337. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17338. *
  17339. * UVGenerator: <Object> // object that provides UV generator functions
  17340. *
  17341. * }
  17342. */
  17343. class ExtrudeGeometry extends BufferGeometry {
  17344. constructor( shapes, options ) {
  17345. super();
  17346. this.type = 'ExtrudeGeometry';
  17347. this.parameters = {
  17348. shapes: shapes,
  17349. options: options
  17350. };
  17351. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17352. const scope = this;
  17353. const verticesArray = [];
  17354. const uvArray = [];
  17355. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  17356. const shape = shapes[ i ];
  17357. addShape( shape );
  17358. }
  17359. // build geometry
  17360. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17361. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17362. this.computeVertexNormals();
  17363. // functions
  17364. function addShape( shape ) {
  17365. const placeholder = [];
  17366. // options
  17367. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17368. const steps = options.steps !== undefined ? options.steps : 1;
  17369. let depth = options.depth !== undefined ? options.depth : 100;
  17370. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17371. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17372. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17373. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17374. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17375. const extrudePath = options.extrudePath;
  17376. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17377. // deprecated options
  17378. if ( options.amount !== undefined ) {
  17379. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17380. depth = options.amount;
  17381. }
  17382. //
  17383. let extrudePts, extrudeByPath = false;
  17384. let splineTube, binormal, normal, position2;
  17385. if ( extrudePath ) {
  17386. extrudePts = extrudePath.getSpacedPoints( steps );
  17387. extrudeByPath = true;
  17388. bevelEnabled = false; // bevels not supported for path extrusion
  17389. // SETUP TNB variables
  17390. // TODO1 - have a .isClosed in spline?
  17391. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17392. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17393. binormal = new Vector3();
  17394. normal = new Vector3();
  17395. position2 = new Vector3();
  17396. }
  17397. // Safeguards if bevels are not enabled
  17398. if ( ! bevelEnabled ) {
  17399. bevelSegments = 0;
  17400. bevelThickness = 0;
  17401. bevelSize = 0;
  17402. bevelOffset = 0;
  17403. }
  17404. // Variables initialization
  17405. const shapePoints = shape.extractPoints( curveSegments );
  17406. let vertices = shapePoints.shape;
  17407. const holes = shapePoints.holes;
  17408. const reverse = ! ShapeUtils.isClockWise( vertices );
  17409. if ( reverse ) {
  17410. vertices = vertices.reverse();
  17411. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17412. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17413. const ahole = holes[ h ];
  17414. if ( ShapeUtils.isClockWise( ahole ) ) {
  17415. holes[ h ] = ahole.reverse();
  17416. }
  17417. }
  17418. }
  17419. const faces = ShapeUtils.triangulateShape( vertices, holes );
  17420. /* Vertices */
  17421. const contour = vertices; // vertices has all points but contour has only points of circumference
  17422. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17423. const ahole = holes[ h ];
  17424. vertices = vertices.concat( ahole );
  17425. }
  17426. function scalePt2( pt, vec, size ) {
  17427. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  17428. return vec.clone().multiplyScalar( size ).add( pt );
  17429. }
  17430. const vlen = vertices.length, flen = faces.length;
  17431. // Find directions for point movement
  17432. function getBevelVec( inPt, inPrev, inNext ) {
  17433. // computes for inPt the corresponding point inPt' on a new contour
  17434. // shifted by 1 unit (length of normalized vector) to the left
  17435. // if we walk along contour clockwise, this new contour is outside the old one
  17436. //
  17437. // inPt' is the intersection of the two lines parallel to the two
  17438. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17439. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17440. // good reading for geometry algorithms (here: line-line intersection)
  17441. // http://geomalgorithms.com/a05-_intersect-1.html
  17442. const v_prev_x = inPt.x - inPrev.x,
  17443. v_prev_y = inPt.y - inPrev.y;
  17444. const v_next_x = inNext.x - inPt.x,
  17445. v_next_y = inNext.y - inPt.y;
  17446. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17447. // check for collinear edges
  17448. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17449. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17450. // not collinear
  17451. // length of vectors for normalizing
  17452. const v_prev_len = Math.sqrt( v_prev_lensq );
  17453. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17454. // shift adjacent points by unit vectors to the left
  17455. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17456. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17457. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17458. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17459. // scaling factor for v_prev to intersection point
  17460. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17461. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17462. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17463. // vector from inPt to intersection point
  17464. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17465. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17466. // Don't normalize!, otherwise sharp corners become ugly
  17467. // but prevent crazy spikes
  17468. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17469. if ( v_trans_lensq <= 2 ) {
  17470. return new Vector2( v_trans_x, v_trans_y );
  17471. } else {
  17472. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17473. }
  17474. } else {
  17475. // handle special case of collinear edges
  17476. let direction_eq = false; // assumes: opposite
  17477. if ( v_prev_x > Number.EPSILON ) {
  17478. if ( v_next_x > Number.EPSILON ) {
  17479. direction_eq = true;
  17480. }
  17481. } else {
  17482. if ( v_prev_x < - Number.EPSILON ) {
  17483. if ( v_next_x < - Number.EPSILON ) {
  17484. direction_eq = true;
  17485. }
  17486. } else {
  17487. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17488. direction_eq = true;
  17489. }
  17490. }
  17491. }
  17492. if ( direction_eq ) {
  17493. // console.log("Warning: lines are a straight sequence");
  17494. v_trans_x = - v_prev_y;
  17495. v_trans_y = v_prev_x;
  17496. shrink_by = Math.sqrt( v_prev_lensq );
  17497. } else {
  17498. // console.log("Warning: lines are a straight spike");
  17499. v_trans_x = v_prev_x;
  17500. v_trans_y = v_prev_y;
  17501. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17502. }
  17503. }
  17504. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17505. }
  17506. const contourMovements = [];
  17507. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17508. if ( j === il ) j = 0;
  17509. if ( k === il ) k = 0;
  17510. // (j)---(i)---(k)
  17511. // console.log('i,j,k', i, j , k)
  17512. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17513. }
  17514. const holesMovements = [];
  17515. let oneHoleMovements, verticesMovements = contourMovements.concat();
  17516. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17517. const ahole = holes[ h ];
  17518. oneHoleMovements = [];
  17519. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17520. if ( j === il ) j = 0;
  17521. if ( k === il ) k = 0;
  17522. // (j)---(i)---(k)
  17523. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17524. }
  17525. holesMovements.push( oneHoleMovements );
  17526. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17527. }
  17528. // Loop bevelSegments, 1 for the front, 1 for the back
  17529. for ( let b = 0; b < bevelSegments; b ++ ) {
  17530. //for ( b = bevelSegments; b > 0; b -- ) {
  17531. const t = b / bevelSegments;
  17532. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17533. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17534. // contract shape
  17535. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  17536. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17537. v( vert.x, vert.y, - z );
  17538. }
  17539. // expand holes
  17540. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17541. const ahole = holes[ h ];
  17542. oneHoleMovements = holesMovements[ h ];
  17543. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  17544. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17545. v( vert.x, vert.y, - z );
  17546. }
  17547. }
  17548. }
  17549. const bs = bevelSize + bevelOffset;
  17550. // Back facing vertices
  17551. for ( let i = 0; i < vlen; i ++ ) {
  17552. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17553. if ( ! extrudeByPath ) {
  17554. v( vert.x, vert.y, 0 );
  17555. } else {
  17556. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17557. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17558. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17559. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17560. v( position2.x, position2.y, position2.z );
  17561. }
  17562. }
  17563. // Add stepped vertices...
  17564. // Including front facing vertices
  17565. for ( let s = 1; s <= steps; s ++ ) {
  17566. for ( let i = 0; i < vlen; i ++ ) {
  17567. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17568. if ( ! extrudeByPath ) {
  17569. v( vert.x, vert.y, depth / steps * s );
  17570. } else {
  17571. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17572. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17573. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17574. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17575. v( position2.x, position2.y, position2.z );
  17576. }
  17577. }
  17578. }
  17579. // Add bevel segments planes
  17580. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17581. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  17582. const t = b / bevelSegments;
  17583. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17584. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17585. // contract shape
  17586. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  17587. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17588. v( vert.x, vert.y, depth + z );
  17589. }
  17590. // expand holes
  17591. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17592. const ahole = holes[ h ];
  17593. oneHoleMovements = holesMovements[ h ];
  17594. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  17595. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17596. if ( ! extrudeByPath ) {
  17597. v( vert.x, vert.y, depth + z );
  17598. } else {
  17599. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17600. }
  17601. }
  17602. }
  17603. }
  17604. /* Faces */
  17605. // Top and bottom faces
  17606. buildLidFaces();
  17607. // Sides faces
  17608. buildSideFaces();
  17609. ///// Internal functions
  17610. function buildLidFaces() {
  17611. const start = verticesArray.length / 3;
  17612. if ( bevelEnabled ) {
  17613. let layer = 0; // steps + 1
  17614. let offset = vlen * layer;
  17615. // Bottom faces
  17616. for ( let i = 0; i < flen; i ++ ) {
  17617. const face = faces[ i ];
  17618. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17619. }
  17620. layer = steps + bevelSegments * 2;
  17621. offset = vlen * layer;
  17622. // Top faces
  17623. for ( let i = 0; i < flen; i ++ ) {
  17624. const face = faces[ i ];
  17625. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17626. }
  17627. } else {
  17628. // Bottom faces
  17629. for ( let i = 0; i < flen; i ++ ) {
  17630. const face = faces[ i ];
  17631. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17632. }
  17633. // Top faces
  17634. for ( let i = 0; i < flen; i ++ ) {
  17635. const face = faces[ i ];
  17636. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17637. }
  17638. }
  17639. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17640. }
  17641. // Create faces for the z-sides of the shape
  17642. function buildSideFaces() {
  17643. const start = verticesArray.length / 3;
  17644. let layeroffset = 0;
  17645. sidewalls( contour, layeroffset );
  17646. layeroffset += contour.length;
  17647. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  17648. const ahole = holes[ h ];
  17649. sidewalls( ahole, layeroffset );
  17650. //, true
  17651. layeroffset += ahole.length;
  17652. }
  17653. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17654. }
  17655. function sidewalls( contour, layeroffset ) {
  17656. let i = contour.length;
  17657. while ( -- i >= 0 ) {
  17658. const j = i;
  17659. let k = i - 1;
  17660. if ( k < 0 ) k = contour.length - 1;
  17661. //console.log('b', i,j, i-1, k,vertices.length);
  17662. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  17663. const slen1 = vlen * s;
  17664. const slen2 = vlen * ( s + 1 );
  17665. const a = layeroffset + j + slen1,
  17666. b = layeroffset + k + slen1,
  17667. c = layeroffset + k + slen2,
  17668. d = layeroffset + j + slen2;
  17669. f4( a, b, c, d );
  17670. }
  17671. }
  17672. }
  17673. function v( x, y, z ) {
  17674. placeholder.push( x );
  17675. placeholder.push( y );
  17676. placeholder.push( z );
  17677. }
  17678. function f3( a, b, c ) {
  17679. addVertex( a );
  17680. addVertex( b );
  17681. addVertex( c );
  17682. const nextIndex = verticesArray.length / 3;
  17683. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17684. addUV( uvs[ 0 ] );
  17685. addUV( uvs[ 1 ] );
  17686. addUV( uvs[ 2 ] );
  17687. }
  17688. function f4( a, b, c, d ) {
  17689. addVertex( a );
  17690. addVertex( b );
  17691. addVertex( d );
  17692. addVertex( b );
  17693. addVertex( c );
  17694. addVertex( d );
  17695. const nextIndex = verticesArray.length / 3;
  17696. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17697. addUV( uvs[ 0 ] );
  17698. addUV( uvs[ 1 ] );
  17699. addUV( uvs[ 3 ] );
  17700. addUV( uvs[ 1 ] );
  17701. addUV( uvs[ 2 ] );
  17702. addUV( uvs[ 3 ] );
  17703. }
  17704. function addVertex( index ) {
  17705. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17706. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17707. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17708. }
  17709. function addUV( vector2 ) {
  17710. uvArray.push( vector2.x );
  17711. uvArray.push( vector2.y );
  17712. }
  17713. }
  17714. }
  17715. toJSON() {
  17716. const data = BufferGeometry.prototype.toJSON.call( this );
  17717. const shapes = this.parameters.shapes;
  17718. const options = this.parameters.options;
  17719. return toJSON( shapes, options, data );
  17720. }
  17721. }
  17722. const WorldUVGenerator = {
  17723. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17724. const a_x = vertices[ indexA * 3 ];
  17725. const a_y = vertices[ indexA * 3 + 1 ];
  17726. const b_x = vertices[ indexB * 3 ];
  17727. const b_y = vertices[ indexB * 3 + 1 ];
  17728. const c_x = vertices[ indexC * 3 ];
  17729. const c_y = vertices[ indexC * 3 + 1 ];
  17730. return [
  17731. new Vector2( a_x, a_y ),
  17732. new Vector2( b_x, b_y ),
  17733. new Vector2( c_x, c_y )
  17734. ];
  17735. },
  17736. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17737. const a_x = vertices[ indexA * 3 ];
  17738. const a_y = vertices[ indexA * 3 + 1 ];
  17739. const a_z = vertices[ indexA * 3 + 2 ];
  17740. const b_x = vertices[ indexB * 3 ];
  17741. const b_y = vertices[ indexB * 3 + 1 ];
  17742. const b_z = vertices[ indexB * 3 + 2 ];
  17743. const c_x = vertices[ indexC * 3 ];
  17744. const c_y = vertices[ indexC * 3 + 1 ];
  17745. const c_z = vertices[ indexC * 3 + 2 ];
  17746. const d_x = vertices[ indexD * 3 ];
  17747. const d_y = vertices[ indexD * 3 + 1 ];
  17748. const d_z = vertices[ indexD * 3 + 2 ];
  17749. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17750. return [
  17751. new Vector2( a_x, 1 - a_z ),
  17752. new Vector2( b_x, 1 - b_z ),
  17753. new Vector2( c_x, 1 - c_z ),
  17754. new Vector2( d_x, 1 - d_z )
  17755. ];
  17756. } else {
  17757. return [
  17758. new Vector2( a_y, 1 - a_z ),
  17759. new Vector2( b_y, 1 - b_z ),
  17760. new Vector2( c_y, 1 - c_z ),
  17761. new Vector2( d_y, 1 - d_z )
  17762. ];
  17763. }
  17764. }
  17765. };
  17766. function toJSON( shapes, options, data ) {
  17767. data.shapes = [];
  17768. if ( Array.isArray( shapes ) ) {
  17769. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  17770. const shape = shapes[ i ];
  17771. data.shapes.push( shape.uuid );
  17772. }
  17773. } else {
  17774. data.shapes.push( shapes.uuid );
  17775. }
  17776. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17777. return data;
  17778. }
  17779. class IcosahedronGeometry extends PolyhedronGeometry {
  17780. constructor( radius = 1, detail = 0 ) {
  17781. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17782. const vertices = [
  17783. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17784. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17785. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17786. ];
  17787. const indices = [
  17788. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17789. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17790. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17791. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17792. ];
  17793. super( vertices, indices, radius, detail );
  17794. this.type = 'IcosahedronGeometry';
  17795. this.parameters = {
  17796. radius: radius,
  17797. detail: detail
  17798. };
  17799. }
  17800. }
  17801. class LatheGeometry extends BufferGeometry {
  17802. constructor( points, segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
  17803. super();
  17804. this.type = 'LatheGeometry';
  17805. this.parameters = {
  17806. points: points,
  17807. segments: segments,
  17808. phiStart: phiStart,
  17809. phiLength: phiLength
  17810. };
  17811. segments = Math.floor( segments );
  17812. // clamp phiLength so it's in range of [ 0, 2PI ]
  17813. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  17814. // buffers
  17815. const indices = [];
  17816. const vertices = [];
  17817. const uvs = [];
  17818. // helper variables
  17819. const inverseSegments = 1.0 / segments;
  17820. const vertex = new Vector3();
  17821. const uv = new Vector2();
  17822. // generate vertices and uvs
  17823. for ( let i = 0; i <= segments; i ++ ) {
  17824. const phi = phiStart + i * inverseSegments * phiLength;
  17825. const sin = Math.sin( phi );
  17826. const cos = Math.cos( phi );
  17827. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  17828. // vertex
  17829. vertex.x = points[ j ].x * sin;
  17830. vertex.y = points[ j ].y;
  17831. vertex.z = points[ j ].x * cos;
  17832. vertices.push( vertex.x, vertex.y, vertex.z );
  17833. // uv
  17834. uv.x = i / segments;
  17835. uv.y = j / ( points.length - 1 );
  17836. uvs.push( uv.x, uv.y );
  17837. }
  17838. }
  17839. // indices
  17840. for ( let i = 0; i < segments; i ++ ) {
  17841. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  17842. const base = j + i * points.length;
  17843. const a = base;
  17844. const b = base + points.length;
  17845. const c = base + points.length + 1;
  17846. const d = base + 1;
  17847. // faces
  17848. indices.push( a, b, d );
  17849. indices.push( b, c, d );
  17850. }
  17851. }
  17852. // build geometry
  17853. this.setIndex( indices );
  17854. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17855. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17856. // generate normals
  17857. this.computeVertexNormals();
  17858. // if the geometry is closed, we need to average the normals along the seam.
  17859. // because the corresponding vertices are identical (but still have different UVs).
  17860. if ( phiLength === Math.PI * 2 ) {
  17861. const normals = this.attributes.normal.array;
  17862. const n1 = new Vector3();
  17863. const n2 = new Vector3();
  17864. const n = new Vector3();
  17865. // this is the buffer offset for the last line of vertices
  17866. const base = segments * points.length * 3;
  17867. for ( let i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  17868. // select the normal of the vertex in the first line
  17869. n1.x = normals[ j + 0 ];
  17870. n1.y = normals[ j + 1 ];
  17871. n1.z = normals[ j + 2 ];
  17872. // select the normal of the vertex in the last line
  17873. n2.x = normals[ base + j + 0 ];
  17874. n2.y = normals[ base + j + 1 ];
  17875. n2.z = normals[ base + j + 2 ];
  17876. // average normals
  17877. n.addVectors( n1, n2 ).normalize();
  17878. // assign the new values to both normals
  17879. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  17880. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  17881. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  17882. }
  17883. }
  17884. }
  17885. }
  17886. class OctahedronGeometry extends PolyhedronGeometry {
  17887. constructor( radius = 1, detail = 0 ) {
  17888. const vertices = [
  17889. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17890. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17891. ];
  17892. const indices = [
  17893. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17894. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17895. 1, 3, 4, 1, 4, 2
  17896. ];
  17897. super( vertices, indices, radius, detail );
  17898. this.type = 'OctahedronGeometry';
  17899. this.parameters = {
  17900. radius: radius,
  17901. detail: detail
  17902. };
  17903. }
  17904. }
  17905. /**
  17906. * Parametric Surfaces Geometry
  17907. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  17908. */
  17909. function ParametricGeometry( func, slices, stacks ) {
  17910. BufferGeometry.call( this );
  17911. this.type = 'ParametricGeometry';
  17912. this.parameters = {
  17913. func: func,
  17914. slices: slices,
  17915. stacks: stacks
  17916. };
  17917. // buffers
  17918. const indices = [];
  17919. const vertices = [];
  17920. const normals = [];
  17921. const uvs = [];
  17922. const EPS = 0.00001;
  17923. const normal = new Vector3();
  17924. const p0 = new Vector3(), p1 = new Vector3();
  17925. const pu = new Vector3(), pv = new Vector3();
  17926. if ( func.length < 3 ) {
  17927. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17928. }
  17929. // generate vertices, normals and uvs
  17930. const sliceCount = slices + 1;
  17931. for ( let i = 0; i <= stacks; i ++ ) {
  17932. const v = i / stacks;
  17933. for ( let j = 0; j <= slices; j ++ ) {
  17934. const u = j / slices;
  17935. // vertex
  17936. func( u, v, p0 );
  17937. vertices.push( p0.x, p0.y, p0.z );
  17938. // normal
  17939. // approximate tangent vectors via finite differences
  17940. if ( u - EPS >= 0 ) {
  17941. func( u - EPS, v, p1 );
  17942. pu.subVectors( p0, p1 );
  17943. } else {
  17944. func( u + EPS, v, p1 );
  17945. pu.subVectors( p1, p0 );
  17946. }
  17947. if ( v - EPS >= 0 ) {
  17948. func( u, v - EPS, p1 );
  17949. pv.subVectors( p0, p1 );
  17950. } else {
  17951. func( u, v + EPS, p1 );
  17952. pv.subVectors( p1, p0 );
  17953. }
  17954. // cross product of tangent vectors returns surface normal
  17955. normal.crossVectors( pu, pv ).normalize();
  17956. normals.push( normal.x, normal.y, normal.z );
  17957. // uv
  17958. uvs.push( u, v );
  17959. }
  17960. }
  17961. // generate indices
  17962. for ( let i = 0; i < stacks; i ++ ) {
  17963. for ( let j = 0; j < slices; j ++ ) {
  17964. const a = i * sliceCount + j;
  17965. const b = i * sliceCount + j + 1;
  17966. const c = ( i + 1 ) * sliceCount + j + 1;
  17967. const d = ( i + 1 ) * sliceCount + j;
  17968. // faces one and two
  17969. indices.push( a, b, d );
  17970. indices.push( b, c, d );
  17971. }
  17972. }
  17973. // build geometry
  17974. this.setIndex( indices );
  17975. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17976. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17977. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17978. }
  17979. ParametricGeometry.prototype = Object.create( BufferGeometry.prototype );
  17980. ParametricGeometry.prototype.constructor = ParametricGeometry;
  17981. class RingGeometry extends BufferGeometry {
  17982. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 8, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17983. super();
  17984. this.type = 'RingGeometry';
  17985. this.parameters = {
  17986. innerRadius: innerRadius,
  17987. outerRadius: outerRadius,
  17988. thetaSegments: thetaSegments,
  17989. phiSegments: phiSegments,
  17990. thetaStart: thetaStart,
  17991. thetaLength: thetaLength
  17992. };
  17993. thetaSegments = Math.max( 3, thetaSegments );
  17994. phiSegments = Math.max( 1, phiSegments );
  17995. // buffers
  17996. const indices = [];
  17997. const vertices = [];
  17998. const normals = [];
  17999. const uvs = [];
  18000. // some helper variables
  18001. let radius = innerRadius;
  18002. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18003. const vertex = new Vector3();
  18004. const uv = new Vector2();
  18005. // generate vertices, normals and uvs
  18006. for ( let j = 0; j <= phiSegments; j ++ ) {
  18007. for ( let i = 0; i <= thetaSegments; i ++ ) {
  18008. // values are generate from the inside of the ring to the outside
  18009. const segment = thetaStart + i / thetaSegments * thetaLength;
  18010. // vertex
  18011. vertex.x = radius * Math.cos( segment );
  18012. vertex.y = radius * Math.sin( segment );
  18013. vertices.push( vertex.x, vertex.y, vertex.z );
  18014. // normal
  18015. normals.push( 0, 0, 1 );
  18016. // uv
  18017. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18018. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18019. uvs.push( uv.x, uv.y );
  18020. }
  18021. // increase the radius for next row of vertices
  18022. radius += radiusStep;
  18023. }
  18024. // indices
  18025. for ( let j = 0; j < phiSegments; j ++ ) {
  18026. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  18027. for ( let i = 0; i < thetaSegments; i ++ ) {
  18028. const segment = i + thetaSegmentLevel;
  18029. const a = segment;
  18030. const b = segment + thetaSegments + 1;
  18031. const c = segment + thetaSegments + 2;
  18032. const d = segment + 1;
  18033. // faces
  18034. indices.push( a, b, d );
  18035. indices.push( b, c, d );
  18036. }
  18037. }
  18038. // build geometry
  18039. this.setIndex( indices );
  18040. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18041. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18042. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18043. }
  18044. }
  18045. class ShapeGeometry extends BufferGeometry {
  18046. constructor( shapes, curveSegments = 12 ) {
  18047. super();
  18048. this.type = 'ShapeGeometry';
  18049. this.parameters = {
  18050. shapes: shapes,
  18051. curveSegments: curveSegments
  18052. };
  18053. // buffers
  18054. const indices = [];
  18055. const vertices = [];
  18056. const normals = [];
  18057. const uvs = [];
  18058. // helper variables
  18059. let groupStart = 0;
  18060. let groupCount = 0;
  18061. // allow single and array values for "shapes" parameter
  18062. if ( Array.isArray( shapes ) === false ) {
  18063. addShape( shapes );
  18064. } else {
  18065. for ( let i = 0; i < shapes.length; i ++ ) {
  18066. addShape( shapes[ i ] );
  18067. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18068. groupStart += groupCount;
  18069. groupCount = 0;
  18070. }
  18071. }
  18072. // build geometry
  18073. this.setIndex( indices );
  18074. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18075. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18076. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18077. // helper functions
  18078. function addShape( shape ) {
  18079. const indexOffset = vertices.length / 3;
  18080. const points = shape.extractPoints( curveSegments );
  18081. let shapeVertices = points.shape;
  18082. const shapeHoles = points.holes;
  18083. // check direction of vertices
  18084. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18085. shapeVertices = shapeVertices.reverse();
  18086. }
  18087. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18088. const shapeHole = shapeHoles[ i ];
  18089. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18090. shapeHoles[ i ] = shapeHole.reverse();
  18091. }
  18092. }
  18093. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18094. // join vertices of inner and outer paths to a single array
  18095. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18096. const shapeHole = shapeHoles[ i ];
  18097. shapeVertices = shapeVertices.concat( shapeHole );
  18098. }
  18099. // vertices, normals, uvs
  18100. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18101. const vertex = shapeVertices[ i ];
  18102. vertices.push( vertex.x, vertex.y, 0 );
  18103. normals.push( 0, 0, 1 );
  18104. uvs.push( vertex.x, vertex.y ); // world uvs
  18105. }
  18106. // incides
  18107. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  18108. const face = faces[ i ];
  18109. const a = face[ 0 ] + indexOffset;
  18110. const b = face[ 1 ] + indexOffset;
  18111. const c = face[ 2 ] + indexOffset;
  18112. indices.push( a, b, c );
  18113. groupCount += 3;
  18114. }
  18115. }
  18116. }
  18117. toJSON() {
  18118. const data = BufferGeometry.prototype.toJSON.call( this );
  18119. const shapes = this.parameters.shapes;
  18120. return toJSON$1( shapes, data );
  18121. }
  18122. }
  18123. function toJSON$1( shapes, data ) {
  18124. data.shapes = [];
  18125. if ( Array.isArray( shapes ) ) {
  18126. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18127. const shape = shapes[ i ];
  18128. data.shapes.push( shape.uuid );
  18129. }
  18130. } else {
  18131. data.shapes.push( shapes.uuid );
  18132. }
  18133. return data;
  18134. }
  18135. class SphereGeometry extends BufferGeometry {
  18136. constructor( radius = 1, widthSegments = 8, heightSegments = 6, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  18137. super();
  18138. this.type = 'SphereGeometry';
  18139. this.parameters = {
  18140. radius: radius,
  18141. widthSegments: widthSegments,
  18142. heightSegments: heightSegments,
  18143. phiStart: phiStart,
  18144. phiLength: phiLength,
  18145. thetaStart: thetaStart,
  18146. thetaLength: thetaLength
  18147. };
  18148. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  18149. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  18150. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18151. let index = 0;
  18152. const grid = [];
  18153. const vertex = new Vector3();
  18154. const normal = new Vector3();
  18155. // buffers
  18156. const indices = [];
  18157. const vertices = [];
  18158. const normals = [];
  18159. const uvs = [];
  18160. // generate vertices, normals and uvs
  18161. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  18162. const verticesRow = [];
  18163. const v = iy / heightSegments;
  18164. // special case for the poles
  18165. let uOffset = 0;
  18166. if ( iy == 0 && thetaStart == 0 ) {
  18167. uOffset = 0.5 / widthSegments;
  18168. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18169. uOffset = - 0.5 / widthSegments;
  18170. }
  18171. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  18172. const u = ix / widthSegments;
  18173. // vertex
  18174. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18175. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18176. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18177. vertices.push( vertex.x, vertex.y, vertex.z );
  18178. // normal
  18179. normal.copy( vertex ).normalize();
  18180. normals.push( normal.x, normal.y, normal.z );
  18181. // uv
  18182. uvs.push( u + uOffset, 1 - v );
  18183. verticesRow.push( index ++ );
  18184. }
  18185. grid.push( verticesRow );
  18186. }
  18187. // indices
  18188. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  18189. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  18190. const a = grid[ iy ][ ix + 1 ];
  18191. const b = grid[ iy ][ ix ];
  18192. const c = grid[ iy + 1 ][ ix ];
  18193. const d = grid[ iy + 1 ][ ix + 1 ];
  18194. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18195. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18196. }
  18197. }
  18198. // build geometry
  18199. this.setIndex( indices );
  18200. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18201. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18202. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18203. }
  18204. }
  18205. class TetrahedronGeometry extends PolyhedronGeometry {
  18206. constructor( radius = 1, detail = 0 ) {
  18207. const vertices = [
  18208. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  18209. ];
  18210. const indices = [
  18211. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  18212. ];
  18213. super( vertices, indices, radius, detail );
  18214. this.type = 'TetrahedronGeometry';
  18215. this.parameters = {
  18216. radius: radius,
  18217. detail: detail
  18218. };
  18219. }
  18220. }
  18221. /**
  18222. * Text = 3D Text
  18223. *
  18224. * parameters = {
  18225. * font: <THREE.Font>, // font
  18226. *
  18227. * size: <float>, // size of the text
  18228. * height: <float>, // thickness to extrude text
  18229. * curveSegments: <int>, // number of points on the curves
  18230. *
  18231. * bevelEnabled: <bool>, // turn on bevel
  18232. * bevelThickness: <float>, // how deep into text bevel goes
  18233. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18234. * bevelOffset: <float> // how far from text outline does bevel start
  18235. * }
  18236. */
  18237. class TextGeometry extends ExtrudeGeometry {
  18238. constructor( text, parameters = {} ) {
  18239. const font = parameters.font;
  18240. if ( ! ( font && font.isFont ) ) {
  18241. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18242. return new BufferGeometry();
  18243. }
  18244. const shapes = font.generateShapes( text, parameters.size );
  18245. // translate parameters to ExtrudeGeometry API
  18246. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18247. // defaults
  18248. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18249. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18250. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18251. super( shapes, parameters );
  18252. this.type = 'TextGeometry';
  18253. }
  18254. }
  18255. class TorusGeometry extends BufferGeometry {
  18256. constructor( radius = 1, tube = 0.4, radialSegments = 8, tubularSegments = 6, arc = Math.PI * 2 ) {
  18257. super();
  18258. this.type = 'TorusGeometry';
  18259. this.parameters = {
  18260. radius: radius,
  18261. tube: tube,
  18262. radialSegments: radialSegments,
  18263. tubularSegments: tubularSegments,
  18264. arc: arc
  18265. };
  18266. radialSegments = Math.floor( radialSegments );
  18267. tubularSegments = Math.floor( tubularSegments );
  18268. // buffers
  18269. const indices = [];
  18270. const vertices = [];
  18271. const normals = [];
  18272. const uvs = [];
  18273. // helper variables
  18274. const center = new Vector3();
  18275. const vertex = new Vector3();
  18276. const normal = new Vector3();
  18277. // generate vertices, normals and uvs
  18278. for ( let j = 0; j <= radialSegments; j ++ ) {
  18279. for ( let i = 0; i <= tubularSegments; i ++ ) {
  18280. const u = i / tubularSegments * arc;
  18281. const v = j / radialSegments * Math.PI * 2;
  18282. // vertex
  18283. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  18284. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  18285. vertex.z = tube * Math.sin( v );
  18286. vertices.push( vertex.x, vertex.y, vertex.z );
  18287. // normal
  18288. center.x = radius * Math.cos( u );
  18289. center.y = radius * Math.sin( u );
  18290. normal.subVectors( vertex, center ).normalize();
  18291. normals.push( normal.x, normal.y, normal.z );
  18292. // uv
  18293. uvs.push( i / tubularSegments );
  18294. uvs.push( j / radialSegments );
  18295. }
  18296. }
  18297. // generate indices
  18298. for ( let j = 1; j <= radialSegments; j ++ ) {
  18299. for ( let i = 1; i <= tubularSegments; i ++ ) {
  18300. // indices
  18301. const a = ( tubularSegments + 1 ) * j + i - 1;
  18302. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  18303. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  18304. const d = ( tubularSegments + 1 ) * j + i;
  18305. // faces
  18306. indices.push( a, b, d );
  18307. indices.push( b, c, d );
  18308. }
  18309. }
  18310. // build geometry
  18311. this.setIndex( indices );
  18312. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18313. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18314. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18315. }
  18316. }
  18317. class TorusKnotGeometry extends BufferGeometry {
  18318. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  18319. super();
  18320. this.type = 'TorusKnotGeometry';
  18321. this.parameters = {
  18322. radius: radius,
  18323. tube: tube,
  18324. tubularSegments: tubularSegments,
  18325. radialSegments: radialSegments,
  18326. p: p,
  18327. q: q
  18328. };
  18329. tubularSegments = Math.floor( tubularSegments );
  18330. radialSegments = Math.floor( radialSegments );
  18331. // buffers
  18332. const indices = [];
  18333. const vertices = [];
  18334. const normals = [];
  18335. const uvs = [];
  18336. // helper variables
  18337. const vertex = new Vector3();
  18338. const normal = new Vector3();
  18339. const P1 = new Vector3();
  18340. const P2 = new Vector3();
  18341. const B = new Vector3();
  18342. const T = new Vector3();
  18343. const N = new Vector3();
  18344. // generate vertices, normals and uvs
  18345. for ( let i = 0; i <= tubularSegments; ++ i ) {
  18346. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  18347. const u = i / tubularSegments * p * Math.PI * 2;
  18348. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  18349. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  18350. calculatePositionOnCurve( u, p, q, radius, P1 );
  18351. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  18352. // calculate orthonormal basis
  18353. T.subVectors( P2, P1 );
  18354. N.addVectors( P2, P1 );
  18355. B.crossVectors( T, N );
  18356. N.crossVectors( B, T );
  18357. // normalize B, N. T can be ignored, we don't use it
  18358. B.normalize();
  18359. N.normalize();
  18360. for ( let j = 0; j <= radialSegments; ++ j ) {
  18361. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  18362. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  18363. const v = j / radialSegments * Math.PI * 2;
  18364. const cx = - tube * Math.cos( v );
  18365. const cy = tube * Math.sin( v );
  18366. // now calculate the final vertex position.
  18367. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  18368. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  18369. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  18370. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  18371. vertices.push( vertex.x, vertex.y, vertex.z );
  18372. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  18373. normal.subVectors( vertex, P1 ).normalize();
  18374. normals.push( normal.x, normal.y, normal.z );
  18375. // uv
  18376. uvs.push( i / tubularSegments );
  18377. uvs.push( j / radialSegments );
  18378. }
  18379. }
  18380. // generate indices
  18381. for ( let j = 1; j <= tubularSegments; j ++ ) {
  18382. for ( let i = 1; i <= radialSegments; i ++ ) {
  18383. // indices
  18384. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  18385. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  18386. const c = ( radialSegments + 1 ) * j + i;
  18387. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  18388. // faces
  18389. indices.push( a, b, d );
  18390. indices.push( b, c, d );
  18391. }
  18392. }
  18393. // build geometry
  18394. this.setIndex( indices );
  18395. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18396. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18397. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18398. // this function calculates the current position on the torus curve
  18399. function calculatePositionOnCurve( u, p, q, radius, position ) {
  18400. const cu = Math.cos( u );
  18401. const su = Math.sin( u );
  18402. const quOverP = q / p * u;
  18403. const cs = Math.cos( quOverP );
  18404. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  18405. position.y = radius * ( 2 + cs ) * su * 0.5;
  18406. position.z = radius * Math.sin( quOverP ) * 0.5;
  18407. }
  18408. }
  18409. }
  18410. class TubeGeometry extends BufferGeometry {
  18411. constructor( path, tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  18412. super();
  18413. this.type = 'TubeGeometry';
  18414. this.parameters = {
  18415. path: path,
  18416. tubularSegments: tubularSegments,
  18417. radius: radius,
  18418. radialSegments: radialSegments,
  18419. closed: closed
  18420. };
  18421. const frames = path.computeFrenetFrames( tubularSegments, closed );
  18422. // expose internals
  18423. this.tangents = frames.tangents;
  18424. this.normals = frames.normals;
  18425. this.binormals = frames.binormals;
  18426. // helper variables
  18427. const vertex = new Vector3();
  18428. const normal = new Vector3();
  18429. const uv = new Vector2();
  18430. let P = new Vector3();
  18431. // buffer
  18432. const vertices = [];
  18433. const normals = [];
  18434. const uvs = [];
  18435. const indices = [];
  18436. // create buffer data
  18437. generateBufferData();
  18438. // build geometry
  18439. this.setIndex( indices );
  18440. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18441. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18442. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18443. // functions
  18444. function generateBufferData() {
  18445. for ( let i = 0; i < tubularSegments; i ++ ) {
  18446. generateSegment( i );
  18447. }
  18448. // if the geometry is not closed, generate the last row of vertices and normals
  18449. // at the regular position on the given path
  18450. //
  18451. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  18452. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  18453. // uvs are generated in a separate function.
  18454. // this makes it easy compute correct values for closed geometries
  18455. generateUVs();
  18456. // finally create faces
  18457. generateIndices();
  18458. }
  18459. function generateSegment( i ) {
  18460. // we use getPointAt to sample evenly distributed points from the given path
  18461. P = path.getPointAt( i / tubularSegments, P );
  18462. // retrieve corresponding normal and binormal
  18463. const N = frames.normals[ i ];
  18464. const B = frames.binormals[ i ];
  18465. // generate normals and vertices for the current segment
  18466. for ( let j = 0; j <= radialSegments; j ++ ) {
  18467. const v = j / radialSegments * Math.PI * 2;
  18468. const sin = Math.sin( v );
  18469. const cos = - Math.cos( v );
  18470. // normal
  18471. normal.x = ( cos * N.x + sin * B.x );
  18472. normal.y = ( cos * N.y + sin * B.y );
  18473. normal.z = ( cos * N.z + sin * B.z );
  18474. normal.normalize();
  18475. normals.push( normal.x, normal.y, normal.z );
  18476. // vertex
  18477. vertex.x = P.x + radius * normal.x;
  18478. vertex.y = P.y + radius * normal.y;
  18479. vertex.z = P.z + radius * normal.z;
  18480. vertices.push( vertex.x, vertex.y, vertex.z );
  18481. }
  18482. }
  18483. function generateIndices() {
  18484. for ( let j = 1; j <= tubularSegments; j ++ ) {
  18485. for ( let i = 1; i <= radialSegments; i ++ ) {
  18486. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  18487. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  18488. const c = ( radialSegments + 1 ) * j + i;
  18489. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  18490. // faces
  18491. indices.push( a, b, d );
  18492. indices.push( b, c, d );
  18493. }
  18494. }
  18495. }
  18496. function generateUVs() {
  18497. for ( let i = 0; i <= tubularSegments; i ++ ) {
  18498. for ( let j = 0; j <= radialSegments; j ++ ) {
  18499. uv.x = i / tubularSegments;
  18500. uv.y = j / radialSegments;
  18501. uvs.push( uv.x, uv.y );
  18502. }
  18503. }
  18504. }
  18505. }
  18506. toJSON() {
  18507. const data = BufferGeometry.prototype.toJSON.call( this );
  18508. data.path = this.parameters.path.toJSON();
  18509. return data;
  18510. }
  18511. }
  18512. class WireframeGeometry extends BufferGeometry {
  18513. constructor( geometry ) {
  18514. super();
  18515. this.type = 'WireframeGeometry';
  18516. if ( geometry.isGeometry === true ) {
  18517. console.error( 'THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  18518. return;
  18519. }
  18520. // buffer
  18521. const vertices = [];
  18522. // helper variables
  18523. const edge = [ 0, 0 ], edges = {};
  18524. const vertex = new Vector3();
  18525. if ( geometry.index !== null ) {
  18526. // indexed BufferGeometry
  18527. const position = geometry.attributes.position;
  18528. const indices = geometry.index;
  18529. let groups = geometry.groups;
  18530. if ( groups.length === 0 ) {
  18531. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  18532. }
  18533. // create a data structure that contains all eges without duplicates
  18534. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  18535. const group = groups[ o ];
  18536. const start = group.start;
  18537. const count = group.count;
  18538. for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
  18539. for ( let j = 0; j < 3; j ++ ) {
  18540. const edge1 = indices.getX( i + j );
  18541. const edge2 = indices.getX( i + ( j + 1 ) % 3 );
  18542. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  18543. edge[ 1 ] = Math.max( edge1, edge2 );
  18544. const key = edge[ 0 ] + ',' + edge[ 1 ];
  18545. if ( edges[ key ] === undefined ) {
  18546. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  18547. }
  18548. }
  18549. }
  18550. }
  18551. // generate vertices
  18552. for ( const key in edges ) {
  18553. const e = edges[ key ];
  18554. vertex.fromBufferAttribute( position, e.index1 );
  18555. vertices.push( vertex.x, vertex.y, vertex.z );
  18556. vertex.fromBufferAttribute( position, e.index2 );
  18557. vertices.push( vertex.x, vertex.y, vertex.z );
  18558. }
  18559. } else {
  18560. // non-indexed BufferGeometry
  18561. const position = geometry.attributes.position;
  18562. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  18563. for ( let j = 0; j < 3; j ++ ) {
  18564. // three edges per triangle, an edge is represented as (index1, index2)
  18565. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  18566. const index1 = 3 * i + j;
  18567. vertex.fromBufferAttribute( position, index1 );
  18568. vertices.push( vertex.x, vertex.y, vertex.z );
  18569. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  18570. vertex.fromBufferAttribute( position, index2 );
  18571. vertices.push( vertex.x, vertex.y, vertex.z );
  18572. }
  18573. }
  18574. }
  18575. // build geometry
  18576. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18577. }
  18578. }
  18579. var Geometries = /*#__PURE__*/Object.freeze({
  18580. __proto__: null,
  18581. BoxGeometry: BoxGeometry,
  18582. BoxBufferGeometry: BoxGeometry,
  18583. CircleGeometry: CircleGeometry,
  18584. CircleBufferGeometry: CircleGeometry,
  18585. ConeGeometry: ConeGeometry,
  18586. ConeBufferGeometry: ConeGeometry,
  18587. CylinderGeometry: CylinderGeometry,
  18588. CylinderBufferGeometry: CylinderGeometry,
  18589. DodecahedronGeometry: DodecahedronGeometry,
  18590. DodecahedronBufferGeometry: DodecahedronGeometry,
  18591. EdgesGeometry: EdgesGeometry,
  18592. ExtrudeGeometry: ExtrudeGeometry,
  18593. ExtrudeBufferGeometry: ExtrudeGeometry,
  18594. IcosahedronGeometry: IcosahedronGeometry,
  18595. IcosahedronBufferGeometry: IcosahedronGeometry,
  18596. LatheGeometry: LatheGeometry,
  18597. LatheBufferGeometry: LatheGeometry,
  18598. OctahedronGeometry: OctahedronGeometry,
  18599. OctahedronBufferGeometry: OctahedronGeometry,
  18600. ParametricGeometry: ParametricGeometry,
  18601. ParametricBufferGeometry: ParametricGeometry,
  18602. PlaneGeometry: PlaneGeometry,
  18603. PlaneBufferGeometry: PlaneGeometry,
  18604. PolyhedronGeometry: PolyhedronGeometry,
  18605. PolyhedronBufferGeometry: PolyhedronGeometry,
  18606. RingGeometry: RingGeometry,
  18607. RingBufferGeometry: RingGeometry,
  18608. ShapeGeometry: ShapeGeometry,
  18609. ShapeBufferGeometry: ShapeGeometry,
  18610. SphereGeometry: SphereGeometry,
  18611. SphereBufferGeometry: SphereGeometry,
  18612. TetrahedronGeometry: TetrahedronGeometry,
  18613. TetrahedronBufferGeometry: TetrahedronGeometry,
  18614. TextGeometry: TextGeometry,
  18615. TextBufferGeometry: TextGeometry,
  18616. TorusGeometry: TorusGeometry,
  18617. TorusBufferGeometry: TorusGeometry,
  18618. TorusKnotGeometry: TorusKnotGeometry,
  18619. TorusKnotBufferGeometry: TorusKnotGeometry,
  18620. TubeGeometry: TubeGeometry,
  18621. TubeBufferGeometry: TubeGeometry,
  18622. WireframeGeometry: WireframeGeometry
  18623. });
  18624. /**
  18625. * parameters = {
  18626. * color: <THREE.Color>
  18627. * }
  18628. */
  18629. function ShadowMaterial( parameters ) {
  18630. Material.call( this );
  18631. this.type = 'ShadowMaterial';
  18632. this.color = new Color( 0x000000 );
  18633. this.transparent = true;
  18634. this.setValues( parameters );
  18635. }
  18636. ShadowMaterial.prototype = Object.create( Material.prototype );
  18637. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18638. ShadowMaterial.prototype.isShadowMaterial = true;
  18639. ShadowMaterial.prototype.copy = function ( source ) {
  18640. Material.prototype.copy.call( this, source );
  18641. this.color.copy( source.color );
  18642. return this;
  18643. };
  18644. function RawShaderMaterial( parameters ) {
  18645. ShaderMaterial.call( this, parameters );
  18646. this.type = 'RawShaderMaterial';
  18647. }
  18648. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18649. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18650. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18651. /**
  18652. * parameters = {
  18653. * color: <hex>,
  18654. * roughness: <float>,
  18655. * metalness: <float>,
  18656. * opacity: <float>,
  18657. *
  18658. * map: new THREE.Texture( <Image> ),
  18659. *
  18660. * lightMap: new THREE.Texture( <Image> ),
  18661. * lightMapIntensity: <float>
  18662. *
  18663. * aoMap: new THREE.Texture( <Image> ),
  18664. * aoMapIntensity: <float>
  18665. *
  18666. * emissive: <hex>,
  18667. * emissiveIntensity: <float>
  18668. * emissiveMap: new THREE.Texture( <Image> ),
  18669. *
  18670. * bumpMap: new THREE.Texture( <Image> ),
  18671. * bumpScale: <float>,
  18672. *
  18673. * normalMap: new THREE.Texture( <Image> ),
  18674. * normalMapType: THREE.TangentSpaceNormalMap,
  18675. * normalScale: <Vector2>,
  18676. *
  18677. * displacementMap: new THREE.Texture( <Image> ),
  18678. * displacementScale: <float>,
  18679. * displacementBias: <float>,
  18680. *
  18681. * roughnessMap: new THREE.Texture( <Image> ),
  18682. *
  18683. * metalnessMap: new THREE.Texture( <Image> ),
  18684. *
  18685. * alphaMap: new THREE.Texture( <Image> ),
  18686. *
  18687. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18688. * envMapIntensity: <float>
  18689. *
  18690. * refractionRatio: <float>,
  18691. *
  18692. * wireframe: <boolean>,
  18693. * wireframeLinewidth: <float>,
  18694. *
  18695. * skinning: <bool>,
  18696. * morphTargets: <bool>,
  18697. * morphNormals: <bool>
  18698. * }
  18699. */
  18700. function MeshStandardMaterial( parameters ) {
  18701. Material.call( this );
  18702. this.defines = { 'STANDARD': '' };
  18703. this.type = 'MeshStandardMaterial';
  18704. this.color = new Color( 0xffffff ); // diffuse
  18705. this.roughness = 1.0;
  18706. this.metalness = 0.0;
  18707. this.map = null;
  18708. this.lightMap = null;
  18709. this.lightMapIntensity = 1.0;
  18710. this.aoMap = null;
  18711. this.aoMapIntensity = 1.0;
  18712. this.emissive = new Color( 0x000000 );
  18713. this.emissiveIntensity = 1.0;
  18714. this.emissiveMap = null;
  18715. this.bumpMap = null;
  18716. this.bumpScale = 1;
  18717. this.normalMap = null;
  18718. this.normalMapType = TangentSpaceNormalMap;
  18719. this.normalScale = new Vector2( 1, 1 );
  18720. this.displacementMap = null;
  18721. this.displacementScale = 1;
  18722. this.displacementBias = 0;
  18723. this.roughnessMap = null;
  18724. this.metalnessMap = null;
  18725. this.alphaMap = null;
  18726. this.envMap = null;
  18727. this.envMapIntensity = 1.0;
  18728. this.refractionRatio = 0.98;
  18729. this.wireframe = false;
  18730. this.wireframeLinewidth = 1;
  18731. this.wireframeLinecap = 'round';
  18732. this.wireframeLinejoin = 'round';
  18733. this.skinning = false;
  18734. this.morphTargets = false;
  18735. this.morphNormals = false;
  18736. this.vertexTangents = false;
  18737. this.setValues( parameters );
  18738. }
  18739. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18740. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18741. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18742. MeshStandardMaterial.prototype.copy = function ( source ) {
  18743. Material.prototype.copy.call( this, source );
  18744. this.defines = { 'STANDARD': '' };
  18745. this.color.copy( source.color );
  18746. this.roughness = source.roughness;
  18747. this.metalness = source.metalness;
  18748. this.map = source.map;
  18749. this.lightMap = source.lightMap;
  18750. this.lightMapIntensity = source.lightMapIntensity;
  18751. this.aoMap = source.aoMap;
  18752. this.aoMapIntensity = source.aoMapIntensity;
  18753. this.emissive.copy( source.emissive );
  18754. this.emissiveMap = source.emissiveMap;
  18755. this.emissiveIntensity = source.emissiveIntensity;
  18756. this.bumpMap = source.bumpMap;
  18757. this.bumpScale = source.bumpScale;
  18758. this.normalMap = source.normalMap;
  18759. this.normalMapType = source.normalMapType;
  18760. this.normalScale.copy( source.normalScale );
  18761. this.displacementMap = source.displacementMap;
  18762. this.displacementScale = source.displacementScale;
  18763. this.displacementBias = source.displacementBias;
  18764. this.roughnessMap = source.roughnessMap;
  18765. this.metalnessMap = source.metalnessMap;
  18766. this.alphaMap = source.alphaMap;
  18767. this.envMap = source.envMap;
  18768. this.envMapIntensity = source.envMapIntensity;
  18769. this.refractionRatio = source.refractionRatio;
  18770. this.wireframe = source.wireframe;
  18771. this.wireframeLinewidth = source.wireframeLinewidth;
  18772. this.wireframeLinecap = source.wireframeLinecap;
  18773. this.wireframeLinejoin = source.wireframeLinejoin;
  18774. this.skinning = source.skinning;
  18775. this.morphTargets = source.morphTargets;
  18776. this.morphNormals = source.morphNormals;
  18777. this.vertexTangents = source.vertexTangents;
  18778. return this;
  18779. };
  18780. /**
  18781. * parameters = {
  18782. * clearcoat: <float>,
  18783. * clearcoatMap: new THREE.Texture( <Image> ),
  18784. * clearcoatRoughness: <float>,
  18785. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  18786. * clearcoatNormalScale: <Vector2>,
  18787. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  18788. *
  18789. * reflectivity: <float>,
  18790. * ior: <float>,
  18791. *
  18792. * sheen: <Color>,
  18793. *
  18794. * transmission: <float>,
  18795. * transmissionMap: new THREE.Texture( <Image> )
  18796. * }
  18797. */
  18798. function MeshPhysicalMaterial( parameters ) {
  18799. MeshStandardMaterial.call( this );
  18800. this.defines = {
  18801. 'STANDARD': '',
  18802. 'PHYSICAL': ''
  18803. };
  18804. this.type = 'MeshPhysicalMaterial';
  18805. this.clearcoat = 0.0;
  18806. this.clearcoatMap = null;
  18807. this.clearcoatRoughness = 0.0;
  18808. this.clearcoatRoughnessMap = null;
  18809. this.clearcoatNormalScale = new Vector2( 1, 1 );
  18810. this.clearcoatNormalMap = null;
  18811. this.reflectivity = 0.5; // maps to F0 = 0.04
  18812. Object.defineProperty( this, 'ior', {
  18813. get: function () {
  18814. return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity );
  18815. },
  18816. set: function ( ior ) {
  18817. this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 );
  18818. }
  18819. } );
  18820. this.sheen = null; // null will disable sheen bsdf
  18821. this.transmission = 0.0;
  18822. this.transmissionMap = null;
  18823. this.setValues( parameters );
  18824. }
  18825. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18826. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18827. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18828. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18829. MeshStandardMaterial.prototype.copy.call( this, source );
  18830. this.defines = {
  18831. 'STANDARD': '',
  18832. 'PHYSICAL': ''
  18833. };
  18834. this.clearcoat = source.clearcoat;
  18835. this.clearcoatMap = source.clearcoatMap;
  18836. this.clearcoatRoughness = source.clearcoatRoughness;
  18837. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  18838. this.clearcoatNormalMap = source.clearcoatNormalMap;
  18839. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  18840. this.reflectivity = source.reflectivity;
  18841. if ( source.sheen ) {
  18842. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  18843. } else {
  18844. this.sheen = null;
  18845. }
  18846. this.transmission = source.transmission;
  18847. this.transmissionMap = source.transmissionMap;
  18848. return this;
  18849. };
  18850. /**
  18851. * parameters = {
  18852. * color: <hex>,
  18853. * specular: <hex>,
  18854. * shininess: <float>,
  18855. * opacity: <float>,
  18856. *
  18857. * map: new THREE.Texture( <Image> ),
  18858. *
  18859. * lightMap: new THREE.Texture( <Image> ),
  18860. * lightMapIntensity: <float>
  18861. *
  18862. * aoMap: new THREE.Texture( <Image> ),
  18863. * aoMapIntensity: <float>
  18864. *
  18865. * emissive: <hex>,
  18866. * emissiveIntensity: <float>
  18867. * emissiveMap: new THREE.Texture( <Image> ),
  18868. *
  18869. * bumpMap: new THREE.Texture( <Image> ),
  18870. * bumpScale: <float>,
  18871. *
  18872. * normalMap: new THREE.Texture( <Image> ),
  18873. * normalMapType: THREE.TangentSpaceNormalMap,
  18874. * normalScale: <Vector2>,
  18875. *
  18876. * displacementMap: new THREE.Texture( <Image> ),
  18877. * displacementScale: <float>,
  18878. * displacementBias: <float>,
  18879. *
  18880. * specularMap: new THREE.Texture( <Image> ),
  18881. *
  18882. * alphaMap: new THREE.Texture( <Image> ),
  18883. *
  18884. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18885. * combine: THREE.MultiplyOperation,
  18886. * reflectivity: <float>,
  18887. * refractionRatio: <float>,
  18888. *
  18889. * wireframe: <boolean>,
  18890. * wireframeLinewidth: <float>,
  18891. *
  18892. * skinning: <bool>,
  18893. * morphTargets: <bool>,
  18894. * morphNormals: <bool>
  18895. * }
  18896. */
  18897. function MeshPhongMaterial( parameters ) {
  18898. Material.call( this );
  18899. this.type = 'MeshPhongMaterial';
  18900. this.color = new Color( 0xffffff ); // diffuse
  18901. this.specular = new Color( 0x111111 );
  18902. this.shininess = 30;
  18903. this.map = null;
  18904. this.lightMap = null;
  18905. this.lightMapIntensity = 1.0;
  18906. this.aoMap = null;
  18907. this.aoMapIntensity = 1.0;
  18908. this.emissive = new Color( 0x000000 );
  18909. this.emissiveIntensity = 1.0;
  18910. this.emissiveMap = null;
  18911. this.bumpMap = null;
  18912. this.bumpScale = 1;
  18913. this.normalMap = null;
  18914. this.normalMapType = TangentSpaceNormalMap;
  18915. this.normalScale = new Vector2( 1, 1 );
  18916. this.displacementMap = null;
  18917. this.displacementScale = 1;
  18918. this.displacementBias = 0;
  18919. this.specularMap = null;
  18920. this.alphaMap = null;
  18921. this.envMap = null;
  18922. this.combine = MultiplyOperation;
  18923. this.reflectivity = 1;
  18924. this.refractionRatio = 0.98;
  18925. this.wireframe = false;
  18926. this.wireframeLinewidth = 1;
  18927. this.wireframeLinecap = 'round';
  18928. this.wireframeLinejoin = 'round';
  18929. this.skinning = false;
  18930. this.morphTargets = false;
  18931. this.morphNormals = false;
  18932. this.setValues( parameters );
  18933. }
  18934. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18935. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18936. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18937. MeshPhongMaterial.prototype.copy = function ( source ) {
  18938. Material.prototype.copy.call( this, source );
  18939. this.color.copy( source.color );
  18940. this.specular.copy( source.specular );
  18941. this.shininess = source.shininess;
  18942. this.map = source.map;
  18943. this.lightMap = source.lightMap;
  18944. this.lightMapIntensity = source.lightMapIntensity;
  18945. this.aoMap = source.aoMap;
  18946. this.aoMapIntensity = source.aoMapIntensity;
  18947. this.emissive.copy( source.emissive );
  18948. this.emissiveMap = source.emissiveMap;
  18949. this.emissiveIntensity = source.emissiveIntensity;
  18950. this.bumpMap = source.bumpMap;
  18951. this.bumpScale = source.bumpScale;
  18952. this.normalMap = source.normalMap;
  18953. this.normalMapType = source.normalMapType;
  18954. this.normalScale.copy( source.normalScale );
  18955. this.displacementMap = source.displacementMap;
  18956. this.displacementScale = source.displacementScale;
  18957. this.displacementBias = source.displacementBias;
  18958. this.specularMap = source.specularMap;
  18959. this.alphaMap = source.alphaMap;
  18960. this.envMap = source.envMap;
  18961. this.combine = source.combine;
  18962. this.reflectivity = source.reflectivity;
  18963. this.refractionRatio = source.refractionRatio;
  18964. this.wireframe = source.wireframe;
  18965. this.wireframeLinewidth = source.wireframeLinewidth;
  18966. this.wireframeLinecap = source.wireframeLinecap;
  18967. this.wireframeLinejoin = source.wireframeLinejoin;
  18968. this.skinning = source.skinning;
  18969. this.morphTargets = source.morphTargets;
  18970. this.morphNormals = source.morphNormals;
  18971. return this;
  18972. };
  18973. /**
  18974. * parameters = {
  18975. * color: <hex>,
  18976. *
  18977. * map: new THREE.Texture( <Image> ),
  18978. * gradientMap: new THREE.Texture( <Image> ),
  18979. *
  18980. * lightMap: new THREE.Texture( <Image> ),
  18981. * lightMapIntensity: <float>
  18982. *
  18983. * aoMap: new THREE.Texture( <Image> ),
  18984. * aoMapIntensity: <float>
  18985. *
  18986. * emissive: <hex>,
  18987. * emissiveIntensity: <float>
  18988. * emissiveMap: new THREE.Texture( <Image> ),
  18989. *
  18990. * bumpMap: new THREE.Texture( <Image> ),
  18991. * bumpScale: <float>,
  18992. *
  18993. * normalMap: new THREE.Texture( <Image> ),
  18994. * normalMapType: THREE.TangentSpaceNormalMap,
  18995. * normalScale: <Vector2>,
  18996. *
  18997. * displacementMap: new THREE.Texture( <Image> ),
  18998. * displacementScale: <float>,
  18999. * displacementBias: <float>,
  19000. *
  19001. * alphaMap: new THREE.Texture( <Image> ),
  19002. *
  19003. * wireframe: <boolean>,
  19004. * wireframeLinewidth: <float>,
  19005. *
  19006. * skinning: <bool>,
  19007. * morphTargets: <bool>,
  19008. * morphNormals: <bool>
  19009. * }
  19010. */
  19011. function MeshToonMaterial( parameters ) {
  19012. Material.call( this );
  19013. this.defines = { 'TOON': '' };
  19014. this.type = 'MeshToonMaterial';
  19015. this.color = new Color( 0xffffff );
  19016. this.map = null;
  19017. this.gradientMap = null;
  19018. this.lightMap = null;
  19019. this.lightMapIntensity = 1.0;
  19020. this.aoMap = null;
  19021. this.aoMapIntensity = 1.0;
  19022. this.emissive = new Color( 0x000000 );
  19023. this.emissiveIntensity = 1.0;
  19024. this.emissiveMap = null;
  19025. this.bumpMap = null;
  19026. this.bumpScale = 1;
  19027. this.normalMap = null;
  19028. this.normalMapType = TangentSpaceNormalMap;
  19029. this.normalScale = new Vector2( 1, 1 );
  19030. this.displacementMap = null;
  19031. this.displacementScale = 1;
  19032. this.displacementBias = 0;
  19033. this.alphaMap = null;
  19034. this.wireframe = false;
  19035. this.wireframeLinewidth = 1;
  19036. this.wireframeLinecap = 'round';
  19037. this.wireframeLinejoin = 'round';
  19038. this.skinning = false;
  19039. this.morphTargets = false;
  19040. this.morphNormals = false;
  19041. this.setValues( parameters );
  19042. }
  19043. MeshToonMaterial.prototype = Object.create( Material.prototype );
  19044. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19045. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19046. MeshToonMaterial.prototype.copy = function ( source ) {
  19047. Material.prototype.copy.call( this, source );
  19048. this.color.copy( source.color );
  19049. this.map = source.map;
  19050. this.gradientMap = source.gradientMap;
  19051. this.lightMap = source.lightMap;
  19052. this.lightMapIntensity = source.lightMapIntensity;
  19053. this.aoMap = source.aoMap;
  19054. this.aoMapIntensity = source.aoMapIntensity;
  19055. this.emissive.copy( source.emissive );
  19056. this.emissiveMap = source.emissiveMap;
  19057. this.emissiveIntensity = source.emissiveIntensity;
  19058. this.bumpMap = source.bumpMap;
  19059. this.bumpScale = source.bumpScale;
  19060. this.normalMap = source.normalMap;
  19061. this.normalMapType = source.normalMapType;
  19062. this.normalScale.copy( source.normalScale );
  19063. this.displacementMap = source.displacementMap;
  19064. this.displacementScale = source.displacementScale;
  19065. this.displacementBias = source.displacementBias;
  19066. this.alphaMap = source.alphaMap;
  19067. this.wireframe = source.wireframe;
  19068. this.wireframeLinewidth = source.wireframeLinewidth;
  19069. this.wireframeLinecap = source.wireframeLinecap;
  19070. this.wireframeLinejoin = source.wireframeLinejoin;
  19071. this.skinning = source.skinning;
  19072. this.morphTargets = source.morphTargets;
  19073. this.morphNormals = source.morphNormals;
  19074. return this;
  19075. };
  19076. /**
  19077. * parameters = {
  19078. * opacity: <float>,
  19079. *
  19080. * bumpMap: new THREE.Texture( <Image> ),
  19081. * bumpScale: <float>,
  19082. *
  19083. * normalMap: new THREE.Texture( <Image> ),
  19084. * normalMapType: THREE.TangentSpaceNormalMap,
  19085. * normalScale: <Vector2>,
  19086. *
  19087. * displacementMap: new THREE.Texture( <Image> ),
  19088. * displacementScale: <float>,
  19089. * displacementBias: <float>,
  19090. *
  19091. * wireframe: <boolean>,
  19092. * wireframeLinewidth: <float>
  19093. *
  19094. * skinning: <bool>,
  19095. * morphTargets: <bool>,
  19096. * morphNormals: <bool>
  19097. * }
  19098. */
  19099. function MeshNormalMaterial( parameters ) {
  19100. Material.call( this );
  19101. this.type = 'MeshNormalMaterial';
  19102. this.bumpMap = null;
  19103. this.bumpScale = 1;
  19104. this.normalMap = null;
  19105. this.normalMapType = TangentSpaceNormalMap;
  19106. this.normalScale = new Vector2( 1, 1 );
  19107. this.displacementMap = null;
  19108. this.displacementScale = 1;
  19109. this.displacementBias = 0;
  19110. this.wireframe = false;
  19111. this.wireframeLinewidth = 1;
  19112. this.fog = false;
  19113. this.skinning = false;
  19114. this.morphTargets = false;
  19115. this.morphNormals = false;
  19116. this.setValues( parameters );
  19117. }
  19118. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19119. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19120. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19121. MeshNormalMaterial.prototype.copy = function ( source ) {
  19122. Material.prototype.copy.call( this, source );
  19123. this.bumpMap = source.bumpMap;
  19124. this.bumpScale = source.bumpScale;
  19125. this.normalMap = source.normalMap;
  19126. this.normalMapType = source.normalMapType;
  19127. this.normalScale.copy( source.normalScale );
  19128. this.displacementMap = source.displacementMap;
  19129. this.displacementScale = source.displacementScale;
  19130. this.displacementBias = source.displacementBias;
  19131. this.wireframe = source.wireframe;
  19132. this.wireframeLinewidth = source.wireframeLinewidth;
  19133. this.skinning = source.skinning;
  19134. this.morphTargets = source.morphTargets;
  19135. this.morphNormals = source.morphNormals;
  19136. return this;
  19137. };
  19138. /**
  19139. * parameters = {
  19140. * color: <hex>,
  19141. * opacity: <float>,
  19142. *
  19143. * map: new THREE.Texture( <Image> ),
  19144. *
  19145. * lightMap: new THREE.Texture( <Image> ),
  19146. * lightMapIntensity: <float>
  19147. *
  19148. * aoMap: new THREE.Texture( <Image> ),
  19149. * aoMapIntensity: <float>
  19150. *
  19151. * emissive: <hex>,
  19152. * emissiveIntensity: <float>
  19153. * emissiveMap: new THREE.Texture( <Image> ),
  19154. *
  19155. * specularMap: new THREE.Texture( <Image> ),
  19156. *
  19157. * alphaMap: new THREE.Texture( <Image> ),
  19158. *
  19159. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19160. * combine: THREE.Multiply,
  19161. * reflectivity: <float>,
  19162. * refractionRatio: <float>,
  19163. *
  19164. * wireframe: <boolean>,
  19165. * wireframeLinewidth: <float>,
  19166. *
  19167. * skinning: <bool>,
  19168. * morphTargets: <bool>,
  19169. * morphNormals: <bool>
  19170. * }
  19171. */
  19172. function MeshLambertMaterial( parameters ) {
  19173. Material.call( this );
  19174. this.type = 'MeshLambertMaterial';
  19175. this.color = new Color( 0xffffff ); // diffuse
  19176. this.map = null;
  19177. this.lightMap = null;
  19178. this.lightMapIntensity = 1.0;
  19179. this.aoMap = null;
  19180. this.aoMapIntensity = 1.0;
  19181. this.emissive = new Color( 0x000000 );
  19182. this.emissiveIntensity = 1.0;
  19183. this.emissiveMap = null;
  19184. this.specularMap = null;
  19185. this.alphaMap = null;
  19186. this.envMap = null;
  19187. this.combine = MultiplyOperation;
  19188. this.reflectivity = 1;
  19189. this.refractionRatio = 0.98;
  19190. this.wireframe = false;
  19191. this.wireframeLinewidth = 1;
  19192. this.wireframeLinecap = 'round';
  19193. this.wireframeLinejoin = 'round';
  19194. this.skinning = false;
  19195. this.morphTargets = false;
  19196. this.morphNormals = false;
  19197. this.setValues( parameters );
  19198. }
  19199. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19200. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19201. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19202. MeshLambertMaterial.prototype.copy = function ( source ) {
  19203. Material.prototype.copy.call( this, source );
  19204. this.color.copy( source.color );
  19205. this.map = source.map;
  19206. this.lightMap = source.lightMap;
  19207. this.lightMapIntensity = source.lightMapIntensity;
  19208. this.aoMap = source.aoMap;
  19209. this.aoMapIntensity = source.aoMapIntensity;
  19210. this.emissive.copy( source.emissive );
  19211. this.emissiveMap = source.emissiveMap;
  19212. this.emissiveIntensity = source.emissiveIntensity;
  19213. this.specularMap = source.specularMap;
  19214. this.alphaMap = source.alphaMap;
  19215. this.envMap = source.envMap;
  19216. this.combine = source.combine;
  19217. this.reflectivity = source.reflectivity;
  19218. this.refractionRatio = source.refractionRatio;
  19219. this.wireframe = source.wireframe;
  19220. this.wireframeLinewidth = source.wireframeLinewidth;
  19221. this.wireframeLinecap = source.wireframeLinecap;
  19222. this.wireframeLinejoin = source.wireframeLinejoin;
  19223. this.skinning = source.skinning;
  19224. this.morphTargets = source.morphTargets;
  19225. this.morphNormals = source.morphNormals;
  19226. return this;
  19227. };
  19228. /**
  19229. * parameters = {
  19230. * color: <hex>,
  19231. * opacity: <float>,
  19232. *
  19233. * matcap: new THREE.Texture( <Image> ),
  19234. *
  19235. * map: new THREE.Texture( <Image> ),
  19236. *
  19237. * bumpMap: new THREE.Texture( <Image> ),
  19238. * bumpScale: <float>,
  19239. *
  19240. * normalMap: new THREE.Texture( <Image> ),
  19241. * normalMapType: THREE.TangentSpaceNormalMap,
  19242. * normalScale: <Vector2>,
  19243. *
  19244. * displacementMap: new THREE.Texture( <Image> ),
  19245. * displacementScale: <float>,
  19246. * displacementBias: <float>,
  19247. *
  19248. * alphaMap: new THREE.Texture( <Image> ),
  19249. *
  19250. * skinning: <bool>,
  19251. * morphTargets: <bool>,
  19252. * morphNormals: <bool>
  19253. * }
  19254. */
  19255. function MeshMatcapMaterial( parameters ) {
  19256. Material.call( this );
  19257. this.defines = { 'MATCAP': '' };
  19258. this.type = 'MeshMatcapMaterial';
  19259. this.color = new Color( 0xffffff ); // diffuse
  19260. this.matcap = null;
  19261. this.map = null;
  19262. this.bumpMap = null;
  19263. this.bumpScale = 1;
  19264. this.normalMap = null;
  19265. this.normalMapType = TangentSpaceNormalMap;
  19266. this.normalScale = new Vector2( 1, 1 );
  19267. this.displacementMap = null;
  19268. this.displacementScale = 1;
  19269. this.displacementBias = 0;
  19270. this.alphaMap = null;
  19271. this.skinning = false;
  19272. this.morphTargets = false;
  19273. this.morphNormals = false;
  19274. this.setValues( parameters );
  19275. }
  19276. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19277. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19278. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19279. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19280. Material.prototype.copy.call( this, source );
  19281. this.defines = { 'MATCAP': '' };
  19282. this.color.copy( source.color );
  19283. this.matcap = source.matcap;
  19284. this.map = source.map;
  19285. this.bumpMap = source.bumpMap;
  19286. this.bumpScale = source.bumpScale;
  19287. this.normalMap = source.normalMap;
  19288. this.normalMapType = source.normalMapType;
  19289. this.normalScale.copy( source.normalScale );
  19290. this.displacementMap = source.displacementMap;
  19291. this.displacementScale = source.displacementScale;
  19292. this.displacementBias = source.displacementBias;
  19293. this.alphaMap = source.alphaMap;
  19294. this.skinning = source.skinning;
  19295. this.morphTargets = source.morphTargets;
  19296. this.morphNormals = source.morphNormals;
  19297. return this;
  19298. };
  19299. /**
  19300. * parameters = {
  19301. * color: <hex>,
  19302. * opacity: <float>,
  19303. *
  19304. * linewidth: <float>,
  19305. *
  19306. * scale: <float>,
  19307. * dashSize: <float>,
  19308. * gapSize: <float>
  19309. * }
  19310. */
  19311. function LineDashedMaterial( parameters ) {
  19312. LineBasicMaterial.call( this );
  19313. this.type = 'LineDashedMaterial';
  19314. this.scale = 1;
  19315. this.dashSize = 3;
  19316. this.gapSize = 1;
  19317. this.setValues( parameters );
  19318. }
  19319. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19320. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19321. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19322. LineDashedMaterial.prototype.copy = function ( source ) {
  19323. LineBasicMaterial.prototype.copy.call( this, source );
  19324. this.scale = source.scale;
  19325. this.dashSize = source.dashSize;
  19326. this.gapSize = source.gapSize;
  19327. return this;
  19328. };
  19329. var Materials = /*#__PURE__*/Object.freeze({
  19330. __proto__: null,
  19331. ShadowMaterial: ShadowMaterial,
  19332. SpriteMaterial: SpriteMaterial,
  19333. RawShaderMaterial: RawShaderMaterial,
  19334. ShaderMaterial: ShaderMaterial,
  19335. PointsMaterial: PointsMaterial,
  19336. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19337. MeshStandardMaterial: MeshStandardMaterial,
  19338. MeshPhongMaterial: MeshPhongMaterial,
  19339. MeshToonMaterial: MeshToonMaterial,
  19340. MeshNormalMaterial: MeshNormalMaterial,
  19341. MeshLambertMaterial: MeshLambertMaterial,
  19342. MeshDepthMaterial: MeshDepthMaterial,
  19343. MeshDistanceMaterial: MeshDistanceMaterial,
  19344. MeshBasicMaterial: MeshBasicMaterial,
  19345. MeshMatcapMaterial: MeshMatcapMaterial,
  19346. LineDashedMaterial: LineDashedMaterial,
  19347. LineBasicMaterial: LineBasicMaterial,
  19348. Material: Material
  19349. });
  19350. const AnimationUtils = {
  19351. // same as Array.prototype.slice, but also works on typed arrays
  19352. arraySlice: function ( array, from, to ) {
  19353. if ( AnimationUtils.isTypedArray( array ) ) {
  19354. // in ios9 array.subarray(from, undefined) will return empty array
  19355. // but array.subarray(from) or array.subarray(from, len) is correct
  19356. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19357. }
  19358. return array.slice( from, to );
  19359. },
  19360. // converts an array to a specific type
  19361. convertArray: function ( array, type, forceClone ) {
  19362. if ( ! array || // let 'undefined' and 'null' pass
  19363. ! forceClone && array.constructor === type ) return array;
  19364. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19365. return new type( array ); // create typed array
  19366. }
  19367. return Array.prototype.slice.call( array ); // create Array
  19368. },
  19369. isTypedArray: function ( object ) {
  19370. return ArrayBuffer.isView( object ) &&
  19371. ! ( object instanceof DataView );
  19372. },
  19373. // returns an array by which times and values can be sorted
  19374. getKeyframeOrder: function ( times ) {
  19375. function compareTime( i, j ) {
  19376. return times[ i ] - times[ j ];
  19377. }
  19378. const n = times.length;
  19379. const result = new Array( n );
  19380. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  19381. result.sort( compareTime );
  19382. return result;
  19383. },
  19384. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19385. sortedArray: function ( values, stride, order ) {
  19386. const nValues = values.length;
  19387. const result = new values.constructor( nValues );
  19388. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19389. const srcOffset = order[ i ] * stride;
  19390. for ( let j = 0; j !== stride; ++ j ) {
  19391. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19392. }
  19393. }
  19394. return result;
  19395. },
  19396. // function for parsing AOS keyframe formats
  19397. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19398. let i = 1, key = jsonKeys[ 0 ];
  19399. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19400. key = jsonKeys[ i ++ ];
  19401. }
  19402. if ( key === undefined ) return; // no data
  19403. let value = key[ valuePropertyName ];
  19404. if ( value === undefined ) return; // no data
  19405. if ( Array.isArray( value ) ) {
  19406. do {
  19407. value = key[ valuePropertyName ];
  19408. if ( value !== undefined ) {
  19409. times.push( key.time );
  19410. values.push.apply( values, value ); // push all elements
  19411. }
  19412. key = jsonKeys[ i ++ ];
  19413. } while ( key !== undefined );
  19414. } else if ( value.toArray !== undefined ) {
  19415. // ...assume THREE.Math-ish
  19416. do {
  19417. value = key[ valuePropertyName ];
  19418. if ( value !== undefined ) {
  19419. times.push( key.time );
  19420. value.toArray( values, values.length );
  19421. }
  19422. key = jsonKeys[ i ++ ];
  19423. } while ( key !== undefined );
  19424. } else {
  19425. // otherwise push as-is
  19426. do {
  19427. value = key[ valuePropertyName ];
  19428. if ( value !== undefined ) {
  19429. times.push( key.time );
  19430. values.push( value );
  19431. }
  19432. key = jsonKeys[ i ++ ];
  19433. } while ( key !== undefined );
  19434. }
  19435. },
  19436. subclip: function ( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  19437. const clip = sourceClip.clone();
  19438. clip.name = name;
  19439. const tracks = [];
  19440. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19441. const track = clip.tracks[ i ];
  19442. const valueSize = track.getValueSize();
  19443. const times = [];
  19444. const values = [];
  19445. for ( let j = 0; j < track.times.length; ++ j ) {
  19446. const frame = track.times[ j ] * fps;
  19447. if ( frame < startFrame || frame >= endFrame ) continue;
  19448. times.push( track.times[ j ] );
  19449. for ( let k = 0; k < valueSize; ++ k ) {
  19450. values.push( track.values[ j * valueSize + k ] );
  19451. }
  19452. }
  19453. if ( times.length === 0 ) continue;
  19454. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  19455. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  19456. tracks.push( track );
  19457. }
  19458. clip.tracks = tracks;
  19459. // find minimum .times value across all tracks in the trimmed clip
  19460. let minStartTime = Infinity;
  19461. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19462. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  19463. minStartTime = clip.tracks[ i ].times[ 0 ];
  19464. }
  19465. }
  19466. // shift all tracks such that clip begins at t=0
  19467. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  19468. clip.tracks[ i ].shift( - 1 * minStartTime );
  19469. }
  19470. clip.resetDuration();
  19471. return clip;
  19472. },
  19473. makeClipAdditive: function ( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  19474. if ( fps <= 0 ) fps = 30;
  19475. const numTracks = referenceClip.tracks.length;
  19476. const referenceTime = referenceFrame / fps;
  19477. // Make each track's values relative to the values at the reference frame
  19478. for ( let i = 0; i < numTracks; ++ i ) {
  19479. const referenceTrack = referenceClip.tracks[ i ];
  19480. const referenceTrackType = referenceTrack.ValueTypeName;
  19481. // Skip this track if it's non-numeric
  19482. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  19483. // Find the track in the target clip whose name and type matches the reference track
  19484. const targetTrack = targetClip.tracks.find( function ( track ) {
  19485. return track.name === referenceTrack.name
  19486. && track.ValueTypeName === referenceTrackType;
  19487. } );
  19488. if ( targetTrack === undefined ) continue;
  19489. let referenceOffset = 0;
  19490. const referenceValueSize = referenceTrack.getValueSize();
  19491. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  19492. referenceOffset = referenceValueSize / 3;
  19493. }
  19494. let targetOffset = 0;
  19495. const targetValueSize = targetTrack.getValueSize();
  19496. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  19497. targetOffset = targetValueSize / 3;
  19498. }
  19499. const lastIndex = referenceTrack.times.length - 1;
  19500. let referenceValue;
  19501. // Find the value to subtract out of the track
  19502. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  19503. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  19504. const startIndex = referenceOffset;
  19505. const endIndex = referenceValueSize - referenceOffset;
  19506. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  19507. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  19508. // Reference frame is after the last keyframe, so just use the last keyframe
  19509. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  19510. const endIndex = startIndex + referenceValueSize - referenceOffset;
  19511. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  19512. } else {
  19513. // Interpolate to the reference value
  19514. const interpolant = referenceTrack.createInterpolant();
  19515. const startIndex = referenceOffset;
  19516. const endIndex = referenceValueSize - referenceOffset;
  19517. interpolant.evaluate( referenceTime );
  19518. referenceValue = AnimationUtils.arraySlice( interpolant.resultBuffer, startIndex, endIndex );
  19519. }
  19520. // Conjugate the quaternion
  19521. if ( referenceTrackType === 'quaternion' ) {
  19522. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  19523. referenceQuat.toArray( referenceValue );
  19524. }
  19525. // Subtract the reference value from all of the track values
  19526. const numTimes = targetTrack.times.length;
  19527. for ( let j = 0; j < numTimes; ++ j ) {
  19528. const valueStart = j * targetValueSize + targetOffset;
  19529. if ( referenceTrackType === 'quaternion' ) {
  19530. // Multiply the conjugate for quaternion track types
  19531. Quaternion.multiplyQuaternionsFlat(
  19532. targetTrack.values,
  19533. valueStart,
  19534. referenceValue,
  19535. 0,
  19536. targetTrack.values,
  19537. valueStart
  19538. );
  19539. } else {
  19540. const valueEnd = targetValueSize - targetOffset * 2;
  19541. // Subtract each value for all other numeric track types
  19542. for ( let k = 0; k < valueEnd; ++ k ) {
  19543. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  19544. }
  19545. }
  19546. }
  19547. }
  19548. targetClip.blendMode = AdditiveAnimationBlendMode;
  19549. return targetClip;
  19550. }
  19551. };
  19552. /**
  19553. * Abstract base class of interpolants over parametric samples.
  19554. *
  19555. * The parameter domain is one dimensional, typically the time or a path
  19556. * along a curve defined by the data.
  19557. *
  19558. * The sample values can have any dimensionality and derived classes may
  19559. * apply special interpretations to the data.
  19560. *
  19561. * This class provides the interval seek in a Template Method, deferring
  19562. * the actual interpolation to derived classes.
  19563. *
  19564. * Time complexity is O(1) for linear access crossing at most two points
  19565. * and O(log N) for random access, where N is the number of positions.
  19566. *
  19567. * References:
  19568. *
  19569. * http://www.oodesign.com/template-method-pattern.html
  19570. *
  19571. */
  19572. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19573. this.parameterPositions = parameterPositions;
  19574. this._cachedIndex = 0;
  19575. this.resultBuffer = resultBuffer !== undefined ?
  19576. resultBuffer : new sampleValues.constructor( sampleSize );
  19577. this.sampleValues = sampleValues;
  19578. this.valueSize = sampleSize;
  19579. }
  19580. Object.assign( Interpolant.prototype, {
  19581. evaluate: function ( t ) {
  19582. const pp = this.parameterPositions;
  19583. let i1 = this._cachedIndex,
  19584. t1 = pp[ i1 ],
  19585. t0 = pp[ i1 - 1 ];
  19586. validate_interval: {
  19587. seek: {
  19588. let right;
  19589. linear_scan: {
  19590. //- See http://jsperf.com/comparison-to-undefined/3
  19591. //- slower code:
  19592. //-
  19593. //- if ( t >= t1 || t1 === undefined ) {
  19594. forward_scan: if ( ! ( t < t1 ) ) {
  19595. for ( let giveUpAt = i1 + 2; ; ) {
  19596. if ( t1 === undefined ) {
  19597. if ( t < t0 ) break forward_scan;
  19598. // after end
  19599. i1 = pp.length;
  19600. this._cachedIndex = i1;
  19601. return this.afterEnd_( i1 - 1, t, t0 );
  19602. }
  19603. if ( i1 === giveUpAt ) break; // this loop
  19604. t0 = t1;
  19605. t1 = pp[ ++ i1 ];
  19606. if ( t < t1 ) {
  19607. // we have arrived at the sought interval
  19608. break seek;
  19609. }
  19610. }
  19611. // prepare binary search on the right side of the index
  19612. right = pp.length;
  19613. break linear_scan;
  19614. }
  19615. //- slower code:
  19616. //- if ( t < t0 || t0 === undefined ) {
  19617. if ( ! ( t >= t0 ) ) {
  19618. // looping?
  19619. const t1global = pp[ 1 ];
  19620. if ( t < t1global ) {
  19621. i1 = 2; // + 1, using the scan for the details
  19622. t0 = t1global;
  19623. }
  19624. // linear reverse scan
  19625. for ( let giveUpAt = i1 - 2; ; ) {
  19626. if ( t0 === undefined ) {
  19627. // before start
  19628. this._cachedIndex = 0;
  19629. return this.beforeStart_( 0, t, t1 );
  19630. }
  19631. if ( i1 === giveUpAt ) break; // this loop
  19632. t1 = t0;
  19633. t0 = pp[ -- i1 - 1 ];
  19634. if ( t >= t0 ) {
  19635. // we have arrived at the sought interval
  19636. break seek;
  19637. }
  19638. }
  19639. // prepare binary search on the left side of the index
  19640. right = i1;
  19641. i1 = 0;
  19642. break linear_scan;
  19643. }
  19644. // the interval is valid
  19645. break validate_interval;
  19646. } // linear scan
  19647. // binary search
  19648. while ( i1 < right ) {
  19649. const mid = ( i1 + right ) >>> 1;
  19650. if ( t < pp[ mid ] ) {
  19651. right = mid;
  19652. } else {
  19653. i1 = mid + 1;
  19654. }
  19655. }
  19656. t1 = pp[ i1 ];
  19657. t0 = pp[ i1 - 1 ];
  19658. // check boundary cases, again
  19659. if ( t0 === undefined ) {
  19660. this._cachedIndex = 0;
  19661. return this.beforeStart_( 0, t, t1 );
  19662. }
  19663. if ( t1 === undefined ) {
  19664. i1 = pp.length;
  19665. this._cachedIndex = i1;
  19666. return this.afterEnd_( i1 - 1, t0, t );
  19667. }
  19668. } // seek
  19669. this._cachedIndex = i1;
  19670. this.intervalChanged_( i1, t0, t1 );
  19671. } // validate_interval
  19672. return this.interpolate_( i1, t0, t, t1 );
  19673. },
  19674. settings: null, // optional, subclass-specific settings structure
  19675. // Note: The indirection allows central control of many interpolants.
  19676. // --- Protected interface
  19677. DefaultSettings_: {},
  19678. getSettings_: function () {
  19679. return this.settings || this.DefaultSettings_;
  19680. },
  19681. copySampleValue_: function ( index ) {
  19682. // copies a sample value to the result buffer
  19683. const result = this.resultBuffer,
  19684. values = this.sampleValues,
  19685. stride = this.valueSize,
  19686. offset = index * stride;
  19687. for ( let i = 0; i !== stride; ++ i ) {
  19688. result[ i ] = values[ offset + i ];
  19689. }
  19690. return result;
  19691. },
  19692. // Template methods for derived classes:
  19693. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19694. throw new Error( 'call to abstract method' );
  19695. // implementations shall return this.resultBuffer
  19696. },
  19697. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19698. // empty
  19699. }
  19700. } );
  19701. // DECLARE ALIAS AFTER assign prototype
  19702. Object.assign( Interpolant.prototype, {
  19703. //( 0, t, t0 ), returns this.resultBuffer
  19704. beforeStart_: Interpolant.prototype.copySampleValue_,
  19705. //( N-1, tN-1, t ), returns this.resultBuffer
  19706. afterEnd_: Interpolant.prototype.copySampleValue_,
  19707. } );
  19708. /**
  19709. * Fast and simple cubic spline interpolant.
  19710. *
  19711. * It was derived from a Hermitian construction setting the first derivative
  19712. * at each sample position to the linear slope between neighboring positions
  19713. * over their parameter interval.
  19714. */
  19715. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19716. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19717. this._weightPrev = - 0;
  19718. this._offsetPrev = - 0;
  19719. this._weightNext = - 0;
  19720. this._offsetNext = - 0;
  19721. }
  19722. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19723. constructor: CubicInterpolant,
  19724. DefaultSettings_: {
  19725. endingStart: ZeroCurvatureEnding,
  19726. endingEnd: ZeroCurvatureEnding
  19727. },
  19728. intervalChanged_: function ( i1, t0, t1 ) {
  19729. const pp = this.parameterPositions;
  19730. let iPrev = i1 - 2,
  19731. iNext = i1 + 1,
  19732. tPrev = pp[ iPrev ],
  19733. tNext = pp[ iNext ];
  19734. if ( tPrev === undefined ) {
  19735. switch ( this.getSettings_().endingStart ) {
  19736. case ZeroSlopeEnding:
  19737. // f'(t0) = 0
  19738. iPrev = i1;
  19739. tPrev = 2 * t0 - t1;
  19740. break;
  19741. case WrapAroundEnding:
  19742. // use the other end of the curve
  19743. iPrev = pp.length - 2;
  19744. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19745. break;
  19746. default: // ZeroCurvatureEnding
  19747. // f''(t0) = 0 a.k.a. Natural Spline
  19748. iPrev = i1;
  19749. tPrev = t1;
  19750. }
  19751. }
  19752. if ( tNext === undefined ) {
  19753. switch ( this.getSettings_().endingEnd ) {
  19754. case ZeroSlopeEnding:
  19755. // f'(tN) = 0
  19756. iNext = i1;
  19757. tNext = 2 * t1 - t0;
  19758. break;
  19759. case WrapAroundEnding:
  19760. // use the other end of the curve
  19761. iNext = 1;
  19762. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19763. break;
  19764. default: // ZeroCurvatureEnding
  19765. // f''(tN) = 0, a.k.a. Natural Spline
  19766. iNext = i1 - 1;
  19767. tNext = t0;
  19768. }
  19769. }
  19770. const halfDt = ( t1 - t0 ) * 0.5,
  19771. stride = this.valueSize;
  19772. this._weightPrev = halfDt / ( t0 - tPrev );
  19773. this._weightNext = halfDt / ( tNext - t1 );
  19774. this._offsetPrev = iPrev * stride;
  19775. this._offsetNext = iNext * stride;
  19776. },
  19777. interpolate_: function ( i1, t0, t, t1 ) {
  19778. const result = this.resultBuffer,
  19779. values = this.sampleValues,
  19780. stride = this.valueSize,
  19781. o1 = i1 * stride, o0 = o1 - stride,
  19782. oP = this._offsetPrev, oN = this._offsetNext,
  19783. wP = this._weightPrev, wN = this._weightNext,
  19784. p = ( t - t0 ) / ( t1 - t0 ),
  19785. pp = p * p,
  19786. ppp = pp * p;
  19787. // evaluate polynomials
  19788. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  19789. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19790. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19791. const sN = wN * ppp - wN * pp;
  19792. // combine data linearly
  19793. for ( let i = 0; i !== stride; ++ i ) {
  19794. result[ i ] =
  19795. sP * values[ oP + i ] +
  19796. s0 * values[ o0 + i ] +
  19797. s1 * values[ o1 + i ] +
  19798. sN * values[ oN + i ];
  19799. }
  19800. return result;
  19801. }
  19802. } );
  19803. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19804. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19805. }
  19806. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19807. constructor: LinearInterpolant,
  19808. interpolate_: function ( i1, t0, t, t1 ) {
  19809. const result = this.resultBuffer,
  19810. values = this.sampleValues,
  19811. stride = this.valueSize,
  19812. offset1 = i1 * stride,
  19813. offset0 = offset1 - stride,
  19814. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19815. weight0 = 1 - weight1;
  19816. for ( let i = 0; i !== stride; ++ i ) {
  19817. result[ i ] =
  19818. values[ offset0 + i ] * weight0 +
  19819. values[ offset1 + i ] * weight1;
  19820. }
  19821. return result;
  19822. }
  19823. } );
  19824. /**
  19825. *
  19826. * Interpolant that evaluates to the sample value at the position preceeding
  19827. * the parameter.
  19828. */
  19829. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19830. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19831. }
  19832. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19833. constructor: DiscreteInterpolant,
  19834. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19835. return this.copySampleValue_( i1 - 1 );
  19836. }
  19837. } );
  19838. function KeyframeTrack( name, times, values, interpolation ) {
  19839. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19840. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19841. this.name = name;
  19842. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19843. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19844. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19845. }
  19846. // Static methods
  19847. Object.assign( KeyframeTrack, {
  19848. // Serialization (in static context, because of constructor invocation
  19849. // and automatic invocation of .toJSON):
  19850. toJSON: function ( track ) {
  19851. const trackType = track.constructor;
  19852. let json;
  19853. // derived classes can define a static toJSON method
  19854. if ( trackType.toJSON !== undefined ) {
  19855. json = trackType.toJSON( track );
  19856. } else {
  19857. // by default, we assume the data can be serialized as-is
  19858. json = {
  19859. 'name': track.name,
  19860. 'times': AnimationUtils.convertArray( track.times, Array ),
  19861. 'values': AnimationUtils.convertArray( track.values, Array )
  19862. };
  19863. const interpolation = track.getInterpolation();
  19864. if ( interpolation !== track.DefaultInterpolation ) {
  19865. json.interpolation = interpolation;
  19866. }
  19867. }
  19868. json.type = track.ValueTypeName; // mandatory
  19869. return json;
  19870. }
  19871. } );
  19872. Object.assign( KeyframeTrack.prototype, {
  19873. constructor: KeyframeTrack,
  19874. TimeBufferType: Float32Array,
  19875. ValueBufferType: Float32Array,
  19876. DefaultInterpolation: InterpolateLinear,
  19877. InterpolantFactoryMethodDiscrete: function ( result ) {
  19878. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19879. },
  19880. InterpolantFactoryMethodLinear: function ( result ) {
  19881. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19882. },
  19883. InterpolantFactoryMethodSmooth: function ( result ) {
  19884. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19885. },
  19886. setInterpolation: function ( interpolation ) {
  19887. let factoryMethod;
  19888. switch ( interpolation ) {
  19889. case InterpolateDiscrete:
  19890. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19891. break;
  19892. case InterpolateLinear:
  19893. factoryMethod = this.InterpolantFactoryMethodLinear;
  19894. break;
  19895. case InterpolateSmooth:
  19896. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19897. break;
  19898. }
  19899. if ( factoryMethod === undefined ) {
  19900. const message = 'unsupported interpolation for ' +
  19901. this.ValueTypeName + ' keyframe track named ' + this.name;
  19902. if ( this.createInterpolant === undefined ) {
  19903. // fall back to default, unless the default itself is messed up
  19904. if ( interpolation !== this.DefaultInterpolation ) {
  19905. this.setInterpolation( this.DefaultInterpolation );
  19906. } else {
  19907. throw new Error( message ); // fatal, in this case
  19908. }
  19909. }
  19910. console.warn( 'THREE.KeyframeTrack:', message );
  19911. return this;
  19912. }
  19913. this.createInterpolant = factoryMethod;
  19914. return this;
  19915. },
  19916. getInterpolation: function () {
  19917. switch ( this.createInterpolant ) {
  19918. case this.InterpolantFactoryMethodDiscrete:
  19919. return InterpolateDiscrete;
  19920. case this.InterpolantFactoryMethodLinear:
  19921. return InterpolateLinear;
  19922. case this.InterpolantFactoryMethodSmooth:
  19923. return InterpolateSmooth;
  19924. }
  19925. },
  19926. getValueSize: function () {
  19927. return this.values.length / this.times.length;
  19928. },
  19929. // move all keyframes either forwards or backwards in time
  19930. shift: function ( timeOffset ) {
  19931. if ( timeOffset !== 0.0 ) {
  19932. const times = this.times;
  19933. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  19934. times[ i ] += timeOffset;
  19935. }
  19936. }
  19937. return this;
  19938. },
  19939. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19940. scale: function ( timeScale ) {
  19941. if ( timeScale !== 1.0 ) {
  19942. const times = this.times;
  19943. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  19944. times[ i ] *= timeScale;
  19945. }
  19946. }
  19947. return this;
  19948. },
  19949. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19950. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19951. trim: function ( startTime, endTime ) {
  19952. const times = this.times,
  19953. nKeys = times.length;
  19954. let from = 0,
  19955. to = nKeys - 1;
  19956. while ( from !== nKeys && times[ from ] < startTime ) {
  19957. ++ from;
  19958. }
  19959. while ( to !== - 1 && times[ to ] > endTime ) {
  19960. -- to;
  19961. }
  19962. ++ to; // inclusive -> exclusive bound
  19963. if ( from !== 0 || to !== nKeys ) {
  19964. // empty tracks are forbidden, so keep at least one keyframe
  19965. if ( from >= to ) {
  19966. to = Math.max( to, 1 );
  19967. from = to - 1;
  19968. }
  19969. const stride = this.getValueSize();
  19970. this.times = AnimationUtils.arraySlice( times, from, to );
  19971. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19972. }
  19973. return this;
  19974. },
  19975. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19976. validate: function () {
  19977. let valid = true;
  19978. const valueSize = this.getValueSize();
  19979. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19980. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19981. valid = false;
  19982. }
  19983. const times = this.times,
  19984. values = this.values,
  19985. nKeys = times.length;
  19986. if ( nKeys === 0 ) {
  19987. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19988. valid = false;
  19989. }
  19990. let prevTime = null;
  19991. for ( let i = 0; i !== nKeys; i ++ ) {
  19992. const currTime = times[ i ];
  19993. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19994. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19995. valid = false;
  19996. break;
  19997. }
  19998. if ( prevTime !== null && prevTime > currTime ) {
  19999. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20000. valid = false;
  20001. break;
  20002. }
  20003. prevTime = currTime;
  20004. }
  20005. if ( values !== undefined ) {
  20006. if ( AnimationUtils.isTypedArray( values ) ) {
  20007. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  20008. const value = values[ i ];
  20009. if ( isNaN( value ) ) {
  20010. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20011. valid = false;
  20012. break;
  20013. }
  20014. }
  20015. }
  20016. }
  20017. return valid;
  20018. },
  20019. // removes equivalent sequential keys as common in morph target sequences
  20020. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20021. optimize: function () {
  20022. // times or values may be shared with other tracks, so overwriting is unsafe
  20023. const times = AnimationUtils.arraySlice( this.times ),
  20024. values = AnimationUtils.arraySlice( this.values ),
  20025. stride = this.getValueSize(),
  20026. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20027. lastIndex = times.length - 1;
  20028. let writeIndex = 1;
  20029. for ( let i = 1; i < lastIndex; ++ i ) {
  20030. let keep = false;
  20031. const time = times[ i ];
  20032. const timeNext = times[ i + 1 ];
  20033. // remove adjacent keyframes scheduled at the same time
  20034. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20035. if ( ! smoothInterpolation ) {
  20036. // remove unnecessary keyframes same as their neighbors
  20037. const offset = i * stride,
  20038. offsetP = offset - stride,
  20039. offsetN = offset + stride;
  20040. for ( let j = 0; j !== stride; ++ j ) {
  20041. const value = values[ offset + j ];
  20042. if ( value !== values[ offsetP + j ] ||
  20043. value !== values[ offsetN + j ] ) {
  20044. keep = true;
  20045. break;
  20046. }
  20047. }
  20048. } else {
  20049. keep = true;
  20050. }
  20051. }
  20052. // in-place compaction
  20053. if ( keep ) {
  20054. if ( i !== writeIndex ) {
  20055. times[ writeIndex ] = times[ i ];
  20056. const readOffset = i * stride,
  20057. writeOffset = writeIndex * stride;
  20058. for ( let j = 0; j !== stride; ++ j ) {
  20059. values[ writeOffset + j ] = values[ readOffset + j ];
  20060. }
  20061. }
  20062. ++ writeIndex;
  20063. }
  20064. }
  20065. // flush last keyframe (compaction looks ahead)
  20066. if ( lastIndex > 0 ) {
  20067. times[ writeIndex ] = times[ lastIndex ];
  20068. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20069. values[ writeOffset + j ] = values[ readOffset + j ];
  20070. }
  20071. ++ writeIndex;
  20072. }
  20073. if ( writeIndex !== times.length ) {
  20074. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20075. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20076. } else {
  20077. this.times = times;
  20078. this.values = values;
  20079. }
  20080. return this;
  20081. },
  20082. clone: function () {
  20083. const times = AnimationUtils.arraySlice( this.times, 0 );
  20084. const values = AnimationUtils.arraySlice( this.values, 0 );
  20085. const TypedKeyframeTrack = this.constructor;
  20086. const track = new TypedKeyframeTrack( this.name, times, values );
  20087. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20088. track.createInterpolant = this.createInterpolant;
  20089. return track;
  20090. }
  20091. } );
  20092. /**
  20093. * A Track of Boolean keyframe values.
  20094. */
  20095. function BooleanKeyframeTrack( name, times, values ) {
  20096. KeyframeTrack.call( this, name, times, values );
  20097. }
  20098. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20099. constructor: BooleanKeyframeTrack,
  20100. ValueTypeName: 'bool',
  20101. ValueBufferType: Array,
  20102. DefaultInterpolation: InterpolateDiscrete,
  20103. InterpolantFactoryMethodLinear: undefined,
  20104. InterpolantFactoryMethodSmooth: undefined
  20105. // Note: Actually this track could have a optimized / compressed
  20106. // representation of a single value and a custom interpolant that
  20107. // computes "firstValue ^ isOdd( index )".
  20108. } );
  20109. /**
  20110. * A Track of keyframe values that represent color.
  20111. */
  20112. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20113. KeyframeTrack.call( this, name, times, values, interpolation );
  20114. }
  20115. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20116. constructor: ColorKeyframeTrack,
  20117. ValueTypeName: 'color'
  20118. // ValueBufferType is inherited
  20119. // DefaultInterpolation is inherited
  20120. // Note: Very basic implementation and nothing special yet.
  20121. // However, this is the place for color space parameterization.
  20122. } );
  20123. /**
  20124. * A Track of numeric keyframe values.
  20125. */
  20126. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20127. KeyframeTrack.call( this, name, times, values, interpolation );
  20128. }
  20129. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20130. constructor: NumberKeyframeTrack,
  20131. ValueTypeName: 'number'
  20132. // ValueBufferType is inherited
  20133. // DefaultInterpolation is inherited
  20134. } );
  20135. /**
  20136. * Spherical linear unit quaternion interpolant.
  20137. */
  20138. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20139. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20140. }
  20141. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20142. constructor: QuaternionLinearInterpolant,
  20143. interpolate_: function ( i1, t0, t, t1 ) {
  20144. const result = this.resultBuffer,
  20145. values = this.sampleValues,
  20146. stride = this.valueSize,
  20147. alpha = ( t - t0 ) / ( t1 - t0 );
  20148. let offset = i1 * stride;
  20149. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  20150. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20151. }
  20152. return result;
  20153. }
  20154. } );
  20155. /**
  20156. * A Track of quaternion keyframe values.
  20157. */
  20158. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20159. KeyframeTrack.call( this, name, times, values, interpolation );
  20160. }
  20161. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20162. constructor: QuaternionKeyframeTrack,
  20163. ValueTypeName: 'quaternion',
  20164. // ValueBufferType is inherited
  20165. DefaultInterpolation: InterpolateLinear,
  20166. InterpolantFactoryMethodLinear: function ( result ) {
  20167. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20168. },
  20169. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20170. } );
  20171. /**
  20172. * A Track that interpolates Strings
  20173. */
  20174. function StringKeyframeTrack( name, times, values, interpolation ) {
  20175. KeyframeTrack.call( this, name, times, values, interpolation );
  20176. }
  20177. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20178. constructor: StringKeyframeTrack,
  20179. ValueTypeName: 'string',
  20180. ValueBufferType: Array,
  20181. DefaultInterpolation: InterpolateDiscrete,
  20182. InterpolantFactoryMethodLinear: undefined,
  20183. InterpolantFactoryMethodSmooth: undefined
  20184. } );
  20185. /**
  20186. * A Track of vectored keyframe values.
  20187. */
  20188. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20189. KeyframeTrack.call( this, name, times, values, interpolation );
  20190. }
  20191. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20192. constructor: VectorKeyframeTrack,
  20193. ValueTypeName: 'vector'
  20194. // ValueBufferType is inherited
  20195. // DefaultInterpolation is inherited
  20196. } );
  20197. function AnimationClip( name, duration = - 1, tracks, blendMode = NormalAnimationBlendMode ) {
  20198. this.name = name;
  20199. this.tracks = tracks;
  20200. this.duration = duration;
  20201. this.blendMode = blendMode;
  20202. this.uuid = MathUtils.generateUUID();
  20203. // this means it should figure out its duration by scanning the tracks
  20204. if ( this.duration < 0 ) {
  20205. this.resetDuration();
  20206. }
  20207. }
  20208. function getTrackTypeForValueTypeName( typeName ) {
  20209. switch ( typeName.toLowerCase() ) {
  20210. case 'scalar':
  20211. case 'double':
  20212. case 'float':
  20213. case 'number':
  20214. case 'integer':
  20215. return NumberKeyframeTrack;
  20216. case 'vector':
  20217. case 'vector2':
  20218. case 'vector3':
  20219. case 'vector4':
  20220. return VectorKeyframeTrack;
  20221. case 'color':
  20222. return ColorKeyframeTrack;
  20223. case 'quaternion':
  20224. return QuaternionKeyframeTrack;
  20225. case 'bool':
  20226. case 'boolean':
  20227. return BooleanKeyframeTrack;
  20228. case 'string':
  20229. return StringKeyframeTrack;
  20230. }
  20231. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20232. }
  20233. function parseKeyframeTrack( json ) {
  20234. if ( json.type === undefined ) {
  20235. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20236. }
  20237. const trackType = getTrackTypeForValueTypeName( json.type );
  20238. if ( json.times === undefined ) {
  20239. const times = [], values = [];
  20240. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20241. json.times = times;
  20242. json.values = values;
  20243. }
  20244. // derived classes can define a static parse method
  20245. if ( trackType.parse !== undefined ) {
  20246. return trackType.parse( json );
  20247. } else {
  20248. // by default, we assume a constructor compatible with the base
  20249. return new trackType( json.name, json.times, json.values, json.interpolation );
  20250. }
  20251. }
  20252. Object.assign( AnimationClip, {
  20253. parse: function ( json ) {
  20254. const tracks = [],
  20255. jsonTracks = json.tracks,
  20256. frameTime = 1.0 / ( json.fps || 1.0 );
  20257. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20258. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20259. }
  20260. const clip = new AnimationClip( json.name, json.duration, tracks, json.blendMode );
  20261. clip.uuid = json.uuid;
  20262. return clip;
  20263. },
  20264. toJSON: function ( clip ) {
  20265. const tracks = [],
  20266. clipTracks = clip.tracks;
  20267. const json = {
  20268. 'name': clip.name,
  20269. 'duration': clip.duration,
  20270. 'tracks': tracks,
  20271. 'uuid': clip.uuid,
  20272. 'blendMode': clip.blendMode
  20273. };
  20274. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20275. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20276. }
  20277. return json;
  20278. },
  20279. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20280. const numMorphTargets = morphTargetSequence.length;
  20281. const tracks = [];
  20282. for ( let i = 0; i < numMorphTargets; i ++ ) {
  20283. let times = [];
  20284. let values = [];
  20285. times.push(
  20286. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20287. i,
  20288. ( i + 1 ) % numMorphTargets );
  20289. values.push( 0, 1, 0 );
  20290. const order = AnimationUtils.getKeyframeOrder( times );
  20291. times = AnimationUtils.sortedArray( times, 1, order );
  20292. values = AnimationUtils.sortedArray( values, 1, order );
  20293. // if there is a key at the first frame, duplicate it as the
  20294. // last frame as well for perfect loop.
  20295. if ( ! noLoop && times[ 0 ] === 0 ) {
  20296. times.push( numMorphTargets );
  20297. values.push( values[ 0 ] );
  20298. }
  20299. tracks.push(
  20300. new NumberKeyframeTrack(
  20301. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20302. times, values
  20303. ).scale( 1.0 / fps ) );
  20304. }
  20305. return new AnimationClip( name, - 1, tracks );
  20306. },
  20307. findByName: function ( objectOrClipArray, name ) {
  20308. let clipArray = objectOrClipArray;
  20309. if ( ! Array.isArray( objectOrClipArray ) ) {
  20310. const o = objectOrClipArray;
  20311. clipArray = o.geometry && o.geometry.animations || o.animations;
  20312. }
  20313. for ( let i = 0; i < clipArray.length; i ++ ) {
  20314. if ( clipArray[ i ].name === name ) {
  20315. return clipArray[ i ];
  20316. }
  20317. }
  20318. return null;
  20319. },
  20320. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20321. const animationToMorphTargets = {};
  20322. // tested with https://regex101.com/ on trick sequences
  20323. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20324. const pattern = /^([\w-]*?)([\d]+)$/;
  20325. // sort morph target names into animation groups based
  20326. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20327. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  20328. const morphTarget = morphTargets[ i ];
  20329. const parts = morphTarget.name.match( pattern );
  20330. if ( parts && parts.length > 1 ) {
  20331. const name = parts[ 1 ];
  20332. let animationMorphTargets = animationToMorphTargets[ name ];
  20333. if ( ! animationMorphTargets ) {
  20334. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20335. }
  20336. animationMorphTargets.push( morphTarget );
  20337. }
  20338. }
  20339. const clips = [];
  20340. for ( const name in animationToMorphTargets ) {
  20341. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20342. }
  20343. return clips;
  20344. },
  20345. // parse the animation.hierarchy format
  20346. parseAnimation: function ( animation, bones ) {
  20347. if ( ! animation ) {
  20348. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20349. return null;
  20350. }
  20351. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20352. // only return track if there are actually keys.
  20353. if ( animationKeys.length !== 0 ) {
  20354. const times = [];
  20355. const values = [];
  20356. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20357. // empty keys are filtered out, so check again
  20358. if ( times.length !== 0 ) {
  20359. destTracks.push( new trackType( trackName, times, values ) );
  20360. }
  20361. }
  20362. };
  20363. const tracks = [];
  20364. const clipName = animation.name || 'default';
  20365. const fps = animation.fps || 30;
  20366. const blendMode = animation.blendMode;
  20367. // automatic length determination in AnimationClip.
  20368. let duration = animation.length || - 1;
  20369. const hierarchyTracks = animation.hierarchy || [];
  20370. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  20371. const animationKeys = hierarchyTracks[ h ].keys;
  20372. // skip empty tracks
  20373. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20374. // process morph targets
  20375. if ( animationKeys[ 0 ].morphTargets ) {
  20376. // figure out all morph targets used in this track
  20377. const morphTargetNames = {};
  20378. let k;
  20379. for ( k = 0; k < animationKeys.length; k ++ ) {
  20380. if ( animationKeys[ k ].morphTargets ) {
  20381. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20382. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20383. }
  20384. }
  20385. }
  20386. // create a track for each morph target with all zero
  20387. // morphTargetInfluences except for the keys in which
  20388. // the morphTarget is named.
  20389. for ( const morphTargetName in morphTargetNames ) {
  20390. const times = [];
  20391. const values = [];
  20392. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20393. const animationKey = animationKeys[ k ];
  20394. times.push( animationKey.time );
  20395. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20396. }
  20397. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20398. }
  20399. duration = morphTargetNames.length * ( fps || 1.0 );
  20400. } else {
  20401. // ...assume skeletal animation
  20402. const boneName = '.bones[' + bones[ h ].name + ']';
  20403. addNonemptyTrack(
  20404. VectorKeyframeTrack, boneName + '.position',
  20405. animationKeys, 'pos', tracks );
  20406. addNonemptyTrack(
  20407. QuaternionKeyframeTrack, boneName + '.quaternion',
  20408. animationKeys, 'rot', tracks );
  20409. addNonemptyTrack(
  20410. VectorKeyframeTrack, boneName + '.scale',
  20411. animationKeys, 'scl', tracks );
  20412. }
  20413. }
  20414. if ( tracks.length === 0 ) {
  20415. return null;
  20416. }
  20417. const clip = new AnimationClip( clipName, duration, tracks, blendMode );
  20418. return clip;
  20419. }
  20420. } );
  20421. Object.assign( AnimationClip.prototype, {
  20422. resetDuration: function () {
  20423. const tracks = this.tracks;
  20424. let duration = 0;
  20425. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  20426. const track = this.tracks[ i ];
  20427. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20428. }
  20429. this.duration = duration;
  20430. return this;
  20431. },
  20432. trim: function () {
  20433. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20434. this.tracks[ i ].trim( 0, this.duration );
  20435. }
  20436. return this;
  20437. },
  20438. validate: function () {
  20439. let valid = true;
  20440. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20441. valid = valid && this.tracks[ i ].validate();
  20442. }
  20443. return valid;
  20444. },
  20445. optimize: function () {
  20446. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20447. this.tracks[ i ].optimize();
  20448. }
  20449. return this;
  20450. },
  20451. clone: function () {
  20452. const tracks = [];
  20453. for ( let i = 0; i < this.tracks.length; i ++ ) {
  20454. tracks.push( this.tracks[ i ].clone() );
  20455. }
  20456. return new AnimationClip( this.name, this.duration, tracks, this.blendMode );
  20457. },
  20458. toJSON: function () {
  20459. return AnimationClip.toJSON( this );
  20460. }
  20461. } );
  20462. const Cache = {
  20463. enabled: false,
  20464. files: {},
  20465. add: function ( key, file ) {
  20466. if ( this.enabled === false ) return;
  20467. // console.log( 'THREE.Cache', 'Adding key:', key );
  20468. this.files[ key ] = file;
  20469. },
  20470. get: function ( key ) {
  20471. if ( this.enabled === false ) return;
  20472. // console.log( 'THREE.Cache', 'Checking key:', key );
  20473. return this.files[ key ];
  20474. },
  20475. remove: function ( key ) {
  20476. delete this.files[ key ];
  20477. },
  20478. clear: function () {
  20479. this.files = {};
  20480. }
  20481. };
  20482. function LoadingManager( onLoad, onProgress, onError ) {
  20483. const scope = this;
  20484. let isLoading = false;
  20485. let itemsLoaded = 0;
  20486. let itemsTotal = 0;
  20487. let urlModifier = undefined;
  20488. const handlers = [];
  20489. // Refer to #5689 for the reason why we don't set .onStart
  20490. // in the constructor
  20491. this.onStart = undefined;
  20492. this.onLoad = onLoad;
  20493. this.onProgress = onProgress;
  20494. this.onError = onError;
  20495. this.itemStart = function ( url ) {
  20496. itemsTotal ++;
  20497. if ( isLoading === false ) {
  20498. if ( scope.onStart !== undefined ) {
  20499. scope.onStart( url, itemsLoaded, itemsTotal );
  20500. }
  20501. }
  20502. isLoading = true;
  20503. };
  20504. this.itemEnd = function ( url ) {
  20505. itemsLoaded ++;
  20506. if ( scope.onProgress !== undefined ) {
  20507. scope.onProgress( url, itemsLoaded, itemsTotal );
  20508. }
  20509. if ( itemsLoaded === itemsTotal ) {
  20510. isLoading = false;
  20511. if ( scope.onLoad !== undefined ) {
  20512. scope.onLoad();
  20513. }
  20514. }
  20515. };
  20516. this.itemError = function ( url ) {
  20517. if ( scope.onError !== undefined ) {
  20518. scope.onError( url );
  20519. }
  20520. };
  20521. this.resolveURL = function ( url ) {
  20522. if ( urlModifier ) {
  20523. return urlModifier( url );
  20524. }
  20525. return url;
  20526. };
  20527. this.setURLModifier = function ( transform ) {
  20528. urlModifier = transform;
  20529. return this;
  20530. };
  20531. this.addHandler = function ( regex, loader ) {
  20532. handlers.push( regex, loader );
  20533. return this;
  20534. };
  20535. this.removeHandler = function ( regex ) {
  20536. const index = handlers.indexOf( regex );
  20537. if ( index !== - 1 ) {
  20538. handlers.splice( index, 2 );
  20539. }
  20540. return this;
  20541. };
  20542. this.getHandler = function ( file ) {
  20543. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  20544. const regex = handlers[ i ];
  20545. const loader = handlers[ i + 1 ];
  20546. if ( regex.global ) regex.lastIndex = 0; // see #17920
  20547. if ( regex.test( file ) ) {
  20548. return loader;
  20549. }
  20550. }
  20551. return null;
  20552. };
  20553. }
  20554. const DefaultLoadingManager = new LoadingManager();
  20555. function Loader( manager ) {
  20556. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20557. this.crossOrigin = 'anonymous';
  20558. this.withCredentials = false;
  20559. this.path = '';
  20560. this.resourcePath = '';
  20561. this.requestHeader = {};
  20562. }
  20563. Object.assign( Loader.prototype, {
  20564. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  20565. loadAsync: function ( url, onProgress ) {
  20566. const scope = this;
  20567. return new Promise( function ( resolve, reject ) {
  20568. scope.load( url, resolve, onProgress, reject );
  20569. } );
  20570. },
  20571. parse: function ( /* data */ ) {},
  20572. setCrossOrigin: function ( crossOrigin ) {
  20573. this.crossOrigin = crossOrigin;
  20574. return this;
  20575. },
  20576. setWithCredentials: function ( value ) {
  20577. this.withCredentials = value;
  20578. return this;
  20579. },
  20580. setPath: function ( path ) {
  20581. this.path = path;
  20582. return this;
  20583. },
  20584. setResourcePath: function ( resourcePath ) {
  20585. this.resourcePath = resourcePath;
  20586. return this;
  20587. },
  20588. setRequestHeader: function ( requestHeader ) {
  20589. this.requestHeader = requestHeader;
  20590. return this;
  20591. }
  20592. } );
  20593. const loading = {};
  20594. function FileLoader( manager ) {
  20595. Loader.call( this, manager );
  20596. }
  20597. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20598. constructor: FileLoader,
  20599. load: function ( url, onLoad, onProgress, onError ) {
  20600. if ( url === undefined ) url = '';
  20601. if ( this.path !== undefined ) url = this.path + url;
  20602. url = this.manager.resolveURL( url );
  20603. const scope = this;
  20604. const cached = Cache.get( url );
  20605. if ( cached !== undefined ) {
  20606. scope.manager.itemStart( url );
  20607. setTimeout( function () {
  20608. if ( onLoad ) onLoad( cached );
  20609. scope.manager.itemEnd( url );
  20610. }, 0 );
  20611. return cached;
  20612. }
  20613. // Check if request is duplicate
  20614. if ( loading[ url ] !== undefined ) {
  20615. loading[ url ].push( {
  20616. onLoad: onLoad,
  20617. onProgress: onProgress,
  20618. onError: onError
  20619. } );
  20620. return;
  20621. }
  20622. // Check for data: URI
  20623. const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20624. const dataUriRegexResult = url.match( dataUriRegex );
  20625. let request;
  20626. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20627. if ( dataUriRegexResult ) {
  20628. const mimeType = dataUriRegexResult[ 1 ];
  20629. const isBase64 = !! dataUriRegexResult[ 2 ];
  20630. let data = dataUriRegexResult[ 3 ];
  20631. data = decodeURIComponent( data );
  20632. if ( isBase64 ) data = atob( data );
  20633. try {
  20634. let response;
  20635. const responseType = ( this.responseType || '' ).toLowerCase();
  20636. switch ( responseType ) {
  20637. case 'arraybuffer':
  20638. case 'blob':
  20639. const view = new Uint8Array( data.length );
  20640. for ( let i = 0; i < data.length; i ++ ) {
  20641. view[ i ] = data.charCodeAt( i );
  20642. }
  20643. if ( responseType === 'blob' ) {
  20644. response = new Blob( [ view.buffer ], { type: mimeType } );
  20645. } else {
  20646. response = view.buffer;
  20647. }
  20648. break;
  20649. case 'document':
  20650. const parser = new DOMParser();
  20651. response = parser.parseFromString( data, mimeType );
  20652. break;
  20653. case 'json':
  20654. response = JSON.parse( data );
  20655. break;
  20656. default: // 'text' or other
  20657. response = data;
  20658. break;
  20659. }
  20660. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20661. setTimeout( function () {
  20662. if ( onLoad ) onLoad( response );
  20663. scope.manager.itemEnd( url );
  20664. }, 0 );
  20665. } catch ( error ) {
  20666. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20667. setTimeout( function () {
  20668. if ( onError ) onError( error );
  20669. scope.manager.itemError( url );
  20670. scope.manager.itemEnd( url );
  20671. }, 0 );
  20672. }
  20673. } else {
  20674. // Initialise array for duplicate requests
  20675. loading[ url ] = [];
  20676. loading[ url ].push( {
  20677. onLoad: onLoad,
  20678. onProgress: onProgress,
  20679. onError: onError
  20680. } );
  20681. request = new XMLHttpRequest();
  20682. request.open( 'GET', url, true );
  20683. request.addEventListener( 'load', function ( event ) {
  20684. const response = this.response;
  20685. const callbacks = loading[ url ];
  20686. delete loading[ url ];
  20687. if ( this.status === 200 || this.status === 0 ) {
  20688. // Some browsers return HTTP Status 0 when using non-http protocol
  20689. // e.g. 'file://' or 'data://'. Handle as success.
  20690. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20691. // Add to cache only on HTTP success, so that we do not cache
  20692. // error response bodies as proper responses to requests.
  20693. Cache.add( url, response );
  20694. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20695. const callback = callbacks[ i ];
  20696. if ( callback.onLoad ) callback.onLoad( response );
  20697. }
  20698. scope.manager.itemEnd( url );
  20699. } else {
  20700. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20701. const callback = callbacks[ i ];
  20702. if ( callback.onError ) callback.onError( event );
  20703. }
  20704. scope.manager.itemError( url );
  20705. scope.manager.itemEnd( url );
  20706. }
  20707. }, false );
  20708. request.addEventListener( 'progress', function ( event ) {
  20709. const callbacks = loading[ url ];
  20710. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20711. const callback = callbacks[ i ];
  20712. if ( callback.onProgress ) callback.onProgress( event );
  20713. }
  20714. }, false );
  20715. request.addEventListener( 'error', function ( event ) {
  20716. const callbacks = loading[ url ];
  20717. delete loading[ url ];
  20718. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20719. const callback = callbacks[ i ];
  20720. if ( callback.onError ) callback.onError( event );
  20721. }
  20722. scope.manager.itemError( url );
  20723. scope.manager.itemEnd( url );
  20724. }, false );
  20725. request.addEventListener( 'abort', function ( event ) {
  20726. const callbacks = loading[ url ];
  20727. delete loading[ url ];
  20728. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  20729. const callback = callbacks[ i ];
  20730. if ( callback.onError ) callback.onError( event );
  20731. }
  20732. scope.manager.itemError( url );
  20733. scope.manager.itemEnd( url );
  20734. }, false );
  20735. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20736. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20737. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20738. for ( const header in this.requestHeader ) {
  20739. request.setRequestHeader( header, this.requestHeader[ header ] );
  20740. }
  20741. request.send( null );
  20742. }
  20743. scope.manager.itemStart( url );
  20744. return request;
  20745. },
  20746. setResponseType: function ( value ) {
  20747. this.responseType = value;
  20748. return this;
  20749. },
  20750. setMimeType: function ( value ) {
  20751. this.mimeType = value;
  20752. return this;
  20753. }
  20754. } );
  20755. function AnimationLoader( manager ) {
  20756. Loader.call( this, manager );
  20757. }
  20758. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20759. constructor: AnimationLoader,
  20760. load: function ( url, onLoad, onProgress, onError ) {
  20761. const scope = this;
  20762. const loader = new FileLoader( scope.manager );
  20763. loader.setPath( scope.path );
  20764. loader.setRequestHeader( scope.requestHeader );
  20765. loader.setWithCredentials( scope.withCredentials );
  20766. loader.load( url, function ( text ) {
  20767. try {
  20768. onLoad( scope.parse( JSON.parse( text ) ) );
  20769. } catch ( e ) {
  20770. if ( onError ) {
  20771. onError( e );
  20772. } else {
  20773. console.error( e );
  20774. }
  20775. scope.manager.itemError( url );
  20776. }
  20777. }, onProgress, onError );
  20778. },
  20779. parse: function ( json ) {
  20780. const animations = [];
  20781. for ( let i = 0; i < json.length; i ++ ) {
  20782. const clip = AnimationClip.parse( json[ i ] );
  20783. animations.push( clip );
  20784. }
  20785. return animations;
  20786. }
  20787. } );
  20788. /**
  20789. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20790. *
  20791. * Sub classes have to implement the parse() method which will be used in load().
  20792. */
  20793. function CompressedTextureLoader( manager ) {
  20794. Loader.call( this, manager );
  20795. }
  20796. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20797. constructor: CompressedTextureLoader,
  20798. load: function ( url, onLoad, onProgress, onError ) {
  20799. const scope = this;
  20800. const images = [];
  20801. const texture = new CompressedTexture();
  20802. const loader = new FileLoader( this.manager );
  20803. loader.setPath( this.path );
  20804. loader.setResponseType( 'arraybuffer' );
  20805. loader.setRequestHeader( this.requestHeader );
  20806. loader.setWithCredentials( scope.withCredentials );
  20807. let loaded = 0;
  20808. function loadTexture( i ) {
  20809. loader.load( url[ i ], function ( buffer ) {
  20810. const texDatas = scope.parse( buffer, true );
  20811. images[ i ] = {
  20812. width: texDatas.width,
  20813. height: texDatas.height,
  20814. format: texDatas.format,
  20815. mipmaps: texDatas.mipmaps
  20816. };
  20817. loaded += 1;
  20818. if ( loaded === 6 ) {
  20819. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  20820. texture.image = images;
  20821. texture.format = texDatas.format;
  20822. texture.needsUpdate = true;
  20823. if ( onLoad ) onLoad( texture );
  20824. }
  20825. }, onProgress, onError );
  20826. }
  20827. if ( Array.isArray( url ) ) {
  20828. for ( let i = 0, il = url.length; i < il; ++ i ) {
  20829. loadTexture( i );
  20830. }
  20831. } else {
  20832. // compressed cubemap texture stored in a single DDS file
  20833. loader.load( url, function ( buffer ) {
  20834. const texDatas = scope.parse( buffer, true );
  20835. if ( texDatas.isCubemap ) {
  20836. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20837. for ( let f = 0; f < faces; f ++ ) {
  20838. images[ f ] = { mipmaps: [] };
  20839. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  20840. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20841. images[ f ].format = texDatas.format;
  20842. images[ f ].width = texDatas.width;
  20843. images[ f ].height = texDatas.height;
  20844. }
  20845. }
  20846. texture.image = images;
  20847. } else {
  20848. texture.image.width = texDatas.width;
  20849. texture.image.height = texDatas.height;
  20850. texture.mipmaps = texDatas.mipmaps;
  20851. }
  20852. if ( texDatas.mipmapCount === 1 ) {
  20853. texture.minFilter = LinearFilter;
  20854. }
  20855. texture.format = texDatas.format;
  20856. texture.needsUpdate = true;
  20857. if ( onLoad ) onLoad( texture );
  20858. }, onProgress, onError );
  20859. }
  20860. return texture;
  20861. }
  20862. } );
  20863. function ImageLoader( manager ) {
  20864. Loader.call( this, manager );
  20865. }
  20866. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20867. constructor: ImageLoader,
  20868. load: function ( url, onLoad, onProgress, onError ) {
  20869. if ( this.path !== undefined ) url = this.path + url;
  20870. url = this.manager.resolveURL( url );
  20871. const scope = this;
  20872. const cached = Cache.get( url );
  20873. if ( cached !== undefined ) {
  20874. scope.manager.itemStart( url );
  20875. setTimeout( function () {
  20876. if ( onLoad ) onLoad( cached );
  20877. scope.manager.itemEnd( url );
  20878. }, 0 );
  20879. return cached;
  20880. }
  20881. const image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20882. function onImageLoad() {
  20883. image.removeEventListener( 'load', onImageLoad, false );
  20884. image.removeEventListener( 'error', onImageError, false );
  20885. Cache.add( url, this );
  20886. if ( onLoad ) onLoad( this );
  20887. scope.manager.itemEnd( url );
  20888. }
  20889. function onImageError( event ) {
  20890. image.removeEventListener( 'load', onImageLoad, false );
  20891. image.removeEventListener( 'error', onImageError, false );
  20892. if ( onError ) onError( event );
  20893. scope.manager.itemError( url );
  20894. scope.manager.itemEnd( url );
  20895. }
  20896. image.addEventListener( 'load', onImageLoad, false );
  20897. image.addEventListener( 'error', onImageError, false );
  20898. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20899. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20900. }
  20901. scope.manager.itemStart( url );
  20902. image.src = url;
  20903. return image;
  20904. }
  20905. } );
  20906. function CubeTextureLoader( manager ) {
  20907. Loader.call( this, manager );
  20908. }
  20909. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20910. constructor: CubeTextureLoader,
  20911. load: function ( urls, onLoad, onProgress, onError ) {
  20912. const texture = new CubeTexture();
  20913. const loader = new ImageLoader( this.manager );
  20914. loader.setCrossOrigin( this.crossOrigin );
  20915. loader.setPath( this.path );
  20916. let loaded = 0;
  20917. function loadTexture( i ) {
  20918. loader.load( urls[ i ], function ( image ) {
  20919. texture.images[ i ] = image;
  20920. loaded ++;
  20921. if ( loaded === 6 ) {
  20922. texture.needsUpdate = true;
  20923. if ( onLoad ) onLoad( texture );
  20924. }
  20925. }, undefined, onError );
  20926. }
  20927. for ( let i = 0; i < urls.length; ++ i ) {
  20928. loadTexture( i );
  20929. }
  20930. return texture;
  20931. }
  20932. } );
  20933. /**
  20934. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20935. *
  20936. * Sub classes have to implement the parse() method which will be used in load().
  20937. */
  20938. function DataTextureLoader( manager ) {
  20939. Loader.call( this, manager );
  20940. }
  20941. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20942. constructor: DataTextureLoader,
  20943. load: function ( url, onLoad, onProgress, onError ) {
  20944. const scope = this;
  20945. const texture = new DataTexture();
  20946. const loader = new FileLoader( this.manager );
  20947. loader.setResponseType( 'arraybuffer' );
  20948. loader.setRequestHeader( this.requestHeader );
  20949. loader.setPath( this.path );
  20950. loader.setWithCredentials( scope.withCredentials );
  20951. loader.load( url, function ( buffer ) {
  20952. const texData = scope.parse( buffer );
  20953. if ( ! texData ) return;
  20954. if ( texData.image !== undefined ) {
  20955. texture.image = texData.image;
  20956. } else if ( texData.data !== undefined ) {
  20957. texture.image.width = texData.width;
  20958. texture.image.height = texData.height;
  20959. texture.image.data = texData.data;
  20960. }
  20961. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20962. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20963. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20964. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  20965. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20966. if ( texData.format !== undefined ) {
  20967. texture.format = texData.format;
  20968. }
  20969. if ( texData.type !== undefined ) {
  20970. texture.type = texData.type;
  20971. }
  20972. if ( texData.mipmaps !== undefined ) {
  20973. texture.mipmaps = texData.mipmaps;
  20974. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  20975. }
  20976. if ( texData.mipmapCount === 1 ) {
  20977. texture.minFilter = LinearFilter;
  20978. }
  20979. texture.needsUpdate = true;
  20980. if ( onLoad ) onLoad( texture, texData );
  20981. }, onProgress, onError );
  20982. return texture;
  20983. }
  20984. } );
  20985. function TextureLoader( manager ) {
  20986. Loader.call( this, manager );
  20987. }
  20988. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  20989. constructor: TextureLoader,
  20990. load: function ( url, onLoad, onProgress, onError ) {
  20991. const texture = new Texture();
  20992. const loader = new ImageLoader( this.manager );
  20993. loader.setCrossOrigin( this.crossOrigin );
  20994. loader.setPath( this.path );
  20995. loader.load( url, function ( image ) {
  20996. texture.image = image;
  20997. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20998. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20999. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21000. texture.needsUpdate = true;
  21001. if ( onLoad !== undefined ) {
  21002. onLoad( texture );
  21003. }
  21004. }, onProgress, onError );
  21005. return texture;
  21006. }
  21007. } );
  21008. /**
  21009. * Extensible curve object.
  21010. *
  21011. * Some common of curve methods:
  21012. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21013. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21014. * .getPoints(), .getSpacedPoints()
  21015. * .getLength()
  21016. * .updateArcLengths()
  21017. *
  21018. * This following curves inherit from THREE.Curve:
  21019. *
  21020. * -- 2D curves --
  21021. * THREE.ArcCurve
  21022. * THREE.CubicBezierCurve
  21023. * THREE.EllipseCurve
  21024. * THREE.LineCurve
  21025. * THREE.QuadraticBezierCurve
  21026. * THREE.SplineCurve
  21027. *
  21028. * -- 3D curves --
  21029. * THREE.CatmullRomCurve3
  21030. * THREE.CubicBezierCurve3
  21031. * THREE.LineCurve3
  21032. * THREE.QuadraticBezierCurve3
  21033. *
  21034. * A series of curves can be represented as a THREE.CurvePath.
  21035. *
  21036. **/
  21037. function Curve() {
  21038. this.type = 'Curve';
  21039. this.arcLengthDivisions = 200;
  21040. }
  21041. Object.assign( Curve.prototype, {
  21042. // Virtual base class method to overwrite and implement in subclasses
  21043. // - t [0 .. 1]
  21044. getPoint: function ( /* t, optionalTarget */ ) {
  21045. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21046. return null;
  21047. },
  21048. // Get point at relative position in curve according to arc length
  21049. // - u [0 .. 1]
  21050. getPointAt: function ( u, optionalTarget ) {
  21051. const t = this.getUtoTmapping( u );
  21052. return this.getPoint( t, optionalTarget );
  21053. },
  21054. // Get sequence of points using getPoint( t )
  21055. getPoints: function ( divisions = 5 ) {
  21056. const points = [];
  21057. for ( let d = 0; d <= divisions; d ++ ) {
  21058. points.push( this.getPoint( d / divisions ) );
  21059. }
  21060. return points;
  21061. },
  21062. // Get sequence of points using getPointAt( u )
  21063. getSpacedPoints: function ( divisions = 5 ) {
  21064. const points = [];
  21065. for ( let d = 0; d <= divisions; d ++ ) {
  21066. points.push( this.getPointAt( d / divisions ) );
  21067. }
  21068. return points;
  21069. },
  21070. // Get total curve arc length
  21071. getLength: function () {
  21072. const lengths = this.getLengths();
  21073. return lengths[ lengths.length - 1 ];
  21074. },
  21075. // Get list of cumulative segment lengths
  21076. getLengths: function ( divisions ) {
  21077. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21078. if ( this.cacheArcLengths &&
  21079. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21080. ! this.needsUpdate ) {
  21081. return this.cacheArcLengths;
  21082. }
  21083. this.needsUpdate = false;
  21084. const cache = [];
  21085. let current, last = this.getPoint( 0 );
  21086. let sum = 0;
  21087. cache.push( 0 );
  21088. for ( let p = 1; p <= divisions; p ++ ) {
  21089. current = this.getPoint( p / divisions );
  21090. sum += current.distanceTo( last );
  21091. cache.push( sum );
  21092. last = current;
  21093. }
  21094. this.cacheArcLengths = cache;
  21095. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21096. },
  21097. updateArcLengths: function () {
  21098. this.needsUpdate = true;
  21099. this.getLengths();
  21100. },
  21101. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21102. getUtoTmapping: function ( u, distance ) {
  21103. const arcLengths = this.getLengths();
  21104. let i = 0;
  21105. const il = arcLengths.length;
  21106. let targetArcLength; // The targeted u distance value to get
  21107. if ( distance ) {
  21108. targetArcLength = distance;
  21109. } else {
  21110. targetArcLength = u * arcLengths[ il - 1 ];
  21111. }
  21112. // binary search for the index with largest value smaller than target u distance
  21113. let low = 0, high = il - 1, comparison;
  21114. while ( low <= high ) {
  21115. 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
  21116. comparison = arcLengths[ i ] - targetArcLength;
  21117. if ( comparison < 0 ) {
  21118. low = i + 1;
  21119. } else if ( comparison > 0 ) {
  21120. high = i - 1;
  21121. } else {
  21122. high = i;
  21123. break;
  21124. // DONE
  21125. }
  21126. }
  21127. i = high;
  21128. if ( arcLengths[ i ] === targetArcLength ) {
  21129. return i / ( il - 1 );
  21130. }
  21131. // we could get finer grain at lengths, or use simple interpolation between two points
  21132. const lengthBefore = arcLengths[ i ];
  21133. const lengthAfter = arcLengths[ i + 1 ];
  21134. const segmentLength = lengthAfter - lengthBefore;
  21135. // determine where we are between the 'before' and 'after' points
  21136. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21137. // add that fractional amount to t
  21138. const t = ( i + segmentFraction ) / ( il - 1 );
  21139. return t;
  21140. },
  21141. // Returns a unit vector tangent at t
  21142. // In case any sub curve does not implement its tangent derivation,
  21143. // 2 points a small delta apart will be used to find its gradient
  21144. // which seems to give a reasonable approximation
  21145. getTangent: function ( t, optionalTarget ) {
  21146. const delta = 0.0001;
  21147. let t1 = t - delta;
  21148. let t2 = t + delta;
  21149. // Capping in case of danger
  21150. if ( t1 < 0 ) t1 = 0;
  21151. if ( t2 > 1 ) t2 = 1;
  21152. const pt1 = this.getPoint( t1 );
  21153. const pt2 = this.getPoint( t2 );
  21154. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  21155. tangent.copy( pt2 ).sub( pt1 ).normalize();
  21156. return tangent;
  21157. },
  21158. getTangentAt: function ( u, optionalTarget ) {
  21159. const t = this.getUtoTmapping( u );
  21160. return this.getTangent( t, optionalTarget );
  21161. },
  21162. computeFrenetFrames: function ( segments, closed ) {
  21163. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21164. const normal = new Vector3();
  21165. const tangents = [];
  21166. const normals = [];
  21167. const binormals = [];
  21168. const vec = new Vector3();
  21169. const mat = new Matrix4();
  21170. // compute the tangent vectors for each segment on the curve
  21171. for ( let i = 0; i <= segments; i ++ ) {
  21172. const u = i / segments;
  21173. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  21174. tangents[ i ].normalize();
  21175. }
  21176. // select an initial normal vector perpendicular to the first tangent vector,
  21177. // and in the direction of the minimum tangent xyz component
  21178. normals[ 0 ] = new Vector3();
  21179. binormals[ 0 ] = new Vector3();
  21180. let min = Number.MAX_VALUE;
  21181. const tx = Math.abs( tangents[ 0 ].x );
  21182. const ty = Math.abs( tangents[ 0 ].y );
  21183. const tz = Math.abs( tangents[ 0 ].z );
  21184. if ( tx <= min ) {
  21185. min = tx;
  21186. normal.set( 1, 0, 0 );
  21187. }
  21188. if ( ty <= min ) {
  21189. min = ty;
  21190. normal.set( 0, 1, 0 );
  21191. }
  21192. if ( tz <= min ) {
  21193. normal.set( 0, 0, 1 );
  21194. }
  21195. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21196. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21197. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21198. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21199. for ( let i = 1; i <= segments; i ++ ) {
  21200. normals[ i ] = normals[ i - 1 ].clone();
  21201. binormals[ i ] = binormals[ i - 1 ].clone();
  21202. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21203. if ( vec.length() > Number.EPSILON ) {
  21204. vec.normalize();
  21205. const theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21206. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21207. }
  21208. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21209. }
  21210. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21211. if ( closed === true ) {
  21212. let theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21213. theta /= segments;
  21214. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21215. theta = - theta;
  21216. }
  21217. for ( let i = 1; i <= segments; i ++ ) {
  21218. // twist a little...
  21219. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21220. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21221. }
  21222. }
  21223. return {
  21224. tangents: tangents,
  21225. normals: normals,
  21226. binormals: binormals
  21227. };
  21228. },
  21229. clone: function () {
  21230. return new this.constructor().copy( this );
  21231. },
  21232. copy: function ( source ) {
  21233. this.arcLengthDivisions = source.arcLengthDivisions;
  21234. return this;
  21235. },
  21236. toJSON: function () {
  21237. const data = {
  21238. metadata: {
  21239. version: 4.5,
  21240. type: 'Curve',
  21241. generator: 'Curve.toJSON'
  21242. }
  21243. };
  21244. data.arcLengthDivisions = this.arcLengthDivisions;
  21245. data.type = this.type;
  21246. return data;
  21247. },
  21248. fromJSON: function ( json ) {
  21249. this.arcLengthDivisions = json.arcLengthDivisions;
  21250. return this;
  21251. }
  21252. } );
  21253. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21254. Curve.call( this );
  21255. this.type = 'EllipseCurve';
  21256. this.aX = aX || 0;
  21257. this.aY = aY || 0;
  21258. this.xRadius = xRadius || 1;
  21259. this.yRadius = yRadius || 1;
  21260. this.aStartAngle = aStartAngle || 0;
  21261. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21262. this.aClockwise = aClockwise || false;
  21263. this.aRotation = aRotation || 0;
  21264. }
  21265. EllipseCurve.prototype = Object.create( Curve.prototype );
  21266. EllipseCurve.prototype.constructor = EllipseCurve;
  21267. EllipseCurve.prototype.isEllipseCurve = true;
  21268. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21269. const point = optionalTarget || new Vector2();
  21270. const twoPi = Math.PI * 2;
  21271. let deltaAngle = this.aEndAngle - this.aStartAngle;
  21272. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21273. // ensures that deltaAngle is 0 .. 2 PI
  21274. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21275. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21276. if ( deltaAngle < Number.EPSILON ) {
  21277. if ( samePoints ) {
  21278. deltaAngle = 0;
  21279. } else {
  21280. deltaAngle = twoPi;
  21281. }
  21282. }
  21283. if ( this.aClockwise === true && ! samePoints ) {
  21284. if ( deltaAngle === twoPi ) {
  21285. deltaAngle = - twoPi;
  21286. } else {
  21287. deltaAngle = deltaAngle - twoPi;
  21288. }
  21289. }
  21290. const angle = this.aStartAngle + t * deltaAngle;
  21291. let x = this.aX + this.xRadius * Math.cos( angle );
  21292. let y = this.aY + this.yRadius * Math.sin( angle );
  21293. if ( this.aRotation !== 0 ) {
  21294. const cos = Math.cos( this.aRotation );
  21295. const sin = Math.sin( this.aRotation );
  21296. const tx = x - this.aX;
  21297. const ty = y - this.aY;
  21298. // Rotate the point about the center of the ellipse.
  21299. x = tx * cos - ty * sin + this.aX;
  21300. y = tx * sin + ty * cos + this.aY;
  21301. }
  21302. return point.set( x, y );
  21303. };
  21304. EllipseCurve.prototype.copy = function ( source ) {
  21305. Curve.prototype.copy.call( this, source );
  21306. this.aX = source.aX;
  21307. this.aY = source.aY;
  21308. this.xRadius = source.xRadius;
  21309. this.yRadius = source.yRadius;
  21310. this.aStartAngle = source.aStartAngle;
  21311. this.aEndAngle = source.aEndAngle;
  21312. this.aClockwise = source.aClockwise;
  21313. this.aRotation = source.aRotation;
  21314. return this;
  21315. };
  21316. EllipseCurve.prototype.toJSON = function () {
  21317. const data = Curve.prototype.toJSON.call( this );
  21318. data.aX = this.aX;
  21319. data.aY = this.aY;
  21320. data.xRadius = this.xRadius;
  21321. data.yRadius = this.yRadius;
  21322. data.aStartAngle = this.aStartAngle;
  21323. data.aEndAngle = this.aEndAngle;
  21324. data.aClockwise = this.aClockwise;
  21325. data.aRotation = this.aRotation;
  21326. return data;
  21327. };
  21328. EllipseCurve.prototype.fromJSON = function ( json ) {
  21329. Curve.prototype.fromJSON.call( this, json );
  21330. this.aX = json.aX;
  21331. this.aY = json.aY;
  21332. this.xRadius = json.xRadius;
  21333. this.yRadius = json.yRadius;
  21334. this.aStartAngle = json.aStartAngle;
  21335. this.aEndAngle = json.aEndAngle;
  21336. this.aClockwise = json.aClockwise;
  21337. this.aRotation = json.aRotation;
  21338. return this;
  21339. };
  21340. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21341. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21342. this.type = 'ArcCurve';
  21343. }
  21344. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21345. ArcCurve.prototype.constructor = ArcCurve;
  21346. ArcCurve.prototype.isArcCurve = true;
  21347. /**
  21348. * Centripetal CatmullRom Curve - which is useful for avoiding
  21349. * cusps and self-intersections in non-uniform catmull rom curves.
  21350. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21351. *
  21352. * curve.type accepts centripetal(default), chordal and catmullrom
  21353. * curve.tension is used for catmullrom which defaults to 0.5
  21354. */
  21355. /*
  21356. Based on an optimized c++ solution in
  21357. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21358. - http://ideone.com/NoEbVM
  21359. This CubicPoly class could be used for reusing some variables and calculations,
  21360. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21361. which can be placed in CurveUtils.
  21362. */
  21363. function CubicPoly() {
  21364. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21365. /*
  21366. * Compute coefficients for a cubic polynomial
  21367. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21368. * such that
  21369. * p(0) = x0, p(1) = x1
  21370. * and
  21371. * p'(0) = t0, p'(1) = t1.
  21372. */
  21373. function init( x0, x1, t0, t1 ) {
  21374. c0 = x0;
  21375. c1 = t0;
  21376. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21377. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21378. }
  21379. return {
  21380. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21381. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21382. },
  21383. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21384. // compute tangents when parameterized in [t1,t2]
  21385. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21386. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21387. // rescale tangents for parametrization in [0,1]
  21388. t1 *= dt1;
  21389. t2 *= dt1;
  21390. init( x1, x2, t1, t2 );
  21391. },
  21392. calc: function ( t ) {
  21393. const t2 = t * t;
  21394. const t3 = t2 * t;
  21395. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21396. }
  21397. };
  21398. }
  21399. //
  21400. const tmp = new Vector3();
  21401. const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21402. function CatmullRomCurve3( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  21403. Curve.call( this );
  21404. this.type = 'CatmullRomCurve3';
  21405. this.points = points;
  21406. this.closed = closed;
  21407. this.curveType = curveType;
  21408. this.tension = tension;
  21409. }
  21410. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21411. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21412. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21413. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  21414. const point = optionalTarget;
  21415. const points = this.points;
  21416. const l = points.length;
  21417. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21418. let intPoint = Math.floor( p );
  21419. let weight = p - intPoint;
  21420. if ( this.closed ) {
  21421. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21422. } else if ( weight === 0 && intPoint === l - 1 ) {
  21423. intPoint = l - 2;
  21424. weight = 1;
  21425. }
  21426. let p0, p3; // 4 points (p1 & p2 defined below)
  21427. if ( this.closed || intPoint > 0 ) {
  21428. p0 = points[ ( intPoint - 1 ) % l ];
  21429. } else {
  21430. // extrapolate first point
  21431. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21432. p0 = tmp;
  21433. }
  21434. const p1 = points[ intPoint % l ];
  21435. const p2 = points[ ( intPoint + 1 ) % l ];
  21436. if ( this.closed || intPoint + 2 < l ) {
  21437. p3 = points[ ( intPoint + 2 ) % l ];
  21438. } else {
  21439. // extrapolate last point
  21440. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21441. p3 = tmp;
  21442. }
  21443. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21444. // init Centripetal / Chordal Catmull-Rom
  21445. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21446. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21447. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21448. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21449. // safety check for repeated points
  21450. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21451. if ( dt0 < 1e-4 ) dt0 = dt1;
  21452. if ( dt2 < 1e-4 ) dt2 = dt1;
  21453. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21454. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21455. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21456. } else if ( this.curveType === 'catmullrom' ) {
  21457. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21458. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21459. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21460. }
  21461. point.set(
  21462. px.calc( weight ),
  21463. py.calc( weight ),
  21464. pz.calc( weight )
  21465. );
  21466. return point;
  21467. };
  21468. CatmullRomCurve3.prototype.copy = function ( source ) {
  21469. Curve.prototype.copy.call( this, source );
  21470. this.points = [];
  21471. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  21472. const point = source.points[ i ];
  21473. this.points.push( point.clone() );
  21474. }
  21475. this.closed = source.closed;
  21476. this.curveType = source.curveType;
  21477. this.tension = source.tension;
  21478. return this;
  21479. };
  21480. CatmullRomCurve3.prototype.toJSON = function () {
  21481. const data = Curve.prototype.toJSON.call( this );
  21482. data.points = [];
  21483. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  21484. const point = this.points[ i ];
  21485. data.points.push( point.toArray() );
  21486. }
  21487. data.closed = this.closed;
  21488. data.curveType = this.curveType;
  21489. data.tension = this.tension;
  21490. return data;
  21491. };
  21492. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21493. Curve.prototype.fromJSON.call( this, json );
  21494. this.points = [];
  21495. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  21496. const point = json.points[ i ];
  21497. this.points.push( new Vector3().fromArray( point ) );
  21498. }
  21499. this.closed = json.closed;
  21500. this.curveType = json.curveType;
  21501. this.tension = json.tension;
  21502. return this;
  21503. };
  21504. /**
  21505. * Bezier Curves formulas obtained from
  21506. * http://en.wikipedia.org/wiki/Bézier_curve
  21507. */
  21508. function CatmullRom( t, p0, p1, p2, p3 ) {
  21509. const v0 = ( p2 - p0 ) * 0.5;
  21510. const v1 = ( p3 - p1 ) * 0.5;
  21511. const t2 = t * t;
  21512. const t3 = t * t2;
  21513. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21514. }
  21515. //
  21516. function QuadraticBezierP0( t, p ) {
  21517. const k = 1 - t;
  21518. return k * k * p;
  21519. }
  21520. function QuadraticBezierP1( t, p ) {
  21521. return 2 * ( 1 - t ) * t * p;
  21522. }
  21523. function QuadraticBezierP2( t, p ) {
  21524. return t * t * p;
  21525. }
  21526. function QuadraticBezier( t, p0, p1, p2 ) {
  21527. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21528. QuadraticBezierP2( t, p2 );
  21529. }
  21530. //
  21531. function CubicBezierP0( t, p ) {
  21532. const k = 1 - t;
  21533. return k * k * k * p;
  21534. }
  21535. function CubicBezierP1( t, p ) {
  21536. const k = 1 - t;
  21537. return 3 * k * k * t * p;
  21538. }
  21539. function CubicBezierP2( t, p ) {
  21540. return 3 * ( 1 - t ) * t * t * p;
  21541. }
  21542. function CubicBezierP3( t, p ) {
  21543. return t * t * t * p;
  21544. }
  21545. function CubicBezier( t, p0, p1, p2, p3 ) {
  21546. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21547. CubicBezierP3( t, p3 );
  21548. }
  21549. function CubicBezierCurve( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  21550. Curve.call( this );
  21551. this.type = 'CubicBezierCurve';
  21552. this.v0 = v0;
  21553. this.v1 = v1;
  21554. this.v2 = v2;
  21555. this.v3 = v3;
  21556. }
  21557. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21558. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21559. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21560. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  21561. const point = optionalTarget;
  21562. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21563. point.set(
  21564. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21565. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21566. );
  21567. return point;
  21568. };
  21569. CubicBezierCurve.prototype.copy = function ( source ) {
  21570. Curve.prototype.copy.call( this, source );
  21571. this.v0.copy( source.v0 );
  21572. this.v1.copy( source.v1 );
  21573. this.v2.copy( source.v2 );
  21574. this.v3.copy( source.v3 );
  21575. return this;
  21576. };
  21577. CubicBezierCurve.prototype.toJSON = function () {
  21578. const data = Curve.prototype.toJSON.call( this );
  21579. data.v0 = this.v0.toArray();
  21580. data.v1 = this.v1.toArray();
  21581. data.v2 = this.v2.toArray();
  21582. data.v3 = this.v3.toArray();
  21583. return data;
  21584. };
  21585. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21586. Curve.prototype.fromJSON.call( this, json );
  21587. this.v0.fromArray( json.v0 );
  21588. this.v1.fromArray( json.v1 );
  21589. this.v2.fromArray( json.v2 );
  21590. this.v3.fromArray( json.v3 );
  21591. return this;
  21592. };
  21593. function CubicBezierCurve3( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  21594. Curve.call( this );
  21595. this.type = 'CubicBezierCurve3';
  21596. this.v0 = v0;
  21597. this.v1 = v1;
  21598. this.v2 = v2;
  21599. this.v3 = v3;
  21600. }
  21601. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21602. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21603. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21604. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  21605. const point = optionalTarget;
  21606. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21607. point.set(
  21608. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21609. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21610. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21611. );
  21612. return point;
  21613. };
  21614. CubicBezierCurve3.prototype.copy = function ( source ) {
  21615. Curve.prototype.copy.call( this, source );
  21616. this.v0.copy( source.v0 );
  21617. this.v1.copy( source.v1 );
  21618. this.v2.copy( source.v2 );
  21619. this.v3.copy( source.v3 );
  21620. return this;
  21621. };
  21622. CubicBezierCurve3.prototype.toJSON = function () {
  21623. const data = Curve.prototype.toJSON.call( this );
  21624. data.v0 = this.v0.toArray();
  21625. data.v1 = this.v1.toArray();
  21626. data.v2 = this.v2.toArray();
  21627. data.v3 = this.v3.toArray();
  21628. return data;
  21629. };
  21630. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21631. Curve.prototype.fromJSON.call( this, json );
  21632. this.v0.fromArray( json.v0 );
  21633. this.v1.fromArray( json.v1 );
  21634. this.v2.fromArray( json.v2 );
  21635. this.v3.fromArray( json.v3 );
  21636. return this;
  21637. };
  21638. function LineCurve( v1 = new Vector2(), v2 = new Vector2() ) {
  21639. Curve.call( this );
  21640. this.type = 'LineCurve';
  21641. this.v1 = v1;
  21642. this.v2 = v2;
  21643. }
  21644. LineCurve.prototype = Object.create( Curve.prototype );
  21645. LineCurve.prototype.constructor = LineCurve;
  21646. LineCurve.prototype.isLineCurve = true;
  21647. LineCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  21648. const point = optionalTarget;
  21649. if ( t === 1 ) {
  21650. point.copy( this.v2 );
  21651. } else {
  21652. point.copy( this.v2 ).sub( this.v1 );
  21653. point.multiplyScalar( t ).add( this.v1 );
  21654. }
  21655. return point;
  21656. };
  21657. // Line curve is linear, so we can overwrite default getPointAt
  21658. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21659. return this.getPoint( u, optionalTarget );
  21660. };
  21661. LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
  21662. const tangent = optionalTarget || new Vector2();
  21663. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  21664. return tangent;
  21665. };
  21666. LineCurve.prototype.copy = function ( source ) {
  21667. Curve.prototype.copy.call( this, source );
  21668. this.v1.copy( source.v1 );
  21669. this.v2.copy( source.v2 );
  21670. return this;
  21671. };
  21672. LineCurve.prototype.toJSON = function () {
  21673. const data = Curve.prototype.toJSON.call( this );
  21674. data.v1 = this.v1.toArray();
  21675. data.v2 = this.v2.toArray();
  21676. return data;
  21677. };
  21678. LineCurve.prototype.fromJSON = function ( json ) {
  21679. Curve.prototype.fromJSON.call( this, json );
  21680. this.v1.fromArray( json.v1 );
  21681. this.v2.fromArray( json.v2 );
  21682. return this;
  21683. };
  21684. function LineCurve3( v1 = new Vector3(), v2 = new Vector3() ) {
  21685. Curve.call( this );
  21686. this.type = 'LineCurve3';
  21687. this.v1 = v1;
  21688. this.v2 = v2;
  21689. }
  21690. LineCurve3.prototype = Object.create( Curve.prototype );
  21691. LineCurve3.prototype.constructor = LineCurve3;
  21692. LineCurve3.prototype.isLineCurve3 = true;
  21693. LineCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  21694. const point = optionalTarget;
  21695. if ( t === 1 ) {
  21696. point.copy( this.v2 );
  21697. } else {
  21698. point.copy( this.v2 ).sub( this.v1 );
  21699. point.multiplyScalar( t ).add( this.v1 );
  21700. }
  21701. return point;
  21702. };
  21703. // Line curve is linear, so we can overwrite default getPointAt
  21704. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21705. return this.getPoint( u, optionalTarget );
  21706. };
  21707. LineCurve3.prototype.copy = function ( source ) {
  21708. Curve.prototype.copy.call( this, source );
  21709. this.v1.copy( source.v1 );
  21710. this.v2.copy( source.v2 );
  21711. return this;
  21712. };
  21713. LineCurve3.prototype.toJSON = function () {
  21714. const data = Curve.prototype.toJSON.call( this );
  21715. data.v1 = this.v1.toArray();
  21716. data.v2 = this.v2.toArray();
  21717. return data;
  21718. };
  21719. LineCurve3.prototype.fromJSON = function ( json ) {
  21720. Curve.prototype.fromJSON.call( this, json );
  21721. this.v1.fromArray( json.v1 );
  21722. this.v2.fromArray( json.v2 );
  21723. return this;
  21724. };
  21725. function QuadraticBezierCurve( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  21726. Curve.call( this );
  21727. this.type = 'QuadraticBezierCurve';
  21728. this.v0 = v0;
  21729. this.v1 = v1;
  21730. this.v2 = v2;
  21731. }
  21732. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21733. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21734. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21735. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  21736. const point = optionalTarget;
  21737. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21738. point.set(
  21739. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21740. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21741. );
  21742. return point;
  21743. };
  21744. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21745. Curve.prototype.copy.call( this, source );
  21746. this.v0.copy( source.v0 );
  21747. this.v1.copy( source.v1 );
  21748. this.v2.copy( source.v2 );
  21749. return this;
  21750. };
  21751. QuadraticBezierCurve.prototype.toJSON = function () {
  21752. const data = Curve.prototype.toJSON.call( this );
  21753. data.v0 = this.v0.toArray();
  21754. data.v1 = this.v1.toArray();
  21755. data.v2 = this.v2.toArray();
  21756. return data;
  21757. };
  21758. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21759. Curve.prototype.fromJSON.call( this, json );
  21760. this.v0.fromArray( json.v0 );
  21761. this.v1.fromArray( json.v1 );
  21762. this.v2.fromArray( json.v2 );
  21763. return this;
  21764. };
  21765. function QuadraticBezierCurve3( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  21766. Curve.call( this );
  21767. this.type = 'QuadraticBezierCurve3';
  21768. this.v0 = v0;
  21769. this.v1 = v1;
  21770. this.v2 = v2;
  21771. }
  21772. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21773. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21774. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21775. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  21776. const point = optionalTarget;
  21777. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21778. point.set(
  21779. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21780. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21781. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21782. );
  21783. return point;
  21784. };
  21785. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21786. Curve.prototype.copy.call( this, source );
  21787. this.v0.copy( source.v0 );
  21788. this.v1.copy( source.v1 );
  21789. this.v2.copy( source.v2 );
  21790. return this;
  21791. };
  21792. QuadraticBezierCurve3.prototype.toJSON = function () {
  21793. const data = Curve.prototype.toJSON.call( this );
  21794. data.v0 = this.v0.toArray();
  21795. data.v1 = this.v1.toArray();
  21796. data.v2 = this.v2.toArray();
  21797. return data;
  21798. };
  21799. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21800. Curve.prototype.fromJSON.call( this, json );
  21801. this.v0.fromArray( json.v0 );
  21802. this.v1.fromArray( json.v1 );
  21803. this.v2.fromArray( json.v2 );
  21804. return this;
  21805. };
  21806. function SplineCurve( points = [] ) {
  21807. Curve.call( this );
  21808. this.type = 'SplineCurve';
  21809. this.points = points;
  21810. }
  21811. SplineCurve.prototype = Object.create( Curve.prototype );
  21812. SplineCurve.prototype.constructor = SplineCurve;
  21813. SplineCurve.prototype.isSplineCurve = true;
  21814. SplineCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  21815. const point = optionalTarget;
  21816. const points = this.points;
  21817. const p = ( points.length - 1 ) * t;
  21818. const intPoint = Math.floor( p );
  21819. const weight = p - intPoint;
  21820. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21821. const p1 = points[ intPoint ];
  21822. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21823. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21824. point.set(
  21825. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21826. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21827. );
  21828. return point;
  21829. };
  21830. SplineCurve.prototype.copy = function ( source ) {
  21831. Curve.prototype.copy.call( this, source );
  21832. this.points = [];
  21833. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  21834. const point = source.points[ i ];
  21835. this.points.push( point.clone() );
  21836. }
  21837. return this;
  21838. };
  21839. SplineCurve.prototype.toJSON = function () {
  21840. const data = Curve.prototype.toJSON.call( this );
  21841. data.points = [];
  21842. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  21843. const point = this.points[ i ];
  21844. data.points.push( point.toArray() );
  21845. }
  21846. return data;
  21847. };
  21848. SplineCurve.prototype.fromJSON = function ( json ) {
  21849. Curve.prototype.fromJSON.call( this, json );
  21850. this.points = [];
  21851. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  21852. const point = json.points[ i ];
  21853. this.points.push( new Vector2().fromArray( point ) );
  21854. }
  21855. return this;
  21856. };
  21857. var Curves = /*#__PURE__*/Object.freeze({
  21858. __proto__: null,
  21859. ArcCurve: ArcCurve,
  21860. CatmullRomCurve3: CatmullRomCurve3,
  21861. CubicBezierCurve: CubicBezierCurve,
  21862. CubicBezierCurve3: CubicBezierCurve3,
  21863. EllipseCurve: EllipseCurve,
  21864. LineCurve: LineCurve,
  21865. LineCurve3: LineCurve3,
  21866. QuadraticBezierCurve: QuadraticBezierCurve,
  21867. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21868. SplineCurve: SplineCurve
  21869. });
  21870. /**************************************************************
  21871. * Curved Path - a curve path is simply a array of connected
  21872. * curves, but retains the api of a curve
  21873. **************************************************************/
  21874. function CurvePath() {
  21875. Curve.call( this );
  21876. this.type = 'CurvePath';
  21877. this.curves = [];
  21878. this.autoClose = false; // Automatically closes the path
  21879. }
  21880. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21881. constructor: CurvePath,
  21882. add: function ( curve ) {
  21883. this.curves.push( curve );
  21884. },
  21885. closePath: function () {
  21886. // Add a line curve if start and end of lines are not connected
  21887. const startPoint = this.curves[ 0 ].getPoint( 0 );
  21888. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21889. if ( ! startPoint.equals( endPoint ) ) {
  21890. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21891. }
  21892. },
  21893. // To get accurate point with reference to
  21894. // entire path distance at time t,
  21895. // following has to be done:
  21896. // 1. Length of each sub path have to be known
  21897. // 2. Locate and identify type of curve
  21898. // 3. Get t for the curve
  21899. // 4. Return curve.getPointAt(t')
  21900. getPoint: function ( t ) {
  21901. const d = t * this.getLength();
  21902. const curveLengths = this.getCurveLengths();
  21903. let i = 0;
  21904. // To think about boundaries points.
  21905. while ( i < curveLengths.length ) {
  21906. if ( curveLengths[ i ] >= d ) {
  21907. const diff = curveLengths[ i ] - d;
  21908. const curve = this.curves[ i ];
  21909. const segmentLength = curve.getLength();
  21910. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21911. return curve.getPointAt( u );
  21912. }
  21913. i ++;
  21914. }
  21915. return null;
  21916. // loop where sum != 0, sum > d , sum+1 <d
  21917. },
  21918. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21919. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21920. // getPoint() depends on getLength
  21921. getLength: function () {
  21922. const lens = this.getCurveLengths();
  21923. return lens[ lens.length - 1 ];
  21924. },
  21925. // cacheLengths must be recalculated.
  21926. updateArcLengths: function () {
  21927. this.needsUpdate = true;
  21928. this.cacheLengths = null;
  21929. this.getCurveLengths();
  21930. },
  21931. // Compute lengths and cache them
  21932. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21933. getCurveLengths: function () {
  21934. // We use cache values if curves and cache array are same length
  21935. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21936. return this.cacheLengths;
  21937. }
  21938. // Get length of sub-curve
  21939. // Push sums into cached array
  21940. const lengths = [];
  21941. let sums = 0;
  21942. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  21943. sums += this.curves[ i ].getLength();
  21944. lengths.push( sums );
  21945. }
  21946. this.cacheLengths = lengths;
  21947. return lengths;
  21948. },
  21949. getSpacedPoints: function ( divisions = 40 ) {
  21950. const points = [];
  21951. for ( let i = 0; i <= divisions; i ++ ) {
  21952. points.push( this.getPoint( i / divisions ) );
  21953. }
  21954. if ( this.autoClose ) {
  21955. points.push( points[ 0 ] );
  21956. }
  21957. return points;
  21958. },
  21959. getPoints: function ( divisions = 12 ) {
  21960. const points = [];
  21961. let last;
  21962. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21963. const curve = curves[ i ];
  21964. const resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21965. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21966. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21967. : divisions;
  21968. const pts = curve.getPoints( resolution );
  21969. for ( let j = 0; j < pts.length; j ++ ) {
  21970. const point = pts[ j ];
  21971. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21972. points.push( point );
  21973. last = point;
  21974. }
  21975. }
  21976. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21977. points.push( points[ 0 ] );
  21978. }
  21979. return points;
  21980. },
  21981. copy: function ( source ) {
  21982. Curve.prototype.copy.call( this, source );
  21983. this.curves = [];
  21984. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  21985. const curve = source.curves[ i ];
  21986. this.curves.push( curve.clone() );
  21987. }
  21988. this.autoClose = source.autoClose;
  21989. return this;
  21990. },
  21991. toJSON: function () {
  21992. const data = Curve.prototype.toJSON.call( this );
  21993. data.autoClose = this.autoClose;
  21994. data.curves = [];
  21995. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  21996. const curve = this.curves[ i ];
  21997. data.curves.push( curve.toJSON() );
  21998. }
  21999. return data;
  22000. },
  22001. fromJSON: function ( json ) {
  22002. Curve.prototype.fromJSON.call( this, json );
  22003. this.autoClose = json.autoClose;
  22004. this.curves = [];
  22005. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  22006. const curve = json.curves[ i ];
  22007. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22008. }
  22009. return this;
  22010. }
  22011. } );
  22012. function Path( points ) {
  22013. CurvePath.call( this );
  22014. this.type = 'Path';
  22015. this.currentPoint = new Vector2();
  22016. if ( points ) {
  22017. this.setFromPoints( points );
  22018. }
  22019. }
  22020. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22021. constructor: Path,
  22022. setFromPoints: function ( points ) {
  22023. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22024. for ( let i = 1, l = points.length; i < l; i ++ ) {
  22025. this.lineTo( points[ i ].x, points[ i ].y );
  22026. }
  22027. return this;
  22028. },
  22029. moveTo: function ( x, y ) {
  22030. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22031. return this;
  22032. },
  22033. lineTo: function ( x, y ) {
  22034. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22035. this.curves.push( curve );
  22036. this.currentPoint.set( x, y );
  22037. return this;
  22038. },
  22039. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22040. const curve = new QuadraticBezierCurve(
  22041. this.currentPoint.clone(),
  22042. new Vector2( aCPx, aCPy ),
  22043. new Vector2( aX, aY )
  22044. );
  22045. this.curves.push( curve );
  22046. this.currentPoint.set( aX, aY );
  22047. return this;
  22048. },
  22049. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22050. const curve = new CubicBezierCurve(
  22051. this.currentPoint.clone(),
  22052. new Vector2( aCP1x, aCP1y ),
  22053. new Vector2( aCP2x, aCP2y ),
  22054. new Vector2( aX, aY )
  22055. );
  22056. this.curves.push( curve );
  22057. this.currentPoint.set( aX, aY );
  22058. return this;
  22059. },
  22060. splineThru: function ( pts /*Array of Vector*/ ) {
  22061. const npts = [ this.currentPoint.clone() ].concat( pts );
  22062. const curve = new SplineCurve( npts );
  22063. this.curves.push( curve );
  22064. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22065. return this;
  22066. },
  22067. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22068. const x0 = this.currentPoint.x;
  22069. const y0 = this.currentPoint.y;
  22070. this.absarc( aX + x0, aY + y0, aRadius,
  22071. aStartAngle, aEndAngle, aClockwise );
  22072. return this;
  22073. },
  22074. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22075. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22076. return this;
  22077. },
  22078. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22079. const x0 = this.currentPoint.x;
  22080. const y0 = this.currentPoint.y;
  22081. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22082. return this;
  22083. },
  22084. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22085. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22086. if ( this.curves.length > 0 ) {
  22087. // if a previous curve is present, attempt to join
  22088. const firstPoint = curve.getPoint( 0 );
  22089. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22090. this.lineTo( firstPoint.x, firstPoint.y );
  22091. }
  22092. }
  22093. this.curves.push( curve );
  22094. const lastPoint = curve.getPoint( 1 );
  22095. this.currentPoint.copy( lastPoint );
  22096. return this;
  22097. },
  22098. copy: function ( source ) {
  22099. CurvePath.prototype.copy.call( this, source );
  22100. this.currentPoint.copy( source.currentPoint );
  22101. return this;
  22102. },
  22103. toJSON: function () {
  22104. const data = CurvePath.prototype.toJSON.call( this );
  22105. data.currentPoint = this.currentPoint.toArray();
  22106. return data;
  22107. },
  22108. fromJSON: function ( json ) {
  22109. CurvePath.prototype.fromJSON.call( this, json );
  22110. this.currentPoint.fromArray( json.currentPoint );
  22111. return this;
  22112. }
  22113. } );
  22114. function Shape( points ) {
  22115. Path.call( this, points );
  22116. this.uuid = MathUtils.generateUUID();
  22117. this.type = 'Shape';
  22118. this.holes = [];
  22119. }
  22120. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22121. constructor: Shape,
  22122. getPointsHoles: function ( divisions ) {
  22123. const holesPts = [];
  22124. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  22125. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22126. }
  22127. return holesPts;
  22128. },
  22129. // get points of shape and holes (keypoints based on segments parameter)
  22130. extractPoints: function ( divisions ) {
  22131. return {
  22132. shape: this.getPoints( divisions ),
  22133. holes: this.getPointsHoles( divisions )
  22134. };
  22135. },
  22136. copy: function ( source ) {
  22137. Path.prototype.copy.call( this, source );
  22138. this.holes = [];
  22139. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  22140. const hole = source.holes[ i ];
  22141. this.holes.push( hole.clone() );
  22142. }
  22143. return this;
  22144. },
  22145. toJSON: function () {
  22146. const data = Path.prototype.toJSON.call( this );
  22147. data.uuid = this.uuid;
  22148. data.holes = [];
  22149. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  22150. const hole = this.holes[ i ];
  22151. data.holes.push( hole.toJSON() );
  22152. }
  22153. return data;
  22154. },
  22155. fromJSON: function ( json ) {
  22156. Path.prototype.fromJSON.call( this, json );
  22157. this.uuid = json.uuid;
  22158. this.holes = [];
  22159. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  22160. const hole = json.holes[ i ];
  22161. this.holes.push( new Path().fromJSON( hole ) );
  22162. }
  22163. return this;
  22164. }
  22165. } );
  22166. function Light( color, intensity = 1 ) {
  22167. Object3D.call( this );
  22168. this.type = 'Light';
  22169. this.color = new Color( color );
  22170. this.intensity = intensity;
  22171. }
  22172. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22173. constructor: Light,
  22174. isLight: true,
  22175. copy: function ( source ) {
  22176. Object3D.prototype.copy.call( this, source );
  22177. this.color.copy( source.color );
  22178. this.intensity = source.intensity;
  22179. return this;
  22180. },
  22181. toJSON: function ( meta ) {
  22182. const data = Object3D.prototype.toJSON.call( this, meta );
  22183. data.object.color = this.color.getHex();
  22184. data.object.intensity = this.intensity;
  22185. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22186. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22187. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22188. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22189. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22190. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22191. return data;
  22192. }
  22193. } );
  22194. function HemisphereLight( skyColor, groundColor, intensity ) {
  22195. Light.call( this, skyColor, intensity );
  22196. this.type = 'HemisphereLight';
  22197. this.position.copy( Object3D.DefaultUp );
  22198. this.updateMatrix();
  22199. this.groundColor = new Color( groundColor );
  22200. }
  22201. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22202. constructor: HemisphereLight,
  22203. isHemisphereLight: true,
  22204. copy: function ( source ) {
  22205. Light.prototype.copy.call( this, source );
  22206. this.groundColor.copy( source.groundColor );
  22207. return this;
  22208. }
  22209. } );
  22210. function LightShadow( camera ) {
  22211. this.camera = camera;
  22212. this.bias = 0;
  22213. this.normalBias = 0;
  22214. this.radius = 1;
  22215. this.mapSize = new Vector2( 512, 512 );
  22216. this.map = null;
  22217. this.mapPass = null;
  22218. this.matrix = new Matrix4();
  22219. this.autoUpdate = true;
  22220. this.needsUpdate = false;
  22221. this._frustum = new Frustum();
  22222. this._frameExtents = new Vector2( 1, 1 );
  22223. this._viewportCount = 1;
  22224. this._viewports = [
  22225. new Vector4( 0, 0, 1, 1 )
  22226. ];
  22227. }
  22228. Object.assign( LightShadow.prototype, {
  22229. _projScreenMatrix: new Matrix4(),
  22230. _lightPositionWorld: new Vector3(),
  22231. _lookTarget: new Vector3(),
  22232. getViewportCount: function () {
  22233. return this._viewportCount;
  22234. },
  22235. getFrustum: function () {
  22236. return this._frustum;
  22237. },
  22238. updateMatrices: function ( light ) {
  22239. const shadowCamera = this.camera,
  22240. shadowMatrix = this.matrix,
  22241. projScreenMatrix = this._projScreenMatrix,
  22242. lookTarget = this._lookTarget,
  22243. lightPositionWorld = this._lightPositionWorld;
  22244. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  22245. shadowCamera.position.copy( lightPositionWorld );
  22246. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  22247. shadowCamera.lookAt( lookTarget );
  22248. shadowCamera.updateMatrixWorld();
  22249. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  22250. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  22251. shadowMatrix.set(
  22252. 0.5, 0.0, 0.0, 0.5,
  22253. 0.0, 0.5, 0.0, 0.5,
  22254. 0.0, 0.0, 0.5, 0.5,
  22255. 0.0, 0.0, 0.0, 1.0
  22256. );
  22257. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  22258. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  22259. },
  22260. getViewport: function ( viewportIndex ) {
  22261. return this._viewports[ viewportIndex ];
  22262. },
  22263. getFrameExtents: function () {
  22264. return this._frameExtents;
  22265. },
  22266. copy: function ( source ) {
  22267. this.camera = source.camera.clone();
  22268. this.bias = source.bias;
  22269. this.radius = source.radius;
  22270. this.mapSize.copy( source.mapSize );
  22271. return this;
  22272. },
  22273. clone: function () {
  22274. return new this.constructor().copy( this );
  22275. },
  22276. toJSON: function () {
  22277. const object = {};
  22278. if ( this.bias !== 0 ) object.bias = this.bias;
  22279. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  22280. if ( this.radius !== 1 ) object.radius = this.radius;
  22281. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22282. object.camera = this.camera.toJSON( false ).object;
  22283. delete object.camera.matrix;
  22284. return object;
  22285. }
  22286. } );
  22287. function SpotLightShadow() {
  22288. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22289. this.focus = 1;
  22290. }
  22291. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22292. constructor: SpotLightShadow,
  22293. isSpotLightShadow: true,
  22294. updateMatrices: function ( light ) {
  22295. const camera = this.camera;
  22296. const fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  22297. const aspect = this.mapSize.width / this.mapSize.height;
  22298. const far = light.distance || camera.far;
  22299. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22300. camera.fov = fov;
  22301. camera.aspect = aspect;
  22302. camera.far = far;
  22303. camera.updateProjectionMatrix();
  22304. }
  22305. LightShadow.prototype.updateMatrices.call( this, light );
  22306. }
  22307. } );
  22308. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22309. Light.call( this, color, intensity );
  22310. this.type = 'SpotLight';
  22311. this.position.copy( Object3D.DefaultUp );
  22312. this.updateMatrix();
  22313. this.target = new Object3D();
  22314. Object.defineProperty( this, 'power', {
  22315. get: function () {
  22316. // intensity = power per solid angle.
  22317. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22318. return this.intensity * Math.PI;
  22319. },
  22320. set: function ( power ) {
  22321. // intensity = power per solid angle.
  22322. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22323. this.intensity = power / Math.PI;
  22324. }
  22325. } );
  22326. this.distance = ( distance !== undefined ) ? distance : 0;
  22327. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22328. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22329. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22330. this.shadow = new SpotLightShadow();
  22331. }
  22332. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22333. constructor: SpotLight,
  22334. isSpotLight: true,
  22335. copy: function ( source ) {
  22336. Light.prototype.copy.call( this, source );
  22337. this.distance = source.distance;
  22338. this.angle = source.angle;
  22339. this.penumbra = source.penumbra;
  22340. this.decay = source.decay;
  22341. this.target = source.target.clone();
  22342. this.shadow = source.shadow.clone();
  22343. return this;
  22344. }
  22345. } );
  22346. function PointLightShadow() {
  22347. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22348. this._frameExtents = new Vector2( 4, 2 );
  22349. this._viewportCount = 6;
  22350. this._viewports = [
  22351. // These viewports map a cube-map onto a 2D texture with the
  22352. // following orientation:
  22353. //
  22354. // xzXZ
  22355. // y Y
  22356. //
  22357. // X - Positive x direction
  22358. // x - Negative x direction
  22359. // Y - Positive y direction
  22360. // y - Negative y direction
  22361. // Z - Positive z direction
  22362. // z - Negative z direction
  22363. // positive X
  22364. new Vector4( 2, 1, 1, 1 ),
  22365. // negative X
  22366. new Vector4( 0, 1, 1, 1 ),
  22367. // positive Z
  22368. new Vector4( 3, 1, 1, 1 ),
  22369. // negative Z
  22370. new Vector4( 1, 1, 1, 1 ),
  22371. // positive Y
  22372. new Vector4( 3, 0, 1, 1 ),
  22373. // negative Y
  22374. new Vector4( 1, 0, 1, 1 )
  22375. ];
  22376. this._cubeDirections = [
  22377. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  22378. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  22379. ];
  22380. this._cubeUps = [
  22381. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  22382. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  22383. ];
  22384. }
  22385. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22386. constructor: PointLightShadow,
  22387. isPointLightShadow: true,
  22388. updateMatrices: function ( light, viewportIndex = 0 ) {
  22389. const camera = this.camera,
  22390. shadowMatrix = this.matrix,
  22391. lightPositionWorld = this._lightPositionWorld,
  22392. lookTarget = this._lookTarget,
  22393. projScreenMatrix = this._projScreenMatrix;
  22394. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  22395. camera.position.copy( lightPositionWorld );
  22396. lookTarget.copy( camera.position );
  22397. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  22398. camera.up.copy( this._cubeUps[ viewportIndex ] );
  22399. camera.lookAt( lookTarget );
  22400. camera.updateMatrixWorld();
  22401. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  22402. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  22403. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  22404. }
  22405. } );
  22406. function PointLight( color, intensity, distance, decay ) {
  22407. Light.call( this, color, intensity );
  22408. this.type = 'PointLight';
  22409. Object.defineProperty( this, 'power', {
  22410. get: function () {
  22411. // intensity = power per solid angle.
  22412. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22413. return this.intensity * 4 * Math.PI;
  22414. },
  22415. set: function ( power ) {
  22416. // intensity = power per solid angle.
  22417. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22418. this.intensity = power / ( 4 * Math.PI );
  22419. }
  22420. } );
  22421. this.distance = ( distance !== undefined ) ? distance : 0;
  22422. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22423. this.shadow = new PointLightShadow();
  22424. }
  22425. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22426. constructor: PointLight,
  22427. isPointLight: true,
  22428. copy: function ( source ) {
  22429. Light.prototype.copy.call( this, source );
  22430. this.distance = source.distance;
  22431. this.decay = source.decay;
  22432. this.shadow = source.shadow.clone();
  22433. return this;
  22434. }
  22435. } );
  22436. function OrthographicCamera( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  22437. Camera.call( this );
  22438. this.type = 'OrthographicCamera';
  22439. this.zoom = 1;
  22440. this.view = null;
  22441. this.left = left;
  22442. this.right = right;
  22443. this.top = top;
  22444. this.bottom = bottom;
  22445. this.near = near;
  22446. this.far = far;
  22447. this.updateProjectionMatrix();
  22448. }
  22449. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22450. constructor: OrthographicCamera,
  22451. isOrthographicCamera: true,
  22452. copy: function ( source, recursive ) {
  22453. Camera.prototype.copy.call( this, source, recursive );
  22454. this.left = source.left;
  22455. this.right = source.right;
  22456. this.top = source.top;
  22457. this.bottom = source.bottom;
  22458. this.near = source.near;
  22459. this.far = source.far;
  22460. this.zoom = source.zoom;
  22461. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22462. return this;
  22463. },
  22464. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22465. if ( this.view === null ) {
  22466. this.view = {
  22467. enabled: true,
  22468. fullWidth: 1,
  22469. fullHeight: 1,
  22470. offsetX: 0,
  22471. offsetY: 0,
  22472. width: 1,
  22473. height: 1
  22474. };
  22475. }
  22476. this.view.enabled = true;
  22477. this.view.fullWidth = fullWidth;
  22478. this.view.fullHeight = fullHeight;
  22479. this.view.offsetX = x;
  22480. this.view.offsetY = y;
  22481. this.view.width = width;
  22482. this.view.height = height;
  22483. this.updateProjectionMatrix();
  22484. },
  22485. clearViewOffset: function () {
  22486. if ( this.view !== null ) {
  22487. this.view.enabled = false;
  22488. }
  22489. this.updateProjectionMatrix();
  22490. },
  22491. updateProjectionMatrix: function () {
  22492. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22493. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22494. const cx = ( this.right + this.left ) / 2;
  22495. const cy = ( this.top + this.bottom ) / 2;
  22496. let left = cx - dx;
  22497. let right = cx + dx;
  22498. let top = cy + dy;
  22499. let bottom = cy - dy;
  22500. if ( this.view !== null && this.view.enabled ) {
  22501. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  22502. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  22503. left += scaleW * this.view.offsetX;
  22504. right = left + scaleW * this.view.width;
  22505. top -= scaleH * this.view.offsetY;
  22506. bottom = top - scaleH * this.view.height;
  22507. }
  22508. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22509. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  22510. },
  22511. toJSON: function ( meta ) {
  22512. const data = Object3D.prototype.toJSON.call( this, meta );
  22513. data.object.zoom = this.zoom;
  22514. data.object.left = this.left;
  22515. data.object.right = this.right;
  22516. data.object.top = this.top;
  22517. data.object.bottom = this.bottom;
  22518. data.object.near = this.near;
  22519. data.object.far = this.far;
  22520. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22521. return data;
  22522. }
  22523. } );
  22524. function DirectionalLightShadow() {
  22525. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22526. }
  22527. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22528. constructor: DirectionalLightShadow,
  22529. isDirectionalLightShadow: true,
  22530. updateMatrices: function ( light ) {
  22531. LightShadow.prototype.updateMatrices.call( this, light );
  22532. }
  22533. } );
  22534. function DirectionalLight( color, intensity ) {
  22535. Light.call( this, color, intensity );
  22536. this.type = 'DirectionalLight';
  22537. this.position.copy( Object3D.DefaultUp );
  22538. this.updateMatrix();
  22539. this.target = new Object3D();
  22540. this.shadow = new DirectionalLightShadow();
  22541. }
  22542. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22543. constructor: DirectionalLight,
  22544. isDirectionalLight: true,
  22545. copy: function ( source ) {
  22546. Light.prototype.copy.call( this, source );
  22547. this.target = source.target.clone();
  22548. this.shadow = source.shadow.clone();
  22549. return this;
  22550. }
  22551. } );
  22552. function AmbientLight( color, intensity ) {
  22553. Light.call( this, color, intensity );
  22554. this.type = 'AmbientLight';
  22555. }
  22556. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22557. constructor: AmbientLight,
  22558. isAmbientLight: true
  22559. } );
  22560. function RectAreaLight( color, intensity, width, height ) {
  22561. Light.call( this, color, intensity );
  22562. this.type = 'RectAreaLight';
  22563. this.width = ( width !== undefined ) ? width : 10;
  22564. this.height = ( height !== undefined ) ? height : 10;
  22565. }
  22566. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22567. constructor: RectAreaLight,
  22568. isRectAreaLight: true,
  22569. copy: function ( source ) {
  22570. Light.prototype.copy.call( this, source );
  22571. this.width = source.width;
  22572. this.height = source.height;
  22573. return this;
  22574. },
  22575. toJSON: function ( meta ) {
  22576. const data = Light.prototype.toJSON.call( this, meta );
  22577. data.object.width = this.width;
  22578. data.object.height = this.height;
  22579. return data;
  22580. }
  22581. } );
  22582. /**
  22583. * Primary reference:
  22584. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  22585. *
  22586. * Secondary reference:
  22587. * https://www.ppsloan.org/publications/StupidSH36.pdf
  22588. */
  22589. // 3-band SH defined by 9 coefficients
  22590. class SphericalHarmonics3 {
  22591. constructor() {
  22592. Object.defineProperty( this, 'isSphericalHarmonics3', { value: true } );
  22593. this.coefficients = [];
  22594. for ( let i = 0; i < 9; i ++ ) {
  22595. this.coefficients.push( new Vector3() );
  22596. }
  22597. }
  22598. set( coefficients ) {
  22599. for ( let i = 0; i < 9; i ++ ) {
  22600. this.coefficients[ i ].copy( coefficients[ i ] );
  22601. }
  22602. return this;
  22603. }
  22604. zero() {
  22605. for ( let i = 0; i < 9; i ++ ) {
  22606. this.coefficients[ i ].set( 0, 0, 0 );
  22607. }
  22608. return this;
  22609. }
  22610. // get the radiance in the direction of the normal
  22611. // target is a Vector3
  22612. getAt( normal, target ) {
  22613. // normal is assumed to be unit length
  22614. const x = normal.x, y = normal.y, z = normal.z;
  22615. const coeff = this.coefficients;
  22616. // band 0
  22617. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  22618. // band 1
  22619. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  22620. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  22621. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  22622. // band 2
  22623. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  22624. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  22625. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  22626. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  22627. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  22628. return target;
  22629. }
  22630. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  22631. // target is a Vector3
  22632. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  22633. getIrradianceAt( normal, target ) {
  22634. // normal is assumed to be unit length
  22635. const x = normal.x, y = normal.y, z = normal.z;
  22636. const coeff = this.coefficients;
  22637. // band 0
  22638. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  22639. // band 1
  22640. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  22641. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  22642. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  22643. // band 2
  22644. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  22645. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  22646. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  22647. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  22648. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  22649. return target;
  22650. }
  22651. add( sh ) {
  22652. for ( let i = 0; i < 9; i ++ ) {
  22653. this.coefficients[ i ].add( sh.coefficients[ i ] );
  22654. }
  22655. return this;
  22656. }
  22657. addScaledSH( sh, s ) {
  22658. for ( let i = 0; i < 9; i ++ ) {
  22659. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  22660. }
  22661. return this;
  22662. }
  22663. scale( s ) {
  22664. for ( let i = 0; i < 9; i ++ ) {
  22665. this.coefficients[ i ].multiplyScalar( s );
  22666. }
  22667. return this;
  22668. }
  22669. lerp( sh, alpha ) {
  22670. for ( let i = 0; i < 9; i ++ ) {
  22671. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  22672. }
  22673. return this;
  22674. }
  22675. equals( sh ) {
  22676. for ( let i = 0; i < 9; i ++ ) {
  22677. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  22678. return false;
  22679. }
  22680. }
  22681. return true;
  22682. }
  22683. copy( sh ) {
  22684. return this.set( sh.coefficients );
  22685. }
  22686. clone() {
  22687. return new this.constructor().copy( this );
  22688. }
  22689. fromArray( array, offset = 0 ) {
  22690. const coefficients = this.coefficients;
  22691. for ( let i = 0; i < 9; i ++ ) {
  22692. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  22693. }
  22694. return this;
  22695. }
  22696. toArray( array = [], offset = 0 ) {
  22697. const coefficients = this.coefficients;
  22698. for ( let i = 0; i < 9; i ++ ) {
  22699. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  22700. }
  22701. return array;
  22702. }
  22703. // evaluate the basis functions
  22704. // shBasis is an Array[ 9 ]
  22705. static getBasisAt( normal, shBasis ) {
  22706. // normal is assumed to be unit length
  22707. const x = normal.x, y = normal.y, z = normal.z;
  22708. // band 0
  22709. shBasis[ 0 ] = 0.282095;
  22710. // band 1
  22711. shBasis[ 1 ] = 0.488603 * y;
  22712. shBasis[ 2 ] = 0.488603 * z;
  22713. shBasis[ 3 ] = 0.488603 * x;
  22714. // band 2
  22715. shBasis[ 4 ] = 1.092548 * x * y;
  22716. shBasis[ 5 ] = 1.092548 * y * z;
  22717. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  22718. shBasis[ 7 ] = 1.092548 * x * z;
  22719. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  22720. }
  22721. }
  22722. function LightProbe( sh, intensity ) {
  22723. Light.call( this, undefined, intensity );
  22724. this.type = 'LightProbe';
  22725. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  22726. }
  22727. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  22728. constructor: LightProbe,
  22729. isLightProbe: true,
  22730. copy: function ( source ) {
  22731. Light.prototype.copy.call( this, source );
  22732. this.sh.copy( source.sh );
  22733. return this;
  22734. },
  22735. fromJSON: function ( json ) {
  22736. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  22737. this.sh.fromArray( json.sh );
  22738. return this;
  22739. },
  22740. toJSON: function ( meta ) {
  22741. const data = Light.prototype.toJSON.call( this, meta );
  22742. data.object.sh = this.sh.toArray();
  22743. return data;
  22744. }
  22745. } );
  22746. function MaterialLoader( manager ) {
  22747. Loader.call( this, manager );
  22748. this.textures = {};
  22749. }
  22750. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22751. constructor: MaterialLoader,
  22752. load: function ( url, onLoad, onProgress, onError ) {
  22753. const scope = this;
  22754. const loader = new FileLoader( scope.manager );
  22755. loader.setPath( scope.path );
  22756. loader.setRequestHeader( scope.requestHeader );
  22757. loader.setWithCredentials( scope.withCredentials );
  22758. loader.load( url, function ( text ) {
  22759. try {
  22760. onLoad( scope.parse( JSON.parse( text ) ) );
  22761. } catch ( e ) {
  22762. if ( onError ) {
  22763. onError( e );
  22764. } else {
  22765. console.error( e );
  22766. }
  22767. scope.manager.itemError( url );
  22768. }
  22769. }, onProgress, onError );
  22770. },
  22771. parse: function ( json ) {
  22772. const textures = this.textures;
  22773. function getTexture( name ) {
  22774. if ( textures[ name ] === undefined ) {
  22775. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22776. }
  22777. return textures[ name ];
  22778. }
  22779. const material = new Materials[ json.type ]();
  22780. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22781. if ( json.name !== undefined ) material.name = json.name;
  22782. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  22783. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22784. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22785. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  22786. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22787. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  22788. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22789. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  22790. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  22791. if ( json.fog !== undefined ) material.fog = json.fog;
  22792. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22793. if ( json.blending !== undefined ) material.blending = json.blending;
  22794. if ( json.combine !== undefined ) material.combine = json.combine;
  22795. if ( json.side !== undefined ) material.side = json.side;
  22796. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22797. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22798. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22799. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22800. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22801. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22802. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  22803. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  22804. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  22805. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  22806. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  22807. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  22808. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  22809. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  22810. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22811. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22812. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22813. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22814. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22815. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22816. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22817. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22818. if ( json.scale !== undefined ) material.scale = json.scale;
  22819. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22820. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22821. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22822. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22823. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22824. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22825. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22826. if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents;
  22827. if ( json.visible !== undefined ) material.visible = json.visible;
  22828. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  22829. if ( json.userData !== undefined ) material.userData = json.userData;
  22830. if ( json.vertexColors !== undefined ) {
  22831. if ( typeof json.vertexColors === 'number' ) {
  22832. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  22833. } else {
  22834. material.vertexColors = json.vertexColors;
  22835. }
  22836. }
  22837. // Shader Material
  22838. if ( json.uniforms !== undefined ) {
  22839. for ( const name in json.uniforms ) {
  22840. const uniform = json.uniforms[ name ];
  22841. material.uniforms[ name ] = {};
  22842. switch ( uniform.type ) {
  22843. case 't':
  22844. material.uniforms[ name ].value = getTexture( uniform.value );
  22845. break;
  22846. case 'c':
  22847. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22848. break;
  22849. case 'v2':
  22850. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22851. break;
  22852. case 'v3':
  22853. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22854. break;
  22855. case 'v4':
  22856. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22857. break;
  22858. case 'm3':
  22859. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22860. break;
  22861. case 'm4':
  22862. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22863. break;
  22864. default:
  22865. material.uniforms[ name ].value = uniform.value;
  22866. }
  22867. }
  22868. }
  22869. if ( json.defines !== undefined ) material.defines = json.defines;
  22870. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22871. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22872. if ( json.extensions !== undefined ) {
  22873. for ( const key in json.extensions ) {
  22874. material.extensions[ key ] = json.extensions[ key ];
  22875. }
  22876. }
  22877. // Deprecated
  22878. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22879. // for PointsMaterial
  22880. if ( json.size !== undefined ) material.size = json.size;
  22881. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22882. // maps
  22883. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22884. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22885. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  22886. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22887. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22888. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22889. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22890. if ( json.normalScale !== undefined ) {
  22891. let normalScale = json.normalScale;
  22892. if ( Array.isArray( normalScale ) === false ) {
  22893. // Blender exporter used to export a scalar. See #7459
  22894. normalScale = [ normalScale, normalScale ];
  22895. }
  22896. material.normalScale = new Vector2().fromArray( normalScale );
  22897. }
  22898. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22899. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22900. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22901. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22902. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22903. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22904. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22905. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22906. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22907. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22908. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22909. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22910. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22911. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22912. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22913. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22914. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22915. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  22916. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  22917. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  22918. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  22919. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  22920. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  22921. return material;
  22922. },
  22923. setTextures: function ( value ) {
  22924. this.textures = value;
  22925. return this;
  22926. }
  22927. } );
  22928. const LoaderUtils = {
  22929. decodeText: function ( array ) {
  22930. if ( typeof TextDecoder !== 'undefined' ) {
  22931. return new TextDecoder().decode( array );
  22932. }
  22933. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22934. // throws a "maximum call stack size exceeded" error for large arrays.
  22935. let s = '';
  22936. for ( let i = 0, il = array.length; i < il; i ++ ) {
  22937. // Implicitly assumes little-endian.
  22938. s += String.fromCharCode( array[ i ] );
  22939. }
  22940. try {
  22941. // merges multi-byte utf-8 characters.
  22942. return decodeURIComponent( escape( s ) );
  22943. } catch ( e ) { // see #16358
  22944. return s;
  22945. }
  22946. },
  22947. extractUrlBase: function ( url ) {
  22948. const index = url.lastIndexOf( '/' );
  22949. if ( index === - 1 ) return './';
  22950. return url.substr( 0, index + 1 );
  22951. }
  22952. };
  22953. function InstancedBufferGeometry() {
  22954. BufferGeometry.call( this );
  22955. this.type = 'InstancedBufferGeometry';
  22956. this.instanceCount = Infinity;
  22957. }
  22958. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22959. constructor: InstancedBufferGeometry,
  22960. isInstancedBufferGeometry: true,
  22961. copy: function ( source ) {
  22962. BufferGeometry.prototype.copy.call( this, source );
  22963. this.instanceCount = source.instanceCount;
  22964. return this;
  22965. },
  22966. clone: function () {
  22967. return new this.constructor().copy( this );
  22968. },
  22969. toJSON: function () {
  22970. const data = BufferGeometry.prototype.toJSON.call( this );
  22971. data.instanceCount = this.instanceCount;
  22972. data.isInstancedBufferGeometry = true;
  22973. return data;
  22974. }
  22975. } );
  22976. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  22977. if ( typeof ( normalized ) === 'number' ) {
  22978. meshPerAttribute = normalized;
  22979. normalized = false;
  22980. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  22981. }
  22982. BufferAttribute.call( this, array, itemSize, normalized );
  22983. this.meshPerAttribute = meshPerAttribute || 1;
  22984. }
  22985. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  22986. constructor: InstancedBufferAttribute,
  22987. isInstancedBufferAttribute: true,
  22988. copy: function ( source ) {
  22989. BufferAttribute.prototype.copy.call( this, source );
  22990. this.meshPerAttribute = source.meshPerAttribute;
  22991. return this;
  22992. },
  22993. toJSON: function () {
  22994. const data = BufferAttribute.prototype.toJSON.call( this );
  22995. data.meshPerAttribute = this.meshPerAttribute;
  22996. data.isInstancedBufferAttribute = true;
  22997. return data;
  22998. }
  22999. } );
  23000. function BufferGeometryLoader( manager ) {
  23001. Loader.call( this, manager );
  23002. }
  23003. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23004. constructor: BufferGeometryLoader,
  23005. load: function ( url, onLoad, onProgress, onError ) {
  23006. const scope = this;
  23007. const loader = new FileLoader( scope.manager );
  23008. loader.setPath( scope.path );
  23009. loader.setRequestHeader( scope.requestHeader );
  23010. loader.setWithCredentials( scope.withCredentials );
  23011. loader.load( url, function ( text ) {
  23012. try {
  23013. onLoad( scope.parse( JSON.parse( text ) ) );
  23014. } catch ( e ) {
  23015. if ( onError ) {
  23016. onError( e );
  23017. } else {
  23018. console.error( e );
  23019. }
  23020. scope.manager.itemError( url );
  23021. }
  23022. }, onProgress, onError );
  23023. },
  23024. parse: function ( json ) {
  23025. const interleavedBufferMap = {};
  23026. const arrayBufferMap = {};
  23027. function getInterleavedBuffer( json, uuid ) {
  23028. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  23029. const interleavedBuffers = json.interleavedBuffers;
  23030. const interleavedBuffer = interleavedBuffers[ uuid ];
  23031. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  23032. const array = getTypedArray( interleavedBuffer.type, buffer );
  23033. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  23034. ib.uuid = interleavedBuffer.uuid;
  23035. interleavedBufferMap[ uuid ] = ib;
  23036. return ib;
  23037. }
  23038. function getArrayBuffer( json, uuid ) {
  23039. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  23040. const arrayBuffers = json.arrayBuffers;
  23041. const arrayBuffer = arrayBuffers[ uuid ];
  23042. const ab = new Uint32Array( arrayBuffer ).buffer;
  23043. arrayBufferMap[ uuid ] = ab;
  23044. return ab;
  23045. }
  23046. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23047. const index = json.data.index;
  23048. if ( index !== undefined ) {
  23049. const typedArray = getTypedArray( index.type, index.array );
  23050. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23051. }
  23052. const attributes = json.data.attributes;
  23053. for ( const key in attributes ) {
  23054. const attribute = attributes[ key ];
  23055. let bufferAttribute;
  23056. if ( attribute.isInterleavedBufferAttribute ) {
  23057. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  23058. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  23059. } else {
  23060. const typedArray = getTypedArray( attribute.type, attribute.array );
  23061. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23062. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23063. }
  23064. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23065. geometry.setAttribute( key, bufferAttribute );
  23066. }
  23067. const morphAttributes = json.data.morphAttributes;
  23068. if ( morphAttributes ) {
  23069. for ( const key in morphAttributes ) {
  23070. const attributeArray = morphAttributes[ key ];
  23071. const array = [];
  23072. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  23073. const attribute = attributeArray[ i ];
  23074. let bufferAttribute;
  23075. if ( attribute.isInterleavedBufferAttribute ) {
  23076. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  23077. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  23078. } else {
  23079. const typedArray = getTypedArray( attribute.type, attribute.array );
  23080. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23081. }
  23082. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23083. array.push( bufferAttribute );
  23084. }
  23085. geometry.morphAttributes[ key ] = array;
  23086. }
  23087. }
  23088. const morphTargetsRelative = json.data.morphTargetsRelative;
  23089. if ( morphTargetsRelative ) {
  23090. geometry.morphTargetsRelative = true;
  23091. }
  23092. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23093. if ( groups !== undefined ) {
  23094. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  23095. const group = groups[ i ];
  23096. geometry.addGroup( group.start, group.count, group.materialIndex );
  23097. }
  23098. }
  23099. const boundingSphere = json.data.boundingSphere;
  23100. if ( boundingSphere !== undefined ) {
  23101. const center = new Vector3();
  23102. if ( boundingSphere.center !== undefined ) {
  23103. center.fromArray( boundingSphere.center );
  23104. }
  23105. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23106. }
  23107. if ( json.name ) geometry.name = json.name;
  23108. if ( json.userData ) geometry.userData = json.userData;
  23109. return geometry;
  23110. }
  23111. } );
  23112. class ObjectLoader extends Loader {
  23113. constructor( manager ) {
  23114. super( manager );
  23115. }
  23116. load( url, onLoad, onProgress, onError ) {
  23117. const scope = this;
  23118. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23119. this.resourcePath = this.resourcePath || path;
  23120. const loader = new FileLoader( this.manager );
  23121. loader.setPath( this.path );
  23122. loader.setRequestHeader( this.requestHeader );
  23123. loader.setWithCredentials( this.withCredentials );
  23124. loader.load( url, function ( text ) {
  23125. let json = null;
  23126. try {
  23127. json = JSON.parse( text );
  23128. } catch ( error ) {
  23129. if ( onError !== undefined ) onError( error );
  23130. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23131. return;
  23132. }
  23133. const metadata = json.metadata;
  23134. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23135. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23136. return;
  23137. }
  23138. scope.parse( json, onLoad );
  23139. }, onProgress, onError );
  23140. }
  23141. parse( json, onLoad ) {
  23142. const animations = this.parseAnimations( json.animations );
  23143. const shapes = this.parseShapes( json.shapes );
  23144. const geometries = this.parseGeometries( json.geometries, shapes );
  23145. const images = this.parseImages( json.images, function () {
  23146. if ( onLoad !== undefined ) onLoad( object );
  23147. } );
  23148. const textures = this.parseTextures( json.textures, images );
  23149. const materials = this.parseMaterials( json.materials, textures );
  23150. const object = this.parseObject( json.object, geometries, materials, animations );
  23151. const skeletons = this.parseSkeletons( json.skeletons, object );
  23152. this.bindSkeletons( object, skeletons );
  23153. //
  23154. if ( onLoad !== undefined ) {
  23155. let hasImages = false;
  23156. for ( const uuid in images ) {
  23157. if ( images[ uuid ] instanceof HTMLImageElement ) {
  23158. hasImages = true;
  23159. break;
  23160. }
  23161. }
  23162. if ( hasImages === false ) onLoad( object );
  23163. }
  23164. return object;
  23165. }
  23166. parseShapes( json ) {
  23167. const shapes = {};
  23168. if ( json !== undefined ) {
  23169. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23170. const shape = new Shape().fromJSON( json[ i ] );
  23171. shapes[ shape.uuid ] = shape;
  23172. }
  23173. }
  23174. return shapes;
  23175. }
  23176. parseSkeletons( json, object ) {
  23177. const skeletons = {};
  23178. const bones = {};
  23179. // generate bone lookup table
  23180. object.traverse( function ( child ) {
  23181. if ( child.isBone ) bones[ child.uuid ] = child;
  23182. } );
  23183. // create skeletons
  23184. if ( json !== undefined ) {
  23185. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23186. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  23187. skeletons[ skeleton.uuid ] = skeleton;
  23188. }
  23189. }
  23190. return skeletons;
  23191. }
  23192. parseGeometries( json, shapes ) {
  23193. const geometries = {};
  23194. let geometryShapes;
  23195. if ( json !== undefined ) {
  23196. const bufferGeometryLoader = new BufferGeometryLoader();
  23197. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23198. let geometry;
  23199. const data = json[ i ];
  23200. switch ( data.type ) {
  23201. case 'PlaneGeometry':
  23202. case 'PlaneBufferGeometry':
  23203. geometry = new Geometries[ data.type ](
  23204. data.width,
  23205. data.height,
  23206. data.widthSegments,
  23207. data.heightSegments
  23208. );
  23209. break;
  23210. case 'BoxGeometry':
  23211. case 'BoxBufferGeometry':
  23212. geometry = new Geometries[ data.type ](
  23213. data.width,
  23214. data.height,
  23215. data.depth,
  23216. data.widthSegments,
  23217. data.heightSegments,
  23218. data.depthSegments
  23219. );
  23220. break;
  23221. case 'CircleGeometry':
  23222. case 'CircleBufferGeometry':
  23223. geometry = new Geometries[ data.type ](
  23224. data.radius,
  23225. data.segments,
  23226. data.thetaStart,
  23227. data.thetaLength
  23228. );
  23229. break;
  23230. case 'CylinderGeometry':
  23231. case 'CylinderBufferGeometry':
  23232. geometry = new Geometries[ data.type ](
  23233. data.radiusTop,
  23234. data.radiusBottom,
  23235. data.height,
  23236. data.radialSegments,
  23237. data.heightSegments,
  23238. data.openEnded,
  23239. data.thetaStart,
  23240. data.thetaLength
  23241. );
  23242. break;
  23243. case 'ConeGeometry':
  23244. case 'ConeBufferGeometry':
  23245. geometry = new Geometries[ data.type ](
  23246. data.radius,
  23247. data.height,
  23248. data.radialSegments,
  23249. data.heightSegments,
  23250. data.openEnded,
  23251. data.thetaStart,
  23252. data.thetaLength
  23253. );
  23254. break;
  23255. case 'SphereGeometry':
  23256. case 'SphereBufferGeometry':
  23257. geometry = new Geometries[ data.type ](
  23258. data.radius,
  23259. data.widthSegments,
  23260. data.heightSegments,
  23261. data.phiStart,
  23262. data.phiLength,
  23263. data.thetaStart,
  23264. data.thetaLength
  23265. );
  23266. break;
  23267. case 'DodecahedronGeometry':
  23268. case 'DodecahedronBufferGeometry':
  23269. case 'IcosahedronGeometry':
  23270. case 'IcosahedronBufferGeometry':
  23271. case 'OctahedronGeometry':
  23272. case 'OctahedronBufferGeometry':
  23273. case 'TetrahedronGeometry':
  23274. case 'TetrahedronBufferGeometry':
  23275. geometry = new Geometries[ data.type ](
  23276. data.radius,
  23277. data.detail
  23278. );
  23279. break;
  23280. case 'RingGeometry':
  23281. case 'RingBufferGeometry':
  23282. geometry = new Geometries[ data.type ](
  23283. data.innerRadius,
  23284. data.outerRadius,
  23285. data.thetaSegments,
  23286. data.phiSegments,
  23287. data.thetaStart,
  23288. data.thetaLength
  23289. );
  23290. break;
  23291. case 'TorusGeometry':
  23292. case 'TorusBufferGeometry':
  23293. geometry = new Geometries[ data.type ](
  23294. data.radius,
  23295. data.tube,
  23296. data.radialSegments,
  23297. data.tubularSegments,
  23298. data.arc
  23299. );
  23300. break;
  23301. case 'TorusKnotGeometry':
  23302. case 'TorusKnotBufferGeometry':
  23303. geometry = new Geometries[ data.type ](
  23304. data.radius,
  23305. data.tube,
  23306. data.tubularSegments,
  23307. data.radialSegments,
  23308. data.p,
  23309. data.q
  23310. );
  23311. break;
  23312. case 'TubeGeometry':
  23313. case 'TubeBufferGeometry':
  23314. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23315. // User defined curves or instances of CurvePath will not be deserialized.
  23316. geometry = new Geometries[ data.type ](
  23317. new Curves[ data.path.type ]().fromJSON( data.path ),
  23318. data.tubularSegments,
  23319. data.radius,
  23320. data.radialSegments,
  23321. data.closed
  23322. );
  23323. break;
  23324. case 'LatheGeometry':
  23325. case 'LatheBufferGeometry':
  23326. geometry = new Geometries[ data.type ](
  23327. data.points,
  23328. data.segments,
  23329. data.phiStart,
  23330. data.phiLength
  23331. );
  23332. break;
  23333. case 'PolyhedronGeometry':
  23334. case 'PolyhedronBufferGeometry':
  23335. geometry = new Geometries[ data.type ](
  23336. data.vertices,
  23337. data.indices,
  23338. data.radius,
  23339. data.details
  23340. );
  23341. break;
  23342. case 'ShapeGeometry':
  23343. case 'ShapeBufferGeometry':
  23344. geometryShapes = [];
  23345. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23346. const shape = shapes[ data.shapes[ j ] ];
  23347. geometryShapes.push( shape );
  23348. }
  23349. geometry = new Geometries[ data.type ](
  23350. geometryShapes,
  23351. data.curveSegments
  23352. );
  23353. break;
  23354. case 'ExtrudeGeometry':
  23355. case 'ExtrudeBufferGeometry':
  23356. geometryShapes = [];
  23357. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23358. const shape = shapes[ data.shapes[ j ] ];
  23359. geometryShapes.push( shape );
  23360. }
  23361. const extrudePath = data.options.extrudePath;
  23362. if ( extrudePath !== undefined ) {
  23363. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23364. }
  23365. geometry = new Geometries[ data.type ](
  23366. geometryShapes,
  23367. data.options
  23368. );
  23369. break;
  23370. case 'BufferGeometry':
  23371. case 'InstancedBufferGeometry':
  23372. geometry = bufferGeometryLoader.parse( data );
  23373. break;
  23374. case 'Geometry':
  23375. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  23376. break;
  23377. default:
  23378. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23379. continue;
  23380. }
  23381. geometry.uuid = data.uuid;
  23382. if ( data.name !== undefined ) geometry.name = data.name;
  23383. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23384. geometries[ data.uuid ] = geometry;
  23385. }
  23386. }
  23387. return geometries;
  23388. }
  23389. parseMaterials( json, textures ) {
  23390. const cache = {}; // MultiMaterial
  23391. const materials = {};
  23392. if ( json !== undefined ) {
  23393. const loader = new MaterialLoader();
  23394. loader.setTextures( textures );
  23395. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23396. const data = json[ i ];
  23397. if ( data.type === 'MultiMaterial' ) {
  23398. // Deprecated
  23399. const array = [];
  23400. for ( let j = 0; j < data.materials.length; j ++ ) {
  23401. const material = data.materials[ j ];
  23402. if ( cache[ material.uuid ] === undefined ) {
  23403. cache[ material.uuid ] = loader.parse( material );
  23404. }
  23405. array.push( cache[ material.uuid ] );
  23406. }
  23407. materials[ data.uuid ] = array;
  23408. } else {
  23409. if ( cache[ data.uuid ] === undefined ) {
  23410. cache[ data.uuid ] = loader.parse( data );
  23411. }
  23412. materials[ data.uuid ] = cache[ data.uuid ];
  23413. }
  23414. }
  23415. }
  23416. return materials;
  23417. }
  23418. parseAnimations( json ) {
  23419. const animations = {};
  23420. if ( json !== undefined ) {
  23421. for ( let i = 0; i < json.length; i ++ ) {
  23422. const data = json[ i ];
  23423. const clip = AnimationClip.parse( data );
  23424. animations[ clip.uuid ] = clip;
  23425. }
  23426. }
  23427. return animations;
  23428. }
  23429. parseImages( json, onLoad ) {
  23430. const scope = this;
  23431. const images = {};
  23432. let loader;
  23433. function loadImage( url ) {
  23434. scope.manager.itemStart( url );
  23435. return loader.load( url, function () {
  23436. scope.manager.itemEnd( url );
  23437. }, undefined, function () {
  23438. scope.manager.itemError( url );
  23439. scope.manager.itemEnd( url );
  23440. } );
  23441. }
  23442. function deserializeImage( image ) {
  23443. if ( typeof image === 'string' ) {
  23444. const url = image;
  23445. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  23446. return loadImage( path );
  23447. } else {
  23448. if ( image.data ) {
  23449. return {
  23450. data: getTypedArray( image.type, image.data ),
  23451. width: image.width,
  23452. height: image.height
  23453. };
  23454. } else {
  23455. return null;
  23456. }
  23457. }
  23458. }
  23459. if ( json !== undefined && json.length > 0 ) {
  23460. const manager = new LoadingManager( onLoad );
  23461. loader = new ImageLoader( manager );
  23462. loader.setCrossOrigin( this.crossOrigin );
  23463. for ( let i = 0, il = json.length; i < il; i ++ ) {
  23464. const image = json[ i ];
  23465. const url = image.url;
  23466. if ( Array.isArray( url ) ) {
  23467. // load array of images e.g CubeTexture
  23468. images[ image.uuid ] = [];
  23469. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  23470. const currentUrl = url[ j ];
  23471. const deserializedImage = deserializeImage( currentUrl );
  23472. if ( deserializedImage !== null ) {
  23473. if ( deserializedImage instanceof HTMLImageElement ) {
  23474. images[ image.uuid ].push( deserializedImage );
  23475. } else {
  23476. // special case: handle array of data textures for cube textures
  23477. images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  23478. }
  23479. }
  23480. }
  23481. } else {
  23482. // load single image
  23483. const deserializedImage = deserializeImage( image.url );
  23484. if ( deserializedImage !== null ) {
  23485. images[ image.uuid ] = deserializedImage;
  23486. }
  23487. }
  23488. }
  23489. }
  23490. return images;
  23491. }
  23492. parseTextures( json, images ) {
  23493. function parseConstant( value, type ) {
  23494. if ( typeof value === 'number' ) return value;
  23495. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23496. return type[ value ];
  23497. }
  23498. const textures = {};
  23499. if ( json !== undefined ) {
  23500. for ( let i = 0, l = json.length; i < l; i ++ ) {
  23501. const data = json[ i ];
  23502. if ( data.image === undefined ) {
  23503. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23504. }
  23505. if ( images[ data.image ] === undefined ) {
  23506. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23507. }
  23508. let texture;
  23509. const image = images[ data.image ];
  23510. if ( Array.isArray( image ) ) {
  23511. texture = new CubeTexture( image );
  23512. if ( image.length === 6 ) texture.needsUpdate = true;
  23513. } else {
  23514. if ( image && image.data ) {
  23515. texture = new DataTexture( image.data, image.width, image.height );
  23516. } else {
  23517. texture = new Texture( image );
  23518. }
  23519. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  23520. }
  23521. texture.uuid = data.uuid;
  23522. if ( data.name !== undefined ) texture.name = data.name;
  23523. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23524. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23525. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23526. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23527. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23528. if ( data.wrap !== undefined ) {
  23529. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23530. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23531. }
  23532. if ( data.format !== undefined ) texture.format = data.format;
  23533. if ( data.type !== undefined ) texture.type = data.type;
  23534. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23535. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23536. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23537. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23538. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23539. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23540. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23541. textures[ data.uuid ] = texture;
  23542. }
  23543. }
  23544. return textures;
  23545. }
  23546. parseObject( data, geometries, materials, animations ) {
  23547. let object;
  23548. function getGeometry( name ) {
  23549. if ( geometries[ name ] === undefined ) {
  23550. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23551. }
  23552. return geometries[ name ];
  23553. }
  23554. function getMaterial( name ) {
  23555. if ( name === undefined ) return undefined;
  23556. if ( Array.isArray( name ) ) {
  23557. const array = [];
  23558. for ( let i = 0, l = name.length; i < l; i ++ ) {
  23559. const uuid = name[ i ];
  23560. if ( materials[ uuid ] === undefined ) {
  23561. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23562. }
  23563. array.push( materials[ uuid ] );
  23564. }
  23565. return array;
  23566. }
  23567. if ( materials[ name ] === undefined ) {
  23568. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23569. }
  23570. return materials[ name ];
  23571. }
  23572. let geometry, material;
  23573. switch ( data.type ) {
  23574. case 'Scene':
  23575. object = new Scene();
  23576. if ( data.background !== undefined ) {
  23577. if ( Number.isInteger( data.background ) ) {
  23578. object.background = new Color( data.background );
  23579. }
  23580. }
  23581. if ( data.fog !== undefined ) {
  23582. if ( data.fog.type === 'Fog' ) {
  23583. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23584. } else if ( data.fog.type === 'FogExp2' ) {
  23585. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23586. }
  23587. }
  23588. break;
  23589. case 'PerspectiveCamera':
  23590. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23591. if ( data.focus !== undefined ) object.focus = data.focus;
  23592. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23593. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23594. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23595. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23596. break;
  23597. case 'OrthographicCamera':
  23598. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23599. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23600. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23601. break;
  23602. case 'AmbientLight':
  23603. object = new AmbientLight( data.color, data.intensity );
  23604. break;
  23605. case 'DirectionalLight':
  23606. object = new DirectionalLight( data.color, data.intensity );
  23607. break;
  23608. case 'PointLight':
  23609. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23610. break;
  23611. case 'RectAreaLight':
  23612. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23613. break;
  23614. case 'SpotLight':
  23615. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23616. break;
  23617. case 'HemisphereLight':
  23618. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23619. break;
  23620. case 'LightProbe':
  23621. object = new LightProbe().fromJSON( data );
  23622. break;
  23623. case 'SkinnedMesh':
  23624. geometry = getGeometry( data.geometry );
  23625. material = getMaterial( data.material );
  23626. object = new SkinnedMesh( geometry, material );
  23627. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  23628. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  23629. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  23630. break;
  23631. case 'Mesh':
  23632. geometry = getGeometry( data.geometry );
  23633. material = getMaterial( data.material );
  23634. object = new Mesh( geometry, material );
  23635. break;
  23636. case 'InstancedMesh':
  23637. geometry = getGeometry( data.geometry );
  23638. material = getMaterial( data.material );
  23639. const count = data.count;
  23640. const instanceMatrix = data.instanceMatrix;
  23641. object = new InstancedMesh( geometry, material, count );
  23642. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  23643. break;
  23644. case 'LOD':
  23645. object = new LOD();
  23646. break;
  23647. case 'Line':
  23648. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  23649. break;
  23650. case 'LineLoop':
  23651. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23652. break;
  23653. case 'LineSegments':
  23654. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23655. break;
  23656. case 'PointCloud':
  23657. case 'Points':
  23658. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23659. break;
  23660. case 'Sprite':
  23661. object = new Sprite( getMaterial( data.material ) );
  23662. break;
  23663. case 'Group':
  23664. object = new Group();
  23665. break;
  23666. case 'Bone':
  23667. object = new Bone();
  23668. break;
  23669. default:
  23670. object = new Object3D();
  23671. }
  23672. object.uuid = data.uuid;
  23673. if ( data.name !== undefined ) object.name = data.name;
  23674. if ( data.matrix !== undefined ) {
  23675. object.matrix.fromArray( data.matrix );
  23676. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23677. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23678. } else {
  23679. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23680. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23681. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23682. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23683. }
  23684. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23685. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23686. if ( data.shadow ) {
  23687. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23688. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  23689. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23690. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23691. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23692. }
  23693. if ( data.visible !== undefined ) object.visible = data.visible;
  23694. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23695. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23696. if ( data.userData !== undefined ) object.userData = data.userData;
  23697. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23698. if ( data.children !== undefined ) {
  23699. const children = data.children;
  23700. for ( let i = 0; i < children.length; i ++ ) {
  23701. object.add( this.parseObject( children[ i ], geometries, materials, animations ) );
  23702. }
  23703. }
  23704. if ( data.animations !== undefined ) {
  23705. const objectAnimations = data.animations;
  23706. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  23707. const uuid = objectAnimations[ i ];
  23708. object.animations.push( animations[ uuid ] );
  23709. }
  23710. }
  23711. if ( data.type === 'LOD' ) {
  23712. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  23713. const levels = data.levels;
  23714. for ( let l = 0; l < levels.length; l ++ ) {
  23715. const level = levels[ l ];
  23716. const child = object.getObjectByProperty( 'uuid', level.object );
  23717. if ( child !== undefined ) {
  23718. object.addLevel( child, level.distance );
  23719. }
  23720. }
  23721. }
  23722. return object;
  23723. }
  23724. bindSkeletons( object, skeletons ) {
  23725. if ( Object.keys( skeletons ).length === 0 ) return;
  23726. object.traverse( function ( child ) {
  23727. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  23728. const skeleton = skeletons[ child.skeleton ];
  23729. if ( skeleton === undefined ) {
  23730. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  23731. } else {
  23732. child.bind( skeleton, child.bindMatrix );
  23733. }
  23734. }
  23735. } );
  23736. }
  23737. /* DEPRECATED */
  23738. setTexturePath( value ) {
  23739. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  23740. return this.setResourcePath( value );
  23741. }
  23742. }
  23743. const TEXTURE_MAPPING = {
  23744. UVMapping: UVMapping,
  23745. CubeReflectionMapping: CubeReflectionMapping,
  23746. CubeRefractionMapping: CubeRefractionMapping,
  23747. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23748. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23749. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23750. CubeUVRefractionMapping: CubeUVRefractionMapping
  23751. };
  23752. const TEXTURE_WRAPPING = {
  23753. RepeatWrapping: RepeatWrapping,
  23754. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23755. MirroredRepeatWrapping: MirroredRepeatWrapping
  23756. };
  23757. const TEXTURE_FILTER = {
  23758. NearestFilter: NearestFilter,
  23759. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23760. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23761. LinearFilter: LinearFilter,
  23762. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23763. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23764. };
  23765. function ImageBitmapLoader( manager ) {
  23766. if ( typeof createImageBitmap === 'undefined' ) {
  23767. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23768. }
  23769. if ( typeof fetch === 'undefined' ) {
  23770. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23771. }
  23772. Loader.call( this, manager );
  23773. this.options = { premultiplyAlpha: 'none' };
  23774. }
  23775. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23776. constructor: ImageBitmapLoader,
  23777. isImageBitmapLoader: true,
  23778. setOptions: function setOptions( options ) {
  23779. this.options = options;
  23780. return this;
  23781. },
  23782. load: function ( url, onLoad, onProgress, onError ) {
  23783. if ( url === undefined ) url = '';
  23784. if ( this.path !== undefined ) url = this.path + url;
  23785. url = this.manager.resolveURL( url );
  23786. const scope = this;
  23787. const cached = Cache.get( url );
  23788. if ( cached !== undefined ) {
  23789. scope.manager.itemStart( url );
  23790. setTimeout( function () {
  23791. if ( onLoad ) onLoad( cached );
  23792. scope.manager.itemEnd( url );
  23793. }, 0 );
  23794. return cached;
  23795. }
  23796. const fetchOptions = {};
  23797. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  23798. fetch( url, fetchOptions ).then( function ( res ) {
  23799. return res.blob();
  23800. } ).then( function ( blob ) {
  23801. return createImageBitmap( blob, scope.options );
  23802. } ).then( function ( imageBitmap ) {
  23803. Cache.add( url, imageBitmap );
  23804. if ( onLoad ) onLoad( imageBitmap );
  23805. scope.manager.itemEnd( url );
  23806. } ).catch( function ( e ) {
  23807. if ( onError ) onError( e );
  23808. scope.manager.itemError( url );
  23809. scope.manager.itemEnd( url );
  23810. } );
  23811. scope.manager.itemStart( url );
  23812. }
  23813. } );
  23814. function ShapePath() {
  23815. this.type = 'ShapePath';
  23816. this.color = new Color();
  23817. this.subPaths = [];
  23818. this.currentPath = null;
  23819. }
  23820. Object.assign( ShapePath.prototype, {
  23821. moveTo: function ( x, y ) {
  23822. this.currentPath = new Path();
  23823. this.subPaths.push( this.currentPath );
  23824. this.currentPath.moveTo( x, y );
  23825. return this;
  23826. },
  23827. lineTo: function ( x, y ) {
  23828. this.currentPath.lineTo( x, y );
  23829. return this;
  23830. },
  23831. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23832. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23833. return this;
  23834. },
  23835. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23836. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23837. return this;
  23838. },
  23839. splineThru: function ( pts ) {
  23840. this.currentPath.splineThru( pts );
  23841. return this;
  23842. },
  23843. toShapes: function ( isCCW, noHoles ) {
  23844. function toShapesNoHoles( inSubpaths ) {
  23845. const shapes = [];
  23846. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23847. const tmpPath = inSubpaths[ i ];
  23848. const tmpShape = new Shape();
  23849. tmpShape.curves = tmpPath.curves;
  23850. shapes.push( tmpShape );
  23851. }
  23852. return shapes;
  23853. }
  23854. function isPointInsidePolygon( inPt, inPolygon ) {
  23855. const polyLen = inPolygon.length;
  23856. // inPt on polygon contour => immediate success or
  23857. // toggling of inside/outside at every single! intersection point of an edge
  23858. // with the horizontal line through inPt, left of inPt
  23859. // not counting lowerY endpoints of edges and whole edges on that line
  23860. let inside = false;
  23861. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23862. let edgeLowPt = inPolygon[ p ];
  23863. let edgeHighPt = inPolygon[ q ];
  23864. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  23865. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  23866. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23867. // not parallel
  23868. if ( edgeDy < 0 ) {
  23869. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23870. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23871. }
  23872. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23873. if ( inPt.y === edgeLowPt.y ) {
  23874. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23875. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23876. } else {
  23877. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23878. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23879. if ( perpEdge < 0 ) continue;
  23880. inside = ! inside; // true intersection left of inPt
  23881. }
  23882. } else {
  23883. // parallel or collinear
  23884. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23885. // edge lies on the same horizontal line as inPt
  23886. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23887. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23888. // continue;
  23889. }
  23890. }
  23891. return inside;
  23892. }
  23893. const isClockWise = ShapeUtils.isClockWise;
  23894. const subPaths = this.subPaths;
  23895. if ( subPaths.length === 0 ) return [];
  23896. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23897. let solid, tmpPath, tmpShape;
  23898. const shapes = [];
  23899. if ( subPaths.length === 1 ) {
  23900. tmpPath = subPaths[ 0 ];
  23901. tmpShape = new Shape();
  23902. tmpShape.curves = tmpPath.curves;
  23903. shapes.push( tmpShape );
  23904. return shapes;
  23905. }
  23906. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23907. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23908. // console.log("Holes first", holesFirst);
  23909. const betterShapeHoles = [];
  23910. const newShapes = [];
  23911. let newShapeHoles = [];
  23912. let mainIdx = 0;
  23913. let tmpPoints;
  23914. newShapes[ mainIdx ] = undefined;
  23915. newShapeHoles[ mainIdx ] = [];
  23916. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  23917. tmpPath = subPaths[ i ];
  23918. tmpPoints = tmpPath.getPoints();
  23919. solid = isClockWise( tmpPoints );
  23920. solid = isCCW ? ! solid : solid;
  23921. if ( solid ) {
  23922. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23923. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23924. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23925. if ( holesFirst ) mainIdx ++;
  23926. newShapeHoles[ mainIdx ] = [];
  23927. //console.log('cw', i);
  23928. } else {
  23929. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23930. //console.log('ccw', i);
  23931. }
  23932. }
  23933. // only Holes? -> probably all Shapes with wrong orientation
  23934. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23935. if ( newShapes.length > 1 ) {
  23936. let ambiguous = false;
  23937. const toChange = [];
  23938. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23939. betterShapeHoles[ sIdx ] = [];
  23940. }
  23941. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23942. const sho = newShapeHoles[ sIdx ];
  23943. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23944. const ho = sho[ hIdx ];
  23945. let hole_unassigned = true;
  23946. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23947. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23948. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23949. if ( hole_unassigned ) {
  23950. hole_unassigned = false;
  23951. betterShapeHoles[ s2Idx ].push( ho );
  23952. } else {
  23953. ambiguous = true;
  23954. }
  23955. }
  23956. }
  23957. if ( hole_unassigned ) {
  23958. betterShapeHoles[ sIdx ].push( ho );
  23959. }
  23960. }
  23961. }
  23962. // console.log("ambiguous: ", ambiguous);
  23963. if ( toChange.length > 0 ) {
  23964. // console.log("to change: ", toChange);
  23965. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23966. }
  23967. }
  23968. let tmpHoles;
  23969. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  23970. tmpShape = newShapes[ i ].s;
  23971. shapes.push( tmpShape );
  23972. tmpHoles = newShapeHoles[ i ];
  23973. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23974. tmpShape.holes.push( tmpHoles[ j ].h );
  23975. }
  23976. }
  23977. //console.log("shape", shapes);
  23978. return shapes;
  23979. }
  23980. } );
  23981. class Font {
  23982. constructor( data ) {
  23983. Object.defineProperty( this, 'isFont', { value: true } );
  23984. this.type = 'Font';
  23985. this.data = data;
  23986. }
  23987. generateShapes( text, size = 100 ) {
  23988. const shapes = [];
  23989. const paths = createPaths( text, size, this.data );
  23990. for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
  23991. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23992. }
  23993. return shapes;
  23994. }
  23995. }
  23996. function createPaths( text, size, data ) {
  23997. const chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988
  23998. const scale = size / data.resolution;
  23999. const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  24000. const paths = [];
  24001. let offsetX = 0, offsetY = 0;
  24002. for ( let i = 0; i < chars.length; i ++ ) {
  24003. const char = chars[ i ];
  24004. if ( char === '\n' ) {
  24005. offsetX = 0;
  24006. offsetY -= line_height;
  24007. } else {
  24008. const ret = createPath( char, scale, offsetX, offsetY, data );
  24009. offsetX += ret.offsetX;
  24010. paths.push( ret.path );
  24011. }
  24012. }
  24013. return paths;
  24014. }
  24015. function createPath( char, scale, offsetX, offsetY, data ) {
  24016. const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  24017. if ( ! glyph ) {
  24018. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  24019. return;
  24020. }
  24021. const path = new ShapePath();
  24022. let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24023. if ( glyph.o ) {
  24024. const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  24025. for ( let i = 0, l = outline.length; i < l; ) {
  24026. const action = outline[ i ++ ];
  24027. switch ( action ) {
  24028. case 'm': // moveTo
  24029. x = outline[ i ++ ] * scale + offsetX;
  24030. y = outline[ i ++ ] * scale + offsetY;
  24031. path.moveTo( x, y );
  24032. break;
  24033. case 'l': // lineTo
  24034. x = outline[ i ++ ] * scale + offsetX;
  24035. y = outline[ i ++ ] * scale + offsetY;
  24036. path.lineTo( x, y );
  24037. break;
  24038. case 'q': // quadraticCurveTo
  24039. cpx = outline[ i ++ ] * scale + offsetX;
  24040. cpy = outline[ i ++ ] * scale + offsetY;
  24041. cpx1 = outline[ i ++ ] * scale + offsetX;
  24042. cpy1 = outline[ i ++ ] * scale + offsetY;
  24043. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  24044. break;
  24045. case 'b': // bezierCurveTo
  24046. cpx = outline[ i ++ ] * scale + offsetX;
  24047. cpy = outline[ i ++ ] * scale + offsetY;
  24048. cpx1 = outline[ i ++ ] * scale + offsetX;
  24049. cpy1 = outline[ i ++ ] * scale + offsetY;
  24050. cpx2 = outline[ i ++ ] * scale + offsetX;
  24051. cpy2 = outline[ i ++ ] * scale + offsetY;
  24052. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  24053. break;
  24054. }
  24055. }
  24056. }
  24057. return { offsetX: glyph.ha * scale, path: path };
  24058. }
  24059. function FontLoader( manager ) {
  24060. Loader.call( this, manager );
  24061. }
  24062. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24063. constructor: FontLoader,
  24064. load: function ( url, onLoad, onProgress, onError ) {
  24065. const scope = this;
  24066. const loader = new FileLoader( this.manager );
  24067. loader.setPath( this.path );
  24068. loader.setRequestHeader( this.requestHeader );
  24069. loader.setWithCredentials( scope.withCredentials );
  24070. loader.load( url, function ( text ) {
  24071. let json;
  24072. try {
  24073. json = JSON.parse( text );
  24074. } catch ( e ) {
  24075. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  24076. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24077. }
  24078. const font = scope.parse( json );
  24079. if ( onLoad ) onLoad( font );
  24080. }, onProgress, onError );
  24081. },
  24082. parse: function ( json ) {
  24083. return new Font( json );
  24084. }
  24085. } );
  24086. let _context;
  24087. const AudioContext = {
  24088. getContext: function () {
  24089. if ( _context === undefined ) {
  24090. _context = new ( window.AudioContext || window.webkitAudioContext )();
  24091. }
  24092. return _context;
  24093. },
  24094. setContext: function ( value ) {
  24095. _context = value;
  24096. }
  24097. };
  24098. function AudioLoader( manager ) {
  24099. Loader.call( this, manager );
  24100. }
  24101. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24102. constructor: AudioLoader,
  24103. load: function ( url, onLoad, onProgress, onError ) {
  24104. const scope = this;
  24105. const loader = new FileLoader( scope.manager );
  24106. loader.setResponseType( 'arraybuffer' );
  24107. loader.setPath( scope.path );
  24108. loader.setRequestHeader( scope.requestHeader );
  24109. loader.setWithCredentials( scope.withCredentials );
  24110. loader.load( url, function ( buffer ) {
  24111. try {
  24112. // Create a copy of the buffer. The `decodeAudioData` method
  24113. // detaches the buffer when complete, preventing reuse.
  24114. const bufferCopy = buffer.slice( 0 );
  24115. const context = AudioContext.getContext();
  24116. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24117. onLoad( audioBuffer );
  24118. } );
  24119. } catch ( e ) {
  24120. if ( onError ) {
  24121. onError( e );
  24122. } else {
  24123. console.error( e );
  24124. }
  24125. scope.manager.itemError( url );
  24126. }
  24127. }, onProgress, onError );
  24128. }
  24129. } );
  24130. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24131. LightProbe.call( this, undefined, intensity );
  24132. const color1 = new Color().set( skyColor );
  24133. const color2 = new Color().set( groundColor );
  24134. const sky = new Vector3( color1.r, color1.g, color1.b );
  24135. const ground = new Vector3( color2.r, color2.g, color2.b );
  24136. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24137. const c0 = Math.sqrt( Math.PI );
  24138. const c1 = c0 * Math.sqrt( 0.75 );
  24139. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24140. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24141. }
  24142. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24143. constructor: HemisphereLightProbe,
  24144. isHemisphereLightProbe: true,
  24145. copy: function ( source ) { // modifying colors not currently supported
  24146. LightProbe.prototype.copy.call( this, source );
  24147. return this;
  24148. },
  24149. toJSON: function ( meta ) {
  24150. const data = LightProbe.prototype.toJSON.call( this, meta );
  24151. // data.sh = this.sh.toArray(); // todo
  24152. return data;
  24153. }
  24154. } );
  24155. function AmbientLightProbe( color, intensity ) {
  24156. LightProbe.call( this, undefined, intensity );
  24157. const color1 = new Color().set( color );
  24158. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24159. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24160. }
  24161. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24162. constructor: AmbientLightProbe,
  24163. isAmbientLightProbe: true,
  24164. copy: function ( source ) { // modifying color not currently supported
  24165. LightProbe.prototype.copy.call( this, source );
  24166. return this;
  24167. },
  24168. toJSON: function ( meta ) {
  24169. const data = LightProbe.prototype.toJSON.call( this, meta );
  24170. // data.sh = this.sh.toArray(); // todo
  24171. return data;
  24172. }
  24173. } );
  24174. const _eyeRight = new Matrix4();
  24175. const _eyeLeft = new Matrix4();
  24176. function StereoCamera() {
  24177. this.type = 'StereoCamera';
  24178. this.aspect = 1;
  24179. this.eyeSep = 0.064;
  24180. this.cameraL = new PerspectiveCamera();
  24181. this.cameraL.layers.enable( 1 );
  24182. this.cameraL.matrixAutoUpdate = false;
  24183. this.cameraR = new PerspectiveCamera();
  24184. this.cameraR.layers.enable( 2 );
  24185. this.cameraR.matrixAutoUpdate = false;
  24186. this._cache = {
  24187. focus: null,
  24188. fov: null,
  24189. aspect: null,
  24190. near: null,
  24191. far: null,
  24192. zoom: null,
  24193. eyeSep: null
  24194. };
  24195. }
  24196. Object.assign( StereoCamera.prototype, {
  24197. update: function ( camera ) {
  24198. const cache = this._cache;
  24199. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  24200. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  24201. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  24202. if ( needsUpdate ) {
  24203. cache.focus = camera.focus;
  24204. cache.fov = camera.fov;
  24205. cache.aspect = camera.aspect * this.aspect;
  24206. cache.near = camera.near;
  24207. cache.far = camera.far;
  24208. cache.zoom = camera.zoom;
  24209. cache.eyeSep = this.eyeSep;
  24210. // Off-axis stereoscopic effect based on
  24211. // http://paulbourke.net/stereographics/stereorender/
  24212. const projectionMatrix = camera.projectionMatrix.clone();
  24213. const eyeSepHalf = cache.eyeSep / 2;
  24214. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  24215. const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  24216. let xmin, xmax;
  24217. // translate xOffset
  24218. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  24219. _eyeRight.elements[ 12 ] = eyeSepHalf;
  24220. // for left eye
  24221. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  24222. xmax = ymax * cache.aspect + eyeSepOnProjection;
  24223. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24224. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24225. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24226. // for right eye
  24227. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  24228. xmax = ymax * cache.aspect - eyeSepOnProjection;
  24229. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  24230. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24231. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24232. }
  24233. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  24234. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  24235. }
  24236. } );
  24237. class Clock {
  24238. constructor( autoStart ) {
  24239. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24240. this.startTime = 0;
  24241. this.oldTime = 0;
  24242. this.elapsedTime = 0;
  24243. this.running = false;
  24244. }
  24245. start() {
  24246. this.startTime = now();
  24247. this.oldTime = this.startTime;
  24248. this.elapsedTime = 0;
  24249. this.running = true;
  24250. }
  24251. stop() {
  24252. this.getElapsedTime();
  24253. this.running = false;
  24254. this.autoStart = false;
  24255. }
  24256. getElapsedTime() {
  24257. this.getDelta();
  24258. return this.elapsedTime;
  24259. }
  24260. getDelta() {
  24261. let diff = 0;
  24262. if ( this.autoStart && ! this.running ) {
  24263. this.start();
  24264. return 0;
  24265. }
  24266. if ( this.running ) {
  24267. const newTime = now();
  24268. diff = ( newTime - this.oldTime ) / 1000;
  24269. this.oldTime = newTime;
  24270. this.elapsedTime += diff;
  24271. }
  24272. return diff;
  24273. }
  24274. }
  24275. function now() {
  24276. return ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24277. }
  24278. const _position$2 = /*@__PURE__*/ new Vector3();
  24279. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  24280. const _scale$1 = /*@__PURE__*/ new Vector3();
  24281. const _orientation = /*@__PURE__*/ new Vector3();
  24282. class AudioListener extends Object3D {
  24283. constructor() {
  24284. super();
  24285. this.type = 'AudioListener';
  24286. this.context = AudioContext.getContext();
  24287. this.gain = this.context.createGain();
  24288. this.gain.connect( this.context.destination );
  24289. this.filter = null;
  24290. this.timeDelta = 0;
  24291. // private
  24292. this._clock = new Clock();
  24293. }
  24294. getInput() {
  24295. return this.gain;
  24296. }
  24297. removeFilter() {
  24298. if ( this.filter !== null ) {
  24299. this.gain.disconnect( this.filter );
  24300. this.filter.disconnect( this.context.destination );
  24301. this.gain.connect( this.context.destination );
  24302. this.filter = null;
  24303. }
  24304. return this;
  24305. }
  24306. getFilter() {
  24307. return this.filter;
  24308. }
  24309. setFilter( value ) {
  24310. if ( this.filter !== null ) {
  24311. this.gain.disconnect( this.filter );
  24312. this.filter.disconnect( this.context.destination );
  24313. } else {
  24314. this.gain.disconnect( this.context.destination );
  24315. }
  24316. this.filter = value;
  24317. this.gain.connect( this.filter );
  24318. this.filter.connect( this.context.destination );
  24319. return this;
  24320. }
  24321. getMasterVolume() {
  24322. return this.gain.gain.value;
  24323. }
  24324. setMasterVolume( value ) {
  24325. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24326. return this;
  24327. }
  24328. updateMatrixWorld( force ) {
  24329. super.updateMatrixWorld( force );
  24330. const listener = this.context.listener;
  24331. const up = this.up;
  24332. this.timeDelta = this._clock.getDelta();
  24333. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  24334. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  24335. if ( listener.positionX ) {
  24336. // code path for Chrome (see #14393)
  24337. const endTime = this.context.currentTime + this.timeDelta;
  24338. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  24339. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  24340. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  24341. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  24342. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  24343. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  24344. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24345. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24346. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24347. } else {
  24348. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  24349. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  24350. }
  24351. }
  24352. }
  24353. class Audio extends Object3D {
  24354. constructor( listener ) {
  24355. super();
  24356. this.type = 'Audio';
  24357. this.listener = listener;
  24358. this.context = listener.context;
  24359. this.gain = this.context.createGain();
  24360. this.gain.connect( listener.getInput() );
  24361. this.autoplay = false;
  24362. this.buffer = null;
  24363. this.detune = 0;
  24364. this.loop = false;
  24365. this.loopStart = 0;
  24366. this.loopEnd = 0;
  24367. this.offset = 0;
  24368. this.duration = undefined;
  24369. this.playbackRate = 1;
  24370. this.isPlaying = false;
  24371. this.hasPlaybackControl = true;
  24372. this.source = null;
  24373. this.sourceType = 'empty';
  24374. this._startedAt = 0;
  24375. this._progress = 0;
  24376. this._connected = false;
  24377. this.filters = [];
  24378. }
  24379. getOutput() {
  24380. return this.gain;
  24381. }
  24382. setNodeSource( audioNode ) {
  24383. this.hasPlaybackControl = false;
  24384. this.sourceType = 'audioNode';
  24385. this.source = audioNode;
  24386. this.connect();
  24387. return this;
  24388. }
  24389. setMediaElementSource( mediaElement ) {
  24390. this.hasPlaybackControl = false;
  24391. this.sourceType = 'mediaNode';
  24392. this.source = this.context.createMediaElementSource( mediaElement );
  24393. this.connect();
  24394. return this;
  24395. }
  24396. setMediaStreamSource( mediaStream ) {
  24397. this.hasPlaybackControl = false;
  24398. this.sourceType = 'mediaStreamNode';
  24399. this.source = this.context.createMediaStreamSource( mediaStream );
  24400. this.connect();
  24401. return this;
  24402. }
  24403. setBuffer( audioBuffer ) {
  24404. this.buffer = audioBuffer;
  24405. this.sourceType = 'buffer';
  24406. if ( this.autoplay ) this.play();
  24407. return this;
  24408. }
  24409. play( delay = 0 ) {
  24410. if ( this.isPlaying === true ) {
  24411. console.warn( 'THREE.Audio: Audio is already playing.' );
  24412. return;
  24413. }
  24414. if ( this.hasPlaybackControl === false ) {
  24415. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24416. return;
  24417. }
  24418. this._startedAt = this.context.currentTime + delay;
  24419. const source = this.context.createBufferSource();
  24420. source.buffer = this.buffer;
  24421. source.loop = this.loop;
  24422. source.loopStart = this.loopStart;
  24423. source.loopEnd = this.loopEnd;
  24424. source.onended = this.onEnded.bind( this );
  24425. source.start( this._startedAt, this._progress + this.offset, this.duration );
  24426. this.isPlaying = true;
  24427. this.source = source;
  24428. this.setDetune( this.detune );
  24429. this.setPlaybackRate( this.playbackRate );
  24430. return this.connect();
  24431. }
  24432. pause() {
  24433. if ( this.hasPlaybackControl === false ) {
  24434. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24435. return;
  24436. }
  24437. if ( this.isPlaying === true ) {
  24438. // update current progress
  24439. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  24440. if ( this.loop === true ) {
  24441. // ensure _progress does not exceed duration with looped audios
  24442. this._progress = this._progress % ( this.duration || this.buffer.duration );
  24443. }
  24444. this.source.stop();
  24445. this.source.onended = null;
  24446. this.isPlaying = false;
  24447. }
  24448. return this;
  24449. }
  24450. stop() {
  24451. if ( this.hasPlaybackControl === false ) {
  24452. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24453. return;
  24454. }
  24455. this._progress = 0;
  24456. this.source.stop();
  24457. this.source.onended = null;
  24458. this.isPlaying = false;
  24459. return this;
  24460. }
  24461. connect() {
  24462. if ( this.filters.length > 0 ) {
  24463. this.source.connect( this.filters[ 0 ] );
  24464. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  24465. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24466. }
  24467. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24468. } else {
  24469. this.source.connect( this.getOutput() );
  24470. }
  24471. this._connected = true;
  24472. return this;
  24473. }
  24474. disconnect() {
  24475. if ( this.filters.length > 0 ) {
  24476. this.source.disconnect( this.filters[ 0 ] );
  24477. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  24478. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24479. }
  24480. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24481. } else {
  24482. this.source.disconnect( this.getOutput() );
  24483. }
  24484. this._connected = false;
  24485. return this;
  24486. }
  24487. getFilters() {
  24488. return this.filters;
  24489. }
  24490. setFilters( value ) {
  24491. if ( ! value ) value = [];
  24492. if ( this._connected === true ) {
  24493. this.disconnect();
  24494. this.filters = value.slice();
  24495. this.connect();
  24496. } else {
  24497. this.filters = value.slice();
  24498. }
  24499. return this;
  24500. }
  24501. setDetune( value ) {
  24502. this.detune = value;
  24503. if ( this.source.detune === undefined ) return; // only set detune when available
  24504. if ( this.isPlaying === true ) {
  24505. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24506. }
  24507. return this;
  24508. }
  24509. getDetune() {
  24510. return this.detune;
  24511. }
  24512. getFilter() {
  24513. return this.getFilters()[ 0 ];
  24514. }
  24515. setFilter( filter ) {
  24516. return this.setFilters( filter ? [ filter ] : [] );
  24517. }
  24518. setPlaybackRate( value ) {
  24519. if ( this.hasPlaybackControl === false ) {
  24520. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24521. return;
  24522. }
  24523. this.playbackRate = value;
  24524. if ( this.isPlaying === true ) {
  24525. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24526. }
  24527. return this;
  24528. }
  24529. getPlaybackRate() {
  24530. return this.playbackRate;
  24531. }
  24532. onEnded() {
  24533. this.isPlaying = false;
  24534. }
  24535. getLoop() {
  24536. if ( this.hasPlaybackControl === false ) {
  24537. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24538. return false;
  24539. }
  24540. return this.loop;
  24541. }
  24542. setLoop( value ) {
  24543. if ( this.hasPlaybackControl === false ) {
  24544. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24545. return;
  24546. }
  24547. this.loop = value;
  24548. if ( this.isPlaying === true ) {
  24549. this.source.loop = this.loop;
  24550. }
  24551. return this;
  24552. }
  24553. setLoopStart( value ) {
  24554. this.loopStart = value;
  24555. return this;
  24556. }
  24557. setLoopEnd( value ) {
  24558. this.loopEnd = value;
  24559. return this;
  24560. }
  24561. getVolume() {
  24562. return this.gain.gain.value;
  24563. }
  24564. setVolume( value ) {
  24565. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24566. return this;
  24567. }
  24568. }
  24569. const _position$3 = /*@__PURE__*/ new Vector3();
  24570. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  24571. const _scale$2 = /*@__PURE__*/ new Vector3();
  24572. const _orientation$1 = /*@__PURE__*/ new Vector3();
  24573. class PositionalAudio extends Audio {
  24574. constructor( listener ) {
  24575. super( listener );
  24576. this.panner = this.context.createPanner();
  24577. this.panner.panningModel = 'HRTF';
  24578. this.panner.connect( this.gain );
  24579. }
  24580. getOutput() {
  24581. return this.panner;
  24582. }
  24583. getRefDistance() {
  24584. return this.panner.refDistance;
  24585. }
  24586. setRefDistance( value ) {
  24587. this.panner.refDistance = value;
  24588. return this;
  24589. }
  24590. getRolloffFactor() {
  24591. return this.panner.rolloffFactor;
  24592. }
  24593. setRolloffFactor( value ) {
  24594. this.panner.rolloffFactor = value;
  24595. return this;
  24596. }
  24597. getDistanceModel() {
  24598. return this.panner.distanceModel;
  24599. }
  24600. setDistanceModel( value ) {
  24601. this.panner.distanceModel = value;
  24602. return this;
  24603. }
  24604. getMaxDistance() {
  24605. return this.panner.maxDistance;
  24606. }
  24607. setMaxDistance( value ) {
  24608. this.panner.maxDistance = value;
  24609. return this;
  24610. }
  24611. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24612. this.panner.coneInnerAngle = coneInnerAngle;
  24613. this.panner.coneOuterAngle = coneOuterAngle;
  24614. this.panner.coneOuterGain = coneOuterGain;
  24615. return this;
  24616. }
  24617. updateMatrixWorld( force ) {
  24618. super.updateMatrixWorld( force );
  24619. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24620. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  24621. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  24622. const panner = this.panner;
  24623. if ( panner.positionX ) {
  24624. // code path for Chrome and Firefox (see #14393)
  24625. const endTime = this.context.currentTime + this.listener.timeDelta;
  24626. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  24627. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  24628. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  24629. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  24630. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  24631. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  24632. } else {
  24633. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  24634. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  24635. }
  24636. }
  24637. }
  24638. class AudioAnalyser {
  24639. constructor( audio, fftSize = 2048 ) {
  24640. this.analyser = audio.context.createAnalyser();
  24641. this.analyser.fftSize = fftSize;
  24642. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24643. audio.getOutput().connect( this.analyser );
  24644. }
  24645. getFrequencyData() {
  24646. this.analyser.getByteFrequencyData( this.data );
  24647. return this.data;
  24648. }
  24649. getAverageFrequency() {
  24650. let value = 0;
  24651. const data = this.getFrequencyData();
  24652. for ( let i = 0; i < data.length; i ++ ) {
  24653. value += data[ i ];
  24654. }
  24655. return value / data.length;
  24656. }
  24657. }
  24658. function PropertyMixer( binding, typeName, valueSize ) {
  24659. this.binding = binding;
  24660. this.valueSize = valueSize;
  24661. let mixFunction,
  24662. mixFunctionAdditive,
  24663. setIdentity;
  24664. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  24665. //
  24666. // interpolators can use .buffer as their .result
  24667. // the data then goes to 'incoming'
  24668. //
  24669. // 'accu0' and 'accu1' are used frame-interleaved for
  24670. // the cumulative result and are compared to detect
  24671. // changes
  24672. //
  24673. // 'orig' stores the original state of the property
  24674. //
  24675. // 'add' is used for additive cumulative results
  24676. //
  24677. // 'work' is optional and is only present for quaternion types. It is used
  24678. // to store intermediate quaternion multiplication results
  24679. switch ( typeName ) {
  24680. case 'quaternion':
  24681. mixFunction = this._slerp;
  24682. mixFunctionAdditive = this._slerpAdditive;
  24683. setIdentity = this._setAdditiveIdentityQuaternion;
  24684. this.buffer = new Float64Array( valueSize * 6 );
  24685. this._workIndex = 5;
  24686. break;
  24687. case 'string':
  24688. case 'bool':
  24689. mixFunction = this._select;
  24690. // Use the regular mix function and for additive on these types,
  24691. // additive is not relevant for non-numeric types
  24692. mixFunctionAdditive = this._select;
  24693. setIdentity = this._setAdditiveIdentityOther;
  24694. this.buffer = new Array( valueSize * 5 );
  24695. break;
  24696. default:
  24697. mixFunction = this._lerp;
  24698. mixFunctionAdditive = this._lerpAdditive;
  24699. setIdentity = this._setAdditiveIdentityNumeric;
  24700. this.buffer = new Float64Array( valueSize * 5 );
  24701. }
  24702. this._mixBufferRegion = mixFunction;
  24703. this._mixBufferRegionAdditive = mixFunctionAdditive;
  24704. this._setIdentity = setIdentity;
  24705. this._origIndex = 3;
  24706. this._addIndex = 4;
  24707. this.cumulativeWeight = 0;
  24708. this.cumulativeWeightAdditive = 0;
  24709. this.useCount = 0;
  24710. this.referenceCount = 0;
  24711. }
  24712. Object.assign( PropertyMixer.prototype, {
  24713. // accumulate data in the 'incoming' region into 'accu<i>'
  24714. accumulate: function ( accuIndex, weight ) {
  24715. // note: happily accumulating nothing when weight = 0, the caller knows
  24716. // the weight and shouldn't have made the call in the first place
  24717. const buffer = this.buffer,
  24718. stride = this.valueSize,
  24719. offset = accuIndex * stride + stride;
  24720. let currentWeight = this.cumulativeWeight;
  24721. if ( currentWeight === 0 ) {
  24722. // accuN := incoming * weight
  24723. for ( let i = 0; i !== stride; ++ i ) {
  24724. buffer[ offset + i ] = buffer[ i ];
  24725. }
  24726. currentWeight = weight;
  24727. } else {
  24728. // accuN := accuN + incoming * weight
  24729. currentWeight += weight;
  24730. const mix = weight / currentWeight;
  24731. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24732. }
  24733. this.cumulativeWeight = currentWeight;
  24734. },
  24735. // accumulate data in the 'incoming' region into 'add'
  24736. accumulateAdditive: function ( weight ) {
  24737. const buffer = this.buffer,
  24738. stride = this.valueSize,
  24739. offset = stride * this._addIndex;
  24740. if ( this.cumulativeWeightAdditive === 0 ) {
  24741. // add = identity
  24742. this._setIdentity();
  24743. }
  24744. // add := add + incoming * weight
  24745. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  24746. this.cumulativeWeightAdditive += weight;
  24747. },
  24748. // apply the state of 'accu<i>' to the binding when accus differ
  24749. apply: function ( accuIndex ) {
  24750. const stride = this.valueSize,
  24751. buffer = this.buffer,
  24752. offset = accuIndex * stride + stride,
  24753. weight = this.cumulativeWeight,
  24754. weightAdditive = this.cumulativeWeightAdditive,
  24755. binding = this.binding;
  24756. this.cumulativeWeight = 0;
  24757. this.cumulativeWeightAdditive = 0;
  24758. if ( weight < 1 ) {
  24759. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24760. const originalValueOffset = stride * this._origIndex;
  24761. this._mixBufferRegion(
  24762. buffer, offset, originalValueOffset, 1 - weight, stride );
  24763. }
  24764. if ( weightAdditive > 0 ) {
  24765. // accuN := accuN + additive accuN
  24766. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  24767. }
  24768. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  24769. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24770. // value has changed -> update scene graph
  24771. binding.setValue( buffer, offset );
  24772. break;
  24773. }
  24774. }
  24775. },
  24776. // remember the state of the bound property and copy it to both accus
  24777. saveOriginalState: function () {
  24778. const binding = this.binding;
  24779. const buffer = this.buffer,
  24780. stride = this.valueSize,
  24781. originalValueOffset = stride * this._origIndex;
  24782. binding.getValue( buffer, originalValueOffset );
  24783. // accu[0..1] := orig -- initially detect changes against the original
  24784. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24785. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24786. }
  24787. // Add to identity for additive
  24788. this._setIdentity();
  24789. this.cumulativeWeight = 0;
  24790. this.cumulativeWeightAdditive = 0;
  24791. },
  24792. // apply the state previously taken via 'saveOriginalState' to the binding
  24793. restoreOriginalState: function () {
  24794. const originalValueOffset = this.valueSize * 3;
  24795. this.binding.setValue( this.buffer, originalValueOffset );
  24796. },
  24797. _setAdditiveIdentityNumeric: function () {
  24798. const startIndex = this._addIndex * this.valueSize;
  24799. const endIndex = startIndex + this.valueSize;
  24800. for ( let i = startIndex; i < endIndex; i ++ ) {
  24801. this.buffer[ i ] = 0;
  24802. }
  24803. },
  24804. _setAdditiveIdentityQuaternion: function () {
  24805. this._setAdditiveIdentityNumeric();
  24806. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  24807. },
  24808. _setAdditiveIdentityOther: function () {
  24809. const startIndex = this._origIndex * this.valueSize;
  24810. const targetIndex = this._addIndex * this.valueSize;
  24811. for ( let i = 0; i < this.valueSize; i ++ ) {
  24812. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  24813. }
  24814. },
  24815. // mix functions
  24816. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24817. if ( t >= 0.5 ) {
  24818. for ( let i = 0; i !== stride; ++ i ) {
  24819. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24820. }
  24821. }
  24822. },
  24823. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24824. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24825. },
  24826. _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24827. const workOffset = this._workIndex * stride;
  24828. // Store result in intermediate buffer offset
  24829. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  24830. // Slerp to the intermediate result
  24831. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  24832. },
  24833. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24834. const s = 1 - t;
  24835. for ( let i = 0; i !== stride; ++ i ) {
  24836. const j = dstOffset + i;
  24837. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24838. }
  24839. },
  24840. _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24841. for ( let i = 0; i !== stride; ++ i ) {
  24842. const j = dstOffset + i;
  24843. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  24844. }
  24845. }
  24846. } );
  24847. // Characters [].:/ are reserved for track binding syntax.
  24848. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24849. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  24850. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24851. // only latin characters, and the unicode \p{L} is not yet supported. So
  24852. // instead, we exclude reserved characters and match everything else.
  24853. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  24854. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24855. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24856. // be matched to parse the rest of the track name.
  24857. const _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  24858. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24859. const _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  24860. // Object on target node, and accessor. May not contain reserved
  24861. // characters. Accessor may contain any character except closing bracket.
  24862. const _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  24863. // Property and accessor. May not contain reserved characters. Accessor may
  24864. // contain any non-bracket characters.
  24865. const _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  24866. const _trackRe = new RegExp( ''
  24867. + '^'
  24868. + _directoryRe
  24869. + _nodeRe
  24870. + _objectRe
  24871. + _propertyRe
  24872. + '$'
  24873. );
  24874. const _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24875. function Composite( targetGroup, path, optionalParsedPath ) {
  24876. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24877. this._targetGroup = targetGroup;
  24878. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24879. }
  24880. Object.assign( Composite.prototype, {
  24881. getValue: function ( array, offset ) {
  24882. this.bind(); // bind all binding
  24883. const firstValidIndex = this._targetGroup.nCachedObjects_,
  24884. binding = this._bindings[ firstValidIndex ];
  24885. // and only call .getValue on the first
  24886. if ( binding !== undefined ) binding.getValue( array, offset );
  24887. },
  24888. setValue: function ( array, offset ) {
  24889. const bindings = this._bindings;
  24890. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24891. bindings[ i ].setValue( array, offset );
  24892. }
  24893. },
  24894. bind: function () {
  24895. const bindings = this._bindings;
  24896. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24897. bindings[ i ].bind();
  24898. }
  24899. },
  24900. unbind: function () {
  24901. const bindings = this._bindings;
  24902. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24903. bindings[ i ].unbind();
  24904. }
  24905. }
  24906. } );
  24907. function PropertyBinding( rootNode, path, parsedPath ) {
  24908. this.path = path;
  24909. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24910. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24911. this.rootNode = rootNode;
  24912. }
  24913. Object.assign( PropertyBinding, {
  24914. Composite: Composite,
  24915. create: function ( root, path, parsedPath ) {
  24916. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24917. return new PropertyBinding( root, path, parsedPath );
  24918. } else {
  24919. return new PropertyBinding.Composite( root, path, parsedPath );
  24920. }
  24921. },
  24922. /**
  24923. * Replaces spaces with underscores and removes unsupported characters from
  24924. * node names, to ensure compatibility with parseTrackName().
  24925. *
  24926. * @param {string} name Node name to be sanitized.
  24927. * @return {string}
  24928. */
  24929. sanitizeNodeName: function ( name ) {
  24930. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  24931. },
  24932. parseTrackName: function ( trackName ) {
  24933. const matches = _trackRe.exec( trackName );
  24934. if ( ! matches ) {
  24935. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24936. }
  24937. const results = {
  24938. // directoryName: matches[ 1 ], // (tschw) currently unused
  24939. nodeName: matches[ 2 ],
  24940. objectName: matches[ 3 ],
  24941. objectIndex: matches[ 4 ],
  24942. propertyName: matches[ 5 ], // required
  24943. propertyIndex: matches[ 6 ]
  24944. };
  24945. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24946. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24947. const objectName = results.nodeName.substring( lastDot + 1 );
  24948. // Object names must be checked against an allowlist. Otherwise, there
  24949. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24950. // 'bar' could be the objectName, or part of a nodeName (which can
  24951. // include '.' characters).
  24952. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24953. results.nodeName = results.nodeName.substring( 0, lastDot );
  24954. results.objectName = objectName;
  24955. }
  24956. }
  24957. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24958. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24959. }
  24960. return results;
  24961. },
  24962. findNode: function ( root, nodeName ) {
  24963. if ( ! nodeName || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24964. return root;
  24965. }
  24966. // search into skeleton bones.
  24967. if ( root.skeleton ) {
  24968. const bone = root.skeleton.getBoneByName( nodeName );
  24969. if ( bone !== undefined ) {
  24970. return bone;
  24971. }
  24972. }
  24973. // search into node subtree.
  24974. if ( root.children ) {
  24975. const searchNodeSubtree = function ( children ) {
  24976. for ( let i = 0; i < children.length; i ++ ) {
  24977. const childNode = children[ i ];
  24978. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24979. return childNode;
  24980. }
  24981. const result = searchNodeSubtree( childNode.children );
  24982. if ( result ) return result;
  24983. }
  24984. return null;
  24985. };
  24986. const subTreeNode = searchNodeSubtree( root.children );
  24987. if ( subTreeNode ) {
  24988. return subTreeNode;
  24989. }
  24990. }
  24991. return null;
  24992. }
  24993. } );
  24994. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24995. // these are used to "bind" a nonexistent property
  24996. _getValue_unavailable: function () {},
  24997. _setValue_unavailable: function () {},
  24998. BindingType: {
  24999. Direct: 0,
  25000. EntireArray: 1,
  25001. ArrayElement: 2,
  25002. HasFromToArray: 3
  25003. },
  25004. Versioning: {
  25005. None: 0,
  25006. NeedsUpdate: 1,
  25007. MatrixWorldNeedsUpdate: 2
  25008. },
  25009. GetterByBindingType: [
  25010. function getValue_direct( buffer, offset ) {
  25011. buffer[ offset ] = this.node[ this.propertyName ];
  25012. },
  25013. function getValue_array( buffer, offset ) {
  25014. const source = this.resolvedProperty;
  25015. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  25016. buffer[ offset ++ ] = source[ i ];
  25017. }
  25018. },
  25019. function getValue_arrayElement( buffer, offset ) {
  25020. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25021. },
  25022. function getValue_toArray( buffer, offset ) {
  25023. this.resolvedProperty.toArray( buffer, offset );
  25024. }
  25025. ],
  25026. SetterByBindingTypeAndVersioning: [
  25027. [
  25028. // Direct
  25029. function setValue_direct( buffer, offset ) {
  25030. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25031. },
  25032. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25033. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25034. this.targetObject.needsUpdate = true;
  25035. },
  25036. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25037. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25038. this.targetObject.matrixWorldNeedsUpdate = true;
  25039. }
  25040. ], [
  25041. // EntireArray
  25042. function setValue_array( buffer, offset ) {
  25043. const dest = this.resolvedProperty;
  25044. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  25045. dest[ i ] = buffer[ offset ++ ];
  25046. }
  25047. },
  25048. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25049. const dest = this.resolvedProperty;
  25050. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  25051. dest[ i ] = buffer[ offset ++ ];
  25052. }
  25053. this.targetObject.needsUpdate = true;
  25054. },
  25055. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25056. const dest = this.resolvedProperty;
  25057. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  25058. dest[ i ] = buffer[ offset ++ ];
  25059. }
  25060. this.targetObject.matrixWorldNeedsUpdate = true;
  25061. }
  25062. ], [
  25063. // ArrayElement
  25064. function setValue_arrayElement( buffer, offset ) {
  25065. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25066. },
  25067. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25068. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25069. this.targetObject.needsUpdate = true;
  25070. },
  25071. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25072. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25073. this.targetObject.matrixWorldNeedsUpdate = true;
  25074. }
  25075. ], [
  25076. // HasToFromArray
  25077. function setValue_fromArray( buffer, offset ) {
  25078. this.resolvedProperty.fromArray( buffer, offset );
  25079. },
  25080. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25081. this.resolvedProperty.fromArray( buffer, offset );
  25082. this.targetObject.needsUpdate = true;
  25083. },
  25084. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25085. this.resolvedProperty.fromArray( buffer, offset );
  25086. this.targetObject.matrixWorldNeedsUpdate = true;
  25087. }
  25088. ]
  25089. ],
  25090. getValue: function getValue_unbound( targetArray, offset ) {
  25091. this.bind();
  25092. this.getValue( targetArray, offset );
  25093. // Note: This class uses a State pattern on a per-method basis:
  25094. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25095. // prototype version of these methods with one that represents
  25096. // the bound state. When the property is not found, the methods
  25097. // become no-ops.
  25098. },
  25099. setValue: function getValue_unbound( sourceArray, offset ) {
  25100. this.bind();
  25101. this.setValue( sourceArray, offset );
  25102. },
  25103. // create getter / setter pair for a property in the scene graph
  25104. bind: function () {
  25105. let targetObject = this.node;
  25106. const parsedPath = this.parsedPath;
  25107. const objectName = parsedPath.objectName;
  25108. const propertyName = parsedPath.propertyName;
  25109. let propertyIndex = parsedPath.propertyIndex;
  25110. if ( ! targetObject ) {
  25111. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25112. this.node = targetObject;
  25113. }
  25114. // set fail state so we can just 'return' on error
  25115. this.getValue = this._getValue_unavailable;
  25116. this.setValue = this._setValue_unavailable;
  25117. // ensure there is a value node
  25118. if ( ! targetObject ) {
  25119. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25120. return;
  25121. }
  25122. if ( objectName ) {
  25123. let objectIndex = parsedPath.objectIndex;
  25124. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25125. switch ( objectName ) {
  25126. case 'materials':
  25127. if ( ! targetObject.material ) {
  25128. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25129. return;
  25130. }
  25131. if ( ! targetObject.material.materials ) {
  25132. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25133. return;
  25134. }
  25135. targetObject = targetObject.material.materials;
  25136. break;
  25137. case 'bones':
  25138. if ( ! targetObject.skeleton ) {
  25139. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25140. return;
  25141. }
  25142. // potential future optimization: skip this if propertyIndex is already an integer
  25143. // and convert the integer string to a true integer.
  25144. targetObject = targetObject.skeleton.bones;
  25145. // support resolving morphTarget names into indices.
  25146. for ( let i = 0; i < targetObject.length; i ++ ) {
  25147. if ( targetObject[ i ].name === objectIndex ) {
  25148. objectIndex = i;
  25149. break;
  25150. }
  25151. }
  25152. break;
  25153. default:
  25154. if ( targetObject[ objectName ] === undefined ) {
  25155. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25156. return;
  25157. }
  25158. targetObject = targetObject[ objectName ];
  25159. }
  25160. if ( objectIndex !== undefined ) {
  25161. if ( targetObject[ objectIndex ] === undefined ) {
  25162. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25163. return;
  25164. }
  25165. targetObject = targetObject[ objectIndex ];
  25166. }
  25167. }
  25168. // resolve property
  25169. const nodeProperty = targetObject[ propertyName ];
  25170. if ( nodeProperty === undefined ) {
  25171. const nodeName = parsedPath.nodeName;
  25172. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25173. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25174. return;
  25175. }
  25176. // determine versioning scheme
  25177. let versioning = this.Versioning.None;
  25178. this.targetObject = targetObject;
  25179. if ( targetObject.needsUpdate !== undefined ) { // material
  25180. versioning = this.Versioning.NeedsUpdate;
  25181. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25182. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25183. }
  25184. // determine how the property gets bound
  25185. let bindingType = this.BindingType.Direct;
  25186. if ( propertyIndex !== undefined ) {
  25187. // access a sub element of the property array (only primitives are supported right now)
  25188. if ( propertyName === 'morphTargetInfluences' ) {
  25189. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25190. // support resolving morphTarget names into indices.
  25191. if ( ! targetObject.geometry ) {
  25192. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25193. return;
  25194. }
  25195. if ( targetObject.geometry.isBufferGeometry ) {
  25196. if ( ! targetObject.geometry.morphAttributes ) {
  25197. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25198. return;
  25199. }
  25200. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  25201. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  25202. }
  25203. } else {
  25204. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  25205. return;
  25206. }
  25207. }
  25208. bindingType = this.BindingType.ArrayElement;
  25209. this.resolvedProperty = nodeProperty;
  25210. this.propertyIndex = propertyIndex;
  25211. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25212. // must use copy for Object3D.Euler/Quaternion
  25213. bindingType = this.BindingType.HasFromToArray;
  25214. this.resolvedProperty = nodeProperty;
  25215. } else if ( Array.isArray( nodeProperty ) ) {
  25216. bindingType = this.BindingType.EntireArray;
  25217. this.resolvedProperty = nodeProperty;
  25218. } else {
  25219. this.propertyName = propertyName;
  25220. }
  25221. // select getter / setter
  25222. this.getValue = this.GetterByBindingType[ bindingType ];
  25223. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25224. },
  25225. unbind: function () {
  25226. this.node = null;
  25227. // back to the prototype version of getValue / setValue
  25228. // note: avoiding to mutate the shape of 'this' via 'delete'
  25229. this.getValue = this._getValue_unbound;
  25230. this.setValue = this._setValue_unbound;
  25231. }
  25232. } );
  25233. // DECLARE ALIAS AFTER assign prototype
  25234. Object.assign( PropertyBinding.prototype, {
  25235. // initial state of these methods that calls 'bind'
  25236. _getValue_unbound: PropertyBinding.prototype.getValue,
  25237. _setValue_unbound: PropertyBinding.prototype.setValue,
  25238. } );
  25239. /**
  25240. *
  25241. * A group of objects that receives a shared animation state.
  25242. *
  25243. * Usage:
  25244. *
  25245. * - Add objects you would otherwise pass as 'root' to the
  25246. * constructor or the .clipAction method of AnimationMixer.
  25247. *
  25248. * - Instead pass this object as 'root'.
  25249. *
  25250. * - You can also add and remove objects later when the mixer
  25251. * is running.
  25252. *
  25253. * Note:
  25254. *
  25255. * Objects of this class appear as one object to the mixer,
  25256. * so cache control of the individual objects must be done
  25257. * on the group.
  25258. *
  25259. * Limitation:
  25260. *
  25261. * - The animated properties must be compatible among the
  25262. * all objects in the group.
  25263. *
  25264. * - A single property can either be controlled through a
  25265. * target group or directly, but not both.
  25266. */
  25267. function AnimationObjectGroup() {
  25268. this.uuid = MathUtils.generateUUID();
  25269. // cached objects followed by the active ones
  25270. this._objects = Array.prototype.slice.call( arguments );
  25271. this.nCachedObjects_ = 0; // threshold
  25272. // note: read by PropertyBinding.Composite
  25273. const indices = {};
  25274. this._indicesByUUID = indices; // for bookkeeping
  25275. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25276. indices[ arguments[ i ].uuid ] = i;
  25277. }
  25278. this._paths = []; // inside: string
  25279. this._parsedPaths = []; // inside: { we don't care, here }
  25280. this._bindings = []; // inside: Array< PropertyBinding >
  25281. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25282. const scope = this;
  25283. this.stats = {
  25284. objects: {
  25285. get total() {
  25286. return scope._objects.length;
  25287. },
  25288. get inUse() {
  25289. return this.total - scope.nCachedObjects_;
  25290. }
  25291. },
  25292. get bindingsPerObject() {
  25293. return scope._bindings.length;
  25294. }
  25295. };
  25296. }
  25297. Object.assign( AnimationObjectGroup.prototype, {
  25298. isAnimationObjectGroup: true,
  25299. add: function () {
  25300. const objects = this._objects,
  25301. indicesByUUID = this._indicesByUUID,
  25302. paths = this._paths,
  25303. parsedPaths = this._parsedPaths,
  25304. bindings = this._bindings,
  25305. nBindings = bindings.length;
  25306. let knownObject = undefined,
  25307. nObjects = objects.length,
  25308. nCachedObjects = this.nCachedObjects_;
  25309. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25310. const object = arguments[ i ],
  25311. uuid = object.uuid;
  25312. let index = indicesByUUID[ uuid ];
  25313. if ( index === undefined ) {
  25314. // unknown object -> add it to the ACTIVE region
  25315. index = nObjects ++;
  25316. indicesByUUID[ uuid ] = index;
  25317. objects.push( object );
  25318. // accounting is done, now do the same for all bindings
  25319. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25320. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25321. }
  25322. } else if ( index < nCachedObjects ) {
  25323. knownObject = objects[ index ];
  25324. // move existing object to the ACTIVE region
  25325. const firstActiveIndex = -- nCachedObjects,
  25326. lastCachedObject = objects[ firstActiveIndex ];
  25327. indicesByUUID[ lastCachedObject.uuid ] = index;
  25328. objects[ index ] = lastCachedObject;
  25329. indicesByUUID[ uuid ] = firstActiveIndex;
  25330. objects[ firstActiveIndex ] = object;
  25331. // accounting is done, now do the same for all bindings
  25332. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25333. const bindingsForPath = bindings[ j ],
  25334. lastCached = bindingsForPath[ firstActiveIndex ];
  25335. let binding = bindingsForPath[ index ];
  25336. bindingsForPath[ index ] = lastCached;
  25337. if ( binding === undefined ) {
  25338. // since we do not bother to create new bindings
  25339. // for objects that are cached, the binding may
  25340. // or may not exist
  25341. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25342. }
  25343. bindingsForPath[ firstActiveIndex ] = binding;
  25344. }
  25345. } else if ( objects[ index ] !== knownObject ) {
  25346. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25347. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25348. } // else the object is already where we want it to be
  25349. } // for arguments
  25350. this.nCachedObjects_ = nCachedObjects;
  25351. },
  25352. remove: function () {
  25353. const objects = this._objects,
  25354. indicesByUUID = this._indicesByUUID,
  25355. bindings = this._bindings,
  25356. nBindings = bindings.length;
  25357. let nCachedObjects = this.nCachedObjects_;
  25358. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25359. const object = arguments[ i ],
  25360. uuid = object.uuid,
  25361. index = indicesByUUID[ uuid ];
  25362. if ( index !== undefined && index >= nCachedObjects ) {
  25363. // move existing object into the CACHED region
  25364. const lastCachedIndex = nCachedObjects ++,
  25365. firstActiveObject = objects[ lastCachedIndex ];
  25366. indicesByUUID[ firstActiveObject.uuid ] = index;
  25367. objects[ index ] = firstActiveObject;
  25368. indicesByUUID[ uuid ] = lastCachedIndex;
  25369. objects[ lastCachedIndex ] = object;
  25370. // accounting is done, now do the same for all bindings
  25371. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25372. const bindingsForPath = bindings[ j ],
  25373. firstActive = bindingsForPath[ lastCachedIndex ],
  25374. binding = bindingsForPath[ index ];
  25375. bindingsForPath[ index ] = firstActive;
  25376. bindingsForPath[ lastCachedIndex ] = binding;
  25377. }
  25378. }
  25379. } // for arguments
  25380. this.nCachedObjects_ = nCachedObjects;
  25381. },
  25382. // remove & forget
  25383. uncache: function () {
  25384. const objects = this._objects,
  25385. indicesByUUID = this._indicesByUUID,
  25386. bindings = this._bindings,
  25387. nBindings = bindings.length;
  25388. let nCachedObjects = this.nCachedObjects_,
  25389. nObjects = objects.length;
  25390. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  25391. const object = arguments[ i ],
  25392. uuid = object.uuid,
  25393. index = indicesByUUID[ uuid ];
  25394. if ( index !== undefined ) {
  25395. delete indicesByUUID[ uuid ];
  25396. if ( index < nCachedObjects ) {
  25397. // object is cached, shrink the CACHED region
  25398. const firstActiveIndex = -- nCachedObjects,
  25399. lastCachedObject = objects[ firstActiveIndex ],
  25400. lastIndex = -- nObjects,
  25401. lastObject = objects[ lastIndex ];
  25402. // last cached object takes this object's place
  25403. indicesByUUID[ lastCachedObject.uuid ] = index;
  25404. objects[ index ] = lastCachedObject;
  25405. // last object goes to the activated slot and pop
  25406. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25407. objects[ firstActiveIndex ] = lastObject;
  25408. objects.pop();
  25409. // accounting is done, now do the same for all bindings
  25410. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25411. const bindingsForPath = bindings[ j ],
  25412. lastCached = bindingsForPath[ firstActiveIndex ],
  25413. last = bindingsForPath[ lastIndex ];
  25414. bindingsForPath[ index ] = lastCached;
  25415. bindingsForPath[ firstActiveIndex ] = last;
  25416. bindingsForPath.pop();
  25417. }
  25418. } else {
  25419. // object is active, just swap with the last and pop
  25420. const lastIndex = -- nObjects,
  25421. lastObject = objects[ lastIndex ];
  25422. if ( lastIndex > 0 ) {
  25423. indicesByUUID[ lastObject.uuid ] = index;
  25424. }
  25425. objects[ index ] = lastObject;
  25426. objects.pop();
  25427. // accounting is done, now do the same for all bindings
  25428. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  25429. const bindingsForPath = bindings[ j ];
  25430. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25431. bindingsForPath.pop();
  25432. }
  25433. } // cached or active
  25434. } // if object is known
  25435. } // for arguments
  25436. this.nCachedObjects_ = nCachedObjects;
  25437. },
  25438. // Internal interface used by befriended PropertyBinding.Composite:
  25439. subscribe_: function ( path, parsedPath ) {
  25440. // returns an array of bindings for the given path that is changed
  25441. // according to the contained objects in the group
  25442. const indicesByPath = this._bindingsIndicesByPath;
  25443. let index = indicesByPath[ path ];
  25444. const bindings = this._bindings;
  25445. if ( index !== undefined ) return bindings[ index ];
  25446. const paths = this._paths,
  25447. parsedPaths = this._parsedPaths,
  25448. objects = this._objects,
  25449. nObjects = objects.length,
  25450. nCachedObjects = this.nCachedObjects_,
  25451. bindingsForPath = new Array( nObjects );
  25452. index = bindings.length;
  25453. indicesByPath[ path ] = index;
  25454. paths.push( path );
  25455. parsedPaths.push( parsedPath );
  25456. bindings.push( bindingsForPath );
  25457. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25458. const object = objects[ i ];
  25459. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25460. }
  25461. return bindingsForPath;
  25462. },
  25463. unsubscribe_: function ( path ) {
  25464. // tells the group to forget about a property path and no longer
  25465. // update the array previously obtained with 'subscribe_'
  25466. const indicesByPath = this._bindingsIndicesByPath,
  25467. index = indicesByPath[ path ];
  25468. if ( index !== undefined ) {
  25469. const paths = this._paths,
  25470. parsedPaths = this._parsedPaths,
  25471. bindings = this._bindings,
  25472. lastBindingsIndex = bindings.length - 1,
  25473. lastBindings = bindings[ lastBindingsIndex ],
  25474. lastBindingsPath = path[ lastBindingsIndex ];
  25475. indicesByPath[ lastBindingsPath ] = index;
  25476. bindings[ index ] = lastBindings;
  25477. bindings.pop();
  25478. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25479. parsedPaths.pop();
  25480. paths[ index ] = paths[ lastBindingsIndex ];
  25481. paths.pop();
  25482. }
  25483. }
  25484. } );
  25485. class AnimationAction {
  25486. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  25487. this._mixer = mixer;
  25488. this._clip = clip;
  25489. this._localRoot = localRoot;
  25490. this.blendMode = blendMode;
  25491. const tracks = clip.tracks,
  25492. nTracks = tracks.length,
  25493. interpolants = new Array( nTracks );
  25494. const interpolantSettings = {
  25495. endingStart: ZeroCurvatureEnding,
  25496. endingEnd: ZeroCurvatureEnding
  25497. };
  25498. for ( let i = 0; i !== nTracks; ++ i ) {
  25499. const interpolant = tracks[ i ].createInterpolant( null );
  25500. interpolants[ i ] = interpolant;
  25501. interpolant.settings = interpolantSettings;
  25502. }
  25503. this._interpolantSettings = interpolantSettings;
  25504. this._interpolants = interpolants; // bound by the mixer
  25505. // inside: PropertyMixer (managed by the mixer)
  25506. this._propertyBindings = new Array( nTracks );
  25507. this._cacheIndex = null; // for the memory manager
  25508. this._byClipCacheIndex = null; // for the memory manager
  25509. this._timeScaleInterpolant = null;
  25510. this._weightInterpolant = null;
  25511. this.loop = LoopRepeat;
  25512. this._loopCount = - 1;
  25513. // global mixer time when the action is to be started
  25514. // it's set back to 'null' upon start of the action
  25515. this._startTime = null;
  25516. // scaled local time of the action
  25517. // gets clamped or wrapped to 0..clip.duration according to loop
  25518. this.time = 0;
  25519. this.timeScale = 1;
  25520. this._effectiveTimeScale = 1;
  25521. this.weight = 1;
  25522. this._effectiveWeight = 1;
  25523. this.repetitions = Infinity; // no. of repetitions when looping
  25524. this.paused = false; // true -> zero effective time scale
  25525. this.enabled = true; // false -> zero effective weight
  25526. this.clampWhenFinished = false;// keep feeding the last frame?
  25527. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25528. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25529. }
  25530. // State & Scheduling
  25531. play() {
  25532. this._mixer._activateAction( this );
  25533. return this;
  25534. }
  25535. stop() {
  25536. this._mixer._deactivateAction( this );
  25537. return this.reset();
  25538. }
  25539. reset() {
  25540. this.paused = false;
  25541. this.enabled = true;
  25542. this.time = 0; // restart clip
  25543. this._loopCount = - 1;// forget previous loops
  25544. this._startTime = null;// forget scheduling
  25545. return this.stopFading().stopWarping();
  25546. }
  25547. isRunning() {
  25548. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25549. this._startTime === null && this._mixer._isActiveAction( this );
  25550. }
  25551. // return true when play has been called
  25552. isScheduled() {
  25553. return this._mixer._isActiveAction( this );
  25554. }
  25555. startAt( time ) {
  25556. this._startTime = time;
  25557. return this;
  25558. }
  25559. setLoop( mode, repetitions ) {
  25560. this.loop = mode;
  25561. this.repetitions = repetitions;
  25562. return this;
  25563. }
  25564. // Weight
  25565. // set the weight stopping any scheduled fading
  25566. // although .enabled = false yields an effective weight of zero, this
  25567. // method does *not* change .enabled, because it would be confusing
  25568. setEffectiveWeight( weight ) {
  25569. this.weight = weight;
  25570. // note: same logic as when updated at runtime
  25571. this._effectiveWeight = this.enabled ? weight : 0;
  25572. return this.stopFading();
  25573. }
  25574. // return the weight considering fading and .enabled
  25575. getEffectiveWeight() {
  25576. return this._effectiveWeight;
  25577. }
  25578. fadeIn( duration ) {
  25579. return this._scheduleFading( duration, 0, 1 );
  25580. }
  25581. fadeOut( duration ) {
  25582. return this._scheduleFading( duration, 1, 0 );
  25583. }
  25584. crossFadeFrom( fadeOutAction, duration, warp ) {
  25585. fadeOutAction.fadeOut( duration );
  25586. this.fadeIn( duration );
  25587. if ( warp ) {
  25588. const fadeInDuration = this._clip.duration,
  25589. fadeOutDuration = fadeOutAction._clip.duration,
  25590. startEndRatio = fadeOutDuration / fadeInDuration,
  25591. endStartRatio = fadeInDuration / fadeOutDuration;
  25592. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25593. this.warp( endStartRatio, 1.0, duration );
  25594. }
  25595. return this;
  25596. }
  25597. crossFadeTo( fadeInAction, duration, warp ) {
  25598. return fadeInAction.crossFadeFrom( this, duration, warp );
  25599. }
  25600. stopFading() {
  25601. const weightInterpolant = this._weightInterpolant;
  25602. if ( weightInterpolant !== null ) {
  25603. this._weightInterpolant = null;
  25604. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25605. }
  25606. return this;
  25607. }
  25608. // Time Scale Control
  25609. // set the time scale stopping any scheduled warping
  25610. // although .paused = true yields an effective time scale of zero, this
  25611. // method does *not* change .paused, because it would be confusing
  25612. setEffectiveTimeScale( timeScale ) {
  25613. this.timeScale = timeScale;
  25614. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25615. return this.stopWarping();
  25616. }
  25617. // return the time scale considering warping and .paused
  25618. getEffectiveTimeScale() {
  25619. return this._effectiveTimeScale;
  25620. }
  25621. setDuration( duration ) {
  25622. this.timeScale = this._clip.duration / duration;
  25623. return this.stopWarping();
  25624. }
  25625. syncWith( action ) {
  25626. this.time = action.time;
  25627. this.timeScale = action.timeScale;
  25628. return this.stopWarping();
  25629. }
  25630. halt( duration ) {
  25631. return this.warp( this._effectiveTimeScale, 0, duration );
  25632. }
  25633. warp( startTimeScale, endTimeScale, duration ) {
  25634. const mixer = this._mixer,
  25635. now = mixer.time,
  25636. timeScale = this.timeScale;
  25637. let interpolant = this._timeScaleInterpolant;
  25638. if ( interpolant === null ) {
  25639. interpolant = mixer._lendControlInterpolant();
  25640. this._timeScaleInterpolant = interpolant;
  25641. }
  25642. const times = interpolant.parameterPositions,
  25643. values = interpolant.sampleValues;
  25644. times[ 0 ] = now;
  25645. times[ 1 ] = now + duration;
  25646. values[ 0 ] = startTimeScale / timeScale;
  25647. values[ 1 ] = endTimeScale / timeScale;
  25648. return this;
  25649. }
  25650. stopWarping() {
  25651. const timeScaleInterpolant = this._timeScaleInterpolant;
  25652. if ( timeScaleInterpolant !== null ) {
  25653. this._timeScaleInterpolant = null;
  25654. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25655. }
  25656. return this;
  25657. }
  25658. // Object Accessors
  25659. getMixer() {
  25660. return this._mixer;
  25661. }
  25662. getClip() {
  25663. return this._clip;
  25664. }
  25665. getRoot() {
  25666. return this._localRoot || this._mixer._root;
  25667. }
  25668. // Interna
  25669. _update( time, deltaTime, timeDirection, accuIndex ) {
  25670. // called by the mixer
  25671. if ( ! this.enabled ) {
  25672. // call ._updateWeight() to update ._effectiveWeight
  25673. this._updateWeight( time );
  25674. return;
  25675. }
  25676. const startTime = this._startTime;
  25677. if ( startTime !== null ) {
  25678. // check for scheduled start of action
  25679. const timeRunning = ( time - startTime ) * timeDirection;
  25680. if ( timeRunning < 0 || timeDirection === 0 ) {
  25681. return; // yet to come / don't decide when delta = 0
  25682. }
  25683. // start
  25684. this._startTime = null; // unschedule
  25685. deltaTime = timeDirection * timeRunning;
  25686. }
  25687. // apply time scale and advance time
  25688. deltaTime *= this._updateTimeScale( time );
  25689. const clipTime = this._updateTime( deltaTime );
  25690. // note: _updateTime may disable the action resulting in
  25691. // an effective weight of 0
  25692. const weight = this._updateWeight( time );
  25693. if ( weight > 0 ) {
  25694. const interpolants = this._interpolants;
  25695. const propertyMixers = this._propertyBindings;
  25696. switch ( this.blendMode ) {
  25697. case AdditiveAnimationBlendMode:
  25698. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  25699. interpolants[ j ].evaluate( clipTime );
  25700. propertyMixers[ j ].accumulateAdditive( weight );
  25701. }
  25702. break;
  25703. case NormalAnimationBlendMode:
  25704. default:
  25705. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  25706. interpolants[ j ].evaluate( clipTime );
  25707. propertyMixers[ j ].accumulate( accuIndex, weight );
  25708. }
  25709. }
  25710. }
  25711. }
  25712. _updateWeight( time ) {
  25713. let weight = 0;
  25714. if ( this.enabled ) {
  25715. weight = this.weight;
  25716. const interpolant = this._weightInterpolant;
  25717. if ( interpolant !== null ) {
  25718. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  25719. weight *= interpolantValue;
  25720. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25721. this.stopFading();
  25722. if ( interpolantValue === 0 ) {
  25723. // faded out, disable
  25724. this.enabled = false;
  25725. }
  25726. }
  25727. }
  25728. }
  25729. this._effectiveWeight = weight;
  25730. return weight;
  25731. }
  25732. _updateTimeScale( time ) {
  25733. let timeScale = 0;
  25734. if ( ! this.paused ) {
  25735. timeScale = this.timeScale;
  25736. const interpolant = this._timeScaleInterpolant;
  25737. if ( interpolant !== null ) {
  25738. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  25739. timeScale *= interpolantValue;
  25740. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25741. this.stopWarping();
  25742. if ( timeScale === 0 ) {
  25743. // motion has halted, pause
  25744. this.paused = true;
  25745. } else {
  25746. // warp done - apply final time scale
  25747. this.timeScale = timeScale;
  25748. }
  25749. }
  25750. }
  25751. }
  25752. this._effectiveTimeScale = timeScale;
  25753. return timeScale;
  25754. }
  25755. _updateTime( deltaTime ) {
  25756. const duration = this._clip.duration;
  25757. const loop = this.loop;
  25758. let time = this.time + deltaTime;
  25759. let loopCount = this._loopCount;
  25760. const pingPong = ( loop === LoopPingPong );
  25761. if ( deltaTime === 0 ) {
  25762. if ( loopCount === - 1 ) return time;
  25763. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25764. }
  25765. if ( loop === LoopOnce ) {
  25766. if ( loopCount === - 1 ) {
  25767. // just started
  25768. this._loopCount = 0;
  25769. this._setEndings( true, true, false );
  25770. }
  25771. handle_stop: {
  25772. if ( time >= duration ) {
  25773. time = duration;
  25774. } else if ( time < 0 ) {
  25775. time = 0;
  25776. } else {
  25777. this.time = time;
  25778. break handle_stop;
  25779. }
  25780. if ( this.clampWhenFinished ) this.paused = true;
  25781. else this.enabled = false;
  25782. this.time = time;
  25783. this._mixer.dispatchEvent( {
  25784. type: 'finished', action: this,
  25785. direction: deltaTime < 0 ? - 1 : 1
  25786. } );
  25787. }
  25788. } else { // repetitive Repeat or PingPong
  25789. if ( loopCount === - 1 ) {
  25790. // just started
  25791. if ( deltaTime >= 0 ) {
  25792. loopCount = 0;
  25793. this._setEndings( true, this.repetitions === 0, pingPong );
  25794. } else {
  25795. // when looping in reverse direction, the initial
  25796. // transition through zero counts as a repetition,
  25797. // so leave loopCount at -1
  25798. this._setEndings( this.repetitions === 0, true, pingPong );
  25799. }
  25800. }
  25801. if ( time >= duration || time < 0 ) {
  25802. // wrap around
  25803. const loopDelta = Math.floor( time / duration ); // signed
  25804. time -= duration * loopDelta;
  25805. loopCount += Math.abs( loopDelta );
  25806. const pending = this.repetitions - loopCount;
  25807. if ( pending <= 0 ) {
  25808. // have to stop (switch state, clamp time, fire event)
  25809. if ( this.clampWhenFinished ) this.paused = true;
  25810. else this.enabled = false;
  25811. time = deltaTime > 0 ? duration : 0;
  25812. this.time = time;
  25813. this._mixer.dispatchEvent( {
  25814. type: 'finished', action: this,
  25815. direction: deltaTime > 0 ? 1 : - 1
  25816. } );
  25817. } else {
  25818. // keep running
  25819. if ( pending === 1 ) {
  25820. // entering the last round
  25821. const atStart = deltaTime < 0;
  25822. this._setEndings( atStart, ! atStart, pingPong );
  25823. } else {
  25824. this._setEndings( false, false, pingPong );
  25825. }
  25826. this._loopCount = loopCount;
  25827. this.time = time;
  25828. this._mixer.dispatchEvent( {
  25829. type: 'loop', action: this, loopDelta: loopDelta
  25830. } );
  25831. }
  25832. } else {
  25833. this.time = time;
  25834. }
  25835. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25836. // invert time for the "pong round"
  25837. return duration - time;
  25838. }
  25839. }
  25840. return time;
  25841. }
  25842. _setEndings( atStart, atEnd, pingPong ) {
  25843. const settings = this._interpolantSettings;
  25844. if ( pingPong ) {
  25845. settings.endingStart = ZeroSlopeEnding;
  25846. settings.endingEnd = ZeroSlopeEnding;
  25847. } else {
  25848. // assuming for LoopOnce atStart == atEnd == true
  25849. if ( atStart ) {
  25850. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25851. } else {
  25852. settings.endingStart = WrapAroundEnding;
  25853. }
  25854. if ( atEnd ) {
  25855. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25856. } else {
  25857. settings.endingEnd = WrapAroundEnding;
  25858. }
  25859. }
  25860. }
  25861. _scheduleFading( duration, weightNow, weightThen ) {
  25862. const mixer = this._mixer, now = mixer.time;
  25863. let interpolant = this._weightInterpolant;
  25864. if ( interpolant === null ) {
  25865. interpolant = mixer._lendControlInterpolant();
  25866. this._weightInterpolant = interpolant;
  25867. }
  25868. const times = interpolant.parameterPositions,
  25869. values = interpolant.sampleValues;
  25870. times[ 0 ] = now;
  25871. values[ 0 ] = weightNow;
  25872. times[ 1 ] = now + duration;
  25873. values[ 1 ] = weightThen;
  25874. return this;
  25875. }
  25876. }
  25877. function AnimationMixer( root ) {
  25878. this._root = root;
  25879. this._initMemoryManager();
  25880. this._accuIndex = 0;
  25881. this.time = 0;
  25882. this.timeScale = 1.0;
  25883. }
  25884. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25885. constructor: AnimationMixer,
  25886. _bindAction: function ( action, prototypeAction ) {
  25887. const root = action._localRoot || this._root,
  25888. tracks = action._clip.tracks,
  25889. nTracks = tracks.length,
  25890. bindings = action._propertyBindings,
  25891. interpolants = action._interpolants,
  25892. rootUuid = root.uuid,
  25893. bindingsByRoot = this._bindingsByRootAndName;
  25894. let bindingsByName = bindingsByRoot[ rootUuid ];
  25895. if ( bindingsByName === undefined ) {
  25896. bindingsByName = {};
  25897. bindingsByRoot[ rootUuid ] = bindingsByName;
  25898. }
  25899. for ( let i = 0; i !== nTracks; ++ i ) {
  25900. const track = tracks[ i ],
  25901. trackName = track.name;
  25902. let binding = bindingsByName[ trackName ];
  25903. if ( binding !== undefined ) {
  25904. bindings[ i ] = binding;
  25905. } else {
  25906. binding = bindings[ i ];
  25907. if ( binding !== undefined ) {
  25908. // existing binding, make sure the cache knows
  25909. if ( binding._cacheIndex === null ) {
  25910. ++ binding.referenceCount;
  25911. this._addInactiveBinding( binding, rootUuid, trackName );
  25912. }
  25913. continue;
  25914. }
  25915. const path = prototypeAction && prototypeAction.
  25916. _propertyBindings[ i ].binding.parsedPath;
  25917. binding = new PropertyMixer(
  25918. PropertyBinding.create( root, trackName, path ),
  25919. track.ValueTypeName, track.getValueSize() );
  25920. ++ binding.referenceCount;
  25921. this._addInactiveBinding( binding, rootUuid, trackName );
  25922. bindings[ i ] = binding;
  25923. }
  25924. interpolants[ i ].resultBuffer = binding.buffer;
  25925. }
  25926. },
  25927. _activateAction: function ( action ) {
  25928. if ( ! this._isActiveAction( action ) ) {
  25929. if ( action._cacheIndex === null ) {
  25930. // this action has been forgotten by the cache, but the user
  25931. // appears to be still using it -> rebind
  25932. const rootUuid = ( action._localRoot || this._root ).uuid,
  25933. clipUuid = action._clip.uuid,
  25934. actionsForClip = this._actionsByClip[ clipUuid ];
  25935. this._bindAction( action,
  25936. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25937. this._addInactiveAction( action, clipUuid, rootUuid );
  25938. }
  25939. const bindings = action._propertyBindings;
  25940. // increment reference counts / sort out state
  25941. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  25942. const binding = bindings[ i ];
  25943. if ( binding.useCount ++ === 0 ) {
  25944. this._lendBinding( binding );
  25945. binding.saveOriginalState();
  25946. }
  25947. }
  25948. this._lendAction( action );
  25949. }
  25950. },
  25951. _deactivateAction: function ( action ) {
  25952. if ( this._isActiveAction( action ) ) {
  25953. const bindings = action._propertyBindings;
  25954. // decrement reference counts / sort out state
  25955. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  25956. const binding = bindings[ i ];
  25957. if ( -- binding.useCount === 0 ) {
  25958. binding.restoreOriginalState();
  25959. this._takeBackBinding( binding );
  25960. }
  25961. }
  25962. this._takeBackAction( action );
  25963. }
  25964. },
  25965. // Memory manager
  25966. _initMemoryManager: function () {
  25967. this._actions = []; // 'nActiveActions' followed by inactive ones
  25968. this._nActiveActions = 0;
  25969. this._actionsByClip = {};
  25970. // inside:
  25971. // {
  25972. // knownActions: Array< AnimationAction > - used as prototypes
  25973. // actionByRoot: AnimationAction - lookup
  25974. // }
  25975. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25976. this._nActiveBindings = 0;
  25977. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25978. this._controlInterpolants = []; // same game as above
  25979. this._nActiveControlInterpolants = 0;
  25980. const scope = this;
  25981. this.stats = {
  25982. actions: {
  25983. get total() {
  25984. return scope._actions.length;
  25985. },
  25986. get inUse() {
  25987. return scope._nActiveActions;
  25988. }
  25989. },
  25990. bindings: {
  25991. get total() {
  25992. return scope._bindings.length;
  25993. },
  25994. get inUse() {
  25995. return scope._nActiveBindings;
  25996. }
  25997. },
  25998. controlInterpolants: {
  25999. get total() {
  26000. return scope._controlInterpolants.length;
  26001. },
  26002. get inUse() {
  26003. return scope._nActiveControlInterpolants;
  26004. }
  26005. }
  26006. };
  26007. },
  26008. // Memory management for AnimationAction objects
  26009. _isActiveAction: function ( action ) {
  26010. const index = action._cacheIndex;
  26011. return index !== null && index < this._nActiveActions;
  26012. },
  26013. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26014. const actions = this._actions,
  26015. actionsByClip = this._actionsByClip;
  26016. let actionsForClip = actionsByClip[ clipUuid ];
  26017. if ( actionsForClip === undefined ) {
  26018. actionsForClip = {
  26019. knownActions: [ action ],
  26020. actionByRoot: {}
  26021. };
  26022. action._byClipCacheIndex = 0;
  26023. actionsByClip[ clipUuid ] = actionsForClip;
  26024. } else {
  26025. const knownActions = actionsForClip.knownActions;
  26026. action._byClipCacheIndex = knownActions.length;
  26027. knownActions.push( action );
  26028. }
  26029. action._cacheIndex = actions.length;
  26030. actions.push( action );
  26031. actionsForClip.actionByRoot[ rootUuid ] = action;
  26032. },
  26033. _removeInactiveAction: function ( action ) {
  26034. const actions = this._actions,
  26035. lastInactiveAction = actions[ actions.length - 1 ],
  26036. cacheIndex = action._cacheIndex;
  26037. lastInactiveAction._cacheIndex = cacheIndex;
  26038. actions[ cacheIndex ] = lastInactiveAction;
  26039. actions.pop();
  26040. action._cacheIndex = null;
  26041. const clipUuid = action._clip.uuid,
  26042. actionsByClip = this._actionsByClip,
  26043. actionsForClip = actionsByClip[ clipUuid ],
  26044. knownActionsForClip = actionsForClip.knownActions,
  26045. lastKnownAction =
  26046. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26047. byClipCacheIndex = action._byClipCacheIndex;
  26048. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26049. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26050. knownActionsForClip.pop();
  26051. action._byClipCacheIndex = null;
  26052. const actionByRoot = actionsForClip.actionByRoot,
  26053. rootUuid = ( action._localRoot || this._root ).uuid;
  26054. delete actionByRoot[ rootUuid ];
  26055. if ( knownActionsForClip.length === 0 ) {
  26056. delete actionsByClip[ clipUuid ];
  26057. }
  26058. this._removeInactiveBindingsForAction( action );
  26059. },
  26060. _removeInactiveBindingsForAction: function ( action ) {
  26061. const bindings = action._propertyBindings;
  26062. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  26063. const binding = bindings[ i ];
  26064. if ( -- binding.referenceCount === 0 ) {
  26065. this._removeInactiveBinding( binding );
  26066. }
  26067. }
  26068. },
  26069. _lendAction: function ( action ) {
  26070. // [ active actions | inactive actions ]
  26071. // [ active actions >| inactive actions ]
  26072. // s a
  26073. // <-swap->
  26074. // a s
  26075. const actions = this._actions,
  26076. prevIndex = action._cacheIndex,
  26077. lastActiveIndex = this._nActiveActions ++,
  26078. firstInactiveAction = actions[ lastActiveIndex ];
  26079. action._cacheIndex = lastActiveIndex;
  26080. actions[ lastActiveIndex ] = action;
  26081. firstInactiveAction._cacheIndex = prevIndex;
  26082. actions[ prevIndex ] = firstInactiveAction;
  26083. },
  26084. _takeBackAction: function ( action ) {
  26085. // [ active actions | inactive actions ]
  26086. // [ active actions |< inactive actions ]
  26087. // a s
  26088. // <-swap->
  26089. // s a
  26090. const actions = this._actions,
  26091. prevIndex = action._cacheIndex,
  26092. firstInactiveIndex = -- this._nActiveActions,
  26093. lastActiveAction = actions[ firstInactiveIndex ];
  26094. action._cacheIndex = firstInactiveIndex;
  26095. actions[ firstInactiveIndex ] = action;
  26096. lastActiveAction._cacheIndex = prevIndex;
  26097. actions[ prevIndex ] = lastActiveAction;
  26098. },
  26099. // Memory management for PropertyMixer objects
  26100. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26101. const bindingsByRoot = this._bindingsByRootAndName,
  26102. bindings = this._bindings;
  26103. let bindingByName = bindingsByRoot[ rootUuid ];
  26104. if ( bindingByName === undefined ) {
  26105. bindingByName = {};
  26106. bindingsByRoot[ rootUuid ] = bindingByName;
  26107. }
  26108. bindingByName[ trackName ] = binding;
  26109. binding._cacheIndex = bindings.length;
  26110. bindings.push( binding );
  26111. },
  26112. _removeInactiveBinding: function ( binding ) {
  26113. const bindings = this._bindings,
  26114. propBinding = binding.binding,
  26115. rootUuid = propBinding.rootNode.uuid,
  26116. trackName = propBinding.path,
  26117. bindingsByRoot = this._bindingsByRootAndName,
  26118. bindingByName = bindingsByRoot[ rootUuid ],
  26119. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26120. cacheIndex = binding._cacheIndex;
  26121. lastInactiveBinding._cacheIndex = cacheIndex;
  26122. bindings[ cacheIndex ] = lastInactiveBinding;
  26123. bindings.pop();
  26124. delete bindingByName[ trackName ];
  26125. if ( Object.keys( bindingByName ).length === 0 ) {
  26126. delete bindingsByRoot[ rootUuid ];
  26127. }
  26128. },
  26129. _lendBinding: function ( binding ) {
  26130. const bindings = this._bindings,
  26131. prevIndex = binding._cacheIndex,
  26132. lastActiveIndex = this._nActiveBindings ++,
  26133. firstInactiveBinding = bindings[ lastActiveIndex ];
  26134. binding._cacheIndex = lastActiveIndex;
  26135. bindings[ lastActiveIndex ] = binding;
  26136. firstInactiveBinding._cacheIndex = prevIndex;
  26137. bindings[ prevIndex ] = firstInactiveBinding;
  26138. },
  26139. _takeBackBinding: function ( binding ) {
  26140. const bindings = this._bindings,
  26141. prevIndex = binding._cacheIndex,
  26142. firstInactiveIndex = -- this._nActiveBindings,
  26143. lastActiveBinding = bindings[ firstInactiveIndex ];
  26144. binding._cacheIndex = firstInactiveIndex;
  26145. bindings[ firstInactiveIndex ] = binding;
  26146. lastActiveBinding._cacheIndex = prevIndex;
  26147. bindings[ prevIndex ] = lastActiveBinding;
  26148. },
  26149. // Memory management of Interpolants for weight and time scale
  26150. _lendControlInterpolant: function () {
  26151. const interpolants = this._controlInterpolants,
  26152. lastActiveIndex = this._nActiveControlInterpolants ++;
  26153. let interpolant = interpolants[ lastActiveIndex ];
  26154. if ( interpolant === undefined ) {
  26155. interpolant = new LinearInterpolant(
  26156. new Float32Array( 2 ), new Float32Array( 2 ),
  26157. 1, this._controlInterpolantsResultBuffer );
  26158. interpolant.__cacheIndex = lastActiveIndex;
  26159. interpolants[ lastActiveIndex ] = interpolant;
  26160. }
  26161. return interpolant;
  26162. },
  26163. _takeBackControlInterpolant: function ( interpolant ) {
  26164. const interpolants = this._controlInterpolants,
  26165. prevIndex = interpolant.__cacheIndex,
  26166. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26167. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26168. interpolant.__cacheIndex = firstInactiveIndex;
  26169. interpolants[ firstInactiveIndex ] = interpolant;
  26170. lastActiveInterpolant.__cacheIndex = prevIndex;
  26171. interpolants[ prevIndex ] = lastActiveInterpolant;
  26172. },
  26173. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26174. // return an action for a clip optionally using a custom root target
  26175. // object (this method allocates a lot of dynamic memory in case a
  26176. // previously unknown clip/root combination is specified)
  26177. clipAction: function ( clip, optionalRoot, blendMode ) {
  26178. const root = optionalRoot || this._root,
  26179. rootUuid = root.uuid;
  26180. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  26181. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26182. const actionsForClip = this._actionsByClip[ clipUuid ];
  26183. let prototypeAction = null;
  26184. if ( blendMode === undefined ) {
  26185. if ( clipObject !== null ) {
  26186. blendMode = clipObject.blendMode;
  26187. } else {
  26188. blendMode = NormalAnimationBlendMode;
  26189. }
  26190. }
  26191. if ( actionsForClip !== undefined ) {
  26192. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  26193. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  26194. return existingAction;
  26195. }
  26196. // we know the clip, so we don't have to parse all
  26197. // the bindings again but can just copy
  26198. prototypeAction = actionsForClip.knownActions[ 0 ];
  26199. // also, take the clip from the prototype action
  26200. if ( clipObject === null )
  26201. clipObject = prototypeAction._clip;
  26202. }
  26203. // clip must be known when specified via string
  26204. if ( clipObject === null ) return null;
  26205. // allocate all resources required to run it
  26206. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  26207. this._bindAction( newAction, prototypeAction );
  26208. // and make the action known to the memory manager
  26209. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26210. return newAction;
  26211. },
  26212. // get an existing action
  26213. existingAction: function ( clip, optionalRoot ) {
  26214. const root = optionalRoot || this._root,
  26215. rootUuid = root.uuid,
  26216. clipObject = typeof clip === 'string' ?
  26217. AnimationClip.findByName( root, clip ) : clip,
  26218. clipUuid = clipObject ? clipObject.uuid : clip,
  26219. actionsForClip = this._actionsByClip[ clipUuid ];
  26220. if ( actionsForClip !== undefined ) {
  26221. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26222. }
  26223. return null;
  26224. },
  26225. // deactivates all previously scheduled actions
  26226. stopAllAction: function () {
  26227. const actions = this._actions,
  26228. nActions = this._nActiveActions;
  26229. for ( let i = nActions - 1; i >= 0; -- i ) {
  26230. actions[ i ].stop();
  26231. }
  26232. return this;
  26233. },
  26234. // advance the time and update apply the animation
  26235. update: function ( deltaTime ) {
  26236. deltaTime *= this.timeScale;
  26237. const actions = this._actions,
  26238. nActions = this._nActiveActions,
  26239. time = this.time += deltaTime,
  26240. timeDirection = Math.sign( deltaTime ),
  26241. accuIndex = this._accuIndex ^= 1;
  26242. // run active actions
  26243. for ( let i = 0; i !== nActions; ++ i ) {
  26244. const action = actions[ i ];
  26245. action._update( time, deltaTime, timeDirection, accuIndex );
  26246. }
  26247. // update scene graph
  26248. const bindings = this._bindings,
  26249. nBindings = this._nActiveBindings;
  26250. for ( let i = 0; i !== nBindings; ++ i ) {
  26251. bindings[ i ].apply( accuIndex );
  26252. }
  26253. return this;
  26254. },
  26255. // Allows you to seek to a specific time in an animation.
  26256. setTime: function ( timeInSeconds ) {
  26257. this.time = 0; // Zero out time attribute for AnimationMixer object;
  26258. for ( let i = 0; i < this._actions.length; i ++ ) {
  26259. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  26260. }
  26261. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  26262. },
  26263. // return this mixer's root target object
  26264. getRoot: function () {
  26265. return this._root;
  26266. },
  26267. // free all resources specific to a particular clip
  26268. uncacheClip: function ( clip ) {
  26269. const actions = this._actions,
  26270. clipUuid = clip.uuid,
  26271. actionsByClip = this._actionsByClip,
  26272. actionsForClip = actionsByClip[ clipUuid ];
  26273. if ( actionsForClip !== undefined ) {
  26274. // note: just calling _removeInactiveAction would mess up the
  26275. // iteration state and also require updating the state we can
  26276. // just throw away
  26277. const actionsToRemove = actionsForClip.knownActions;
  26278. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26279. const action = actionsToRemove[ i ];
  26280. this._deactivateAction( action );
  26281. const cacheIndex = action._cacheIndex,
  26282. lastInactiveAction = actions[ actions.length - 1 ];
  26283. action._cacheIndex = null;
  26284. action._byClipCacheIndex = null;
  26285. lastInactiveAction._cacheIndex = cacheIndex;
  26286. actions[ cacheIndex ] = lastInactiveAction;
  26287. actions.pop();
  26288. this._removeInactiveBindingsForAction( action );
  26289. }
  26290. delete actionsByClip[ clipUuid ];
  26291. }
  26292. },
  26293. // free all resources specific to a particular root target object
  26294. uncacheRoot: function ( root ) {
  26295. const rootUuid = root.uuid,
  26296. actionsByClip = this._actionsByClip;
  26297. for ( const clipUuid in actionsByClip ) {
  26298. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26299. action = actionByRoot[ rootUuid ];
  26300. if ( action !== undefined ) {
  26301. this._deactivateAction( action );
  26302. this._removeInactiveAction( action );
  26303. }
  26304. }
  26305. const bindingsByRoot = this._bindingsByRootAndName,
  26306. bindingByName = bindingsByRoot[ rootUuid ];
  26307. if ( bindingByName !== undefined ) {
  26308. for ( const trackName in bindingByName ) {
  26309. const binding = bindingByName[ trackName ];
  26310. binding.restoreOriginalState();
  26311. this._removeInactiveBinding( binding );
  26312. }
  26313. }
  26314. },
  26315. // remove a targeted clip from the cache
  26316. uncacheAction: function ( clip, optionalRoot ) {
  26317. const action = this.existingAction( clip, optionalRoot );
  26318. if ( action !== null ) {
  26319. this._deactivateAction( action );
  26320. this._removeInactiveAction( action );
  26321. }
  26322. }
  26323. } );
  26324. class Uniform {
  26325. constructor( value ) {
  26326. if ( typeof value === 'string' ) {
  26327. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26328. value = arguments[ 1 ];
  26329. }
  26330. this.value = value;
  26331. }
  26332. clone() {
  26333. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26334. }
  26335. }
  26336. let _geometryId = 0; // Geometry uses even numbers as Id
  26337. const _m1$3 = new Matrix4();
  26338. const _obj$1 = new Object3D();
  26339. const _offset$1 = new Vector3();
  26340. function Geometry() {
  26341. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  26342. this.uuid = MathUtils.generateUUID();
  26343. this.name = '';
  26344. this.type = 'Geometry';
  26345. this.vertices = [];
  26346. this.colors = [];
  26347. this.faces = [];
  26348. this.faceVertexUvs = [[]];
  26349. this.morphTargets = [];
  26350. this.morphNormals = [];
  26351. this.skinWeights = [];
  26352. this.skinIndices = [];
  26353. this.lineDistances = [];
  26354. this.boundingBox = null;
  26355. this.boundingSphere = null;
  26356. // update flags
  26357. this.elementsNeedUpdate = false;
  26358. this.verticesNeedUpdate = false;
  26359. this.uvsNeedUpdate = false;
  26360. this.normalsNeedUpdate = false;
  26361. this.colorsNeedUpdate = false;
  26362. this.lineDistancesNeedUpdate = false;
  26363. this.groupsNeedUpdate = false;
  26364. }
  26365. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26366. constructor: Geometry,
  26367. isGeometry: true,
  26368. applyMatrix4: function ( matrix ) {
  26369. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  26370. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  26371. const vertex = this.vertices[ i ];
  26372. vertex.applyMatrix4( matrix );
  26373. }
  26374. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  26375. const face = this.faces[ i ];
  26376. face.normal.applyMatrix3( normalMatrix ).normalize();
  26377. for ( let j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26378. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  26379. }
  26380. }
  26381. if ( this.boundingBox !== null ) {
  26382. this.computeBoundingBox();
  26383. }
  26384. if ( this.boundingSphere !== null ) {
  26385. this.computeBoundingSphere();
  26386. }
  26387. this.verticesNeedUpdate = true;
  26388. this.normalsNeedUpdate = true;
  26389. return this;
  26390. },
  26391. rotateX: function ( angle ) {
  26392. // rotate geometry around world x-axis
  26393. _m1$3.makeRotationX( angle );
  26394. this.applyMatrix4( _m1$3 );
  26395. return this;
  26396. },
  26397. rotateY: function ( angle ) {
  26398. // rotate geometry around world y-axis
  26399. _m1$3.makeRotationY( angle );
  26400. this.applyMatrix4( _m1$3 );
  26401. return this;
  26402. },
  26403. rotateZ: function ( angle ) {
  26404. // rotate geometry around world z-axis
  26405. _m1$3.makeRotationZ( angle );
  26406. this.applyMatrix4( _m1$3 );
  26407. return this;
  26408. },
  26409. translate: function ( x, y, z ) {
  26410. // translate geometry
  26411. _m1$3.makeTranslation( x, y, z );
  26412. this.applyMatrix4( _m1$3 );
  26413. return this;
  26414. },
  26415. scale: function ( x, y, z ) {
  26416. // scale geometry
  26417. _m1$3.makeScale( x, y, z );
  26418. this.applyMatrix4( _m1$3 );
  26419. return this;
  26420. },
  26421. lookAt: function ( vector ) {
  26422. _obj$1.lookAt( vector );
  26423. _obj$1.updateMatrix();
  26424. this.applyMatrix4( _obj$1.matrix );
  26425. return this;
  26426. },
  26427. fromBufferGeometry: function ( geometry ) {
  26428. const scope = this;
  26429. const index = geometry.index !== null ? geometry.index : undefined;
  26430. const attributes = geometry.attributes;
  26431. if ( attributes.position === undefined ) {
  26432. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  26433. return this;
  26434. }
  26435. const position = attributes.position;
  26436. const normal = attributes.normal;
  26437. const color = attributes.color;
  26438. const uv = attributes.uv;
  26439. const uv2 = attributes.uv2;
  26440. if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  26441. for ( let i = 0; i < position.count; i ++ ) {
  26442. scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
  26443. if ( color !== undefined ) {
  26444. scope.colors.push( new Color().fromBufferAttribute( color, i ) );
  26445. }
  26446. }
  26447. function addFace( a, b, c, materialIndex ) {
  26448. const vertexColors = ( color === undefined ) ? [] : [
  26449. scope.colors[ a ].clone(),
  26450. scope.colors[ b ].clone(),
  26451. scope.colors[ c ].clone()
  26452. ];
  26453. const vertexNormals = ( normal === undefined ) ? [] : [
  26454. new Vector3().fromBufferAttribute( normal, a ),
  26455. new Vector3().fromBufferAttribute( normal, b ),
  26456. new Vector3().fromBufferAttribute( normal, c )
  26457. ];
  26458. const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  26459. scope.faces.push( face );
  26460. if ( uv !== undefined ) {
  26461. scope.faceVertexUvs[ 0 ].push( [
  26462. new Vector2().fromBufferAttribute( uv, a ),
  26463. new Vector2().fromBufferAttribute( uv, b ),
  26464. new Vector2().fromBufferAttribute( uv, c )
  26465. ] );
  26466. }
  26467. if ( uv2 !== undefined ) {
  26468. scope.faceVertexUvs[ 1 ].push( [
  26469. new Vector2().fromBufferAttribute( uv2, a ),
  26470. new Vector2().fromBufferAttribute( uv2, b ),
  26471. new Vector2().fromBufferAttribute( uv2, c )
  26472. ] );
  26473. }
  26474. }
  26475. const groups = geometry.groups;
  26476. if ( groups.length > 0 ) {
  26477. for ( let i = 0; i < groups.length; i ++ ) {
  26478. const group = groups[ i ];
  26479. const start = group.start;
  26480. const count = group.count;
  26481. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  26482. if ( index !== undefined ) {
  26483. addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
  26484. } else {
  26485. addFace( j, j + 1, j + 2, group.materialIndex );
  26486. }
  26487. }
  26488. }
  26489. } else {
  26490. if ( index !== undefined ) {
  26491. for ( let i = 0; i < index.count; i += 3 ) {
  26492. addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
  26493. }
  26494. } else {
  26495. for ( let i = 0; i < position.count; i += 3 ) {
  26496. addFace( i, i + 1, i + 2 );
  26497. }
  26498. }
  26499. }
  26500. this.computeFaceNormals();
  26501. if ( geometry.boundingBox !== null ) {
  26502. this.boundingBox = geometry.boundingBox.clone();
  26503. }
  26504. if ( geometry.boundingSphere !== null ) {
  26505. this.boundingSphere = geometry.boundingSphere.clone();
  26506. }
  26507. return this;
  26508. },
  26509. center: function () {
  26510. this.computeBoundingBox();
  26511. this.boundingBox.getCenter( _offset$1 ).negate();
  26512. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  26513. return this;
  26514. },
  26515. normalize: function () {
  26516. this.computeBoundingSphere();
  26517. const center = this.boundingSphere.center;
  26518. const radius = this.boundingSphere.radius;
  26519. const s = radius === 0 ? 1 : 1.0 / radius;
  26520. const matrix = new Matrix4();
  26521. matrix.set(
  26522. s, 0, 0, - s * center.x,
  26523. 0, s, 0, - s * center.y,
  26524. 0, 0, s, - s * center.z,
  26525. 0, 0, 0, 1
  26526. );
  26527. this.applyMatrix4( matrix );
  26528. return this;
  26529. },
  26530. computeFaceNormals: function () {
  26531. const cb = new Vector3(), ab = new Vector3();
  26532. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26533. const face = this.faces[ f ];
  26534. const vA = this.vertices[ face.a ];
  26535. const vB = this.vertices[ face.b ];
  26536. const vC = this.vertices[ face.c ];
  26537. cb.subVectors( vC, vB );
  26538. ab.subVectors( vA, vB );
  26539. cb.cross( ab );
  26540. cb.normalize();
  26541. face.normal.copy( cb );
  26542. }
  26543. },
  26544. computeVertexNormals: function ( areaWeighted = true ) {
  26545. const vertices = new Array( this.vertices.length );
  26546. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  26547. vertices[ v ] = new Vector3();
  26548. }
  26549. if ( areaWeighted ) {
  26550. // vertex normals weighted by triangle areas
  26551. // http://www.iquilezles.org/www/articles/normals/normals.htm
  26552. const cb = new Vector3(), ab = new Vector3();
  26553. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26554. const face = this.faces[ f ];
  26555. const vA = this.vertices[ face.a ];
  26556. const vB = this.vertices[ face.b ];
  26557. const vC = this.vertices[ face.c ];
  26558. cb.subVectors( vC, vB );
  26559. ab.subVectors( vA, vB );
  26560. cb.cross( ab );
  26561. vertices[ face.a ].add( cb );
  26562. vertices[ face.b ].add( cb );
  26563. vertices[ face.c ].add( cb );
  26564. }
  26565. } else {
  26566. this.computeFaceNormals();
  26567. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26568. const face = this.faces[ f ];
  26569. vertices[ face.a ].add( face.normal );
  26570. vertices[ face.b ].add( face.normal );
  26571. vertices[ face.c ].add( face.normal );
  26572. }
  26573. }
  26574. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  26575. vertices[ v ].normalize();
  26576. }
  26577. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26578. const face = this.faces[ f ];
  26579. const vertexNormals = face.vertexNormals;
  26580. if ( vertexNormals.length === 3 ) {
  26581. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  26582. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  26583. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  26584. } else {
  26585. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  26586. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  26587. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  26588. }
  26589. }
  26590. if ( this.faces.length > 0 ) {
  26591. this.normalsNeedUpdate = true;
  26592. }
  26593. },
  26594. computeFlatVertexNormals: function () {
  26595. this.computeFaceNormals();
  26596. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26597. const face = this.faces[ f ];
  26598. const vertexNormals = face.vertexNormals;
  26599. if ( vertexNormals.length === 3 ) {
  26600. vertexNormals[ 0 ].copy( face.normal );
  26601. vertexNormals[ 1 ].copy( face.normal );
  26602. vertexNormals[ 2 ].copy( face.normal );
  26603. } else {
  26604. vertexNormals[ 0 ] = face.normal.clone();
  26605. vertexNormals[ 1 ] = face.normal.clone();
  26606. vertexNormals[ 2 ] = face.normal.clone();
  26607. }
  26608. }
  26609. if ( this.faces.length > 0 ) {
  26610. this.normalsNeedUpdate = true;
  26611. }
  26612. },
  26613. computeMorphNormals: function () {
  26614. // save original normals
  26615. // - create temp variables on first access
  26616. // otherwise just copy (for faster repeated calls)
  26617. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26618. const face = this.faces[ f ];
  26619. if ( ! face.__originalFaceNormal ) {
  26620. face.__originalFaceNormal = face.normal.clone();
  26621. } else {
  26622. face.__originalFaceNormal.copy( face.normal );
  26623. }
  26624. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  26625. for ( let i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  26626. if ( ! face.__originalVertexNormals[ i ] ) {
  26627. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  26628. } else {
  26629. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  26630. }
  26631. }
  26632. }
  26633. // use temp geometry to compute face and vertex normals for each morph
  26634. const tmpGeo = new Geometry();
  26635. tmpGeo.faces = this.faces;
  26636. for ( let i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  26637. // create on first access
  26638. if ( ! this.morphNormals[ i ] ) {
  26639. this.morphNormals[ i ] = {};
  26640. this.morphNormals[ i ].faceNormals = [];
  26641. this.morphNormals[ i ].vertexNormals = [];
  26642. const dstNormalsFace = this.morphNormals[ i ].faceNormals;
  26643. const dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  26644. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26645. const faceNormal = new Vector3();
  26646. const vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  26647. dstNormalsFace.push( faceNormal );
  26648. dstNormalsVertex.push( vertexNormals );
  26649. }
  26650. }
  26651. const morphNormals = this.morphNormals[ i ];
  26652. // set vertices to morph target
  26653. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  26654. // compute morph normals
  26655. tmpGeo.computeFaceNormals();
  26656. tmpGeo.computeVertexNormals();
  26657. // store morph normals
  26658. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26659. const face = this.faces[ f ];
  26660. const faceNormal = morphNormals.faceNormals[ f ];
  26661. const vertexNormals = morphNormals.vertexNormals[ f ];
  26662. faceNormal.copy( face.normal );
  26663. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  26664. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  26665. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  26666. }
  26667. }
  26668. // restore original normals
  26669. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  26670. const face = this.faces[ f ];
  26671. face.normal = face.__originalFaceNormal;
  26672. face.vertexNormals = face.__originalVertexNormals;
  26673. }
  26674. },
  26675. computeBoundingBox: function () {
  26676. if ( this.boundingBox === null ) {
  26677. this.boundingBox = new Box3();
  26678. }
  26679. this.boundingBox.setFromPoints( this.vertices );
  26680. },
  26681. computeBoundingSphere: function () {
  26682. if ( this.boundingSphere === null ) {
  26683. this.boundingSphere = new Sphere();
  26684. }
  26685. this.boundingSphere.setFromPoints( this.vertices );
  26686. },
  26687. merge: function ( geometry, matrix, materialIndexOffset = 0 ) {
  26688. if ( ! ( geometry && geometry.isGeometry ) ) {
  26689. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  26690. return;
  26691. }
  26692. let normalMatrix;
  26693. const vertexOffset = this.vertices.length,
  26694. vertices1 = this.vertices,
  26695. vertices2 = geometry.vertices,
  26696. faces1 = this.faces,
  26697. faces2 = geometry.faces,
  26698. colors1 = this.colors,
  26699. colors2 = geometry.colors;
  26700. if ( matrix !== undefined ) {
  26701. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  26702. }
  26703. // vertices
  26704. for ( let i = 0, il = vertices2.length; i < il; i ++ ) {
  26705. const vertex = vertices2[ i ];
  26706. const vertexCopy = vertex.clone();
  26707. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  26708. vertices1.push( vertexCopy );
  26709. }
  26710. // colors
  26711. for ( let i = 0, il = colors2.length; i < il; i ++ ) {
  26712. colors1.push( colors2[ i ].clone() );
  26713. }
  26714. // faces
  26715. for ( let i = 0, il = faces2.length; i < il; i ++ ) {
  26716. const face = faces2[ i ];
  26717. let normal, color;
  26718. const faceVertexNormals = face.vertexNormals,
  26719. faceVertexColors = face.vertexColors;
  26720. const faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  26721. faceCopy.normal.copy( face.normal );
  26722. if ( normalMatrix !== undefined ) {
  26723. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  26724. }
  26725. for ( let j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  26726. normal = faceVertexNormals[ j ].clone();
  26727. if ( normalMatrix !== undefined ) {
  26728. normal.applyMatrix3( normalMatrix ).normalize();
  26729. }
  26730. faceCopy.vertexNormals.push( normal );
  26731. }
  26732. faceCopy.color.copy( face.color );
  26733. for ( let j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  26734. color = faceVertexColors[ j ];
  26735. faceCopy.vertexColors.push( color.clone() );
  26736. }
  26737. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  26738. faces1.push( faceCopy );
  26739. }
  26740. // uvs
  26741. for ( let i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  26742. const faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  26743. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  26744. for ( let j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  26745. const uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  26746. for ( let k = 0, kl = uvs2.length; k < kl; k ++ ) {
  26747. uvsCopy.push( uvs2[ k ].clone() );
  26748. }
  26749. this.faceVertexUvs[ i ].push( uvsCopy );
  26750. }
  26751. }
  26752. },
  26753. mergeMesh: function ( mesh ) {
  26754. if ( ! ( mesh && mesh.isMesh ) ) {
  26755. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  26756. return;
  26757. }
  26758. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  26759. this.merge( mesh.geometry, mesh.matrix );
  26760. },
  26761. /*
  26762. * Checks for duplicate vertices with hashmap.
  26763. * Duplicated vertices are removed
  26764. * and faces' vertices are updated.
  26765. */
  26766. mergeVertices: function ( precisionPoints = 4 ) {
  26767. const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  26768. const unique = [], changes = [];
  26769. const precision = Math.pow( 10, precisionPoints );
  26770. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  26771. const v = this.vertices[ i ];
  26772. const key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  26773. if ( verticesMap[ key ] === undefined ) {
  26774. verticesMap[ key ] = i;
  26775. unique.push( this.vertices[ i ] );
  26776. changes[ i ] = unique.length - 1;
  26777. } else {
  26778. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  26779. changes[ i ] = changes[ verticesMap[ key ] ];
  26780. }
  26781. }
  26782. // if faces are completely degenerate after merging vertices, we
  26783. // have to remove them from the geometry.
  26784. const faceIndicesToRemove = [];
  26785. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  26786. const face = this.faces[ i ];
  26787. face.a = changes[ face.a ];
  26788. face.b = changes[ face.b ];
  26789. face.c = changes[ face.c ];
  26790. const indices = [ face.a, face.b, face.c ];
  26791. // if any duplicate vertices are found in a Face3
  26792. // we have to remove the face as nothing can be saved
  26793. for ( let n = 0; n < 3; n ++ ) {
  26794. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  26795. faceIndicesToRemove.push( i );
  26796. break;
  26797. }
  26798. }
  26799. }
  26800. for ( let i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  26801. const idx = faceIndicesToRemove[ i ];
  26802. this.faces.splice( idx, 1 );
  26803. for ( let j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  26804. this.faceVertexUvs[ j ].splice( idx, 1 );
  26805. }
  26806. }
  26807. // Use unique set of vertices
  26808. const diff = this.vertices.length - unique.length;
  26809. this.vertices = unique;
  26810. return diff;
  26811. },
  26812. setFromPoints: function ( points ) {
  26813. this.vertices = [];
  26814. for ( let i = 0, l = points.length; i < l; i ++ ) {
  26815. const point = points[ i ];
  26816. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  26817. }
  26818. return this;
  26819. },
  26820. sortFacesByMaterialIndex: function () {
  26821. const faces = this.faces;
  26822. const length = faces.length;
  26823. // tag faces
  26824. for ( let i = 0; i < length; i ++ ) {
  26825. faces[ i ]._id = i;
  26826. }
  26827. // sort faces
  26828. function materialIndexSort( a, b ) {
  26829. return a.materialIndex - b.materialIndex;
  26830. }
  26831. faces.sort( materialIndexSort );
  26832. // sort uvs
  26833. const uvs1 = this.faceVertexUvs[ 0 ];
  26834. const uvs2 = this.faceVertexUvs[ 1 ];
  26835. let newUvs1, newUvs2;
  26836. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  26837. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  26838. for ( let i = 0; i < length; i ++ ) {
  26839. const id = faces[ i ]._id;
  26840. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  26841. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  26842. }
  26843. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  26844. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  26845. },
  26846. toJSON: function () {
  26847. const data = {
  26848. metadata: {
  26849. version: 4.5,
  26850. type: 'Geometry',
  26851. generator: 'Geometry.toJSON'
  26852. }
  26853. };
  26854. // standard Geometry serialization
  26855. data.uuid = this.uuid;
  26856. data.type = this.type;
  26857. if ( this.name !== '' ) data.name = this.name;
  26858. if ( this.parameters !== undefined ) {
  26859. const parameters = this.parameters;
  26860. for ( const key in parameters ) {
  26861. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  26862. }
  26863. return data;
  26864. }
  26865. const vertices = [];
  26866. for ( let i = 0; i < this.vertices.length; i ++ ) {
  26867. const vertex = this.vertices[ i ];
  26868. vertices.push( vertex.x, vertex.y, vertex.z );
  26869. }
  26870. const faces = [];
  26871. const normals = [];
  26872. const normalsHash = {};
  26873. const colors = [];
  26874. const colorsHash = {};
  26875. const uvs = [];
  26876. const uvsHash = {};
  26877. for ( let i = 0; i < this.faces.length; i ++ ) {
  26878. const face = this.faces[ i ];
  26879. const hasMaterial = true;
  26880. const hasFaceUv = false; // deprecated
  26881. const hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  26882. const hasFaceNormal = face.normal.length() > 0;
  26883. const hasFaceVertexNormal = face.vertexNormals.length > 0;
  26884. const hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  26885. const hasFaceVertexColor = face.vertexColors.length > 0;
  26886. let faceType = 0;
  26887. faceType = setBit( faceType, 0, 0 ); // isQuad
  26888. faceType = setBit( faceType, 1, hasMaterial );
  26889. faceType = setBit( faceType, 2, hasFaceUv );
  26890. faceType = setBit( faceType, 3, hasFaceVertexUv );
  26891. faceType = setBit( faceType, 4, hasFaceNormal );
  26892. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  26893. faceType = setBit( faceType, 6, hasFaceColor );
  26894. faceType = setBit( faceType, 7, hasFaceVertexColor );
  26895. faces.push( faceType );
  26896. faces.push( face.a, face.b, face.c );
  26897. faces.push( face.materialIndex );
  26898. if ( hasFaceVertexUv ) {
  26899. const faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  26900. faces.push(
  26901. getUvIndex( faceVertexUvs[ 0 ] ),
  26902. getUvIndex( faceVertexUvs[ 1 ] ),
  26903. getUvIndex( faceVertexUvs[ 2 ] )
  26904. );
  26905. }
  26906. if ( hasFaceNormal ) {
  26907. faces.push( getNormalIndex( face.normal ) );
  26908. }
  26909. if ( hasFaceVertexNormal ) {
  26910. const vertexNormals = face.vertexNormals;
  26911. faces.push(
  26912. getNormalIndex( vertexNormals[ 0 ] ),
  26913. getNormalIndex( vertexNormals[ 1 ] ),
  26914. getNormalIndex( vertexNormals[ 2 ] )
  26915. );
  26916. }
  26917. if ( hasFaceColor ) {
  26918. faces.push( getColorIndex( face.color ) );
  26919. }
  26920. if ( hasFaceVertexColor ) {
  26921. const vertexColors = face.vertexColors;
  26922. faces.push(
  26923. getColorIndex( vertexColors[ 0 ] ),
  26924. getColorIndex( vertexColors[ 1 ] ),
  26925. getColorIndex( vertexColors[ 2 ] )
  26926. );
  26927. }
  26928. }
  26929. function setBit( value, position, enabled ) {
  26930. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  26931. }
  26932. function getNormalIndex( normal ) {
  26933. const hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  26934. if ( normalsHash[ hash ] !== undefined ) {
  26935. return normalsHash[ hash ];
  26936. }
  26937. normalsHash[ hash ] = normals.length / 3;
  26938. normals.push( normal.x, normal.y, normal.z );
  26939. return normalsHash[ hash ];
  26940. }
  26941. function getColorIndex( color ) {
  26942. const hash = color.r.toString() + color.g.toString() + color.b.toString();
  26943. if ( colorsHash[ hash ] !== undefined ) {
  26944. return colorsHash[ hash ];
  26945. }
  26946. colorsHash[ hash ] = colors.length;
  26947. colors.push( color.getHex() );
  26948. return colorsHash[ hash ];
  26949. }
  26950. function getUvIndex( uv ) {
  26951. const hash = uv.x.toString() + uv.y.toString();
  26952. if ( uvsHash[ hash ] !== undefined ) {
  26953. return uvsHash[ hash ];
  26954. }
  26955. uvsHash[ hash ] = uvs.length / 2;
  26956. uvs.push( uv.x, uv.y );
  26957. return uvsHash[ hash ];
  26958. }
  26959. data.data = {};
  26960. data.data.vertices = vertices;
  26961. data.data.normals = normals;
  26962. if ( colors.length > 0 ) data.data.colors = colors;
  26963. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  26964. data.data.faces = faces;
  26965. return data;
  26966. },
  26967. clone: function () {
  26968. /*
  26969. // Handle primitives
  26970. const parameters = this.parameters;
  26971. if ( parameters !== undefined ) {
  26972. const values = [];
  26973. for ( const key in parameters ) {
  26974. values.push( parameters[ key ] );
  26975. }
  26976. const geometry = Object.create( this.constructor.prototype );
  26977. this.constructor.apply( geometry, values );
  26978. return geometry;
  26979. }
  26980. return new this.constructor().copy( this );
  26981. */
  26982. return new Geometry().copy( this );
  26983. },
  26984. copy: function ( source ) {
  26985. // reset
  26986. this.vertices = [];
  26987. this.colors = [];
  26988. this.faces = [];
  26989. this.faceVertexUvs = [[]];
  26990. this.morphTargets = [];
  26991. this.morphNormals = [];
  26992. this.skinWeights = [];
  26993. this.skinIndices = [];
  26994. this.lineDistances = [];
  26995. this.boundingBox = null;
  26996. this.boundingSphere = null;
  26997. // name
  26998. this.name = source.name;
  26999. // vertices
  27000. const vertices = source.vertices;
  27001. for ( let i = 0, il = vertices.length; i < il; i ++ ) {
  27002. this.vertices.push( vertices[ i ].clone() );
  27003. }
  27004. // colors
  27005. const colors = source.colors;
  27006. for ( let i = 0, il = colors.length; i < il; i ++ ) {
  27007. this.colors.push( colors[ i ].clone() );
  27008. }
  27009. // faces
  27010. const faces = source.faces;
  27011. for ( let i = 0, il = faces.length; i < il; i ++ ) {
  27012. this.faces.push( faces[ i ].clone() );
  27013. }
  27014. // face vertex uvs
  27015. for ( let i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  27016. const faceVertexUvs = source.faceVertexUvs[ i ];
  27017. if ( this.faceVertexUvs[ i ] === undefined ) {
  27018. this.faceVertexUvs[ i ] = [];
  27019. }
  27020. for ( let j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  27021. const uvs = faceVertexUvs[ j ], uvsCopy = [];
  27022. for ( let k = 0, kl = uvs.length; k < kl; k ++ ) {
  27023. const uv = uvs[ k ];
  27024. uvsCopy.push( uv.clone() );
  27025. }
  27026. this.faceVertexUvs[ i ].push( uvsCopy );
  27027. }
  27028. }
  27029. // morph targets
  27030. const morphTargets = source.morphTargets;
  27031. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  27032. const morphTarget = {};
  27033. morphTarget.name = morphTargets[ i ].name;
  27034. // vertices
  27035. if ( morphTargets[ i ].vertices !== undefined ) {
  27036. morphTarget.vertices = [];
  27037. for ( let j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  27038. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  27039. }
  27040. }
  27041. // normals
  27042. if ( morphTargets[ i ].normals !== undefined ) {
  27043. morphTarget.normals = [];
  27044. for ( let j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  27045. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  27046. }
  27047. }
  27048. this.morphTargets.push( morphTarget );
  27049. }
  27050. // morph normals
  27051. const morphNormals = source.morphNormals;
  27052. for ( let i = 0, il = morphNormals.length; i < il; i ++ ) {
  27053. const morphNormal = {};
  27054. // vertex normals
  27055. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  27056. morphNormal.vertexNormals = [];
  27057. for ( let j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  27058. const srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  27059. const destVertexNormal = {};
  27060. destVertexNormal.a = srcVertexNormal.a.clone();
  27061. destVertexNormal.b = srcVertexNormal.b.clone();
  27062. destVertexNormal.c = srcVertexNormal.c.clone();
  27063. morphNormal.vertexNormals.push( destVertexNormal );
  27064. }
  27065. }
  27066. // face normals
  27067. if ( morphNormals[ i ].faceNormals !== undefined ) {
  27068. morphNormal.faceNormals = [];
  27069. for ( let j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  27070. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  27071. }
  27072. }
  27073. this.morphNormals.push( morphNormal );
  27074. }
  27075. // skin weights
  27076. const skinWeights = source.skinWeights;
  27077. for ( let i = 0, il = skinWeights.length; i < il; i ++ ) {
  27078. this.skinWeights.push( skinWeights[ i ].clone() );
  27079. }
  27080. // skin indices
  27081. const skinIndices = source.skinIndices;
  27082. for ( let i = 0, il = skinIndices.length; i < il; i ++ ) {
  27083. this.skinIndices.push( skinIndices[ i ].clone() );
  27084. }
  27085. // line distances
  27086. const lineDistances = source.lineDistances;
  27087. for ( let i = 0, il = lineDistances.length; i < il; i ++ ) {
  27088. this.lineDistances.push( lineDistances[ i ] );
  27089. }
  27090. // bounding box
  27091. const boundingBox = source.boundingBox;
  27092. if ( boundingBox !== null ) {
  27093. this.boundingBox = boundingBox.clone();
  27094. }
  27095. // bounding sphere
  27096. const boundingSphere = source.boundingSphere;
  27097. if ( boundingSphere !== null ) {
  27098. this.boundingSphere = boundingSphere.clone();
  27099. }
  27100. // update flags
  27101. this.elementsNeedUpdate = source.elementsNeedUpdate;
  27102. this.verticesNeedUpdate = source.verticesNeedUpdate;
  27103. this.uvsNeedUpdate = source.uvsNeedUpdate;
  27104. this.normalsNeedUpdate = source.normalsNeedUpdate;
  27105. this.colorsNeedUpdate = source.colorsNeedUpdate;
  27106. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  27107. this.groupsNeedUpdate = source.groupsNeedUpdate;
  27108. return this;
  27109. },
  27110. dispose: function () {
  27111. this.dispatchEvent( { type: 'dispose' } );
  27112. }
  27113. } );
  27114. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27115. InterleavedBuffer.call( this, array, stride );
  27116. this.meshPerAttribute = meshPerAttribute || 1;
  27117. }
  27118. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27119. constructor: InstancedInterleavedBuffer,
  27120. isInstancedInterleavedBuffer: true,
  27121. copy: function ( source ) {
  27122. InterleavedBuffer.prototype.copy.call( this, source );
  27123. this.meshPerAttribute = source.meshPerAttribute;
  27124. return this;
  27125. },
  27126. clone: function ( data ) {
  27127. const ib = InterleavedBuffer.prototype.clone.call( this, data );
  27128. ib.meshPerAttribute = this.meshPerAttribute;
  27129. return ib;
  27130. },
  27131. toJSON: function ( data ) {
  27132. const json = InterleavedBuffer.prototype.toJSON.call( this, data );
  27133. json.isInstancedInterleavedBuffer = true;
  27134. json.meshPerAttribute = this.meshPerAttribute;
  27135. return json;
  27136. }
  27137. } );
  27138. function GLBufferAttribute( buffer, type, itemSize, elementSize, count ) {
  27139. this.buffer = buffer;
  27140. this.type = type;
  27141. this.itemSize = itemSize;
  27142. this.elementSize = elementSize;
  27143. this.count = count;
  27144. this.version = 0;
  27145. }
  27146. Object.defineProperty( GLBufferAttribute.prototype, 'needsUpdate', {
  27147. set: function ( value ) {
  27148. if ( value === true ) this.version ++;
  27149. }
  27150. } );
  27151. Object.assign( GLBufferAttribute.prototype, {
  27152. isGLBufferAttribute: true,
  27153. setBuffer: function ( buffer ) {
  27154. this.buffer = buffer;
  27155. return this;
  27156. },
  27157. setType: function ( type, elementSize ) {
  27158. this.type = type;
  27159. this.elementSize = elementSize;
  27160. return this;
  27161. },
  27162. setItemSize: function ( itemSize ) {
  27163. this.itemSize = itemSize;
  27164. return this;
  27165. },
  27166. setCount: function ( count ) {
  27167. this.count = count;
  27168. return this;
  27169. },
  27170. } );
  27171. function Raycaster( origin, direction, near, far ) {
  27172. this.ray = new Ray( origin, direction );
  27173. // direction is assumed to be normalized (for accurate distance calculations)
  27174. this.near = near || 0;
  27175. this.far = far || Infinity;
  27176. this.camera = null;
  27177. this.layers = new Layers();
  27178. this.params = {
  27179. Mesh: {},
  27180. Line: { threshold: 1 },
  27181. LOD: {},
  27182. Points: { threshold: 1 },
  27183. Sprite: {}
  27184. };
  27185. Object.defineProperties( this.params, {
  27186. PointCloud: {
  27187. get: function () {
  27188. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27189. return this.Points;
  27190. }
  27191. }
  27192. } );
  27193. }
  27194. function ascSort( a, b ) {
  27195. return a.distance - b.distance;
  27196. }
  27197. function intersectObject( object, raycaster, intersects, recursive ) {
  27198. if ( object.layers.test( raycaster.layers ) ) {
  27199. object.raycast( raycaster, intersects );
  27200. }
  27201. if ( recursive === true ) {
  27202. const children = object.children;
  27203. for ( let i = 0, l = children.length; i < l; i ++ ) {
  27204. intersectObject( children[ i ], raycaster, intersects, true );
  27205. }
  27206. }
  27207. }
  27208. Object.assign( Raycaster.prototype, {
  27209. set: function ( origin, direction ) {
  27210. // direction is assumed to be normalized (for accurate distance calculations)
  27211. this.ray.set( origin, direction );
  27212. },
  27213. setFromCamera: function ( coords, camera ) {
  27214. if ( camera && camera.isPerspectiveCamera ) {
  27215. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27216. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27217. this.camera = camera;
  27218. } else if ( camera && camera.isOrthographicCamera ) {
  27219. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27220. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27221. this.camera = camera;
  27222. } else {
  27223. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  27224. }
  27225. },
  27226. intersectObject: function ( object, recursive, optionalTarget ) {
  27227. const intersects = optionalTarget || [];
  27228. intersectObject( object, this, intersects, recursive );
  27229. intersects.sort( ascSort );
  27230. return intersects;
  27231. },
  27232. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27233. const intersects = optionalTarget || [];
  27234. if ( Array.isArray( objects ) === false ) {
  27235. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27236. return intersects;
  27237. }
  27238. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  27239. intersectObject( objects[ i ], this, intersects, recursive );
  27240. }
  27241. intersects.sort( ascSort );
  27242. return intersects;
  27243. }
  27244. } );
  27245. /**
  27246. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27247. *
  27248. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27249. * The azimuthal angle (theta) is measured from the positive z-axis.
  27250. */
  27251. class Spherical {
  27252. constructor( radius = 1, phi = 0, theta = 0 ) {
  27253. this.radius = radius;
  27254. this.phi = phi; // polar angle
  27255. this.theta = theta; // azimuthal angle
  27256. return this;
  27257. }
  27258. set( radius, phi, theta ) {
  27259. this.radius = radius;
  27260. this.phi = phi;
  27261. this.theta = theta;
  27262. return this;
  27263. }
  27264. clone() {
  27265. return new this.constructor().copy( this );
  27266. }
  27267. copy( other ) {
  27268. this.radius = other.radius;
  27269. this.phi = other.phi;
  27270. this.theta = other.theta;
  27271. return this;
  27272. }
  27273. // restrict phi to be betwee EPS and PI-EPS
  27274. makeSafe() {
  27275. const EPS = 0.000001;
  27276. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27277. return this;
  27278. }
  27279. setFromVector3( v ) {
  27280. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27281. }
  27282. setFromCartesianCoords( x, y, z ) {
  27283. this.radius = Math.sqrt( x * x + y * y + z * z );
  27284. if ( this.radius === 0 ) {
  27285. this.theta = 0;
  27286. this.phi = 0;
  27287. } else {
  27288. this.theta = Math.atan2( x, z );
  27289. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  27290. }
  27291. return this;
  27292. }
  27293. }
  27294. /**
  27295. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27296. */
  27297. class Cylindrical {
  27298. constructor( radius, theta, y ) {
  27299. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27300. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27301. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  27302. return this;
  27303. }
  27304. set( radius, theta, y ) {
  27305. this.radius = radius;
  27306. this.theta = theta;
  27307. this.y = y;
  27308. return this;
  27309. }
  27310. clone() {
  27311. return new this.constructor().copy( this );
  27312. }
  27313. copy( other ) {
  27314. this.radius = other.radius;
  27315. this.theta = other.theta;
  27316. this.y = other.y;
  27317. return this;
  27318. }
  27319. setFromVector3( v ) {
  27320. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27321. }
  27322. setFromCartesianCoords( x, y, z ) {
  27323. this.radius = Math.sqrt( x * x + z * z );
  27324. this.theta = Math.atan2( x, z );
  27325. this.y = y;
  27326. return this;
  27327. }
  27328. }
  27329. const _vector$8 = /*@__PURE__*/ new Vector2();
  27330. class Box2 {
  27331. constructor( min, max ) {
  27332. Object.defineProperty( this, 'isBox2', { value: true } );
  27333. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  27334. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  27335. }
  27336. set( min, max ) {
  27337. this.min.copy( min );
  27338. this.max.copy( max );
  27339. return this;
  27340. }
  27341. setFromPoints( points ) {
  27342. this.makeEmpty();
  27343. for ( let i = 0, il = points.length; i < il; i ++ ) {
  27344. this.expandByPoint( points[ i ] );
  27345. }
  27346. return this;
  27347. }
  27348. setFromCenterAndSize( center, size ) {
  27349. const halfSize = _vector$8.copy( size ).multiplyScalar( 0.5 );
  27350. this.min.copy( center ).sub( halfSize );
  27351. this.max.copy( center ).add( halfSize );
  27352. return this;
  27353. }
  27354. clone() {
  27355. return new this.constructor().copy( this );
  27356. }
  27357. copy( box ) {
  27358. this.min.copy( box.min );
  27359. this.max.copy( box.max );
  27360. return this;
  27361. }
  27362. makeEmpty() {
  27363. this.min.x = this.min.y = + Infinity;
  27364. this.max.x = this.max.y = - Infinity;
  27365. return this;
  27366. }
  27367. isEmpty() {
  27368. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27369. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27370. }
  27371. getCenter( target ) {
  27372. if ( target === undefined ) {
  27373. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  27374. target = new Vector2();
  27375. }
  27376. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27377. }
  27378. getSize( target ) {
  27379. if ( target === undefined ) {
  27380. console.warn( 'THREE.Box2: .getSize() target is now required' );
  27381. target = new Vector2();
  27382. }
  27383. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27384. }
  27385. expandByPoint( point ) {
  27386. this.min.min( point );
  27387. this.max.max( point );
  27388. return this;
  27389. }
  27390. expandByVector( vector ) {
  27391. this.min.sub( vector );
  27392. this.max.add( vector );
  27393. return this;
  27394. }
  27395. expandByScalar( scalar ) {
  27396. this.min.addScalar( - scalar );
  27397. this.max.addScalar( scalar );
  27398. return this;
  27399. }
  27400. containsPoint( point ) {
  27401. return point.x < this.min.x || point.x > this.max.x ||
  27402. point.y < this.min.y || point.y > this.max.y ? false : true;
  27403. }
  27404. containsBox( box ) {
  27405. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27406. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27407. }
  27408. getParameter( point, target ) {
  27409. // This can potentially have a divide by zero if the box
  27410. // has a size dimension of 0.
  27411. if ( target === undefined ) {
  27412. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  27413. target = new Vector2();
  27414. }
  27415. return target.set(
  27416. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27417. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27418. );
  27419. }
  27420. intersectsBox( box ) {
  27421. // using 4 splitting planes to rule out intersections
  27422. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27423. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27424. }
  27425. clampPoint( point, target ) {
  27426. if ( target === undefined ) {
  27427. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  27428. target = new Vector2();
  27429. }
  27430. return target.copy( point ).clamp( this.min, this.max );
  27431. }
  27432. distanceToPoint( point ) {
  27433. const clampedPoint = _vector$8.copy( point ).clamp( this.min, this.max );
  27434. return clampedPoint.sub( point ).length();
  27435. }
  27436. intersect( box ) {
  27437. this.min.max( box.min );
  27438. this.max.min( box.max );
  27439. return this;
  27440. }
  27441. union( box ) {
  27442. this.min.min( box.min );
  27443. this.max.max( box.max );
  27444. return this;
  27445. }
  27446. translate( offset ) {
  27447. this.min.add( offset );
  27448. this.max.add( offset );
  27449. return this;
  27450. }
  27451. equals( box ) {
  27452. return box.min.equals( this.min ) && box.max.equals( this.max );
  27453. }
  27454. }
  27455. const _startP = /*@__PURE__*/ new Vector3();
  27456. const _startEnd = /*@__PURE__*/ new Vector3();
  27457. class Line3 {
  27458. constructor( start, end ) {
  27459. this.start = ( start !== undefined ) ? start : new Vector3();
  27460. this.end = ( end !== undefined ) ? end : new Vector3();
  27461. }
  27462. set( start, end ) {
  27463. this.start.copy( start );
  27464. this.end.copy( end );
  27465. return this;
  27466. }
  27467. clone() {
  27468. return new this.constructor().copy( this );
  27469. }
  27470. copy( line ) {
  27471. this.start.copy( line.start );
  27472. this.end.copy( line.end );
  27473. return this;
  27474. }
  27475. getCenter( target ) {
  27476. if ( target === undefined ) {
  27477. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27478. target = new Vector3();
  27479. }
  27480. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27481. }
  27482. delta( target ) {
  27483. if ( target === undefined ) {
  27484. console.warn( 'THREE.Line3: .delta() target is now required' );
  27485. target = new Vector3();
  27486. }
  27487. return target.subVectors( this.end, this.start );
  27488. }
  27489. distanceSq() {
  27490. return this.start.distanceToSquared( this.end );
  27491. }
  27492. distance() {
  27493. return this.start.distanceTo( this.end );
  27494. }
  27495. at( t, target ) {
  27496. if ( target === undefined ) {
  27497. console.warn( 'THREE.Line3: .at() target is now required' );
  27498. target = new Vector3();
  27499. }
  27500. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27501. }
  27502. closestPointToPointParameter( point, clampToLine ) {
  27503. _startP.subVectors( point, this.start );
  27504. _startEnd.subVectors( this.end, this.start );
  27505. const startEnd2 = _startEnd.dot( _startEnd );
  27506. const startEnd_startP = _startEnd.dot( _startP );
  27507. let t = startEnd_startP / startEnd2;
  27508. if ( clampToLine ) {
  27509. t = MathUtils.clamp( t, 0, 1 );
  27510. }
  27511. return t;
  27512. }
  27513. closestPointToPoint( point, clampToLine, target ) {
  27514. const t = this.closestPointToPointParameter( point, clampToLine );
  27515. if ( target === undefined ) {
  27516. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27517. target = new Vector3();
  27518. }
  27519. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27520. }
  27521. applyMatrix4( matrix ) {
  27522. this.start.applyMatrix4( matrix );
  27523. this.end.applyMatrix4( matrix );
  27524. return this;
  27525. }
  27526. equals( line ) {
  27527. return line.start.equals( this.start ) && line.end.equals( this.end );
  27528. }
  27529. }
  27530. function ImmediateRenderObject( material ) {
  27531. Object3D.call( this );
  27532. this.material = material;
  27533. this.render = function ( /* renderCallback */ ) {};
  27534. this.hasPositions = false;
  27535. this.hasNormals = false;
  27536. this.hasColors = false;
  27537. this.hasUvs = false;
  27538. this.positionArray = null;
  27539. this.normalArray = null;
  27540. this.colorArray = null;
  27541. this.uvArray = null;
  27542. this.count = 0;
  27543. }
  27544. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27545. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27546. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27547. const _vector$9 = /*@__PURE__*/ new Vector3();
  27548. class SpotLightHelper extends Object3D {
  27549. constructor( light, color ) {
  27550. super();
  27551. this.light = light;
  27552. this.light.updateMatrixWorld();
  27553. this.matrix = light.matrixWorld;
  27554. this.matrixAutoUpdate = false;
  27555. this.color = color;
  27556. const geometry = new BufferGeometry();
  27557. const positions = [
  27558. 0, 0, 0, 0, 0, 1,
  27559. 0, 0, 0, 1, 0, 1,
  27560. 0, 0, 0, - 1, 0, 1,
  27561. 0, 0, 0, 0, 1, 1,
  27562. 0, 0, 0, 0, - 1, 1
  27563. ];
  27564. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27565. const p1 = ( i / l ) * Math.PI * 2;
  27566. const p2 = ( j / l ) * Math.PI * 2;
  27567. positions.push(
  27568. Math.cos( p1 ), Math.sin( p1 ), 1,
  27569. Math.cos( p2 ), Math.sin( p2 ), 1
  27570. );
  27571. }
  27572. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27573. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  27574. this.cone = new LineSegments( geometry, material );
  27575. this.add( this.cone );
  27576. this.update();
  27577. }
  27578. dispose() {
  27579. this.cone.geometry.dispose();
  27580. this.cone.material.dispose();
  27581. }
  27582. update() {
  27583. this.light.updateMatrixWorld();
  27584. const coneLength = this.light.distance ? this.light.distance : 1000;
  27585. const coneWidth = coneLength * Math.tan( this.light.angle );
  27586. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27587. _vector$9.setFromMatrixPosition( this.light.target.matrixWorld );
  27588. this.cone.lookAt( _vector$9 );
  27589. if ( this.color !== undefined ) {
  27590. this.cone.material.color.set( this.color );
  27591. } else {
  27592. this.cone.material.color.copy( this.light.color );
  27593. }
  27594. }
  27595. }
  27596. const _vector$a = /*@__PURE__*/ new Vector3();
  27597. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  27598. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  27599. class SkeletonHelper extends LineSegments {
  27600. constructor( object ) {
  27601. const bones = getBoneList( object );
  27602. const geometry = new BufferGeometry();
  27603. const vertices = [];
  27604. const colors = [];
  27605. const color1 = new Color( 0, 0, 1 );
  27606. const color2 = new Color( 0, 1, 0 );
  27607. for ( let i = 0; i < bones.length; i ++ ) {
  27608. const bone = bones[ i ];
  27609. if ( bone.parent && bone.parent.isBone ) {
  27610. vertices.push( 0, 0, 0 );
  27611. vertices.push( 0, 0, 0 );
  27612. colors.push( color1.r, color1.g, color1.b );
  27613. colors.push( color2.r, color2.g, color2.b );
  27614. }
  27615. }
  27616. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27617. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27618. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  27619. super( geometry, material );
  27620. this.type = 'SkeletonHelper';
  27621. this.isSkeletonHelper = true;
  27622. this.root = object;
  27623. this.bones = bones;
  27624. this.matrix = object.matrixWorld;
  27625. this.matrixAutoUpdate = false;
  27626. }
  27627. updateMatrixWorld( force ) {
  27628. const bones = this.bones;
  27629. const geometry = this.geometry;
  27630. const position = geometry.getAttribute( 'position' );
  27631. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  27632. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  27633. const bone = bones[ i ];
  27634. if ( bone.parent && bone.parent.isBone ) {
  27635. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  27636. _vector$a.setFromMatrixPosition( _boneMatrix );
  27637. position.setXYZ( j, _vector$a.x, _vector$a.y, _vector$a.z );
  27638. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  27639. _vector$a.setFromMatrixPosition( _boneMatrix );
  27640. position.setXYZ( j + 1, _vector$a.x, _vector$a.y, _vector$a.z );
  27641. j += 2;
  27642. }
  27643. }
  27644. geometry.getAttribute( 'position' ).needsUpdate = true;
  27645. super.updateMatrixWorld( force );
  27646. }
  27647. }
  27648. function getBoneList( object ) {
  27649. const boneList = [];
  27650. if ( object && object.isBone ) {
  27651. boneList.push( object );
  27652. }
  27653. for ( let i = 0; i < object.children.length; i ++ ) {
  27654. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27655. }
  27656. return boneList;
  27657. }
  27658. class PointLightHelper extends Mesh {
  27659. constructor( light, sphereSize, color ) {
  27660. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  27661. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  27662. super( geometry, material );
  27663. this.light = light;
  27664. this.light.updateMatrixWorld();
  27665. this.color = color;
  27666. this.type = 'PointLightHelper';
  27667. this.matrix = this.light.matrixWorld;
  27668. this.matrixAutoUpdate = false;
  27669. this.update();
  27670. /*
  27671. // TODO: delete this comment?
  27672. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27673. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27674. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27675. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27676. const d = light.distance;
  27677. if ( d === 0.0 ) {
  27678. this.lightDistance.visible = false;
  27679. } else {
  27680. this.lightDistance.scale.set( d, d, d );
  27681. }
  27682. this.add( this.lightDistance );
  27683. */
  27684. }
  27685. dispose() {
  27686. this.geometry.dispose();
  27687. this.material.dispose();
  27688. }
  27689. update() {
  27690. if ( this.color !== undefined ) {
  27691. this.material.color.set( this.color );
  27692. } else {
  27693. this.material.color.copy( this.light.color );
  27694. }
  27695. /*
  27696. const d = this.light.distance;
  27697. if ( d === 0.0 ) {
  27698. this.lightDistance.visible = false;
  27699. } else {
  27700. this.lightDistance.visible = true;
  27701. this.lightDistance.scale.set( d, d, d );
  27702. }
  27703. */
  27704. }
  27705. }
  27706. const _vector$b = /*@__PURE__*/ new Vector3();
  27707. const _color1 = /*@__PURE__*/ new Color();
  27708. const _color2 = /*@__PURE__*/ new Color();
  27709. class HemisphereLightHelper extends Object3D {
  27710. constructor( light, size, color ) {
  27711. super();
  27712. this.light = light;
  27713. this.light.updateMatrixWorld();
  27714. this.matrix = light.matrixWorld;
  27715. this.matrixAutoUpdate = false;
  27716. this.color = color;
  27717. const geometry = new OctahedronGeometry( size );
  27718. geometry.rotateY( Math.PI * 0.5 );
  27719. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  27720. if ( this.color === undefined ) this.material.vertexColors = true;
  27721. const position = geometry.getAttribute( 'position' );
  27722. const colors = new Float32Array( position.count * 3 );
  27723. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27724. this.add( new Mesh( geometry, this.material ) );
  27725. this.update();
  27726. }
  27727. dispose() {
  27728. this.children[ 0 ].geometry.dispose();
  27729. this.children[ 0 ].material.dispose();
  27730. }
  27731. update() {
  27732. const mesh = this.children[ 0 ];
  27733. if ( this.color !== undefined ) {
  27734. this.material.color.set( this.color );
  27735. } else {
  27736. const colors = mesh.geometry.getAttribute( 'color' );
  27737. _color1.copy( this.light.color );
  27738. _color2.copy( this.light.groundColor );
  27739. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  27740. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  27741. colors.setXYZ( i, color.r, color.g, color.b );
  27742. }
  27743. colors.needsUpdate = true;
  27744. }
  27745. mesh.lookAt( _vector$b.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27746. }
  27747. }
  27748. class GridHelper extends LineSegments {
  27749. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  27750. color1 = new Color( color1 );
  27751. color2 = new Color( color2 );
  27752. const center = divisions / 2;
  27753. const step = size / divisions;
  27754. const halfSize = size / 2;
  27755. const vertices = [], colors = [];
  27756. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27757. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27758. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27759. const color = i === center ? color1 : color2;
  27760. color.toArray( colors, j ); j += 3;
  27761. color.toArray( colors, j ); j += 3;
  27762. color.toArray( colors, j ); j += 3;
  27763. color.toArray( colors, j ); j += 3;
  27764. }
  27765. const geometry = new BufferGeometry();
  27766. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27767. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27768. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  27769. super( geometry, material );
  27770. this.type = 'GridHelper';
  27771. }
  27772. }
  27773. class PolarGridHelper extends LineSegments {
  27774. constructor( radius = 10, radials = 16, circles = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  27775. color1 = new Color( color1 );
  27776. color2 = new Color( color2 );
  27777. const vertices = [];
  27778. const colors = [];
  27779. // create the radials
  27780. for ( let i = 0; i <= radials; i ++ ) {
  27781. const v = ( i / radials ) * ( Math.PI * 2 );
  27782. const x = Math.sin( v ) * radius;
  27783. const z = Math.cos( v ) * radius;
  27784. vertices.push( 0, 0, 0 );
  27785. vertices.push( x, 0, z );
  27786. const color = ( i & 1 ) ? color1 : color2;
  27787. colors.push( color.r, color.g, color.b );
  27788. colors.push( color.r, color.g, color.b );
  27789. }
  27790. // create the circles
  27791. for ( let i = 0; i <= circles; i ++ ) {
  27792. const color = ( i & 1 ) ? color1 : color2;
  27793. const r = radius - ( radius / circles * i );
  27794. for ( let j = 0; j < divisions; j ++ ) {
  27795. // first vertex
  27796. let v = ( j / divisions ) * ( Math.PI * 2 );
  27797. let x = Math.sin( v ) * r;
  27798. let z = Math.cos( v ) * r;
  27799. vertices.push( x, 0, z );
  27800. colors.push( color.r, color.g, color.b );
  27801. // second vertex
  27802. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27803. x = Math.sin( v ) * r;
  27804. z = Math.cos( v ) * r;
  27805. vertices.push( x, 0, z );
  27806. colors.push( color.r, color.g, color.b );
  27807. }
  27808. }
  27809. const geometry = new BufferGeometry();
  27810. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27811. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27812. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  27813. super( geometry, material );
  27814. this.type = 'PolarGridHelper';
  27815. }
  27816. }
  27817. const _v1$6 = /*@__PURE__*/ new Vector3();
  27818. const _v2$3 = /*@__PURE__*/ new Vector3();
  27819. const _v3$1 = /*@__PURE__*/ new Vector3();
  27820. class DirectionalLightHelper extends Object3D {
  27821. constructor( light, size, color ) {
  27822. super();
  27823. this.light = light;
  27824. this.light.updateMatrixWorld();
  27825. this.matrix = light.matrixWorld;
  27826. this.matrixAutoUpdate = false;
  27827. this.color = color;
  27828. if ( size === undefined ) size = 1;
  27829. let geometry = new BufferGeometry();
  27830. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  27831. - size, size, 0,
  27832. size, size, 0,
  27833. size, - size, 0,
  27834. - size, - size, 0,
  27835. - size, size, 0
  27836. ], 3 ) );
  27837. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  27838. this.lightPlane = new Line( geometry, material );
  27839. this.add( this.lightPlane );
  27840. geometry = new BufferGeometry();
  27841. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27842. this.targetLine = new Line( geometry, material );
  27843. this.add( this.targetLine );
  27844. this.update();
  27845. }
  27846. dispose() {
  27847. this.lightPlane.geometry.dispose();
  27848. this.lightPlane.material.dispose();
  27849. this.targetLine.geometry.dispose();
  27850. this.targetLine.material.dispose();
  27851. }
  27852. update() {
  27853. _v1$6.setFromMatrixPosition( this.light.matrixWorld );
  27854. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  27855. _v3$1.subVectors( _v2$3, _v1$6 );
  27856. this.lightPlane.lookAt( _v2$3 );
  27857. if ( this.color !== undefined ) {
  27858. this.lightPlane.material.color.set( this.color );
  27859. this.targetLine.material.color.set( this.color );
  27860. } else {
  27861. this.lightPlane.material.color.copy( this.light.color );
  27862. this.targetLine.material.color.copy( this.light.color );
  27863. }
  27864. this.targetLine.lookAt( _v2$3 );
  27865. this.targetLine.scale.z = _v3$1.length();
  27866. }
  27867. }
  27868. const _vector$c = /*@__PURE__*/ new Vector3();
  27869. const _camera = /*@__PURE__*/ new Camera();
  27870. /**
  27871. * - shows frustum, line of sight and up of the camera
  27872. * - suitable for fast updates
  27873. * - based on frustum visualization in lightgl.js shadowmap example
  27874. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27875. */
  27876. class CameraHelper extends LineSegments {
  27877. constructor( camera ) {
  27878. const geometry = new BufferGeometry();
  27879. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  27880. const vertices = [];
  27881. const colors = [];
  27882. const pointMap = {};
  27883. // colors
  27884. const colorFrustum = new Color( 0xffaa00 );
  27885. const colorCone = new Color( 0xff0000 );
  27886. const colorUp = new Color( 0x00aaff );
  27887. const colorTarget = new Color( 0xffffff );
  27888. const colorCross = new Color( 0x333333 );
  27889. // near
  27890. addLine( 'n1', 'n2', colorFrustum );
  27891. addLine( 'n2', 'n4', colorFrustum );
  27892. addLine( 'n4', 'n3', colorFrustum );
  27893. addLine( 'n3', 'n1', colorFrustum );
  27894. // far
  27895. addLine( 'f1', 'f2', colorFrustum );
  27896. addLine( 'f2', 'f4', colorFrustum );
  27897. addLine( 'f4', 'f3', colorFrustum );
  27898. addLine( 'f3', 'f1', colorFrustum );
  27899. // sides
  27900. addLine( 'n1', 'f1', colorFrustum );
  27901. addLine( 'n2', 'f2', colorFrustum );
  27902. addLine( 'n3', 'f3', colorFrustum );
  27903. addLine( 'n4', 'f4', colorFrustum );
  27904. // cone
  27905. addLine( 'p', 'n1', colorCone );
  27906. addLine( 'p', 'n2', colorCone );
  27907. addLine( 'p', 'n3', colorCone );
  27908. addLine( 'p', 'n4', colorCone );
  27909. // up
  27910. addLine( 'u1', 'u2', colorUp );
  27911. addLine( 'u2', 'u3', colorUp );
  27912. addLine( 'u3', 'u1', colorUp );
  27913. // target
  27914. addLine( 'c', 't', colorTarget );
  27915. addLine( 'p', 'c', colorCross );
  27916. // cross
  27917. addLine( 'cn1', 'cn2', colorCross );
  27918. addLine( 'cn3', 'cn4', colorCross );
  27919. addLine( 'cf1', 'cf2', colorCross );
  27920. addLine( 'cf3', 'cf4', colorCross );
  27921. function addLine( a, b, color ) {
  27922. addPoint( a, color );
  27923. addPoint( b, color );
  27924. }
  27925. function addPoint( id, color ) {
  27926. vertices.push( 0, 0, 0 );
  27927. colors.push( color.r, color.g, color.b );
  27928. if ( pointMap[ id ] === undefined ) {
  27929. pointMap[ id ] = [];
  27930. }
  27931. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27932. }
  27933. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27934. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27935. super( geometry, material );
  27936. this.type = 'CameraHelper';
  27937. this.camera = camera;
  27938. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27939. this.matrix = camera.matrixWorld;
  27940. this.matrixAutoUpdate = false;
  27941. this.pointMap = pointMap;
  27942. this.update();
  27943. }
  27944. update() {
  27945. const geometry = this.geometry;
  27946. const pointMap = this.pointMap;
  27947. const w = 1, h = 1;
  27948. // we need just camera projection matrix inverse
  27949. // world matrix must be identity
  27950. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27951. // center / target
  27952. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  27953. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  27954. // near
  27955. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  27956. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  27957. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  27958. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  27959. // far
  27960. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  27961. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  27962. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  27963. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  27964. // up
  27965. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  27966. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  27967. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  27968. // cross
  27969. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  27970. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  27971. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  27972. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  27973. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  27974. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  27975. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  27976. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  27977. geometry.getAttribute( 'position' ).needsUpdate = true;
  27978. }
  27979. }
  27980. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  27981. _vector$c.set( x, y, z ).unproject( camera );
  27982. const points = pointMap[ point ];
  27983. if ( points !== undefined ) {
  27984. const position = geometry.getAttribute( 'position' );
  27985. for ( let i = 0, l = points.length; i < l; i ++ ) {
  27986. position.setXYZ( points[ i ], _vector$c.x, _vector$c.y, _vector$c.z );
  27987. }
  27988. }
  27989. }
  27990. const _box$3 = /*@__PURE__*/ new Box3();
  27991. class BoxHelper extends LineSegments {
  27992. constructor( object, color = 0xffff00 ) {
  27993. 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 ] );
  27994. const positions = new Float32Array( 8 * 3 );
  27995. const geometry = new BufferGeometry();
  27996. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27997. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27998. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  27999. this.object = object;
  28000. this.type = 'BoxHelper';
  28001. this.matrixAutoUpdate = false;
  28002. this.update();
  28003. }
  28004. update( object ) {
  28005. if ( object !== undefined ) {
  28006. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28007. }
  28008. if ( this.object !== undefined ) {
  28009. _box$3.setFromObject( this.object );
  28010. }
  28011. if ( _box$3.isEmpty() ) return;
  28012. const min = _box$3.min;
  28013. const max = _box$3.max;
  28014. /*
  28015. 5____4
  28016. 1/___0/|
  28017. | 6__|_7
  28018. 2/___3/
  28019. 0: max.x, max.y, max.z
  28020. 1: min.x, max.y, max.z
  28021. 2: min.x, min.y, max.z
  28022. 3: max.x, min.y, max.z
  28023. 4: max.x, max.y, min.z
  28024. 5: min.x, max.y, min.z
  28025. 6: min.x, min.y, min.z
  28026. 7: max.x, min.y, min.z
  28027. */
  28028. const position = this.geometry.attributes.position;
  28029. const array = position.array;
  28030. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28031. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28032. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28033. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28034. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28035. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28036. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28037. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28038. position.needsUpdate = true;
  28039. this.geometry.computeBoundingSphere();
  28040. }
  28041. setFromObject( object ) {
  28042. this.object = object;
  28043. this.update();
  28044. return this;
  28045. }
  28046. copy( source ) {
  28047. LineSegments.prototype.copy.call( this, source );
  28048. this.object = source.object;
  28049. return this;
  28050. }
  28051. }
  28052. class Box3Helper extends LineSegments {
  28053. constructor( box, color = 0xffff00 ) {
  28054. 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 ] );
  28055. 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 ];
  28056. const geometry = new BufferGeometry();
  28057. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28058. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28059. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28060. this.box = box;
  28061. this.type = 'Box3Helper';
  28062. this.geometry.computeBoundingSphere();
  28063. }
  28064. updateMatrixWorld( force ) {
  28065. const box = this.box;
  28066. if ( box.isEmpty() ) return;
  28067. box.getCenter( this.position );
  28068. box.getSize( this.scale );
  28069. this.scale.multiplyScalar( 0.5 );
  28070. super.updateMatrixWorld( force );
  28071. }
  28072. }
  28073. class PlaneHelper extends Line {
  28074. constructor( plane, size = 1, hex = 0xffff00 ) {
  28075. const color = hex;
  28076. 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 ];
  28077. const geometry = new BufferGeometry();
  28078. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28079. geometry.computeBoundingSphere();
  28080. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28081. this.type = 'PlaneHelper';
  28082. this.plane = plane;
  28083. this.size = size;
  28084. const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28085. const geometry2 = new BufferGeometry();
  28086. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28087. geometry2.computeBoundingSphere();
  28088. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28089. }
  28090. updateMatrixWorld( force ) {
  28091. let scale = - this.plane.constant;
  28092. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28093. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28094. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28095. this.lookAt( this.plane.normal );
  28096. super.updateMatrixWorld( force );
  28097. }
  28098. }
  28099. const _axis = /*@__PURE__*/ new Vector3();
  28100. let _lineGeometry, _coneGeometry;
  28101. class ArrowHelper extends Object3D {
  28102. constructor( dir, origin, length, color, headLength, headWidth ) {
  28103. super();
  28104. // dir is assumed to be normalized
  28105. this.type = 'ArrowHelper';
  28106. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28107. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28108. if ( length === undefined ) length = 1;
  28109. if ( color === undefined ) color = 0xffff00;
  28110. if ( headLength === undefined ) headLength = 0.2 * length;
  28111. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28112. if ( _lineGeometry === undefined ) {
  28113. _lineGeometry = new BufferGeometry();
  28114. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28115. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  28116. _coneGeometry.translate( 0, - 0.5, 0 );
  28117. }
  28118. this.position.copy( origin );
  28119. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28120. this.line.matrixAutoUpdate = false;
  28121. this.add( this.line );
  28122. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28123. this.cone.matrixAutoUpdate = false;
  28124. this.add( this.cone );
  28125. this.setDirection( dir );
  28126. this.setLength( length, headLength, headWidth );
  28127. }
  28128. setDirection( dir ) {
  28129. // dir is assumed to be normalized
  28130. if ( dir.y > 0.99999 ) {
  28131. this.quaternion.set( 0, 0, 0, 1 );
  28132. } else if ( dir.y < - 0.99999 ) {
  28133. this.quaternion.set( 1, 0, 0, 0 );
  28134. } else {
  28135. _axis.set( dir.z, 0, - dir.x ).normalize();
  28136. const radians = Math.acos( dir.y );
  28137. this.quaternion.setFromAxisAngle( _axis, radians );
  28138. }
  28139. }
  28140. setLength( length, headLength, headWidth ) {
  28141. if ( headLength === undefined ) headLength = 0.2 * length;
  28142. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28143. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28144. this.line.updateMatrix();
  28145. this.cone.scale.set( headWidth, headLength, headWidth );
  28146. this.cone.position.y = length;
  28147. this.cone.updateMatrix();
  28148. }
  28149. setColor( color ) {
  28150. this.line.material.color.set( color );
  28151. this.cone.material.color.set( color );
  28152. }
  28153. copy( source ) {
  28154. super.copy( source, false );
  28155. this.line.copy( source.line );
  28156. this.cone.copy( source.cone );
  28157. return this;
  28158. }
  28159. }
  28160. class AxesHelper extends LineSegments {
  28161. constructor( size = 1 ) {
  28162. const vertices = [
  28163. 0, 0, 0, size, 0, 0,
  28164. 0, 0, 0, 0, size, 0,
  28165. 0, 0, 0, 0, 0, size
  28166. ];
  28167. const colors = [
  28168. 1, 0, 0, 1, 0.6, 0,
  28169. 0, 1, 0, 0.6, 1, 0,
  28170. 0, 0, 1, 0, 0.6, 1
  28171. ];
  28172. const geometry = new BufferGeometry();
  28173. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28174. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28175. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28176. super( geometry, material );
  28177. this.type = 'AxesHelper';
  28178. }
  28179. }
  28180. const _floatView = new Float32Array( 1 );
  28181. const _int32View = new Int32Array( _floatView.buffer );
  28182. const DataUtils = {
  28183. // Converts float32 to float16 (stored as uint16 value).
  28184. toHalfFloat: function ( val ) {
  28185. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28186. /* This method is faster than the OpenEXR implementation (very often
  28187. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28188. * by James Tursa?s half-precision code. */
  28189. _floatView[ 0 ] = val;
  28190. const x = _int32View[ 0 ];
  28191. let bits = ( x >> 16 ) & 0x8000; /* Get the sign */
  28192. let m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
  28193. const e = ( x >> 23 ) & 0xff; /* Using int is faster here */
  28194. /* If zero, or denormal, or exponent underflows too much for a denormal
  28195. * half, return signed zero. */
  28196. if ( e < 103 ) return bits;
  28197. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28198. if ( e > 142 ) {
  28199. bits |= 0x7c00;
  28200. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28201. * not Inf, so make sure we set one mantissa bit too. */
  28202. bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
  28203. return bits;
  28204. }
  28205. /* If exponent underflows but not too much, return a denormal */
  28206. if ( e < 113 ) {
  28207. m |= 0x0800;
  28208. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28209. * to 1, which is OK. */
  28210. bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
  28211. return bits;
  28212. }
  28213. bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
  28214. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28215. * the exponent, which is OK. */
  28216. bits += m & 1;
  28217. return bits;
  28218. }
  28219. };
  28220. const LOD_MIN = 4;
  28221. const LOD_MAX = 8;
  28222. const SIZE_MAX = Math.pow( 2, LOD_MAX );
  28223. // The standard deviations (radians) associated with the extra mips. These are
  28224. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28225. // geometric shadowing function. These sigma values squared must match the
  28226. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28227. const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  28228. const TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  28229. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  28230. // samples and exit early, but not recompile the shader.
  28231. const MAX_SAMPLES = 20;
  28232. const ENCODINGS = {
  28233. [ LinearEncoding ]: 0,
  28234. [ sRGBEncoding ]: 1,
  28235. [ RGBEEncoding ]: 2,
  28236. [ RGBM7Encoding ]: 3,
  28237. [ RGBM16Encoding ]: 4,
  28238. [ RGBDEncoding ]: 5,
  28239. [ GammaEncoding ]: 6
  28240. };
  28241. const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
  28242. const { _lodPlanes, _sizeLods, _sigmas } = /*@__PURE__*/ _createPlanes();
  28243. const _clearColor = /*@__PURE__*/ new Color();
  28244. const _backgroundColor = /*@__PURE__*/ new Color();
  28245. let _oldTarget = null;
  28246. // Golden Ratio
  28247. const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  28248. const INV_PHI = 1 / PHI;
  28249. // Vertices of a dodecahedron (except the opposites, which represent the
  28250. // same axis), used as axis directions evenly spread on a sphere.
  28251. const _axisDirections = [
  28252. /*@__PURE__*/ new Vector3( 1, 1, 1 ),
  28253. /*@__PURE__*/ new Vector3( - 1, 1, 1 ),
  28254. /*@__PURE__*/ new Vector3( 1, 1, - 1 ),
  28255. /*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
  28256. /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
  28257. /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
  28258. /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
  28259. /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
  28260. /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
  28261. /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ) ];
  28262. /**
  28263. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28264. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28265. * blur to be quickly accessed based on material roughness. It is packed into a
  28266. * special CubeUV format that allows us to perform custom interpolation so that
  28267. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28268. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28269. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28270. * higher roughness levels. In this way we maintain resolution to smoothly
  28271. * interpolate diffuse lighting while limiting sampling computation.
  28272. */
  28273. function convertLinearToRGBE( color ) {
  28274. const maxComponent = Math.max( color.r, color.g, color.b );
  28275. const fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  28276. color.multiplyScalar( Math.pow( 2.0, - fExp ) );
  28277. const alpha = ( fExp + 128.0 ) / 255.0;
  28278. return alpha;
  28279. }
  28280. class PMREMGenerator {
  28281. constructor( renderer ) {
  28282. this._renderer = renderer;
  28283. this._pingPongRenderTarget = null;
  28284. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  28285. this._equirectShader = null;
  28286. this._cubemapShader = null;
  28287. this._compileMaterial( this._blurMaterial );
  28288. }
  28289. /**
  28290. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28291. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28292. * in radians to be applied to the scene before PMREM generation. Optional near
  28293. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28294. * is placed at the origin).
  28295. */
  28296. fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
  28297. _oldTarget = this._renderer.getRenderTarget();
  28298. const cubeUVRenderTarget = this._allocateTargets();
  28299. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  28300. if ( sigma > 0 ) {
  28301. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  28302. }
  28303. this._applyPMREM( cubeUVRenderTarget );
  28304. this._cleanup( cubeUVRenderTarget );
  28305. return cubeUVRenderTarget;
  28306. }
  28307. /**
  28308. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28309. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28310. * as this matches best with the 256 x 256 cubemap output.
  28311. */
  28312. fromEquirectangular( equirectangular ) {
  28313. return this._fromTexture( equirectangular );
  28314. }
  28315. /**
  28316. * Generates a PMREM from an cubemap texture, which can be either LDR
  28317. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28318. * as this matches best with the 256 x 256 cubemap output.
  28319. */
  28320. fromCubemap( cubemap ) {
  28321. return this._fromTexture( cubemap );
  28322. }
  28323. /**
  28324. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28325. * your texture's network fetch for increased concurrency.
  28326. */
  28327. compileCubemapShader() {
  28328. if ( this._cubemapShader === null ) {
  28329. this._cubemapShader = _getCubemapShader();
  28330. this._compileMaterial( this._cubemapShader );
  28331. }
  28332. }
  28333. /**
  28334. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28335. * your texture's network fetch for increased concurrency.
  28336. */
  28337. compileEquirectangularShader() {
  28338. if ( this._equirectShader === null ) {
  28339. this._equirectShader = _getEquirectShader();
  28340. this._compileMaterial( this._equirectShader );
  28341. }
  28342. }
  28343. /**
  28344. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28345. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28346. * one of them will cause any others to also become unusable.
  28347. */
  28348. dispose() {
  28349. this._blurMaterial.dispose();
  28350. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  28351. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  28352. for ( let i = 0; i < _lodPlanes.length; i ++ ) {
  28353. _lodPlanes[ i ].dispose();
  28354. }
  28355. }
  28356. // private interface
  28357. _cleanup( outputTarget ) {
  28358. this._pingPongRenderTarget.dispose();
  28359. this._renderer.setRenderTarget( _oldTarget );
  28360. outputTarget.scissorTest = false;
  28361. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  28362. }
  28363. _fromTexture( texture ) {
  28364. _oldTarget = this._renderer.getRenderTarget();
  28365. const cubeUVRenderTarget = this._allocateTargets( texture );
  28366. this._textureToCubeUV( texture, cubeUVRenderTarget );
  28367. this._applyPMREM( cubeUVRenderTarget );
  28368. this._cleanup( cubeUVRenderTarget );
  28369. return cubeUVRenderTarget;
  28370. }
  28371. _allocateTargets( texture ) { // warning: null texture is valid
  28372. const params = {
  28373. magFilter: NearestFilter,
  28374. minFilter: NearestFilter,
  28375. generateMipmaps: false,
  28376. type: UnsignedByteType,
  28377. format: RGBEFormat,
  28378. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  28379. depthBuffer: false
  28380. };
  28381. const cubeUVRenderTarget = _createRenderTarget( params );
  28382. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28383. this._pingPongRenderTarget = _createRenderTarget( params );
  28384. return cubeUVRenderTarget;
  28385. }
  28386. _compileMaterial( material ) {
  28387. const tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  28388. this._renderer.compile( tmpMesh, _flatCamera );
  28389. }
  28390. _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
  28391. const fov = 90;
  28392. const aspect = 1;
  28393. const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  28394. const upSign = [ 1, - 1, 1, 1, 1, 1 ];
  28395. const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  28396. const renderer = this._renderer;
  28397. const outputEncoding = renderer.outputEncoding;
  28398. const toneMapping = renderer.toneMapping;
  28399. renderer.getClearColor( _clearColor );
  28400. const clearAlpha = renderer.getClearAlpha();
  28401. const originalBackground = scene.background;
  28402. renderer.toneMapping = NoToneMapping;
  28403. renderer.outputEncoding = LinearEncoding;
  28404. const background = scene.background;
  28405. if ( background ) {
  28406. if ( background.isColor ) {
  28407. _backgroundColor.copy( background ).convertSRGBToLinear();
  28408. scene.background = null;
  28409. const alpha = convertLinearToRGBE( _backgroundColor );
  28410. renderer.setClearColor( _backgroundColor );
  28411. renderer.setClearAlpha( alpha );
  28412. }
  28413. } else {
  28414. _backgroundColor.copy( _clearColor ).convertSRGBToLinear();
  28415. const alpha = convertLinearToRGBE( _backgroundColor );
  28416. renderer.setClearColor( _backgroundColor );
  28417. renderer.setClearAlpha( alpha );
  28418. }
  28419. for ( let i = 0; i < 6; i ++ ) {
  28420. const col = i % 3;
  28421. if ( col == 0 ) {
  28422. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28423. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  28424. } else if ( col == 1 ) {
  28425. cubeCamera.up.set( 0, 0, upSign[ i ] );
  28426. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  28427. } else {
  28428. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28429. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  28430. }
  28431. _setViewport( cubeUVRenderTarget,
  28432. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  28433. renderer.setRenderTarget( cubeUVRenderTarget );
  28434. renderer.render( scene, cubeCamera );
  28435. }
  28436. renderer.toneMapping = toneMapping;
  28437. renderer.outputEncoding = outputEncoding;
  28438. renderer.setClearColor( _clearColor, clearAlpha );
  28439. scene.background = originalBackground;
  28440. }
  28441. _textureToCubeUV( texture, cubeUVRenderTarget ) {
  28442. const renderer = this._renderer;
  28443. if ( texture.isCubeTexture ) {
  28444. if ( this._cubemapShader == null ) {
  28445. this._cubemapShader = _getCubemapShader();
  28446. }
  28447. } else {
  28448. if ( this._equirectShader == null ) {
  28449. this._equirectShader = _getEquirectShader();
  28450. }
  28451. }
  28452. const material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28453. const mesh = new Mesh( _lodPlanes[ 0 ], material );
  28454. const uniforms = material.uniforms;
  28455. uniforms[ 'envMap' ].value = texture;
  28456. if ( ! texture.isCubeTexture ) {
  28457. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  28458. }
  28459. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  28460. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  28461. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  28462. renderer.setRenderTarget( cubeUVRenderTarget );
  28463. renderer.render( mesh, _flatCamera );
  28464. }
  28465. _applyPMREM( cubeUVRenderTarget ) {
  28466. const renderer = this._renderer;
  28467. const autoClear = renderer.autoClear;
  28468. renderer.autoClear = false;
  28469. for ( let i = 1; i < TOTAL_LODS; i ++ ) {
  28470. const sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  28471. const poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  28472. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  28473. }
  28474. renderer.autoClear = autoClear;
  28475. }
  28476. /**
  28477. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28478. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28479. * the blur latitudinally (around the poles), and then longitudinally (towards
  28480. * the poles) to approximate the orthogonally-separable blur. It is least
  28481. * accurate at the poles, but still does a decent job.
  28482. */
  28483. _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  28484. const pingPongRenderTarget = this._pingPongRenderTarget;
  28485. this._halfBlur(
  28486. cubeUVRenderTarget,
  28487. pingPongRenderTarget,
  28488. lodIn,
  28489. lodOut,
  28490. sigma,
  28491. 'latitudinal',
  28492. poleAxis );
  28493. this._halfBlur(
  28494. pingPongRenderTarget,
  28495. cubeUVRenderTarget,
  28496. lodOut,
  28497. lodOut,
  28498. sigma,
  28499. 'longitudinal',
  28500. poleAxis );
  28501. }
  28502. _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  28503. const renderer = this._renderer;
  28504. const blurMaterial = this._blurMaterial;
  28505. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  28506. console.error(
  28507. 'blur direction must be either latitudinal or longitudinal!' );
  28508. }
  28509. // Number of standard deviations at which to cut off the discrete approximation.
  28510. const STANDARD_DEVIATIONS = 3;
  28511. const blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  28512. const blurUniforms = blurMaterial.uniforms;
  28513. const pixels = _sizeLods[ lodIn ] - 1;
  28514. const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  28515. const sigmaPixels = sigmaRadians / radiansPerPixel;
  28516. const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  28517. if ( samples > MAX_SAMPLES ) {
  28518. console.warn( `sigmaRadians, ${
  28519. sigmaRadians}, is too large and will clip, as it requested ${
  28520. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  28521. }
  28522. const weights = [];
  28523. let sum = 0;
  28524. for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
  28525. const x = i / sigmaPixels;
  28526. const weight = Math.exp( - x * x / 2 );
  28527. weights.push( weight );
  28528. if ( i == 0 ) {
  28529. sum += weight;
  28530. } else if ( i < samples ) {
  28531. sum += 2 * weight;
  28532. }
  28533. }
  28534. for ( let i = 0; i < weights.length; i ++ ) {
  28535. weights[ i ] = weights[ i ] / sum;
  28536. }
  28537. blurUniforms[ 'envMap' ].value = targetIn.texture;
  28538. blurUniforms[ 'samples' ].value = samples;
  28539. blurUniforms[ 'weights' ].value = weights;
  28540. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  28541. if ( poleAxis ) {
  28542. blurUniforms[ 'poleAxis' ].value = poleAxis;
  28543. }
  28544. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  28545. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  28546. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  28547. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  28548. const outputSize = _sizeLods[ lodOut ];
  28549. const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  28550. const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  28551. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  28552. renderer.setRenderTarget( targetOut );
  28553. renderer.render( blurMesh, _flatCamera );
  28554. }
  28555. }
  28556. function _isLDR( texture ) {
  28557. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  28558. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28559. }
  28560. function _createPlanes() {
  28561. const _lodPlanes = [];
  28562. const _sizeLods = [];
  28563. const _sigmas = [];
  28564. let lod = LOD_MAX;
  28565. for ( let i = 0; i < TOTAL_LODS; i ++ ) {
  28566. const sizeLod = Math.pow( 2, lod );
  28567. _sizeLods.push( sizeLod );
  28568. let sigma = 1.0 / sizeLod;
  28569. if ( i > LOD_MAX - LOD_MIN ) {
  28570. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  28571. } else if ( i == 0 ) {
  28572. sigma = 0;
  28573. }
  28574. _sigmas.push( sigma );
  28575. const texelSize = 1.0 / ( sizeLod - 1 );
  28576. const min = - texelSize / 2;
  28577. const max = 1 + texelSize / 2;
  28578. const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  28579. const cubeFaces = 6;
  28580. const vertices = 6;
  28581. const positionSize = 3;
  28582. const uvSize = 2;
  28583. const faceIndexSize = 1;
  28584. const position = new Float32Array( positionSize * vertices * cubeFaces );
  28585. const uv = new Float32Array( uvSize * vertices * cubeFaces );
  28586. const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  28587. for ( let face = 0; face < cubeFaces; face ++ ) {
  28588. const x = ( face % 3 ) * 2 / 3 - 1;
  28589. const y = face > 2 ? 0 : - 1;
  28590. const coordinates = [
  28591. x, y, 0,
  28592. x + 2 / 3, y, 0,
  28593. x + 2 / 3, y + 1, 0,
  28594. x, y, 0,
  28595. x + 2 / 3, y + 1, 0,
  28596. x, y + 1, 0
  28597. ];
  28598. position.set( coordinates, positionSize * vertices * face );
  28599. uv.set( uv1, uvSize * vertices * face );
  28600. const fill = [ face, face, face, face, face, face ];
  28601. faceIndex.set( fill, faceIndexSize * vertices * face );
  28602. }
  28603. const planes = new BufferGeometry();
  28604. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  28605. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  28606. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  28607. _lodPlanes.push( planes );
  28608. if ( lod > LOD_MIN ) {
  28609. lod --;
  28610. }
  28611. }
  28612. return { _lodPlanes, _sizeLods, _sigmas };
  28613. }
  28614. function _createRenderTarget( params ) {
  28615. const cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  28616. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28617. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28618. cubeUVRenderTarget.scissorTest = true;
  28619. return cubeUVRenderTarget;
  28620. }
  28621. function _setViewport( target, x, y, width, height ) {
  28622. target.viewport.set( x, y, width, height );
  28623. target.scissor.set( x, y, width, height );
  28624. }
  28625. function _getBlurShader( maxSamples ) {
  28626. const weights = new Float32Array( maxSamples );
  28627. const poleAxis = new Vector3( 0, 1, 0 );
  28628. const shaderMaterial = new RawShaderMaterial( {
  28629. name: 'SphericalGaussianBlur',
  28630. defines: { 'n': maxSamples },
  28631. uniforms: {
  28632. 'envMap': { value: null },
  28633. 'samples': { value: 1 },
  28634. 'weights': { value: weights },
  28635. 'latitudinal': { value: false },
  28636. 'dTheta': { value: 0 },
  28637. 'mipInt': { value: 0 },
  28638. 'poleAxis': { value: poleAxis },
  28639. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  28640. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  28641. },
  28642. vertexShader: _getCommonVertexShader(),
  28643. fragmentShader: /* glsl */`
  28644. precision mediump float;
  28645. precision mediump int;
  28646. varying vec3 vOutputDirection;
  28647. uniform sampler2D envMap;
  28648. uniform int samples;
  28649. uniform float weights[ n ];
  28650. uniform bool latitudinal;
  28651. uniform float dTheta;
  28652. uniform float mipInt;
  28653. uniform vec3 poleAxis;
  28654. ${ _getEncodings() }
  28655. #define ENVMAP_TYPE_CUBE_UV
  28656. #include <cube_uv_reflection_fragment>
  28657. vec3 getSample( float theta, vec3 axis ) {
  28658. float cosTheta = cos( theta );
  28659. // Rodrigues' axis-angle rotation
  28660. vec3 sampleDirection = vOutputDirection * cosTheta
  28661. + cross( axis, vOutputDirection ) * sin( theta )
  28662. + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
  28663. return bilinearCubeUV( envMap, sampleDirection, mipInt );
  28664. }
  28665. void main() {
  28666. vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
  28667. if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
  28668. axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
  28669. }
  28670. axis = normalize( axis );
  28671. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  28672. gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
  28673. for ( int i = 1; i < n; i++ ) {
  28674. if ( i >= samples ) {
  28675. break;
  28676. }
  28677. float theta = dTheta * float( i );
  28678. gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
  28679. gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
  28680. }
  28681. gl_FragColor = linearToOutputTexel( gl_FragColor );
  28682. }
  28683. `,
  28684. blending: NoBlending,
  28685. depthTest: false,
  28686. depthWrite: false
  28687. } );
  28688. return shaderMaterial;
  28689. }
  28690. function _getEquirectShader() {
  28691. const texelSize = new Vector2( 1, 1 );
  28692. const shaderMaterial = new RawShaderMaterial( {
  28693. name: 'EquirectangularToCubeUV',
  28694. uniforms: {
  28695. 'envMap': { value: null },
  28696. 'texelSize': { value: texelSize },
  28697. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  28698. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  28699. },
  28700. vertexShader: _getCommonVertexShader(),
  28701. fragmentShader: /* glsl */`
  28702. precision mediump float;
  28703. precision mediump int;
  28704. varying vec3 vOutputDirection;
  28705. uniform sampler2D envMap;
  28706. uniform vec2 texelSize;
  28707. ${ _getEncodings() }
  28708. #include <common>
  28709. void main() {
  28710. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  28711. vec3 outputDirection = normalize( vOutputDirection );
  28712. vec2 uv = equirectUv( outputDirection );
  28713. vec2 f = fract( uv / texelSize - 0.5 );
  28714. uv -= f * texelSize;
  28715. vec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  28716. uv.x += texelSize.x;
  28717. vec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  28718. uv.y += texelSize.y;
  28719. vec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  28720. uv.x -= texelSize.x;
  28721. vec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  28722. vec3 tm = mix( tl, tr, f.x );
  28723. vec3 bm = mix( bl, br, f.x );
  28724. gl_FragColor.rgb = mix( tm, bm, f.y );
  28725. gl_FragColor = linearToOutputTexel( gl_FragColor );
  28726. }
  28727. `,
  28728. blending: NoBlending,
  28729. depthTest: false,
  28730. depthWrite: false
  28731. } );
  28732. return shaderMaterial;
  28733. }
  28734. function _getCubemapShader() {
  28735. const shaderMaterial = new RawShaderMaterial( {
  28736. name: 'CubemapToCubeUV',
  28737. uniforms: {
  28738. 'envMap': { value: null },
  28739. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  28740. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  28741. },
  28742. vertexShader: _getCommonVertexShader(),
  28743. fragmentShader: /* glsl */`
  28744. precision mediump float;
  28745. precision mediump int;
  28746. varying vec3 vOutputDirection;
  28747. uniform samplerCube envMap;
  28748. ${ _getEncodings() }
  28749. void main() {
  28750. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  28751. gl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;
  28752. gl_FragColor = linearToOutputTexel( gl_FragColor );
  28753. }
  28754. `,
  28755. blending: NoBlending,
  28756. depthTest: false,
  28757. depthWrite: false
  28758. } );
  28759. return shaderMaterial;
  28760. }
  28761. function _getCommonVertexShader() {
  28762. return /* glsl */`
  28763. precision mediump float;
  28764. precision mediump int;
  28765. attribute vec3 position;
  28766. attribute vec2 uv;
  28767. attribute float faceIndex;
  28768. varying vec3 vOutputDirection;
  28769. // RH coordinate system; PMREM face-indexing convention
  28770. vec3 getDirection( vec2 uv, float face ) {
  28771. uv = 2.0 * uv - 1.0;
  28772. vec3 direction = vec3( uv, 1.0 );
  28773. if ( face == 0.0 ) {
  28774. direction = direction.zyx; // ( 1, v, u ) pos x
  28775. } else if ( face == 1.0 ) {
  28776. direction = direction.xzy;
  28777. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  28778. } else if ( face == 2.0 ) {
  28779. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  28780. } else if ( face == 3.0 ) {
  28781. direction = direction.zyx;
  28782. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  28783. } else if ( face == 4.0 ) {
  28784. direction = direction.xzy;
  28785. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  28786. } else if ( face == 5.0 ) {
  28787. direction.z *= -1.0; // ( u, v, -1 ) neg z
  28788. }
  28789. return direction;
  28790. }
  28791. void main() {
  28792. vOutputDirection = getDirection( uv, faceIndex );
  28793. gl_Position = vec4( position, 1.0 );
  28794. }
  28795. `;
  28796. }
  28797. function _getEncodings() {
  28798. return /* glsl */`
  28799. uniform int inputEncoding;
  28800. uniform int outputEncoding;
  28801. #include <encodings_pars_fragment>
  28802. vec4 inputTexelToLinear( vec4 value ) {
  28803. if ( inputEncoding == 0 ) {
  28804. return value;
  28805. } else if ( inputEncoding == 1 ) {
  28806. return sRGBToLinear( value );
  28807. } else if ( inputEncoding == 2 ) {
  28808. return RGBEToLinear( value );
  28809. } else if ( inputEncoding == 3 ) {
  28810. return RGBMToLinear( value, 7.0 );
  28811. } else if ( inputEncoding == 4 ) {
  28812. return RGBMToLinear( value, 16.0 );
  28813. } else if ( inputEncoding == 5 ) {
  28814. return RGBDToLinear( value, 256.0 );
  28815. } else {
  28816. return GammaToLinear( value, 2.2 );
  28817. }
  28818. }
  28819. vec4 linearToOutputTexel( vec4 value ) {
  28820. if ( outputEncoding == 0 ) {
  28821. return value;
  28822. } else if ( outputEncoding == 1 ) {
  28823. return LinearTosRGB( value );
  28824. } else if ( outputEncoding == 2 ) {
  28825. return LinearToRGBE( value );
  28826. } else if ( outputEncoding == 3 ) {
  28827. return LinearToRGBM( value, 7.0 );
  28828. } else if ( outputEncoding == 4 ) {
  28829. return LinearToRGBM( value, 16.0 );
  28830. } else if ( outputEncoding == 5 ) {
  28831. return LinearToRGBD( value, 256.0 );
  28832. } else {
  28833. return LinearToGamma( value, 2.2 );
  28834. }
  28835. }
  28836. vec4 envMapTexelToLinear( vec4 color ) {
  28837. return inputTexelToLinear( color );
  28838. }
  28839. `;
  28840. }
  28841. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28842. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28843. return new Face3( a, b, c, normal, color, materialIndex );
  28844. }
  28845. const LineStrip = 0;
  28846. const LinePieces = 1;
  28847. const NoColors = 0;
  28848. const FaceColors = 1;
  28849. const VertexColors = 2;
  28850. function MeshFaceMaterial( materials ) {
  28851. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28852. return materials;
  28853. }
  28854. function MultiMaterial( materials = [] ) {
  28855. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28856. materials.isMultiMaterial = true;
  28857. materials.materials = materials;
  28858. materials.clone = function () {
  28859. return materials.slice();
  28860. };
  28861. return materials;
  28862. }
  28863. function PointCloud( geometry, material ) {
  28864. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28865. return new Points( geometry, material );
  28866. }
  28867. function Particle( material ) {
  28868. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28869. return new Sprite( material );
  28870. }
  28871. function ParticleSystem( geometry, material ) {
  28872. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28873. return new Points( geometry, material );
  28874. }
  28875. function PointCloudMaterial( parameters ) {
  28876. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28877. return new PointsMaterial( parameters );
  28878. }
  28879. function ParticleBasicMaterial( parameters ) {
  28880. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28881. return new PointsMaterial( parameters );
  28882. }
  28883. function ParticleSystemMaterial( parameters ) {
  28884. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28885. return new PointsMaterial( parameters );
  28886. }
  28887. function Vertex( x, y, z ) {
  28888. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28889. return new Vector3( x, y, z );
  28890. }
  28891. //
  28892. function DynamicBufferAttribute( array, itemSize ) {
  28893. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  28894. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  28895. }
  28896. function Int8Attribute( array, itemSize ) {
  28897. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28898. return new Int8BufferAttribute( array, itemSize );
  28899. }
  28900. function Uint8Attribute( array, itemSize ) {
  28901. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28902. return new Uint8BufferAttribute( array, itemSize );
  28903. }
  28904. function Uint8ClampedAttribute( array, itemSize ) {
  28905. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28906. return new Uint8ClampedBufferAttribute( array, itemSize );
  28907. }
  28908. function Int16Attribute( array, itemSize ) {
  28909. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28910. return new Int16BufferAttribute( array, itemSize );
  28911. }
  28912. function Uint16Attribute( array, itemSize ) {
  28913. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28914. return new Uint16BufferAttribute( array, itemSize );
  28915. }
  28916. function Int32Attribute( array, itemSize ) {
  28917. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28918. return new Int32BufferAttribute( array, itemSize );
  28919. }
  28920. function Uint32Attribute( array, itemSize ) {
  28921. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28922. return new Uint32BufferAttribute( array, itemSize );
  28923. }
  28924. function Float32Attribute( array, itemSize ) {
  28925. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28926. return new Float32BufferAttribute( array, itemSize );
  28927. }
  28928. function Float64Attribute( array, itemSize ) {
  28929. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28930. return new Float64BufferAttribute( array, itemSize );
  28931. }
  28932. //
  28933. Curve.create = function ( construct, getPoint ) {
  28934. console.log( 'THREE.Curve.create() has been deprecated' );
  28935. construct.prototype = Object.create( Curve.prototype );
  28936. construct.prototype.constructor = construct;
  28937. construct.prototype.getPoint = getPoint;
  28938. return construct;
  28939. };
  28940. //
  28941. Object.assign( CurvePath.prototype, {
  28942. createPointsGeometry: function ( divisions ) {
  28943. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28944. // generate geometry from path points (for Line or Points objects)
  28945. const pts = this.getPoints( divisions );
  28946. return this.createGeometry( pts );
  28947. },
  28948. createSpacedPointsGeometry: function ( divisions ) {
  28949. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28950. // generate geometry from equidistant sampling along the path
  28951. const pts = this.getSpacedPoints( divisions );
  28952. return this.createGeometry( pts );
  28953. },
  28954. createGeometry: function ( points ) {
  28955. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28956. const geometry = new Geometry();
  28957. for ( let i = 0, l = points.length; i < l; i ++ ) {
  28958. const point = points[ i ];
  28959. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28960. }
  28961. return geometry;
  28962. }
  28963. } );
  28964. //
  28965. Object.assign( Path.prototype, {
  28966. fromPoints: function ( points ) {
  28967. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28968. return this.setFromPoints( points );
  28969. }
  28970. } );
  28971. //
  28972. function ClosedSplineCurve3( points ) {
  28973. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28974. CatmullRomCurve3.call( this, points );
  28975. this.type = 'catmullrom';
  28976. this.closed = true;
  28977. }
  28978. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28979. //
  28980. function SplineCurve3( points ) {
  28981. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28982. CatmullRomCurve3.call( this, points );
  28983. this.type = 'catmullrom';
  28984. }
  28985. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28986. //
  28987. function Spline( points ) {
  28988. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28989. CatmullRomCurve3.call( this, points );
  28990. this.type = 'catmullrom';
  28991. }
  28992. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28993. Object.assign( Spline.prototype, {
  28994. initFromArray: function ( /* a */ ) {
  28995. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28996. },
  28997. getControlPointsArray: function ( /* optionalTarget */ ) {
  28998. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28999. },
  29000. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29001. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29002. }
  29003. } );
  29004. //
  29005. function AxisHelper( size ) {
  29006. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29007. return new AxesHelper( size );
  29008. }
  29009. function BoundingBoxHelper( object, color ) {
  29010. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29011. return new BoxHelper( object, color );
  29012. }
  29013. function EdgesHelper( object, hex ) {
  29014. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29015. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29016. }
  29017. GridHelper.prototype.setColors = function () {
  29018. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29019. };
  29020. SkeletonHelper.prototype.update = function () {
  29021. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29022. };
  29023. function WireframeHelper( object, hex ) {
  29024. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29025. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29026. }
  29027. //
  29028. Object.assign( Loader.prototype, {
  29029. extractUrlBase: function ( url ) {
  29030. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29031. return LoaderUtils.extractUrlBase( url );
  29032. }
  29033. } );
  29034. Loader.Handlers = {
  29035. add: function ( /* regex, loader */ ) {
  29036. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  29037. },
  29038. get: function ( /* file */ ) {
  29039. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  29040. }
  29041. };
  29042. function XHRLoader( manager ) {
  29043. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29044. return new FileLoader( manager );
  29045. }
  29046. function BinaryTextureLoader( manager ) {
  29047. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29048. return new DataTextureLoader( manager );
  29049. }
  29050. //
  29051. Object.assign( Box2.prototype, {
  29052. center: function ( optionalTarget ) {
  29053. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29054. return this.getCenter( optionalTarget );
  29055. },
  29056. empty: function () {
  29057. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29058. return this.isEmpty();
  29059. },
  29060. isIntersectionBox: function ( box ) {
  29061. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29062. return this.intersectsBox( box );
  29063. },
  29064. size: function ( optionalTarget ) {
  29065. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29066. return this.getSize( optionalTarget );
  29067. }
  29068. } );
  29069. Object.assign( Box3.prototype, {
  29070. center: function ( optionalTarget ) {
  29071. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29072. return this.getCenter( optionalTarget );
  29073. },
  29074. empty: function () {
  29075. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29076. return this.isEmpty();
  29077. },
  29078. isIntersectionBox: function ( box ) {
  29079. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29080. return this.intersectsBox( box );
  29081. },
  29082. isIntersectionSphere: function ( sphere ) {
  29083. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29084. return this.intersectsSphere( sphere );
  29085. },
  29086. size: function ( optionalTarget ) {
  29087. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29088. return this.getSize( optionalTarget );
  29089. }
  29090. } );
  29091. Object.assign( Sphere.prototype, {
  29092. empty: function () {
  29093. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  29094. return this.isEmpty();
  29095. },
  29096. } );
  29097. Frustum.prototype.setFromMatrix = function ( m ) {
  29098. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  29099. return this.setFromProjectionMatrix( m );
  29100. };
  29101. Line3.prototype.center = function ( optionalTarget ) {
  29102. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29103. return this.getCenter( optionalTarget );
  29104. };
  29105. Object.assign( MathUtils, {
  29106. random16: function () {
  29107. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29108. return Math.random();
  29109. },
  29110. nearestPowerOfTwo: function ( value ) {
  29111. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29112. return MathUtils.floorPowerOfTwo( value );
  29113. },
  29114. nextPowerOfTwo: function ( value ) {
  29115. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29116. return MathUtils.ceilPowerOfTwo( value );
  29117. }
  29118. } );
  29119. Object.assign( Matrix3.prototype, {
  29120. flattenToArrayOffset: function ( array, offset ) {
  29121. console.warn( 'THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  29122. return this.toArray( array, offset );
  29123. },
  29124. multiplyVector3: function ( vector ) {
  29125. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29126. return vector.applyMatrix3( this );
  29127. },
  29128. multiplyVector3Array: function ( /* a */ ) {
  29129. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29130. },
  29131. applyToBufferAttribute: function ( attribute ) {
  29132. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  29133. return attribute.applyMatrix3( this );
  29134. },
  29135. applyToVector3Array: function ( /* array, offset, length */ ) {
  29136. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29137. },
  29138. getInverse: function ( matrix ) {
  29139. console.warn( 'THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  29140. return this.copy( matrix ).invert();
  29141. }
  29142. } );
  29143. Object.assign( Matrix4.prototype, {
  29144. extractPosition: function ( m ) {
  29145. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29146. return this.copyPosition( m );
  29147. },
  29148. flattenToArrayOffset: function ( array, offset ) {
  29149. console.warn( 'THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  29150. return this.toArray( array, offset );
  29151. },
  29152. getPosition: function () {
  29153. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29154. return new Vector3().setFromMatrixColumn( this, 3 );
  29155. },
  29156. setRotationFromQuaternion: function ( q ) {
  29157. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29158. return this.makeRotationFromQuaternion( q );
  29159. },
  29160. multiplyToArray: function () {
  29161. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29162. },
  29163. multiplyVector3: function ( vector ) {
  29164. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29165. return vector.applyMatrix4( this );
  29166. },
  29167. multiplyVector4: function ( vector ) {
  29168. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29169. return vector.applyMatrix4( this );
  29170. },
  29171. multiplyVector3Array: function ( /* a */ ) {
  29172. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29173. },
  29174. rotateAxis: function ( v ) {
  29175. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29176. v.transformDirection( this );
  29177. },
  29178. crossVector: function ( vector ) {
  29179. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29180. return vector.applyMatrix4( this );
  29181. },
  29182. translate: function () {
  29183. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29184. },
  29185. rotateX: function () {
  29186. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29187. },
  29188. rotateY: function () {
  29189. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29190. },
  29191. rotateZ: function () {
  29192. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29193. },
  29194. rotateByAxis: function () {
  29195. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29196. },
  29197. applyToBufferAttribute: function ( attribute ) {
  29198. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  29199. return attribute.applyMatrix4( this );
  29200. },
  29201. applyToVector3Array: function ( /* array, offset, length */ ) {
  29202. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29203. },
  29204. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29205. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29206. return this.makePerspective( left, right, top, bottom, near, far );
  29207. },
  29208. getInverse: function ( matrix ) {
  29209. console.warn( 'THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  29210. return this.copy( matrix ).invert();
  29211. }
  29212. } );
  29213. Plane.prototype.isIntersectionLine = function ( line ) {
  29214. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29215. return this.intersectsLine( line );
  29216. };
  29217. Object.assign( Quaternion.prototype, {
  29218. multiplyVector3: function ( vector ) {
  29219. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29220. return vector.applyQuaternion( this );
  29221. },
  29222. inverse: function ( ) {
  29223. console.warn( 'THREE.Quaternion: .inverse() has been renamed to invert().' );
  29224. return this.invert();
  29225. }
  29226. } );
  29227. Object.assign( Ray.prototype, {
  29228. isIntersectionBox: function ( box ) {
  29229. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29230. return this.intersectsBox( box );
  29231. },
  29232. isIntersectionPlane: function ( plane ) {
  29233. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29234. return this.intersectsPlane( plane );
  29235. },
  29236. isIntersectionSphere: function ( sphere ) {
  29237. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29238. return this.intersectsSphere( sphere );
  29239. }
  29240. } );
  29241. Object.assign( Triangle.prototype, {
  29242. area: function () {
  29243. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  29244. return this.getArea();
  29245. },
  29246. barycoordFromPoint: function ( point, target ) {
  29247. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29248. return this.getBarycoord( point, target );
  29249. },
  29250. midpoint: function ( target ) {
  29251. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  29252. return this.getMidpoint( target );
  29253. },
  29254. normal: function ( target ) {
  29255. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29256. return this.getNormal( target );
  29257. },
  29258. plane: function ( target ) {
  29259. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  29260. return this.getPlane( target );
  29261. }
  29262. } );
  29263. Object.assign( Triangle, {
  29264. barycoordFromPoint: function ( point, a, b, c, target ) {
  29265. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29266. return Triangle.getBarycoord( point, a, b, c, target );
  29267. },
  29268. normal: function ( a, b, c, target ) {
  29269. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29270. return Triangle.getNormal( a, b, c, target );
  29271. }
  29272. } );
  29273. Object.assign( Shape.prototype, {
  29274. extractAllPoints: function ( divisions ) {
  29275. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  29276. return this.extractPoints( divisions );
  29277. },
  29278. extrude: function ( options ) {
  29279. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  29280. return new ExtrudeGeometry( this, options );
  29281. },
  29282. makeGeometry: function ( options ) {
  29283. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  29284. return new ShapeGeometry( this, options );
  29285. }
  29286. } );
  29287. Object.assign( Vector2.prototype, {
  29288. fromAttribute: function ( attribute, index, offset ) {
  29289. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29290. return this.fromBufferAttribute( attribute, index, offset );
  29291. },
  29292. distanceToManhattan: function ( v ) {
  29293. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29294. return this.manhattanDistanceTo( v );
  29295. },
  29296. lengthManhattan: function () {
  29297. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29298. return this.manhattanLength();
  29299. }
  29300. } );
  29301. Object.assign( Vector3.prototype, {
  29302. setEulerFromRotationMatrix: function () {
  29303. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29304. },
  29305. setEulerFromQuaternion: function () {
  29306. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29307. },
  29308. getPositionFromMatrix: function ( m ) {
  29309. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29310. return this.setFromMatrixPosition( m );
  29311. },
  29312. getScaleFromMatrix: function ( m ) {
  29313. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29314. return this.setFromMatrixScale( m );
  29315. },
  29316. getColumnFromMatrix: function ( index, matrix ) {
  29317. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29318. return this.setFromMatrixColumn( matrix, index );
  29319. },
  29320. applyProjection: function ( m ) {
  29321. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29322. return this.applyMatrix4( m );
  29323. },
  29324. fromAttribute: function ( attribute, index, offset ) {
  29325. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29326. return this.fromBufferAttribute( attribute, index, offset );
  29327. },
  29328. distanceToManhattan: function ( v ) {
  29329. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29330. return this.manhattanDistanceTo( v );
  29331. },
  29332. lengthManhattan: function () {
  29333. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29334. return this.manhattanLength();
  29335. }
  29336. } );
  29337. Object.assign( Vector4.prototype, {
  29338. fromAttribute: function ( attribute, index, offset ) {
  29339. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29340. return this.fromBufferAttribute( attribute, index, offset );
  29341. },
  29342. lengthManhattan: function () {
  29343. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29344. return this.manhattanLength();
  29345. }
  29346. } );
  29347. //
  29348. Object.assign( Geometry.prototype, {
  29349. computeTangents: function () {
  29350. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  29351. },
  29352. computeLineDistances: function () {
  29353. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  29354. },
  29355. applyMatrix: function ( matrix ) {
  29356. console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29357. return this.applyMatrix4( matrix );
  29358. }
  29359. } );
  29360. //
  29361. Object.assign( Object3D.prototype, {
  29362. getChildByName: function ( name ) {
  29363. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  29364. return this.getObjectByName( name );
  29365. },
  29366. renderDepth: function () {
  29367. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  29368. },
  29369. translate: function ( distance, axis ) {
  29370. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  29371. return this.translateOnAxis( axis, distance );
  29372. },
  29373. getWorldRotation: function () {
  29374. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  29375. },
  29376. applyMatrix: function ( matrix ) {
  29377. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  29378. return this.applyMatrix4( matrix );
  29379. }
  29380. } );
  29381. Object.defineProperties( Object3D.prototype, {
  29382. eulerOrder: {
  29383. get: function () {
  29384. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29385. return this.rotation.order;
  29386. },
  29387. set: function ( value ) {
  29388. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29389. this.rotation.order = value;
  29390. }
  29391. },
  29392. useQuaternion: {
  29393. get: function () {
  29394. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29395. },
  29396. set: function () {
  29397. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29398. }
  29399. }
  29400. } );
  29401. Object.assign( Mesh.prototype, {
  29402. setDrawMode: function () {
  29403. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29404. },
  29405. } );
  29406. Object.defineProperties( Mesh.prototype, {
  29407. drawMode: {
  29408. get: function () {
  29409. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  29410. return TrianglesDrawMode;
  29411. },
  29412. set: function () {
  29413. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29414. }
  29415. }
  29416. } );
  29417. Object.defineProperties( LOD.prototype, {
  29418. objects: {
  29419. get: function () {
  29420. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  29421. return this.levels;
  29422. }
  29423. }
  29424. } );
  29425. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  29426. get: function () {
  29427. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29428. },
  29429. set: function () {
  29430. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29431. }
  29432. } );
  29433. SkinnedMesh.prototype.initBones = function () {
  29434. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29435. };
  29436. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  29437. get: function () {
  29438. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29439. return this.arcLengthDivisions;
  29440. },
  29441. set: function ( value ) {
  29442. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29443. this.arcLengthDivisions = value;
  29444. }
  29445. } );
  29446. //
  29447. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29448. console.warn( 'THREE.PerspectiveCamera.setLens is deprecated. ' +
  29449. 'Use .setFocalLength and .filmGauge for a photographic setup.' );
  29450. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29451. this.setFocalLength( focalLength );
  29452. };
  29453. //
  29454. Object.defineProperties( Light.prototype, {
  29455. onlyShadow: {
  29456. set: function () {
  29457. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29458. }
  29459. },
  29460. shadowCameraFov: {
  29461. set: function ( value ) {
  29462. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29463. this.shadow.camera.fov = value;
  29464. }
  29465. },
  29466. shadowCameraLeft: {
  29467. set: function ( value ) {
  29468. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29469. this.shadow.camera.left = value;
  29470. }
  29471. },
  29472. shadowCameraRight: {
  29473. set: function ( value ) {
  29474. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29475. this.shadow.camera.right = value;
  29476. }
  29477. },
  29478. shadowCameraTop: {
  29479. set: function ( value ) {
  29480. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29481. this.shadow.camera.top = value;
  29482. }
  29483. },
  29484. shadowCameraBottom: {
  29485. set: function ( value ) {
  29486. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29487. this.shadow.camera.bottom = value;
  29488. }
  29489. },
  29490. shadowCameraNear: {
  29491. set: function ( value ) {
  29492. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29493. this.shadow.camera.near = value;
  29494. }
  29495. },
  29496. shadowCameraFar: {
  29497. set: function ( value ) {
  29498. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29499. this.shadow.camera.far = value;
  29500. }
  29501. },
  29502. shadowCameraVisible: {
  29503. set: function () {
  29504. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29505. }
  29506. },
  29507. shadowBias: {
  29508. set: function ( value ) {
  29509. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29510. this.shadow.bias = value;
  29511. }
  29512. },
  29513. shadowDarkness: {
  29514. set: function () {
  29515. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29516. }
  29517. },
  29518. shadowMapWidth: {
  29519. set: function ( value ) {
  29520. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29521. this.shadow.mapSize.width = value;
  29522. }
  29523. },
  29524. shadowMapHeight: {
  29525. set: function ( value ) {
  29526. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29527. this.shadow.mapSize.height = value;
  29528. }
  29529. }
  29530. } );
  29531. //
  29532. Object.defineProperties( BufferAttribute.prototype, {
  29533. length: {
  29534. get: function () {
  29535. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29536. return this.array.length;
  29537. }
  29538. },
  29539. dynamic: {
  29540. get: function () {
  29541. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29542. return this.usage === DynamicDrawUsage;
  29543. },
  29544. set: function ( /* value */ ) {
  29545. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29546. this.setUsage( DynamicDrawUsage );
  29547. }
  29548. }
  29549. } );
  29550. Object.assign( BufferAttribute.prototype, {
  29551. setDynamic: function ( value ) {
  29552. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29553. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29554. return this;
  29555. },
  29556. copyIndicesArray: function ( /* indices */ ) {
  29557. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  29558. },
  29559. setArray: function ( /* array */ ) {
  29560. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29561. }
  29562. } );
  29563. Object.assign( BufferGeometry.prototype, {
  29564. addIndex: function ( index ) {
  29565. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  29566. this.setIndex( index );
  29567. },
  29568. addAttribute: function ( name, attribute ) {
  29569. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  29570. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  29571. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  29572. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  29573. }
  29574. if ( name === 'index' ) {
  29575. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  29576. this.setIndex( attribute );
  29577. return this;
  29578. }
  29579. return this.setAttribute( name, attribute );
  29580. },
  29581. addDrawCall: function ( start, count, indexOffset ) {
  29582. if ( indexOffset !== undefined ) {
  29583. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  29584. }
  29585. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  29586. this.addGroup( start, count );
  29587. },
  29588. clearDrawCalls: function () {
  29589. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  29590. this.clearGroups();
  29591. },
  29592. computeTangents: function () {
  29593. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  29594. },
  29595. computeOffsets: function () {
  29596. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  29597. },
  29598. removeAttribute: function ( name ) {
  29599. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  29600. return this.deleteAttribute( name );
  29601. },
  29602. applyMatrix: function ( matrix ) {
  29603. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29604. return this.applyMatrix4( matrix );
  29605. }
  29606. } );
  29607. Object.defineProperties( BufferGeometry.prototype, {
  29608. drawcalls: {
  29609. get: function () {
  29610. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  29611. return this.groups;
  29612. }
  29613. },
  29614. offsets: {
  29615. get: function () {
  29616. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  29617. return this.groups;
  29618. }
  29619. }
  29620. } );
  29621. Object.defineProperties( InstancedBufferGeometry.prototype, {
  29622. maxInstancedCount: {
  29623. get: function () {
  29624. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  29625. return this.instanceCount;
  29626. },
  29627. set: function ( value ) {
  29628. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  29629. this.instanceCount = value;
  29630. }
  29631. }
  29632. } );
  29633. Object.defineProperties( Raycaster.prototype, {
  29634. linePrecision: {
  29635. get: function () {
  29636. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  29637. return this.params.Line.threshold;
  29638. },
  29639. set: function ( value ) {
  29640. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  29641. this.params.Line.threshold = value;
  29642. }
  29643. }
  29644. } );
  29645. Object.defineProperties( InterleavedBuffer.prototype, {
  29646. dynamic: {
  29647. get: function () {
  29648. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  29649. return this.usage === DynamicDrawUsage;
  29650. },
  29651. set: function ( value ) {
  29652. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  29653. this.setUsage( value );
  29654. }
  29655. }
  29656. } );
  29657. Object.assign( InterleavedBuffer.prototype, {
  29658. setDynamic: function ( value ) {
  29659. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29660. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29661. return this;
  29662. },
  29663. setArray: function ( /* array */ ) {
  29664. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29665. }
  29666. } );
  29667. //
  29668. Object.assign( ExtrudeGeometry.prototype, {
  29669. getArrays: function () {
  29670. console.error( 'THREE.ExtrudeGeometry: .getArrays() has been removed.' );
  29671. },
  29672. addShapeList: function () {
  29673. console.error( 'THREE.ExtrudeGeometry: .addShapeList() has been removed.' );
  29674. },
  29675. addShape: function () {
  29676. console.error( 'THREE.ExtrudeGeometry: .addShape() has been removed.' );
  29677. }
  29678. } );
  29679. //
  29680. Object.assign( Scene.prototype, {
  29681. dispose: function () {
  29682. console.error( 'THREE.Scene: .dispose() has been removed.' );
  29683. }
  29684. } );
  29685. //
  29686. Object.defineProperties( Uniform.prototype, {
  29687. dynamic: {
  29688. set: function () {
  29689. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  29690. }
  29691. },
  29692. onUpdate: {
  29693. value: function () {
  29694. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  29695. return this;
  29696. }
  29697. }
  29698. } );
  29699. //
  29700. Object.defineProperties( Material.prototype, {
  29701. wrapAround: {
  29702. get: function () {
  29703. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29704. },
  29705. set: function () {
  29706. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  29707. }
  29708. },
  29709. overdraw: {
  29710. get: function () {
  29711. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29712. },
  29713. set: function () {
  29714. console.warn( 'THREE.Material: .overdraw has been removed.' );
  29715. }
  29716. },
  29717. wrapRGB: {
  29718. get: function () {
  29719. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  29720. return new Color();
  29721. }
  29722. },
  29723. shading: {
  29724. get: function () {
  29725. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29726. },
  29727. set: function ( value ) {
  29728. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  29729. this.flatShading = ( value === FlatShading );
  29730. }
  29731. },
  29732. stencilMask: {
  29733. get: function () {
  29734. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29735. return this.stencilFuncMask;
  29736. },
  29737. set: function ( value ) {
  29738. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  29739. this.stencilFuncMask = value;
  29740. }
  29741. }
  29742. } );
  29743. Object.defineProperties( MeshPhongMaterial.prototype, {
  29744. metal: {
  29745. get: function () {
  29746. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  29747. return false;
  29748. },
  29749. set: function () {
  29750. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  29751. }
  29752. }
  29753. } );
  29754. Object.defineProperties( MeshPhysicalMaterial.prototype, {
  29755. transparency: {
  29756. get: function () {
  29757. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  29758. return this.transmission;
  29759. },
  29760. set: function ( value ) {
  29761. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  29762. this.transmission = value;
  29763. }
  29764. }
  29765. } );
  29766. Object.defineProperties( ShaderMaterial.prototype, {
  29767. derivatives: {
  29768. get: function () {
  29769. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29770. return this.extensions.derivatives;
  29771. },
  29772. set: function ( value ) {
  29773. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  29774. this.extensions.derivatives = value;
  29775. }
  29776. }
  29777. } );
  29778. //
  29779. Object.assign( WebGLRenderer.prototype, {
  29780. clearTarget: function ( renderTarget, color, depth, stencil ) {
  29781. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  29782. this.setRenderTarget( renderTarget );
  29783. this.clear( color, depth, stencil );
  29784. },
  29785. animate: function ( callback ) {
  29786. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  29787. this.setAnimationLoop( callback );
  29788. },
  29789. getCurrentRenderTarget: function () {
  29790. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  29791. return this.getRenderTarget();
  29792. },
  29793. getMaxAnisotropy: function () {
  29794. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  29795. return this.capabilities.getMaxAnisotropy();
  29796. },
  29797. getPrecision: function () {
  29798. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  29799. return this.capabilities.precision;
  29800. },
  29801. resetGLState: function () {
  29802. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  29803. return this.state.reset();
  29804. },
  29805. supportsFloatTextures: function () {
  29806. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  29807. return this.extensions.get( 'OES_texture_float' );
  29808. },
  29809. supportsHalfFloatTextures: function () {
  29810. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  29811. return this.extensions.get( 'OES_texture_half_float' );
  29812. },
  29813. supportsStandardDerivatives: function () {
  29814. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  29815. return this.extensions.get( 'OES_standard_derivatives' );
  29816. },
  29817. supportsCompressedTextureS3TC: function () {
  29818. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  29819. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  29820. },
  29821. supportsCompressedTexturePVRTC: function () {
  29822. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  29823. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  29824. },
  29825. supportsBlendMinMax: function () {
  29826. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  29827. return this.extensions.get( 'EXT_blend_minmax' );
  29828. },
  29829. supportsVertexTextures: function () {
  29830. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  29831. return this.capabilities.vertexTextures;
  29832. },
  29833. supportsInstancedArrays: function () {
  29834. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  29835. return this.extensions.get( 'ANGLE_instanced_arrays' );
  29836. },
  29837. enableScissorTest: function ( boolean ) {
  29838. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  29839. this.setScissorTest( boolean );
  29840. },
  29841. initMaterial: function () {
  29842. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  29843. },
  29844. addPrePlugin: function () {
  29845. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  29846. },
  29847. addPostPlugin: function () {
  29848. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  29849. },
  29850. updateShadowMap: function () {
  29851. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  29852. },
  29853. setFaceCulling: function () {
  29854. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  29855. },
  29856. allocTextureUnit: function () {
  29857. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  29858. },
  29859. setTexture: function () {
  29860. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  29861. },
  29862. setTexture2D: function () {
  29863. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  29864. },
  29865. setTextureCube: function () {
  29866. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  29867. },
  29868. getActiveMipMapLevel: function () {
  29869. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  29870. return this.getActiveMipmapLevel();
  29871. }
  29872. } );
  29873. Object.defineProperties( WebGLRenderer.prototype, {
  29874. shadowMapEnabled: {
  29875. get: function () {
  29876. return this.shadowMap.enabled;
  29877. },
  29878. set: function ( value ) {
  29879. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  29880. this.shadowMap.enabled = value;
  29881. }
  29882. },
  29883. shadowMapType: {
  29884. get: function () {
  29885. return this.shadowMap.type;
  29886. },
  29887. set: function ( value ) {
  29888. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  29889. this.shadowMap.type = value;
  29890. }
  29891. },
  29892. shadowMapCullFace: {
  29893. get: function () {
  29894. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29895. return undefined;
  29896. },
  29897. set: function ( /* value */ ) {
  29898. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  29899. }
  29900. },
  29901. context: {
  29902. get: function () {
  29903. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  29904. return this.getContext();
  29905. }
  29906. },
  29907. vr: {
  29908. get: function () {
  29909. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  29910. return this.xr;
  29911. }
  29912. },
  29913. gammaInput: {
  29914. get: function () {
  29915. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  29916. return false;
  29917. },
  29918. set: function () {
  29919. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  29920. }
  29921. },
  29922. gammaOutput: {
  29923. get: function () {
  29924. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  29925. return false;
  29926. },
  29927. set: function ( value ) {
  29928. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  29929. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  29930. }
  29931. },
  29932. toneMappingWhitePoint: {
  29933. get: function () {
  29934. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  29935. return 1.0;
  29936. },
  29937. set: function () {
  29938. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  29939. }
  29940. },
  29941. } );
  29942. Object.defineProperties( WebGLShadowMap.prototype, {
  29943. cullFace: {
  29944. get: function () {
  29945. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29946. return undefined;
  29947. },
  29948. set: function ( /* cullFace */ ) {
  29949. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  29950. }
  29951. },
  29952. renderReverseSided: {
  29953. get: function () {
  29954. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29955. return undefined;
  29956. },
  29957. set: function () {
  29958. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29959. }
  29960. },
  29961. renderSingleSided: {
  29962. get: function () {
  29963. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29964. return undefined;
  29965. },
  29966. set: function () {
  29967. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29968. }
  29969. }
  29970. } );
  29971. function WebGLRenderTargetCube( width, height, options ) {
  29972. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  29973. return new WebGLCubeRenderTarget( width, options );
  29974. }
  29975. //
  29976. Object.defineProperties( WebGLRenderTarget.prototype, {
  29977. wrapS: {
  29978. get: function () {
  29979. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29980. return this.texture.wrapS;
  29981. },
  29982. set: function ( value ) {
  29983. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29984. this.texture.wrapS = value;
  29985. }
  29986. },
  29987. wrapT: {
  29988. get: function () {
  29989. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29990. return this.texture.wrapT;
  29991. },
  29992. set: function ( value ) {
  29993. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29994. this.texture.wrapT = value;
  29995. }
  29996. },
  29997. magFilter: {
  29998. get: function () {
  29999. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30000. return this.texture.magFilter;
  30001. },
  30002. set: function ( value ) {
  30003. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30004. this.texture.magFilter = value;
  30005. }
  30006. },
  30007. minFilter: {
  30008. get: function () {
  30009. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30010. return this.texture.minFilter;
  30011. },
  30012. set: function ( value ) {
  30013. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30014. this.texture.minFilter = value;
  30015. }
  30016. },
  30017. anisotropy: {
  30018. get: function () {
  30019. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30020. return this.texture.anisotropy;
  30021. },
  30022. set: function ( value ) {
  30023. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30024. this.texture.anisotropy = value;
  30025. }
  30026. },
  30027. offset: {
  30028. get: function () {
  30029. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30030. return this.texture.offset;
  30031. },
  30032. set: function ( value ) {
  30033. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30034. this.texture.offset = value;
  30035. }
  30036. },
  30037. repeat: {
  30038. get: function () {
  30039. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30040. return this.texture.repeat;
  30041. },
  30042. set: function ( value ) {
  30043. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30044. this.texture.repeat = value;
  30045. }
  30046. },
  30047. format: {
  30048. get: function () {
  30049. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30050. return this.texture.format;
  30051. },
  30052. set: function ( value ) {
  30053. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30054. this.texture.format = value;
  30055. }
  30056. },
  30057. type: {
  30058. get: function () {
  30059. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30060. return this.texture.type;
  30061. },
  30062. set: function ( value ) {
  30063. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30064. this.texture.type = value;
  30065. }
  30066. },
  30067. generateMipmaps: {
  30068. get: function () {
  30069. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30070. return this.texture.generateMipmaps;
  30071. },
  30072. set: function ( value ) {
  30073. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30074. this.texture.generateMipmaps = value;
  30075. }
  30076. }
  30077. } );
  30078. //
  30079. Object.defineProperties( Audio.prototype, {
  30080. load: {
  30081. value: function ( file ) {
  30082. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30083. const scope = this;
  30084. const audioLoader = new AudioLoader();
  30085. audioLoader.load( file, function ( buffer ) {
  30086. scope.setBuffer( buffer );
  30087. } );
  30088. return this;
  30089. }
  30090. },
  30091. startTime: {
  30092. set: function () {
  30093. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  30094. }
  30095. }
  30096. } );
  30097. AudioAnalyser.prototype.getData = function () {
  30098. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30099. return this.getFrequencyData();
  30100. };
  30101. //
  30102. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30103. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30104. return this.update( renderer, scene );
  30105. };
  30106. CubeCamera.prototype.clear = function ( renderer, color, depth, stencil ) {
  30107. console.warn( 'THREE.CubeCamera: .clear() is now .renderTarget.clear().' );
  30108. return this.renderTarget.clear( renderer, color, depth, stencil );
  30109. };
  30110. //
  30111. const GeometryUtils = {
  30112. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30113. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30114. let matrix;
  30115. if ( geometry2.isMesh ) {
  30116. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30117. matrix = geometry2.matrix;
  30118. geometry2 = geometry2.geometry;
  30119. }
  30120. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30121. },
  30122. center: function ( geometry ) {
  30123. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30124. return geometry.center();
  30125. }
  30126. };
  30127. ImageUtils.crossOrigin = undefined;
  30128. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30129. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30130. const loader = new TextureLoader();
  30131. loader.setCrossOrigin( this.crossOrigin );
  30132. const texture = loader.load( url, onLoad, undefined, onError );
  30133. if ( mapping ) texture.mapping = mapping;
  30134. return texture;
  30135. };
  30136. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30137. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30138. const loader = new CubeTextureLoader();
  30139. loader.setCrossOrigin( this.crossOrigin );
  30140. const texture = loader.load( urls, onLoad, undefined, onError );
  30141. if ( mapping ) texture.mapping = mapping;
  30142. return texture;
  30143. };
  30144. ImageUtils.loadCompressedTexture = function () {
  30145. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30146. };
  30147. ImageUtils.loadCompressedTextureCube = function () {
  30148. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30149. };
  30150. //
  30151. function CanvasRenderer() {
  30152. console.error( 'THREE.CanvasRenderer has been removed' );
  30153. }
  30154. //
  30155. function JSONLoader() {
  30156. console.error( 'THREE.JSONLoader has been removed.' );
  30157. }
  30158. //
  30159. const SceneUtils = {
  30160. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30161. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30162. },
  30163. detach: function ( /* child, parent, scene */ ) {
  30164. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30165. },
  30166. attach: function ( /* child, scene, parent */ ) {
  30167. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30168. }
  30169. };
  30170. //
  30171. function LensFlare() {
  30172. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  30173. }
  30174. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  30175. /* eslint-disable no-undef */
  30176. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  30177. revision: REVISION,
  30178. } } ) );
  30179. /* eslint-enable no-undef */
  30180. }
  30181. 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, ClosedSplineCurve3, 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, Face3, Face4, FaceColors, FileLoader, FlatShading, Float16BufferAttribute, Float32Attribute, Float32BufferAttribute, Float64Attribute, Float64BufferAttribute, FloatType, Fog, FogExp2, Font, FontLoader, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GammaEncoding, Geometry, GeometryUtils, 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, Spline, SplineCurve, SplineCurve3, 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 };