three.module.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536
  1. // Polyfills
  2. if ( Number.EPSILON === undefined ) {
  3. Number.EPSILON = Math.pow( 2, - 52 );
  4. }
  5. if ( Number.isInteger === undefined ) {
  6. // Missing in IE
  7. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  8. Number.isInteger = function ( value ) {
  9. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  10. };
  11. }
  12. //
  13. if ( Math.sign === undefined ) {
  14. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  15. Math.sign = function ( x ) {
  16. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  17. };
  18. }
  19. if ( 'name' in Function.prototype === false ) {
  20. // Missing in IE
  21. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  22. Object.defineProperty( Function.prototype, 'name', {
  23. get: function () {
  24. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  25. }
  26. } );
  27. }
  28. if ( Object.assign === undefined ) {
  29. // Missing in IE
  30. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  31. Object.assign = function ( target ) {
  32. if ( target === undefined || target === null ) {
  33. throw new TypeError( 'Cannot convert undefined or null to object' );
  34. }
  35. const output = Object( target );
  36. for ( let index = 1; index < arguments.length; index ++ ) {
  37. const source = arguments[ index ];
  38. if ( source !== undefined && source !== null ) {
  39. for ( const nextKey in source ) {
  40. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  41. output[ nextKey ] = source[ nextKey ];
  42. }
  43. }
  44. }
  45. }
  46. return output;
  47. };
  48. }
  49. const REVISION = '118';
  50. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  51. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  52. const CullFaceNone = 0;
  53. const CullFaceBack = 1;
  54. const CullFaceFront = 2;
  55. const CullFaceFrontBack = 3;
  56. const FrontFaceDirectionCW = 0;
  57. const FrontFaceDirectionCCW = 1;
  58. const BasicShadowMap = 0;
  59. const PCFShadowMap = 1;
  60. const PCFSoftShadowMap = 2;
  61. const VSMShadowMap = 3;
  62. const FrontSide = 0;
  63. const BackSide = 1;
  64. const DoubleSide = 2;
  65. const FlatShading = 1;
  66. const SmoothShading = 2;
  67. const NoBlending = 0;
  68. const NormalBlending = 1;
  69. const AdditiveBlending = 2;
  70. const SubtractiveBlending = 3;
  71. const MultiplyBlending = 4;
  72. const CustomBlending = 5;
  73. const AddEquation = 100;
  74. const SubtractEquation = 101;
  75. const ReverseSubtractEquation = 102;
  76. const MinEquation = 103;
  77. const MaxEquation = 104;
  78. const ZeroFactor = 200;
  79. const OneFactor = 201;
  80. const SrcColorFactor = 202;
  81. const OneMinusSrcColorFactor = 203;
  82. const SrcAlphaFactor = 204;
  83. const OneMinusSrcAlphaFactor = 205;
  84. const DstAlphaFactor = 206;
  85. const OneMinusDstAlphaFactor = 207;
  86. const DstColorFactor = 208;
  87. const OneMinusDstColorFactor = 209;
  88. const SrcAlphaSaturateFactor = 210;
  89. const NeverDepth = 0;
  90. const AlwaysDepth = 1;
  91. const LessDepth = 2;
  92. const LessEqualDepth = 3;
  93. const EqualDepth = 4;
  94. const GreaterEqualDepth = 5;
  95. const GreaterDepth = 6;
  96. const NotEqualDepth = 7;
  97. const MultiplyOperation = 0;
  98. const MixOperation = 1;
  99. const AddOperation = 2;
  100. const NoToneMapping = 0;
  101. const LinearToneMapping = 1;
  102. const ReinhardToneMapping = 2;
  103. const CineonToneMapping = 3;
  104. const ACESFilmicToneMapping = 4;
  105. const CustomToneMapping = 5;
  106. const UVMapping = 300;
  107. const CubeReflectionMapping = 301;
  108. const CubeRefractionMapping = 302;
  109. const EquirectangularReflectionMapping = 303;
  110. const EquirectangularRefractionMapping = 304;
  111. const CubeUVReflectionMapping = 306;
  112. const CubeUVRefractionMapping = 307;
  113. const RepeatWrapping = 1000;
  114. const ClampToEdgeWrapping = 1001;
  115. const MirroredRepeatWrapping = 1002;
  116. const NearestFilter = 1003;
  117. const NearestMipmapNearestFilter = 1004;
  118. const NearestMipMapNearestFilter = 1004;
  119. const NearestMipmapLinearFilter = 1005;
  120. const NearestMipMapLinearFilter = 1005;
  121. const LinearFilter = 1006;
  122. const LinearMipmapNearestFilter = 1007;
  123. const LinearMipMapNearestFilter = 1007;
  124. const LinearMipmapLinearFilter = 1008;
  125. const LinearMipMapLinearFilter = 1008;
  126. const UnsignedByteType = 1009;
  127. const ByteType = 1010;
  128. const ShortType = 1011;
  129. const UnsignedShortType = 1012;
  130. const IntType = 1013;
  131. const UnsignedIntType = 1014;
  132. const FloatType = 1015;
  133. const HalfFloatType = 1016;
  134. const UnsignedShort4444Type = 1017;
  135. const UnsignedShort5551Type = 1018;
  136. const UnsignedShort565Type = 1019;
  137. const UnsignedInt248Type = 1020;
  138. const AlphaFormat = 1021;
  139. const RGBFormat = 1022;
  140. const RGBAFormat = 1023;
  141. const LuminanceFormat = 1024;
  142. const LuminanceAlphaFormat = 1025;
  143. const RGBEFormat = RGBAFormat;
  144. const DepthFormat = 1026;
  145. const DepthStencilFormat = 1027;
  146. const RedFormat = 1028;
  147. const RedIntegerFormat = 1029;
  148. const RGFormat = 1030;
  149. const RGIntegerFormat = 1031;
  150. const RGBIntegerFormat = 1032;
  151. const RGBAIntegerFormat = 1033;
  152. const RGB_S3TC_DXT1_Format = 33776;
  153. const RGBA_S3TC_DXT1_Format = 33777;
  154. const RGBA_S3TC_DXT3_Format = 33778;
  155. const RGBA_S3TC_DXT5_Format = 33779;
  156. const RGB_PVRTC_4BPPV1_Format = 35840;
  157. const RGB_PVRTC_2BPPV1_Format = 35841;
  158. const RGBA_PVRTC_4BPPV1_Format = 35842;
  159. const RGBA_PVRTC_2BPPV1_Format = 35843;
  160. const RGB_ETC1_Format = 36196;
  161. const RGB_ETC2_Format = 37492;
  162. const RGBA_ETC2_EAC_Format = 37496;
  163. const RGBA_ASTC_4x4_Format = 37808;
  164. const RGBA_ASTC_5x4_Format = 37809;
  165. const RGBA_ASTC_5x5_Format = 37810;
  166. const RGBA_ASTC_6x5_Format = 37811;
  167. const RGBA_ASTC_6x6_Format = 37812;
  168. const RGBA_ASTC_8x5_Format = 37813;
  169. const RGBA_ASTC_8x6_Format = 37814;
  170. const RGBA_ASTC_8x8_Format = 37815;
  171. const RGBA_ASTC_10x5_Format = 37816;
  172. const RGBA_ASTC_10x6_Format = 37817;
  173. const RGBA_ASTC_10x8_Format = 37818;
  174. const RGBA_ASTC_10x10_Format = 37819;
  175. const RGBA_ASTC_12x10_Format = 37820;
  176. const RGBA_ASTC_12x12_Format = 37821;
  177. const RGBA_BPTC_Format = 36492;
  178. const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  179. const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  180. const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  181. const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  182. const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  183. const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  184. const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  185. const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  186. const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  187. const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  188. const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  189. const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  190. const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  191. const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  192. const LoopOnce = 2200;
  193. const LoopRepeat = 2201;
  194. const LoopPingPong = 2202;
  195. const InterpolateDiscrete = 2300;
  196. const InterpolateLinear = 2301;
  197. const InterpolateSmooth = 2302;
  198. const ZeroCurvatureEnding = 2400;
  199. const ZeroSlopeEnding = 2401;
  200. const WrapAroundEnding = 2402;
  201. const NormalAnimationBlendMode = 2500;
  202. const AdditiveAnimationBlendMode = 2501;
  203. const TrianglesDrawMode = 0;
  204. const TriangleStripDrawMode = 1;
  205. const TriangleFanDrawMode = 2;
  206. const LinearEncoding = 3000;
  207. const sRGBEncoding = 3001;
  208. const GammaEncoding = 3007;
  209. const RGBEEncoding = 3002;
  210. const LogLuvEncoding = 3003;
  211. const RGBM7Encoding = 3004;
  212. const RGBM16Encoding = 3005;
  213. const RGBDEncoding = 3006;
  214. const BasicDepthPacking = 3200;
  215. const RGBADepthPacking = 3201;
  216. const TangentSpaceNormalMap = 0;
  217. const ObjectSpaceNormalMap = 1;
  218. const ZeroStencilOp = 0;
  219. const KeepStencilOp = 7680;
  220. const ReplaceStencilOp = 7681;
  221. const IncrementStencilOp = 7682;
  222. const DecrementStencilOp = 7683;
  223. const IncrementWrapStencilOp = 34055;
  224. const DecrementWrapStencilOp = 34056;
  225. const InvertStencilOp = 5386;
  226. const NeverStencilFunc = 512;
  227. const LessStencilFunc = 513;
  228. const EqualStencilFunc = 514;
  229. const LessEqualStencilFunc = 515;
  230. const GreaterStencilFunc = 516;
  231. const NotEqualStencilFunc = 517;
  232. const GreaterEqualStencilFunc = 518;
  233. const AlwaysStencilFunc = 519;
  234. const StaticDrawUsage = 35044;
  235. const DynamicDrawUsage = 35048;
  236. const StreamDrawUsage = 35040;
  237. const StaticReadUsage = 35045;
  238. const DynamicReadUsage = 35049;
  239. const StreamReadUsage = 35041;
  240. const StaticCopyUsage = 35046;
  241. const DynamicCopyUsage = 35050;
  242. const StreamCopyUsage = 35042;
  243. /**
  244. * https://github.com/mrdoob/eventdispatcher.js/
  245. */
  246. function EventDispatcher() {}
  247. Object.assign( EventDispatcher.prototype, {
  248. addEventListener: function ( type, listener ) {
  249. if ( this._listeners === undefined ) this._listeners = {};
  250. const listeners = this._listeners;
  251. if ( listeners[ type ] === undefined ) {
  252. listeners[ type ] = [];
  253. }
  254. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  255. listeners[ type ].push( listener );
  256. }
  257. },
  258. hasEventListener: function ( type, listener ) {
  259. if ( this._listeners === undefined ) return false;
  260. const listeners = this._listeners;
  261. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  262. },
  263. removeEventListener: function ( type, listener ) {
  264. if ( this._listeners === undefined ) return;
  265. const listeners = this._listeners;
  266. const listenerArray = listeners[ type ];
  267. if ( listenerArray !== undefined ) {
  268. const index = listenerArray.indexOf( listener );
  269. if ( index !== - 1 ) {
  270. listenerArray.splice( index, 1 );
  271. }
  272. }
  273. },
  274. dispatchEvent: function ( event ) {
  275. if ( this._listeners === undefined ) return;
  276. const listeners = this._listeners;
  277. const listenerArray = listeners[ event.type ];
  278. if ( listenerArray !== undefined ) {
  279. event.target = this;
  280. // Make a copy, in case listeners are removed while iterating.
  281. const array = listenerArray.slice( 0 );
  282. for ( let i = 0, l = array.length; i < l; i ++ ) {
  283. array[ i ].call( this, event );
  284. }
  285. }
  286. }
  287. } );
  288. /**
  289. * @author alteredq / http://alteredqualia.com/
  290. * @author mrdoob / http://mrdoob.com/
  291. * @author WestLangley / http://github.com/WestLangley
  292. * @author thezwap
  293. */
  294. const _lut = [];
  295. for ( let i = 0; i < 256; i ++ ) {
  296. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  297. }
  298. const MathUtils = {
  299. DEG2RAD: Math.PI / 180,
  300. RAD2DEG: 180 / Math.PI,
  301. generateUUID: function () {
  302. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  303. const d0 = Math.random() * 0xffffffff | 0;
  304. const d1 = Math.random() * 0xffffffff | 0;
  305. const d2 = Math.random() * 0xffffffff | 0;
  306. const d3 = Math.random() * 0xffffffff | 0;
  307. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  308. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  309. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  310. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  311. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  312. return uuid.toUpperCase();
  313. },
  314. clamp: function ( value, min, max ) {
  315. return Math.max( min, Math.min( max, value ) );
  316. },
  317. // compute euclidian modulo of m % n
  318. // https://en.wikipedia.org/wiki/Modulo_operation
  319. euclideanModulo: function ( n, m ) {
  320. return ( ( n % m ) + m ) % m;
  321. },
  322. // Linear mapping from range <a1, a2> to range <b1, b2>
  323. mapLinear: function ( x, a1, a2, b1, b2 ) {
  324. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  325. },
  326. // https://en.wikipedia.org/wiki/Linear_interpolation
  327. lerp: function ( x, y, t ) {
  328. return ( 1 - t ) * x + t * y;
  329. },
  330. // http://en.wikipedia.org/wiki/Smoothstep
  331. smoothstep: function ( x, min, max ) {
  332. if ( x <= min ) return 0;
  333. if ( x >= max ) return 1;
  334. x = ( x - min ) / ( max - min );
  335. return x * x * ( 3 - 2 * x );
  336. },
  337. smootherstep: function ( x, min, max ) {
  338. if ( x <= min ) return 0;
  339. if ( x >= max ) return 1;
  340. x = ( x - min ) / ( max - min );
  341. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  342. },
  343. // Random integer from <low, high> interval
  344. randInt: function ( low, high ) {
  345. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  346. },
  347. // Random float from <low, high> interval
  348. randFloat: function ( low, high ) {
  349. return low + Math.random() * ( high - low );
  350. },
  351. // Random float from <-range/2, range/2> interval
  352. randFloatSpread: function ( range ) {
  353. return range * ( 0.5 - Math.random() );
  354. },
  355. degToRad: function ( degrees ) {
  356. return degrees * MathUtils.DEG2RAD;
  357. },
  358. radToDeg: function ( radians ) {
  359. return radians * MathUtils.RAD2DEG;
  360. },
  361. isPowerOfTwo: function ( value ) {
  362. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  363. },
  364. ceilPowerOfTwo: function ( value ) {
  365. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  366. },
  367. floorPowerOfTwo: function ( value ) {
  368. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  369. },
  370. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  371. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  372. // rotations are applied to the axes in the order specified by 'order'
  373. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  374. // angles are in radians
  375. const cos = Math.cos;
  376. const sin = Math.sin;
  377. const c2 = cos( b / 2 );
  378. const s2 = sin( b / 2 );
  379. const c13 = cos( ( a + c ) / 2 );
  380. const s13 = sin( ( a + c ) / 2 );
  381. const c1_3 = cos( ( a - c ) / 2 );
  382. const s1_3 = sin( ( a - c ) / 2 );
  383. const c3_1 = cos( ( c - a ) / 2 );
  384. const s3_1 = sin( ( c - a ) / 2 );
  385. switch ( order ) {
  386. case 'XYX':
  387. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  388. break;
  389. case 'YZY':
  390. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  391. break;
  392. case 'ZXZ':
  393. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  394. break;
  395. case 'XZX':
  396. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  397. break;
  398. case 'YXY':
  399. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  400. break;
  401. case 'ZYZ':
  402. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  403. break;
  404. default:
  405. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  406. }
  407. }
  408. };
  409. /**
  410. * @author mrdoob / http://mrdoob.com/
  411. * @author philogb / http://blog.thejit.org/
  412. * @author egraether / http://egraether.com/
  413. * @author zz85 / http://www.lab4games.net/zz85/blog
  414. */
  415. function Vector2( x = 0, y = 0 ) {
  416. this.x = x;
  417. this.y = y;
  418. }
  419. Object.defineProperties( Vector2.prototype, {
  420. "width": {
  421. get: function () {
  422. return this.x;
  423. },
  424. set: function ( value ) {
  425. this.x = value;
  426. }
  427. },
  428. "height": {
  429. get: function () {
  430. return this.y;
  431. },
  432. set: function ( value ) {
  433. this.y = value;
  434. }
  435. }
  436. } );
  437. Object.assign( Vector2.prototype, {
  438. isVector2: true,
  439. set: function ( x, y ) {
  440. this.x = x;
  441. this.y = y;
  442. return this;
  443. },
  444. setScalar: function ( scalar ) {
  445. this.x = scalar;
  446. this.y = scalar;
  447. return this;
  448. },
  449. setX: function ( x ) {
  450. this.x = x;
  451. return this;
  452. },
  453. setY: function ( y ) {
  454. this.y = y;
  455. return this;
  456. },
  457. setComponent: function ( index, value ) {
  458. switch ( index ) {
  459. case 0: this.x = value; break;
  460. case 1: this.y = value; break;
  461. default: throw new Error( 'index is out of range: ' + index );
  462. }
  463. return this;
  464. },
  465. getComponent: function ( index ) {
  466. switch ( index ) {
  467. case 0: return this.x;
  468. case 1: return this.y;
  469. default: throw new Error( 'index is out of range: ' + index );
  470. }
  471. },
  472. clone: function () {
  473. return new this.constructor( this.x, this.y );
  474. },
  475. copy: function ( v ) {
  476. this.x = v.x;
  477. this.y = v.y;
  478. return this;
  479. },
  480. add: function ( v, w ) {
  481. if ( w !== undefined ) {
  482. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  483. return this.addVectors( v, w );
  484. }
  485. this.x += v.x;
  486. this.y += v.y;
  487. return this;
  488. },
  489. addScalar: function ( s ) {
  490. this.x += s;
  491. this.y += s;
  492. return this;
  493. },
  494. addVectors: function ( a, b ) {
  495. this.x = a.x + b.x;
  496. this.y = a.y + b.y;
  497. return this;
  498. },
  499. addScaledVector: function ( v, s ) {
  500. this.x += v.x * s;
  501. this.y += v.y * s;
  502. return this;
  503. },
  504. sub: function ( v, w ) {
  505. if ( w !== undefined ) {
  506. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  507. return this.subVectors( v, w );
  508. }
  509. this.x -= v.x;
  510. this.y -= v.y;
  511. return this;
  512. },
  513. subScalar: function ( s ) {
  514. this.x -= s;
  515. this.y -= s;
  516. return this;
  517. },
  518. subVectors: function ( a, b ) {
  519. this.x = a.x - b.x;
  520. this.y = a.y - b.y;
  521. return this;
  522. },
  523. multiply: function ( v ) {
  524. this.x *= v.x;
  525. this.y *= v.y;
  526. return this;
  527. },
  528. multiplyScalar: function ( scalar ) {
  529. this.x *= scalar;
  530. this.y *= scalar;
  531. return this;
  532. },
  533. divide: function ( v ) {
  534. this.x /= v.x;
  535. this.y /= v.y;
  536. return this;
  537. },
  538. divideScalar: function ( scalar ) {
  539. return this.multiplyScalar( 1 / scalar );
  540. },
  541. applyMatrix3: function ( m ) {
  542. const x = this.x, y = this.y;
  543. const e = m.elements;
  544. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  545. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  546. return this;
  547. },
  548. min: function ( v ) {
  549. this.x = Math.min( this.x, v.x );
  550. this.y = Math.min( this.y, v.y );
  551. return this;
  552. },
  553. max: function ( v ) {
  554. this.x = Math.max( this.x, v.x );
  555. this.y = Math.max( this.y, v.y );
  556. return this;
  557. },
  558. clamp: function ( min, max ) {
  559. // assumes min < max, componentwise
  560. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  561. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  562. return this;
  563. },
  564. clampScalar: function ( minVal, maxVal ) {
  565. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  566. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  567. return this;
  568. },
  569. clampLength: function ( min, max ) {
  570. const length = this.length();
  571. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  572. },
  573. floor: function () {
  574. this.x = Math.floor( this.x );
  575. this.y = Math.floor( this.y );
  576. return this;
  577. },
  578. ceil: function () {
  579. this.x = Math.ceil( this.x );
  580. this.y = Math.ceil( this.y );
  581. return this;
  582. },
  583. round: function () {
  584. this.x = Math.round( this.x );
  585. this.y = Math.round( this.y );
  586. return this;
  587. },
  588. roundToZero: function () {
  589. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  590. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  591. return this;
  592. },
  593. negate: function () {
  594. this.x = - this.x;
  595. this.y = - this.y;
  596. return this;
  597. },
  598. dot: function ( v ) {
  599. return this.x * v.x + this.y * v.y;
  600. },
  601. cross: function ( v ) {
  602. return this.x * v.y - this.y * v.x;
  603. },
  604. lengthSq: function () {
  605. return this.x * this.x + this.y * this.y;
  606. },
  607. length: function () {
  608. return Math.sqrt( this.x * this.x + this.y * this.y );
  609. },
  610. manhattanLength: function () {
  611. return Math.abs( this.x ) + Math.abs( this.y );
  612. },
  613. normalize: function () {
  614. return this.divideScalar( this.length() || 1 );
  615. },
  616. angle: function () {
  617. // computes the angle in radians with respect to the positive x-axis
  618. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  619. return angle;
  620. },
  621. distanceTo: function ( v ) {
  622. return Math.sqrt( this.distanceToSquared( v ) );
  623. },
  624. distanceToSquared: function ( v ) {
  625. const dx = this.x - v.x, dy = this.y - v.y;
  626. return dx * dx + dy * dy;
  627. },
  628. manhattanDistanceTo: function ( v ) {
  629. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  630. },
  631. setLength: function ( length ) {
  632. return this.normalize().multiplyScalar( length );
  633. },
  634. lerp: function ( v, alpha ) {
  635. this.x += ( v.x - this.x ) * alpha;
  636. this.y += ( v.y - this.y ) * alpha;
  637. return this;
  638. },
  639. lerpVectors: function ( v1, v2, alpha ) {
  640. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  641. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  642. return this;
  643. },
  644. equals: function ( v ) {
  645. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  646. },
  647. fromArray: function ( array, offset ) {
  648. if ( offset === undefined ) offset = 0;
  649. this.x = array[ offset ];
  650. this.y = array[ offset + 1 ];
  651. return this;
  652. },
  653. toArray: function ( array, offset ) {
  654. if ( array === undefined ) array = [];
  655. if ( offset === undefined ) offset = 0;
  656. array[ offset ] = this.x;
  657. array[ offset + 1 ] = this.y;
  658. return array;
  659. },
  660. fromBufferAttribute: function ( attribute, index, offset ) {
  661. if ( offset !== undefined ) {
  662. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  663. }
  664. this.x = attribute.getX( index );
  665. this.y = attribute.getY( index );
  666. return this;
  667. },
  668. rotateAround: function ( center, angle ) {
  669. const c = Math.cos( angle ), s = Math.sin( angle );
  670. const x = this.x - center.x;
  671. const y = this.y - center.y;
  672. this.x = x * c - y * s + center.x;
  673. this.y = x * s + y * c + center.y;
  674. return this;
  675. },
  676. random: function () {
  677. this.x = Math.random();
  678. this.y = Math.random();
  679. return this;
  680. }
  681. } );
  682. /**
  683. * @author alteredq / http://alteredqualia.com/
  684. * @author WestLangley / http://github.com/WestLangley
  685. * @author bhouston / http://clara.io
  686. * @author tschw
  687. */
  688. function Matrix3() {
  689. this.elements = [
  690. 1, 0, 0,
  691. 0, 1, 0,
  692. 0, 0, 1
  693. ];
  694. if ( arguments.length > 0 ) {
  695. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  696. }
  697. }
  698. Object.assign( Matrix3.prototype, {
  699. isMatrix3: true,
  700. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  701. const te = this.elements;
  702. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  703. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  704. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  705. return this;
  706. },
  707. identity: function () {
  708. this.set(
  709. 1, 0, 0,
  710. 0, 1, 0,
  711. 0, 0, 1
  712. );
  713. return this;
  714. },
  715. clone: function () {
  716. return new this.constructor().fromArray( this.elements );
  717. },
  718. copy: function ( m ) {
  719. const te = this.elements;
  720. const me = m.elements;
  721. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  722. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  723. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  724. return this;
  725. },
  726. extractBasis: function ( xAxis, yAxis, zAxis ) {
  727. xAxis.setFromMatrix3Column( this, 0 );
  728. yAxis.setFromMatrix3Column( this, 1 );
  729. zAxis.setFromMatrix3Column( this, 2 );
  730. return this;
  731. },
  732. setFromMatrix4: function ( m ) {
  733. const me = m.elements;
  734. this.set(
  735. me[ 0 ], me[ 4 ], me[ 8 ],
  736. me[ 1 ], me[ 5 ], me[ 9 ],
  737. me[ 2 ], me[ 6 ], me[ 10 ]
  738. );
  739. return this;
  740. },
  741. multiply: function ( m ) {
  742. return this.multiplyMatrices( this, m );
  743. },
  744. premultiply: function ( m ) {
  745. return this.multiplyMatrices( m, this );
  746. },
  747. multiplyMatrices: function ( a, b ) {
  748. const ae = a.elements;
  749. const be = b.elements;
  750. const te = this.elements;
  751. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  752. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  753. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  754. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  755. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  756. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  757. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  758. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  759. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  760. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  761. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  762. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  763. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  764. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  765. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  766. return this;
  767. },
  768. multiplyScalar: function ( s ) {
  769. const te = this.elements;
  770. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  771. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  772. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  773. return this;
  774. },
  775. determinant: function () {
  776. const te = this.elements;
  777. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  778. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  779. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  780. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  781. },
  782. getInverse: function ( matrix, throwOnDegenerate ) {
  783. if ( throwOnDegenerate !== undefined ) {
  784. console.warn( "THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate." );
  785. }
  786. const me = matrix.elements,
  787. te = this.elements,
  788. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  789. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  790. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  791. t11 = n33 * n22 - n32 * n23,
  792. t12 = n32 * n13 - n33 * n12,
  793. t13 = n23 * n12 - n22 * n13,
  794. det = n11 * t11 + n21 * t12 + n31 * t13;
  795. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  796. const detInv = 1 / det;
  797. te[ 0 ] = t11 * detInv;
  798. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  799. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  800. te[ 3 ] = t12 * detInv;
  801. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  802. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  803. te[ 6 ] = t13 * detInv;
  804. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  805. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  806. return this;
  807. },
  808. transpose: function () {
  809. let tmp;
  810. const m = this.elements;
  811. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  812. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  813. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  814. return this;
  815. },
  816. getNormalMatrix: function ( matrix4 ) {
  817. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  818. },
  819. transposeIntoArray: function ( r ) {
  820. const m = this.elements;
  821. r[ 0 ] = m[ 0 ];
  822. r[ 1 ] = m[ 3 ];
  823. r[ 2 ] = m[ 6 ];
  824. r[ 3 ] = m[ 1 ];
  825. r[ 4 ] = m[ 4 ];
  826. r[ 5 ] = m[ 7 ];
  827. r[ 6 ] = m[ 2 ];
  828. r[ 7 ] = m[ 5 ];
  829. r[ 8 ] = m[ 8 ];
  830. return this;
  831. },
  832. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  833. const c = Math.cos( rotation );
  834. const s = Math.sin( rotation );
  835. this.set(
  836. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  837. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  838. 0, 0, 1
  839. );
  840. },
  841. scale: function ( sx, sy ) {
  842. const te = this.elements;
  843. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  844. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  845. return this;
  846. },
  847. rotate: function ( theta ) {
  848. const c = Math.cos( theta );
  849. const s = Math.sin( theta );
  850. const te = this.elements;
  851. const a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  852. const a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  853. te[ 0 ] = c * a11 + s * a21;
  854. te[ 3 ] = c * a12 + s * a22;
  855. te[ 6 ] = c * a13 + s * a23;
  856. te[ 1 ] = - s * a11 + c * a21;
  857. te[ 4 ] = - s * a12 + c * a22;
  858. te[ 7 ] = - s * a13 + c * a23;
  859. return this;
  860. },
  861. translate: function ( tx, ty ) {
  862. const te = this.elements;
  863. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  864. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  865. return this;
  866. },
  867. equals: function ( matrix ) {
  868. const te = this.elements;
  869. const me = matrix.elements;
  870. for ( let i = 0; i < 9; i ++ ) {
  871. if ( te[ i ] !== me[ i ] ) return false;
  872. }
  873. return true;
  874. },
  875. fromArray: function ( array, offset ) {
  876. if ( offset === undefined ) offset = 0;
  877. for ( let i = 0; i < 9; i ++ ) {
  878. this.elements[ i ] = array[ i + offset ];
  879. }
  880. return this;
  881. },
  882. toArray: function ( array, offset ) {
  883. if ( array === undefined ) array = [];
  884. if ( offset === undefined ) offset = 0;
  885. const te = this.elements;
  886. array[ offset ] = te[ 0 ];
  887. array[ offset + 1 ] = te[ 1 ];
  888. array[ offset + 2 ] = te[ 2 ];
  889. array[ offset + 3 ] = te[ 3 ];
  890. array[ offset + 4 ] = te[ 4 ];
  891. array[ offset + 5 ] = te[ 5 ];
  892. array[ offset + 6 ] = te[ 6 ];
  893. array[ offset + 7 ] = te[ 7 ];
  894. array[ offset + 8 ] = te[ 8 ];
  895. return array;
  896. }
  897. } );
  898. /**
  899. * @author mrdoob / http://mrdoob.com/
  900. * @author alteredq / http://alteredqualia.com/
  901. * @author szimek / https://github.com/szimek/
  902. */
  903. let _canvas;
  904. const ImageUtils = {
  905. getDataURL: function ( image ) {
  906. if ( /^data:/i.test( image.src ) ) {
  907. return image.src;
  908. }
  909. if ( typeof HTMLCanvasElement == 'undefined' ) {
  910. return image.src;
  911. }
  912. let canvas;
  913. if ( image instanceof HTMLCanvasElement ) {
  914. canvas = image;
  915. } else {
  916. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  917. _canvas.width = image.width;
  918. _canvas.height = image.height;
  919. const context = _canvas.getContext( '2d' );
  920. if ( image instanceof ImageData ) {
  921. context.putImageData( image, 0, 0 );
  922. } else {
  923. context.drawImage( image, 0, 0, image.width, image.height );
  924. }
  925. canvas = _canvas;
  926. }
  927. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  928. return canvas.toDataURL( 'image/jpeg', 0.6 );
  929. } else {
  930. return canvas.toDataURL( 'image/png' );
  931. }
  932. }
  933. };
  934. /**
  935. * @author mrdoob / http://mrdoob.com/
  936. * @author alteredq / http://alteredqualia.com/
  937. * @author szimek / https://github.com/szimek/
  938. */
  939. let textureId = 0;
  940. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  941. Object.defineProperty( this, 'id', { value: textureId ++ } );
  942. this.uuid = MathUtils.generateUUID();
  943. this.name = '';
  944. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  945. this.mipmaps = [];
  946. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  947. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  948. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  949. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  950. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  951. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  952. this.format = format !== undefined ? format : RGBAFormat;
  953. this.internalFormat = null;
  954. this.type = type !== undefined ? type : UnsignedByteType;
  955. this.offset = new Vector2( 0, 0 );
  956. this.repeat = new Vector2( 1, 1 );
  957. this.center = new Vector2( 0, 0 );
  958. this.rotation = 0;
  959. this.matrixAutoUpdate = true;
  960. this.matrix = new Matrix3();
  961. this.generateMipmaps = true;
  962. this.premultiplyAlpha = false;
  963. this.flipY = true;
  964. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  965. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  966. //
  967. // Also changing the encoding after already used by a Material will not automatically make the Material
  968. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  969. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  970. this.version = 0;
  971. this.onUpdate = null;
  972. }
  973. Texture.DEFAULT_IMAGE = undefined;
  974. Texture.DEFAULT_MAPPING = UVMapping;
  975. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  976. constructor: Texture,
  977. isTexture: true,
  978. updateMatrix: function () {
  979. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  980. },
  981. clone: function () {
  982. return new this.constructor().copy( this );
  983. },
  984. copy: function ( source ) {
  985. this.name = source.name;
  986. this.image = source.image;
  987. this.mipmaps = source.mipmaps.slice( 0 );
  988. this.mapping = source.mapping;
  989. this.wrapS = source.wrapS;
  990. this.wrapT = source.wrapT;
  991. this.magFilter = source.magFilter;
  992. this.minFilter = source.minFilter;
  993. this.anisotropy = source.anisotropy;
  994. this.format = source.format;
  995. this.internalFormat = source.internalFormat;
  996. this.type = source.type;
  997. this.offset.copy( source.offset );
  998. this.repeat.copy( source.repeat );
  999. this.center.copy( source.center );
  1000. this.rotation = source.rotation;
  1001. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1002. this.matrix.copy( source.matrix );
  1003. this.generateMipmaps = source.generateMipmaps;
  1004. this.premultiplyAlpha = source.premultiplyAlpha;
  1005. this.flipY = source.flipY;
  1006. this.unpackAlignment = source.unpackAlignment;
  1007. this.encoding = source.encoding;
  1008. return this;
  1009. },
  1010. toJSON: function ( meta ) {
  1011. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1012. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1013. return meta.textures[ this.uuid ];
  1014. }
  1015. const output = {
  1016. metadata: {
  1017. version: 4.5,
  1018. type: 'Texture',
  1019. generator: 'Texture.toJSON'
  1020. },
  1021. uuid: this.uuid,
  1022. name: this.name,
  1023. mapping: this.mapping,
  1024. repeat: [ this.repeat.x, this.repeat.y ],
  1025. offset: [ this.offset.x, this.offset.y ],
  1026. center: [ this.center.x, this.center.y ],
  1027. rotation: this.rotation,
  1028. wrap: [ this.wrapS, this.wrapT ],
  1029. format: this.format,
  1030. type: this.type,
  1031. encoding: this.encoding,
  1032. minFilter: this.minFilter,
  1033. magFilter: this.magFilter,
  1034. anisotropy: this.anisotropy,
  1035. flipY: this.flipY,
  1036. premultiplyAlpha: this.premultiplyAlpha,
  1037. unpackAlignment: this.unpackAlignment
  1038. };
  1039. if ( this.image !== undefined ) {
  1040. // TODO: Move to THREE.Image
  1041. const image = this.image;
  1042. if ( image.uuid === undefined ) {
  1043. image.uuid = MathUtils.generateUUID(); // UGH
  1044. }
  1045. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1046. let url;
  1047. if ( Array.isArray( image ) ) {
  1048. // process array of images e.g. CubeTexture
  1049. url = [];
  1050. for ( let i = 0, l = image.length; i < l; i ++ ) {
  1051. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1052. }
  1053. } else {
  1054. // process single image
  1055. url = ImageUtils.getDataURL( image );
  1056. }
  1057. meta.images[ image.uuid ] = {
  1058. uuid: image.uuid,
  1059. url: url
  1060. };
  1061. }
  1062. output.image = image.uuid;
  1063. }
  1064. if ( ! isRootObject ) {
  1065. meta.textures[ this.uuid ] = output;
  1066. }
  1067. return output;
  1068. },
  1069. dispose: function () {
  1070. this.dispatchEvent( { type: 'dispose' } );
  1071. },
  1072. transformUv: function ( uv ) {
  1073. if ( this.mapping !== UVMapping ) return uv;
  1074. uv.applyMatrix3( this.matrix );
  1075. if ( uv.x < 0 || uv.x > 1 ) {
  1076. switch ( this.wrapS ) {
  1077. case RepeatWrapping:
  1078. uv.x = uv.x - Math.floor( uv.x );
  1079. break;
  1080. case ClampToEdgeWrapping:
  1081. uv.x = uv.x < 0 ? 0 : 1;
  1082. break;
  1083. case MirroredRepeatWrapping:
  1084. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1085. uv.x = Math.ceil( uv.x ) - uv.x;
  1086. } else {
  1087. uv.x = uv.x - Math.floor( uv.x );
  1088. }
  1089. break;
  1090. }
  1091. }
  1092. if ( uv.y < 0 || uv.y > 1 ) {
  1093. switch ( this.wrapT ) {
  1094. case RepeatWrapping:
  1095. uv.y = uv.y - Math.floor( uv.y );
  1096. break;
  1097. case ClampToEdgeWrapping:
  1098. uv.y = uv.y < 0 ? 0 : 1;
  1099. break;
  1100. case MirroredRepeatWrapping:
  1101. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1102. uv.y = Math.ceil( uv.y ) - uv.y;
  1103. } else {
  1104. uv.y = uv.y - Math.floor( uv.y );
  1105. }
  1106. break;
  1107. }
  1108. }
  1109. if ( this.flipY ) {
  1110. uv.y = 1 - uv.y;
  1111. }
  1112. return uv;
  1113. }
  1114. } );
  1115. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1116. set: function ( value ) {
  1117. if ( value === true ) this.version ++;
  1118. }
  1119. } );
  1120. /**
  1121. * @author supereggbert / http://www.paulbrunt.co.uk/
  1122. * @author philogb / http://blog.thejit.org/
  1123. * @author mikael emtinger / http://gomo.se/
  1124. * @author egraether / http://egraether.com/
  1125. * @author WestLangley / http://github.com/WestLangley
  1126. */
  1127. function Vector4( x = 0, y = 0, z = 0, w = 1 ) {
  1128. this.x = x;
  1129. this.y = y;
  1130. this.z = z;
  1131. this.w = w;
  1132. }
  1133. Object.defineProperties( Vector4.prototype, {
  1134. "width": {
  1135. get: function () {
  1136. return this.z;
  1137. },
  1138. set: function ( value ) {
  1139. this.z = value;
  1140. }
  1141. },
  1142. "height": {
  1143. get: function () {
  1144. return this.w;
  1145. },
  1146. set: function ( value ) {
  1147. this.w = value;
  1148. }
  1149. }
  1150. } );
  1151. Object.assign( Vector4.prototype, {
  1152. isVector4: true,
  1153. set: function ( x, y, z, w ) {
  1154. this.x = x;
  1155. this.y = y;
  1156. this.z = z;
  1157. this.w = w;
  1158. return this;
  1159. },
  1160. setScalar: function ( scalar ) {
  1161. this.x = scalar;
  1162. this.y = scalar;
  1163. this.z = scalar;
  1164. this.w = scalar;
  1165. return this;
  1166. },
  1167. setX: function ( x ) {
  1168. this.x = x;
  1169. return this;
  1170. },
  1171. setY: function ( y ) {
  1172. this.y = y;
  1173. return this;
  1174. },
  1175. setZ: function ( z ) {
  1176. this.z = z;
  1177. return this;
  1178. },
  1179. setW: function ( w ) {
  1180. this.w = w;
  1181. return this;
  1182. },
  1183. setComponent: function ( index, value ) {
  1184. switch ( index ) {
  1185. case 0: this.x = value; break;
  1186. case 1: this.y = value; break;
  1187. case 2: this.z = value; break;
  1188. case 3: this.w = value; break;
  1189. default: throw new Error( 'index is out of range: ' + index );
  1190. }
  1191. return this;
  1192. },
  1193. getComponent: function ( index ) {
  1194. switch ( index ) {
  1195. case 0: return this.x;
  1196. case 1: return this.y;
  1197. case 2: return this.z;
  1198. case 3: return this.w;
  1199. default: throw new Error( 'index is out of range: ' + index );
  1200. }
  1201. },
  1202. clone: function () {
  1203. return new this.constructor( this.x, this.y, this.z, this.w );
  1204. },
  1205. copy: function ( v ) {
  1206. this.x = v.x;
  1207. this.y = v.y;
  1208. this.z = v.z;
  1209. this.w = ( v.w !== undefined ) ? v.w : 1;
  1210. return this;
  1211. },
  1212. add: function ( v, w ) {
  1213. if ( w !== undefined ) {
  1214. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1215. return this.addVectors( v, w );
  1216. }
  1217. this.x += v.x;
  1218. this.y += v.y;
  1219. this.z += v.z;
  1220. this.w += v.w;
  1221. return this;
  1222. },
  1223. addScalar: function ( s ) {
  1224. this.x += s;
  1225. this.y += s;
  1226. this.z += s;
  1227. this.w += s;
  1228. return this;
  1229. },
  1230. addVectors: function ( a, b ) {
  1231. this.x = a.x + b.x;
  1232. this.y = a.y + b.y;
  1233. this.z = a.z + b.z;
  1234. this.w = a.w + b.w;
  1235. return this;
  1236. },
  1237. addScaledVector: function ( v, s ) {
  1238. this.x += v.x * s;
  1239. this.y += v.y * s;
  1240. this.z += v.z * s;
  1241. this.w += v.w * s;
  1242. return this;
  1243. },
  1244. sub: function ( v, w ) {
  1245. if ( w !== undefined ) {
  1246. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1247. return this.subVectors( v, w );
  1248. }
  1249. this.x -= v.x;
  1250. this.y -= v.y;
  1251. this.z -= v.z;
  1252. this.w -= v.w;
  1253. return this;
  1254. },
  1255. subScalar: function ( s ) {
  1256. this.x -= s;
  1257. this.y -= s;
  1258. this.z -= s;
  1259. this.w -= s;
  1260. return this;
  1261. },
  1262. subVectors: function ( a, b ) {
  1263. this.x = a.x - b.x;
  1264. this.y = a.y - b.y;
  1265. this.z = a.z - b.z;
  1266. this.w = a.w - b.w;
  1267. return this;
  1268. },
  1269. multiplyScalar: function ( scalar ) {
  1270. this.x *= scalar;
  1271. this.y *= scalar;
  1272. this.z *= scalar;
  1273. this.w *= scalar;
  1274. return this;
  1275. },
  1276. applyMatrix4: function ( m ) {
  1277. const x = this.x, y = this.y, z = this.z, w = this.w;
  1278. const e = m.elements;
  1279. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1280. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1281. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1282. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1283. return this;
  1284. },
  1285. divideScalar: function ( scalar ) {
  1286. return this.multiplyScalar( 1 / scalar );
  1287. },
  1288. setAxisAngleFromQuaternion: function ( q ) {
  1289. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1290. // q is assumed to be normalized
  1291. this.w = 2 * Math.acos( q.w );
  1292. const s = Math.sqrt( 1 - q.w * q.w );
  1293. if ( s < 0.0001 ) {
  1294. this.x = 1;
  1295. this.y = 0;
  1296. this.z = 0;
  1297. } else {
  1298. this.x = q.x / s;
  1299. this.y = q.y / s;
  1300. this.z = q.z / s;
  1301. }
  1302. return this;
  1303. },
  1304. setAxisAngleFromRotationMatrix: function ( m ) {
  1305. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1306. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1307. let angle, x, y, z; // variables for result
  1308. const epsilon = 0.01, // margin to allow for rounding errors
  1309. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1310. te = m.elements,
  1311. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1312. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1313. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1314. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1315. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1316. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1317. // singularity found
  1318. // first check for identity matrix which must have +1 for all terms
  1319. // in leading diagonal and zero in other terms
  1320. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1321. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1322. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1323. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1324. // this singularity is identity matrix so angle = 0
  1325. this.set( 1, 0, 0, 0 );
  1326. return this; // zero angle, arbitrary axis
  1327. }
  1328. // otherwise this singularity is angle = 180
  1329. angle = Math.PI;
  1330. const xx = ( m11 + 1 ) / 2;
  1331. const yy = ( m22 + 1 ) / 2;
  1332. const zz = ( m33 + 1 ) / 2;
  1333. const xy = ( m12 + m21 ) / 4;
  1334. const xz = ( m13 + m31 ) / 4;
  1335. const yz = ( m23 + m32 ) / 4;
  1336. if ( ( xx > yy ) && ( xx > zz ) ) {
  1337. // m11 is the largest diagonal term
  1338. if ( xx < epsilon ) {
  1339. x = 0;
  1340. y = 0.707106781;
  1341. z = 0.707106781;
  1342. } else {
  1343. x = Math.sqrt( xx );
  1344. y = xy / x;
  1345. z = xz / x;
  1346. }
  1347. } else if ( yy > zz ) {
  1348. // m22 is the largest diagonal term
  1349. if ( yy < epsilon ) {
  1350. x = 0.707106781;
  1351. y = 0;
  1352. z = 0.707106781;
  1353. } else {
  1354. y = Math.sqrt( yy );
  1355. x = xy / y;
  1356. z = yz / y;
  1357. }
  1358. } else {
  1359. // m33 is the largest diagonal term so base result on this
  1360. if ( zz < epsilon ) {
  1361. x = 0.707106781;
  1362. y = 0.707106781;
  1363. z = 0;
  1364. } else {
  1365. z = Math.sqrt( zz );
  1366. x = xz / z;
  1367. y = yz / z;
  1368. }
  1369. }
  1370. this.set( x, y, z, angle );
  1371. return this; // return 180 deg rotation
  1372. }
  1373. // as we have reached here there are no singularities so we can handle normally
  1374. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1375. ( m13 - m31 ) * ( m13 - m31 ) +
  1376. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1377. if ( Math.abs( s ) < 0.001 ) s = 1;
  1378. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1379. // caught by singularity test above, but I've left it in just in case
  1380. this.x = ( m32 - m23 ) / s;
  1381. this.y = ( m13 - m31 ) / s;
  1382. this.z = ( m21 - m12 ) / s;
  1383. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1384. return this;
  1385. },
  1386. min: function ( v ) {
  1387. this.x = Math.min( this.x, v.x );
  1388. this.y = Math.min( this.y, v.y );
  1389. this.z = Math.min( this.z, v.z );
  1390. this.w = Math.min( this.w, v.w );
  1391. return this;
  1392. },
  1393. max: function ( v ) {
  1394. this.x = Math.max( this.x, v.x );
  1395. this.y = Math.max( this.y, v.y );
  1396. this.z = Math.max( this.z, v.z );
  1397. this.w = Math.max( this.w, v.w );
  1398. return this;
  1399. },
  1400. clamp: function ( min, max ) {
  1401. // assumes min < max, componentwise
  1402. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1403. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1404. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1405. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1406. return this;
  1407. },
  1408. clampScalar: function ( minVal, maxVal ) {
  1409. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1410. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1411. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1412. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1413. return this;
  1414. },
  1415. clampLength: function ( min, max ) {
  1416. const length = this.length();
  1417. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1418. },
  1419. floor: function () {
  1420. this.x = Math.floor( this.x );
  1421. this.y = Math.floor( this.y );
  1422. this.z = Math.floor( this.z );
  1423. this.w = Math.floor( this.w );
  1424. return this;
  1425. },
  1426. ceil: function () {
  1427. this.x = Math.ceil( this.x );
  1428. this.y = Math.ceil( this.y );
  1429. this.z = Math.ceil( this.z );
  1430. this.w = Math.ceil( this.w );
  1431. return this;
  1432. },
  1433. round: function () {
  1434. this.x = Math.round( this.x );
  1435. this.y = Math.round( this.y );
  1436. this.z = Math.round( this.z );
  1437. this.w = Math.round( this.w );
  1438. return this;
  1439. },
  1440. roundToZero: function () {
  1441. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1442. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1443. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1444. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1445. return this;
  1446. },
  1447. negate: function () {
  1448. this.x = - this.x;
  1449. this.y = - this.y;
  1450. this.z = - this.z;
  1451. this.w = - this.w;
  1452. return this;
  1453. },
  1454. dot: function ( v ) {
  1455. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1456. },
  1457. lengthSq: function () {
  1458. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1459. },
  1460. length: function () {
  1461. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1462. },
  1463. manhattanLength: function () {
  1464. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1465. },
  1466. normalize: function () {
  1467. return this.divideScalar( this.length() || 1 );
  1468. },
  1469. setLength: function ( length ) {
  1470. return this.normalize().multiplyScalar( length );
  1471. },
  1472. lerp: function ( v, alpha ) {
  1473. this.x += ( v.x - this.x ) * alpha;
  1474. this.y += ( v.y - this.y ) * alpha;
  1475. this.z += ( v.z - this.z ) * alpha;
  1476. this.w += ( v.w - this.w ) * alpha;
  1477. return this;
  1478. },
  1479. lerpVectors: function ( v1, v2, alpha ) {
  1480. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1481. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1482. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1483. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1484. return this;
  1485. },
  1486. equals: function ( v ) {
  1487. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1488. },
  1489. fromArray: function ( array, offset ) {
  1490. if ( offset === undefined ) offset = 0;
  1491. this.x = array[ offset ];
  1492. this.y = array[ offset + 1 ];
  1493. this.z = array[ offset + 2 ];
  1494. this.w = array[ offset + 3 ];
  1495. return this;
  1496. },
  1497. toArray: function ( array, offset ) {
  1498. if ( array === undefined ) array = [];
  1499. if ( offset === undefined ) offset = 0;
  1500. array[ offset ] = this.x;
  1501. array[ offset + 1 ] = this.y;
  1502. array[ offset + 2 ] = this.z;
  1503. array[ offset + 3 ] = this.w;
  1504. return array;
  1505. },
  1506. fromBufferAttribute: function ( attribute, index, offset ) {
  1507. if ( offset !== undefined ) {
  1508. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1509. }
  1510. this.x = attribute.getX( index );
  1511. this.y = attribute.getY( index );
  1512. this.z = attribute.getZ( index );
  1513. this.w = attribute.getW( index );
  1514. return this;
  1515. },
  1516. random: function () {
  1517. this.x = Math.random();
  1518. this.y = Math.random();
  1519. this.z = Math.random();
  1520. this.w = Math.random();
  1521. return this;
  1522. }
  1523. } );
  1524. /**
  1525. * @author szimek / https://github.com/szimek/
  1526. * @author alteredq / http://alteredqualia.com/
  1527. * @author Marius Kintel / https://github.com/kintel
  1528. */
  1529. /*
  1530. In options, we can specify:
  1531. * Texture parameters for an auto-generated target texture
  1532. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1533. */
  1534. function WebGLRenderTarget( width, height, options ) {
  1535. this.width = width;
  1536. this.height = height;
  1537. this.scissor = new Vector4( 0, 0, width, height );
  1538. this.scissorTest = false;
  1539. this.viewport = new Vector4( 0, 0, width, height );
  1540. options = options || {};
  1541. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1542. this.texture.image = {};
  1543. this.texture.image.width = width;
  1544. this.texture.image.height = height;
  1545. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1546. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1547. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1548. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  1549. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1550. }
  1551. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1552. constructor: WebGLRenderTarget,
  1553. isWebGLRenderTarget: true,
  1554. setSize: function ( width, height ) {
  1555. if ( this.width !== width || this.height !== height ) {
  1556. this.width = width;
  1557. this.height = height;
  1558. this.texture.image.width = width;
  1559. this.texture.image.height = height;
  1560. this.dispose();
  1561. }
  1562. this.viewport.set( 0, 0, width, height );
  1563. this.scissor.set( 0, 0, width, height );
  1564. },
  1565. clone: function () {
  1566. return new this.constructor().copy( this );
  1567. },
  1568. copy: function ( source ) {
  1569. this.width = source.width;
  1570. this.height = source.height;
  1571. this.viewport.copy( source.viewport );
  1572. this.texture = source.texture.clone();
  1573. this.depthBuffer = source.depthBuffer;
  1574. this.stencilBuffer = source.stencilBuffer;
  1575. this.depthTexture = source.depthTexture;
  1576. return this;
  1577. },
  1578. dispose: function () {
  1579. this.dispatchEvent( { type: 'dispose' } );
  1580. }
  1581. } );
  1582. /**
  1583. * @author Mugen87 / https://github.com/Mugen87
  1584. * @author Matt DesLauriers / @mattdesl
  1585. */
  1586. function WebGLMultisampleRenderTarget( width, height, options ) {
  1587. WebGLRenderTarget.call( this, width, height, options );
  1588. this.samples = 4;
  1589. }
  1590. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  1591. constructor: WebGLMultisampleRenderTarget,
  1592. isWebGLMultisampleRenderTarget: true,
  1593. copy: function ( source ) {
  1594. WebGLRenderTarget.prototype.copy.call( this, source );
  1595. this.samples = source.samples;
  1596. return this;
  1597. }
  1598. } );
  1599. /**
  1600. * @author mikael emtinger / http://gomo.se/
  1601. * @author alteredq / http://alteredqualia.com/
  1602. * @author WestLangley / http://github.com/WestLangley
  1603. * @author bhouston / http://clara.io
  1604. */
  1605. function Quaternion( x = 0, y = 0, z = 0, w = 1 ) {
  1606. this._x = x;
  1607. this._y = y;
  1608. this._z = z;
  1609. this._w = w;
  1610. }
  1611. Object.assign( Quaternion, {
  1612. slerp: function ( qa, qb, qm, t ) {
  1613. return qm.copy( qa ).slerp( qb, t );
  1614. },
  1615. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1616. // fuzz-free, array-based Quaternion SLERP operation
  1617. let x0 = src0[ srcOffset0 + 0 ],
  1618. y0 = src0[ srcOffset0 + 1 ],
  1619. z0 = src0[ srcOffset0 + 2 ],
  1620. w0 = src0[ srcOffset0 + 3 ];
  1621. const x1 = src1[ srcOffset1 + 0 ],
  1622. y1 = src1[ srcOffset1 + 1 ],
  1623. z1 = src1[ srcOffset1 + 2 ],
  1624. w1 = src1[ srcOffset1 + 3 ];
  1625. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1626. let s = 1 - t,
  1627. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1628. dir = ( cos >= 0 ? 1 : - 1 ),
  1629. sqrSin = 1 - cos * cos;
  1630. // Skip the Slerp for tiny steps to avoid numeric problems:
  1631. if ( sqrSin > Number.EPSILON ) {
  1632. const sin = Math.sqrt( sqrSin ),
  1633. len = Math.atan2( sin, cos * dir );
  1634. s = Math.sin( s * len ) / sin;
  1635. t = Math.sin( t * len ) / sin;
  1636. }
  1637. const tDir = t * dir;
  1638. x0 = x0 * s + x1 * tDir;
  1639. y0 = y0 * s + y1 * tDir;
  1640. z0 = z0 * s + z1 * tDir;
  1641. w0 = w0 * s + w1 * tDir;
  1642. // Normalize in case we just did a lerp:
  1643. if ( s === 1 - t ) {
  1644. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1645. x0 *= f;
  1646. y0 *= f;
  1647. z0 *= f;
  1648. w0 *= f;
  1649. }
  1650. }
  1651. dst[ dstOffset ] = x0;
  1652. dst[ dstOffset + 1 ] = y0;
  1653. dst[ dstOffset + 2 ] = z0;
  1654. dst[ dstOffset + 3 ] = w0;
  1655. },
  1656. multiplyQuaternionsFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1657. const x0 = src0[ srcOffset0 ];
  1658. const y0 = src0[ srcOffset0 + 1 ];
  1659. const z0 = src0[ srcOffset0 + 2 ];
  1660. const w0 = src0[ srcOffset0 + 3 ];
  1661. const x1 = src1[ srcOffset1 ];
  1662. const y1 = src1[ srcOffset1 + 1 ];
  1663. const z1 = src1[ srcOffset1 + 2 ];
  1664. const w1 = src1[ srcOffset1 + 3 ];
  1665. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1666. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1667. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1668. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1669. return dst;
  1670. }
  1671. } );
  1672. Object.defineProperties( Quaternion.prototype, {
  1673. x: {
  1674. get: function () {
  1675. return this._x;
  1676. },
  1677. set: function ( value ) {
  1678. this._x = value;
  1679. this._onChangeCallback();
  1680. }
  1681. },
  1682. y: {
  1683. get: function () {
  1684. return this._y;
  1685. },
  1686. set: function ( value ) {
  1687. this._y = value;
  1688. this._onChangeCallback();
  1689. }
  1690. },
  1691. z: {
  1692. get: function () {
  1693. return this._z;
  1694. },
  1695. set: function ( value ) {
  1696. this._z = value;
  1697. this._onChangeCallback();
  1698. }
  1699. },
  1700. w: {
  1701. get: function () {
  1702. return this._w;
  1703. },
  1704. set: function ( value ) {
  1705. this._w = value;
  1706. this._onChangeCallback();
  1707. }
  1708. }
  1709. } );
  1710. Object.assign( Quaternion.prototype, {
  1711. isQuaternion: true,
  1712. set: function ( x, y, z, w ) {
  1713. this._x = x;
  1714. this._y = y;
  1715. this._z = z;
  1716. this._w = w;
  1717. this._onChangeCallback();
  1718. return this;
  1719. },
  1720. clone: function () {
  1721. return new this.constructor( this._x, this._y, this._z, this._w );
  1722. },
  1723. copy: function ( quaternion ) {
  1724. this._x = quaternion.x;
  1725. this._y = quaternion.y;
  1726. this._z = quaternion.z;
  1727. this._w = quaternion.w;
  1728. this._onChangeCallback();
  1729. return this;
  1730. },
  1731. setFromEuler: function ( euler, update ) {
  1732. if ( ! ( euler && euler.isEuler ) ) {
  1733. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1734. }
  1735. const x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1736. // http://www.mathworks.com/matlabcentral/fileexchange/
  1737. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1738. // content/SpinCalc.m
  1739. const cos = Math.cos;
  1740. const sin = Math.sin;
  1741. const c1 = cos( x / 2 );
  1742. const c2 = cos( y / 2 );
  1743. const c3 = cos( z / 2 );
  1744. const s1 = sin( x / 2 );
  1745. const s2 = sin( y / 2 );
  1746. const s3 = sin( z / 2 );
  1747. switch ( order ) {
  1748. case 'XYZ':
  1749. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1750. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1751. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1752. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1753. break;
  1754. case 'YXZ':
  1755. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1756. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1757. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1758. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1759. break;
  1760. case 'ZXY':
  1761. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1762. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1763. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1764. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1765. break;
  1766. case 'ZYX':
  1767. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1768. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1769. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1770. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1771. break;
  1772. case 'YZX':
  1773. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1774. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1775. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1776. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1777. break;
  1778. case 'XZY':
  1779. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1780. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1781. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1782. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1783. break;
  1784. default:
  1785. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1786. }
  1787. if ( update !== false ) this._onChangeCallback();
  1788. return this;
  1789. },
  1790. setFromAxisAngle: function ( axis, angle ) {
  1791. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1792. // assumes axis is normalized
  1793. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  1794. this._x = axis.x * s;
  1795. this._y = axis.y * s;
  1796. this._z = axis.z * s;
  1797. this._w = Math.cos( halfAngle );
  1798. this._onChangeCallback();
  1799. return this;
  1800. },
  1801. setFromRotationMatrix: function ( m ) {
  1802. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1803. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1804. const te = m.elements,
  1805. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1806. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1807. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1808. trace = m11 + m22 + m33;
  1809. if ( trace > 0 ) {
  1810. const s = 0.5 / Math.sqrt( trace + 1.0 );
  1811. this._w = 0.25 / s;
  1812. this._x = ( m32 - m23 ) * s;
  1813. this._y = ( m13 - m31 ) * s;
  1814. this._z = ( m21 - m12 ) * s;
  1815. } else if ( m11 > m22 && m11 > m33 ) {
  1816. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1817. this._w = ( m32 - m23 ) / s;
  1818. this._x = 0.25 * s;
  1819. this._y = ( m12 + m21 ) / s;
  1820. this._z = ( m13 + m31 ) / s;
  1821. } else if ( m22 > m33 ) {
  1822. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1823. this._w = ( m13 - m31 ) / s;
  1824. this._x = ( m12 + m21 ) / s;
  1825. this._y = 0.25 * s;
  1826. this._z = ( m23 + m32 ) / s;
  1827. } else {
  1828. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1829. this._w = ( m21 - m12 ) / s;
  1830. this._x = ( m13 + m31 ) / s;
  1831. this._y = ( m23 + m32 ) / s;
  1832. this._z = 0.25 * s;
  1833. }
  1834. this._onChangeCallback();
  1835. return this;
  1836. },
  1837. setFromUnitVectors: function ( vFrom, vTo ) {
  1838. // assumes direction vectors vFrom and vTo are normalized
  1839. const EPS = 0.000001;
  1840. let r = vFrom.dot( vTo ) + 1;
  1841. if ( r < EPS ) {
  1842. r = 0;
  1843. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1844. this._x = - vFrom.y;
  1845. this._y = vFrom.x;
  1846. this._z = 0;
  1847. this._w = r;
  1848. } else {
  1849. this._x = 0;
  1850. this._y = - vFrom.z;
  1851. this._z = vFrom.y;
  1852. this._w = r;
  1853. }
  1854. } else {
  1855. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1856. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1857. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1858. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1859. this._w = r;
  1860. }
  1861. return this.normalize();
  1862. },
  1863. angleTo: function ( q ) {
  1864. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1865. },
  1866. rotateTowards: function ( q, step ) {
  1867. const angle = this.angleTo( q );
  1868. if ( angle === 0 ) return this;
  1869. const t = Math.min( 1, step / angle );
  1870. this.slerp( q, t );
  1871. return this;
  1872. },
  1873. inverse: function () {
  1874. // quaternion is assumed to have unit length
  1875. return this.conjugate();
  1876. },
  1877. conjugate: function () {
  1878. this._x *= - 1;
  1879. this._y *= - 1;
  1880. this._z *= - 1;
  1881. this._onChangeCallback();
  1882. return this;
  1883. },
  1884. dot: function ( v ) {
  1885. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1886. },
  1887. lengthSq: function () {
  1888. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1889. },
  1890. length: function () {
  1891. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1892. },
  1893. normalize: function () {
  1894. let l = this.length();
  1895. if ( l === 0 ) {
  1896. this._x = 0;
  1897. this._y = 0;
  1898. this._z = 0;
  1899. this._w = 1;
  1900. } else {
  1901. l = 1 / l;
  1902. this._x = this._x * l;
  1903. this._y = this._y * l;
  1904. this._z = this._z * l;
  1905. this._w = this._w * l;
  1906. }
  1907. this._onChangeCallback();
  1908. return this;
  1909. },
  1910. multiply: function ( q, p ) {
  1911. if ( p !== undefined ) {
  1912. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1913. return this.multiplyQuaternions( q, p );
  1914. }
  1915. return this.multiplyQuaternions( this, q );
  1916. },
  1917. premultiply: function ( q ) {
  1918. return this.multiplyQuaternions( q, this );
  1919. },
  1920. multiplyQuaternions: function ( a, b ) {
  1921. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1922. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1923. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1924. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1925. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1926. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1927. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1928. this._onChangeCallback();
  1929. return this;
  1930. },
  1931. slerp: function ( qb, t ) {
  1932. if ( t === 0 ) return this;
  1933. if ( t === 1 ) return this.copy( qb );
  1934. const x = this._x, y = this._y, z = this._z, w = this._w;
  1935. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1936. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1937. if ( cosHalfTheta < 0 ) {
  1938. this._w = - qb._w;
  1939. this._x = - qb._x;
  1940. this._y = - qb._y;
  1941. this._z = - qb._z;
  1942. cosHalfTheta = - cosHalfTheta;
  1943. } else {
  1944. this.copy( qb );
  1945. }
  1946. if ( cosHalfTheta >= 1.0 ) {
  1947. this._w = w;
  1948. this._x = x;
  1949. this._y = y;
  1950. this._z = z;
  1951. return this;
  1952. }
  1953. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1954. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1955. const s = 1 - t;
  1956. this._w = s * w + t * this._w;
  1957. this._x = s * x + t * this._x;
  1958. this._y = s * y + t * this._y;
  1959. this._z = s * z + t * this._z;
  1960. this.normalize();
  1961. this._onChangeCallback();
  1962. return this;
  1963. }
  1964. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1965. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1966. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1967. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1968. this._w = ( w * ratioA + this._w * ratioB );
  1969. this._x = ( x * ratioA + this._x * ratioB );
  1970. this._y = ( y * ratioA + this._y * ratioB );
  1971. this._z = ( z * ratioA + this._z * ratioB );
  1972. this._onChangeCallback();
  1973. return this;
  1974. },
  1975. equals: function ( quaternion ) {
  1976. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1977. },
  1978. fromArray: function ( array, offset ) {
  1979. if ( offset === undefined ) offset = 0;
  1980. this._x = array[ offset ];
  1981. this._y = array[ offset + 1 ];
  1982. this._z = array[ offset + 2 ];
  1983. this._w = array[ offset + 3 ];
  1984. this._onChangeCallback();
  1985. return this;
  1986. },
  1987. toArray: function ( array, offset ) {
  1988. if ( array === undefined ) array = [];
  1989. if ( offset === undefined ) offset = 0;
  1990. array[ offset ] = this._x;
  1991. array[ offset + 1 ] = this._y;
  1992. array[ offset + 2 ] = this._z;
  1993. array[ offset + 3 ] = this._w;
  1994. return array;
  1995. },
  1996. fromBufferAttribute: function ( attribute, index ) {
  1997. this._x = attribute.getX( index );
  1998. this._y = attribute.getY( index );
  1999. this._z = attribute.getZ( index );
  2000. this._w = attribute.getW( index );
  2001. return this;
  2002. },
  2003. _onChange: function ( callback ) {
  2004. this._onChangeCallback = callback;
  2005. return this;
  2006. },
  2007. _onChangeCallback: function () {}
  2008. } );
  2009. /**
  2010. * @author mrdoob / http://mrdoob.com/
  2011. * @author kile / http://kile.stravaganza.org/
  2012. * @author philogb / http://blog.thejit.org/
  2013. * @author mikael emtinger / http://gomo.se/
  2014. * @author egraether / http://egraether.com/
  2015. * @author WestLangley / http://github.com/WestLangley
  2016. */
  2017. const _vector = new Vector3();
  2018. const _quaternion = new Quaternion();
  2019. function Vector3( x = 0, y = 0, z = 0 ) {
  2020. this.x = x;
  2021. this.y = y;
  2022. this.z = z;
  2023. }
  2024. Object.assign( Vector3.prototype, {
  2025. isVector3: true,
  2026. set: function ( x, y, z ) {
  2027. this.x = x;
  2028. this.y = y;
  2029. this.z = z;
  2030. return this;
  2031. },
  2032. setScalar: function ( scalar ) {
  2033. this.x = scalar;
  2034. this.y = scalar;
  2035. this.z = scalar;
  2036. return this;
  2037. },
  2038. setX: function ( x ) {
  2039. this.x = x;
  2040. return this;
  2041. },
  2042. setY: function ( y ) {
  2043. this.y = y;
  2044. return this;
  2045. },
  2046. setZ: function ( z ) {
  2047. this.z = z;
  2048. return this;
  2049. },
  2050. setComponent: function ( index, value ) {
  2051. switch ( index ) {
  2052. case 0: this.x = value; break;
  2053. case 1: this.y = value; break;
  2054. case 2: this.z = value; break;
  2055. default: throw new Error( 'index is out of range: ' + index );
  2056. }
  2057. return this;
  2058. },
  2059. getComponent: function ( index ) {
  2060. switch ( index ) {
  2061. case 0: return this.x;
  2062. case 1: return this.y;
  2063. case 2: return this.z;
  2064. default: throw new Error( 'index is out of range: ' + index );
  2065. }
  2066. },
  2067. clone: function () {
  2068. return new this.constructor( this.x, this.y, this.z );
  2069. },
  2070. copy: function ( v ) {
  2071. this.x = v.x;
  2072. this.y = v.y;
  2073. this.z = v.z;
  2074. return this;
  2075. },
  2076. add: function ( v, w ) {
  2077. if ( w !== undefined ) {
  2078. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2079. return this.addVectors( v, w );
  2080. }
  2081. this.x += v.x;
  2082. this.y += v.y;
  2083. this.z += v.z;
  2084. return this;
  2085. },
  2086. addScalar: function ( s ) {
  2087. this.x += s;
  2088. this.y += s;
  2089. this.z += s;
  2090. return this;
  2091. },
  2092. addVectors: function ( a, b ) {
  2093. this.x = a.x + b.x;
  2094. this.y = a.y + b.y;
  2095. this.z = a.z + b.z;
  2096. return this;
  2097. },
  2098. addScaledVector: function ( v, s ) {
  2099. this.x += v.x * s;
  2100. this.y += v.y * s;
  2101. this.z += v.z * s;
  2102. return this;
  2103. },
  2104. sub: function ( v, w ) {
  2105. if ( w !== undefined ) {
  2106. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2107. return this.subVectors( v, w );
  2108. }
  2109. this.x -= v.x;
  2110. this.y -= v.y;
  2111. this.z -= v.z;
  2112. return this;
  2113. },
  2114. subScalar: function ( s ) {
  2115. this.x -= s;
  2116. this.y -= s;
  2117. this.z -= s;
  2118. return this;
  2119. },
  2120. subVectors: function ( a, b ) {
  2121. this.x = a.x - b.x;
  2122. this.y = a.y - b.y;
  2123. this.z = a.z - b.z;
  2124. return this;
  2125. },
  2126. multiply: function ( v, w ) {
  2127. if ( w !== undefined ) {
  2128. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2129. return this.multiplyVectors( v, w );
  2130. }
  2131. this.x *= v.x;
  2132. this.y *= v.y;
  2133. this.z *= v.z;
  2134. return this;
  2135. },
  2136. multiplyScalar: function ( scalar ) {
  2137. this.x *= scalar;
  2138. this.y *= scalar;
  2139. this.z *= scalar;
  2140. return this;
  2141. },
  2142. multiplyVectors: function ( a, b ) {
  2143. this.x = a.x * b.x;
  2144. this.y = a.y * b.y;
  2145. this.z = a.z * b.z;
  2146. return this;
  2147. },
  2148. applyEuler: function ( euler ) {
  2149. if ( ! ( euler && euler.isEuler ) ) {
  2150. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2151. }
  2152. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2153. },
  2154. applyAxisAngle: function ( axis, angle ) {
  2155. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2156. },
  2157. applyMatrix3: function ( m ) {
  2158. const x = this.x, y = this.y, z = this.z;
  2159. const e = m.elements;
  2160. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2161. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2162. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2163. return this;
  2164. },
  2165. applyNormalMatrix: function ( m ) {
  2166. return this.applyMatrix3( m ).normalize();
  2167. },
  2168. applyMatrix4: function ( m ) {
  2169. const x = this.x, y = this.y, z = this.z;
  2170. const e = m.elements;
  2171. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2172. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2173. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2174. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2175. return this;
  2176. },
  2177. applyQuaternion: function ( q ) {
  2178. const x = this.x, y = this.y, z = this.z;
  2179. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2180. // calculate quat * vector
  2181. const ix = qw * x + qy * z - qz * y;
  2182. const iy = qw * y + qz * x - qx * z;
  2183. const iz = qw * z + qx * y - qy * x;
  2184. const iw = - qx * x - qy * y - qz * z;
  2185. // calculate result * inverse quat
  2186. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2187. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2188. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2189. return this;
  2190. },
  2191. project: function ( camera ) {
  2192. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2193. },
  2194. unproject: function ( camera ) {
  2195. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2196. },
  2197. transformDirection: function ( m ) {
  2198. // input: THREE.Matrix4 affine matrix
  2199. // vector interpreted as a direction
  2200. const x = this.x, y = this.y, z = this.z;
  2201. const e = m.elements;
  2202. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2203. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2204. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2205. return this.normalize();
  2206. },
  2207. divide: function ( v ) {
  2208. this.x /= v.x;
  2209. this.y /= v.y;
  2210. this.z /= v.z;
  2211. return this;
  2212. },
  2213. divideScalar: function ( scalar ) {
  2214. return this.multiplyScalar( 1 / scalar );
  2215. },
  2216. min: function ( v ) {
  2217. this.x = Math.min( this.x, v.x );
  2218. this.y = Math.min( this.y, v.y );
  2219. this.z = Math.min( this.z, v.z );
  2220. return this;
  2221. },
  2222. max: function ( v ) {
  2223. this.x = Math.max( this.x, v.x );
  2224. this.y = Math.max( this.y, v.y );
  2225. this.z = Math.max( this.z, v.z );
  2226. return this;
  2227. },
  2228. clamp: function ( min, max ) {
  2229. // assumes min < max, componentwise
  2230. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2231. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2232. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2233. return this;
  2234. },
  2235. clampScalar: function ( minVal, maxVal ) {
  2236. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2237. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2238. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2239. return this;
  2240. },
  2241. clampLength: function ( min, max ) {
  2242. const length = this.length();
  2243. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2244. },
  2245. floor: function () {
  2246. this.x = Math.floor( this.x );
  2247. this.y = Math.floor( this.y );
  2248. this.z = Math.floor( this.z );
  2249. return this;
  2250. },
  2251. ceil: function () {
  2252. this.x = Math.ceil( this.x );
  2253. this.y = Math.ceil( this.y );
  2254. this.z = Math.ceil( this.z );
  2255. return this;
  2256. },
  2257. round: function () {
  2258. this.x = Math.round( this.x );
  2259. this.y = Math.round( this.y );
  2260. this.z = Math.round( this.z );
  2261. return this;
  2262. },
  2263. roundToZero: function () {
  2264. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2265. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2266. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2267. return this;
  2268. },
  2269. negate: function () {
  2270. this.x = - this.x;
  2271. this.y = - this.y;
  2272. this.z = - this.z;
  2273. return this;
  2274. },
  2275. dot: function ( v ) {
  2276. return this.x * v.x + this.y * v.y + this.z * v.z;
  2277. },
  2278. // TODO lengthSquared?
  2279. lengthSq: function () {
  2280. return this.x * this.x + this.y * this.y + this.z * this.z;
  2281. },
  2282. length: function () {
  2283. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2284. },
  2285. manhattanLength: function () {
  2286. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2287. },
  2288. normalize: function () {
  2289. return this.divideScalar( this.length() || 1 );
  2290. },
  2291. setLength: function ( length ) {
  2292. return this.normalize().multiplyScalar( length );
  2293. },
  2294. lerp: function ( v, alpha ) {
  2295. this.x += ( v.x - this.x ) * alpha;
  2296. this.y += ( v.y - this.y ) * alpha;
  2297. this.z += ( v.z - this.z ) * alpha;
  2298. return this;
  2299. },
  2300. lerpVectors: function ( v1, v2, alpha ) {
  2301. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2302. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2303. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2304. return this;
  2305. },
  2306. cross: function ( v, w ) {
  2307. if ( w !== undefined ) {
  2308. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2309. return this.crossVectors( v, w );
  2310. }
  2311. return this.crossVectors( this, v );
  2312. },
  2313. crossVectors: function ( a, b ) {
  2314. const ax = a.x, ay = a.y, az = a.z;
  2315. const bx = b.x, by = b.y, bz = b.z;
  2316. this.x = ay * bz - az * by;
  2317. this.y = az * bx - ax * bz;
  2318. this.z = ax * by - ay * bx;
  2319. return this;
  2320. },
  2321. projectOnVector: function ( v ) {
  2322. const denominator = v.lengthSq();
  2323. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2324. const scalar = v.dot( this ) / denominator;
  2325. return this.copy( v ).multiplyScalar( scalar );
  2326. },
  2327. projectOnPlane: function ( planeNormal ) {
  2328. _vector.copy( this ).projectOnVector( planeNormal );
  2329. return this.sub( _vector );
  2330. },
  2331. reflect: function ( normal ) {
  2332. // reflect incident vector off plane orthogonal to normal
  2333. // normal is assumed to have unit length
  2334. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2335. },
  2336. angleTo: function ( v ) {
  2337. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2338. if ( denominator === 0 ) return Math.PI / 2;
  2339. const theta = this.dot( v ) / denominator;
  2340. // clamp, to handle numerical problems
  2341. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2342. },
  2343. distanceTo: function ( v ) {
  2344. return Math.sqrt( this.distanceToSquared( v ) );
  2345. },
  2346. distanceToSquared: function ( v ) {
  2347. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2348. return dx * dx + dy * dy + dz * dz;
  2349. },
  2350. manhattanDistanceTo: function ( v ) {
  2351. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2352. },
  2353. setFromSpherical: function ( s ) {
  2354. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2355. },
  2356. setFromSphericalCoords: function ( radius, phi, theta ) {
  2357. const sinPhiRadius = Math.sin( phi ) * radius;
  2358. this.x = sinPhiRadius * Math.sin( theta );
  2359. this.y = Math.cos( phi ) * radius;
  2360. this.z = sinPhiRadius * Math.cos( theta );
  2361. return this;
  2362. },
  2363. setFromCylindrical: function ( c ) {
  2364. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2365. },
  2366. setFromCylindricalCoords: function ( radius, theta, y ) {
  2367. this.x = radius * Math.sin( theta );
  2368. this.y = y;
  2369. this.z = radius * Math.cos( theta );
  2370. return this;
  2371. },
  2372. setFromMatrixPosition: function ( m ) {
  2373. const e = m.elements;
  2374. this.x = e[ 12 ];
  2375. this.y = e[ 13 ];
  2376. this.z = e[ 14 ];
  2377. return this;
  2378. },
  2379. setFromMatrixScale: function ( m ) {
  2380. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2381. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2382. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2383. this.x = sx;
  2384. this.y = sy;
  2385. this.z = sz;
  2386. return this;
  2387. },
  2388. setFromMatrixColumn: function ( m, index ) {
  2389. return this.fromArray( m.elements, index * 4 );
  2390. },
  2391. setFromMatrix3Column: function ( m, index ) {
  2392. return this.fromArray( m.elements, index * 3 );
  2393. },
  2394. equals: function ( v ) {
  2395. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2396. },
  2397. fromArray: function ( array, offset ) {
  2398. if ( offset === undefined ) offset = 0;
  2399. this.x = array[ offset ];
  2400. this.y = array[ offset + 1 ];
  2401. this.z = array[ offset + 2 ];
  2402. return this;
  2403. },
  2404. toArray: function ( array, offset ) {
  2405. if ( array === undefined ) array = [];
  2406. if ( offset === undefined ) offset = 0;
  2407. array[ offset ] = this.x;
  2408. array[ offset + 1 ] = this.y;
  2409. array[ offset + 2 ] = this.z;
  2410. return array;
  2411. },
  2412. fromBufferAttribute: function ( attribute, index, offset ) {
  2413. if ( offset !== undefined ) {
  2414. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2415. }
  2416. this.x = attribute.getX( index );
  2417. this.y = attribute.getY( index );
  2418. this.z = attribute.getZ( index );
  2419. return this;
  2420. },
  2421. random: function () {
  2422. this.x = Math.random();
  2423. this.y = Math.random();
  2424. this.z = Math.random();
  2425. return this;
  2426. }
  2427. } );
  2428. const _v1 = new Vector3();
  2429. const _m1 = new Matrix4();
  2430. const _zero = new Vector3( 0, 0, 0 );
  2431. const _one = new Vector3( 1, 1, 1 );
  2432. const _x = new Vector3();
  2433. const _y = new Vector3();
  2434. const _z = new Vector3();
  2435. /**
  2436. * @author mrdoob / http://mrdoob.com/
  2437. * @author supereggbert / http://www.paulbrunt.co.uk/
  2438. * @author philogb / http://blog.thejit.org/
  2439. * @author jordi_ros / http://plattsoft.com
  2440. * @author D1plo1d / http://github.com/D1plo1d
  2441. * @author alteredq / http://alteredqualia.com/
  2442. * @author mikael emtinger / http://gomo.se/
  2443. * @author timknip / http://www.floorplanner.com/
  2444. * @author bhouston / http://clara.io
  2445. * @author WestLangley / http://github.com/WestLangley
  2446. */
  2447. function Matrix4() {
  2448. this.elements = [
  2449. 1, 0, 0, 0,
  2450. 0, 1, 0, 0,
  2451. 0, 0, 1, 0,
  2452. 0, 0, 0, 1
  2453. ];
  2454. if ( arguments.length > 0 ) {
  2455. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2456. }
  2457. }
  2458. Object.assign( Matrix4.prototype, {
  2459. isMatrix4: true,
  2460. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2461. const te = this.elements;
  2462. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2463. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2464. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2465. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2466. return this;
  2467. },
  2468. identity: function () {
  2469. this.set(
  2470. 1, 0, 0, 0,
  2471. 0, 1, 0, 0,
  2472. 0, 0, 1, 0,
  2473. 0, 0, 0, 1
  2474. );
  2475. return this;
  2476. },
  2477. clone: function () {
  2478. return new Matrix4().fromArray( this.elements );
  2479. },
  2480. copy: function ( m ) {
  2481. const te = this.elements;
  2482. const me = m.elements;
  2483. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2484. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2485. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2486. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2487. return this;
  2488. },
  2489. copyPosition: function ( m ) {
  2490. const te = this.elements, me = m.elements;
  2491. te[ 12 ] = me[ 12 ];
  2492. te[ 13 ] = me[ 13 ];
  2493. te[ 14 ] = me[ 14 ];
  2494. return this;
  2495. },
  2496. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2497. xAxis.setFromMatrixColumn( this, 0 );
  2498. yAxis.setFromMatrixColumn( this, 1 );
  2499. zAxis.setFromMatrixColumn( this, 2 );
  2500. return this;
  2501. },
  2502. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2503. this.set(
  2504. xAxis.x, yAxis.x, zAxis.x, 0,
  2505. xAxis.y, yAxis.y, zAxis.y, 0,
  2506. xAxis.z, yAxis.z, zAxis.z, 0,
  2507. 0, 0, 0, 1
  2508. );
  2509. return this;
  2510. },
  2511. extractRotation: function ( m ) {
  2512. // this method does not support reflection matrices
  2513. const te = this.elements;
  2514. const me = m.elements;
  2515. const scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length();
  2516. const scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length();
  2517. const scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length();
  2518. te[ 0 ] = me[ 0 ] * scaleX;
  2519. te[ 1 ] = me[ 1 ] * scaleX;
  2520. te[ 2 ] = me[ 2 ] * scaleX;
  2521. te[ 3 ] = 0;
  2522. te[ 4 ] = me[ 4 ] * scaleY;
  2523. te[ 5 ] = me[ 5 ] * scaleY;
  2524. te[ 6 ] = me[ 6 ] * scaleY;
  2525. te[ 7 ] = 0;
  2526. te[ 8 ] = me[ 8 ] * scaleZ;
  2527. te[ 9 ] = me[ 9 ] * scaleZ;
  2528. te[ 10 ] = me[ 10 ] * scaleZ;
  2529. te[ 11 ] = 0;
  2530. te[ 12 ] = 0;
  2531. te[ 13 ] = 0;
  2532. te[ 14 ] = 0;
  2533. te[ 15 ] = 1;
  2534. return this;
  2535. },
  2536. makeRotationFromEuler: function ( euler ) {
  2537. if ( ! ( euler && euler.isEuler ) ) {
  2538. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2539. }
  2540. const te = this.elements;
  2541. const x = euler.x, y = euler.y, z = euler.z;
  2542. const a = Math.cos( x ), b = Math.sin( x );
  2543. const c = Math.cos( y ), d = Math.sin( y );
  2544. const e = Math.cos( z ), f = Math.sin( z );
  2545. if ( euler.order === 'XYZ' ) {
  2546. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  2547. te[ 0 ] = c * e;
  2548. te[ 4 ] = - c * f;
  2549. te[ 8 ] = d;
  2550. te[ 1 ] = af + be * d;
  2551. te[ 5 ] = ae - bf * d;
  2552. te[ 9 ] = - b * c;
  2553. te[ 2 ] = bf - ae * d;
  2554. te[ 6 ] = be + af * d;
  2555. te[ 10 ] = a * c;
  2556. } else if ( euler.order === 'YXZ' ) {
  2557. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  2558. te[ 0 ] = ce + df * b;
  2559. te[ 4 ] = de * b - cf;
  2560. te[ 8 ] = a * d;
  2561. te[ 1 ] = a * f;
  2562. te[ 5 ] = a * e;
  2563. te[ 9 ] = - b;
  2564. te[ 2 ] = cf * b - de;
  2565. te[ 6 ] = df + ce * b;
  2566. te[ 10 ] = a * c;
  2567. } else if ( euler.order === 'ZXY' ) {
  2568. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  2569. te[ 0 ] = ce - df * b;
  2570. te[ 4 ] = - a * f;
  2571. te[ 8 ] = de + cf * b;
  2572. te[ 1 ] = cf + de * b;
  2573. te[ 5 ] = a * e;
  2574. te[ 9 ] = df - ce * b;
  2575. te[ 2 ] = - a * d;
  2576. te[ 6 ] = b;
  2577. te[ 10 ] = a * c;
  2578. } else if ( euler.order === 'ZYX' ) {
  2579. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  2580. te[ 0 ] = c * e;
  2581. te[ 4 ] = be * d - af;
  2582. te[ 8 ] = ae * d + bf;
  2583. te[ 1 ] = c * f;
  2584. te[ 5 ] = bf * d + ae;
  2585. te[ 9 ] = af * d - be;
  2586. te[ 2 ] = - d;
  2587. te[ 6 ] = b * c;
  2588. te[ 10 ] = a * c;
  2589. } else if ( euler.order === 'YZX' ) {
  2590. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2591. te[ 0 ] = c * e;
  2592. te[ 4 ] = bd - ac * f;
  2593. te[ 8 ] = bc * f + ad;
  2594. te[ 1 ] = f;
  2595. te[ 5 ] = a * e;
  2596. te[ 9 ] = - b * e;
  2597. te[ 2 ] = - d * e;
  2598. te[ 6 ] = ad * f + bc;
  2599. te[ 10 ] = ac - bd * f;
  2600. } else if ( euler.order === 'XZY' ) {
  2601. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2602. te[ 0 ] = c * e;
  2603. te[ 4 ] = - f;
  2604. te[ 8 ] = d * e;
  2605. te[ 1 ] = ac * f + bd;
  2606. te[ 5 ] = a * e;
  2607. te[ 9 ] = ad * f - bc;
  2608. te[ 2 ] = bc * f - ad;
  2609. te[ 6 ] = b * e;
  2610. te[ 10 ] = bd * f + ac;
  2611. }
  2612. // bottom row
  2613. te[ 3 ] = 0;
  2614. te[ 7 ] = 0;
  2615. te[ 11 ] = 0;
  2616. // last column
  2617. te[ 12 ] = 0;
  2618. te[ 13 ] = 0;
  2619. te[ 14 ] = 0;
  2620. te[ 15 ] = 1;
  2621. return this;
  2622. },
  2623. makeRotationFromQuaternion: function ( q ) {
  2624. return this.compose( _zero, q, _one );
  2625. },
  2626. lookAt: function ( eye, target, up ) {
  2627. const te = this.elements;
  2628. _z.subVectors( eye, target );
  2629. if ( _z.lengthSq() === 0 ) {
  2630. // eye and target are in the same position
  2631. _z.z = 1;
  2632. }
  2633. _z.normalize();
  2634. _x.crossVectors( up, _z );
  2635. if ( _x.lengthSq() === 0 ) {
  2636. // up and z are parallel
  2637. if ( Math.abs( up.z ) === 1 ) {
  2638. _z.x += 0.0001;
  2639. } else {
  2640. _z.z += 0.0001;
  2641. }
  2642. _z.normalize();
  2643. _x.crossVectors( up, _z );
  2644. }
  2645. _x.normalize();
  2646. _y.crossVectors( _z, _x );
  2647. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  2648. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  2649. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  2650. return this;
  2651. },
  2652. multiply: function ( m, n ) {
  2653. if ( n !== undefined ) {
  2654. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2655. return this.multiplyMatrices( m, n );
  2656. }
  2657. return this.multiplyMatrices( this, m );
  2658. },
  2659. premultiply: function ( m ) {
  2660. return this.multiplyMatrices( m, this );
  2661. },
  2662. multiplyMatrices: function ( a, b ) {
  2663. const ae = a.elements;
  2664. const be = b.elements;
  2665. const te = this.elements;
  2666. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2667. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2668. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2669. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2670. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2671. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2672. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2673. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2674. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2675. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2676. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2677. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2678. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2679. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2680. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2681. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2682. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2683. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2684. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2685. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2686. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2687. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2688. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2689. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2690. return this;
  2691. },
  2692. multiplyScalar: function ( s ) {
  2693. const te = this.elements;
  2694. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2695. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2696. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2697. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2698. return this;
  2699. },
  2700. determinant: function () {
  2701. const te = this.elements;
  2702. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2703. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2704. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2705. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2706. //TODO: make this more efficient
  2707. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2708. return (
  2709. n41 * (
  2710. + n14 * n23 * n32
  2711. - n13 * n24 * n32
  2712. - n14 * n22 * n33
  2713. + n12 * n24 * n33
  2714. + n13 * n22 * n34
  2715. - n12 * n23 * n34
  2716. ) +
  2717. n42 * (
  2718. + n11 * n23 * n34
  2719. - n11 * n24 * n33
  2720. + n14 * n21 * n33
  2721. - n13 * n21 * n34
  2722. + n13 * n24 * n31
  2723. - n14 * n23 * n31
  2724. ) +
  2725. n43 * (
  2726. + n11 * n24 * n32
  2727. - n11 * n22 * n34
  2728. - n14 * n21 * n32
  2729. + n12 * n21 * n34
  2730. + n14 * n22 * n31
  2731. - n12 * n24 * n31
  2732. ) +
  2733. n44 * (
  2734. - n13 * n22 * n31
  2735. - n11 * n23 * n32
  2736. + n11 * n22 * n33
  2737. + n13 * n21 * n32
  2738. - n12 * n21 * n33
  2739. + n12 * n23 * n31
  2740. )
  2741. );
  2742. },
  2743. transpose: function () {
  2744. const te = this.elements;
  2745. let tmp;
  2746. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2747. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2748. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2749. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2750. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2751. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2752. return this;
  2753. },
  2754. setPosition: function ( x, y, z ) {
  2755. const te = this.elements;
  2756. if ( x.isVector3 ) {
  2757. te[ 12 ] = x.x;
  2758. te[ 13 ] = x.y;
  2759. te[ 14 ] = x.z;
  2760. } else {
  2761. te[ 12 ] = x;
  2762. te[ 13 ] = y;
  2763. te[ 14 ] = z;
  2764. }
  2765. return this;
  2766. },
  2767. getInverse: function ( m, throwOnDegenerate ) {
  2768. if ( throwOnDegenerate !== undefined ) {
  2769. console.warn( "THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate." );
  2770. }
  2771. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2772. const te = this.elements,
  2773. me = m.elements,
  2774. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2775. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2776. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2777. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2778. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2779. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2780. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2781. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2782. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2783. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  2784. const detInv = 1 / det;
  2785. te[ 0 ] = t11 * detInv;
  2786. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2787. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2788. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2789. te[ 4 ] = t12 * detInv;
  2790. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2791. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2792. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2793. te[ 8 ] = t13 * detInv;
  2794. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2795. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2796. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2797. te[ 12 ] = t14 * detInv;
  2798. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2799. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2800. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2801. return this;
  2802. },
  2803. scale: function ( v ) {
  2804. const te = this.elements;
  2805. const x = v.x, y = v.y, z = v.z;
  2806. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2807. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2808. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2809. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2810. return this;
  2811. },
  2812. getMaxScaleOnAxis: function () {
  2813. const te = this.elements;
  2814. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2815. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2816. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2817. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2818. },
  2819. makeTranslation: function ( x, y, z ) {
  2820. this.set(
  2821. 1, 0, 0, x,
  2822. 0, 1, 0, y,
  2823. 0, 0, 1, z,
  2824. 0, 0, 0, 1
  2825. );
  2826. return this;
  2827. },
  2828. makeRotationX: function ( theta ) {
  2829. const c = Math.cos( theta ), s = Math.sin( theta );
  2830. this.set(
  2831. 1, 0, 0, 0,
  2832. 0, c, - s, 0,
  2833. 0, s, c, 0,
  2834. 0, 0, 0, 1
  2835. );
  2836. return this;
  2837. },
  2838. makeRotationY: function ( theta ) {
  2839. const c = Math.cos( theta ), s = Math.sin( theta );
  2840. this.set(
  2841. c, 0, s, 0,
  2842. 0, 1, 0, 0,
  2843. - s, 0, c, 0,
  2844. 0, 0, 0, 1
  2845. );
  2846. return this;
  2847. },
  2848. makeRotationZ: function ( theta ) {
  2849. const c = Math.cos( theta ), s = Math.sin( theta );
  2850. this.set(
  2851. c, - s, 0, 0,
  2852. s, c, 0, 0,
  2853. 0, 0, 1, 0,
  2854. 0, 0, 0, 1
  2855. );
  2856. return this;
  2857. },
  2858. makeRotationAxis: function ( axis, angle ) {
  2859. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2860. const c = Math.cos( angle );
  2861. const s = Math.sin( angle );
  2862. const t = 1 - c;
  2863. const x = axis.x, y = axis.y, z = axis.z;
  2864. const tx = t * x, ty = t * y;
  2865. this.set(
  2866. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2867. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2868. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2869. 0, 0, 0, 1
  2870. );
  2871. return this;
  2872. },
  2873. makeScale: function ( x, y, z ) {
  2874. this.set(
  2875. x, 0, 0, 0,
  2876. 0, y, 0, 0,
  2877. 0, 0, z, 0,
  2878. 0, 0, 0, 1
  2879. );
  2880. return this;
  2881. },
  2882. makeShear: function ( x, y, z ) {
  2883. this.set(
  2884. 1, y, z, 0,
  2885. x, 1, z, 0,
  2886. x, y, 1, 0,
  2887. 0, 0, 0, 1
  2888. );
  2889. return this;
  2890. },
  2891. compose: function ( position, quaternion, scale ) {
  2892. const te = this.elements;
  2893. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2894. const x2 = x + x, y2 = y + y, z2 = z + z;
  2895. const xx = x * x2, xy = x * y2, xz = x * z2;
  2896. const yy = y * y2, yz = y * z2, zz = z * z2;
  2897. const wx = w * x2, wy = w * y2, wz = w * z2;
  2898. const sx = scale.x, sy = scale.y, sz = scale.z;
  2899. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2900. te[ 1 ] = ( xy + wz ) * sx;
  2901. te[ 2 ] = ( xz - wy ) * sx;
  2902. te[ 3 ] = 0;
  2903. te[ 4 ] = ( xy - wz ) * sy;
  2904. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2905. te[ 6 ] = ( yz + wx ) * sy;
  2906. te[ 7 ] = 0;
  2907. te[ 8 ] = ( xz + wy ) * sz;
  2908. te[ 9 ] = ( yz - wx ) * sz;
  2909. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2910. te[ 11 ] = 0;
  2911. te[ 12 ] = position.x;
  2912. te[ 13 ] = position.y;
  2913. te[ 14 ] = position.z;
  2914. te[ 15 ] = 1;
  2915. return this;
  2916. },
  2917. decompose: function ( position, quaternion, scale ) {
  2918. const te = this.elements;
  2919. let sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2920. let sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2921. let sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2922. // if determine is negative, we need to invert one scale
  2923. const det = this.determinant();
  2924. if ( det < 0 ) sx = - sx;
  2925. position.x = te[ 12 ];
  2926. position.y = te[ 13 ];
  2927. position.z = te[ 14 ];
  2928. // scale the rotation part
  2929. _m1.copy( this );
  2930. const invSX = 1 / sx;
  2931. const invSY = 1 / sy;
  2932. const invSZ = 1 / sz;
  2933. _m1.elements[ 0 ] *= invSX;
  2934. _m1.elements[ 1 ] *= invSX;
  2935. _m1.elements[ 2 ] *= invSX;
  2936. _m1.elements[ 4 ] *= invSY;
  2937. _m1.elements[ 5 ] *= invSY;
  2938. _m1.elements[ 6 ] *= invSY;
  2939. _m1.elements[ 8 ] *= invSZ;
  2940. _m1.elements[ 9 ] *= invSZ;
  2941. _m1.elements[ 10 ] *= invSZ;
  2942. quaternion.setFromRotationMatrix( _m1 );
  2943. scale.x = sx;
  2944. scale.y = sy;
  2945. scale.z = sz;
  2946. return this;
  2947. },
  2948. makePerspective: function ( left, right, top, bottom, near, far ) {
  2949. if ( far === undefined ) {
  2950. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2951. }
  2952. const te = this.elements;
  2953. const x = 2 * near / ( right - left );
  2954. const y = 2 * near / ( top - bottom );
  2955. const a = ( right + left ) / ( right - left );
  2956. const b = ( top + bottom ) / ( top - bottom );
  2957. const c = - ( far + near ) / ( far - near );
  2958. const d = - 2 * far * near / ( far - near );
  2959. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2960. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2961. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2962. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2963. return this;
  2964. },
  2965. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2966. const te = this.elements;
  2967. const w = 1.0 / ( right - left );
  2968. const h = 1.0 / ( top - bottom );
  2969. const p = 1.0 / ( far - near );
  2970. const x = ( right + left ) * w;
  2971. const y = ( top + bottom ) * h;
  2972. const z = ( far + near ) * p;
  2973. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2974. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2975. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2976. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2977. return this;
  2978. },
  2979. equals: function ( matrix ) {
  2980. const te = this.elements;
  2981. const me = matrix.elements;
  2982. for ( let i = 0; i < 16; i ++ ) {
  2983. if ( te[ i ] !== me[ i ] ) return false;
  2984. }
  2985. return true;
  2986. },
  2987. fromArray: function ( array, offset ) {
  2988. if ( offset === undefined ) offset = 0;
  2989. for ( let i = 0; i < 16; i ++ ) {
  2990. this.elements[ i ] = array[ i + offset ];
  2991. }
  2992. return this;
  2993. },
  2994. toArray: function ( array, offset ) {
  2995. if ( array === undefined ) array = [];
  2996. if ( offset === undefined ) offset = 0;
  2997. const te = this.elements;
  2998. array[ offset ] = te[ 0 ];
  2999. array[ offset + 1 ] = te[ 1 ];
  3000. array[ offset + 2 ] = te[ 2 ];
  3001. array[ offset + 3 ] = te[ 3 ];
  3002. array[ offset + 4 ] = te[ 4 ];
  3003. array[ offset + 5 ] = te[ 5 ];
  3004. array[ offset + 6 ] = te[ 6 ];
  3005. array[ offset + 7 ] = te[ 7 ];
  3006. array[ offset + 8 ] = te[ 8 ];
  3007. array[ offset + 9 ] = te[ 9 ];
  3008. array[ offset + 10 ] = te[ 10 ];
  3009. array[ offset + 11 ] = te[ 11 ];
  3010. array[ offset + 12 ] = te[ 12 ];
  3011. array[ offset + 13 ] = te[ 13 ];
  3012. array[ offset + 14 ] = te[ 14 ];
  3013. array[ offset + 15 ] = te[ 15 ];
  3014. return array;
  3015. }
  3016. } );
  3017. /**
  3018. * @author mrdoob / http://mrdoob.com/
  3019. * @author WestLangley / http://github.com/WestLangley
  3020. * @author bhouston / http://clara.io
  3021. */
  3022. const _matrix = new Matrix4();
  3023. const _quaternion$1 = new Quaternion();
  3024. function Euler( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
  3025. this._x = x;
  3026. this._y = y;
  3027. this._z = z;
  3028. this._order = order;
  3029. }
  3030. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3031. Euler.DefaultOrder = 'XYZ';
  3032. Object.defineProperties( Euler.prototype, {
  3033. x: {
  3034. get: function () {
  3035. return this._x;
  3036. },
  3037. set: function ( value ) {
  3038. this._x = value;
  3039. this._onChangeCallback();
  3040. }
  3041. },
  3042. y: {
  3043. get: function () {
  3044. return this._y;
  3045. },
  3046. set: function ( value ) {
  3047. this._y = value;
  3048. this._onChangeCallback();
  3049. }
  3050. },
  3051. z: {
  3052. get: function () {
  3053. return this._z;
  3054. },
  3055. set: function ( value ) {
  3056. this._z = value;
  3057. this._onChangeCallback();
  3058. }
  3059. },
  3060. order: {
  3061. get: function () {
  3062. return this._order;
  3063. },
  3064. set: function ( value ) {
  3065. this._order = value;
  3066. this._onChangeCallback();
  3067. }
  3068. }
  3069. } );
  3070. Object.assign( Euler.prototype, {
  3071. isEuler: true,
  3072. set: function ( x, y, z, order ) {
  3073. this._x = x;
  3074. this._y = y;
  3075. this._z = z;
  3076. this._order = order || this._order;
  3077. this._onChangeCallback();
  3078. return this;
  3079. },
  3080. clone: function () {
  3081. return new this.constructor( this._x, this._y, this._z, this._order );
  3082. },
  3083. copy: function ( euler ) {
  3084. this._x = euler._x;
  3085. this._y = euler._y;
  3086. this._z = euler._z;
  3087. this._order = euler._order;
  3088. this._onChangeCallback();
  3089. return this;
  3090. },
  3091. setFromRotationMatrix: function ( m, order, update ) {
  3092. const clamp = MathUtils.clamp;
  3093. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3094. const te = m.elements;
  3095. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3096. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3097. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3098. order = order || this._order;
  3099. switch ( order ) {
  3100. case 'XYZ':
  3101. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3102. if ( Math.abs( m13 ) < 0.9999999 ) {
  3103. this._x = Math.atan2( - m23, m33 );
  3104. this._z = Math.atan2( - m12, m11 );
  3105. } else {
  3106. this._x = Math.atan2( m32, m22 );
  3107. this._z = 0;
  3108. }
  3109. break;
  3110. case 'YXZ':
  3111. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3112. if ( Math.abs( m23 ) < 0.9999999 ) {
  3113. this._y = Math.atan2( m13, m33 );
  3114. this._z = Math.atan2( m21, m22 );
  3115. } else {
  3116. this._y = Math.atan2( - m31, m11 );
  3117. this._z = 0;
  3118. }
  3119. break;
  3120. case 'ZXY':
  3121. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3122. if ( Math.abs( m32 ) < 0.9999999 ) {
  3123. this._y = Math.atan2( - m31, m33 );
  3124. this._z = Math.atan2( - m12, m22 );
  3125. } else {
  3126. this._y = 0;
  3127. this._z = Math.atan2( m21, m11 );
  3128. }
  3129. break;
  3130. case 'ZYX':
  3131. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3132. if ( Math.abs( m31 ) < 0.9999999 ) {
  3133. this._x = Math.atan2( m32, m33 );
  3134. this._z = Math.atan2( m21, m11 );
  3135. } else {
  3136. this._x = 0;
  3137. this._z = Math.atan2( - m12, m22 );
  3138. }
  3139. break;
  3140. case 'YZX':
  3141. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3142. if ( Math.abs( m21 ) < 0.9999999 ) {
  3143. this._x = Math.atan2( - m23, m22 );
  3144. this._y = Math.atan2( - m31, m11 );
  3145. } else {
  3146. this._x = 0;
  3147. this._y = Math.atan2( m13, m33 );
  3148. }
  3149. break;
  3150. case 'XZY':
  3151. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3152. if ( Math.abs( m12 ) < 0.9999999 ) {
  3153. this._x = Math.atan2( m32, m22 );
  3154. this._y = Math.atan2( m13, m11 );
  3155. } else {
  3156. this._x = Math.atan2( - m23, m33 );
  3157. this._y = 0;
  3158. }
  3159. break;
  3160. default:
  3161. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3162. }
  3163. this._order = order;
  3164. if ( update !== false ) this._onChangeCallback();
  3165. return this;
  3166. },
  3167. setFromQuaternion: function ( q, order, update ) {
  3168. _matrix.makeRotationFromQuaternion( q );
  3169. return this.setFromRotationMatrix( _matrix, order, update );
  3170. },
  3171. setFromVector3: function ( v, order ) {
  3172. return this.set( v.x, v.y, v.z, order || this._order );
  3173. },
  3174. reorder: function ( newOrder ) {
  3175. // WARNING: this discards revolution information -bhouston
  3176. _quaternion$1.setFromEuler( this );
  3177. return this.setFromQuaternion( _quaternion$1, newOrder );
  3178. },
  3179. equals: function ( euler ) {
  3180. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3181. },
  3182. fromArray: function ( array ) {
  3183. this._x = array[ 0 ];
  3184. this._y = array[ 1 ];
  3185. this._z = array[ 2 ];
  3186. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3187. this._onChangeCallback();
  3188. return this;
  3189. },
  3190. toArray: function ( array, offset ) {
  3191. if ( array === undefined ) array = [];
  3192. if ( offset === undefined ) offset = 0;
  3193. array[ offset ] = this._x;
  3194. array[ offset + 1 ] = this._y;
  3195. array[ offset + 2 ] = this._z;
  3196. array[ offset + 3 ] = this._order;
  3197. return array;
  3198. },
  3199. toVector3: function ( optionalResult ) {
  3200. if ( optionalResult ) {
  3201. return optionalResult.set( this._x, this._y, this._z );
  3202. } else {
  3203. return new Vector3( this._x, this._y, this._z );
  3204. }
  3205. },
  3206. _onChange: function ( callback ) {
  3207. this._onChangeCallback = callback;
  3208. return this;
  3209. },
  3210. _onChangeCallback: function () {}
  3211. } );
  3212. /**
  3213. * @author mrdoob / http://mrdoob.com/
  3214. */
  3215. function Layers() {
  3216. this.mask = 1 | 0;
  3217. }
  3218. Object.assign( Layers.prototype, {
  3219. set: function ( channel ) {
  3220. this.mask = 1 << channel | 0;
  3221. },
  3222. enable: function ( channel ) {
  3223. this.mask |= 1 << channel | 0;
  3224. },
  3225. enableAll: function () {
  3226. this.mask = 0xffffffff | 0;
  3227. },
  3228. toggle: function ( channel ) {
  3229. this.mask ^= 1 << channel | 0;
  3230. },
  3231. disable: function ( channel ) {
  3232. this.mask &= ~ ( 1 << channel | 0 );
  3233. },
  3234. disableAll: function () {
  3235. this.mask = 0;
  3236. },
  3237. test: function ( layers ) {
  3238. return ( this.mask & layers.mask ) !== 0;
  3239. }
  3240. } );
  3241. let _object3DId = 0;
  3242. const _v1$1 = new Vector3();
  3243. const _q1 = new Quaternion();
  3244. const _m1$1 = new Matrix4();
  3245. const _target = new Vector3();
  3246. const _position = new Vector3();
  3247. const _scale = new Vector3();
  3248. const _quaternion$2 = new Quaternion();
  3249. const _xAxis = new Vector3( 1, 0, 0 );
  3250. const _yAxis = new Vector3( 0, 1, 0 );
  3251. const _zAxis = new Vector3( 0, 0, 1 );
  3252. const _addedEvent = { type: 'added' };
  3253. const _removedEvent = { type: 'removed' };
  3254. /**
  3255. * @author mrdoob / http://mrdoob.com/
  3256. * @author mikael emtinger / http://gomo.se/
  3257. * @author alteredq / http://alteredqualia.com/
  3258. * @author WestLangley / http://github.com/WestLangley
  3259. * @author elephantatwork / www.elephantatwork.ch
  3260. */
  3261. function Object3D() {
  3262. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3263. this.uuid = MathUtils.generateUUID();
  3264. this.name = '';
  3265. this.type = 'Object3D';
  3266. this.parent = null;
  3267. this.children = [];
  3268. this.up = Object3D.DefaultUp.clone();
  3269. const position = new Vector3();
  3270. const rotation = new Euler();
  3271. const quaternion = new Quaternion();
  3272. const scale = new Vector3( 1, 1, 1 );
  3273. function onRotationChange() {
  3274. quaternion.setFromEuler( rotation, false );
  3275. }
  3276. function onQuaternionChange() {
  3277. rotation.setFromQuaternion( quaternion, undefined, false );
  3278. }
  3279. rotation._onChange( onRotationChange );
  3280. quaternion._onChange( onQuaternionChange );
  3281. Object.defineProperties( this, {
  3282. position: {
  3283. configurable: true,
  3284. enumerable: true,
  3285. value: position
  3286. },
  3287. rotation: {
  3288. configurable: true,
  3289. enumerable: true,
  3290. value: rotation
  3291. },
  3292. quaternion: {
  3293. configurable: true,
  3294. enumerable: true,
  3295. value: quaternion
  3296. },
  3297. scale: {
  3298. configurable: true,
  3299. enumerable: true,
  3300. value: scale
  3301. },
  3302. modelViewMatrix: {
  3303. value: new Matrix4()
  3304. },
  3305. normalMatrix: {
  3306. value: new Matrix3()
  3307. }
  3308. } );
  3309. this.matrix = new Matrix4();
  3310. this.matrixWorld = new Matrix4();
  3311. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3312. this.matrixWorldNeedsUpdate = false;
  3313. this.layers = new Layers();
  3314. this.visible = true;
  3315. this.castShadow = false;
  3316. this.receiveShadow = false;
  3317. this.frustumCulled = true;
  3318. this.renderOrder = 0;
  3319. this.userData = {};
  3320. }
  3321. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3322. Object3D.DefaultMatrixAutoUpdate = true;
  3323. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3324. constructor: Object3D,
  3325. isObject3D: true,
  3326. onBeforeRender: function () {},
  3327. onAfterRender: function () {},
  3328. applyMatrix4: function ( matrix ) {
  3329. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3330. this.matrix.premultiply( matrix );
  3331. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3332. },
  3333. applyQuaternion: function ( q ) {
  3334. this.quaternion.premultiply( q );
  3335. return this;
  3336. },
  3337. setRotationFromAxisAngle: function ( axis, angle ) {
  3338. // assumes axis is normalized
  3339. this.quaternion.setFromAxisAngle( axis, angle );
  3340. },
  3341. setRotationFromEuler: function ( euler ) {
  3342. this.quaternion.setFromEuler( euler, true );
  3343. },
  3344. setRotationFromMatrix: function ( m ) {
  3345. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3346. this.quaternion.setFromRotationMatrix( m );
  3347. },
  3348. setRotationFromQuaternion: function ( q ) {
  3349. // assumes q is normalized
  3350. this.quaternion.copy( q );
  3351. },
  3352. rotateOnAxis: function ( axis, angle ) {
  3353. // rotate object on axis in object space
  3354. // axis is assumed to be normalized
  3355. _q1.setFromAxisAngle( axis, angle );
  3356. this.quaternion.multiply( _q1 );
  3357. return this;
  3358. },
  3359. rotateOnWorldAxis: function ( axis, angle ) {
  3360. // rotate object on axis in world space
  3361. // axis is assumed to be normalized
  3362. // method assumes no rotated parent
  3363. _q1.setFromAxisAngle( axis, angle );
  3364. this.quaternion.premultiply( _q1 );
  3365. return this;
  3366. },
  3367. rotateX: function ( angle ) {
  3368. return this.rotateOnAxis( _xAxis, angle );
  3369. },
  3370. rotateY: function ( angle ) {
  3371. return this.rotateOnAxis( _yAxis, angle );
  3372. },
  3373. rotateZ: function ( angle ) {
  3374. return this.rotateOnAxis( _zAxis, angle );
  3375. },
  3376. translateOnAxis: function ( axis, distance ) {
  3377. // translate object by distance along axis in object space
  3378. // axis is assumed to be normalized
  3379. _v1$1.copy( axis ).applyQuaternion( this.quaternion );
  3380. this.position.add( _v1$1.multiplyScalar( distance ) );
  3381. return this;
  3382. },
  3383. translateX: function ( distance ) {
  3384. return this.translateOnAxis( _xAxis, distance );
  3385. },
  3386. translateY: function ( distance ) {
  3387. return this.translateOnAxis( _yAxis, distance );
  3388. },
  3389. translateZ: function ( distance ) {
  3390. return this.translateOnAxis( _zAxis, distance );
  3391. },
  3392. localToWorld: function ( vector ) {
  3393. return vector.applyMatrix4( this.matrixWorld );
  3394. },
  3395. worldToLocal: function ( vector ) {
  3396. return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) );
  3397. },
  3398. lookAt: function ( x, y, z ) {
  3399. // This method does not support objects having non-uniformly-scaled parent(s)
  3400. if ( x.isVector3 ) {
  3401. _target.copy( x );
  3402. } else {
  3403. _target.set( x, y, z );
  3404. }
  3405. const parent = this.parent;
  3406. this.updateWorldMatrix( true, false );
  3407. _position.setFromMatrixPosition( this.matrixWorld );
  3408. if ( this.isCamera || this.isLight ) {
  3409. _m1$1.lookAt( _position, _target, this.up );
  3410. } else {
  3411. _m1$1.lookAt( _target, _position, this.up );
  3412. }
  3413. this.quaternion.setFromRotationMatrix( _m1$1 );
  3414. if ( parent ) {
  3415. _m1$1.extractRotation( parent.matrixWorld );
  3416. _q1.setFromRotationMatrix( _m1$1 );
  3417. this.quaternion.premultiply( _q1.inverse() );
  3418. }
  3419. },
  3420. add: function ( object ) {
  3421. if ( arguments.length > 1 ) {
  3422. for ( let i = 0; i < arguments.length; i ++ ) {
  3423. this.add( arguments[ i ] );
  3424. }
  3425. return this;
  3426. }
  3427. if ( object === this ) {
  3428. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3429. return this;
  3430. }
  3431. if ( ( object && object.isObject3D ) ) {
  3432. if ( object.parent !== null ) {
  3433. object.parent.remove( object );
  3434. }
  3435. object.parent = this;
  3436. this.children.push( object );
  3437. object.dispatchEvent( _addedEvent );
  3438. } else {
  3439. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3440. }
  3441. return this;
  3442. },
  3443. remove: function ( object ) {
  3444. if ( arguments.length > 1 ) {
  3445. for ( let i = 0; i < arguments.length; i ++ ) {
  3446. this.remove( arguments[ i ] );
  3447. }
  3448. return this;
  3449. }
  3450. const index = this.children.indexOf( object );
  3451. if ( index !== - 1 ) {
  3452. object.parent = null;
  3453. this.children.splice( index, 1 );
  3454. object.dispatchEvent( _removedEvent );
  3455. }
  3456. return this;
  3457. },
  3458. attach: function ( object ) {
  3459. // adds object as a child of this, while maintaining the object's world transform
  3460. this.updateWorldMatrix( true, false );
  3461. _m1$1.getInverse( this.matrixWorld );
  3462. if ( object.parent !== null ) {
  3463. object.parent.updateWorldMatrix( true, false );
  3464. _m1$1.multiply( object.parent.matrixWorld );
  3465. }
  3466. object.applyMatrix4( _m1$1 );
  3467. object.updateWorldMatrix( false, false );
  3468. this.add( object );
  3469. return this;
  3470. },
  3471. getObjectById: function ( id ) {
  3472. return this.getObjectByProperty( 'id', id );
  3473. },
  3474. getObjectByName: function ( name ) {
  3475. return this.getObjectByProperty( 'name', name );
  3476. },
  3477. getObjectByProperty: function ( name, value ) {
  3478. if ( this[ name ] === value ) return this;
  3479. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  3480. const child = this.children[ i ];
  3481. const object = child.getObjectByProperty( name, value );
  3482. if ( object !== undefined ) {
  3483. return object;
  3484. }
  3485. }
  3486. return undefined;
  3487. },
  3488. getWorldPosition: function ( target ) {
  3489. if ( target === undefined ) {
  3490. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3491. target = new Vector3();
  3492. }
  3493. this.updateMatrixWorld( true );
  3494. return target.setFromMatrixPosition( this.matrixWorld );
  3495. },
  3496. getWorldQuaternion: function ( target ) {
  3497. if ( target === undefined ) {
  3498. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3499. target = new Quaternion();
  3500. }
  3501. this.updateMatrixWorld( true );
  3502. this.matrixWorld.decompose( _position, target, _scale );
  3503. return target;
  3504. },
  3505. getWorldScale: function ( target ) {
  3506. if ( target === undefined ) {
  3507. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3508. target = new Vector3();
  3509. }
  3510. this.updateMatrixWorld( true );
  3511. this.matrixWorld.decompose( _position, _quaternion$2, target );
  3512. return target;
  3513. },
  3514. getWorldDirection: function ( target ) {
  3515. if ( target === undefined ) {
  3516. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3517. target = new Vector3();
  3518. }
  3519. this.updateMatrixWorld( true );
  3520. const e = this.matrixWorld.elements;
  3521. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3522. },
  3523. raycast: function () {},
  3524. traverse: function ( callback ) {
  3525. callback( this );
  3526. const children = this.children;
  3527. for ( let i = 0, l = children.length; i < l; i ++ ) {
  3528. children[ i ].traverse( callback );
  3529. }
  3530. },
  3531. traverseVisible: function ( callback ) {
  3532. if ( this.visible === false ) return;
  3533. callback( this );
  3534. const children = this.children;
  3535. for ( let i = 0, l = children.length; i < l; i ++ ) {
  3536. children[ i ].traverseVisible( callback );
  3537. }
  3538. },
  3539. traverseAncestors: function ( callback ) {
  3540. const parent = this.parent;
  3541. if ( parent !== null ) {
  3542. callback( parent );
  3543. parent.traverseAncestors( callback );
  3544. }
  3545. },
  3546. updateMatrix: function () {
  3547. this.matrix.compose( this.position, this.quaternion, this.scale );
  3548. this.matrixWorldNeedsUpdate = true;
  3549. },
  3550. updateMatrixWorld: function ( force ) {
  3551. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3552. if ( this.matrixWorldNeedsUpdate || force ) {
  3553. if ( this.parent === null ) {
  3554. this.matrixWorld.copy( this.matrix );
  3555. } else {
  3556. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3557. }
  3558. this.matrixWorldNeedsUpdate = false;
  3559. force = true;
  3560. }
  3561. // update children
  3562. const children = this.children;
  3563. for ( let i = 0, l = children.length; i < l; i ++ ) {
  3564. children[ i ].updateMatrixWorld( force );
  3565. }
  3566. },
  3567. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3568. const parent = this.parent;
  3569. if ( updateParents === true && parent !== null ) {
  3570. parent.updateWorldMatrix( true, false );
  3571. }
  3572. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3573. if ( this.parent === null ) {
  3574. this.matrixWorld.copy( this.matrix );
  3575. } else {
  3576. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3577. }
  3578. // update children
  3579. if ( updateChildren === true ) {
  3580. const children = this.children;
  3581. for ( let i = 0, l = children.length; i < l; i ++ ) {
  3582. children[ i ].updateWorldMatrix( false, true );
  3583. }
  3584. }
  3585. },
  3586. toJSON: function ( meta ) {
  3587. // meta is a string when called from JSON.stringify
  3588. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  3589. const output = {};
  3590. // meta is a hash used to collect geometries, materials.
  3591. // not providing it implies that this is the root object
  3592. // being serialized.
  3593. if ( isRootObject ) {
  3594. // initialize meta obj
  3595. meta = {
  3596. geometries: {},
  3597. materials: {},
  3598. textures: {},
  3599. images: {},
  3600. shapes: {}
  3601. };
  3602. output.metadata = {
  3603. version: 4.5,
  3604. type: 'Object',
  3605. generator: 'Object3D.toJSON'
  3606. };
  3607. }
  3608. // standard Object3D serialization
  3609. const object = {};
  3610. object.uuid = this.uuid;
  3611. object.type = this.type;
  3612. if ( this.name !== '' ) object.name = this.name;
  3613. if ( this.castShadow === true ) object.castShadow = true;
  3614. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3615. if ( this.visible === false ) object.visible = false;
  3616. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3617. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3618. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3619. object.layers = this.layers.mask;
  3620. object.matrix = this.matrix.toArray();
  3621. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3622. // object specific properties
  3623. if ( this.isInstancedMesh ) {
  3624. object.type = 'InstancedMesh';
  3625. object.count = this.count;
  3626. object.instanceMatrix = this.instanceMatrix.toJSON();
  3627. }
  3628. //
  3629. function serialize( library, element ) {
  3630. if ( library[ element.uuid ] === undefined ) {
  3631. library[ element.uuid ] = element.toJSON( meta );
  3632. }
  3633. return element.uuid;
  3634. }
  3635. if ( this.isMesh || this.isLine || this.isPoints ) {
  3636. object.geometry = serialize( meta.geometries, this.geometry );
  3637. const parameters = this.geometry.parameters;
  3638. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3639. const shapes = parameters.shapes;
  3640. if ( Array.isArray( shapes ) ) {
  3641. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  3642. const shape = shapes[ i ];
  3643. serialize( meta.shapes, shape );
  3644. }
  3645. } else {
  3646. serialize( meta.shapes, shapes );
  3647. }
  3648. }
  3649. }
  3650. if ( this.material !== undefined ) {
  3651. if ( Array.isArray( this.material ) ) {
  3652. const uuids = [];
  3653. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  3654. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3655. }
  3656. object.material = uuids;
  3657. } else {
  3658. object.material = serialize( meta.materials, this.material );
  3659. }
  3660. }
  3661. //
  3662. if ( this.children.length > 0 ) {
  3663. object.children = [];
  3664. for ( let i = 0; i < this.children.length; i ++ ) {
  3665. object.children.push( this.children[ i ].toJSON( meta ).object );
  3666. }
  3667. }
  3668. if ( isRootObject ) {
  3669. const geometries = extractFromCache( meta.geometries );
  3670. const materials = extractFromCache( meta.materials );
  3671. const textures = extractFromCache( meta.textures );
  3672. const images = extractFromCache( meta.images );
  3673. const shapes = extractFromCache( meta.shapes );
  3674. if ( geometries.length > 0 ) output.geometries = geometries;
  3675. if ( materials.length > 0 ) output.materials = materials;
  3676. if ( textures.length > 0 ) output.textures = textures;
  3677. if ( images.length > 0 ) output.images = images;
  3678. if ( shapes.length > 0 ) output.shapes = shapes;
  3679. }
  3680. output.object = object;
  3681. return output;
  3682. // extract data from the cache hash
  3683. // remove metadata on each item
  3684. // and return as array
  3685. function extractFromCache( cache ) {
  3686. const values = [];
  3687. for ( const key in cache ) {
  3688. const data = cache[ key ];
  3689. delete data.metadata;
  3690. values.push( data );
  3691. }
  3692. return values;
  3693. }
  3694. },
  3695. clone: function ( recursive ) {
  3696. return new this.constructor().copy( this, recursive );
  3697. },
  3698. copy: function ( source, recursive ) {
  3699. if ( recursive === undefined ) recursive = true;
  3700. this.name = source.name;
  3701. this.up.copy( source.up );
  3702. this.position.copy( source.position );
  3703. this.quaternion.copy( source.quaternion );
  3704. this.scale.copy( source.scale );
  3705. this.matrix.copy( source.matrix );
  3706. this.matrixWorld.copy( source.matrixWorld );
  3707. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3708. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3709. this.layers.mask = source.layers.mask;
  3710. this.visible = source.visible;
  3711. this.castShadow = source.castShadow;
  3712. this.receiveShadow = source.receiveShadow;
  3713. this.frustumCulled = source.frustumCulled;
  3714. this.renderOrder = source.renderOrder;
  3715. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3716. if ( recursive === true ) {
  3717. for ( let i = 0; i < source.children.length; i ++ ) {
  3718. const child = source.children[ i ];
  3719. this.add( child.clone() );
  3720. }
  3721. }
  3722. return this;
  3723. }
  3724. } );
  3725. /**
  3726. * @author mrdoob / http://mrdoob.com/
  3727. */
  3728. function Scene() {
  3729. Object3D.call( this );
  3730. this.type = 'Scene';
  3731. this.background = null;
  3732. this.environment = null;
  3733. this.fog = null;
  3734. this.overrideMaterial = null;
  3735. this.autoUpdate = true; // checked by the renderer
  3736. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3737. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3738. }
  3739. }
  3740. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3741. constructor: Scene,
  3742. isScene: true,
  3743. copy: function ( source, recursive ) {
  3744. Object3D.prototype.copy.call( this, source, recursive );
  3745. if ( source.background !== null ) this.background = source.background.clone();
  3746. if ( source.environment !== null ) this.environment = source.environment.clone();
  3747. if ( source.fog !== null ) this.fog = source.fog.clone();
  3748. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3749. this.autoUpdate = source.autoUpdate;
  3750. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3751. return this;
  3752. },
  3753. toJSON: function ( meta ) {
  3754. const data = Object3D.prototype.toJSON.call( this, meta );
  3755. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3756. if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
  3757. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3758. return data;
  3759. },
  3760. dispose: function () {
  3761. this.dispatchEvent( { type: 'dispose' } );
  3762. }
  3763. } );
  3764. const _points = [
  3765. new Vector3(),
  3766. new Vector3(),
  3767. new Vector3(),
  3768. new Vector3(),
  3769. new Vector3(),
  3770. new Vector3(),
  3771. new Vector3(),
  3772. new Vector3()
  3773. ];
  3774. const _vector$1 = new Vector3();
  3775. const _box = new Box3();
  3776. // triangle centered vertices
  3777. const _v0 = new Vector3();
  3778. const _v1$2 = new Vector3();
  3779. const _v2 = new Vector3();
  3780. // triangle edge vectors
  3781. const _f0 = new Vector3();
  3782. const _f1 = new Vector3();
  3783. const _f2 = new Vector3();
  3784. const _center = new Vector3();
  3785. const _extents = new Vector3();
  3786. const _triangleNormal = new Vector3();
  3787. const _testAxis = new Vector3();
  3788. /**
  3789. * @author bhouston / http://clara.io
  3790. * @author WestLangley / http://github.com/WestLangley
  3791. */
  3792. function Box3( min, max ) {
  3793. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3794. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3795. }
  3796. Object.assign( Box3.prototype, {
  3797. isBox3: true,
  3798. set: function ( min, max ) {
  3799. this.min.copy( min );
  3800. this.max.copy( max );
  3801. return this;
  3802. },
  3803. setFromArray: function ( array ) {
  3804. let minX = + Infinity;
  3805. let minY = + Infinity;
  3806. let minZ = + Infinity;
  3807. let maxX = - Infinity;
  3808. let maxY = - Infinity;
  3809. let maxZ = - Infinity;
  3810. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  3811. const x = array[ i ];
  3812. const y = array[ i + 1 ];
  3813. const z = array[ i + 2 ];
  3814. if ( x < minX ) minX = x;
  3815. if ( y < minY ) minY = y;
  3816. if ( z < minZ ) minZ = z;
  3817. if ( x > maxX ) maxX = x;
  3818. if ( y > maxY ) maxY = y;
  3819. if ( z > maxZ ) maxZ = z;
  3820. }
  3821. this.min.set( minX, minY, minZ );
  3822. this.max.set( maxX, maxY, maxZ );
  3823. return this;
  3824. },
  3825. setFromBufferAttribute: function ( attribute ) {
  3826. let minX = + Infinity;
  3827. let minY = + Infinity;
  3828. let minZ = + Infinity;
  3829. let maxX = - Infinity;
  3830. let maxY = - Infinity;
  3831. let maxZ = - Infinity;
  3832. for ( let i = 0, l = attribute.count; i < l; i ++ ) {
  3833. const x = attribute.getX( i );
  3834. const y = attribute.getY( i );
  3835. const z = attribute.getZ( i );
  3836. if ( x < minX ) minX = x;
  3837. if ( y < minY ) minY = y;
  3838. if ( z < minZ ) minZ = z;
  3839. if ( x > maxX ) maxX = x;
  3840. if ( y > maxY ) maxY = y;
  3841. if ( z > maxZ ) maxZ = z;
  3842. }
  3843. this.min.set( minX, minY, minZ );
  3844. this.max.set( maxX, maxY, maxZ );
  3845. return this;
  3846. },
  3847. setFromPoints: function ( points ) {
  3848. this.makeEmpty();
  3849. for ( let i = 0, il = points.length; i < il; i ++ ) {
  3850. this.expandByPoint( points[ i ] );
  3851. }
  3852. return this;
  3853. },
  3854. setFromCenterAndSize: function ( center, size ) {
  3855. const halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  3856. this.min.copy( center ).sub( halfSize );
  3857. this.max.copy( center ).add( halfSize );
  3858. return this;
  3859. },
  3860. setFromObject: function ( object ) {
  3861. this.makeEmpty();
  3862. return this.expandByObject( object );
  3863. },
  3864. clone: function () {
  3865. return new this.constructor().copy( this );
  3866. },
  3867. copy: function ( box ) {
  3868. this.min.copy( box.min );
  3869. this.max.copy( box.max );
  3870. return this;
  3871. },
  3872. makeEmpty: function () {
  3873. this.min.x = this.min.y = this.min.z = + Infinity;
  3874. this.max.x = this.max.y = this.max.z = - Infinity;
  3875. return this;
  3876. },
  3877. isEmpty: function () {
  3878. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3879. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3880. },
  3881. getCenter: function ( target ) {
  3882. if ( target === undefined ) {
  3883. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3884. target = new Vector3();
  3885. }
  3886. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3887. },
  3888. getSize: function ( target ) {
  3889. if ( target === undefined ) {
  3890. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3891. target = new Vector3();
  3892. }
  3893. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3894. },
  3895. expandByPoint: function ( point ) {
  3896. this.min.min( point );
  3897. this.max.max( point );
  3898. return this;
  3899. },
  3900. expandByVector: function ( vector ) {
  3901. this.min.sub( vector );
  3902. this.max.add( vector );
  3903. return this;
  3904. },
  3905. expandByScalar: function ( scalar ) {
  3906. this.min.addScalar( - scalar );
  3907. this.max.addScalar( scalar );
  3908. return this;
  3909. },
  3910. expandByObject: function ( object ) {
  3911. // Computes the world-axis-aligned bounding box of an object (including its children),
  3912. // accounting for both the object's, and children's, world transforms
  3913. object.updateWorldMatrix( false, false );
  3914. const geometry = object.geometry;
  3915. if ( geometry !== undefined ) {
  3916. if ( geometry.boundingBox === null ) {
  3917. geometry.computeBoundingBox();
  3918. }
  3919. _box.copy( geometry.boundingBox );
  3920. _box.applyMatrix4( object.matrixWorld );
  3921. this.union( _box );
  3922. }
  3923. const children = object.children;
  3924. for ( let i = 0, l = children.length; i < l; i ++ ) {
  3925. this.expandByObject( children[ i ] );
  3926. }
  3927. return this;
  3928. },
  3929. containsPoint: function ( point ) {
  3930. return point.x < this.min.x || point.x > this.max.x ||
  3931. point.y < this.min.y || point.y > this.max.y ||
  3932. point.z < this.min.z || point.z > this.max.z ? false : true;
  3933. },
  3934. containsBox: function ( box ) {
  3935. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3936. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3937. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3938. },
  3939. getParameter: function ( point, target ) {
  3940. // This can potentially have a divide by zero if the box
  3941. // has a size dimension of 0.
  3942. if ( target === undefined ) {
  3943. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3944. target = new Vector3();
  3945. }
  3946. return target.set(
  3947. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3948. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3949. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3950. );
  3951. },
  3952. intersectsBox: function ( box ) {
  3953. // using 6 splitting planes to rule out intersections.
  3954. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3955. box.max.y < this.min.y || box.min.y > this.max.y ||
  3956. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3957. },
  3958. intersectsSphere: function ( sphere ) {
  3959. // Find the point on the AABB closest to the sphere center.
  3960. this.clampPoint( sphere.center, _vector$1 );
  3961. // If that point is inside the sphere, the AABB and sphere intersect.
  3962. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3963. },
  3964. intersectsPlane: function ( plane ) {
  3965. // We compute the minimum and maximum dot product values. If those values
  3966. // are on the same side (back or front) of the plane, then there is no intersection.
  3967. let min, max;
  3968. if ( plane.normal.x > 0 ) {
  3969. min = plane.normal.x * this.min.x;
  3970. max = plane.normal.x * this.max.x;
  3971. } else {
  3972. min = plane.normal.x * this.max.x;
  3973. max = plane.normal.x * this.min.x;
  3974. }
  3975. if ( plane.normal.y > 0 ) {
  3976. min += plane.normal.y * this.min.y;
  3977. max += plane.normal.y * this.max.y;
  3978. } else {
  3979. min += plane.normal.y * this.max.y;
  3980. max += plane.normal.y * this.min.y;
  3981. }
  3982. if ( plane.normal.z > 0 ) {
  3983. min += plane.normal.z * this.min.z;
  3984. max += plane.normal.z * this.max.z;
  3985. } else {
  3986. min += plane.normal.z * this.max.z;
  3987. max += plane.normal.z * this.min.z;
  3988. }
  3989. return ( min <= - plane.constant && max >= - plane.constant );
  3990. },
  3991. intersectsTriangle: function ( triangle ) {
  3992. if ( this.isEmpty() ) {
  3993. return false;
  3994. }
  3995. // compute box center and extents
  3996. this.getCenter( _center );
  3997. _extents.subVectors( this.max, _center );
  3998. // translate triangle to aabb origin
  3999. _v0.subVectors( triangle.a, _center );
  4000. _v1$2.subVectors( triangle.b, _center );
  4001. _v2.subVectors( triangle.c, _center );
  4002. // compute edge vectors for triangle
  4003. _f0.subVectors( _v1$2, _v0 );
  4004. _f1.subVectors( _v2, _v1$2 );
  4005. _f2.subVectors( _v0, _v2 );
  4006. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  4007. // 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
  4008. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  4009. let axes = [
  4010. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  4011. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  4012. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  4013. ];
  4014. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4015. return false;
  4016. }
  4017. // test 3 face normals from the aabb
  4018. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  4019. if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) {
  4020. return false;
  4021. }
  4022. // finally testing the face normal of the triangle
  4023. // use already existing triangle edge vectors here
  4024. _triangleNormal.crossVectors( _f0, _f1 );
  4025. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  4026. return satForAxes( axes, _v0, _v1$2, _v2, _extents );
  4027. },
  4028. clampPoint: function ( point, target ) {
  4029. if ( target === undefined ) {
  4030. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  4031. target = new Vector3();
  4032. }
  4033. return target.copy( point ).clamp( this.min, this.max );
  4034. },
  4035. distanceToPoint: function ( point ) {
  4036. const clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  4037. return clampedPoint.sub( point ).length();
  4038. },
  4039. getBoundingSphere: function ( target ) {
  4040. if ( target === undefined ) {
  4041. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4042. //target = new Sphere(); // removed to avoid cyclic dependency
  4043. }
  4044. this.getCenter( target.center );
  4045. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  4046. return target;
  4047. },
  4048. intersect: function ( box ) {
  4049. this.min.max( box.min );
  4050. this.max.min( box.max );
  4051. // 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.
  4052. if ( this.isEmpty() ) this.makeEmpty();
  4053. return this;
  4054. },
  4055. union: function ( box ) {
  4056. this.min.min( box.min );
  4057. this.max.max( box.max );
  4058. return this;
  4059. },
  4060. applyMatrix4: function ( matrix ) {
  4061. // transform of empty box is an empty box.
  4062. if ( this.isEmpty() ) return this;
  4063. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4064. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4065. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4066. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4067. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4068. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4069. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4070. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4071. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4072. this.setFromPoints( _points );
  4073. return this;
  4074. },
  4075. translate: function ( offset ) {
  4076. this.min.add( offset );
  4077. this.max.add( offset );
  4078. return this;
  4079. },
  4080. equals: function ( box ) {
  4081. return box.min.equals( this.min ) && box.max.equals( this.max );
  4082. }
  4083. } );
  4084. function satForAxes( axes, v0, v1, v2, extents ) {
  4085. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  4086. _testAxis.fromArray( axes, i );
  4087. // project the aabb onto the seperating axis
  4088. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  4089. // project all 3 vertices of the triangle onto the seperating axis
  4090. const p0 = v0.dot( _testAxis );
  4091. const p1 = v1.dot( _testAxis );
  4092. const p2 = v2.dot( _testAxis );
  4093. // actual test, basically see if either of the most extreme of the triangle points intersects r
  4094. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  4095. // points of the projected triangle are outside the projected half-length of the aabb
  4096. // the axis is seperating and we can exit
  4097. return false;
  4098. }
  4099. }
  4100. return true;
  4101. }
  4102. const _box$1 = new Box3();
  4103. /**
  4104. * @author bhouston / http://clara.io
  4105. * @author mrdoob / http://mrdoob.com/
  4106. */
  4107. function Sphere( center, radius ) {
  4108. this.center = ( center !== undefined ) ? center : new Vector3();
  4109. this.radius = ( radius !== undefined ) ? radius : - 1;
  4110. }
  4111. Object.assign( Sphere.prototype, {
  4112. set: function ( center, radius ) {
  4113. this.center.copy( center );
  4114. this.radius = radius;
  4115. return this;
  4116. },
  4117. setFromPoints: function ( points, optionalCenter ) {
  4118. const center = this.center;
  4119. if ( optionalCenter !== undefined ) {
  4120. center.copy( optionalCenter );
  4121. } else {
  4122. _box$1.setFromPoints( points ).getCenter( center );
  4123. }
  4124. let maxRadiusSq = 0;
  4125. for ( let i = 0, il = points.length; i < il; i ++ ) {
  4126. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4127. }
  4128. this.radius = Math.sqrt( maxRadiusSq );
  4129. return this;
  4130. },
  4131. clone: function () {
  4132. return new this.constructor().copy( this );
  4133. },
  4134. copy: function ( sphere ) {
  4135. this.center.copy( sphere.center );
  4136. this.radius = sphere.radius;
  4137. return this;
  4138. },
  4139. isEmpty: function () {
  4140. return ( this.radius < 0 );
  4141. },
  4142. makeEmpty: function () {
  4143. this.center.set( 0, 0, 0 );
  4144. this.radius = - 1;
  4145. return this;
  4146. },
  4147. containsPoint: function ( point ) {
  4148. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4149. },
  4150. distanceToPoint: function ( point ) {
  4151. return ( point.distanceTo( this.center ) - this.radius );
  4152. },
  4153. intersectsSphere: function ( sphere ) {
  4154. const radiusSum = this.radius + sphere.radius;
  4155. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4156. },
  4157. intersectsBox: function ( box ) {
  4158. return box.intersectsSphere( this );
  4159. },
  4160. intersectsPlane: function ( plane ) {
  4161. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4162. },
  4163. clampPoint: function ( point, target ) {
  4164. const deltaLengthSq = this.center.distanceToSquared( point );
  4165. if ( target === undefined ) {
  4166. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4167. target = new Vector3();
  4168. }
  4169. target.copy( point );
  4170. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4171. target.sub( this.center ).normalize();
  4172. target.multiplyScalar( this.radius ).add( this.center );
  4173. }
  4174. return target;
  4175. },
  4176. getBoundingBox: function ( target ) {
  4177. if ( target === undefined ) {
  4178. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4179. target = new Box3();
  4180. }
  4181. if ( this.isEmpty() ) {
  4182. // Empty sphere produces empty bounding box
  4183. target.makeEmpty();
  4184. return target;
  4185. }
  4186. target.set( this.center, this.center );
  4187. target.expandByScalar( this.radius );
  4188. return target;
  4189. },
  4190. applyMatrix4: function ( matrix ) {
  4191. this.center.applyMatrix4( matrix );
  4192. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4193. return this;
  4194. },
  4195. translate: function ( offset ) {
  4196. this.center.add( offset );
  4197. return this;
  4198. },
  4199. equals: function ( sphere ) {
  4200. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4201. }
  4202. } );
  4203. const _vector$2 = new Vector3();
  4204. const _segCenter = new Vector3();
  4205. const _segDir = new Vector3();
  4206. const _diff = new Vector3();
  4207. const _edge1 = new Vector3();
  4208. const _edge2 = new Vector3();
  4209. const _normal = new Vector3();
  4210. /**
  4211. * @author bhouston / http://clara.io
  4212. */
  4213. function Ray( origin, direction ) {
  4214. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4215. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  4216. }
  4217. Object.assign( Ray.prototype, {
  4218. set: function ( origin, direction ) {
  4219. this.origin.copy( origin );
  4220. this.direction.copy( direction );
  4221. return this;
  4222. },
  4223. clone: function () {
  4224. return new this.constructor().copy( this );
  4225. },
  4226. copy: function ( ray ) {
  4227. this.origin.copy( ray.origin );
  4228. this.direction.copy( ray.direction );
  4229. return this;
  4230. },
  4231. at: function ( t, target ) {
  4232. if ( target === undefined ) {
  4233. console.warn( 'THREE.Ray: .at() target is now required' );
  4234. target = new Vector3();
  4235. }
  4236. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4237. },
  4238. lookAt: function ( v ) {
  4239. this.direction.copy( v ).sub( this.origin ).normalize();
  4240. return this;
  4241. },
  4242. recast: function ( t ) {
  4243. this.origin.copy( this.at( t, _vector$2 ) );
  4244. return this;
  4245. },
  4246. closestPointToPoint: function ( point, target ) {
  4247. if ( target === undefined ) {
  4248. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4249. target = new Vector3();
  4250. }
  4251. target.subVectors( point, this.origin );
  4252. const directionDistance = target.dot( this.direction );
  4253. if ( directionDistance < 0 ) {
  4254. return target.copy( this.origin );
  4255. }
  4256. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4257. },
  4258. distanceToPoint: function ( point ) {
  4259. return Math.sqrt( this.distanceSqToPoint( point ) );
  4260. },
  4261. distanceSqToPoint: function ( point ) {
  4262. const directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  4263. // point behind the ray
  4264. if ( directionDistance < 0 ) {
  4265. return this.origin.distanceToSquared( point );
  4266. }
  4267. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4268. return _vector$2.distanceToSquared( point );
  4269. },
  4270. distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4271. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4272. // It returns the min distance between the ray and the segment
  4273. // defined by v0 and v1
  4274. // It can also set two optional targets :
  4275. // - The closest point on the ray
  4276. // - The closest point on the segment
  4277. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4278. _segDir.copy( v1 ).sub( v0 ).normalize();
  4279. _diff.copy( this.origin ).sub( _segCenter );
  4280. const segExtent = v0.distanceTo( v1 ) * 0.5;
  4281. const a01 = - this.direction.dot( _segDir );
  4282. const b0 = _diff.dot( this.direction );
  4283. const b1 = - _diff.dot( _segDir );
  4284. const c = _diff.lengthSq();
  4285. const det = Math.abs( 1 - a01 * a01 );
  4286. let s0, s1, sqrDist, extDet;
  4287. if ( det > 0 ) {
  4288. // The ray and segment are not parallel.
  4289. s0 = a01 * b1 - b0;
  4290. s1 = a01 * b0 - b1;
  4291. extDet = segExtent * det;
  4292. if ( s0 >= 0 ) {
  4293. if ( s1 >= - extDet ) {
  4294. if ( s1 <= extDet ) {
  4295. // region 0
  4296. // Minimum at interior points of ray and segment.
  4297. const invDet = 1 / det;
  4298. s0 *= invDet;
  4299. s1 *= invDet;
  4300. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4301. } else {
  4302. // region 1
  4303. s1 = segExtent;
  4304. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4305. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4306. }
  4307. } else {
  4308. // region 5
  4309. s1 = - segExtent;
  4310. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4311. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4312. }
  4313. } else {
  4314. if ( s1 <= - extDet ) {
  4315. // region 4
  4316. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4317. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4318. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4319. } else if ( s1 <= extDet ) {
  4320. // region 3
  4321. s0 = 0;
  4322. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4323. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4324. } else {
  4325. // region 2
  4326. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4327. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4328. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4329. }
  4330. }
  4331. } else {
  4332. // Ray and segment are parallel.
  4333. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4334. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4335. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4336. }
  4337. if ( optionalPointOnRay ) {
  4338. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4339. }
  4340. if ( optionalPointOnSegment ) {
  4341. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  4342. }
  4343. return sqrDist;
  4344. },
  4345. intersectSphere: function ( sphere, target ) {
  4346. _vector$2.subVectors( sphere.center, this.origin );
  4347. const tca = _vector$2.dot( this.direction );
  4348. const d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  4349. const radius2 = sphere.radius * sphere.radius;
  4350. if ( d2 > radius2 ) return null;
  4351. const thc = Math.sqrt( radius2 - d2 );
  4352. // t0 = first intersect point - entrance on front of sphere
  4353. const t0 = tca - thc;
  4354. // t1 = second intersect point - exit point on back of sphere
  4355. const t1 = tca + thc;
  4356. // test to see if both t0 and t1 are behind the ray - if so, return null
  4357. if ( t0 < 0 && t1 < 0 ) return null;
  4358. // test to see if t0 is behind the ray:
  4359. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4360. // in order to always return an intersect point that is in front of the ray.
  4361. if ( t0 < 0 ) return this.at( t1, target );
  4362. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4363. return this.at( t0, target );
  4364. },
  4365. intersectsSphere: function ( sphere ) {
  4366. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4367. },
  4368. distanceToPlane: function ( plane ) {
  4369. const denominator = plane.normal.dot( this.direction );
  4370. if ( denominator === 0 ) {
  4371. // line is coplanar, return origin
  4372. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4373. return 0;
  4374. }
  4375. // Null is preferable to undefined since undefined means.... it is undefined
  4376. return null;
  4377. }
  4378. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4379. // Return if the ray never intersects the plane
  4380. return t >= 0 ? t : null;
  4381. },
  4382. intersectPlane: function ( plane, target ) {
  4383. const t = this.distanceToPlane( plane );
  4384. if ( t === null ) {
  4385. return null;
  4386. }
  4387. return this.at( t, target );
  4388. },
  4389. intersectsPlane: function ( plane ) {
  4390. // check if the ray lies on the plane first
  4391. const distToPoint = plane.distanceToPoint( this.origin );
  4392. if ( distToPoint === 0 ) {
  4393. return true;
  4394. }
  4395. const denominator = plane.normal.dot( this.direction );
  4396. if ( denominator * distToPoint < 0 ) {
  4397. return true;
  4398. }
  4399. // ray origin is behind the plane (and is pointing behind it)
  4400. return false;
  4401. },
  4402. intersectBox: function ( box, target ) {
  4403. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  4404. const invdirx = 1 / this.direction.x,
  4405. invdiry = 1 / this.direction.y,
  4406. invdirz = 1 / this.direction.z;
  4407. const origin = this.origin;
  4408. if ( invdirx >= 0 ) {
  4409. tmin = ( box.min.x - origin.x ) * invdirx;
  4410. tmax = ( box.max.x - origin.x ) * invdirx;
  4411. } else {
  4412. tmin = ( box.max.x - origin.x ) * invdirx;
  4413. tmax = ( box.min.x - origin.x ) * invdirx;
  4414. }
  4415. if ( invdiry >= 0 ) {
  4416. tymin = ( box.min.y - origin.y ) * invdiry;
  4417. tymax = ( box.max.y - origin.y ) * invdiry;
  4418. } else {
  4419. tymin = ( box.max.y - origin.y ) * invdiry;
  4420. tymax = ( box.min.y - origin.y ) * invdiry;
  4421. }
  4422. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4423. // These lines also handle the case where tmin or tmax is NaN
  4424. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4425. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4426. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4427. if ( invdirz >= 0 ) {
  4428. tzmin = ( box.min.z - origin.z ) * invdirz;
  4429. tzmax = ( box.max.z - origin.z ) * invdirz;
  4430. } else {
  4431. tzmin = ( box.max.z - origin.z ) * invdirz;
  4432. tzmax = ( box.min.z - origin.z ) * invdirz;
  4433. }
  4434. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4435. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4436. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4437. //return point closest to the ray (positive side)
  4438. if ( tmax < 0 ) return null;
  4439. return this.at( tmin >= 0 ? tmin : tmax, target );
  4440. },
  4441. intersectsBox: function ( box ) {
  4442. return this.intersectBox( box, _vector$2 ) !== null;
  4443. },
  4444. intersectTriangle: function ( a, b, c, backfaceCulling, target ) {
  4445. // Compute the offset origin, edges, and normal.
  4446. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4447. _edge1.subVectors( b, a );
  4448. _edge2.subVectors( c, a );
  4449. _normal.crossVectors( _edge1, _edge2 );
  4450. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4451. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4452. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4453. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4454. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4455. let DdN = this.direction.dot( _normal );
  4456. let sign;
  4457. if ( DdN > 0 ) {
  4458. if ( backfaceCulling ) return null;
  4459. sign = 1;
  4460. } else if ( DdN < 0 ) {
  4461. sign = - 1;
  4462. DdN = - DdN;
  4463. } else {
  4464. return null;
  4465. }
  4466. _diff.subVectors( this.origin, a );
  4467. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  4468. // b1 < 0, no intersection
  4469. if ( DdQxE2 < 0 ) {
  4470. return null;
  4471. }
  4472. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  4473. // b2 < 0, no intersection
  4474. if ( DdE1xQ < 0 ) {
  4475. return null;
  4476. }
  4477. // b1+b2 > 1, no intersection
  4478. if ( DdQxE2 + DdE1xQ > DdN ) {
  4479. return null;
  4480. }
  4481. // Line intersects triangle, check if ray does.
  4482. const QdN = - sign * _diff.dot( _normal );
  4483. // t < 0, no intersection
  4484. if ( QdN < 0 ) {
  4485. return null;
  4486. }
  4487. // Ray intersects triangle.
  4488. return this.at( QdN / DdN, target );
  4489. },
  4490. applyMatrix4: function ( matrix4 ) {
  4491. this.origin.applyMatrix4( matrix4 );
  4492. this.direction.transformDirection( matrix4 );
  4493. return this;
  4494. },
  4495. equals: function ( ray ) {
  4496. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4497. }
  4498. } );
  4499. /**
  4500. * @author bhouston / http://clara.io
  4501. */
  4502. const _vector1 = new Vector3();
  4503. const _vector2 = new Vector3();
  4504. const _normalMatrix = new Matrix3();
  4505. function Plane( normal, constant ) {
  4506. // normal is assumed to be normalized
  4507. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4508. this.constant = ( constant !== undefined ) ? constant : 0;
  4509. }
  4510. Object.assign( Plane.prototype, {
  4511. isPlane: true,
  4512. set: function ( normal, constant ) {
  4513. this.normal.copy( normal );
  4514. this.constant = constant;
  4515. return this;
  4516. },
  4517. setComponents: function ( x, y, z, w ) {
  4518. this.normal.set( x, y, z );
  4519. this.constant = w;
  4520. return this;
  4521. },
  4522. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  4523. this.normal.copy( normal );
  4524. this.constant = - point.dot( this.normal );
  4525. return this;
  4526. },
  4527. setFromCoplanarPoints: function ( a, b, c ) {
  4528. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4529. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4530. this.setFromNormalAndCoplanarPoint( normal, a );
  4531. return this;
  4532. },
  4533. clone: function () {
  4534. return new this.constructor().copy( this );
  4535. },
  4536. copy: function ( plane ) {
  4537. this.normal.copy( plane.normal );
  4538. this.constant = plane.constant;
  4539. return this;
  4540. },
  4541. normalize: function () {
  4542. // Note: will lead to a divide by zero if the plane is invalid.
  4543. const inverseNormalLength = 1.0 / this.normal.length();
  4544. this.normal.multiplyScalar( inverseNormalLength );
  4545. this.constant *= inverseNormalLength;
  4546. return this;
  4547. },
  4548. negate: function () {
  4549. this.constant *= - 1;
  4550. this.normal.negate();
  4551. return this;
  4552. },
  4553. distanceToPoint: function ( point ) {
  4554. return this.normal.dot( point ) + this.constant;
  4555. },
  4556. distanceToSphere: function ( sphere ) {
  4557. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4558. },
  4559. projectPoint: function ( point, target ) {
  4560. if ( target === undefined ) {
  4561. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4562. target = new Vector3();
  4563. }
  4564. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4565. },
  4566. intersectLine: function ( line, target ) {
  4567. if ( target === undefined ) {
  4568. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4569. target = new Vector3();
  4570. }
  4571. const direction = line.delta( _vector1 );
  4572. const denominator = this.normal.dot( direction );
  4573. if ( denominator === 0 ) {
  4574. // line is coplanar, return origin
  4575. if ( this.distanceToPoint( line.start ) === 0 ) {
  4576. return target.copy( line.start );
  4577. }
  4578. // Unsure if this is the correct method to handle this case.
  4579. return undefined;
  4580. }
  4581. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4582. if ( t < 0 || t > 1 ) {
  4583. return undefined;
  4584. }
  4585. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4586. },
  4587. intersectsLine: function ( line ) {
  4588. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4589. const startSign = this.distanceToPoint( line.start );
  4590. const endSign = this.distanceToPoint( line.end );
  4591. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4592. },
  4593. intersectsBox: function ( box ) {
  4594. return box.intersectsPlane( this );
  4595. },
  4596. intersectsSphere: function ( sphere ) {
  4597. return sphere.intersectsPlane( this );
  4598. },
  4599. coplanarPoint: function ( target ) {
  4600. if ( target === undefined ) {
  4601. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4602. target = new Vector3();
  4603. }
  4604. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4605. },
  4606. applyMatrix4: function ( matrix, optionalNormalMatrix ) {
  4607. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4608. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4609. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4610. this.constant = - referencePoint.dot( normal );
  4611. return this;
  4612. },
  4613. translate: function ( offset ) {
  4614. this.constant -= offset.dot( this.normal );
  4615. return this;
  4616. },
  4617. equals: function ( plane ) {
  4618. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4619. }
  4620. } );
  4621. /**
  4622. * @author bhouston / http://clara.io
  4623. * @author mrdoob / http://mrdoob.com/
  4624. */
  4625. const _v0$1 = new Vector3();
  4626. const _v1$3 = new Vector3();
  4627. const _v2$1 = new Vector3();
  4628. const _v3 = new Vector3();
  4629. const _vab = new Vector3();
  4630. const _vac = new Vector3();
  4631. const _vbc = new Vector3();
  4632. const _vap = new Vector3();
  4633. const _vbp = new Vector3();
  4634. const _vcp = new Vector3();
  4635. function Triangle( a, b, c ) {
  4636. this.a = ( a !== undefined ) ? a : new Vector3();
  4637. this.b = ( b !== undefined ) ? b : new Vector3();
  4638. this.c = ( c !== undefined ) ? c : new Vector3();
  4639. }
  4640. Object.assign( Triangle, {
  4641. getNormal: function ( a, b, c, target ) {
  4642. if ( target === undefined ) {
  4643. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4644. target = new Vector3();
  4645. }
  4646. target.subVectors( c, b );
  4647. _v0$1.subVectors( a, b );
  4648. target.cross( _v0$1 );
  4649. const targetLengthSq = target.lengthSq();
  4650. if ( targetLengthSq > 0 ) {
  4651. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4652. }
  4653. return target.set( 0, 0, 0 );
  4654. },
  4655. // static/instance method to calculate barycentric coordinates
  4656. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4657. getBarycoord: function ( point, a, b, c, target ) {
  4658. _v0$1.subVectors( c, a );
  4659. _v1$3.subVectors( b, a );
  4660. _v2$1.subVectors( point, a );
  4661. const dot00 = _v0$1.dot( _v0$1 );
  4662. const dot01 = _v0$1.dot( _v1$3 );
  4663. const dot02 = _v0$1.dot( _v2$1 );
  4664. const dot11 = _v1$3.dot( _v1$3 );
  4665. const dot12 = _v1$3.dot( _v2$1 );
  4666. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4667. if ( target === undefined ) {
  4668. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4669. target = new Vector3();
  4670. }
  4671. // collinear or singular triangle
  4672. if ( denom === 0 ) {
  4673. // arbitrary location outside of triangle?
  4674. // not sure if this is the best idea, maybe should be returning undefined
  4675. return target.set( - 2, - 1, - 1 );
  4676. }
  4677. const invDenom = 1 / denom;
  4678. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4679. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4680. // barycentric coordinates must always sum to 1
  4681. return target.set( 1 - u - v, v, u );
  4682. },
  4683. containsPoint: function ( point, a, b, c ) {
  4684. Triangle.getBarycoord( point, a, b, c, _v3 );
  4685. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4686. },
  4687. getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4688. this.getBarycoord( point, p1, p2, p3, _v3 );
  4689. target.set( 0, 0 );
  4690. target.addScaledVector( uv1, _v3.x );
  4691. target.addScaledVector( uv2, _v3.y );
  4692. target.addScaledVector( uv3, _v3.z );
  4693. return target;
  4694. },
  4695. isFrontFacing: function ( a, b, c, direction ) {
  4696. _v0$1.subVectors( c, b );
  4697. _v1$3.subVectors( a, b );
  4698. // strictly front facing
  4699. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4700. }
  4701. } );
  4702. Object.assign( Triangle.prototype, {
  4703. set: function ( a, b, c ) {
  4704. this.a.copy( a );
  4705. this.b.copy( b );
  4706. this.c.copy( c );
  4707. return this;
  4708. },
  4709. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4710. this.a.copy( points[ i0 ] );
  4711. this.b.copy( points[ i1 ] );
  4712. this.c.copy( points[ i2 ] );
  4713. return this;
  4714. },
  4715. clone: function () {
  4716. return new this.constructor().copy( this );
  4717. },
  4718. copy: function ( triangle ) {
  4719. this.a.copy( triangle.a );
  4720. this.b.copy( triangle.b );
  4721. this.c.copy( triangle.c );
  4722. return this;
  4723. },
  4724. getArea: function () {
  4725. _v0$1.subVectors( this.c, this.b );
  4726. _v1$3.subVectors( this.a, this.b );
  4727. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4728. },
  4729. getMidpoint: function ( target ) {
  4730. if ( target === undefined ) {
  4731. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4732. target = new Vector3();
  4733. }
  4734. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4735. },
  4736. getNormal: function ( target ) {
  4737. return Triangle.getNormal( this.a, this.b, this.c, target );
  4738. },
  4739. getPlane: function ( target ) {
  4740. if ( target === undefined ) {
  4741. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4742. target = new Plane();
  4743. }
  4744. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4745. },
  4746. getBarycoord: function ( point, target ) {
  4747. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4748. },
  4749. getUV: function ( point, uv1, uv2, uv3, target ) {
  4750. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4751. },
  4752. containsPoint: function ( point ) {
  4753. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4754. },
  4755. isFrontFacing: function ( direction ) {
  4756. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4757. },
  4758. intersectsBox: function ( box ) {
  4759. return box.intersectsTriangle( this );
  4760. },
  4761. closestPointToPoint: function ( p, target ) {
  4762. if ( target === undefined ) {
  4763. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4764. target = new Vector3();
  4765. }
  4766. const a = this.a, b = this.b, c = this.c;
  4767. let v, w;
  4768. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4769. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4770. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4771. // basically, we're distinguishing which of the voronoi regions of the triangle
  4772. // the point lies in with the minimum amount of redundant computation.
  4773. _vab.subVectors( b, a );
  4774. _vac.subVectors( c, a );
  4775. _vap.subVectors( p, a );
  4776. const d1 = _vab.dot( _vap );
  4777. const d2 = _vac.dot( _vap );
  4778. if ( d1 <= 0 && d2 <= 0 ) {
  4779. // vertex region of A; barycentric coords (1, 0, 0)
  4780. return target.copy( a );
  4781. }
  4782. _vbp.subVectors( p, b );
  4783. const d3 = _vab.dot( _vbp );
  4784. const d4 = _vac.dot( _vbp );
  4785. if ( d3 >= 0 && d4 <= d3 ) {
  4786. // vertex region of B; barycentric coords (0, 1, 0)
  4787. return target.copy( b );
  4788. }
  4789. const vc = d1 * d4 - d3 * d2;
  4790. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4791. v = d1 / ( d1 - d3 );
  4792. // edge region of AB; barycentric coords (1-v, v, 0)
  4793. return target.copy( a ).addScaledVector( _vab, v );
  4794. }
  4795. _vcp.subVectors( p, c );
  4796. const d5 = _vab.dot( _vcp );
  4797. const d6 = _vac.dot( _vcp );
  4798. if ( d6 >= 0 && d5 <= d6 ) {
  4799. // vertex region of C; barycentric coords (0, 0, 1)
  4800. return target.copy( c );
  4801. }
  4802. const vb = d5 * d2 - d1 * d6;
  4803. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4804. w = d2 / ( d2 - d6 );
  4805. // edge region of AC; barycentric coords (1-w, 0, w)
  4806. return target.copy( a ).addScaledVector( _vac, w );
  4807. }
  4808. const va = d3 * d6 - d5 * d4;
  4809. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4810. _vbc.subVectors( c, b );
  4811. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4812. // edge region of BC; barycentric coords (0, 1-w, w)
  4813. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4814. }
  4815. // face region
  4816. const denom = 1 / ( va + vb + vc );
  4817. // u = va * denom
  4818. v = vb * denom;
  4819. w = vc * denom;
  4820. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4821. },
  4822. equals: function ( triangle ) {
  4823. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4824. }
  4825. } );
  4826. /**
  4827. * @author mrdoob / http://mrdoob.com/
  4828. */
  4829. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4830. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4831. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4832. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4833. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4834. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4835. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4836. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4837. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4838. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4839. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4840. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4841. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4842. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4843. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4844. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4845. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4846. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4847. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4848. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4849. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4850. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4851. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4852. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4853. const _hslA = { h: 0, s: 0, l: 0 };
  4854. const _hslB = { h: 0, s: 0, l: 0 };
  4855. function Color( r, g, b ) {
  4856. if ( g === undefined && b === undefined ) {
  4857. // r is THREE.Color, hex or string
  4858. return this.set( r );
  4859. }
  4860. return this.setRGB( r, g, b );
  4861. }
  4862. function hue2rgb( p, q, t ) {
  4863. if ( t < 0 ) t += 1;
  4864. if ( t > 1 ) t -= 1;
  4865. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4866. if ( t < 1 / 2 ) return q;
  4867. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4868. return p;
  4869. }
  4870. function SRGBToLinear( c ) {
  4871. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4872. }
  4873. function LinearToSRGB( c ) {
  4874. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4875. }
  4876. Object.assign( Color.prototype, {
  4877. isColor: true,
  4878. r: 1, g: 1, b: 1,
  4879. set: function ( value ) {
  4880. if ( value && value.isColor ) {
  4881. this.copy( value );
  4882. } else if ( typeof value === 'number' ) {
  4883. this.setHex( value );
  4884. } else if ( typeof value === 'string' ) {
  4885. this.setStyle( value );
  4886. }
  4887. return this;
  4888. },
  4889. setScalar: function ( scalar ) {
  4890. this.r = scalar;
  4891. this.g = scalar;
  4892. this.b = scalar;
  4893. return this;
  4894. },
  4895. setHex: function ( hex ) {
  4896. hex = Math.floor( hex );
  4897. this.r = ( hex >> 16 & 255 ) / 255;
  4898. this.g = ( hex >> 8 & 255 ) / 255;
  4899. this.b = ( hex & 255 ) / 255;
  4900. return this;
  4901. },
  4902. setRGB: function ( r, g, b ) {
  4903. this.r = r;
  4904. this.g = g;
  4905. this.b = b;
  4906. return this;
  4907. },
  4908. setHSL: function ( h, s, l ) {
  4909. // h,s,l ranges are in 0.0 - 1.0
  4910. h = MathUtils.euclideanModulo( h, 1 );
  4911. s = MathUtils.clamp( s, 0, 1 );
  4912. l = MathUtils.clamp( l, 0, 1 );
  4913. if ( s === 0 ) {
  4914. this.r = this.g = this.b = l;
  4915. } else {
  4916. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4917. const q = ( 2 * l ) - p;
  4918. this.r = hue2rgb( q, p, h + 1 / 3 );
  4919. this.g = hue2rgb( q, p, h );
  4920. this.b = hue2rgb( q, p, h - 1 / 3 );
  4921. }
  4922. return this;
  4923. },
  4924. setStyle: function ( style ) {
  4925. function handleAlpha( string ) {
  4926. if ( string === undefined ) return;
  4927. if ( parseFloat( string ) < 1 ) {
  4928. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4929. }
  4930. }
  4931. let m;
  4932. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4933. // rgb / hsl
  4934. let color;
  4935. const name = m[ 1 ];
  4936. const components = m[ 2 ];
  4937. switch ( name ) {
  4938. case 'rgb':
  4939. case 'rgba':
  4940. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4941. // rgb(255,0,0) rgba(255,0,0,0.5)
  4942. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4943. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4944. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4945. handleAlpha( color[ 5 ] );
  4946. return this;
  4947. }
  4948. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4949. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4950. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4951. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4952. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4953. handleAlpha( color[ 5 ] );
  4954. return this;
  4955. }
  4956. break;
  4957. case 'hsl':
  4958. case 'hsla':
  4959. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4960. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4961. const h = parseFloat( color[ 1 ] ) / 360;
  4962. const s = parseInt( color[ 2 ], 10 ) / 100;
  4963. const l = parseInt( color[ 3 ], 10 ) / 100;
  4964. handleAlpha( color[ 5 ] );
  4965. return this.setHSL( h, s, l );
  4966. }
  4967. break;
  4968. }
  4969. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4970. // hex color
  4971. const hex = m[ 1 ];
  4972. const size = hex.length;
  4973. if ( size === 3 ) {
  4974. // #ff0
  4975. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4976. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4977. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4978. return this;
  4979. } else if ( size === 6 ) {
  4980. // #ff0000
  4981. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4982. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4983. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4984. return this;
  4985. }
  4986. }
  4987. if ( style && style.length > 0 ) {
  4988. return this.setColorName( style );
  4989. }
  4990. return this;
  4991. },
  4992. setColorName: function ( style ) {
  4993. // color keywords
  4994. const hex = _colorKeywords[ style ];
  4995. if ( hex !== undefined ) {
  4996. // red
  4997. this.setHex( hex );
  4998. } else {
  4999. // unknown color
  5000. console.warn( 'THREE.Color: Unknown color ' + style );
  5001. }
  5002. return this;
  5003. },
  5004. clone: function () {
  5005. return new this.constructor( this.r, this.g, this.b );
  5006. },
  5007. copy: function ( color ) {
  5008. this.r = color.r;
  5009. this.g = color.g;
  5010. this.b = color.b;
  5011. return this;
  5012. },
  5013. copyGammaToLinear: function ( color, gammaFactor ) {
  5014. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5015. this.r = Math.pow( color.r, gammaFactor );
  5016. this.g = Math.pow( color.g, gammaFactor );
  5017. this.b = Math.pow( color.b, gammaFactor );
  5018. return this;
  5019. },
  5020. copyLinearToGamma: function ( color, gammaFactor ) {
  5021. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5022. const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5023. this.r = Math.pow( color.r, safeInverse );
  5024. this.g = Math.pow( color.g, safeInverse );
  5025. this.b = Math.pow( color.b, safeInverse );
  5026. return this;
  5027. },
  5028. convertGammaToLinear: function ( gammaFactor ) {
  5029. this.copyGammaToLinear( this, gammaFactor );
  5030. return this;
  5031. },
  5032. convertLinearToGamma: function ( gammaFactor ) {
  5033. this.copyLinearToGamma( this, gammaFactor );
  5034. return this;
  5035. },
  5036. copySRGBToLinear: function ( color ) {
  5037. this.r = SRGBToLinear( color.r );
  5038. this.g = SRGBToLinear( color.g );
  5039. this.b = SRGBToLinear( color.b );
  5040. return this;
  5041. },
  5042. copyLinearToSRGB: function ( color ) {
  5043. this.r = LinearToSRGB( color.r );
  5044. this.g = LinearToSRGB( color.g );
  5045. this.b = LinearToSRGB( color.b );
  5046. return this;
  5047. },
  5048. convertSRGBToLinear: function () {
  5049. this.copySRGBToLinear( this );
  5050. return this;
  5051. },
  5052. convertLinearToSRGB: function () {
  5053. this.copyLinearToSRGB( this );
  5054. return this;
  5055. },
  5056. getHex: function () {
  5057. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5058. },
  5059. getHexString: function () {
  5060. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5061. },
  5062. getHSL: function ( target ) {
  5063. // h,s,l ranges are in 0.0 - 1.0
  5064. if ( target === undefined ) {
  5065. console.warn( 'THREE.Color: .getHSL() target is now required' );
  5066. target = { h: 0, s: 0, l: 0 };
  5067. }
  5068. const r = this.r, g = this.g, b = this.b;
  5069. const max = Math.max( r, g, b );
  5070. const min = Math.min( r, g, b );
  5071. let hue, saturation;
  5072. const lightness = ( min + max ) / 2.0;
  5073. if ( min === max ) {
  5074. hue = 0;
  5075. saturation = 0;
  5076. } else {
  5077. const delta = max - min;
  5078. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5079. switch ( max ) {
  5080. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5081. case g: hue = ( b - r ) / delta + 2; break;
  5082. case b: hue = ( r - g ) / delta + 4; break;
  5083. }
  5084. hue /= 6;
  5085. }
  5086. target.h = hue;
  5087. target.s = saturation;
  5088. target.l = lightness;
  5089. return target;
  5090. },
  5091. getStyle: function () {
  5092. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5093. },
  5094. offsetHSL: function ( h, s, l ) {
  5095. this.getHSL( _hslA );
  5096. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  5097. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  5098. return this;
  5099. },
  5100. add: function ( color ) {
  5101. this.r += color.r;
  5102. this.g += color.g;
  5103. this.b += color.b;
  5104. return this;
  5105. },
  5106. addColors: function ( color1, color2 ) {
  5107. this.r = color1.r + color2.r;
  5108. this.g = color1.g + color2.g;
  5109. this.b = color1.b + color2.b;
  5110. return this;
  5111. },
  5112. addScalar: function ( s ) {
  5113. this.r += s;
  5114. this.g += s;
  5115. this.b += s;
  5116. return this;
  5117. },
  5118. sub: function ( color ) {
  5119. this.r = Math.max( 0, this.r - color.r );
  5120. this.g = Math.max( 0, this.g - color.g );
  5121. this.b = Math.max( 0, this.b - color.b );
  5122. return this;
  5123. },
  5124. multiply: function ( color ) {
  5125. this.r *= color.r;
  5126. this.g *= color.g;
  5127. this.b *= color.b;
  5128. return this;
  5129. },
  5130. multiplyScalar: function ( s ) {
  5131. this.r *= s;
  5132. this.g *= s;
  5133. this.b *= s;
  5134. return this;
  5135. },
  5136. lerp: function ( color, alpha ) {
  5137. this.r += ( color.r - this.r ) * alpha;
  5138. this.g += ( color.g - this.g ) * alpha;
  5139. this.b += ( color.b - this.b ) * alpha;
  5140. return this;
  5141. },
  5142. lerpHSL: function ( color, alpha ) {
  5143. this.getHSL( _hslA );
  5144. color.getHSL( _hslB );
  5145. const h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  5146. const s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  5147. const l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  5148. this.setHSL( h, s, l );
  5149. return this;
  5150. },
  5151. equals: function ( c ) {
  5152. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5153. },
  5154. fromArray: function ( array, offset ) {
  5155. if ( offset === undefined ) offset = 0;
  5156. this.r = array[ offset ];
  5157. this.g = array[ offset + 1 ];
  5158. this.b = array[ offset + 2 ];
  5159. return this;
  5160. },
  5161. toArray: function ( array, offset ) {
  5162. if ( array === undefined ) array = [];
  5163. if ( offset === undefined ) offset = 0;
  5164. array[ offset ] = this.r;
  5165. array[ offset + 1 ] = this.g;
  5166. array[ offset + 2 ] = this.b;
  5167. return array;
  5168. },
  5169. fromBufferAttribute: function ( attribute, index ) {
  5170. this.r = attribute.getX( index );
  5171. this.g = attribute.getY( index );
  5172. this.b = attribute.getZ( index );
  5173. if ( attribute.normalized === true ) {
  5174. // assuming Uint8Array
  5175. this.r /= 255;
  5176. this.g /= 255;
  5177. this.b /= 255;
  5178. }
  5179. return this;
  5180. },
  5181. toJSON: function () {
  5182. return this.getHex();
  5183. }
  5184. } );
  5185. Color.NAMES = _colorKeywords;
  5186. /**
  5187. * @author mrdoob / http://mrdoob.com/
  5188. * @author alteredq / http://alteredqualia.com/
  5189. */
  5190. function Face3( a, b, c, normal, color, materialIndex ) {
  5191. this.a = a;
  5192. this.b = b;
  5193. this.c = c;
  5194. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5195. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5196. this.color = ( color && color.isColor ) ? color : new Color();
  5197. this.vertexColors = Array.isArray( color ) ? color : [];
  5198. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5199. }
  5200. Object.assign( Face3.prototype, {
  5201. clone: function () {
  5202. return new this.constructor().copy( this );
  5203. },
  5204. copy: function ( source ) {
  5205. this.a = source.a;
  5206. this.b = source.b;
  5207. this.c = source.c;
  5208. this.normal.copy( source.normal );
  5209. this.color.copy( source.color );
  5210. this.materialIndex = source.materialIndex;
  5211. for ( let i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5212. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5213. }
  5214. for ( let i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5215. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5216. }
  5217. return this;
  5218. }
  5219. } );
  5220. /**
  5221. * @author mrdoob / http://mrdoob.com/
  5222. * @author alteredq / http://alteredqualia.com/
  5223. */
  5224. let materialId = 0;
  5225. function Material() {
  5226. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5227. this.uuid = MathUtils.generateUUID();
  5228. this.name = '';
  5229. this.type = 'Material';
  5230. this.fog = true;
  5231. this.blending = NormalBlending;
  5232. this.side = FrontSide;
  5233. this.flatShading = false;
  5234. this.vertexColors = false;
  5235. this.opacity = 1;
  5236. this.transparent = false;
  5237. this.blendSrc = SrcAlphaFactor;
  5238. this.blendDst = OneMinusSrcAlphaFactor;
  5239. this.blendEquation = AddEquation;
  5240. this.blendSrcAlpha = null;
  5241. this.blendDstAlpha = null;
  5242. this.blendEquationAlpha = null;
  5243. this.depthFunc = LessEqualDepth;
  5244. this.depthTest = true;
  5245. this.depthWrite = true;
  5246. this.stencilWriteMask = 0xff;
  5247. this.stencilFunc = AlwaysStencilFunc;
  5248. this.stencilRef = 0;
  5249. this.stencilFuncMask = 0xff;
  5250. this.stencilFail = KeepStencilOp;
  5251. this.stencilZFail = KeepStencilOp;
  5252. this.stencilZPass = KeepStencilOp;
  5253. this.stencilWrite = false;
  5254. this.clippingPlanes = null;
  5255. this.clipIntersection = false;
  5256. this.clipShadows = false;
  5257. this.shadowSide = null;
  5258. this.colorWrite = true;
  5259. this.precision = null; // override the renderer's default precision for this material
  5260. this.polygonOffset = false;
  5261. this.polygonOffsetFactor = 0;
  5262. this.polygonOffsetUnits = 0;
  5263. this.dithering = false;
  5264. this.alphaTest = 0;
  5265. this.premultipliedAlpha = false;
  5266. this.visible = true;
  5267. this.toneMapped = true;
  5268. this.userData = {};
  5269. this.version = 0;
  5270. }
  5271. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5272. constructor: Material,
  5273. isMaterial: true,
  5274. onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
  5275. customProgramCacheKey: function () {
  5276. return this.onBeforeCompile.toString();
  5277. },
  5278. setValues: function ( values ) {
  5279. if ( values === undefined ) return;
  5280. for ( const key in values ) {
  5281. const newValue = values[ key ];
  5282. if ( newValue === undefined ) {
  5283. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5284. continue;
  5285. }
  5286. // for backward compatability if shading is set in the constructor
  5287. if ( key === 'shading' ) {
  5288. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5289. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5290. continue;
  5291. }
  5292. const currentValue = this[ key ];
  5293. if ( currentValue === undefined ) {
  5294. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5295. continue;
  5296. }
  5297. if ( currentValue && currentValue.isColor ) {
  5298. currentValue.set( newValue );
  5299. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5300. currentValue.copy( newValue );
  5301. } else {
  5302. this[ key ] = newValue;
  5303. }
  5304. }
  5305. },
  5306. toJSON: function ( meta ) {
  5307. const isRoot = ( meta === undefined || typeof meta === 'string' );
  5308. if ( isRoot ) {
  5309. meta = {
  5310. textures: {},
  5311. images: {}
  5312. };
  5313. }
  5314. const data = {
  5315. metadata: {
  5316. version: 4.5,
  5317. type: 'Material',
  5318. generator: 'Material.toJSON'
  5319. }
  5320. };
  5321. // standard Material serialization
  5322. data.uuid = this.uuid;
  5323. data.type = this.type;
  5324. if ( this.name !== '' ) data.name = this.name;
  5325. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5326. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5327. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5328. if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  5329. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5330. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5331. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5332. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5333. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5334. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5335. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5336. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5337. }
  5338. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5339. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5340. }
  5341. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5342. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5343. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5344. }
  5345. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5346. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5347. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5348. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5349. if ( this.aoMap && this.aoMap.isTexture ) {
  5350. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5351. data.aoMapIntensity = this.aoMapIntensity;
  5352. }
  5353. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5354. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5355. data.bumpScale = this.bumpScale;
  5356. }
  5357. if ( this.normalMap && this.normalMap.isTexture ) {
  5358. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5359. data.normalMapType = this.normalMapType;
  5360. data.normalScale = this.normalScale.toArray();
  5361. }
  5362. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5363. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5364. data.displacementScale = this.displacementScale;
  5365. data.displacementBias = this.displacementBias;
  5366. }
  5367. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5368. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5369. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5370. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5371. if ( this.envMap && this.envMap.isTexture ) {
  5372. data.envMap = this.envMap.toJSON( meta ).uuid;
  5373. data.reflectivity = this.reflectivity; // Scale behind envMap
  5374. data.refractionRatio = this.refractionRatio;
  5375. if ( this.combine !== undefined ) data.combine = this.combine;
  5376. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5377. }
  5378. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5379. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5380. }
  5381. if ( this.size !== undefined ) data.size = this.size;
  5382. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5383. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5384. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5385. if ( this.side !== FrontSide ) data.side = this.side;
  5386. if ( this.vertexColors ) data.vertexColors = true;
  5387. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5388. if ( this.transparent === true ) data.transparent = this.transparent;
  5389. data.depthFunc = this.depthFunc;
  5390. data.depthTest = this.depthTest;
  5391. data.depthWrite = this.depthWrite;
  5392. data.stencilWrite = this.stencilWrite;
  5393. data.stencilWriteMask = this.stencilWriteMask;
  5394. data.stencilFunc = this.stencilFunc;
  5395. data.stencilRef = this.stencilRef;
  5396. data.stencilFuncMask = this.stencilFuncMask;
  5397. data.stencilFail = this.stencilFail;
  5398. data.stencilZFail = this.stencilZFail;
  5399. data.stencilZPass = this.stencilZPass;
  5400. // rotation (SpriteMaterial)
  5401. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5402. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5403. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5404. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5405. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5406. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5407. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5408. if ( this.scale !== undefined ) data.scale = this.scale;
  5409. if ( this.dithering === true ) data.dithering = true;
  5410. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5411. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5412. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5413. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5414. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5415. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5416. if ( this.morphTargets === true ) data.morphTargets = true;
  5417. if ( this.morphNormals === true ) data.morphNormals = true;
  5418. if ( this.skinning === true ) data.skinning = true;
  5419. if ( this.visible === false ) data.visible = false;
  5420. if ( this.toneMapped === false ) data.toneMapped = false;
  5421. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5422. // TODO: Copied from Object3D.toJSON
  5423. function extractFromCache( cache ) {
  5424. const values = [];
  5425. for ( const key in cache ) {
  5426. const data = cache[ key ];
  5427. delete data.metadata;
  5428. values.push( data );
  5429. }
  5430. return values;
  5431. }
  5432. if ( isRoot ) {
  5433. const textures = extractFromCache( meta.textures );
  5434. const images = extractFromCache( meta.images );
  5435. if ( textures.length > 0 ) data.textures = textures;
  5436. if ( images.length > 0 ) data.images = images;
  5437. }
  5438. return data;
  5439. },
  5440. clone: function () {
  5441. return new this.constructor().copy( this );
  5442. },
  5443. copy: function ( source ) {
  5444. this.name = source.name;
  5445. this.fog = source.fog;
  5446. this.blending = source.blending;
  5447. this.side = source.side;
  5448. this.flatShading = source.flatShading;
  5449. this.vertexColors = source.vertexColors;
  5450. this.opacity = source.opacity;
  5451. this.transparent = source.transparent;
  5452. this.blendSrc = source.blendSrc;
  5453. this.blendDst = source.blendDst;
  5454. this.blendEquation = source.blendEquation;
  5455. this.blendSrcAlpha = source.blendSrcAlpha;
  5456. this.blendDstAlpha = source.blendDstAlpha;
  5457. this.blendEquationAlpha = source.blendEquationAlpha;
  5458. this.depthFunc = source.depthFunc;
  5459. this.depthTest = source.depthTest;
  5460. this.depthWrite = source.depthWrite;
  5461. this.stencilWriteMask = source.stencilWriteMask;
  5462. this.stencilFunc = source.stencilFunc;
  5463. this.stencilRef = source.stencilRef;
  5464. this.stencilFuncMask = source.stencilFuncMask;
  5465. this.stencilFail = source.stencilFail;
  5466. this.stencilZFail = source.stencilZFail;
  5467. this.stencilZPass = source.stencilZPass;
  5468. this.stencilWrite = source.stencilWrite;
  5469. const srcPlanes = source.clippingPlanes;
  5470. let dstPlanes = null;
  5471. if ( srcPlanes !== null ) {
  5472. const n = srcPlanes.length;
  5473. dstPlanes = new Array( n );
  5474. for ( let i = 0; i !== n; ++ i ) {
  5475. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5476. }
  5477. }
  5478. this.clippingPlanes = dstPlanes;
  5479. this.clipIntersection = source.clipIntersection;
  5480. this.clipShadows = source.clipShadows;
  5481. this.shadowSide = source.shadowSide;
  5482. this.colorWrite = source.colorWrite;
  5483. this.precision = source.precision;
  5484. this.polygonOffset = source.polygonOffset;
  5485. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5486. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5487. this.dithering = source.dithering;
  5488. this.alphaTest = source.alphaTest;
  5489. this.premultipliedAlpha = source.premultipliedAlpha;
  5490. this.visible = source.visible;
  5491. this.toneMapped = source.toneMapped;
  5492. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5493. return this;
  5494. },
  5495. dispose: function () {
  5496. this.dispatchEvent( { type: 'dispose' } );
  5497. }
  5498. } );
  5499. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5500. set: function ( value ) {
  5501. if ( value === true ) this.version ++;
  5502. }
  5503. } );
  5504. /**
  5505. * @author mrdoob / http://mrdoob.com/
  5506. * @author alteredq / http://alteredqualia.com/
  5507. *
  5508. * parameters = {
  5509. * color: <hex>,
  5510. * opacity: <float>,
  5511. * map: new THREE.Texture( <Image> ),
  5512. *
  5513. * lightMap: new THREE.Texture( <Image> ),
  5514. * lightMapIntensity: <float>
  5515. *
  5516. * aoMap: new THREE.Texture( <Image> ),
  5517. * aoMapIntensity: <float>
  5518. *
  5519. * specularMap: new THREE.Texture( <Image> ),
  5520. *
  5521. * alphaMap: new THREE.Texture( <Image> ),
  5522. *
  5523. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5524. * combine: THREE.Multiply,
  5525. * reflectivity: <float>,
  5526. * refractionRatio: <float>,
  5527. *
  5528. * depthTest: <bool>,
  5529. * depthWrite: <bool>,
  5530. *
  5531. * wireframe: <boolean>,
  5532. * wireframeLinewidth: <float>,
  5533. *
  5534. * skinning: <bool>,
  5535. * morphTargets: <bool>
  5536. * }
  5537. */
  5538. function MeshBasicMaterial( parameters ) {
  5539. Material.call( this );
  5540. this.type = 'MeshBasicMaterial';
  5541. this.color = new Color( 0xffffff ); // emissive
  5542. this.map = null;
  5543. this.lightMap = null;
  5544. this.lightMapIntensity = 1.0;
  5545. this.aoMap = null;
  5546. this.aoMapIntensity = 1.0;
  5547. this.specularMap = null;
  5548. this.alphaMap = null;
  5549. this.envMap = null;
  5550. this.combine = MultiplyOperation;
  5551. this.reflectivity = 1;
  5552. this.refractionRatio = 0.98;
  5553. this.wireframe = false;
  5554. this.wireframeLinewidth = 1;
  5555. this.wireframeLinecap = 'round';
  5556. this.wireframeLinejoin = 'round';
  5557. this.skinning = false;
  5558. this.morphTargets = false;
  5559. this.setValues( parameters );
  5560. }
  5561. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5562. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5563. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5564. MeshBasicMaterial.prototype.copy = function ( source ) {
  5565. Material.prototype.copy.call( this, source );
  5566. this.color.copy( source.color );
  5567. this.map = source.map;
  5568. this.lightMap = source.lightMap;
  5569. this.lightMapIntensity = source.lightMapIntensity;
  5570. this.aoMap = source.aoMap;
  5571. this.aoMapIntensity = source.aoMapIntensity;
  5572. this.specularMap = source.specularMap;
  5573. this.alphaMap = source.alphaMap;
  5574. this.envMap = source.envMap;
  5575. this.combine = source.combine;
  5576. this.reflectivity = source.reflectivity;
  5577. this.refractionRatio = source.refractionRatio;
  5578. this.wireframe = source.wireframe;
  5579. this.wireframeLinewidth = source.wireframeLinewidth;
  5580. this.wireframeLinecap = source.wireframeLinecap;
  5581. this.wireframeLinejoin = source.wireframeLinejoin;
  5582. this.skinning = source.skinning;
  5583. this.morphTargets = source.morphTargets;
  5584. return this;
  5585. };
  5586. /**
  5587. * @author mrdoob / http://mrdoob.com/
  5588. */
  5589. const _vector$3 = new Vector3();
  5590. const _vector2$1 = new Vector2();
  5591. function BufferAttribute( array, itemSize, normalized ) {
  5592. if ( Array.isArray( array ) ) {
  5593. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5594. }
  5595. this.name = '';
  5596. this.array = array;
  5597. this.itemSize = itemSize;
  5598. this.count = array !== undefined ? array.length / itemSize : 0;
  5599. this.normalized = normalized === true;
  5600. this.usage = StaticDrawUsage;
  5601. this.updateRange = { offset: 0, count: - 1 };
  5602. this.version = 0;
  5603. }
  5604. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5605. set: function ( value ) {
  5606. if ( value === true ) this.version ++;
  5607. }
  5608. } );
  5609. Object.assign( BufferAttribute.prototype, {
  5610. isBufferAttribute: true,
  5611. onUploadCallback: function () {},
  5612. setUsage: function ( value ) {
  5613. this.usage = value;
  5614. return this;
  5615. },
  5616. copy: function ( source ) {
  5617. this.name = source.name;
  5618. this.array = new source.array.constructor( source.array );
  5619. this.itemSize = source.itemSize;
  5620. this.count = source.count;
  5621. this.normalized = source.normalized;
  5622. this.usage = source.usage;
  5623. return this;
  5624. },
  5625. copyAt: function ( index1, attribute, index2 ) {
  5626. index1 *= this.itemSize;
  5627. index2 *= attribute.itemSize;
  5628. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  5629. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5630. }
  5631. return this;
  5632. },
  5633. copyArray: function ( array ) {
  5634. this.array.set( array );
  5635. return this;
  5636. },
  5637. copyColorsArray: function ( colors ) {
  5638. const array = this.array;
  5639. let offset = 0;
  5640. for ( let i = 0, l = colors.length; i < l; i ++ ) {
  5641. let color = colors[ i ];
  5642. if ( color === undefined ) {
  5643. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5644. color = new Color();
  5645. }
  5646. array[ offset ++ ] = color.r;
  5647. array[ offset ++ ] = color.g;
  5648. array[ offset ++ ] = color.b;
  5649. }
  5650. return this;
  5651. },
  5652. copyVector2sArray: function ( vectors ) {
  5653. const array = this.array;
  5654. let offset = 0;
  5655. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5656. let vector = vectors[ i ];
  5657. if ( vector === undefined ) {
  5658. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5659. vector = new Vector2();
  5660. }
  5661. array[ offset ++ ] = vector.x;
  5662. array[ offset ++ ] = vector.y;
  5663. }
  5664. return this;
  5665. },
  5666. copyVector3sArray: function ( vectors ) {
  5667. const array = this.array;
  5668. let offset = 0;
  5669. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5670. let vector = vectors[ i ];
  5671. if ( vector === undefined ) {
  5672. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5673. vector = new Vector3();
  5674. }
  5675. array[ offset ++ ] = vector.x;
  5676. array[ offset ++ ] = vector.y;
  5677. array[ offset ++ ] = vector.z;
  5678. }
  5679. return this;
  5680. },
  5681. copyVector4sArray: function ( vectors ) {
  5682. const array = this.array;
  5683. let offset = 0;
  5684. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5685. let vector = vectors[ i ];
  5686. if ( vector === undefined ) {
  5687. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5688. vector = new Vector4();
  5689. }
  5690. array[ offset ++ ] = vector.x;
  5691. array[ offset ++ ] = vector.y;
  5692. array[ offset ++ ] = vector.z;
  5693. array[ offset ++ ] = vector.w;
  5694. }
  5695. return this;
  5696. },
  5697. applyMatrix3: function ( m ) {
  5698. if ( this.itemSize === 2 ) {
  5699. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5700. _vector2$1.fromBufferAttribute( this, i );
  5701. _vector2$1.applyMatrix3( m );
  5702. this.setXY( i, _vector2$1.x, _vector2$1.y, );
  5703. }
  5704. } else if ( this.itemSize === 3 ) {
  5705. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5706. _vector$3.fromBufferAttribute( this, i );
  5707. _vector$3.applyMatrix3( m );
  5708. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5709. }
  5710. }
  5711. return this;
  5712. },
  5713. applyMatrix4: function ( m ) {
  5714. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5715. _vector$3.x = this.getX( i );
  5716. _vector$3.y = this.getY( i );
  5717. _vector$3.z = this.getZ( i );
  5718. _vector$3.applyMatrix4( m );
  5719. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5720. }
  5721. return this;
  5722. },
  5723. applyNormalMatrix: function ( m ) {
  5724. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5725. _vector$3.x = this.getX( i );
  5726. _vector$3.y = this.getY( i );
  5727. _vector$3.z = this.getZ( i );
  5728. _vector$3.applyNormalMatrix( m );
  5729. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5730. }
  5731. return this;
  5732. },
  5733. transformDirection: function ( m ) {
  5734. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5735. _vector$3.x = this.getX( i );
  5736. _vector$3.y = this.getY( i );
  5737. _vector$3.z = this.getZ( i );
  5738. _vector$3.transformDirection( m );
  5739. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5740. }
  5741. return this;
  5742. },
  5743. set: function ( value, offset ) {
  5744. if ( offset === undefined ) offset = 0;
  5745. this.array.set( value, offset );
  5746. return this;
  5747. },
  5748. getX: function ( index ) {
  5749. return this.array[ index * this.itemSize ];
  5750. },
  5751. setX: function ( index, x ) {
  5752. this.array[ index * this.itemSize ] = x;
  5753. return this;
  5754. },
  5755. getY: function ( index ) {
  5756. return this.array[ index * this.itemSize + 1 ];
  5757. },
  5758. setY: function ( index, y ) {
  5759. this.array[ index * this.itemSize + 1 ] = y;
  5760. return this;
  5761. },
  5762. getZ: function ( index ) {
  5763. return this.array[ index * this.itemSize + 2 ];
  5764. },
  5765. setZ: function ( index, z ) {
  5766. this.array[ index * this.itemSize + 2 ] = z;
  5767. return this;
  5768. },
  5769. getW: function ( index ) {
  5770. return this.array[ index * this.itemSize + 3 ];
  5771. },
  5772. setW: function ( index, w ) {
  5773. this.array[ index * this.itemSize + 3 ] = w;
  5774. return this;
  5775. },
  5776. setXY: function ( index, x, y ) {
  5777. index *= this.itemSize;
  5778. this.array[ index + 0 ] = x;
  5779. this.array[ index + 1 ] = y;
  5780. return this;
  5781. },
  5782. setXYZ: function ( index, x, y, z ) {
  5783. index *= this.itemSize;
  5784. this.array[ index + 0 ] = x;
  5785. this.array[ index + 1 ] = y;
  5786. this.array[ index + 2 ] = z;
  5787. return this;
  5788. },
  5789. setXYZW: function ( index, x, y, z, w ) {
  5790. index *= this.itemSize;
  5791. this.array[ index + 0 ] = x;
  5792. this.array[ index + 1 ] = y;
  5793. this.array[ index + 2 ] = z;
  5794. this.array[ index + 3 ] = w;
  5795. return this;
  5796. },
  5797. onUpload: function ( callback ) {
  5798. this.onUploadCallback = callback;
  5799. return this;
  5800. },
  5801. clone: function () {
  5802. return new this.constructor( this.array, this.itemSize ).copy( this );
  5803. },
  5804. toJSON: function () {
  5805. return {
  5806. itemSize: this.itemSize,
  5807. type: this.array.constructor.name,
  5808. array: Array.prototype.slice.call( this.array ),
  5809. normalized: this.normalized
  5810. };
  5811. }
  5812. } );
  5813. //
  5814. function Int8BufferAttribute( array, itemSize, normalized ) {
  5815. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5816. }
  5817. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5818. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5819. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5820. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5821. }
  5822. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5823. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5824. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5825. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5826. }
  5827. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5828. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5829. function Int16BufferAttribute( array, itemSize, normalized ) {
  5830. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5831. }
  5832. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5833. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5834. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5835. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5836. }
  5837. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5838. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5839. function Int32BufferAttribute( array, itemSize, normalized ) {
  5840. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5841. }
  5842. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5843. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5844. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5845. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5846. }
  5847. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5848. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5849. function Float32BufferAttribute( array, itemSize, normalized ) {
  5850. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5851. }
  5852. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5853. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5854. function Float64BufferAttribute( array, itemSize, normalized ) {
  5855. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5856. }
  5857. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5858. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5859. /**
  5860. * @author mrdoob / http://mrdoob.com/
  5861. */
  5862. function DirectGeometry() {
  5863. this.vertices = [];
  5864. this.normals = [];
  5865. this.colors = [];
  5866. this.uvs = [];
  5867. this.uvs2 = [];
  5868. this.groups = [];
  5869. this.morphTargets = {};
  5870. this.skinWeights = [];
  5871. this.skinIndices = [];
  5872. // this.lineDistances = [];
  5873. this.boundingBox = null;
  5874. this.boundingSphere = null;
  5875. // update flags
  5876. this.verticesNeedUpdate = false;
  5877. this.normalsNeedUpdate = false;
  5878. this.colorsNeedUpdate = false;
  5879. this.uvsNeedUpdate = false;
  5880. this.groupsNeedUpdate = false;
  5881. }
  5882. Object.assign( DirectGeometry.prototype, {
  5883. computeGroups: function ( geometry ) {
  5884. const groups = [];
  5885. let group, i;
  5886. let materialIndex = undefined;
  5887. const faces = geometry.faces;
  5888. for ( i = 0; i < faces.length; i ++ ) {
  5889. const face = faces[ i ];
  5890. // materials
  5891. if ( face.materialIndex !== materialIndex ) {
  5892. materialIndex = face.materialIndex;
  5893. if ( group !== undefined ) {
  5894. group.count = ( i * 3 ) - group.start;
  5895. groups.push( group );
  5896. }
  5897. group = {
  5898. start: i * 3,
  5899. materialIndex: materialIndex
  5900. };
  5901. }
  5902. }
  5903. if ( group !== undefined ) {
  5904. group.count = ( i * 3 ) - group.start;
  5905. groups.push( group );
  5906. }
  5907. this.groups = groups;
  5908. },
  5909. fromGeometry: function ( geometry ) {
  5910. const faces = geometry.faces;
  5911. const vertices = geometry.vertices;
  5912. const faceVertexUvs = geometry.faceVertexUvs;
  5913. const hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5914. const hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5915. // morphs
  5916. const morphTargets = geometry.morphTargets;
  5917. const morphTargetsLength = morphTargets.length;
  5918. let morphTargetsPosition;
  5919. if ( morphTargetsLength > 0 ) {
  5920. morphTargetsPosition = [];
  5921. for ( let i = 0; i < morphTargetsLength; i ++ ) {
  5922. morphTargetsPosition[ i ] = {
  5923. name: morphTargets[ i ].name,
  5924. data: []
  5925. };
  5926. }
  5927. this.morphTargets.position = morphTargetsPosition;
  5928. }
  5929. const morphNormals = geometry.morphNormals;
  5930. const morphNormalsLength = morphNormals.length;
  5931. let morphTargetsNormal;
  5932. if ( morphNormalsLength > 0 ) {
  5933. morphTargetsNormal = [];
  5934. for ( let i = 0; i < morphNormalsLength; i ++ ) {
  5935. morphTargetsNormal[ i ] = {
  5936. name: morphNormals[ i ].name,
  5937. data: []
  5938. };
  5939. }
  5940. this.morphTargets.normal = morphTargetsNormal;
  5941. }
  5942. // skins
  5943. const skinIndices = geometry.skinIndices;
  5944. const skinWeights = geometry.skinWeights;
  5945. const hasSkinIndices = skinIndices.length === vertices.length;
  5946. const hasSkinWeights = skinWeights.length === vertices.length;
  5947. //
  5948. if ( vertices.length > 0 && faces.length === 0 ) {
  5949. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5950. }
  5951. for ( let i = 0; i < faces.length; i ++ ) {
  5952. const face = faces[ i ];
  5953. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5954. const vertexNormals = face.vertexNormals;
  5955. if ( vertexNormals.length === 3 ) {
  5956. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5957. } else {
  5958. const normal = face.normal;
  5959. this.normals.push( normal, normal, normal );
  5960. }
  5961. const vertexColors = face.vertexColors;
  5962. if ( vertexColors.length === 3 ) {
  5963. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5964. } else {
  5965. const color = face.color;
  5966. this.colors.push( color, color, color );
  5967. }
  5968. if ( hasFaceVertexUv === true ) {
  5969. const vertexUvs = faceVertexUvs[ 0 ][ i ];
  5970. if ( vertexUvs !== undefined ) {
  5971. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5972. } else {
  5973. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5974. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5975. }
  5976. }
  5977. if ( hasFaceVertexUv2 === true ) {
  5978. const vertexUvs = faceVertexUvs[ 1 ][ i ];
  5979. if ( vertexUvs !== undefined ) {
  5980. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5981. } else {
  5982. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5983. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5984. }
  5985. }
  5986. // morphs
  5987. for ( let j = 0; j < morphTargetsLength; j ++ ) {
  5988. const morphTarget = morphTargets[ j ].vertices;
  5989. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5990. }
  5991. for ( let j = 0; j < morphNormalsLength; j ++ ) {
  5992. const morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5993. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5994. }
  5995. // skins
  5996. if ( hasSkinIndices ) {
  5997. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5998. }
  5999. if ( hasSkinWeights ) {
  6000. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6001. }
  6002. }
  6003. this.computeGroups( geometry );
  6004. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6005. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6006. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6007. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6008. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6009. if ( geometry.boundingSphere !== null ) {
  6010. this.boundingSphere = geometry.boundingSphere.clone();
  6011. }
  6012. if ( geometry.boundingBox !== null ) {
  6013. this.boundingBox = geometry.boundingBox.clone();
  6014. }
  6015. return this;
  6016. }
  6017. } );
  6018. /**
  6019. * @author mrdoob / http://mrdoob.com/
  6020. */
  6021. function arrayMax( array ) {
  6022. if ( array.length === 0 ) return - Infinity;
  6023. let max = array[ 0 ];
  6024. for ( let i = 1, l = array.length; i < l; ++ i ) {
  6025. if ( array[ i ] > max ) max = array[ i ];
  6026. }
  6027. return max;
  6028. }
  6029. /**
  6030. * @author alteredq / http://alteredqualia.com/
  6031. * @author mrdoob / http://mrdoob.com/
  6032. */
  6033. let _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6034. const _m1$2 = new Matrix4();
  6035. const _obj = new Object3D();
  6036. const _offset = new Vector3();
  6037. const _box$2 = new Box3();
  6038. const _boxMorphTargets = new Box3();
  6039. const _vector$4 = new Vector3();
  6040. function BufferGeometry() {
  6041. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  6042. this.uuid = MathUtils.generateUUID();
  6043. this.name = '';
  6044. this.type = 'BufferGeometry';
  6045. this.index = null;
  6046. this.attributes = {};
  6047. this.morphAttributes = {};
  6048. this.morphTargetsRelative = false;
  6049. this.groups = [];
  6050. this.boundingBox = null;
  6051. this.boundingSphere = null;
  6052. this.drawRange = { start: 0, count: Infinity };
  6053. this.userData = {};
  6054. }
  6055. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6056. constructor: BufferGeometry,
  6057. isBufferGeometry: true,
  6058. getIndex: function () {
  6059. return this.index;
  6060. },
  6061. setIndex: function ( index ) {
  6062. if ( Array.isArray( index ) ) {
  6063. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6064. } else {
  6065. this.index = index;
  6066. }
  6067. },
  6068. getAttribute: function ( name ) {
  6069. return this.attributes[ name ];
  6070. },
  6071. setAttribute: function ( name, attribute ) {
  6072. this.attributes[ name ] = attribute;
  6073. return this;
  6074. },
  6075. deleteAttribute: function ( name ) {
  6076. delete this.attributes[ name ];
  6077. return this;
  6078. },
  6079. addGroup: function ( start, count, materialIndex ) {
  6080. this.groups.push( {
  6081. start: start,
  6082. count: count,
  6083. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6084. } );
  6085. },
  6086. clearGroups: function () {
  6087. this.groups = [];
  6088. },
  6089. setDrawRange: function ( start, count ) {
  6090. this.drawRange.start = start;
  6091. this.drawRange.count = count;
  6092. },
  6093. applyMatrix4: function ( matrix ) {
  6094. const position = this.attributes.position;
  6095. if ( position !== undefined ) {
  6096. position.applyMatrix4( matrix );
  6097. position.needsUpdate = true;
  6098. }
  6099. const normal = this.attributes.normal;
  6100. if ( normal !== undefined ) {
  6101. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6102. normal.applyNormalMatrix( normalMatrix );
  6103. normal.needsUpdate = true;
  6104. }
  6105. const tangent = this.attributes.tangent;
  6106. if ( tangent !== undefined ) {
  6107. tangent.transformDirection( matrix );
  6108. tangent.needsUpdate = true;
  6109. }
  6110. if ( this.boundingBox !== null ) {
  6111. this.computeBoundingBox();
  6112. }
  6113. if ( this.boundingSphere !== null ) {
  6114. this.computeBoundingSphere();
  6115. }
  6116. return this;
  6117. },
  6118. rotateX: function ( angle ) {
  6119. // rotate geometry around world x-axis
  6120. _m1$2.makeRotationX( angle );
  6121. this.applyMatrix4( _m1$2 );
  6122. return this;
  6123. },
  6124. rotateY: function ( angle ) {
  6125. // rotate geometry around world y-axis
  6126. _m1$2.makeRotationY( angle );
  6127. this.applyMatrix4( _m1$2 );
  6128. return this;
  6129. },
  6130. rotateZ: function ( angle ) {
  6131. // rotate geometry around world z-axis
  6132. _m1$2.makeRotationZ( angle );
  6133. this.applyMatrix4( _m1$2 );
  6134. return this;
  6135. },
  6136. translate: function ( x, y, z ) {
  6137. // translate geometry
  6138. _m1$2.makeTranslation( x, y, z );
  6139. this.applyMatrix4( _m1$2 );
  6140. return this;
  6141. },
  6142. scale: function ( x, y, z ) {
  6143. // scale geometry
  6144. _m1$2.makeScale( x, y, z );
  6145. this.applyMatrix4( _m1$2 );
  6146. return this;
  6147. },
  6148. lookAt: function ( vector ) {
  6149. _obj.lookAt( vector );
  6150. _obj.updateMatrix();
  6151. this.applyMatrix4( _obj.matrix );
  6152. return this;
  6153. },
  6154. center: function () {
  6155. this.computeBoundingBox();
  6156. this.boundingBox.getCenter( _offset ).negate();
  6157. this.translate( _offset.x, _offset.y, _offset.z );
  6158. return this;
  6159. },
  6160. setFromObject: function ( object ) {
  6161. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6162. const geometry = object.geometry;
  6163. if ( object.isPoints || object.isLine ) {
  6164. const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6165. const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6166. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6167. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6168. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6169. const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6170. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6171. }
  6172. if ( geometry.boundingSphere !== null ) {
  6173. this.boundingSphere = geometry.boundingSphere.clone();
  6174. }
  6175. if ( geometry.boundingBox !== null ) {
  6176. this.boundingBox = geometry.boundingBox.clone();
  6177. }
  6178. } else if ( object.isMesh ) {
  6179. if ( geometry && geometry.isGeometry ) {
  6180. this.fromGeometry( geometry );
  6181. }
  6182. }
  6183. return this;
  6184. },
  6185. setFromPoints: function ( points ) {
  6186. const position = [];
  6187. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6188. const point = points[ i ];
  6189. position.push( point.x, point.y, point.z || 0 );
  6190. }
  6191. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6192. return this;
  6193. },
  6194. updateFromObject: function ( object ) {
  6195. let geometry = object.geometry;
  6196. if ( object.isMesh ) {
  6197. let direct = geometry.__directGeometry;
  6198. if ( geometry.elementsNeedUpdate === true ) {
  6199. direct = undefined;
  6200. geometry.elementsNeedUpdate = false;
  6201. }
  6202. if ( direct === undefined ) {
  6203. return this.fromGeometry( geometry );
  6204. }
  6205. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6206. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6207. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6208. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6209. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6210. geometry.verticesNeedUpdate = false;
  6211. geometry.normalsNeedUpdate = false;
  6212. geometry.colorsNeedUpdate = false;
  6213. geometry.uvsNeedUpdate = false;
  6214. geometry.groupsNeedUpdate = false;
  6215. geometry = direct;
  6216. }
  6217. if ( geometry.verticesNeedUpdate === true ) {
  6218. const attribute = this.attributes.position;
  6219. if ( attribute !== undefined ) {
  6220. attribute.copyVector3sArray( geometry.vertices );
  6221. attribute.needsUpdate = true;
  6222. }
  6223. geometry.verticesNeedUpdate = false;
  6224. }
  6225. if ( geometry.normalsNeedUpdate === true ) {
  6226. const attribute = this.attributes.normal;
  6227. if ( attribute !== undefined ) {
  6228. attribute.copyVector3sArray( geometry.normals );
  6229. attribute.needsUpdate = true;
  6230. }
  6231. geometry.normalsNeedUpdate = false;
  6232. }
  6233. if ( geometry.colorsNeedUpdate === true ) {
  6234. const attribute = this.attributes.color;
  6235. if ( attribute !== undefined ) {
  6236. attribute.copyColorsArray( geometry.colors );
  6237. attribute.needsUpdate = true;
  6238. }
  6239. geometry.colorsNeedUpdate = false;
  6240. }
  6241. if ( geometry.uvsNeedUpdate ) {
  6242. const attribute = this.attributes.uv;
  6243. if ( attribute !== undefined ) {
  6244. attribute.copyVector2sArray( geometry.uvs );
  6245. attribute.needsUpdate = true;
  6246. }
  6247. geometry.uvsNeedUpdate = false;
  6248. }
  6249. if ( geometry.lineDistancesNeedUpdate ) {
  6250. const attribute = this.attributes.lineDistance;
  6251. if ( attribute !== undefined ) {
  6252. attribute.copyArray( geometry.lineDistances );
  6253. attribute.needsUpdate = true;
  6254. }
  6255. geometry.lineDistancesNeedUpdate = false;
  6256. }
  6257. if ( geometry.groupsNeedUpdate ) {
  6258. geometry.computeGroups( object.geometry );
  6259. this.groups = geometry.groups;
  6260. geometry.groupsNeedUpdate = false;
  6261. }
  6262. return this;
  6263. },
  6264. fromGeometry: function ( geometry ) {
  6265. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6266. return this.fromDirectGeometry( geometry.__directGeometry );
  6267. },
  6268. fromDirectGeometry: function ( geometry ) {
  6269. const positions = new Float32Array( geometry.vertices.length * 3 );
  6270. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6271. if ( geometry.normals.length > 0 ) {
  6272. const normals = new Float32Array( geometry.normals.length * 3 );
  6273. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6274. }
  6275. if ( geometry.colors.length > 0 ) {
  6276. const colors = new Float32Array( geometry.colors.length * 3 );
  6277. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6278. }
  6279. if ( geometry.uvs.length > 0 ) {
  6280. const uvs = new Float32Array( geometry.uvs.length * 2 );
  6281. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6282. }
  6283. if ( geometry.uvs2.length > 0 ) {
  6284. const uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6285. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6286. }
  6287. // groups
  6288. this.groups = geometry.groups;
  6289. // morphs
  6290. for ( const name in geometry.morphTargets ) {
  6291. const array = [];
  6292. const morphTargets = geometry.morphTargets[ name ];
  6293. for ( let i = 0, l = morphTargets.length; i < l; i ++ ) {
  6294. const morphTarget = morphTargets[ i ];
  6295. const attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6296. attribute.name = morphTarget.name;
  6297. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6298. }
  6299. this.morphAttributes[ name ] = array;
  6300. }
  6301. // skinning
  6302. if ( geometry.skinIndices.length > 0 ) {
  6303. const skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6304. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6305. }
  6306. if ( geometry.skinWeights.length > 0 ) {
  6307. const skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6308. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6309. }
  6310. //
  6311. if ( geometry.boundingSphere !== null ) {
  6312. this.boundingSphere = geometry.boundingSphere.clone();
  6313. }
  6314. if ( geometry.boundingBox !== null ) {
  6315. this.boundingBox = geometry.boundingBox.clone();
  6316. }
  6317. return this;
  6318. },
  6319. computeBoundingBox: function () {
  6320. if ( this.boundingBox === null ) {
  6321. this.boundingBox = new Box3();
  6322. }
  6323. const position = this.attributes.position;
  6324. const morphAttributesPosition = this.morphAttributes.position;
  6325. if ( position !== undefined ) {
  6326. this.boundingBox.setFromBufferAttribute( position );
  6327. // process morph attributes if present
  6328. if ( morphAttributesPosition ) {
  6329. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6330. const morphAttribute = morphAttributesPosition[ i ];
  6331. _box$2.setFromBufferAttribute( morphAttribute );
  6332. if ( this.morphTargetsRelative ) {
  6333. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6334. this.boundingBox.expandByPoint( _vector$4 );
  6335. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6336. this.boundingBox.expandByPoint( _vector$4 );
  6337. } else {
  6338. this.boundingBox.expandByPoint( _box$2.min );
  6339. this.boundingBox.expandByPoint( _box$2.max );
  6340. }
  6341. }
  6342. }
  6343. } else {
  6344. this.boundingBox.makeEmpty();
  6345. }
  6346. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6347. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6348. }
  6349. },
  6350. computeBoundingSphere: function () {
  6351. if ( this.boundingSphere === null ) {
  6352. this.boundingSphere = new Sphere();
  6353. }
  6354. const position = this.attributes.position;
  6355. const morphAttributesPosition = this.morphAttributes.position;
  6356. if ( position ) {
  6357. // first, find the center of the bounding sphere
  6358. const center = this.boundingSphere.center;
  6359. _box$2.setFromBufferAttribute( position );
  6360. // process morph attributes if present
  6361. if ( morphAttributesPosition ) {
  6362. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6363. const morphAttribute = morphAttributesPosition[ i ];
  6364. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6365. if ( this.morphTargetsRelative ) {
  6366. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6367. _box$2.expandByPoint( _vector$4 );
  6368. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6369. _box$2.expandByPoint( _vector$4 );
  6370. } else {
  6371. _box$2.expandByPoint( _boxMorphTargets.min );
  6372. _box$2.expandByPoint( _boxMorphTargets.max );
  6373. }
  6374. }
  6375. }
  6376. _box$2.getCenter( center );
  6377. // second, try to find a boundingSphere with a radius smaller than the
  6378. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6379. let maxRadiusSq = 0;
  6380. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6381. _vector$4.fromBufferAttribute( position, i );
  6382. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6383. }
  6384. // process morph attributes if present
  6385. if ( morphAttributesPosition ) {
  6386. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6387. const morphAttribute = morphAttributesPosition[ i ];
  6388. const morphTargetsRelative = this.morphTargetsRelative;
  6389. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6390. _vector$4.fromBufferAttribute( morphAttribute, j );
  6391. if ( morphTargetsRelative ) {
  6392. _offset.fromBufferAttribute( position, j );
  6393. _vector$4.add( _offset );
  6394. }
  6395. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6396. }
  6397. }
  6398. }
  6399. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6400. if ( isNaN( this.boundingSphere.radius ) ) {
  6401. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6402. }
  6403. }
  6404. },
  6405. computeFaceNormals: function () {
  6406. // backwards compatibility
  6407. },
  6408. computeVertexNormals: function () {
  6409. const index = this.index;
  6410. const positionAttribute = this.getAttribute( 'position' );
  6411. if ( positionAttribute !== undefined ) {
  6412. let normalAttribute = this.getAttribute( 'normal' );
  6413. if ( normalAttribute === undefined ) {
  6414. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6415. this.setAttribute( 'normal', normalAttribute );
  6416. } else {
  6417. // reset existing normals to zero
  6418. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6419. normalAttribute.setXYZ( i, 0, 0, 0 );
  6420. }
  6421. }
  6422. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6423. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6424. const cb = new Vector3(), ab = new Vector3();
  6425. // indexed elements
  6426. if ( index ) {
  6427. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6428. const vA = index.getX( i + 0 );
  6429. const vB = index.getX( i + 1 );
  6430. const vC = index.getX( i + 2 );
  6431. pA.fromBufferAttribute( positionAttribute, vA );
  6432. pB.fromBufferAttribute( positionAttribute, vB );
  6433. pC.fromBufferAttribute( positionAttribute, vC );
  6434. cb.subVectors( pC, pB );
  6435. ab.subVectors( pA, pB );
  6436. cb.cross( ab );
  6437. nA.fromBufferAttribute( normalAttribute, vA );
  6438. nB.fromBufferAttribute( normalAttribute, vB );
  6439. nC.fromBufferAttribute( normalAttribute, vC );
  6440. nA.add( cb );
  6441. nB.add( cb );
  6442. nC.add( cb );
  6443. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6444. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6445. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6446. }
  6447. } else {
  6448. // non-indexed elements (unconnected triangle soup)
  6449. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6450. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6451. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6452. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6453. cb.subVectors( pC, pB );
  6454. ab.subVectors( pA, pB );
  6455. cb.cross( ab );
  6456. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6457. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6458. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6459. }
  6460. }
  6461. this.normalizeNormals();
  6462. normalAttribute.needsUpdate = true;
  6463. }
  6464. },
  6465. merge: function ( geometry, offset ) {
  6466. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6467. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6468. return;
  6469. }
  6470. if ( offset === undefined ) {
  6471. offset = 0;
  6472. console.warn(
  6473. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6474. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6475. );
  6476. }
  6477. const attributes = this.attributes;
  6478. for ( const key in attributes ) {
  6479. if ( geometry.attributes[ key ] === undefined ) continue;
  6480. const attribute1 = attributes[ key ];
  6481. const attributeArray1 = attribute1.array;
  6482. const attribute2 = geometry.attributes[ key ];
  6483. const attributeArray2 = attribute2.array;
  6484. const attributeOffset = attribute2.itemSize * offset;
  6485. const length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6486. for ( let i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6487. attributeArray1[ j ] = attributeArray2[ i ];
  6488. }
  6489. }
  6490. return this;
  6491. },
  6492. normalizeNormals: function () {
  6493. const normals = this.attributes.normal;
  6494. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6495. _vector$4.fromBufferAttribute( normals, i );
  6496. _vector$4.normalize();
  6497. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6498. }
  6499. },
  6500. toNonIndexed: function () {
  6501. function convertBufferAttribute( attribute, indices ) {
  6502. const array = attribute.array;
  6503. const itemSize = attribute.itemSize;
  6504. const normalized = attribute.normalized;
  6505. const array2 = new array.constructor( indices.length * itemSize );
  6506. let index = 0, index2 = 0;
  6507. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6508. index = indices[ i ] * itemSize;
  6509. for ( let j = 0; j < itemSize; j ++ ) {
  6510. array2[ index2 ++ ] = array[ index ++ ];
  6511. }
  6512. }
  6513. return new BufferAttribute( array2, itemSize, normalized );
  6514. }
  6515. //
  6516. if ( this.index === null ) {
  6517. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6518. return this;
  6519. }
  6520. const geometry2 = new BufferGeometry();
  6521. const indices = this.index.array;
  6522. const attributes = this.attributes;
  6523. // attributes
  6524. for ( const name in attributes ) {
  6525. const attribute = attributes[ name ];
  6526. const newAttribute = convertBufferAttribute( attribute, indices );
  6527. geometry2.setAttribute( name, newAttribute );
  6528. }
  6529. // morph attributes
  6530. const morphAttributes = this.morphAttributes;
  6531. for ( const name in morphAttributes ) {
  6532. const morphArray = [];
  6533. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6534. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6535. const attribute = morphAttribute[ i ];
  6536. const newAttribute = convertBufferAttribute( attribute, indices );
  6537. morphArray.push( newAttribute );
  6538. }
  6539. geometry2.morphAttributes[ name ] = morphArray;
  6540. }
  6541. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6542. // groups
  6543. const groups = this.groups;
  6544. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6545. const group = groups[ i ];
  6546. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6547. }
  6548. return geometry2;
  6549. },
  6550. toJSON: function () {
  6551. const data = {
  6552. metadata: {
  6553. version: 4.5,
  6554. type: 'BufferGeometry',
  6555. generator: 'BufferGeometry.toJSON'
  6556. }
  6557. };
  6558. // standard BufferGeometry serialization
  6559. data.uuid = this.uuid;
  6560. data.type = this.type;
  6561. if ( this.name !== '' ) data.name = this.name;
  6562. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6563. if ( this.parameters !== undefined ) {
  6564. const parameters = this.parameters;
  6565. for ( const key in parameters ) {
  6566. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6567. }
  6568. return data;
  6569. }
  6570. data.data = { attributes: {} };
  6571. const index = this.index;
  6572. if ( index !== null ) {
  6573. data.data.index = {
  6574. type: index.array.constructor.name,
  6575. array: Array.prototype.slice.call( index.array )
  6576. };
  6577. }
  6578. const attributes = this.attributes;
  6579. for ( const key in attributes ) {
  6580. const attribute = attributes[ key ];
  6581. const attributeData = attribute.toJSON( data.data );
  6582. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6583. data.data.attributes[ key ] = attributeData;
  6584. }
  6585. const morphAttributes = {};
  6586. let hasMorphAttributes = false;
  6587. for ( const key in this.morphAttributes ) {
  6588. const attributeArray = this.morphAttributes[ key ];
  6589. const array = [];
  6590. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6591. const attribute = attributeArray[ i ];
  6592. const attributeData = attribute.toJSON( data.data );
  6593. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6594. array.push( attributeData );
  6595. }
  6596. if ( array.length > 0 ) {
  6597. morphAttributes[ key ] = array;
  6598. hasMorphAttributes = true;
  6599. }
  6600. }
  6601. if ( hasMorphAttributes ) {
  6602. data.data.morphAttributes = morphAttributes;
  6603. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6604. }
  6605. const groups = this.groups;
  6606. if ( groups.length > 0 ) {
  6607. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6608. }
  6609. const boundingSphere = this.boundingSphere;
  6610. if ( boundingSphere !== null ) {
  6611. data.data.boundingSphere = {
  6612. center: boundingSphere.center.toArray(),
  6613. radius: boundingSphere.radius
  6614. };
  6615. }
  6616. return data;
  6617. },
  6618. clone: function () {
  6619. /*
  6620. // Handle primitives
  6621. const parameters = this.parameters;
  6622. if ( parameters !== undefined ) {
  6623. const values = [];
  6624. for ( const key in parameters ) {
  6625. values.push( parameters[ key ] );
  6626. }
  6627. const geometry = Object.create( this.constructor.prototype );
  6628. this.constructor.apply( geometry, values );
  6629. return geometry;
  6630. }
  6631. return new this.constructor().copy( this );
  6632. */
  6633. return new BufferGeometry().copy( this );
  6634. },
  6635. copy: function ( source ) {
  6636. // reset
  6637. this.index = null;
  6638. this.attributes = {};
  6639. this.morphAttributes = {};
  6640. this.groups = [];
  6641. this.boundingBox = null;
  6642. this.boundingSphere = null;
  6643. // used for storing cloned, shared data
  6644. const data = {};
  6645. // name
  6646. this.name = source.name;
  6647. // index
  6648. const index = source.index;
  6649. if ( index !== null ) {
  6650. this.setIndex( index.clone( data ) );
  6651. }
  6652. // attributes
  6653. const attributes = source.attributes;
  6654. for ( const name in attributes ) {
  6655. const attribute = attributes[ name ];
  6656. this.setAttribute( name, attribute.clone( data ) );
  6657. }
  6658. // morph attributes
  6659. const morphAttributes = source.morphAttributes;
  6660. for ( const name in morphAttributes ) {
  6661. const array = [];
  6662. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6663. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6664. array.push( morphAttribute[ i ].clone( data ) );
  6665. }
  6666. this.morphAttributes[ name ] = array;
  6667. }
  6668. this.morphTargetsRelative = source.morphTargetsRelative;
  6669. // groups
  6670. const groups = source.groups;
  6671. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6672. const group = groups[ i ];
  6673. this.addGroup( group.start, group.count, group.materialIndex );
  6674. }
  6675. // bounding box
  6676. const boundingBox = source.boundingBox;
  6677. if ( boundingBox !== null ) {
  6678. this.boundingBox = boundingBox.clone();
  6679. }
  6680. // bounding sphere
  6681. const boundingSphere = source.boundingSphere;
  6682. if ( boundingSphere !== null ) {
  6683. this.boundingSphere = boundingSphere.clone();
  6684. }
  6685. // draw range
  6686. this.drawRange.start = source.drawRange.start;
  6687. this.drawRange.count = source.drawRange.count;
  6688. // user data
  6689. this.userData = source.userData;
  6690. return this;
  6691. },
  6692. dispose: function () {
  6693. this.dispatchEvent( { type: 'dispose' } );
  6694. }
  6695. } );
  6696. /**
  6697. * @author mrdoob / http://mrdoob.com/
  6698. * @author alteredq / http://alteredqualia.com/
  6699. * @author mikael emtinger / http://gomo.se/
  6700. * @author jonobr1 / http://jonobr1.com/
  6701. */
  6702. const _inverseMatrix = new Matrix4();
  6703. const _ray = new Ray();
  6704. const _sphere = new Sphere();
  6705. const _vA = new Vector3();
  6706. const _vB = new Vector3();
  6707. const _vC = new Vector3();
  6708. const _tempA = new Vector3();
  6709. const _tempB = new Vector3();
  6710. const _tempC = new Vector3();
  6711. const _morphA = new Vector3();
  6712. const _morphB = new Vector3();
  6713. const _morphC = new Vector3();
  6714. const _uvA = new Vector2();
  6715. const _uvB = new Vector2();
  6716. const _uvC = new Vector2();
  6717. const _intersectionPoint = new Vector3();
  6718. const _intersectionPointWorld = new Vector3();
  6719. function Mesh( geometry, material ) {
  6720. Object3D.call( this );
  6721. this.type = 'Mesh';
  6722. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6723. this.material = material !== undefined ? material : new MeshBasicMaterial();
  6724. this.updateMorphTargets();
  6725. }
  6726. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6727. constructor: Mesh,
  6728. isMesh: true,
  6729. copy: function ( source ) {
  6730. Object3D.prototype.copy.call( this, source );
  6731. if ( source.morphTargetInfluences !== undefined ) {
  6732. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6733. }
  6734. if ( source.morphTargetDictionary !== undefined ) {
  6735. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6736. }
  6737. this.material = source.material;
  6738. this.geometry = source.geometry;
  6739. return this;
  6740. },
  6741. updateMorphTargets: function () {
  6742. const geometry = this.geometry;
  6743. if ( geometry.isBufferGeometry ) {
  6744. const morphAttributes = geometry.morphAttributes;
  6745. const keys = Object.keys( morphAttributes );
  6746. if ( keys.length > 0 ) {
  6747. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6748. if ( morphAttribute !== undefined ) {
  6749. this.morphTargetInfluences = [];
  6750. this.morphTargetDictionary = {};
  6751. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6752. const name = morphAttribute[ m ].name || String( m );
  6753. this.morphTargetInfluences.push( 0 );
  6754. this.morphTargetDictionary[ name ] = m;
  6755. }
  6756. }
  6757. }
  6758. } else {
  6759. const morphTargets = geometry.morphTargets;
  6760. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6761. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6762. }
  6763. }
  6764. },
  6765. raycast: function ( raycaster, intersects ) {
  6766. const geometry = this.geometry;
  6767. const material = this.material;
  6768. const matrixWorld = this.matrixWorld;
  6769. if ( material === undefined ) return;
  6770. // Checking boundingSphere distance to ray
  6771. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6772. _sphere.copy( geometry.boundingSphere );
  6773. _sphere.applyMatrix4( matrixWorld );
  6774. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6775. //
  6776. _inverseMatrix.getInverse( matrixWorld );
  6777. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6778. // Check boundingBox before continuing
  6779. if ( geometry.boundingBox !== null ) {
  6780. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6781. }
  6782. let intersection;
  6783. if ( geometry.isBufferGeometry ) {
  6784. const index = geometry.index;
  6785. const position = geometry.attributes.position;
  6786. const morphPosition = geometry.morphAttributes.position;
  6787. const morphTargetsRelative = geometry.morphTargetsRelative;
  6788. const uv = geometry.attributes.uv;
  6789. const uv2 = geometry.attributes.uv2;
  6790. const groups = geometry.groups;
  6791. const drawRange = geometry.drawRange;
  6792. if ( index !== null ) {
  6793. // indexed buffer geometry
  6794. if ( Array.isArray( material ) ) {
  6795. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6796. const group = groups[ i ];
  6797. const groupMaterial = material[ group.materialIndex ];
  6798. const start = Math.max( group.start, drawRange.start );
  6799. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6800. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6801. const a = index.getX( j );
  6802. const b = index.getX( j + 1 );
  6803. const c = index.getX( j + 2 );
  6804. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6805. if ( intersection ) {
  6806. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6807. intersection.face.materialIndex = group.materialIndex;
  6808. intersects.push( intersection );
  6809. }
  6810. }
  6811. }
  6812. } else {
  6813. const start = Math.max( 0, drawRange.start );
  6814. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6815. for ( let i = start, il = end; i < il; i += 3 ) {
  6816. const a = index.getX( i );
  6817. const b = index.getX( i + 1 );
  6818. const c = index.getX( i + 2 );
  6819. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6820. if ( intersection ) {
  6821. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6822. intersects.push( intersection );
  6823. }
  6824. }
  6825. }
  6826. } else if ( position !== undefined ) {
  6827. // non-indexed buffer geometry
  6828. if ( Array.isArray( material ) ) {
  6829. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6830. const group = groups[ i ];
  6831. const groupMaterial = material[ group.materialIndex ];
  6832. const start = Math.max( group.start, drawRange.start );
  6833. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6834. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6835. const a = j;
  6836. const b = j + 1;
  6837. const c = j + 2;
  6838. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6839. if ( intersection ) {
  6840. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6841. intersection.face.materialIndex = group.materialIndex;
  6842. intersects.push( intersection );
  6843. }
  6844. }
  6845. }
  6846. } else {
  6847. const start = Math.max( 0, drawRange.start );
  6848. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6849. for ( let i = start, il = end; i < il; i += 3 ) {
  6850. const a = i;
  6851. const b = i + 1;
  6852. const c = i + 2;
  6853. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6854. if ( intersection ) {
  6855. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6856. intersects.push( intersection );
  6857. }
  6858. }
  6859. }
  6860. }
  6861. } else if ( geometry.isGeometry ) {
  6862. const isMultiMaterial = Array.isArray( material );
  6863. const vertices = geometry.vertices;
  6864. const faces = geometry.faces;
  6865. let uvs;
  6866. const faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6867. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6868. for ( let f = 0, fl = faces.length; f < fl; f ++ ) {
  6869. const face = faces[ f ];
  6870. const faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6871. if ( faceMaterial === undefined ) continue;
  6872. const fvA = vertices[ face.a ];
  6873. const fvB = vertices[ face.b ];
  6874. const fvC = vertices[ face.c ];
  6875. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6876. if ( intersection ) {
  6877. if ( uvs && uvs[ f ] ) {
  6878. const uvs_f = uvs[ f ];
  6879. _uvA.copy( uvs_f[ 0 ] );
  6880. _uvB.copy( uvs_f[ 1 ] );
  6881. _uvC.copy( uvs_f[ 2 ] );
  6882. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6883. }
  6884. intersection.face = face;
  6885. intersection.faceIndex = f;
  6886. intersects.push( intersection );
  6887. }
  6888. }
  6889. }
  6890. }
  6891. } );
  6892. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6893. let intersect;
  6894. if ( material.side === BackSide ) {
  6895. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6896. } else {
  6897. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6898. }
  6899. if ( intersect === null ) return null;
  6900. _intersectionPointWorld.copy( point );
  6901. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6902. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6903. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6904. return {
  6905. distance: distance,
  6906. point: _intersectionPointWorld.clone(),
  6907. object: object
  6908. };
  6909. }
  6910. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6911. _vA.fromBufferAttribute( position, a );
  6912. _vB.fromBufferAttribute( position, b );
  6913. _vC.fromBufferAttribute( position, c );
  6914. const morphInfluences = object.morphTargetInfluences;
  6915. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6916. _morphA.set( 0, 0, 0 );
  6917. _morphB.set( 0, 0, 0 );
  6918. _morphC.set( 0, 0, 0 );
  6919. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  6920. const influence = morphInfluences[ i ];
  6921. const morphAttribute = morphPosition[ i ];
  6922. if ( influence === 0 ) continue;
  6923. _tempA.fromBufferAttribute( morphAttribute, a );
  6924. _tempB.fromBufferAttribute( morphAttribute, b );
  6925. _tempC.fromBufferAttribute( morphAttribute, c );
  6926. if ( morphTargetsRelative ) {
  6927. _morphA.addScaledVector( _tempA, influence );
  6928. _morphB.addScaledVector( _tempB, influence );
  6929. _morphC.addScaledVector( _tempC, influence );
  6930. } else {
  6931. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6932. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6933. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6934. }
  6935. }
  6936. _vA.add( _morphA );
  6937. _vB.add( _morphB );
  6938. _vC.add( _morphC );
  6939. }
  6940. if ( object.isSkinnedMesh ) {
  6941. object.boneTransform( a, _vA );
  6942. object.boneTransform( b, _vB );
  6943. object.boneTransform( c, _vC );
  6944. }
  6945. const intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6946. if ( intersection ) {
  6947. if ( uv ) {
  6948. _uvA.fromBufferAttribute( uv, a );
  6949. _uvB.fromBufferAttribute( uv, b );
  6950. _uvC.fromBufferAttribute( uv, c );
  6951. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6952. }
  6953. if ( uv2 ) {
  6954. _uvA.fromBufferAttribute( uv2, a );
  6955. _uvB.fromBufferAttribute( uv2, b );
  6956. _uvC.fromBufferAttribute( uv2, c );
  6957. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6958. }
  6959. const face = new Face3( a, b, c );
  6960. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6961. intersection.face = face;
  6962. }
  6963. return intersection;
  6964. }
  6965. /**
  6966. * @author mrdoob / http://mrdoob.com/
  6967. * @author kile / http://kile.stravaganza.org/
  6968. * @author alteredq / http://alteredqualia.com/
  6969. * @author mikael emtinger / http://gomo.se/
  6970. * @author zz85 / http://www.lab4games.net/zz85/blog
  6971. * @author bhouston / http://clara.io
  6972. */
  6973. let _geometryId = 0; // Geometry uses even numbers as Id
  6974. const _m1$3 = new Matrix4();
  6975. const _obj$1 = new Object3D();
  6976. const _offset$1 = new Vector3();
  6977. function Geometry() {
  6978. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  6979. this.uuid = MathUtils.generateUUID();
  6980. this.name = '';
  6981. this.type = 'Geometry';
  6982. this.vertices = [];
  6983. this.colors = [];
  6984. this.faces = [];
  6985. this.faceVertexUvs = [[]];
  6986. this.morphTargets = [];
  6987. this.morphNormals = [];
  6988. this.skinWeights = [];
  6989. this.skinIndices = [];
  6990. this.lineDistances = [];
  6991. this.boundingBox = null;
  6992. this.boundingSphere = null;
  6993. // update flags
  6994. this.elementsNeedUpdate = false;
  6995. this.verticesNeedUpdate = false;
  6996. this.uvsNeedUpdate = false;
  6997. this.normalsNeedUpdate = false;
  6998. this.colorsNeedUpdate = false;
  6999. this.lineDistancesNeedUpdate = false;
  7000. this.groupsNeedUpdate = false;
  7001. }
  7002. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7003. constructor: Geometry,
  7004. isGeometry: true,
  7005. applyMatrix4: function ( matrix ) {
  7006. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7007. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  7008. const vertex = this.vertices[ i ];
  7009. vertex.applyMatrix4( matrix );
  7010. }
  7011. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  7012. const face = this.faces[ i ];
  7013. face.normal.applyMatrix3( normalMatrix ).normalize();
  7014. for ( let j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  7015. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  7016. }
  7017. }
  7018. if ( this.boundingBox !== null ) {
  7019. this.computeBoundingBox();
  7020. }
  7021. if ( this.boundingSphere !== null ) {
  7022. this.computeBoundingSphere();
  7023. }
  7024. this.verticesNeedUpdate = true;
  7025. this.normalsNeedUpdate = true;
  7026. return this;
  7027. },
  7028. rotateX: function ( angle ) {
  7029. // rotate geometry around world x-axis
  7030. _m1$3.makeRotationX( angle );
  7031. this.applyMatrix4( _m1$3 );
  7032. return this;
  7033. },
  7034. rotateY: function ( angle ) {
  7035. // rotate geometry around world y-axis
  7036. _m1$3.makeRotationY( angle );
  7037. this.applyMatrix4( _m1$3 );
  7038. return this;
  7039. },
  7040. rotateZ: function ( angle ) {
  7041. // rotate geometry around world z-axis
  7042. _m1$3.makeRotationZ( angle );
  7043. this.applyMatrix4( _m1$3 );
  7044. return this;
  7045. },
  7046. translate: function ( x, y, z ) {
  7047. // translate geometry
  7048. _m1$3.makeTranslation( x, y, z );
  7049. this.applyMatrix4( _m1$3 );
  7050. return this;
  7051. },
  7052. scale: function ( x, y, z ) {
  7053. // scale geometry
  7054. _m1$3.makeScale( x, y, z );
  7055. this.applyMatrix4( _m1$3 );
  7056. return this;
  7057. },
  7058. lookAt: function ( vector ) {
  7059. _obj$1.lookAt( vector );
  7060. _obj$1.updateMatrix();
  7061. this.applyMatrix4( _obj$1.matrix );
  7062. return this;
  7063. },
  7064. fromBufferGeometry: function ( geometry ) {
  7065. const scope = this;
  7066. const index = geometry.index !== null ? geometry.index : undefined;
  7067. const attributes = geometry.attributes;
  7068. if ( attributes.position === undefined ) {
  7069. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  7070. return this;
  7071. }
  7072. const position = attributes.position;
  7073. const normal = attributes.normal;
  7074. const color = attributes.color;
  7075. const uv = attributes.uv;
  7076. const uv2 = attributes.uv2;
  7077. if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  7078. for ( let i = 0; i < position.count; i ++ ) {
  7079. scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
  7080. if ( color !== undefined ) {
  7081. scope.colors.push( new Color().fromBufferAttribute( color, i ) );
  7082. }
  7083. }
  7084. function addFace( a, b, c, materialIndex ) {
  7085. const vertexColors = ( color === undefined ) ? [] : [
  7086. scope.colors[ a ].clone(),
  7087. scope.colors[ b ].clone(),
  7088. scope.colors[ c ].clone()
  7089. ];
  7090. const vertexNormals = ( normal === undefined ) ? [] : [
  7091. new Vector3().fromBufferAttribute( normal, a ),
  7092. new Vector3().fromBufferAttribute( normal, b ),
  7093. new Vector3().fromBufferAttribute( normal, c )
  7094. ];
  7095. const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7096. scope.faces.push( face );
  7097. if ( uv !== undefined ) {
  7098. scope.faceVertexUvs[ 0 ].push( [
  7099. new Vector2().fromBufferAttribute( uv, a ),
  7100. new Vector2().fromBufferAttribute( uv, b ),
  7101. new Vector2().fromBufferAttribute( uv, c )
  7102. ] );
  7103. }
  7104. if ( uv2 !== undefined ) {
  7105. scope.faceVertexUvs[ 1 ].push( [
  7106. new Vector2().fromBufferAttribute( uv2, a ),
  7107. new Vector2().fromBufferAttribute( uv2, b ),
  7108. new Vector2().fromBufferAttribute( uv2, c )
  7109. ] );
  7110. }
  7111. }
  7112. const groups = geometry.groups;
  7113. if ( groups.length > 0 ) {
  7114. for ( let i = 0; i < groups.length; i ++ ) {
  7115. const group = groups[ i ];
  7116. const start = group.start;
  7117. const count = group.count;
  7118. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  7119. if ( index !== undefined ) {
  7120. addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
  7121. } else {
  7122. addFace( j, j + 1, j + 2, group.materialIndex );
  7123. }
  7124. }
  7125. }
  7126. } else {
  7127. if ( index !== undefined ) {
  7128. for ( let i = 0; i < index.count; i += 3 ) {
  7129. addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
  7130. }
  7131. } else {
  7132. for ( let i = 0; i < position.count; i += 3 ) {
  7133. addFace( i, i + 1, i + 2 );
  7134. }
  7135. }
  7136. }
  7137. this.computeFaceNormals();
  7138. if ( geometry.boundingBox !== null ) {
  7139. this.boundingBox = geometry.boundingBox.clone();
  7140. }
  7141. if ( geometry.boundingSphere !== null ) {
  7142. this.boundingSphere = geometry.boundingSphere.clone();
  7143. }
  7144. return this;
  7145. },
  7146. center: function () {
  7147. this.computeBoundingBox();
  7148. this.boundingBox.getCenter( _offset$1 ).negate();
  7149. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  7150. return this;
  7151. },
  7152. normalize: function () {
  7153. this.computeBoundingSphere();
  7154. const center = this.boundingSphere.center;
  7155. const radius = this.boundingSphere.radius;
  7156. const s = radius === 0 ? 1 : 1.0 / radius;
  7157. const matrix = new Matrix4();
  7158. matrix.set(
  7159. s, 0, 0, - s * center.x,
  7160. 0, s, 0, - s * center.y,
  7161. 0, 0, s, - s * center.z,
  7162. 0, 0, 0, 1
  7163. );
  7164. this.applyMatrix4( matrix );
  7165. return this;
  7166. },
  7167. computeFaceNormals: function () {
  7168. const cb = new Vector3(), ab = new Vector3();
  7169. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7170. const face = this.faces[ f ];
  7171. const vA = this.vertices[ face.a ];
  7172. const vB = this.vertices[ face.b ];
  7173. const vC = this.vertices[ face.c ];
  7174. cb.subVectors( vC, vB );
  7175. ab.subVectors( vA, vB );
  7176. cb.cross( ab );
  7177. cb.normalize();
  7178. face.normal.copy( cb );
  7179. }
  7180. },
  7181. computeVertexNormals: function ( areaWeighted ) {
  7182. if ( areaWeighted === undefined ) areaWeighted = true;
  7183. const vertices = new Array( this.vertices.length );
  7184. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7185. vertices[ v ] = new Vector3();
  7186. }
  7187. if ( areaWeighted ) {
  7188. // vertex normals weighted by triangle areas
  7189. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7190. const cb = new Vector3(), ab = new Vector3();
  7191. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7192. const face = this.faces[ f ];
  7193. const vA = this.vertices[ face.a ];
  7194. const vB = this.vertices[ face.b ];
  7195. const vC = this.vertices[ face.c ];
  7196. cb.subVectors( vC, vB );
  7197. ab.subVectors( vA, vB );
  7198. cb.cross( ab );
  7199. vertices[ face.a ].add( cb );
  7200. vertices[ face.b ].add( cb );
  7201. vertices[ face.c ].add( cb );
  7202. }
  7203. } else {
  7204. this.computeFaceNormals();
  7205. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7206. const face = this.faces[ f ];
  7207. vertices[ face.a ].add( face.normal );
  7208. vertices[ face.b ].add( face.normal );
  7209. vertices[ face.c ].add( face.normal );
  7210. }
  7211. }
  7212. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7213. vertices[ v ].normalize();
  7214. }
  7215. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7216. const face = this.faces[ f ];
  7217. const vertexNormals = face.vertexNormals;
  7218. if ( vertexNormals.length === 3 ) {
  7219. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7220. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7221. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7222. } else {
  7223. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7224. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7225. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7226. }
  7227. }
  7228. if ( this.faces.length > 0 ) {
  7229. this.normalsNeedUpdate = true;
  7230. }
  7231. },
  7232. computeFlatVertexNormals: function () {
  7233. this.computeFaceNormals();
  7234. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7235. const face = this.faces[ f ];
  7236. const vertexNormals = face.vertexNormals;
  7237. if ( vertexNormals.length === 3 ) {
  7238. vertexNormals[ 0 ].copy( face.normal );
  7239. vertexNormals[ 1 ].copy( face.normal );
  7240. vertexNormals[ 2 ].copy( face.normal );
  7241. } else {
  7242. vertexNormals[ 0 ] = face.normal.clone();
  7243. vertexNormals[ 1 ] = face.normal.clone();
  7244. vertexNormals[ 2 ] = face.normal.clone();
  7245. }
  7246. }
  7247. if ( this.faces.length > 0 ) {
  7248. this.normalsNeedUpdate = true;
  7249. }
  7250. },
  7251. computeMorphNormals: function () {
  7252. // save original normals
  7253. // - create temp variables on first access
  7254. // otherwise just copy (for faster repeated calls)
  7255. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7256. const face = this.faces[ f ];
  7257. if ( ! face.__originalFaceNormal ) {
  7258. face.__originalFaceNormal = face.normal.clone();
  7259. } else {
  7260. face.__originalFaceNormal.copy( face.normal );
  7261. }
  7262. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7263. for ( let i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7264. if ( ! face.__originalVertexNormals[ i ] ) {
  7265. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7266. } else {
  7267. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7268. }
  7269. }
  7270. }
  7271. // use temp geometry to compute face and vertex normals for each morph
  7272. const tmpGeo = new Geometry();
  7273. tmpGeo.faces = this.faces;
  7274. for ( let i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7275. // create on first access
  7276. if ( ! this.morphNormals[ i ] ) {
  7277. this.morphNormals[ i ] = {};
  7278. this.morphNormals[ i ].faceNormals = [];
  7279. this.morphNormals[ i ].vertexNormals = [];
  7280. const dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7281. const dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7282. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7283. const faceNormal = new Vector3();
  7284. const vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7285. dstNormalsFace.push( faceNormal );
  7286. dstNormalsVertex.push( vertexNormals );
  7287. }
  7288. }
  7289. const morphNormals = this.morphNormals[ i ];
  7290. // set vertices to morph target
  7291. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7292. // compute morph normals
  7293. tmpGeo.computeFaceNormals();
  7294. tmpGeo.computeVertexNormals();
  7295. // store morph normals
  7296. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7297. const face = this.faces[ f ];
  7298. const faceNormal = morphNormals.faceNormals[ f ];
  7299. const vertexNormals = morphNormals.vertexNormals[ f ];
  7300. faceNormal.copy( face.normal );
  7301. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7302. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7303. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7304. }
  7305. }
  7306. // restore original normals
  7307. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7308. const face = this.faces[ f ];
  7309. face.normal = face.__originalFaceNormal;
  7310. face.vertexNormals = face.__originalVertexNormals;
  7311. }
  7312. },
  7313. computeBoundingBox: function () {
  7314. if ( this.boundingBox === null ) {
  7315. this.boundingBox = new Box3();
  7316. }
  7317. this.boundingBox.setFromPoints( this.vertices );
  7318. },
  7319. computeBoundingSphere: function () {
  7320. if ( this.boundingSphere === null ) {
  7321. this.boundingSphere = new Sphere();
  7322. }
  7323. this.boundingSphere.setFromPoints( this.vertices );
  7324. },
  7325. merge: function ( geometry, matrix, materialIndexOffset ) {
  7326. if ( ! ( geometry && geometry.isGeometry ) ) {
  7327. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7328. return;
  7329. }
  7330. let normalMatrix,
  7331. vertexOffset = this.vertices.length,
  7332. vertices1 = this.vertices,
  7333. vertices2 = geometry.vertices,
  7334. faces1 = this.faces,
  7335. faces2 = geometry.faces,
  7336. colors1 = this.colors,
  7337. colors2 = geometry.colors;
  7338. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7339. if ( matrix !== undefined ) {
  7340. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7341. }
  7342. // vertices
  7343. for ( let i = 0, il = vertices2.length; i < il; i ++ ) {
  7344. const vertex = vertices2[ i ];
  7345. const vertexCopy = vertex.clone();
  7346. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7347. vertices1.push( vertexCopy );
  7348. }
  7349. // colors
  7350. for ( let i = 0, il = colors2.length; i < il; i ++ ) {
  7351. colors1.push( colors2[ i ].clone() );
  7352. }
  7353. // faces
  7354. for ( let i = 0, il = faces2.length; i < il; i ++ ) {
  7355. let face = faces2[ i ], faceCopy, normal, color,
  7356. faceVertexNormals = face.vertexNormals,
  7357. faceVertexColors = face.vertexColors;
  7358. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7359. faceCopy.normal.copy( face.normal );
  7360. if ( normalMatrix !== undefined ) {
  7361. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7362. }
  7363. for ( let j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7364. normal = faceVertexNormals[ j ].clone();
  7365. if ( normalMatrix !== undefined ) {
  7366. normal.applyMatrix3( normalMatrix ).normalize();
  7367. }
  7368. faceCopy.vertexNormals.push( normal );
  7369. }
  7370. faceCopy.color.copy( face.color );
  7371. for ( let j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7372. color = faceVertexColors[ j ];
  7373. faceCopy.vertexColors.push( color.clone() );
  7374. }
  7375. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7376. faces1.push( faceCopy );
  7377. }
  7378. // uvs
  7379. for ( let i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7380. const faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7381. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7382. for ( let j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7383. const uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7384. for ( let k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7385. uvsCopy.push( uvs2[ k ].clone() );
  7386. }
  7387. this.faceVertexUvs[ i ].push( uvsCopy );
  7388. }
  7389. }
  7390. },
  7391. mergeMesh: function ( mesh ) {
  7392. if ( ! ( mesh && mesh.isMesh ) ) {
  7393. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7394. return;
  7395. }
  7396. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7397. this.merge( mesh.geometry, mesh.matrix );
  7398. },
  7399. /*
  7400. * Checks for duplicate vertices with hashmap.
  7401. * Duplicated vertices are removed
  7402. * and faces' vertices are updated.
  7403. */
  7404. mergeVertices: function () {
  7405. const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7406. const unique = [], changes = [];
  7407. const precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7408. const precision = Math.pow( 10, precisionPoints );
  7409. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  7410. const v = this.vertices[ i ];
  7411. const key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7412. if ( verticesMap[ key ] === undefined ) {
  7413. verticesMap[ key ] = i;
  7414. unique.push( this.vertices[ i ] );
  7415. changes[ i ] = unique.length - 1;
  7416. } else {
  7417. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7418. changes[ i ] = changes[ verticesMap[ key ] ];
  7419. }
  7420. }
  7421. // if faces are completely degenerate after merging vertices, we
  7422. // have to remove them from the geometry.
  7423. const faceIndicesToRemove = [];
  7424. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  7425. const face = this.faces[ i ];
  7426. face.a = changes[ face.a ];
  7427. face.b = changes[ face.b ];
  7428. face.c = changes[ face.c ];
  7429. const indices = [ face.a, face.b, face.c ];
  7430. // if any duplicate vertices are found in a Face3
  7431. // we have to remove the face as nothing can be saved
  7432. for ( let n = 0; n < 3; n ++ ) {
  7433. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7434. faceIndicesToRemove.push( i );
  7435. break;
  7436. }
  7437. }
  7438. }
  7439. for ( let i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7440. const idx = faceIndicesToRemove[ i ];
  7441. this.faces.splice( idx, 1 );
  7442. for ( let j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7443. this.faceVertexUvs[ j ].splice( idx, 1 );
  7444. }
  7445. }
  7446. // Use unique set of vertices
  7447. const diff = this.vertices.length - unique.length;
  7448. this.vertices = unique;
  7449. return diff;
  7450. },
  7451. setFromPoints: function ( points ) {
  7452. this.vertices = [];
  7453. for ( let i = 0, l = points.length; i < l; i ++ ) {
  7454. const point = points[ i ];
  7455. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7456. }
  7457. return this;
  7458. },
  7459. sortFacesByMaterialIndex: function () {
  7460. const faces = this.faces;
  7461. const length = faces.length;
  7462. // tag faces
  7463. for ( let i = 0; i < length; i ++ ) {
  7464. faces[ i ]._id = i;
  7465. }
  7466. // sort faces
  7467. function materialIndexSort( a, b ) {
  7468. return a.materialIndex - b.materialIndex;
  7469. }
  7470. faces.sort( materialIndexSort );
  7471. // sort uvs
  7472. const uvs1 = this.faceVertexUvs[ 0 ];
  7473. const uvs2 = this.faceVertexUvs[ 1 ];
  7474. let newUvs1, newUvs2;
  7475. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7476. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7477. for ( let i = 0; i < length; i ++ ) {
  7478. const id = faces[ i ]._id;
  7479. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7480. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7481. }
  7482. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7483. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7484. },
  7485. toJSON: function () {
  7486. const data = {
  7487. metadata: {
  7488. version: 4.5,
  7489. type: 'Geometry',
  7490. generator: 'Geometry.toJSON'
  7491. }
  7492. };
  7493. // standard Geometry serialization
  7494. data.uuid = this.uuid;
  7495. data.type = this.type;
  7496. if ( this.name !== '' ) data.name = this.name;
  7497. if ( this.parameters !== undefined ) {
  7498. const parameters = this.parameters;
  7499. for ( const key in parameters ) {
  7500. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7501. }
  7502. return data;
  7503. }
  7504. const vertices = [];
  7505. for ( let i = 0; i < this.vertices.length; i ++ ) {
  7506. const vertex = this.vertices[ i ];
  7507. vertices.push( vertex.x, vertex.y, vertex.z );
  7508. }
  7509. const faces = [];
  7510. const normals = [];
  7511. const normalsHash = {};
  7512. const colors = [];
  7513. const colorsHash = {};
  7514. const uvs = [];
  7515. const uvsHash = {};
  7516. for ( let i = 0; i < this.faces.length; i ++ ) {
  7517. const face = this.faces[ i ];
  7518. const hasMaterial = true;
  7519. const hasFaceUv = false; // deprecated
  7520. const hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7521. const hasFaceNormal = face.normal.length() > 0;
  7522. const hasFaceVertexNormal = face.vertexNormals.length > 0;
  7523. const hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7524. const hasFaceVertexColor = face.vertexColors.length > 0;
  7525. let faceType = 0;
  7526. faceType = setBit( faceType, 0, 0 ); // isQuad
  7527. faceType = setBit( faceType, 1, hasMaterial );
  7528. faceType = setBit( faceType, 2, hasFaceUv );
  7529. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7530. faceType = setBit( faceType, 4, hasFaceNormal );
  7531. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7532. faceType = setBit( faceType, 6, hasFaceColor );
  7533. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7534. faces.push( faceType );
  7535. faces.push( face.a, face.b, face.c );
  7536. faces.push( face.materialIndex );
  7537. if ( hasFaceVertexUv ) {
  7538. const faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7539. faces.push(
  7540. getUvIndex( faceVertexUvs[ 0 ] ),
  7541. getUvIndex( faceVertexUvs[ 1 ] ),
  7542. getUvIndex( faceVertexUvs[ 2 ] )
  7543. );
  7544. }
  7545. if ( hasFaceNormal ) {
  7546. faces.push( getNormalIndex( face.normal ) );
  7547. }
  7548. if ( hasFaceVertexNormal ) {
  7549. const vertexNormals = face.vertexNormals;
  7550. faces.push(
  7551. getNormalIndex( vertexNormals[ 0 ] ),
  7552. getNormalIndex( vertexNormals[ 1 ] ),
  7553. getNormalIndex( vertexNormals[ 2 ] )
  7554. );
  7555. }
  7556. if ( hasFaceColor ) {
  7557. faces.push( getColorIndex( face.color ) );
  7558. }
  7559. if ( hasFaceVertexColor ) {
  7560. const vertexColors = face.vertexColors;
  7561. faces.push(
  7562. getColorIndex( vertexColors[ 0 ] ),
  7563. getColorIndex( vertexColors[ 1 ] ),
  7564. getColorIndex( vertexColors[ 2 ] )
  7565. );
  7566. }
  7567. }
  7568. function setBit( value, position, enabled ) {
  7569. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7570. }
  7571. function getNormalIndex( normal ) {
  7572. const hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7573. if ( normalsHash[ hash ] !== undefined ) {
  7574. return normalsHash[ hash ];
  7575. }
  7576. normalsHash[ hash ] = normals.length / 3;
  7577. normals.push( normal.x, normal.y, normal.z );
  7578. return normalsHash[ hash ];
  7579. }
  7580. function getColorIndex( color ) {
  7581. const hash = color.r.toString() + color.g.toString() + color.b.toString();
  7582. if ( colorsHash[ hash ] !== undefined ) {
  7583. return colorsHash[ hash ];
  7584. }
  7585. colorsHash[ hash ] = colors.length;
  7586. colors.push( color.getHex() );
  7587. return colorsHash[ hash ];
  7588. }
  7589. function getUvIndex( uv ) {
  7590. const hash = uv.x.toString() + uv.y.toString();
  7591. if ( uvsHash[ hash ] !== undefined ) {
  7592. return uvsHash[ hash ];
  7593. }
  7594. uvsHash[ hash ] = uvs.length / 2;
  7595. uvs.push( uv.x, uv.y );
  7596. return uvsHash[ hash ];
  7597. }
  7598. data.data = {};
  7599. data.data.vertices = vertices;
  7600. data.data.normals = normals;
  7601. if ( colors.length > 0 ) data.data.colors = colors;
  7602. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7603. data.data.faces = faces;
  7604. return data;
  7605. },
  7606. clone: function () {
  7607. /*
  7608. // Handle primitives
  7609. const parameters = this.parameters;
  7610. if ( parameters !== undefined ) {
  7611. const values = [];
  7612. for ( const key in parameters ) {
  7613. values.push( parameters[ key ] );
  7614. }
  7615. const geometry = Object.create( this.constructor.prototype );
  7616. this.constructor.apply( geometry, values );
  7617. return geometry;
  7618. }
  7619. return new this.constructor().copy( this );
  7620. */
  7621. return new Geometry().copy( this );
  7622. },
  7623. copy: function ( source ) {
  7624. // reset
  7625. this.vertices = [];
  7626. this.colors = [];
  7627. this.faces = [];
  7628. this.faceVertexUvs = [[]];
  7629. this.morphTargets = [];
  7630. this.morphNormals = [];
  7631. this.skinWeights = [];
  7632. this.skinIndices = [];
  7633. this.lineDistances = [];
  7634. this.boundingBox = null;
  7635. this.boundingSphere = null;
  7636. // name
  7637. this.name = source.name;
  7638. // vertices
  7639. const vertices = source.vertices;
  7640. for ( let i = 0, il = vertices.length; i < il; i ++ ) {
  7641. this.vertices.push( vertices[ i ].clone() );
  7642. }
  7643. // colors
  7644. const colors = source.colors;
  7645. for ( let i = 0, il = colors.length; i < il; i ++ ) {
  7646. this.colors.push( colors[ i ].clone() );
  7647. }
  7648. // faces
  7649. const faces = source.faces;
  7650. for ( let i = 0, il = faces.length; i < il; i ++ ) {
  7651. this.faces.push( faces[ i ].clone() );
  7652. }
  7653. // face vertex uvs
  7654. for ( let i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7655. const faceVertexUvs = source.faceVertexUvs[ i ];
  7656. if ( this.faceVertexUvs[ i ] === undefined ) {
  7657. this.faceVertexUvs[ i ] = [];
  7658. }
  7659. for ( let j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7660. const uvs = faceVertexUvs[ j ], uvsCopy = [];
  7661. for ( let k = 0, kl = uvs.length; k < kl; k ++ ) {
  7662. const uv = uvs[ k ];
  7663. uvsCopy.push( uv.clone() );
  7664. }
  7665. this.faceVertexUvs[ i ].push( uvsCopy );
  7666. }
  7667. }
  7668. // morph targets
  7669. const morphTargets = source.morphTargets;
  7670. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  7671. const morphTarget = {};
  7672. morphTarget.name = morphTargets[ i ].name;
  7673. // vertices
  7674. if ( morphTargets[ i ].vertices !== undefined ) {
  7675. morphTarget.vertices = [];
  7676. for ( let j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7677. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7678. }
  7679. }
  7680. // normals
  7681. if ( morphTargets[ i ].normals !== undefined ) {
  7682. morphTarget.normals = [];
  7683. for ( let j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7684. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7685. }
  7686. }
  7687. this.morphTargets.push( morphTarget );
  7688. }
  7689. // morph normals
  7690. const morphNormals = source.morphNormals;
  7691. for ( let i = 0, il = morphNormals.length; i < il; i ++ ) {
  7692. const morphNormal = {};
  7693. // vertex normals
  7694. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7695. morphNormal.vertexNormals = [];
  7696. for ( let j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7697. const srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7698. const destVertexNormal = {};
  7699. destVertexNormal.a = srcVertexNormal.a.clone();
  7700. destVertexNormal.b = srcVertexNormal.b.clone();
  7701. destVertexNormal.c = srcVertexNormal.c.clone();
  7702. morphNormal.vertexNormals.push( destVertexNormal );
  7703. }
  7704. }
  7705. // face normals
  7706. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7707. morphNormal.faceNormals = [];
  7708. for ( let j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7709. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7710. }
  7711. }
  7712. this.morphNormals.push( morphNormal );
  7713. }
  7714. // skin weights
  7715. const skinWeights = source.skinWeights;
  7716. for ( let i = 0, il = skinWeights.length; i < il; i ++ ) {
  7717. this.skinWeights.push( skinWeights[ i ].clone() );
  7718. }
  7719. // skin indices
  7720. const skinIndices = source.skinIndices;
  7721. for ( let i = 0, il = skinIndices.length; i < il; i ++ ) {
  7722. this.skinIndices.push( skinIndices[ i ].clone() );
  7723. }
  7724. // line distances
  7725. const lineDistances = source.lineDistances;
  7726. for ( let i = 0, il = lineDistances.length; i < il; i ++ ) {
  7727. this.lineDistances.push( lineDistances[ i ] );
  7728. }
  7729. // bounding box
  7730. const boundingBox = source.boundingBox;
  7731. if ( boundingBox !== null ) {
  7732. this.boundingBox = boundingBox.clone();
  7733. }
  7734. // bounding sphere
  7735. const boundingSphere = source.boundingSphere;
  7736. if ( boundingSphere !== null ) {
  7737. this.boundingSphere = boundingSphere.clone();
  7738. }
  7739. // update flags
  7740. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7741. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7742. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7743. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7744. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7745. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7746. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7747. return this;
  7748. },
  7749. dispose: function () {
  7750. this.dispatchEvent( { type: 'dispose' } );
  7751. }
  7752. } );
  7753. /**
  7754. * @author mrdoob / http://mrdoob.com/
  7755. * @author Mugen87 / https://github.com/Mugen87
  7756. */
  7757. // BoxGeometry
  7758. class BoxGeometry extends Geometry {
  7759. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7760. super();
  7761. this.type = 'BoxGeometry';
  7762. this.parameters = {
  7763. width: width,
  7764. height: height,
  7765. depth: depth,
  7766. widthSegments: widthSegments,
  7767. heightSegments: heightSegments,
  7768. depthSegments: depthSegments
  7769. };
  7770. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7771. this.mergeVertices();
  7772. }
  7773. }
  7774. // BoxBufferGeometry
  7775. class BoxBufferGeometry extends BufferGeometry {
  7776. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7777. super();
  7778. this.type = 'BoxBufferGeometry';
  7779. this.parameters = {
  7780. width: width,
  7781. height: height,
  7782. depth: depth,
  7783. widthSegments: widthSegments,
  7784. heightSegments: heightSegments,
  7785. depthSegments: depthSegments
  7786. };
  7787. const scope = this;
  7788. width = width || 1;
  7789. height = height || 1;
  7790. depth = depth || 1;
  7791. // segments
  7792. widthSegments = Math.floor( widthSegments ) || 1;
  7793. heightSegments = Math.floor( heightSegments ) || 1;
  7794. depthSegments = Math.floor( depthSegments ) || 1;
  7795. // buffers
  7796. const indices = [];
  7797. const vertices = [];
  7798. const normals = [];
  7799. const uvs = [];
  7800. // helper variables
  7801. let numberOfVertices = 0;
  7802. let groupStart = 0;
  7803. // build each side of the box geometry
  7804. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7805. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7806. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7807. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7808. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7809. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7810. // build geometry
  7811. this.setIndex( indices );
  7812. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7813. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7814. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7815. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7816. const segmentWidth = width / gridX;
  7817. const segmentHeight = height / gridY;
  7818. const widthHalf = width / 2;
  7819. const heightHalf = height / 2;
  7820. const depthHalf = depth / 2;
  7821. const gridX1 = gridX + 1;
  7822. const gridY1 = gridY + 1;
  7823. let vertexCounter = 0;
  7824. let groupCount = 0;
  7825. const vector = new Vector3();
  7826. // generate vertices, normals and uvs
  7827. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7828. const y = iy * segmentHeight - heightHalf;
  7829. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7830. const x = ix * segmentWidth - widthHalf;
  7831. // set values to correct vector component
  7832. vector[ u ] = x * udir;
  7833. vector[ v ] = y * vdir;
  7834. vector[ w ] = depthHalf;
  7835. // now apply vector to vertex buffer
  7836. vertices.push( vector.x, vector.y, vector.z );
  7837. // set values to correct vector component
  7838. vector[ u ] = 0;
  7839. vector[ v ] = 0;
  7840. vector[ w ] = depth > 0 ? 1 : - 1;
  7841. // now apply vector to normal buffer
  7842. normals.push( vector.x, vector.y, vector.z );
  7843. // uvs
  7844. uvs.push( ix / gridX );
  7845. uvs.push( 1 - ( iy / gridY ) );
  7846. // counters
  7847. vertexCounter += 1;
  7848. }
  7849. }
  7850. // indices
  7851. // 1. you need three indices to draw a single face
  7852. // 2. a single segment consists of two faces
  7853. // 3. so we need to generate six (2*3) indices per segment
  7854. for ( let iy = 0; iy < gridY; iy ++ ) {
  7855. for ( let ix = 0; ix < gridX; ix ++ ) {
  7856. const a = numberOfVertices + ix + gridX1 * iy;
  7857. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7858. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7859. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7860. // faces
  7861. indices.push( a, b, d );
  7862. indices.push( b, c, d );
  7863. // increase counter
  7864. groupCount += 6;
  7865. }
  7866. }
  7867. // add a group to the geometry. this will ensure multi material support
  7868. scope.addGroup( groupStart, groupCount, materialIndex );
  7869. // calculate new start value for groups
  7870. groupStart += groupCount;
  7871. // update total number of vertices
  7872. numberOfVertices += vertexCounter;
  7873. }
  7874. }
  7875. }
  7876. /**
  7877. * Uniform Utilities
  7878. */
  7879. function cloneUniforms( src ) {
  7880. const dst = {};
  7881. for ( const u in src ) {
  7882. dst[ u ] = {};
  7883. for ( const p in src[ u ] ) {
  7884. const property = src[ u ][ p ];
  7885. if ( property && ( property.isColor ||
  7886. property.isMatrix3 || property.isMatrix4 ||
  7887. property.isVector2 || property.isVector3 || property.isVector4 ||
  7888. property.isTexture ) ) {
  7889. dst[ u ][ p ] = property.clone();
  7890. } else if ( Array.isArray( property ) ) {
  7891. dst[ u ][ p ] = property.slice();
  7892. } else {
  7893. dst[ u ][ p ] = property;
  7894. }
  7895. }
  7896. }
  7897. return dst;
  7898. }
  7899. function mergeUniforms( uniforms ) {
  7900. const merged = {};
  7901. for ( let u = 0; u < uniforms.length; u ++ ) {
  7902. const tmp = cloneUniforms( uniforms[ u ] );
  7903. for ( const p in tmp ) {
  7904. merged[ p ] = tmp[ p ];
  7905. }
  7906. }
  7907. return merged;
  7908. }
  7909. // Legacy
  7910. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7911. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7912. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7913. /**
  7914. * @author alteredq / http://alteredqualia.com/
  7915. *
  7916. * parameters = {
  7917. * defines: { "label" : "value" },
  7918. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7919. *
  7920. * fragmentShader: <string>,
  7921. * vertexShader: <string>,
  7922. *
  7923. * wireframe: <boolean>,
  7924. * wireframeLinewidth: <float>,
  7925. *
  7926. * lights: <bool>,
  7927. *
  7928. * skinning: <bool>,
  7929. * morphTargets: <bool>,
  7930. * morphNormals: <bool>
  7931. * }
  7932. */
  7933. function ShaderMaterial( parameters ) {
  7934. Material.call( this );
  7935. this.type = 'ShaderMaterial';
  7936. this.defines = {};
  7937. this.uniforms = {};
  7938. this.vertexShader = default_vertex;
  7939. this.fragmentShader = default_fragment;
  7940. this.linewidth = 1;
  7941. this.wireframe = false;
  7942. this.wireframeLinewidth = 1;
  7943. this.fog = false; // set to use scene fog
  7944. this.lights = false; // set to use scene lights
  7945. this.clipping = false; // set to use user-defined clipping planes
  7946. this.skinning = false; // set to use skinning attribute streams
  7947. this.morphTargets = false; // set to use morph targets
  7948. this.morphNormals = false; // set to use morph normals
  7949. this.extensions = {
  7950. derivatives: false, // set to use derivatives
  7951. fragDepth: false, // set to use fragment depth values
  7952. drawBuffers: false, // set to use draw buffers
  7953. shaderTextureLOD: false // set to use shader texture LOD
  7954. };
  7955. // When rendered geometry doesn't include these attributes but the material does,
  7956. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7957. this.defaultAttributeValues = {
  7958. 'color': [ 1, 1, 1 ],
  7959. 'uv': [ 0, 0 ],
  7960. 'uv2': [ 0, 0 ]
  7961. };
  7962. this.index0AttributeName = undefined;
  7963. this.uniformsNeedUpdate = false;
  7964. if ( parameters !== undefined ) {
  7965. if ( parameters.attributes !== undefined ) {
  7966. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7967. }
  7968. this.setValues( parameters );
  7969. }
  7970. }
  7971. ShaderMaterial.prototype = Object.create( Material.prototype );
  7972. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7973. ShaderMaterial.prototype.isShaderMaterial = true;
  7974. ShaderMaterial.prototype.copy = function ( source ) {
  7975. Material.prototype.copy.call( this, source );
  7976. this.fragmentShader = source.fragmentShader;
  7977. this.vertexShader = source.vertexShader;
  7978. this.uniforms = cloneUniforms( source.uniforms );
  7979. this.defines = Object.assign( {}, source.defines );
  7980. this.wireframe = source.wireframe;
  7981. this.wireframeLinewidth = source.wireframeLinewidth;
  7982. this.lights = source.lights;
  7983. this.clipping = source.clipping;
  7984. this.skinning = source.skinning;
  7985. this.morphTargets = source.morphTargets;
  7986. this.morphNormals = source.morphNormals;
  7987. this.extensions = Object.assign( {}, source.extensions );
  7988. return this;
  7989. };
  7990. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7991. const data = Material.prototype.toJSON.call( this, meta );
  7992. data.uniforms = {};
  7993. for ( const name in this.uniforms ) {
  7994. const uniform = this.uniforms[ name ];
  7995. const value = uniform.value;
  7996. if ( value && value.isTexture ) {
  7997. data.uniforms[ name ] = {
  7998. type: 't',
  7999. value: value.toJSON( meta ).uuid
  8000. };
  8001. } else if ( value && value.isColor ) {
  8002. data.uniforms[ name ] = {
  8003. type: 'c',
  8004. value: value.getHex()
  8005. };
  8006. } else if ( value && value.isVector2 ) {
  8007. data.uniforms[ name ] = {
  8008. type: 'v2',
  8009. value: value.toArray()
  8010. };
  8011. } else if ( value && value.isVector3 ) {
  8012. data.uniforms[ name ] = {
  8013. type: 'v3',
  8014. value: value.toArray()
  8015. };
  8016. } else if ( value && value.isVector4 ) {
  8017. data.uniforms[ name ] = {
  8018. type: 'v4',
  8019. value: value.toArray()
  8020. };
  8021. } else if ( value && value.isMatrix3 ) {
  8022. data.uniforms[ name ] = {
  8023. type: 'm3',
  8024. value: value.toArray()
  8025. };
  8026. } else if ( value && value.isMatrix4 ) {
  8027. data.uniforms[ name ] = {
  8028. type: 'm4',
  8029. value: value.toArray()
  8030. };
  8031. } else {
  8032. data.uniforms[ name ] = {
  8033. value: value
  8034. };
  8035. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8036. }
  8037. }
  8038. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  8039. data.vertexShader = this.vertexShader;
  8040. data.fragmentShader = this.fragmentShader;
  8041. const extensions = {};
  8042. for ( const key in this.extensions ) {
  8043. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  8044. }
  8045. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  8046. return data;
  8047. };
  8048. /**
  8049. * @author mrdoob / http://mrdoob.com/
  8050. * @author mikael emtinger / http://gomo.se/
  8051. * @author WestLangley / http://github.com/WestLangley
  8052. */
  8053. function Camera() {
  8054. Object3D.call( this );
  8055. this.type = 'Camera';
  8056. this.matrixWorldInverse = new Matrix4();
  8057. this.projectionMatrix = new Matrix4();
  8058. this.projectionMatrixInverse = new Matrix4();
  8059. }
  8060. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8061. constructor: Camera,
  8062. isCamera: true,
  8063. copy: function ( source, recursive ) {
  8064. Object3D.prototype.copy.call( this, source, recursive );
  8065. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8066. this.projectionMatrix.copy( source.projectionMatrix );
  8067. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  8068. return this;
  8069. },
  8070. getWorldDirection: function ( target ) {
  8071. if ( target === undefined ) {
  8072. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  8073. target = new Vector3();
  8074. }
  8075. this.updateMatrixWorld( true );
  8076. const e = this.matrixWorld.elements;
  8077. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  8078. },
  8079. updateMatrixWorld: function ( force ) {
  8080. Object3D.prototype.updateMatrixWorld.call( this, force );
  8081. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8082. },
  8083. updateWorldMatrix: function ( updateParents, updateChildren ) {
  8084. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  8085. this.matrixWorldInverse.getInverse( this.matrixWorld );
  8086. },
  8087. clone: function () {
  8088. return new this.constructor().copy( this );
  8089. }
  8090. } );
  8091. /**
  8092. * @author mrdoob / http://mrdoob.com/
  8093. * @author greggman / http://games.greggman.com/
  8094. * @author zz85 / http://www.lab4games.net/zz85/blog
  8095. * @author tschw
  8096. */
  8097. function PerspectiveCamera( fov, aspect, near, far ) {
  8098. Camera.call( this );
  8099. this.type = 'PerspectiveCamera';
  8100. this.fov = fov !== undefined ? fov : 50;
  8101. this.zoom = 1;
  8102. this.near = near !== undefined ? near : 0.1;
  8103. this.far = far !== undefined ? far : 2000;
  8104. this.focus = 10;
  8105. this.aspect = aspect !== undefined ? aspect : 1;
  8106. this.view = null;
  8107. this.filmGauge = 35; // width of the film (default in millimeters)
  8108. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8109. this.updateProjectionMatrix();
  8110. }
  8111. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  8112. constructor: PerspectiveCamera,
  8113. isPerspectiveCamera: true,
  8114. copy: function ( source, recursive ) {
  8115. Camera.prototype.copy.call( this, source, recursive );
  8116. this.fov = source.fov;
  8117. this.zoom = source.zoom;
  8118. this.near = source.near;
  8119. this.far = source.far;
  8120. this.focus = source.focus;
  8121. this.aspect = source.aspect;
  8122. this.view = source.view === null ? null : Object.assign( {}, source.view );
  8123. this.filmGauge = source.filmGauge;
  8124. this.filmOffset = source.filmOffset;
  8125. return this;
  8126. },
  8127. /**
  8128. * Sets the FOV by focal length in respect to the current .filmGauge.
  8129. *
  8130. * The default film gauge is 35, so that the focal length can be specified for
  8131. * a 35mm (full frame) camera.
  8132. *
  8133. * Values for focal length and film gauge must have the same unit.
  8134. */
  8135. setFocalLength: function ( focalLength ) {
  8136. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  8137. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8138. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  8139. this.updateProjectionMatrix();
  8140. },
  8141. /**
  8142. * Calculates the focal length from the current .fov and .filmGauge.
  8143. */
  8144. getFocalLength: function () {
  8145. const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  8146. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8147. },
  8148. getEffectiveFOV: function () {
  8149. return MathUtils.RAD2DEG * 2 * Math.atan(
  8150. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  8151. },
  8152. getFilmWidth: function () {
  8153. // film not completely covered in portrait format (aspect < 1)
  8154. return this.filmGauge * Math.min( this.aspect, 1 );
  8155. },
  8156. getFilmHeight: function () {
  8157. // film not completely covered in landscape format (aspect > 1)
  8158. return this.filmGauge / Math.max( this.aspect, 1 );
  8159. },
  8160. /**
  8161. * Sets an offset in a larger frustum. This is useful for multi-window or
  8162. * multi-monitor/multi-machine setups.
  8163. *
  8164. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8165. * the monitors are in grid like this
  8166. *
  8167. * +---+---+---+
  8168. * | A | B | C |
  8169. * +---+---+---+
  8170. * | D | E | F |
  8171. * +---+---+---+
  8172. *
  8173. * then for each monitor you would call it like this
  8174. *
  8175. * const w = 1920;
  8176. * const h = 1080;
  8177. * const fullWidth = w * 3;
  8178. * const fullHeight = h * 2;
  8179. *
  8180. * --A--
  8181. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8182. * --B--
  8183. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8184. * --C--
  8185. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8186. * --D--
  8187. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8188. * --E--
  8189. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8190. * --F--
  8191. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8192. *
  8193. * Note there is no reason monitors have to be the same size or in a grid.
  8194. */
  8195. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8196. this.aspect = fullWidth / fullHeight;
  8197. if ( this.view === null ) {
  8198. this.view = {
  8199. enabled: true,
  8200. fullWidth: 1,
  8201. fullHeight: 1,
  8202. offsetX: 0,
  8203. offsetY: 0,
  8204. width: 1,
  8205. height: 1
  8206. };
  8207. }
  8208. this.view.enabled = true;
  8209. this.view.fullWidth = fullWidth;
  8210. this.view.fullHeight = fullHeight;
  8211. this.view.offsetX = x;
  8212. this.view.offsetY = y;
  8213. this.view.width = width;
  8214. this.view.height = height;
  8215. this.updateProjectionMatrix();
  8216. },
  8217. clearViewOffset: function () {
  8218. if ( this.view !== null ) {
  8219. this.view.enabled = false;
  8220. }
  8221. this.updateProjectionMatrix();
  8222. },
  8223. updateProjectionMatrix: function () {
  8224. let near = this.near,
  8225. top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8226. height = 2 * top,
  8227. width = this.aspect * height,
  8228. left = - 0.5 * width,
  8229. view = this.view;
  8230. if ( this.view !== null && this.view.enabled ) {
  8231. const fullWidth = view.fullWidth,
  8232. fullHeight = view.fullHeight;
  8233. left += view.offsetX * width / fullWidth;
  8234. top -= view.offsetY * height / fullHeight;
  8235. width *= view.width / fullWidth;
  8236. height *= view.height / fullHeight;
  8237. }
  8238. const skew = this.filmOffset;
  8239. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8240. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8241. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8242. },
  8243. toJSON: function ( meta ) {
  8244. const data = Object3D.prototype.toJSON.call( this, meta );
  8245. data.object.fov = this.fov;
  8246. data.object.zoom = this.zoom;
  8247. data.object.near = this.near;
  8248. data.object.far = this.far;
  8249. data.object.focus = this.focus;
  8250. data.object.aspect = this.aspect;
  8251. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8252. data.object.filmGauge = this.filmGauge;
  8253. data.object.filmOffset = this.filmOffset;
  8254. return data;
  8255. }
  8256. } );
  8257. /**
  8258. * Camera for rendering cube maps
  8259. * - renders scene into axis-aligned cube
  8260. *
  8261. * @author alteredq / http://alteredqualia.com/
  8262. */
  8263. const fov = 90, aspect = 1;
  8264. function CubeCamera( near, far, renderTarget ) {
  8265. Object3D.call( this );
  8266. this.type = 'CubeCamera';
  8267. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  8268. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  8269. return;
  8270. }
  8271. this.renderTarget = renderTarget;
  8272. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8273. cameraPX.layers = this.layers;
  8274. cameraPX.up.set( 0, - 1, 0 );
  8275. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8276. this.add( cameraPX );
  8277. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8278. cameraNX.layers = this.layers;
  8279. cameraNX.up.set( 0, - 1, 0 );
  8280. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8281. this.add( cameraNX );
  8282. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8283. cameraPY.layers = this.layers;
  8284. cameraPY.up.set( 0, 0, 1 );
  8285. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8286. this.add( cameraPY );
  8287. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8288. cameraNY.layers = this.layers;
  8289. cameraNY.up.set( 0, 0, - 1 );
  8290. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8291. this.add( cameraNY );
  8292. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8293. cameraPZ.layers = this.layers;
  8294. cameraPZ.up.set( 0, - 1, 0 );
  8295. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8296. this.add( cameraPZ );
  8297. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8298. cameraNZ.layers = this.layers;
  8299. cameraNZ.up.set( 0, - 1, 0 );
  8300. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8301. this.add( cameraNZ );
  8302. this.update = function ( renderer, scene ) {
  8303. if ( this.parent === null ) this.updateMatrixWorld();
  8304. const currentXrEnabled = renderer.xr.enabled;
  8305. const currentRenderTarget = renderer.getRenderTarget();
  8306. renderer.xr.enabled = false;
  8307. const generateMipmaps = renderTarget.texture.generateMipmaps;
  8308. renderTarget.texture.generateMipmaps = false;
  8309. renderer.setRenderTarget( renderTarget, 0 );
  8310. renderer.render( scene, cameraPX );
  8311. renderer.setRenderTarget( renderTarget, 1 );
  8312. renderer.render( scene, cameraNX );
  8313. renderer.setRenderTarget( renderTarget, 2 );
  8314. renderer.render( scene, cameraPY );
  8315. renderer.setRenderTarget( renderTarget, 3 );
  8316. renderer.render( scene, cameraNY );
  8317. renderer.setRenderTarget( renderTarget, 4 );
  8318. renderer.render( scene, cameraPZ );
  8319. renderTarget.texture.generateMipmaps = generateMipmaps;
  8320. renderer.setRenderTarget( renderTarget, 5 );
  8321. renderer.render( scene, cameraNZ );
  8322. renderer.setRenderTarget( currentRenderTarget );
  8323. renderer.xr.enabled = currentXrEnabled;
  8324. };
  8325. this.clear = function ( renderer, color, depth, stencil ) {
  8326. const currentRenderTarget = renderer.getRenderTarget();
  8327. for ( let i = 0; i < 6; i ++ ) {
  8328. renderer.setRenderTarget( renderTarget, i );
  8329. renderer.clear( color, depth, stencil );
  8330. }
  8331. renderer.setRenderTarget( currentRenderTarget );
  8332. };
  8333. }
  8334. CubeCamera.prototype = Object.create( Object3D.prototype );
  8335. CubeCamera.prototype.constructor = CubeCamera;
  8336. /**
  8337. * @author alteredq / http://alteredqualia.com
  8338. * @author WestLangley / http://github.com/WestLangley
  8339. */
  8340. function WebGLCubeRenderTarget( size, options, dummy ) {
  8341. if ( Number.isInteger( options ) ) {
  8342. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  8343. options = dummy;
  8344. }
  8345. WebGLRenderTarget.call( this, size, size, options );
  8346. }
  8347. WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
  8348. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  8349. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8350. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8351. this.texture.type = texture.type;
  8352. this.texture.format = texture.format;
  8353. this.texture.encoding = texture.encoding;
  8354. const scene = new Scene();
  8355. const shader = {
  8356. uniforms: {
  8357. tEquirect: { value: null },
  8358. },
  8359. vertexShader: [
  8360. "varying vec3 vWorldDirection;",
  8361. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8362. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8363. "}",
  8364. "void main() {",
  8365. " vWorldDirection = transformDirection( position, modelMatrix );",
  8366. " #include <begin_vertex>",
  8367. " #include <project_vertex>",
  8368. "}"
  8369. ].join( '\n' ),
  8370. fragmentShader: [
  8371. "uniform sampler2D tEquirect;",
  8372. "varying vec3 vWorldDirection;",
  8373. "#include <common>",
  8374. "void main() {",
  8375. " vec3 direction = normalize( vWorldDirection );",
  8376. " vec2 sampleUV = equirectUv( direction );",
  8377. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8378. "}"
  8379. ].join( '\n' ),
  8380. };
  8381. const material = new ShaderMaterial( {
  8382. name: 'CubemapFromEquirect',
  8383. uniforms: cloneUniforms( shader.uniforms ),
  8384. vertexShader: shader.vertexShader,
  8385. fragmentShader: shader.fragmentShader,
  8386. side: BackSide,
  8387. blending: NoBlending
  8388. } );
  8389. material.uniforms.tEquirect.value = texture;
  8390. const mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8391. scene.add( mesh );
  8392. const camera = new CubeCamera( 1, 10, this );
  8393. camera.update( renderer, scene );
  8394. mesh.geometry.dispose();
  8395. mesh.material.dispose();
  8396. return this;
  8397. };
  8398. /**
  8399. * @author alteredq / http://alteredqualia.com/
  8400. */
  8401. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8402. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8403. this.image = { data: data || null, width: width || 1, height: height || 1 };
  8404. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8405. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8406. this.generateMipmaps = false;
  8407. this.flipY = false;
  8408. this.unpackAlignment = 1;
  8409. this.needsUpdate = true;
  8410. }
  8411. DataTexture.prototype = Object.create( Texture.prototype );
  8412. DataTexture.prototype.constructor = DataTexture;
  8413. DataTexture.prototype.isDataTexture = true;
  8414. /**
  8415. * @author mrdoob / http://mrdoob.com/
  8416. * @author alteredq / http://alteredqualia.com/
  8417. * @author bhouston / http://clara.io
  8418. */
  8419. const _sphere$1 = new Sphere();
  8420. const _vector$5 = new Vector3();
  8421. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8422. this.planes = [
  8423. ( p0 !== undefined ) ? p0 : new Plane(),
  8424. ( p1 !== undefined ) ? p1 : new Plane(),
  8425. ( p2 !== undefined ) ? p2 : new Plane(),
  8426. ( p3 !== undefined ) ? p3 : new Plane(),
  8427. ( p4 !== undefined ) ? p4 : new Plane(),
  8428. ( p5 !== undefined ) ? p5 : new Plane()
  8429. ];
  8430. }
  8431. Object.assign( Frustum.prototype, {
  8432. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8433. const planes = this.planes;
  8434. planes[ 0 ].copy( p0 );
  8435. planes[ 1 ].copy( p1 );
  8436. planes[ 2 ].copy( p2 );
  8437. planes[ 3 ].copy( p3 );
  8438. planes[ 4 ].copy( p4 );
  8439. planes[ 5 ].copy( p5 );
  8440. return this;
  8441. },
  8442. clone: function () {
  8443. return new this.constructor().copy( this );
  8444. },
  8445. copy: function ( frustum ) {
  8446. const planes = this.planes;
  8447. for ( let i = 0; i < 6; i ++ ) {
  8448. planes[ i ].copy( frustum.planes[ i ] );
  8449. }
  8450. return this;
  8451. },
  8452. setFromProjectionMatrix: function ( m ) {
  8453. const planes = this.planes;
  8454. const me = m.elements;
  8455. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8456. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8457. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8458. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8459. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8460. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8461. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8462. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8463. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8464. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8465. return this;
  8466. },
  8467. intersectsObject: function ( object ) {
  8468. const geometry = object.geometry;
  8469. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8470. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  8471. return this.intersectsSphere( _sphere$1 );
  8472. },
  8473. intersectsSprite: function ( sprite ) {
  8474. _sphere$1.center.set( 0, 0, 0 );
  8475. _sphere$1.radius = 0.7071067811865476;
  8476. _sphere$1.applyMatrix4( sprite.matrixWorld );
  8477. return this.intersectsSphere( _sphere$1 );
  8478. },
  8479. intersectsSphere: function ( sphere ) {
  8480. const planes = this.planes;
  8481. const center = sphere.center;
  8482. const negRadius = - sphere.radius;
  8483. for ( let i = 0; i < 6; i ++ ) {
  8484. const distance = planes[ i ].distanceToPoint( center );
  8485. if ( distance < negRadius ) {
  8486. return false;
  8487. }
  8488. }
  8489. return true;
  8490. },
  8491. intersectsBox: function ( box ) {
  8492. const planes = this.planes;
  8493. for ( let i = 0; i < 6; i ++ ) {
  8494. const plane = planes[ i ];
  8495. // corner at max distance
  8496. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8497. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8498. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8499. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  8500. return false;
  8501. }
  8502. }
  8503. return true;
  8504. },
  8505. containsPoint: function ( point ) {
  8506. const planes = this.planes;
  8507. for ( let i = 0; i < 6; i ++ ) {
  8508. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8509. return false;
  8510. }
  8511. }
  8512. return true;
  8513. }
  8514. } );
  8515. /**
  8516. * Uniforms library for shared webgl shaders
  8517. */
  8518. const UniformsLib = {
  8519. common: {
  8520. diffuse: { value: new Color( 0xeeeeee ) },
  8521. opacity: { value: 1.0 },
  8522. map: { value: null },
  8523. uvTransform: { value: new Matrix3() },
  8524. uv2Transform: { value: new Matrix3() },
  8525. alphaMap: { value: null },
  8526. },
  8527. specularmap: {
  8528. specularMap: { value: null },
  8529. },
  8530. envmap: {
  8531. envMap: { value: null },
  8532. flipEnvMap: { value: - 1 },
  8533. reflectivity: { value: 1.0 },
  8534. refractionRatio: { value: 0.98 },
  8535. maxMipLevel: { value: 0 }
  8536. },
  8537. aomap: {
  8538. aoMap: { value: null },
  8539. aoMapIntensity: { value: 1 }
  8540. },
  8541. lightmap: {
  8542. lightMap: { value: null },
  8543. lightMapIntensity: { value: 1 }
  8544. },
  8545. emissivemap: {
  8546. emissiveMap: { value: null }
  8547. },
  8548. bumpmap: {
  8549. bumpMap: { value: null },
  8550. bumpScale: { value: 1 }
  8551. },
  8552. normalmap: {
  8553. normalMap: { value: null },
  8554. normalScale: { value: new Vector2( 1, 1 ) }
  8555. },
  8556. displacementmap: {
  8557. displacementMap: { value: null },
  8558. displacementScale: { value: 1 },
  8559. displacementBias: { value: 0 }
  8560. },
  8561. roughnessmap: {
  8562. roughnessMap: { value: null }
  8563. },
  8564. metalnessmap: {
  8565. metalnessMap: { value: null }
  8566. },
  8567. gradientmap: {
  8568. gradientMap: { value: null }
  8569. },
  8570. fog: {
  8571. fogDensity: { value: 0.00025 },
  8572. fogNear: { value: 1 },
  8573. fogFar: { value: 2000 },
  8574. fogColor: { value: new Color( 0xffffff ) }
  8575. },
  8576. lights: {
  8577. ambientLightColor: { value: [] },
  8578. lightProbe: { value: [] },
  8579. directionalLights: { value: [], properties: {
  8580. direction: {},
  8581. color: {}
  8582. } },
  8583. directionalLightShadows: { value: [], properties: {
  8584. shadowBias: {},
  8585. shadowNormalBias: {},
  8586. shadowRadius: {},
  8587. shadowMapSize: {}
  8588. } },
  8589. directionalShadowMap: { value: [] },
  8590. directionalShadowMatrix: { value: [] },
  8591. spotLights: { value: [], properties: {
  8592. color: {},
  8593. position: {},
  8594. direction: {},
  8595. distance: {},
  8596. coneCos: {},
  8597. penumbraCos: {},
  8598. decay: {}
  8599. } },
  8600. spotLightShadows: { value: [], properties: {
  8601. shadowBias: {},
  8602. shadowNormalBias: {},
  8603. shadowRadius: {},
  8604. shadowMapSize: {}
  8605. } },
  8606. spotShadowMap: { value: [] },
  8607. spotShadowMatrix: { value: [] },
  8608. pointLights: { value: [], properties: {
  8609. color: {},
  8610. position: {},
  8611. decay: {},
  8612. distance: {}
  8613. } },
  8614. pointLightShadows: { value: [], properties: {
  8615. shadowBias: {},
  8616. shadowNormalBias: {},
  8617. shadowRadius: {},
  8618. shadowMapSize: {},
  8619. shadowCameraNear: {},
  8620. shadowCameraFar: {}
  8621. } },
  8622. pointShadowMap: { value: [] },
  8623. pointShadowMatrix: { value: [] },
  8624. hemisphereLights: { value: [], properties: {
  8625. direction: {},
  8626. skyColor: {},
  8627. groundColor: {}
  8628. } },
  8629. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8630. rectAreaLights: { value: [], properties: {
  8631. color: {},
  8632. position: {},
  8633. width: {},
  8634. height: {}
  8635. } }
  8636. },
  8637. points: {
  8638. diffuse: { value: new Color( 0xeeeeee ) },
  8639. opacity: { value: 1.0 },
  8640. size: { value: 1.0 },
  8641. scale: { value: 1.0 },
  8642. map: { value: null },
  8643. alphaMap: { value: null },
  8644. uvTransform: { value: new Matrix3() }
  8645. },
  8646. sprite: {
  8647. diffuse: { value: new Color( 0xeeeeee ) },
  8648. opacity: { value: 1.0 },
  8649. center: { value: new Vector2( 0.5, 0.5 ) },
  8650. rotation: { value: 0.0 },
  8651. map: { value: null },
  8652. alphaMap: { value: null },
  8653. uvTransform: { value: new Matrix3() }
  8654. }
  8655. };
  8656. /**
  8657. * @author mrdoob / http://mrdoob.com/
  8658. */
  8659. function WebGLAnimation() {
  8660. let context = null;
  8661. let isAnimating = false;
  8662. let animationLoop = null;
  8663. let requestId = null;
  8664. function onAnimationFrame( time, frame ) {
  8665. animationLoop( time, frame );
  8666. requestId = context.requestAnimationFrame( onAnimationFrame );
  8667. }
  8668. return {
  8669. start: function () {
  8670. if ( isAnimating === true ) return;
  8671. if ( animationLoop === null ) return;
  8672. requestId = context.requestAnimationFrame( onAnimationFrame );
  8673. isAnimating = true;
  8674. },
  8675. stop: function () {
  8676. context.cancelAnimationFrame( requestId );
  8677. isAnimating = false;
  8678. },
  8679. setAnimationLoop: function ( callback ) {
  8680. animationLoop = callback;
  8681. },
  8682. setContext: function ( value ) {
  8683. context = value;
  8684. }
  8685. };
  8686. }
  8687. /**
  8688. * @author mrdoob / http://mrdoob.com/
  8689. */
  8690. function WebGLAttributes( gl, capabilities ) {
  8691. const isWebGL2 = capabilities.isWebGL2;
  8692. const buffers = new WeakMap();
  8693. function createBuffer( attribute, bufferType ) {
  8694. const array = attribute.array;
  8695. const usage = attribute.usage;
  8696. const buffer = gl.createBuffer();
  8697. gl.bindBuffer( bufferType, buffer );
  8698. gl.bufferData( bufferType, array, usage );
  8699. attribute.onUploadCallback();
  8700. let type = 5126;
  8701. if ( array instanceof Float32Array ) {
  8702. type = 5126;
  8703. } else if ( array instanceof Float64Array ) {
  8704. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  8705. } else if ( array instanceof Uint16Array ) {
  8706. type = 5123;
  8707. } else if ( array instanceof Int16Array ) {
  8708. type = 5122;
  8709. } else if ( array instanceof Uint32Array ) {
  8710. type = 5125;
  8711. } else if ( array instanceof Int32Array ) {
  8712. type = 5124;
  8713. } else if ( array instanceof Int8Array ) {
  8714. type = 5120;
  8715. } else if ( array instanceof Uint8Array ) {
  8716. type = 5121;
  8717. }
  8718. return {
  8719. buffer: buffer,
  8720. type: type,
  8721. bytesPerElement: array.BYTES_PER_ELEMENT,
  8722. version: attribute.version
  8723. };
  8724. }
  8725. function updateBuffer( buffer, attribute, bufferType ) {
  8726. const array = attribute.array;
  8727. const updateRange = attribute.updateRange;
  8728. gl.bindBuffer( bufferType, buffer );
  8729. if ( updateRange.count === - 1 ) {
  8730. // Not using update ranges
  8731. gl.bufferSubData( bufferType, 0, array );
  8732. } else {
  8733. if ( isWebGL2 ) {
  8734. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8735. array, updateRange.offset, updateRange.count );
  8736. } else {
  8737. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  8738. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  8739. }
  8740. updateRange.count = - 1; // reset range
  8741. }
  8742. }
  8743. //
  8744. function get( attribute ) {
  8745. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8746. return buffers.get( attribute );
  8747. }
  8748. function remove( attribute ) {
  8749. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8750. const data = buffers.get( attribute );
  8751. if ( data ) {
  8752. gl.deleteBuffer( data.buffer );
  8753. buffers.delete( attribute );
  8754. }
  8755. }
  8756. function update( attribute, bufferType ) {
  8757. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  8758. const data = buffers.get( attribute );
  8759. if ( data === undefined ) {
  8760. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  8761. } else if ( data.version < attribute.version ) {
  8762. updateBuffer( data.buffer, attribute, bufferType );
  8763. data.version = attribute.version;
  8764. }
  8765. }
  8766. return {
  8767. get: get,
  8768. remove: remove,
  8769. update: update
  8770. };
  8771. }
  8772. /**
  8773. * @author mrdoob / http://mrdoob.com/
  8774. * @author Mugen87 / https://github.com/Mugen87
  8775. */
  8776. // PlaneGeometry
  8777. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  8778. Geometry.call( this );
  8779. this.type = 'PlaneGeometry';
  8780. this.parameters = {
  8781. width: width,
  8782. height: height,
  8783. widthSegments: widthSegments,
  8784. heightSegments: heightSegments
  8785. };
  8786. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  8787. this.mergeVertices();
  8788. }
  8789. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  8790. PlaneGeometry.prototype.constructor = PlaneGeometry;
  8791. // PlaneBufferGeometry
  8792. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  8793. BufferGeometry.call( this );
  8794. this.type = 'PlaneBufferGeometry';
  8795. this.parameters = {
  8796. width: width,
  8797. height: height,
  8798. widthSegments: widthSegments,
  8799. heightSegments: heightSegments
  8800. };
  8801. width = width || 1;
  8802. height = height || 1;
  8803. const width_half = width / 2;
  8804. const height_half = height / 2;
  8805. const gridX = Math.floor( widthSegments ) || 1;
  8806. const gridY = Math.floor( heightSegments ) || 1;
  8807. const gridX1 = gridX + 1;
  8808. const gridY1 = gridY + 1;
  8809. const segment_width = width / gridX;
  8810. const segment_height = height / gridY;
  8811. // buffers
  8812. const indices = [];
  8813. const vertices = [];
  8814. const normals = [];
  8815. const uvs = [];
  8816. // generate vertices, normals and uvs
  8817. for ( let iy = 0; iy < gridY1; iy ++ ) {
  8818. const y = iy * segment_height - height_half;
  8819. for ( let ix = 0; ix < gridX1; ix ++ ) {
  8820. const x = ix * segment_width - width_half;
  8821. vertices.push( x, - y, 0 );
  8822. normals.push( 0, 0, 1 );
  8823. uvs.push( ix / gridX );
  8824. uvs.push( 1 - ( iy / gridY ) );
  8825. }
  8826. }
  8827. // indices
  8828. for ( let iy = 0; iy < gridY; iy ++ ) {
  8829. for ( let ix = 0; ix < gridX; ix ++ ) {
  8830. const a = ix + gridX1 * iy;
  8831. const b = ix + gridX1 * ( iy + 1 );
  8832. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  8833. const d = ( ix + 1 ) + gridX1 * iy;
  8834. // faces
  8835. indices.push( a, b, d );
  8836. indices.push( b, c, d );
  8837. }
  8838. }
  8839. // build geometry
  8840. this.setIndex( indices );
  8841. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8842. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8843. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8844. }
  8845. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8846. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  8847. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8848. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8849. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8850. 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";
  8851. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8852. var begin_vertex = "vec3 transformed = vec3( position );";
  8853. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8854. 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";
  8855. 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";
  8856. 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";
  8857. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8858. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8859. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8860. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8861. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8862. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8863. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8864. 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 return 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}";
  8865. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction) {\n vec3 absDirection = abs(direction);\n float face = -1.0;\n if (absDirection.x > absDirection.z) {\n if (absDirection.x > absDirection.y)\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if (absDirection.z > absDirection.y)\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n}\nvec2 getUV(vec3 direction, float face) {\n vec2 uv;\n if (face == 0.0) {\n uv = vec2(direction.z, direction.y) / abs(direction.x); } else if (face == 1.0) {\n uv = vec2(-direction.x, -direction.z) / abs(direction.y); } else if (face == 2.0) {\n uv = vec2(-direction.x, direction.y) / abs(direction.z); } else if (face == 3.0) {\n uv = vec2(-direction.z, direction.y) / abs(direction.x); } else if (face == 4.0) {\n uv = vec2(-direction.x, direction.z) / abs(direction.y); } else {\n uv = vec2(direction.x, direction.y) / abs(direction.z); }\n return 0.5 * (uv + 1.0);\n}\nvec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {\n float face = getFace(direction);\n float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);\n mipInt = max(mipInt, cubeUV_minMipLevel);\n float faceSize = exp2(mipInt);\n float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);\n vec2 uv = getUV(direction, face) * (faceSize - 1.0);\n vec2 f = fract(uv);\n uv += 0.5 - f;\n if (face > 2.0) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n if(mipInt < cubeUV_maxMipLevel){\n uv.y += 2.0 * cubeUV_maxTileSize;\n }\n uv.y += filterInt * 2.0 * cubeUV_minTileSize;\n uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);\n uv *= texelSize;\n vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x += texelSize;\n vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.y += texelSize;\n vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x -= texelSize;\n vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n vec3 tm = mix(tl, tr, f.x);\n vec3 bm = mix(bl, br, f.x);\n return mix(tm, bm, f.y);\n}\n#define r0 1.0\n#define v0 0.339\n#define m0 -2.0\n#define r1 0.8\n#define v1 0.276\n#define m1 -1.0\n#define r4 0.4\n#define v4 0.046\n#define m4 2.0\n#define r5 0.305\n#define v5 0.016\n#define m5 3.0\n#define r6 0.21\n#define v6 0.0038\n#define m6 4.0\nfloat roughnessToMip(float roughness) {\n float mip = 0.0;\n if (roughness >= r1) {\n mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;\n } else if (roughness >= r4) {\n mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;\n } else if (roughness >= r5) {\n mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;\n } else if (roughness >= r6) {\n mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;\n } else {\n mip = -2.0 * log2(1.16 * roughness); }\n return mip;\n}\nvec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {\n float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);\n float mipF = fract(mip);\n float mipInt = floor(mip);\n vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);\n if (mipF == 0.0) {\n return vec4(color0, 1.0);\n } else {\n vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);\n return vec4(mix(color0, color1, mipF), 1.0);\n }\n}\n#endif";
  8866. 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";
  8867. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8868. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8869. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8870. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8871. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8872. 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}";
  8873. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\t\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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\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";
  8874. 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";
  8875. 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";
  8876. 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";
  8877. 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";
  8878. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8879. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8880. 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";
  8881. 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";
  8882. 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}";
  8883. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8884. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8885. 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";
  8886. 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";
  8887. 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 vec3 reflectVec = reflect( -viewDir, normal );\n\t\t reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t vec3 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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  8888. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8889. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3\tdiffuseColor;\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)";
  8890. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8891. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\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)";
  8892. 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";
  8893. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\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}";
  8894. 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";
  8895. 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";
  8896. 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";
  8897. 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";
  8898. 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";
  8899. 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";
  8900. 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";
  8901. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8902. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8903. 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";
  8904. 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";
  8905. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8906. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8907. 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";
  8908. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  8909. 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\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  8910. 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;";
  8911. 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";
  8912. 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";
  8913. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8914. 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";
  8915. 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";
  8916. 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}";
  8917. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8918. 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;";
  8919. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8920. 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";
  8921. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8922. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8923. 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";
  8924. 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";
  8925. 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";
  8926. 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}";
  8927. 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";
  8928. 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";
  8929. 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";
  8930. 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";
  8931. 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";
  8932. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8933. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8934. 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; }";
  8935. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8936. 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";
  8937. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8938. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8939. 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";
  8940. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8941. 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";
  8942. 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}";
  8943. 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}";
  8944. 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}";
  8945. 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}";
  8946. 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}";
  8947. 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}";
  8948. 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}";
  8949. 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}";
  8950. 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}";
  8951. 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}";
  8952. 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}";
  8953. 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}";
  8954. 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}";
  8955. 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}";
  8956. 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}";
  8957. 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}";
  8958. 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}";
  8959. 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}";
  8960. 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}";
  8961. 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}";
  8962. 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}";
  8963. 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}";
  8964. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSPARENCY\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSPARENCY\n\tuniform float transparency;\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 <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#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSPARENCY\n\t\tdiffuseColor.a *= saturate( 1. - transparency + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );\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}";
  8965. 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}";
  8966. 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}";
  8967. 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}";
  8968. 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}";
  8969. 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}";
  8970. 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}";
  8971. 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}";
  8972. 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}";
  8973. 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}";
  8974. const ShaderChunk = {
  8975. alphamap_fragment: alphamap_fragment,
  8976. alphamap_pars_fragment: alphamap_pars_fragment,
  8977. alphatest_fragment: alphatest_fragment,
  8978. aomap_fragment: aomap_fragment,
  8979. aomap_pars_fragment: aomap_pars_fragment,
  8980. begin_vertex: begin_vertex,
  8981. beginnormal_vertex: beginnormal_vertex,
  8982. bsdfs: bsdfs,
  8983. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8984. clipping_planes_fragment: clipping_planes_fragment,
  8985. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8986. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8987. clipping_planes_vertex: clipping_planes_vertex,
  8988. color_fragment: color_fragment,
  8989. color_pars_fragment: color_pars_fragment,
  8990. color_pars_vertex: color_pars_vertex,
  8991. color_vertex: color_vertex,
  8992. common: common,
  8993. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8994. defaultnormal_vertex: defaultnormal_vertex,
  8995. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8996. displacementmap_vertex: displacementmap_vertex,
  8997. emissivemap_fragment: emissivemap_fragment,
  8998. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8999. encodings_fragment: encodings_fragment,
  9000. encodings_pars_fragment: encodings_pars_fragment,
  9001. envmap_fragment: envmap_fragment,
  9002. envmap_common_pars_fragment: envmap_common_pars_fragment,
  9003. envmap_pars_fragment: envmap_pars_fragment,
  9004. envmap_pars_vertex: envmap_pars_vertex,
  9005. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9006. envmap_vertex: envmap_vertex,
  9007. fog_vertex: fog_vertex,
  9008. fog_pars_vertex: fog_pars_vertex,
  9009. fog_fragment: fog_fragment,
  9010. fog_pars_fragment: fog_pars_fragment,
  9011. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9012. lightmap_fragment: lightmap_fragment,
  9013. lightmap_pars_fragment: lightmap_pars_fragment,
  9014. lights_lambert_vertex: lights_lambert_vertex,
  9015. lights_pars_begin: lights_pars_begin,
  9016. lights_toon_fragment: lights_toon_fragment,
  9017. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9018. lights_phong_fragment: lights_phong_fragment,
  9019. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9020. lights_physical_fragment: lights_physical_fragment,
  9021. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9022. lights_fragment_begin: lights_fragment_begin,
  9023. lights_fragment_maps: lights_fragment_maps,
  9024. lights_fragment_end: lights_fragment_end,
  9025. logdepthbuf_fragment: logdepthbuf_fragment,
  9026. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9027. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9028. logdepthbuf_vertex: logdepthbuf_vertex,
  9029. map_fragment: map_fragment,
  9030. map_pars_fragment: map_pars_fragment,
  9031. map_particle_fragment: map_particle_fragment,
  9032. map_particle_pars_fragment: map_particle_pars_fragment,
  9033. metalnessmap_fragment: metalnessmap_fragment,
  9034. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9035. morphnormal_vertex: morphnormal_vertex,
  9036. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9037. morphtarget_vertex: morphtarget_vertex,
  9038. normal_fragment_begin: normal_fragment_begin,
  9039. normal_fragment_maps: normal_fragment_maps,
  9040. normalmap_pars_fragment: normalmap_pars_fragment,
  9041. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9042. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9043. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9044. packing: packing,
  9045. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9046. project_vertex: project_vertex,
  9047. dithering_fragment: dithering_fragment,
  9048. dithering_pars_fragment: dithering_pars_fragment,
  9049. roughnessmap_fragment: roughnessmap_fragment,
  9050. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9051. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9052. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9053. shadowmap_vertex: shadowmap_vertex,
  9054. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9055. skinbase_vertex: skinbase_vertex,
  9056. skinning_pars_vertex: skinning_pars_vertex,
  9057. skinning_vertex: skinning_vertex,
  9058. skinnormal_vertex: skinnormal_vertex,
  9059. specularmap_fragment: specularmap_fragment,
  9060. specularmap_pars_fragment: specularmap_pars_fragment,
  9061. tonemapping_fragment: tonemapping_fragment,
  9062. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9063. uv_pars_fragment: uv_pars_fragment,
  9064. uv_pars_vertex: uv_pars_vertex,
  9065. uv_vertex: uv_vertex,
  9066. uv2_pars_fragment: uv2_pars_fragment,
  9067. uv2_pars_vertex: uv2_pars_vertex,
  9068. uv2_vertex: uv2_vertex,
  9069. worldpos_vertex: worldpos_vertex,
  9070. background_frag: background_frag,
  9071. background_vert: background_vert,
  9072. cube_frag: cube_frag,
  9073. cube_vert: cube_vert,
  9074. depth_frag: depth_frag,
  9075. depth_vert: depth_vert,
  9076. distanceRGBA_frag: distanceRGBA_frag,
  9077. distanceRGBA_vert: distanceRGBA_vert,
  9078. equirect_frag: equirect_frag,
  9079. equirect_vert: equirect_vert,
  9080. linedashed_frag: linedashed_frag,
  9081. linedashed_vert: linedashed_vert,
  9082. meshbasic_frag: meshbasic_frag,
  9083. meshbasic_vert: meshbasic_vert,
  9084. meshlambert_frag: meshlambert_frag,
  9085. meshlambert_vert: meshlambert_vert,
  9086. meshmatcap_frag: meshmatcap_frag,
  9087. meshmatcap_vert: meshmatcap_vert,
  9088. meshtoon_frag: meshtoon_frag,
  9089. meshtoon_vert: meshtoon_vert,
  9090. meshphong_frag: meshphong_frag,
  9091. meshphong_vert: meshphong_vert,
  9092. meshphysical_frag: meshphysical_frag,
  9093. meshphysical_vert: meshphysical_vert,
  9094. normal_frag: normal_frag,
  9095. normal_vert: normal_vert,
  9096. points_frag: points_frag,
  9097. points_vert: points_vert,
  9098. shadow_frag: shadow_frag,
  9099. shadow_vert: shadow_vert,
  9100. sprite_frag: sprite_frag,
  9101. sprite_vert: sprite_vert
  9102. };
  9103. /**
  9104. * @author alteredq / http://alteredqualia.com/
  9105. * @author mrdoob / http://mrdoob.com/
  9106. * @author mikael emtinger / http://gomo.se/
  9107. */
  9108. const ShaderLib = {
  9109. basic: {
  9110. uniforms: mergeUniforms( [
  9111. UniformsLib.common,
  9112. UniformsLib.specularmap,
  9113. UniformsLib.envmap,
  9114. UniformsLib.aomap,
  9115. UniformsLib.lightmap,
  9116. UniformsLib.fog
  9117. ] ),
  9118. vertexShader: ShaderChunk.meshbasic_vert,
  9119. fragmentShader: ShaderChunk.meshbasic_frag
  9120. },
  9121. lambert: {
  9122. uniforms: mergeUniforms( [
  9123. UniformsLib.common,
  9124. UniformsLib.specularmap,
  9125. UniformsLib.envmap,
  9126. UniformsLib.aomap,
  9127. UniformsLib.lightmap,
  9128. UniformsLib.emissivemap,
  9129. UniformsLib.fog,
  9130. UniformsLib.lights,
  9131. {
  9132. emissive: { value: new Color( 0x000000 ) }
  9133. }
  9134. ] ),
  9135. vertexShader: ShaderChunk.meshlambert_vert,
  9136. fragmentShader: ShaderChunk.meshlambert_frag
  9137. },
  9138. phong: {
  9139. uniforms: mergeUniforms( [
  9140. UniformsLib.common,
  9141. UniformsLib.specularmap,
  9142. UniformsLib.envmap,
  9143. UniformsLib.aomap,
  9144. UniformsLib.lightmap,
  9145. UniformsLib.emissivemap,
  9146. UniformsLib.bumpmap,
  9147. UniformsLib.normalmap,
  9148. UniformsLib.displacementmap,
  9149. UniformsLib.fog,
  9150. UniformsLib.lights,
  9151. {
  9152. emissive: { value: new Color( 0x000000 ) },
  9153. specular: { value: new Color( 0x111111 ) },
  9154. shininess: { value: 30 }
  9155. }
  9156. ] ),
  9157. vertexShader: ShaderChunk.meshphong_vert,
  9158. fragmentShader: ShaderChunk.meshphong_frag
  9159. },
  9160. standard: {
  9161. uniforms: mergeUniforms( [
  9162. UniformsLib.common,
  9163. UniformsLib.envmap,
  9164. UniformsLib.aomap,
  9165. UniformsLib.lightmap,
  9166. UniformsLib.emissivemap,
  9167. UniformsLib.bumpmap,
  9168. UniformsLib.normalmap,
  9169. UniformsLib.displacementmap,
  9170. UniformsLib.roughnessmap,
  9171. UniformsLib.metalnessmap,
  9172. UniformsLib.fog,
  9173. UniformsLib.lights,
  9174. {
  9175. emissive: { value: new Color( 0x000000 ) },
  9176. roughness: { value: 1.0 },
  9177. metalness: { value: 0.0 },
  9178. envMapIntensity: { value: 1 } // temporary
  9179. }
  9180. ] ),
  9181. vertexShader: ShaderChunk.meshphysical_vert,
  9182. fragmentShader: ShaderChunk.meshphysical_frag
  9183. },
  9184. toon: {
  9185. uniforms: mergeUniforms( [
  9186. UniformsLib.common,
  9187. UniformsLib.aomap,
  9188. UniformsLib.lightmap,
  9189. UniformsLib.emissivemap,
  9190. UniformsLib.bumpmap,
  9191. UniformsLib.normalmap,
  9192. UniformsLib.displacementmap,
  9193. UniformsLib.gradientmap,
  9194. UniformsLib.fog,
  9195. UniformsLib.lights,
  9196. {
  9197. emissive: { value: new Color( 0x000000 ) }
  9198. }
  9199. ] ),
  9200. vertexShader: ShaderChunk.meshtoon_vert,
  9201. fragmentShader: ShaderChunk.meshtoon_frag
  9202. },
  9203. matcap: {
  9204. uniforms: mergeUniforms( [
  9205. UniformsLib.common,
  9206. UniformsLib.bumpmap,
  9207. UniformsLib.normalmap,
  9208. UniformsLib.displacementmap,
  9209. UniformsLib.fog,
  9210. {
  9211. matcap: { value: null }
  9212. }
  9213. ] ),
  9214. vertexShader: ShaderChunk.meshmatcap_vert,
  9215. fragmentShader: ShaderChunk.meshmatcap_frag
  9216. },
  9217. points: {
  9218. uniforms: mergeUniforms( [
  9219. UniformsLib.points,
  9220. UniformsLib.fog
  9221. ] ),
  9222. vertexShader: ShaderChunk.points_vert,
  9223. fragmentShader: ShaderChunk.points_frag
  9224. },
  9225. dashed: {
  9226. uniforms: mergeUniforms( [
  9227. UniformsLib.common,
  9228. UniformsLib.fog,
  9229. {
  9230. scale: { value: 1 },
  9231. dashSize: { value: 1 },
  9232. totalSize: { value: 2 }
  9233. }
  9234. ] ),
  9235. vertexShader: ShaderChunk.linedashed_vert,
  9236. fragmentShader: ShaderChunk.linedashed_frag
  9237. },
  9238. depth: {
  9239. uniforms: mergeUniforms( [
  9240. UniformsLib.common,
  9241. UniformsLib.displacementmap
  9242. ] ),
  9243. vertexShader: ShaderChunk.depth_vert,
  9244. fragmentShader: ShaderChunk.depth_frag
  9245. },
  9246. normal: {
  9247. uniforms: mergeUniforms( [
  9248. UniformsLib.common,
  9249. UniformsLib.bumpmap,
  9250. UniformsLib.normalmap,
  9251. UniformsLib.displacementmap,
  9252. {
  9253. opacity: { value: 1.0 }
  9254. }
  9255. ] ),
  9256. vertexShader: ShaderChunk.normal_vert,
  9257. fragmentShader: ShaderChunk.normal_frag
  9258. },
  9259. sprite: {
  9260. uniforms: mergeUniforms( [
  9261. UniformsLib.sprite,
  9262. UniformsLib.fog
  9263. ] ),
  9264. vertexShader: ShaderChunk.sprite_vert,
  9265. fragmentShader: ShaderChunk.sprite_frag
  9266. },
  9267. background: {
  9268. uniforms: {
  9269. uvTransform: { value: new Matrix3() },
  9270. t2D: { value: null },
  9271. },
  9272. vertexShader: ShaderChunk.background_vert,
  9273. fragmentShader: ShaderChunk.background_frag
  9274. },
  9275. /* -------------------------------------------------------------------------
  9276. // Cube map shader
  9277. ------------------------------------------------------------------------- */
  9278. cube: {
  9279. uniforms: mergeUniforms( [
  9280. UniformsLib.envmap,
  9281. {
  9282. opacity: { value: 1.0 }
  9283. }
  9284. ] ),
  9285. vertexShader: ShaderChunk.cube_vert,
  9286. fragmentShader: ShaderChunk.cube_frag
  9287. },
  9288. equirect: {
  9289. uniforms: {
  9290. tEquirect: { value: null },
  9291. },
  9292. vertexShader: ShaderChunk.equirect_vert,
  9293. fragmentShader: ShaderChunk.equirect_frag
  9294. },
  9295. distanceRGBA: {
  9296. uniforms: mergeUniforms( [
  9297. UniformsLib.common,
  9298. UniformsLib.displacementmap,
  9299. {
  9300. referencePosition: { value: new Vector3() },
  9301. nearDistance: { value: 1 },
  9302. farDistance: { value: 1000 }
  9303. }
  9304. ] ),
  9305. vertexShader: ShaderChunk.distanceRGBA_vert,
  9306. fragmentShader: ShaderChunk.distanceRGBA_frag
  9307. },
  9308. shadow: {
  9309. uniforms: mergeUniforms( [
  9310. UniformsLib.lights,
  9311. UniformsLib.fog,
  9312. {
  9313. color: { value: new Color( 0x00000 ) },
  9314. opacity: { value: 1.0 }
  9315. },
  9316. ] ),
  9317. vertexShader: ShaderChunk.shadow_vert,
  9318. fragmentShader: ShaderChunk.shadow_frag
  9319. }
  9320. };
  9321. ShaderLib.physical = {
  9322. uniforms: mergeUniforms( [
  9323. ShaderLib.standard.uniforms,
  9324. {
  9325. clearcoat: { value: 0 },
  9326. clearcoatMap: { value: null },
  9327. clearcoatRoughness: { value: 0 },
  9328. clearcoatRoughnessMap: { value: null },
  9329. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  9330. clearcoatNormalMap: { value: null },
  9331. sheen: { value: new Color( 0x000000 ) },
  9332. transparency: { value: 0 },
  9333. }
  9334. ] ),
  9335. vertexShader: ShaderChunk.meshphysical_vert,
  9336. fragmentShader: ShaderChunk.meshphysical_frag
  9337. };
  9338. /**
  9339. * @author mrdoob / http://mrdoob.com/
  9340. */
  9341. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9342. const clearColor = new Color( 0x000000 );
  9343. let clearAlpha = 0;
  9344. let planeMesh;
  9345. let boxMesh;
  9346. let currentBackground = null;
  9347. let currentBackgroundVersion = 0;
  9348. let currentTonemapping = null;
  9349. function render( renderList, scene, camera, forceClear ) {
  9350. let background = scene.isScene === true ? scene.background : null;
  9351. // Ignore background in AR
  9352. // TODO: Reconsider this.
  9353. const xr = renderer.xr;
  9354. const session = xr.getSession && xr.getSession();
  9355. if ( session && session.environmentBlendMode === 'additive' ) {
  9356. background = null;
  9357. }
  9358. if ( background === null ) {
  9359. setClear( clearColor, clearAlpha );
  9360. } else if ( background && background.isColor ) {
  9361. setClear( background, 1 );
  9362. forceClear = true;
  9363. }
  9364. if ( renderer.autoClear || forceClear ) {
  9365. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9366. }
  9367. if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) {
  9368. if ( boxMesh === undefined ) {
  9369. boxMesh = new Mesh(
  9370. new BoxBufferGeometry( 1, 1, 1 ),
  9371. new ShaderMaterial( {
  9372. name: 'BackgroundCubeMaterial',
  9373. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9374. vertexShader: ShaderLib.cube.vertexShader,
  9375. fragmentShader: ShaderLib.cube.fragmentShader,
  9376. side: BackSide,
  9377. depthTest: false,
  9378. depthWrite: false,
  9379. fog: false
  9380. } )
  9381. );
  9382. boxMesh.geometry.deleteAttribute( 'normal' );
  9383. boxMesh.geometry.deleteAttribute( 'uv' );
  9384. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9385. this.matrixWorld.copyPosition( camera.matrixWorld );
  9386. };
  9387. // enable code injection for non-built-in material
  9388. Object.defineProperty( boxMesh.material, 'envMap', {
  9389. get: function () {
  9390. return this.uniforms.envMap.value;
  9391. }
  9392. } );
  9393. objects.update( boxMesh );
  9394. }
  9395. const texture = background.isWebGLCubeRenderTarget ? background.texture : background;
  9396. boxMesh.material.uniforms.envMap.value = texture;
  9397. boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1;
  9398. if ( currentBackground !== background ||
  9399. currentBackgroundVersion !== texture.version ||
  9400. currentTonemapping !== renderer.toneMapping ) {
  9401. boxMesh.material.needsUpdate = true;
  9402. currentBackground = background;
  9403. currentBackgroundVersion = texture.version;
  9404. currentTonemapping = renderer.toneMapping;
  9405. }
  9406. // push to the pre-sorted opaque render list
  9407. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9408. } else if ( background && background.isTexture ) {
  9409. if ( planeMesh === undefined ) {
  9410. planeMesh = new Mesh(
  9411. new PlaneBufferGeometry( 2, 2 ),
  9412. new ShaderMaterial( {
  9413. name: 'BackgroundMaterial',
  9414. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9415. vertexShader: ShaderLib.background.vertexShader,
  9416. fragmentShader: ShaderLib.background.fragmentShader,
  9417. side: FrontSide,
  9418. depthTest: false,
  9419. depthWrite: false,
  9420. fog: false
  9421. } )
  9422. );
  9423. planeMesh.geometry.deleteAttribute( 'normal' );
  9424. // enable code injection for non-built-in material
  9425. Object.defineProperty( planeMesh.material, 'map', {
  9426. get: function () {
  9427. return this.uniforms.t2D.value;
  9428. }
  9429. } );
  9430. objects.update( planeMesh );
  9431. }
  9432. planeMesh.material.uniforms.t2D.value = background;
  9433. if ( background.matrixAutoUpdate === true ) {
  9434. background.updateMatrix();
  9435. }
  9436. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9437. if ( currentBackground !== background ||
  9438. currentBackgroundVersion !== background.version ||
  9439. currentTonemapping !== renderer.toneMapping ) {
  9440. planeMesh.material.needsUpdate = true;
  9441. currentBackground = background;
  9442. currentBackgroundVersion = background.version;
  9443. currentTonemapping = renderer.toneMapping;
  9444. }
  9445. // push to the pre-sorted opaque render list
  9446. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9447. }
  9448. }
  9449. function setClear( color, alpha ) {
  9450. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9451. }
  9452. return {
  9453. getClearColor: function () {
  9454. return clearColor;
  9455. },
  9456. setClearColor: function ( color, alpha ) {
  9457. clearColor.set( color );
  9458. clearAlpha = alpha !== undefined ? alpha : 1;
  9459. setClear( clearColor, clearAlpha );
  9460. },
  9461. getClearAlpha: function () {
  9462. return clearAlpha;
  9463. },
  9464. setClearAlpha: function ( alpha ) {
  9465. clearAlpha = alpha;
  9466. setClear( clearColor, clearAlpha );
  9467. },
  9468. render: render
  9469. };
  9470. }
  9471. /**
  9472. * @author Mugen87 / https://github.com/Mugen87
  9473. * @author Takahiro / https://github.com/takahirox
  9474. */
  9475. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  9476. const maxVertexAttributes = gl.getParameter( 34921 );
  9477. const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  9478. const vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9479. const bindingStates = {};
  9480. const defaultState = createBindingState( null );
  9481. let currentState = defaultState;
  9482. function setup( object, material, program, geometry, index ) {
  9483. let updateBuffers = false;
  9484. if ( vaoAvailable ) {
  9485. const state = getBindingState( geometry, program, material );
  9486. if ( currentState !== state ) {
  9487. currentState = state;
  9488. bindVertexArrayObject( currentState.object );
  9489. }
  9490. updateBuffers = needsUpdate( geometry );
  9491. if ( updateBuffers ) saveCache( geometry );
  9492. } else {
  9493. const wireframe = ( material.wireframe === true );
  9494. if ( currentState.geometry !== geometry.id ||
  9495. currentState.program !== program.id ||
  9496. currentState.wireframe !== wireframe ) {
  9497. currentState.geometry = geometry.id;
  9498. currentState.program = program.id;
  9499. currentState.wireframe = wireframe;
  9500. updateBuffers = true;
  9501. }
  9502. }
  9503. if ( object.isInstancedMesh === true ) {
  9504. updateBuffers = true;
  9505. }
  9506. if ( index !== null ) {
  9507. attributes.update( index, 34963 );
  9508. }
  9509. if ( updateBuffers ) {
  9510. setupVertexAttributes( object, material, program, geometry );
  9511. if ( index !== null ) {
  9512. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  9513. }
  9514. }
  9515. }
  9516. function createVertexArrayObject() {
  9517. if ( capabilities.isWebGL2 ) return gl.createVertexArray();
  9518. return extension.createVertexArrayOES();
  9519. }
  9520. function bindVertexArrayObject( vao ) {
  9521. if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
  9522. return extension.bindVertexArrayOES( vao );
  9523. }
  9524. function deleteVertexArrayObject( vao ) {
  9525. if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
  9526. return extension.deleteVertexArrayOES( vao );
  9527. }
  9528. function getBindingState( geometry, program, material ) {
  9529. const wireframe = ( material.wireframe === true );
  9530. let programMap = bindingStates[ geometry.id ];
  9531. if ( programMap === undefined ) {
  9532. programMap = {};
  9533. bindingStates[ geometry.id ] = programMap;
  9534. }
  9535. let stateMap = programMap[ program.id ];
  9536. if ( stateMap === undefined ) {
  9537. stateMap = {};
  9538. programMap[ program.id ] = stateMap;
  9539. }
  9540. let state = stateMap[ wireframe ];
  9541. if ( state === undefined ) {
  9542. state = createBindingState( createVertexArrayObject() );
  9543. stateMap[ wireframe ] = state;
  9544. }
  9545. return state;
  9546. }
  9547. function createBindingState( vao ) {
  9548. const newAttributes = [];
  9549. const enabledAttributes = [];
  9550. const attributeDivisors = [];
  9551. for ( let i = 0; i < maxVertexAttributes; i ++ ) {
  9552. newAttributes[ i ] = 0;
  9553. enabledAttributes[ i ] = 0;
  9554. attributeDivisors[ i ] = 0;
  9555. }
  9556. return {
  9557. // for backward compatibility on non-VAO support browser
  9558. geometry: null,
  9559. program: null,
  9560. wireframe: false,
  9561. newAttributes: newAttributes,
  9562. enabledAttributes: enabledAttributes,
  9563. attributeDivisors: attributeDivisors,
  9564. object: vao,
  9565. attributes: {}
  9566. };
  9567. }
  9568. function needsUpdate( geometry ) {
  9569. const cachedAttributes = currentState.attributes;
  9570. const geometryAttributes = geometry.attributes;
  9571. if ( Object.keys( cachedAttributes ).length !== Object.keys( geometryAttributes ).length ) return true;
  9572. for ( const key in geometryAttributes ) {
  9573. const cachedAttribute = cachedAttributes[ key ];
  9574. const geometryAttribute = geometryAttributes[ key ];
  9575. if ( cachedAttribute.attribute !== geometryAttribute ) return true;
  9576. if ( cachedAttribute.data !== geometryAttribute.data ) return true;
  9577. }
  9578. return false;
  9579. }
  9580. function saveCache( geometry ) {
  9581. const cache = {};
  9582. const attributes = geometry.attributes;
  9583. for ( const key in attributes ) {
  9584. const attribute = attributes[ key ];
  9585. const data = {};
  9586. data.attribute = attribute;
  9587. if ( attribute.data ) {
  9588. data.data = attribute.data;
  9589. }
  9590. cache[ key ] = data;
  9591. }
  9592. currentState.attributes = cache;
  9593. }
  9594. function initAttributes() {
  9595. const newAttributes = currentState.newAttributes;
  9596. for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {
  9597. newAttributes[ i ] = 0;
  9598. }
  9599. }
  9600. function enableAttribute( attribute ) {
  9601. enableAttributeAndDivisor( attribute, 0 );
  9602. }
  9603. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  9604. const newAttributes = currentState.newAttributes;
  9605. const enabledAttributes = currentState.enabledAttributes;
  9606. const attributeDivisors = currentState.attributeDivisors;
  9607. newAttributes[ attribute ] = 1;
  9608. if ( enabledAttributes[ attribute ] === 0 ) {
  9609. gl.enableVertexAttribArray( attribute );
  9610. enabledAttributes[ attribute ] = 1;
  9611. }
  9612. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  9613. const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  9614. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  9615. attributeDivisors[ attribute ] = meshPerAttribute;
  9616. }
  9617. }
  9618. function disableUnusedAttributes() {
  9619. const newAttributes = currentState.newAttributes;
  9620. const enabledAttributes = currentState.enabledAttributes;
  9621. for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  9622. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  9623. gl.disableVertexAttribArray( i );
  9624. enabledAttributes[ i ] = 0;
  9625. }
  9626. }
  9627. }
  9628. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  9629. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  9630. gl.vertexAttribIPointer( index, size, type, normalized, stride, offset );
  9631. } else {
  9632. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  9633. }
  9634. }
  9635. function setupVertexAttributes( object, material, program, geometry ) {
  9636. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  9637. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  9638. }
  9639. initAttributes();
  9640. const geometryAttributes = geometry.attributes;
  9641. const programAttributes = program.getAttributes();
  9642. const materialDefaultAttributeValues = material.defaultAttributeValues;
  9643. for ( const name in programAttributes ) {
  9644. const programAttribute = programAttributes[ name ];
  9645. if ( programAttribute >= 0 ) {
  9646. const geometryAttribute = geometryAttributes[ name ];
  9647. if ( geometryAttribute !== undefined ) {
  9648. const normalized = geometryAttribute.normalized;
  9649. const size = geometryAttribute.itemSize;
  9650. const attribute = attributes.get( geometryAttribute );
  9651. // TODO Attribute may not be available on context restore
  9652. if ( attribute === undefined ) continue;
  9653. const buffer = attribute.buffer;
  9654. const type = attribute.type;
  9655. const bytesPerElement = attribute.bytesPerElement;
  9656. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  9657. const data = geometryAttribute.data;
  9658. const stride = data.stride;
  9659. const offset = geometryAttribute.offset;
  9660. if ( data && data.isInstancedInterleavedBuffer ) {
  9661. enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  9662. if ( geometry._maxInstanceCount === undefined ) {
  9663. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9664. }
  9665. } else {
  9666. enableAttribute( programAttribute );
  9667. }
  9668. gl.bindBuffer( 34962, buffer );
  9669. vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  9670. } else {
  9671. if ( geometryAttribute.isInstancedBufferAttribute ) {
  9672. enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  9673. if ( geometry._maxInstanceCount === undefined ) {
  9674. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9675. }
  9676. } else {
  9677. enableAttribute( programAttribute );
  9678. }
  9679. gl.bindBuffer( 34962, buffer );
  9680. vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  9681. }
  9682. } else if ( name === 'instanceMatrix' ) {
  9683. const attribute = attributes.get( object.instanceMatrix );
  9684. // TODO Attribute may not be available on context restore
  9685. if ( attribute === undefined ) continue;
  9686. const buffer = attribute.buffer;
  9687. const type = attribute.type;
  9688. enableAttributeAndDivisor( programAttribute + 0, 1 );
  9689. enableAttributeAndDivisor( programAttribute + 1, 1 );
  9690. enableAttributeAndDivisor( programAttribute + 2, 1 );
  9691. enableAttributeAndDivisor( programAttribute + 3, 1 );
  9692. gl.bindBuffer( 34962, buffer );
  9693. gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  9694. gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  9695. gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  9696. gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  9697. } else if ( materialDefaultAttributeValues !== undefined ) {
  9698. const value = materialDefaultAttributeValues[ name ];
  9699. if ( value !== undefined ) {
  9700. switch ( value.length ) {
  9701. case 2:
  9702. gl.vertexAttrib2fv( programAttribute, value );
  9703. break;
  9704. case 3:
  9705. gl.vertexAttrib3fv( programAttribute, value );
  9706. break;
  9707. case 4:
  9708. gl.vertexAttrib4fv( programAttribute, value );
  9709. break;
  9710. default:
  9711. gl.vertexAttrib1fv( programAttribute, value );
  9712. }
  9713. }
  9714. }
  9715. }
  9716. }
  9717. disableUnusedAttributes();
  9718. }
  9719. function dispose() {
  9720. reset();
  9721. for ( const geometryId in bindingStates ) {
  9722. const programMap = bindingStates[ geometryId ];
  9723. for ( const programId in programMap ) {
  9724. const stateMap = programMap[ programId ];
  9725. for ( const wireframe in stateMap ) {
  9726. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9727. delete stateMap[ wireframe ];
  9728. }
  9729. delete programMap[ programId ];
  9730. }
  9731. delete bindingStates[ geometryId ];
  9732. }
  9733. }
  9734. function releaseStatesOfGeometry( geometry ) {
  9735. if ( bindingStates[ geometry.id ] === undefined ) return;
  9736. const programMap = bindingStates[ geometry.id ];
  9737. for ( const programId in programMap ) {
  9738. const stateMap = programMap[ programId ];
  9739. for ( const wireframe in stateMap ) {
  9740. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9741. delete stateMap[ wireframe ];
  9742. }
  9743. delete programMap[ programId ];
  9744. }
  9745. delete bindingStates[ geometry.id ];
  9746. }
  9747. function releaseStatesOfProgram( program ) {
  9748. for ( const geometryId in bindingStates ) {
  9749. const programMap = bindingStates[ geometryId ];
  9750. if ( programMap[ program.id ] === undefined ) continue;
  9751. const stateMap = programMap[ program.id ];
  9752. for ( const wireframe in stateMap ) {
  9753. deleteVertexArrayObject( stateMap[ wireframe ].object );
  9754. delete stateMap[ wireframe ];
  9755. }
  9756. delete programMap[ program.id ];
  9757. }
  9758. }
  9759. function reset() {
  9760. resetDefaultState();
  9761. if ( currentState === defaultState ) return;
  9762. currentState = defaultState;
  9763. bindVertexArrayObject( currentState.object );
  9764. }
  9765. // for backward-compatilibity
  9766. function resetDefaultState() {
  9767. defaultState.geometry = null;
  9768. defaultState.program = null;
  9769. defaultState.wireframe = false;
  9770. }
  9771. return {
  9772. setup: setup,
  9773. reset: reset,
  9774. resetDefaultState: resetDefaultState,
  9775. dispose: dispose,
  9776. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9777. releaseStatesOfProgram: releaseStatesOfProgram,
  9778. initAttributes: initAttributes,
  9779. enableAttribute: enableAttribute,
  9780. disableUnusedAttributes: disableUnusedAttributes
  9781. };
  9782. }
  9783. /**
  9784. * @author mrdoob / http://mrdoob.com/
  9785. */
  9786. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9787. const isWebGL2 = capabilities.isWebGL2;
  9788. let mode;
  9789. function setMode( value ) {
  9790. mode = value;
  9791. }
  9792. function render( start, count ) {
  9793. gl.drawArrays( mode, start, count );
  9794. info.update( count, mode );
  9795. }
  9796. function renderInstances( geometry, start, count, primcount ) {
  9797. if ( primcount === 0 ) return;
  9798. let extension, methodName;
  9799. if ( isWebGL2 ) {
  9800. extension = gl;
  9801. methodName = 'drawArraysInstanced';
  9802. } else {
  9803. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9804. methodName = 'drawArraysInstancedANGLE';
  9805. if ( extension === null ) {
  9806. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9807. return;
  9808. }
  9809. }
  9810. extension[ methodName ]( mode, start, count, primcount );
  9811. info.update( count, mode, primcount );
  9812. }
  9813. //
  9814. this.setMode = setMode;
  9815. this.render = render;
  9816. this.renderInstances = renderInstances;
  9817. }
  9818. /**
  9819. * @author mrdoob / http://mrdoob.com/
  9820. */
  9821. function WebGLCapabilities( gl, extensions, parameters ) {
  9822. let maxAnisotropy;
  9823. function getMaxAnisotropy() {
  9824. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9825. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9826. if ( extension !== null ) {
  9827. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9828. } else {
  9829. maxAnisotropy = 0;
  9830. }
  9831. return maxAnisotropy;
  9832. }
  9833. function getMaxPrecision( precision ) {
  9834. if ( precision === 'highp' ) {
  9835. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9836. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9837. return 'highp';
  9838. }
  9839. precision = 'mediump';
  9840. }
  9841. if ( precision === 'mediump' ) {
  9842. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9843. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9844. return 'mediump';
  9845. }
  9846. }
  9847. return 'lowp';
  9848. }
  9849. /* eslint-disable no-undef */
  9850. const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  9851. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  9852. /* eslint-enable no-undef */
  9853. let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9854. const maxPrecision = getMaxPrecision( precision );
  9855. if ( maxPrecision !== precision ) {
  9856. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9857. precision = maxPrecision;
  9858. }
  9859. const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9860. const maxTextures = gl.getParameter( 34930 );
  9861. const maxVertexTextures = gl.getParameter( 35660 );
  9862. const maxTextureSize = gl.getParameter( 3379 );
  9863. const maxCubemapSize = gl.getParameter( 34076 );
  9864. const maxAttributes = gl.getParameter( 34921 );
  9865. const maxVertexUniforms = gl.getParameter( 36347 );
  9866. const maxVaryings = gl.getParameter( 36348 );
  9867. const maxFragmentUniforms = gl.getParameter( 36349 );
  9868. const vertexTextures = maxVertexTextures > 0;
  9869. const floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9870. const floatVertexTextures = vertexTextures && floatFragmentTextures;
  9871. const maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9872. return {
  9873. isWebGL2: isWebGL2,
  9874. getMaxAnisotropy: getMaxAnisotropy,
  9875. getMaxPrecision: getMaxPrecision,
  9876. precision: precision,
  9877. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9878. maxTextures: maxTextures,
  9879. maxVertexTextures: maxVertexTextures,
  9880. maxTextureSize: maxTextureSize,
  9881. maxCubemapSize: maxCubemapSize,
  9882. maxAttributes: maxAttributes,
  9883. maxVertexUniforms: maxVertexUniforms,
  9884. maxVaryings: maxVaryings,
  9885. maxFragmentUniforms: maxFragmentUniforms,
  9886. vertexTextures: vertexTextures,
  9887. floatFragmentTextures: floatFragmentTextures,
  9888. floatVertexTextures: floatVertexTextures,
  9889. maxSamples: maxSamples
  9890. };
  9891. }
  9892. /**
  9893. * @author tschw
  9894. */
  9895. function WebGLClipping() {
  9896. const scope = this;
  9897. let globalState = null,
  9898. numGlobalPlanes = 0,
  9899. localClippingEnabled = false,
  9900. renderingShadows = false;
  9901. const plane = new Plane(),
  9902. viewNormalMatrix = new Matrix3(),
  9903. uniform = { value: null, needsUpdate: false };
  9904. this.uniform = uniform;
  9905. this.numPlanes = 0;
  9906. this.numIntersection = 0;
  9907. this.init = function ( planes, enableLocalClipping, camera ) {
  9908. const enabled =
  9909. planes.length !== 0 ||
  9910. enableLocalClipping ||
  9911. // enable state of previous frame - the clipping code has to
  9912. // run another frame in order to reset the state:
  9913. numGlobalPlanes !== 0 ||
  9914. localClippingEnabled;
  9915. localClippingEnabled = enableLocalClipping;
  9916. globalState = projectPlanes( planes, camera, 0 );
  9917. numGlobalPlanes = planes.length;
  9918. return enabled;
  9919. };
  9920. this.beginShadows = function () {
  9921. renderingShadows = true;
  9922. projectPlanes( null );
  9923. };
  9924. this.endShadows = function () {
  9925. renderingShadows = false;
  9926. resetGlobalState();
  9927. };
  9928. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9929. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9930. // there's no local clipping
  9931. if ( renderingShadows ) {
  9932. // there's no global clipping
  9933. projectPlanes( null );
  9934. } else {
  9935. resetGlobalState();
  9936. }
  9937. } else {
  9938. const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9939. lGlobal = nGlobal * 4;
  9940. let dstArray = cache.clippingState || null;
  9941. uniform.value = dstArray; // ensure unique state
  9942. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9943. for ( let i = 0; i !== lGlobal; ++ i ) {
  9944. dstArray[ i ] = globalState[ i ];
  9945. }
  9946. cache.clippingState = dstArray;
  9947. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9948. this.numPlanes += nGlobal;
  9949. }
  9950. };
  9951. function resetGlobalState() {
  9952. if ( uniform.value !== globalState ) {
  9953. uniform.value = globalState;
  9954. uniform.needsUpdate = numGlobalPlanes > 0;
  9955. }
  9956. scope.numPlanes = numGlobalPlanes;
  9957. scope.numIntersection = 0;
  9958. }
  9959. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9960. let nPlanes = planes !== null ? planes.length : 0,
  9961. dstArray = null;
  9962. if ( nPlanes !== 0 ) {
  9963. dstArray = uniform.value;
  9964. if ( skipTransform !== true || dstArray === null ) {
  9965. const flatSize = dstOffset + nPlanes * 4,
  9966. viewMatrix = camera.matrixWorldInverse;
  9967. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9968. if ( dstArray === null || dstArray.length < flatSize ) {
  9969. dstArray = new Float32Array( flatSize );
  9970. }
  9971. for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9972. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9973. plane.normal.toArray( dstArray, i4 );
  9974. dstArray[ i4 + 3 ] = plane.constant;
  9975. }
  9976. }
  9977. uniform.value = dstArray;
  9978. uniform.needsUpdate = true;
  9979. }
  9980. scope.numPlanes = nPlanes;
  9981. scope.numIntersection = 0;
  9982. return dstArray;
  9983. }
  9984. }
  9985. /**
  9986. * @author mrdoob / http://mrdoob.com/
  9987. */
  9988. function WebGLExtensions( gl ) {
  9989. const extensions = {};
  9990. return {
  9991. get: function ( name ) {
  9992. if ( extensions[ name ] !== undefined ) {
  9993. return extensions[ name ];
  9994. }
  9995. let extension;
  9996. switch ( name ) {
  9997. case 'WEBGL_depth_texture':
  9998. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9999. break;
  10000. case 'EXT_texture_filter_anisotropic':
  10001. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  10002. break;
  10003. case 'WEBGL_compressed_texture_s3tc':
  10004. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  10005. break;
  10006. case 'WEBGL_compressed_texture_pvrtc':
  10007. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  10008. break;
  10009. default:
  10010. extension = gl.getExtension( name );
  10011. }
  10012. if ( extension === null ) {
  10013. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  10014. }
  10015. extensions[ name ] = extension;
  10016. return extension;
  10017. }
  10018. };
  10019. }
  10020. /**
  10021. * @author mrdoob / http://mrdoob.com/
  10022. */
  10023. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  10024. const geometries = new WeakMap();
  10025. const wireframeAttributes = new WeakMap();
  10026. function onGeometryDispose( event ) {
  10027. const geometry = event.target;
  10028. const buffergeometry = geometries.get( geometry );
  10029. if ( buffergeometry.index !== null ) {
  10030. attributes.remove( buffergeometry.index );
  10031. }
  10032. for ( const name in buffergeometry.attributes ) {
  10033. attributes.remove( buffergeometry.attributes[ name ] );
  10034. }
  10035. geometry.removeEventListener( 'dispose', onGeometryDispose );
  10036. geometries.delete( geometry );
  10037. const attribute = wireframeAttributes.get( buffergeometry );
  10038. if ( attribute ) {
  10039. attributes.remove( attribute );
  10040. wireframeAttributes.delete( buffergeometry );
  10041. }
  10042. bindingStates.releaseStatesOfGeometry( geometry );
  10043. if ( geometry.isInstancedBufferGeometry === true ) {
  10044. delete geometry._maxInstanceCount;
  10045. }
  10046. //
  10047. info.memory.geometries --;
  10048. }
  10049. function get( object, geometry ) {
  10050. let buffergeometry = geometries.get( geometry );
  10051. if ( buffergeometry ) return buffergeometry;
  10052. geometry.addEventListener( 'dispose', onGeometryDispose );
  10053. if ( geometry.isBufferGeometry ) {
  10054. buffergeometry = geometry;
  10055. } else if ( geometry.isGeometry ) {
  10056. if ( geometry._bufferGeometry === undefined ) {
  10057. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  10058. }
  10059. buffergeometry = geometry._bufferGeometry;
  10060. }
  10061. geometries.set( geometry, buffergeometry );
  10062. info.memory.geometries ++;
  10063. return buffergeometry;
  10064. }
  10065. function update( geometry ) {
  10066. const geometryAttributes = geometry.attributes;
  10067. // Updating index buffer in VAO now. See WebGLBindingStates.
  10068. for ( const name in geometryAttributes ) {
  10069. attributes.update( geometryAttributes[ name ], 34962 );
  10070. }
  10071. // morph targets
  10072. const morphAttributes = geometry.morphAttributes;
  10073. for ( const name in morphAttributes ) {
  10074. const array = morphAttributes[ name ];
  10075. for ( let i = 0, l = array.length; i < l; i ++ ) {
  10076. attributes.update( array[ i ], 34962 );
  10077. }
  10078. }
  10079. }
  10080. function updateWireframeAttribute( geometry ) {
  10081. const indices = [];
  10082. const geometryIndex = geometry.index;
  10083. const geometryPosition = geometry.attributes.position;
  10084. let version = 0;
  10085. if ( geometryIndex !== null ) {
  10086. const array = geometryIndex.array;
  10087. version = geometryIndex.version;
  10088. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  10089. const a = array[ i + 0 ];
  10090. const b = array[ i + 1 ];
  10091. const c = array[ i + 2 ];
  10092. indices.push( a, b, b, c, c, a );
  10093. }
  10094. } else {
  10095. const array = geometryPosition.array;
  10096. version = geometryPosition.version;
  10097. for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  10098. const a = i + 0;
  10099. const b = i + 1;
  10100. const c = i + 2;
  10101. indices.push( a, b, b, c, c, a );
  10102. }
  10103. }
  10104. const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  10105. attribute.version = version;
  10106. // Updating index buffer in VAO now. See WebGLBindingStates
  10107. //
  10108. const previousAttribute = wireframeAttributes.get( geometry );
  10109. if ( previousAttribute ) attributes.remove( previousAttribute );
  10110. //
  10111. wireframeAttributes.set( geometry, attribute );
  10112. }
  10113. function getWireframeAttribute( geometry ) {
  10114. const currentAttribute = wireframeAttributes.get( geometry );
  10115. if ( currentAttribute ) {
  10116. const geometryIndex = geometry.index;
  10117. if ( geometryIndex !== null ) {
  10118. // if the attribute is obsolete, create a new one
  10119. if ( currentAttribute.version < geometryIndex.version ) {
  10120. updateWireframeAttribute( geometry );
  10121. }
  10122. }
  10123. } else {
  10124. updateWireframeAttribute( geometry );
  10125. }
  10126. return wireframeAttributes.get( geometry );
  10127. }
  10128. return {
  10129. get: get,
  10130. update: update,
  10131. getWireframeAttribute: getWireframeAttribute
  10132. };
  10133. }
  10134. /**
  10135. * @author mrdoob / http://mrdoob.com/
  10136. */
  10137. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  10138. const isWebGL2 = capabilities.isWebGL2;
  10139. let mode;
  10140. function setMode( value ) {
  10141. mode = value;
  10142. }
  10143. let type, bytesPerElement;
  10144. function setIndex( value ) {
  10145. type = value.type;
  10146. bytesPerElement = value.bytesPerElement;
  10147. }
  10148. function render( start, count ) {
  10149. gl.drawElements( mode, count, type, start * bytesPerElement );
  10150. info.update( count, mode );
  10151. }
  10152. function renderInstances( geometry, start, count, primcount ) {
  10153. if ( primcount === 0 ) return;
  10154. let extension, methodName;
  10155. if ( isWebGL2 ) {
  10156. extension = gl;
  10157. methodName = 'drawElementsInstanced';
  10158. } else {
  10159. extension = extensions.get( 'ANGLE_instanced_arrays' );
  10160. methodName = 'drawElementsInstancedANGLE';
  10161. if ( extension === null ) {
  10162. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  10163. return;
  10164. }
  10165. }
  10166. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  10167. info.update( count, mode, primcount );
  10168. }
  10169. //
  10170. this.setMode = setMode;
  10171. this.setIndex = setIndex;
  10172. this.render = render;
  10173. this.renderInstances = renderInstances;
  10174. }
  10175. /**
  10176. * @author Mugen87 / https://github.com/Mugen87
  10177. */
  10178. function WebGLInfo( gl ) {
  10179. const memory = {
  10180. geometries: 0,
  10181. textures: 0
  10182. };
  10183. const render = {
  10184. frame: 0,
  10185. calls: 0,
  10186. triangles: 0,
  10187. points: 0,
  10188. lines: 0
  10189. };
  10190. function update( count, mode, instanceCount ) {
  10191. instanceCount = instanceCount || 1;
  10192. render.calls ++;
  10193. switch ( mode ) {
  10194. case 4:
  10195. render.triangles += instanceCount * ( count / 3 );
  10196. break;
  10197. case 1:
  10198. render.lines += instanceCount * ( count / 2 );
  10199. break;
  10200. case 3:
  10201. render.lines += instanceCount * ( count - 1 );
  10202. break;
  10203. case 2:
  10204. render.lines += instanceCount * count;
  10205. break;
  10206. case 0:
  10207. render.points += instanceCount * count;
  10208. break;
  10209. default:
  10210. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  10211. break;
  10212. }
  10213. }
  10214. function reset() {
  10215. render.frame ++;
  10216. render.calls = 0;
  10217. render.triangles = 0;
  10218. render.points = 0;
  10219. render.lines = 0;
  10220. }
  10221. return {
  10222. memory: memory,
  10223. render: render,
  10224. programs: null,
  10225. autoReset: true,
  10226. reset: reset,
  10227. update: update
  10228. };
  10229. }
  10230. /**
  10231. * @author mrdoob / http://mrdoob.com/
  10232. */
  10233. function numericalSort( a, b ) {
  10234. return a[ 0 ] - b[ 0 ];
  10235. }
  10236. function absNumericalSort( a, b ) {
  10237. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  10238. }
  10239. function WebGLMorphtargets( gl ) {
  10240. const influencesList = {};
  10241. const morphInfluences = new Float32Array( 8 );
  10242. const workInfluences = [];
  10243. for ( let i = 0; i < 8; i ++ ) {
  10244. workInfluences[ i ] = [ i, 0 ];
  10245. }
  10246. function update( object, geometry, material, program ) {
  10247. const objectInfluences = object.morphTargetInfluences;
  10248. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10249. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10250. const length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10251. let influences = influencesList[ geometry.id ];
  10252. if ( influences === undefined ) {
  10253. // initialise list
  10254. influences = [];
  10255. for ( let i = 0; i < length; i ++ ) {
  10256. influences[ i ] = [ i, 0 ];
  10257. }
  10258. influencesList[ geometry.id ] = influences;
  10259. }
  10260. // Collect influences
  10261. for ( let i = 0; i < length; i ++ ) {
  10262. const influence = influences[ i ];
  10263. influence[ 0 ] = i;
  10264. influence[ 1 ] = objectInfluences[ i ];
  10265. }
  10266. influences.sort( absNumericalSort );
  10267. for ( let i = 0; i < 8; i ++ ) {
  10268. if ( i < length && influences[ i ][ 1 ] ) {
  10269. workInfluences[ i ][ 0 ] = influences[ i ][ 0 ];
  10270. workInfluences[ i ][ 1 ] = influences[ i ][ 1 ];
  10271. } else {
  10272. workInfluences[ i ][ 0 ] = Number.MAX_SAFE_INTEGER;
  10273. workInfluences[ i ][ 1 ] = 0;
  10274. }
  10275. }
  10276. workInfluences.sort( numericalSort );
  10277. const morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10278. const morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10279. let morphInfluencesSum = 0;
  10280. for ( let i = 0; i < 8; i ++ ) {
  10281. const influence = workInfluences[ i ];
  10282. const index = influence[ 0 ];
  10283. const value = influence[ 1 ];
  10284. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  10285. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== morphTargets[ index ] ) {
  10286. geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  10287. }
  10288. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== morphNormals[ index ] ) {
  10289. geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  10290. }
  10291. morphInfluences[ i ] = value;
  10292. morphInfluencesSum += value;
  10293. } else {
  10294. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== undefined ) {
  10295. geometry.deleteAttribute( 'morphTarget' + i );
  10296. }
  10297. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== undefined ) {
  10298. geometry.deleteAttribute( 'morphNormal' + i );
  10299. }
  10300. morphInfluences[ i ] = 0;
  10301. }
  10302. }
  10303. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10304. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10305. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10306. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10307. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  10308. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  10309. }
  10310. return {
  10311. update: update
  10312. };
  10313. }
  10314. /**
  10315. * @author mrdoob / http://mrdoob.com/
  10316. */
  10317. function WebGLObjects( gl, geometries, attributes, info ) {
  10318. let updateMap = new WeakMap();
  10319. function update( object ) {
  10320. const frame = info.render.frame;
  10321. const geometry = object.geometry;
  10322. const buffergeometry = geometries.get( object, geometry );
  10323. // Update once per frame
  10324. if ( updateMap.get( buffergeometry ) !== frame ) {
  10325. if ( geometry.isGeometry ) {
  10326. buffergeometry.updateFromObject( object );
  10327. }
  10328. geometries.update( buffergeometry );
  10329. updateMap.set( buffergeometry, frame );
  10330. }
  10331. if ( object.isInstancedMesh ) {
  10332. attributes.update( object.instanceMatrix, 34962 );
  10333. }
  10334. return buffergeometry;
  10335. }
  10336. function dispose() {
  10337. updateMap = new WeakMap();
  10338. }
  10339. return {
  10340. update: update,
  10341. dispose: dispose
  10342. };
  10343. }
  10344. /**
  10345. * @author mrdoob / http://mrdoob.com/
  10346. */
  10347. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  10348. images = images !== undefined ? images : [];
  10349. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  10350. format = format !== undefined ? format : RGBFormat;
  10351. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  10352. this.flipY = false;
  10353. }
  10354. CubeTexture.prototype = Object.create( Texture.prototype );
  10355. CubeTexture.prototype.constructor = CubeTexture;
  10356. CubeTexture.prototype.isCubeTexture = true;
  10357. Object.defineProperty( CubeTexture.prototype, 'images', {
  10358. get: function () {
  10359. return this.image;
  10360. },
  10361. set: function ( value ) {
  10362. this.image = value;
  10363. }
  10364. } );
  10365. /**
  10366. * @author Takahiro https://github.com/takahirox
  10367. */
  10368. function DataTexture2DArray( data, width, height, depth ) {
  10369. Texture.call( this, null );
  10370. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10371. this.magFilter = NearestFilter;
  10372. this.minFilter = NearestFilter;
  10373. this.wrapR = ClampToEdgeWrapping;
  10374. this.generateMipmaps = false;
  10375. this.flipY = false;
  10376. this.needsUpdate = true;
  10377. }
  10378. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  10379. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10380. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10381. /**
  10382. * @author Artur Trzesiok
  10383. */
  10384. function DataTexture3D( data, width, height, depth ) {
  10385. // We're going to add .setXXX() methods for setting properties later.
  10386. // Users can still set in DataTexture3D directly.
  10387. //
  10388. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10389. // texture.anisotropy = 16;
  10390. //
  10391. // See #14839
  10392. Texture.call( this, null );
  10393. this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 };
  10394. this.magFilter = NearestFilter;
  10395. this.minFilter = NearestFilter;
  10396. this.wrapR = ClampToEdgeWrapping;
  10397. this.generateMipmaps = false;
  10398. this.flipY = false;
  10399. this.needsUpdate = true;
  10400. }
  10401. DataTexture3D.prototype = Object.create( Texture.prototype );
  10402. DataTexture3D.prototype.constructor = DataTexture3D;
  10403. DataTexture3D.prototype.isDataTexture3D = true;
  10404. /**
  10405. * @author tschw
  10406. * @author Mugen87 / https://github.com/Mugen87
  10407. * @author mrdoob / http://mrdoob.com/
  10408. *
  10409. * Uniforms of a program.
  10410. * Those form a tree structure with a special top-level container for the root,
  10411. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10412. *
  10413. *
  10414. * Properties of inner nodes including the top-level container:
  10415. *
  10416. * .seq - array of nested uniforms
  10417. * .map - nested uniforms by name
  10418. *
  10419. *
  10420. * Methods of all nodes except the top-level container:
  10421. *
  10422. * .setValue( gl, value, [textures] )
  10423. *
  10424. * uploads a uniform value(s)
  10425. * the 'textures' parameter is needed for sampler uniforms
  10426. *
  10427. *
  10428. * Static methods of the top-level container (textures factorizations):
  10429. *
  10430. * .upload( gl, seq, values, textures )
  10431. *
  10432. * sets uniforms in 'seq' to 'values[id].value'
  10433. *
  10434. * .seqWithValue( seq, values ) : filteredSeq
  10435. *
  10436. * filters 'seq' entries with corresponding entry in values
  10437. *
  10438. *
  10439. * Methods of the top-level container (textures factorizations):
  10440. *
  10441. * .setValue( gl, name, value, textures )
  10442. *
  10443. * sets uniform with name 'name' to 'value'
  10444. *
  10445. * .setOptional( gl, obj, prop )
  10446. *
  10447. * like .set for an optional property of the object
  10448. *
  10449. */
  10450. const emptyTexture = new Texture();
  10451. const emptyTexture2dArray = new DataTexture2DArray();
  10452. const emptyTexture3d = new DataTexture3D();
  10453. const emptyCubeTexture = new CubeTexture();
  10454. // --- Utilities ---
  10455. // Array Caches (provide typed arrays for temporary by size)
  10456. const arrayCacheF32 = [];
  10457. const arrayCacheI32 = [];
  10458. // Float32Array caches used for uploading Matrix uniforms
  10459. const mat4array = new Float32Array( 16 );
  10460. const mat3array = new Float32Array( 9 );
  10461. const mat2array = new Float32Array( 4 );
  10462. // Flattening for arrays of vectors and matrices
  10463. function flatten( array, nBlocks, blockSize ) {
  10464. const firstElem = array[ 0 ];
  10465. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10466. // unoptimized: ! isNaN( firstElem )
  10467. // see http://jacksondunstan.com/articles/983
  10468. let n = nBlocks * blockSize,
  10469. r = arrayCacheF32[ n ];
  10470. if ( r === undefined ) {
  10471. r = new Float32Array( n );
  10472. arrayCacheF32[ n ] = r;
  10473. }
  10474. if ( nBlocks !== 0 ) {
  10475. firstElem.toArray( r, 0 );
  10476. for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10477. offset += blockSize;
  10478. array[ i ].toArray( r, offset );
  10479. }
  10480. }
  10481. return r;
  10482. }
  10483. function arraysEqual( a, b ) {
  10484. if ( a.length !== b.length ) return false;
  10485. for ( let i = 0, l = a.length; i < l; i ++ ) {
  10486. if ( a[ i ] !== b[ i ] ) return false;
  10487. }
  10488. return true;
  10489. }
  10490. function copyArray( a, b ) {
  10491. for ( let i = 0, l = b.length; i < l; i ++ ) {
  10492. a[ i ] = b[ i ];
  10493. }
  10494. }
  10495. // Texture unit allocation
  10496. function allocTexUnits( textures, n ) {
  10497. let r = arrayCacheI32[ n ];
  10498. if ( r === undefined ) {
  10499. r = new Int32Array( n );
  10500. arrayCacheI32[ n ] = r;
  10501. }
  10502. for ( let i = 0; i !== n; ++ i ) {
  10503. r[ i ] = textures.allocateTextureUnit();
  10504. }
  10505. return r;
  10506. }
  10507. // --- Setters ---
  10508. // Note: Defining these methods externally, because they come in a bunch
  10509. // and this way their names minify.
  10510. // Single scalar
  10511. function setValueV1f( gl, v ) {
  10512. const cache = this.cache;
  10513. if ( cache[ 0 ] === v ) return;
  10514. gl.uniform1f( this.addr, v );
  10515. cache[ 0 ] = v;
  10516. }
  10517. // Single float vector (from flat array or THREE.VectorN)
  10518. function setValueV2f( gl, v ) {
  10519. const cache = this.cache;
  10520. if ( v.x !== undefined ) {
  10521. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10522. gl.uniform2f( this.addr, v.x, v.y );
  10523. cache[ 0 ] = v.x;
  10524. cache[ 1 ] = v.y;
  10525. }
  10526. } else {
  10527. if ( arraysEqual( cache, v ) ) return;
  10528. gl.uniform2fv( this.addr, v );
  10529. copyArray( cache, v );
  10530. }
  10531. }
  10532. function setValueV3f( gl, v ) {
  10533. const cache = this.cache;
  10534. if ( v.x !== undefined ) {
  10535. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10536. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10537. cache[ 0 ] = v.x;
  10538. cache[ 1 ] = v.y;
  10539. cache[ 2 ] = v.z;
  10540. }
  10541. } else if ( v.r !== undefined ) {
  10542. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10543. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10544. cache[ 0 ] = v.r;
  10545. cache[ 1 ] = v.g;
  10546. cache[ 2 ] = v.b;
  10547. }
  10548. } else {
  10549. if ( arraysEqual( cache, v ) ) return;
  10550. gl.uniform3fv( this.addr, v );
  10551. copyArray( cache, v );
  10552. }
  10553. }
  10554. function setValueV4f( gl, v ) {
  10555. const cache = this.cache;
  10556. if ( v.x !== undefined ) {
  10557. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10558. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10559. cache[ 0 ] = v.x;
  10560. cache[ 1 ] = v.y;
  10561. cache[ 2 ] = v.z;
  10562. cache[ 3 ] = v.w;
  10563. }
  10564. } else {
  10565. if ( arraysEqual( cache, v ) ) return;
  10566. gl.uniform4fv( this.addr, v );
  10567. copyArray( cache, v );
  10568. }
  10569. }
  10570. // Single matrix (from flat array or MatrixN)
  10571. function setValueM2( gl, v ) {
  10572. const cache = this.cache;
  10573. const elements = v.elements;
  10574. if ( elements === undefined ) {
  10575. if ( arraysEqual( cache, v ) ) return;
  10576. gl.uniformMatrix2fv( this.addr, false, v );
  10577. copyArray( cache, v );
  10578. } else {
  10579. if ( arraysEqual( cache, elements ) ) return;
  10580. mat2array.set( elements );
  10581. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10582. copyArray( cache, elements );
  10583. }
  10584. }
  10585. function setValueM3( gl, v ) {
  10586. const cache = this.cache;
  10587. const elements = v.elements;
  10588. if ( elements === undefined ) {
  10589. if ( arraysEqual( cache, v ) ) return;
  10590. gl.uniformMatrix3fv( this.addr, false, v );
  10591. copyArray( cache, v );
  10592. } else {
  10593. if ( arraysEqual( cache, elements ) ) return;
  10594. mat3array.set( elements );
  10595. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10596. copyArray( cache, elements );
  10597. }
  10598. }
  10599. function setValueM4( gl, v ) {
  10600. const cache = this.cache;
  10601. const elements = v.elements;
  10602. if ( elements === undefined ) {
  10603. if ( arraysEqual( cache, v ) ) return;
  10604. gl.uniformMatrix4fv( this.addr, false, v );
  10605. copyArray( cache, v );
  10606. } else {
  10607. if ( arraysEqual( cache, elements ) ) return;
  10608. mat4array.set( elements );
  10609. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10610. copyArray( cache, elements );
  10611. }
  10612. }
  10613. // Single texture (2D / Cube)
  10614. function setValueT1( gl, v, textures ) {
  10615. const cache = this.cache;
  10616. const unit = textures.allocateTextureUnit();
  10617. if ( cache[ 0 ] !== unit ) {
  10618. gl.uniform1i( this.addr, unit );
  10619. cache[ 0 ] = unit;
  10620. }
  10621. textures.safeSetTexture2D( v || emptyTexture, unit );
  10622. }
  10623. function setValueT2DArray1( gl, v, textures ) {
  10624. const cache = this.cache;
  10625. const unit = textures.allocateTextureUnit();
  10626. if ( cache[ 0 ] !== unit ) {
  10627. gl.uniform1i( this.addr, unit );
  10628. cache[ 0 ] = unit;
  10629. }
  10630. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10631. }
  10632. function setValueT3D1( gl, v, textures ) {
  10633. const cache = this.cache;
  10634. const unit = textures.allocateTextureUnit();
  10635. if ( cache[ 0 ] !== unit ) {
  10636. gl.uniform1i( this.addr, unit );
  10637. cache[ 0 ] = unit;
  10638. }
  10639. textures.setTexture3D( v || emptyTexture3d, unit );
  10640. }
  10641. function setValueT6( gl, v, textures ) {
  10642. const cache = this.cache;
  10643. const unit = textures.allocateTextureUnit();
  10644. if ( cache[ 0 ] !== unit ) {
  10645. gl.uniform1i( this.addr, unit );
  10646. cache[ 0 ] = unit;
  10647. }
  10648. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10649. }
  10650. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10651. function setValueV1i( gl, v ) {
  10652. const cache = this.cache;
  10653. if ( cache[ 0 ] === v ) return;
  10654. gl.uniform1i( this.addr, v );
  10655. cache[ 0 ] = v;
  10656. }
  10657. function setValueV2i( gl, v ) {
  10658. const cache = this.cache;
  10659. if ( arraysEqual( cache, v ) ) return;
  10660. gl.uniform2iv( this.addr, v );
  10661. copyArray( cache, v );
  10662. }
  10663. function setValueV3i( gl, v ) {
  10664. const cache = this.cache;
  10665. if ( arraysEqual( cache, v ) ) return;
  10666. gl.uniform3iv( this.addr, v );
  10667. copyArray( cache, v );
  10668. }
  10669. function setValueV4i( gl, v ) {
  10670. const cache = this.cache;
  10671. if ( arraysEqual( cache, v ) ) return;
  10672. gl.uniform4iv( this.addr, v );
  10673. copyArray( cache, v );
  10674. }
  10675. // uint
  10676. function setValueV1ui( gl, v ) {
  10677. const cache = this.cache;
  10678. if ( cache[ 0 ] === v ) return;
  10679. gl.uniform1ui( this.addr, v );
  10680. cache[ 0 ] = v;
  10681. }
  10682. // Helper to pick the right setter for the singular case
  10683. function getSingularSetter( type ) {
  10684. switch ( type ) {
  10685. case 0x1406: return setValueV1f; // FLOAT
  10686. case 0x8b50: return setValueV2f; // _VEC2
  10687. case 0x8b51: return setValueV3f; // _VEC3
  10688. case 0x8b52: return setValueV4f; // _VEC4
  10689. case 0x8b5a: return setValueM2; // _MAT2
  10690. case 0x8b5b: return setValueM3; // _MAT3
  10691. case 0x8b5c: return setValueM4; // _MAT4
  10692. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10693. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10694. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10695. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10696. case 0x1405: return setValueV1ui; // UINT
  10697. case 0x8b5e: // SAMPLER_2D
  10698. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10699. case 0x8dca: // INT_SAMPLER_2D
  10700. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10701. case 0x8b62: // SAMPLER_2D_SHADOW
  10702. return setValueT1;
  10703. case 0x8b5f: // SAMPLER_3D
  10704. case 0x8dcb: // INT_SAMPLER_3D
  10705. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  10706. return setValueT3D1;
  10707. case 0x8b60: // SAMPLER_CUBE
  10708. case 0x8dcc: // INT_SAMPLER_CUBE
  10709. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10710. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10711. return setValueT6;
  10712. case 0x8dc1: // SAMPLER_2D_ARRAY
  10713. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10714. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10715. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  10716. return setValueT2DArray1;
  10717. }
  10718. }
  10719. // Array of scalars
  10720. function setValueV1fArray( gl, v ) {
  10721. gl.uniform1fv( this.addr, v );
  10722. }
  10723. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10724. function setValueV1iArray( gl, v ) {
  10725. gl.uniform1iv( this.addr, v );
  10726. }
  10727. function setValueV2iArray( gl, v ) {
  10728. gl.uniform2iv( this.addr, v );
  10729. }
  10730. function setValueV3iArray( gl, v ) {
  10731. gl.uniform3iv( this.addr, v );
  10732. }
  10733. function setValueV4iArray( gl, v ) {
  10734. gl.uniform4iv( this.addr, v );
  10735. }
  10736. // Array of vectors (flat or from THREE classes)
  10737. function setValueV2fArray( gl, v ) {
  10738. const data = flatten( v, this.size, 2 );
  10739. gl.uniform2fv( this.addr, data );
  10740. }
  10741. function setValueV3fArray( gl, v ) {
  10742. const data = flatten( v, this.size, 3 );
  10743. gl.uniform3fv( this.addr, data );
  10744. }
  10745. function setValueV4fArray( gl, v ) {
  10746. const data = flatten( v, this.size, 4 );
  10747. gl.uniform4fv( this.addr, data );
  10748. }
  10749. // Array of matrices (flat or from THREE clases)
  10750. function setValueM2Array( gl, v ) {
  10751. const data = flatten( v, this.size, 4 );
  10752. gl.uniformMatrix2fv( this.addr, false, data );
  10753. }
  10754. function setValueM3Array( gl, v ) {
  10755. const data = flatten( v, this.size, 9 );
  10756. gl.uniformMatrix3fv( this.addr, false, data );
  10757. }
  10758. function setValueM4Array( gl, v ) {
  10759. const data = flatten( v, this.size, 16 );
  10760. gl.uniformMatrix4fv( this.addr, false, data );
  10761. }
  10762. // Array of textures (2D / Cube)
  10763. function setValueT1Array( gl, v, textures ) {
  10764. const n = v.length;
  10765. const units = allocTexUnits( textures, n );
  10766. gl.uniform1iv( this.addr, units );
  10767. for ( let i = 0; i !== n; ++ i ) {
  10768. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10769. }
  10770. }
  10771. function setValueT6Array( gl, v, textures ) {
  10772. const n = v.length;
  10773. const units = allocTexUnits( textures, n );
  10774. gl.uniform1iv( this.addr, units );
  10775. for ( let i = 0; i !== n; ++ i ) {
  10776. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10777. }
  10778. }
  10779. // Helper to pick the right setter for a pure (bottom-level) array
  10780. function getPureArraySetter( type ) {
  10781. switch ( type ) {
  10782. case 0x1406: return setValueV1fArray; // FLOAT
  10783. case 0x8b50: return setValueV2fArray; // _VEC2
  10784. case 0x8b51: return setValueV3fArray; // _VEC3
  10785. case 0x8b52: return setValueV4fArray; // _VEC4
  10786. case 0x8b5a: return setValueM2Array; // _MAT2
  10787. case 0x8b5b: return setValueM3Array; // _MAT3
  10788. case 0x8b5c: return setValueM4Array; // _MAT4
  10789. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10790. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10791. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10792. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10793. case 0x8b5e: // SAMPLER_2D
  10794. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10795. case 0x8dca: // INT_SAMPLER_2D
  10796. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10797. case 0x8b62: // SAMPLER_2D_SHADOW
  10798. return setValueT1Array;
  10799. case 0x8b60: // SAMPLER_CUBE
  10800. case 0x8dcc: // INT_SAMPLER_CUBE
  10801. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10802. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  10803. return setValueT6Array;
  10804. }
  10805. }
  10806. // --- Uniform Classes ---
  10807. function SingleUniform( id, activeInfo, addr ) {
  10808. this.id = id;
  10809. this.addr = addr;
  10810. this.cache = [];
  10811. this.setValue = getSingularSetter( activeInfo.type );
  10812. // this.path = activeInfo.name; // DEBUG
  10813. }
  10814. function PureArrayUniform( id, activeInfo, addr ) {
  10815. this.id = id;
  10816. this.addr = addr;
  10817. this.cache = [];
  10818. this.size = activeInfo.size;
  10819. this.setValue = getPureArraySetter( activeInfo.type );
  10820. // this.path = activeInfo.name; // DEBUG
  10821. }
  10822. PureArrayUniform.prototype.updateCache = function ( data ) {
  10823. let cache = this.cache;
  10824. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10825. this.cache = new Float32Array( data.length );
  10826. }
  10827. copyArray( cache, data );
  10828. };
  10829. function StructuredUniform( id ) {
  10830. this.id = id;
  10831. this.seq = [];
  10832. this.map = {};
  10833. }
  10834. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10835. const seq = this.seq;
  10836. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10837. const u = seq[ i ];
  10838. u.setValue( gl, value[ u.id ], textures );
  10839. }
  10840. };
  10841. // --- Top-level ---
  10842. // Parser - builds up the property tree from the path strings
  10843. const RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10844. // extracts
  10845. // - the identifier (member name or array index)
  10846. // - followed by an optional right bracket (found when array index)
  10847. // - followed by an optional left bracket or dot (type of subscript)
  10848. //
  10849. // Note: These portions can be read in a non-overlapping fashion and
  10850. // allow straightforward parsing of the hierarchy that WebGL encodes
  10851. // in the uniform names.
  10852. function addUniform( container, uniformObject ) {
  10853. container.seq.push( uniformObject );
  10854. container.map[ uniformObject.id ] = uniformObject;
  10855. }
  10856. function parseUniform( activeInfo, addr, container ) {
  10857. const path = activeInfo.name,
  10858. pathLength = path.length;
  10859. // reset RegExp object, because of the early exit of a previous run
  10860. RePathPart.lastIndex = 0;
  10861. while ( true ) {
  10862. const match = RePathPart.exec( path ),
  10863. matchEnd = RePathPart.lastIndex;
  10864. let id = match[ 1 ],
  10865. idIsIndex = match[ 2 ] === ']',
  10866. subscript = match[ 3 ];
  10867. if ( idIsIndex ) id = id | 0; // convert to integer
  10868. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10869. // bare name or "pure" bottom-level array "[0]" suffix
  10870. addUniform( container, subscript === undefined ?
  10871. new SingleUniform( id, activeInfo, addr ) :
  10872. new PureArrayUniform( id, activeInfo, addr ) );
  10873. break;
  10874. } else {
  10875. // step into inner node / create it in case it doesn't exist
  10876. const map = container.map;
  10877. let next = map[ id ];
  10878. if ( next === undefined ) {
  10879. next = new StructuredUniform( id );
  10880. addUniform( container, next );
  10881. }
  10882. container = next;
  10883. }
  10884. }
  10885. }
  10886. // Root Container
  10887. function WebGLUniforms( gl, program ) {
  10888. this.seq = [];
  10889. this.map = {};
  10890. const n = gl.getProgramParameter( program, 35718 );
  10891. for ( let i = 0; i < n; ++ i ) {
  10892. const info = gl.getActiveUniform( program, i ),
  10893. addr = gl.getUniformLocation( program, info.name );
  10894. parseUniform( info, addr, this );
  10895. }
  10896. }
  10897. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10898. const u = this.map[ name ];
  10899. if ( u !== undefined ) u.setValue( gl, value, textures );
  10900. };
  10901. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10902. const v = object[ name ];
  10903. if ( v !== undefined ) this.setValue( gl, name, v );
  10904. };
  10905. // Static interface
  10906. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10907. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10908. const u = seq[ i ],
  10909. v = values[ u.id ];
  10910. if ( v.needsUpdate !== false ) {
  10911. // note: always updating when .needsUpdate is undefined
  10912. u.setValue( gl, v.value, textures );
  10913. }
  10914. }
  10915. };
  10916. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10917. const r = [];
  10918. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  10919. const u = seq[ i ];
  10920. if ( u.id in values ) r.push( u );
  10921. }
  10922. return r;
  10923. };
  10924. /**
  10925. * @author mrdoob / http://mrdoob.com/
  10926. */
  10927. function WebGLShader( gl, type, string ) {
  10928. const shader = gl.createShader( type );
  10929. gl.shaderSource( shader, string );
  10930. gl.compileShader( shader );
  10931. return shader;
  10932. }
  10933. /**
  10934. * @author mrdoob / http://mrdoob.com/
  10935. */
  10936. let programIdCount = 0;
  10937. function addLineNumbers( string ) {
  10938. const lines = string.split( '\n' );
  10939. for ( let i = 0; i < lines.length; i ++ ) {
  10940. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10941. }
  10942. return lines.join( '\n' );
  10943. }
  10944. function getEncodingComponents( encoding ) {
  10945. switch ( encoding ) {
  10946. case LinearEncoding:
  10947. return [ 'Linear', '( value )' ];
  10948. case sRGBEncoding:
  10949. return [ 'sRGB', '( value )' ];
  10950. case RGBEEncoding:
  10951. return [ 'RGBE', '( value )' ];
  10952. case RGBM7Encoding:
  10953. return [ 'RGBM', '( value, 7.0 )' ];
  10954. case RGBM16Encoding:
  10955. return [ 'RGBM', '( value, 16.0 )' ];
  10956. case RGBDEncoding:
  10957. return [ 'RGBD', '( value, 256.0 )' ];
  10958. case GammaEncoding:
  10959. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10960. case LogLuvEncoding:
  10961. return [ 'LogLuv', '( value )' ];
  10962. default:
  10963. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  10964. return [ 'Linear', '( value )' ];
  10965. }
  10966. }
  10967. function getShaderErrors( gl, shader, type ) {
  10968. const status = gl.getShaderParameter( shader, 35713 );
  10969. const log = gl.getShaderInfoLog( shader ).trim();
  10970. if ( status && log === '' ) return '';
  10971. // --enable-privileged-webgl-extension
  10972. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10973. const source = gl.getShaderSource( shader );
  10974. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10975. }
  10976. function getTexelDecodingFunction( functionName, encoding ) {
  10977. const components = getEncodingComponents( encoding );
  10978. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10979. }
  10980. function getTexelEncodingFunction( functionName, encoding ) {
  10981. const components = getEncodingComponents( encoding );
  10982. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10983. }
  10984. function getToneMappingFunction( functionName, toneMapping ) {
  10985. let toneMappingName;
  10986. switch ( toneMapping ) {
  10987. case LinearToneMapping:
  10988. toneMappingName = 'Linear';
  10989. break;
  10990. case ReinhardToneMapping:
  10991. toneMappingName = 'Reinhard';
  10992. break;
  10993. case CineonToneMapping:
  10994. toneMappingName = 'OptimizedCineon';
  10995. break;
  10996. case ACESFilmicToneMapping:
  10997. toneMappingName = 'ACESFilmic';
  10998. break;
  10999. case CustomToneMapping:
  11000. toneMappingName = 'Custom';
  11001. break;
  11002. default:
  11003. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  11004. toneMappingName = 'Linear';
  11005. }
  11006. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11007. }
  11008. function generateExtensions( parameters ) {
  11009. const chunks = [
  11010. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  11011. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  11012. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  11013. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  11014. ];
  11015. return chunks.filter( filterEmptyLine ).join( '\n' );
  11016. }
  11017. function generateDefines( defines ) {
  11018. const chunks = [];
  11019. for ( const name in defines ) {
  11020. const value = defines[ name ];
  11021. if ( value === false ) continue;
  11022. chunks.push( '#define ' + name + ' ' + value );
  11023. }
  11024. return chunks.join( '\n' );
  11025. }
  11026. function fetchAttributeLocations( gl, program ) {
  11027. const attributes = {};
  11028. const n = gl.getProgramParameter( program, 35721 );
  11029. for ( let i = 0; i < n; i ++ ) {
  11030. const info = gl.getActiveAttrib( program, i );
  11031. const name = info.name;
  11032. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11033. attributes[ name ] = gl.getAttribLocation( program, name );
  11034. }
  11035. return attributes;
  11036. }
  11037. function filterEmptyLine( string ) {
  11038. return string !== '';
  11039. }
  11040. function replaceLightNums( string, parameters ) {
  11041. return string
  11042. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  11043. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  11044. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  11045. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  11046. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  11047. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  11048. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  11049. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  11050. }
  11051. function replaceClippingPlaneNums( string, parameters ) {
  11052. return string
  11053. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  11054. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  11055. }
  11056. // Resolve Includes
  11057. const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11058. function resolveIncludes( string ) {
  11059. return string.replace( includePattern, includeReplacer );
  11060. }
  11061. function includeReplacer( match, include ) {
  11062. const string = ShaderChunk[ include ];
  11063. if ( string === undefined ) {
  11064. throw new Error( 'Can not resolve #include <' + include + '>' );
  11065. }
  11066. return resolveIncludes( string );
  11067. }
  11068. // Unroll Loops
  11069. const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11070. const unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;
  11071. function unrollLoops( string ) {
  11072. return string
  11073. .replace( unrollLoopPattern, loopReplacer )
  11074. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  11075. }
  11076. function deprecatedLoopReplacer( match, start, end, snippet ) {
  11077. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  11078. return loopReplacer( match, start, end, snippet );
  11079. }
  11080. function loopReplacer( match, start, end, snippet ) {
  11081. let string = '';
  11082. for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
  11083. string += snippet
  11084. .replace( /\[ i \]/g, '[ ' + i + ' ]' )
  11085. .replace( /UNROLLED_LOOP_INDEX/g, i );
  11086. }
  11087. return string;
  11088. }
  11089. //
  11090. function generatePrecision( parameters ) {
  11091. let precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;";
  11092. if ( parameters.precision === "highp" ) {
  11093. precisionstring += "\n#define HIGH_PRECISION";
  11094. } else if ( parameters.precision === "mediump" ) {
  11095. precisionstring += "\n#define MEDIUM_PRECISION";
  11096. } else if ( parameters.precision === "lowp" ) {
  11097. precisionstring += "\n#define LOW_PRECISION";
  11098. }
  11099. return precisionstring;
  11100. }
  11101. function generateShadowMapTypeDefine( parameters ) {
  11102. let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11103. if ( parameters.shadowMapType === PCFShadowMap ) {
  11104. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11105. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  11106. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11107. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  11108. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11109. }
  11110. return shadowMapTypeDefine;
  11111. }
  11112. function generateEnvMapTypeDefine( parameters ) {
  11113. let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11114. if ( parameters.envMap ) {
  11115. switch ( parameters.envMapMode ) {
  11116. case CubeReflectionMapping:
  11117. case CubeRefractionMapping:
  11118. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11119. break;
  11120. case CubeUVReflectionMapping:
  11121. case CubeUVRefractionMapping:
  11122. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11123. break;
  11124. case EquirectangularReflectionMapping:
  11125. case EquirectangularRefractionMapping:
  11126. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  11127. break;
  11128. }
  11129. }
  11130. return envMapTypeDefine;
  11131. }
  11132. function generateEnvMapModeDefine( parameters ) {
  11133. let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11134. if ( parameters.envMap ) {
  11135. switch ( parameters.envMapMode ) {
  11136. case CubeRefractionMapping:
  11137. case EquirectangularRefractionMapping:
  11138. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11139. break;
  11140. }
  11141. }
  11142. return envMapModeDefine;
  11143. }
  11144. function generateEnvMapBlendingDefine( parameters ) {
  11145. let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11146. if ( parameters.envMap ) {
  11147. switch ( parameters.combine ) {
  11148. case MultiplyOperation:
  11149. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11150. break;
  11151. case MixOperation:
  11152. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11153. break;
  11154. case AddOperation:
  11155. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11156. break;
  11157. }
  11158. }
  11159. return envMapBlendingDefine;
  11160. }
  11161. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  11162. const gl = renderer.getContext();
  11163. const defines = parameters.defines;
  11164. let vertexShader = parameters.vertexShader;
  11165. let fragmentShader = parameters.fragmentShader;
  11166. const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  11167. const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  11168. const envMapModeDefine = generateEnvMapModeDefine( parameters );
  11169. const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  11170. const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  11171. const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  11172. const customDefines = generateDefines( defines );
  11173. const program = gl.createProgram();
  11174. let prefixVertex, prefixFragment;
  11175. if ( parameters.isRawShaderMaterial ) {
  11176. prefixVertex = [
  11177. customDefines
  11178. ].filter( filterEmptyLine ).join( '\n' );
  11179. if ( prefixVertex.length > 0 ) {
  11180. prefixVertex += '\n';
  11181. }
  11182. prefixFragment = [
  11183. customExtensions,
  11184. customDefines
  11185. ].filter( filterEmptyLine ).join( '\n' );
  11186. if ( prefixFragment.length > 0 ) {
  11187. prefixFragment += '\n';
  11188. }
  11189. } else {
  11190. prefixVertex = [
  11191. generatePrecision( parameters ),
  11192. '#define SHADER_NAME ' + parameters.shaderName,
  11193. customDefines,
  11194. parameters.instancing ? '#define USE_INSTANCING' : '',
  11195. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  11196. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11197. '#define MAX_BONES ' + parameters.maxBones,
  11198. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11199. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11200. parameters.map ? '#define USE_MAP' : '',
  11201. parameters.envMap ? '#define USE_ENVMAP' : '',
  11202. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11203. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11204. parameters.aoMap ? '#define USE_AOMAP' : '',
  11205. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11206. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11207. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11208. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11209. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11210. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11211. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11212. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11213. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  11214. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11215. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11216. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11217. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11218. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11219. parameters.vertexColors ? '#define USE_COLOR' : '',
  11220. parameters.vertexUvs ? '#define USE_UV' : '',
  11221. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11222. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11223. parameters.skinning ? '#define USE_SKINNING' : '',
  11224. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  11225. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  11226. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  11227. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11228. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11229. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11230. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11231. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  11232. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11233. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11234. 'uniform mat4 modelMatrix;',
  11235. 'uniform mat4 modelViewMatrix;',
  11236. 'uniform mat4 projectionMatrix;',
  11237. 'uniform mat4 viewMatrix;',
  11238. 'uniform mat3 normalMatrix;',
  11239. 'uniform vec3 cameraPosition;',
  11240. 'uniform bool isOrthographic;',
  11241. '#ifdef USE_INSTANCING',
  11242. ' attribute mat4 instanceMatrix;',
  11243. '#endif',
  11244. 'attribute vec3 position;',
  11245. 'attribute vec3 normal;',
  11246. 'attribute vec2 uv;',
  11247. '#ifdef USE_TANGENT',
  11248. ' attribute vec4 tangent;',
  11249. '#endif',
  11250. '#ifdef USE_COLOR',
  11251. ' attribute vec3 color;',
  11252. '#endif',
  11253. '#ifdef USE_MORPHTARGETS',
  11254. ' attribute vec3 morphTarget0;',
  11255. ' attribute vec3 morphTarget1;',
  11256. ' attribute vec3 morphTarget2;',
  11257. ' attribute vec3 morphTarget3;',
  11258. ' #ifdef USE_MORPHNORMALS',
  11259. ' attribute vec3 morphNormal0;',
  11260. ' attribute vec3 morphNormal1;',
  11261. ' attribute vec3 morphNormal2;',
  11262. ' attribute vec3 morphNormal3;',
  11263. ' #else',
  11264. ' attribute vec3 morphTarget4;',
  11265. ' attribute vec3 morphTarget5;',
  11266. ' attribute vec3 morphTarget6;',
  11267. ' attribute vec3 morphTarget7;',
  11268. ' #endif',
  11269. '#endif',
  11270. '#ifdef USE_SKINNING',
  11271. ' attribute vec4 skinIndex;',
  11272. ' attribute vec4 skinWeight;',
  11273. '#endif',
  11274. '\n'
  11275. ].filter( filterEmptyLine ).join( '\n' );
  11276. prefixFragment = [
  11277. customExtensions,
  11278. generatePrecision( parameters ),
  11279. '#define SHADER_NAME ' + parameters.shaderName,
  11280. customDefines,
  11281. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  11282. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  11283. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  11284. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  11285. parameters.map ? '#define USE_MAP' : '',
  11286. parameters.matcap ? '#define USE_MATCAP' : '',
  11287. parameters.envMap ? '#define USE_ENVMAP' : '',
  11288. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  11289. parameters.envMap ? '#define ' + envMapModeDefine : '',
  11290. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  11291. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  11292. parameters.aoMap ? '#define USE_AOMAP' : '',
  11293. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  11294. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  11295. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  11296. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  11297. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  11298. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  11299. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  11300. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  11301. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  11302. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  11303. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  11304. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  11305. parameters.sheen ? '#define USE_SHEEN' : '',
  11306. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  11307. parameters.vertexColors ? '#define USE_COLOR' : '',
  11308. parameters.vertexUvs ? '#define USE_UV' : '',
  11309. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  11310. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  11311. parameters.flatShading ? '#define FLAT_SHADED' : '',
  11312. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  11313. parameters.flipSided ? '#define FLIP_SIDED' : '',
  11314. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  11315. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  11316. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  11317. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  11318. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  11319. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  11320. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  11321. 'uniform mat4 viewMatrix;',
  11322. 'uniform vec3 cameraPosition;',
  11323. 'uniform bool isOrthographic;',
  11324. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  11325. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  11326. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  11327. parameters.dithering ? '#define DITHERING' : '',
  11328. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  11329. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  11330. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  11331. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  11332. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  11333. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  11334. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  11335. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  11336. '\n'
  11337. ].filter( filterEmptyLine ).join( '\n' );
  11338. }
  11339. vertexShader = resolveIncludes( vertexShader );
  11340. vertexShader = replaceLightNums( vertexShader, parameters );
  11341. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  11342. fragmentShader = resolveIncludes( fragmentShader );
  11343. fragmentShader = replaceLightNums( fragmentShader, parameters );
  11344. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  11345. vertexShader = unrollLoops( vertexShader );
  11346. fragmentShader = unrollLoops( fragmentShader );
  11347. if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) {
  11348. let isGLSL3ShaderMaterial = false;
  11349. const versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  11350. if ( parameters.isShaderMaterial &&
  11351. vertexShader.match( versionRegex ) !== null &&
  11352. fragmentShader.match( versionRegex ) !== null ) {
  11353. isGLSL3ShaderMaterial = true;
  11354. vertexShader = vertexShader.replace( versionRegex, '' );
  11355. fragmentShader = fragmentShader.replace( versionRegex, '' );
  11356. }
  11357. // GLSL 3.0 conversion
  11358. prefixVertex = [
  11359. '#version 300 es\n',
  11360. '#define attribute in',
  11361. '#define varying out',
  11362. '#define texture2D texture'
  11363. ].join( '\n' ) + '\n' + prefixVertex;
  11364. prefixFragment = [
  11365. '#version 300 es\n',
  11366. '#define varying in',
  11367. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  11368. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  11369. '#define gl_FragDepthEXT gl_FragDepth',
  11370. '#define texture2D texture',
  11371. '#define textureCube texture',
  11372. '#define texture2DProj textureProj',
  11373. '#define texture2DLodEXT textureLod',
  11374. '#define texture2DProjLodEXT textureProjLod',
  11375. '#define textureCubeLodEXT textureLod',
  11376. '#define texture2DGradEXT textureGrad',
  11377. '#define texture2DProjGradEXT textureProjGrad',
  11378. '#define textureCubeGradEXT textureGrad'
  11379. ].join( '\n' ) + '\n' + prefixFragment;
  11380. }
  11381. const vertexGlsl = prefixVertex + vertexShader;
  11382. const fragmentGlsl = prefixFragment + fragmentShader;
  11383. // console.log( '*VERTEX*', vertexGlsl );
  11384. // console.log( '*FRAGMENT*', fragmentGlsl );
  11385. const glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  11386. const glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  11387. gl.attachShader( program, glVertexShader );
  11388. gl.attachShader( program, glFragmentShader );
  11389. // Force a particular attribute to index 0.
  11390. if ( parameters.index0AttributeName !== undefined ) {
  11391. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  11392. } else if ( parameters.morphTargets === true ) {
  11393. // programs with morphTargets displace position out of attribute 0
  11394. gl.bindAttribLocation( program, 0, 'position' );
  11395. }
  11396. gl.linkProgram( program );
  11397. // check for link errors
  11398. if ( renderer.debug.checkShaderErrors ) {
  11399. const programLog = gl.getProgramInfoLog( program ).trim();
  11400. const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  11401. const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  11402. let runnable = true;
  11403. let haveDiagnostics = true;
  11404. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  11405. runnable = false;
  11406. const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  11407. const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  11408. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  11409. } else if ( programLog !== '' ) {
  11410. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  11411. } else if ( vertexLog === '' || fragmentLog === '' ) {
  11412. haveDiagnostics = false;
  11413. }
  11414. if ( haveDiagnostics ) {
  11415. this.diagnostics = {
  11416. runnable: runnable,
  11417. programLog: programLog,
  11418. vertexShader: {
  11419. log: vertexLog,
  11420. prefix: prefixVertex
  11421. },
  11422. fragmentShader: {
  11423. log: fragmentLog,
  11424. prefix: prefixFragment
  11425. }
  11426. };
  11427. }
  11428. }
  11429. // Clean up
  11430. // Crashes in iOS9 and iOS10. #18402
  11431. // gl.detachShader( program, glVertexShader );
  11432. // gl.detachShader( program, glFragmentShader );
  11433. gl.deleteShader( glVertexShader );
  11434. gl.deleteShader( glFragmentShader );
  11435. // set up caching for uniform locations
  11436. let cachedUniforms;
  11437. this.getUniforms = function () {
  11438. if ( cachedUniforms === undefined ) {
  11439. cachedUniforms = new WebGLUniforms( gl, program );
  11440. }
  11441. return cachedUniforms;
  11442. };
  11443. // set up caching for attribute locations
  11444. let cachedAttributes;
  11445. this.getAttributes = function () {
  11446. if ( cachedAttributes === undefined ) {
  11447. cachedAttributes = fetchAttributeLocations( gl, program );
  11448. }
  11449. return cachedAttributes;
  11450. };
  11451. // free resource
  11452. this.destroy = function () {
  11453. bindingStates.releaseStatesOfProgram( this );
  11454. gl.deleteProgram( program );
  11455. this.program = undefined;
  11456. };
  11457. //
  11458. this.name = parameters.shaderName;
  11459. this.id = programIdCount ++;
  11460. this.cacheKey = cacheKey;
  11461. this.usedTimes = 1;
  11462. this.program = program;
  11463. this.vertexShader = glVertexShader;
  11464. this.fragmentShader = glFragmentShader;
  11465. return this;
  11466. }
  11467. /**
  11468. * @author mrdoob / http://mrdoob.com/
  11469. */
  11470. function WebGLPrograms( renderer, extensions, capabilities, bindingStates ) {
  11471. const programs = [];
  11472. const isWebGL2 = capabilities.isWebGL2;
  11473. const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11474. const floatVertexTextures = capabilities.floatVertexTextures;
  11475. const maxVertexUniforms = capabilities.maxVertexUniforms;
  11476. const vertexTextures = capabilities.vertexTextures;
  11477. let precision = capabilities.precision;
  11478. const shaderIDs = {
  11479. MeshDepthMaterial: 'depth',
  11480. MeshDistanceMaterial: 'distanceRGBA',
  11481. MeshNormalMaterial: 'normal',
  11482. MeshBasicMaterial: 'basic',
  11483. MeshLambertMaterial: 'lambert',
  11484. MeshPhongMaterial: 'phong',
  11485. MeshToonMaterial: 'toon',
  11486. MeshStandardMaterial: 'physical',
  11487. MeshPhysicalMaterial: 'physical',
  11488. MeshMatcapMaterial: 'matcap',
  11489. LineBasicMaterial: 'basic',
  11490. LineDashedMaterial: 'dashed',
  11491. PointsMaterial: 'points',
  11492. ShadowMaterial: 'shadow',
  11493. SpriteMaterial: 'sprite'
  11494. };
  11495. const parameterNames = [
  11496. "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing",
  11497. "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding", "envMapCubeUV",
  11498. "lightMap", "lightMapEncoding", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "tangentSpaceNormalMap", "clearcoatMap", "clearcoatRoughnessMap", "clearcoatNormalMap", "displacementMap", "specularMap",
  11499. "roughnessMap", "metalnessMap", "gradientMap",
  11500. "alphaMap", "combine", "vertexColors", "vertexTangents", "vertexUvs", "uvsVertexOnly", "fog", "useFog", "fogExp2",
  11501. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  11502. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  11503. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  11504. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  11505. "numDirLightShadows", "numPointLightShadows", "numSpotLightShadows",
  11506. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  11507. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering",
  11508. "sheen"
  11509. ];
  11510. function getShaderObject( material, shaderID ) {
  11511. let shaderobject;
  11512. if ( shaderID ) {
  11513. const shader = ShaderLib[ shaderID ];
  11514. shaderobject = {
  11515. name: material.name || material.type,
  11516. uniforms: UniformsUtils.clone( shader.uniforms ),
  11517. vertexShader: shader.vertexShader,
  11518. fragmentShader: shader.fragmentShader
  11519. };
  11520. } else {
  11521. shaderobject = {
  11522. name: material.name || material.type,
  11523. uniforms: material.uniforms,
  11524. vertexShader: material.vertexShader,
  11525. fragmentShader: material.fragmentShader
  11526. };
  11527. }
  11528. return shaderobject;
  11529. }
  11530. function allocateBones( object ) {
  11531. const skeleton = object.skeleton;
  11532. const bones = skeleton.bones;
  11533. if ( floatVertexTextures ) {
  11534. return 1024;
  11535. } else {
  11536. // default for when object is not specified
  11537. // ( for example when prebuilding shader to be used with multiple objects )
  11538. //
  11539. // - leave some extra space for other uniforms
  11540. // - limit here is ANGLE's 254 max uniform vectors
  11541. // (up to 54 should be safe)
  11542. const nVertexUniforms = maxVertexUniforms;
  11543. const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  11544. const maxBones = Math.min( nVertexMatrices, bones.length );
  11545. if ( maxBones < bones.length ) {
  11546. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  11547. return 0;
  11548. }
  11549. return maxBones;
  11550. }
  11551. }
  11552. function getTextureEncodingFromMap( map ) {
  11553. let encoding;
  11554. if ( ! map ) {
  11555. encoding = LinearEncoding;
  11556. } else if ( map.isTexture ) {
  11557. encoding = map.encoding;
  11558. } else if ( map.isWebGLRenderTarget ) {
  11559. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  11560. encoding = map.texture.encoding;
  11561. }
  11562. return encoding;
  11563. }
  11564. function getParameters( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
  11565. const fog = scene.fog;
  11566. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  11567. const envMap = material.envMap || environment;
  11568. const shaderID = shaderIDs[ material.type ];
  11569. // heuristics to create shader parameters according to lights in the scene
  11570. // (not to blow over maxLights budget)
  11571. const maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11572. if ( material.precision !== null ) {
  11573. precision = capabilities.getMaxPrecision( material.precision );
  11574. if ( precision !== material.precision ) {
  11575. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11576. }
  11577. }
  11578. const shaderobject = getShaderObject( material, shaderID );
  11579. material.onBeforeCompile( shaderobject, renderer );
  11580. const currentRenderTarget = renderer.getRenderTarget();
  11581. const parameters = {
  11582. isWebGL2: isWebGL2,
  11583. shaderID: shaderID,
  11584. shaderName: shaderobject.name,
  11585. uniforms: shaderobject.uniforms,
  11586. vertexShader: shaderobject.vertexShader,
  11587. fragmentShader: shaderobject.fragmentShader,
  11588. defines: material.defines,
  11589. isRawShaderMaterial: material.isRawShaderMaterial,
  11590. isShaderMaterial: material.isShaderMaterial,
  11591. precision: precision,
  11592. instancing: object.isInstancedMesh === true,
  11593. supportsVertexTextures: vertexTextures,
  11594. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  11595. map: !! material.map,
  11596. mapEncoding: getTextureEncodingFromMap( material.map ),
  11597. matcap: !! material.matcap,
  11598. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  11599. envMap: !! envMap,
  11600. envMapMode: envMap && envMap.mapping,
  11601. envMapEncoding: getTextureEncodingFromMap( envMap ),
  11602. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  11603. lightMap: !! material.lightMap,
  11604. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  11605. aoMap: !! material.aoMap,
  11606. emissiveMap: !! material.emissiveMap,
  11607. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  11608. bumpMap: !! material.bumpMap,
  11609. normalMap: !! material.normalMap,
  11610. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11611. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11612. clearcoatMap: !! material.clearcoatMap,
  11613. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  11614. clearcoatNormalMap: !! material.clearcoatNormalMap,
  11615. displacementMap: !! material.displacementMap,
  11616. roughnessMap: !! material.roughnessMap,
  11617. metalnessMap: !! material.metalnessMap,
  11618. specularMap: !! material.specularMap,
  11619. alphaMap: !! material.alphaMap,
  11620. gradientMap: !! material.gradientMap,
  11621. sheen: !! material.sheen,
  11622. combine: material.combine,
  11623. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11624. vertexColors: material.vertexColors,
  11625. 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,
  11626. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap ) && !! material.displacementMap,
  11627. fog: !! fog,
  11628. useFog: material.fog,
  11629. fogExp2: ( fog && fog.isFogExp2 ),
  11630. flatShading: material.flatShading,
  11631. sizeAttenuation: material.sizeAttenuation,
  11632. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11633. skinning: material.skinning && maxBones > 0,
  11634. maxBones: maxBones,
  11635. useVertexTexture: floatVertexTextures,
  11636. morphTargets: material.morphTargets,
  11637. morphNormals: material.morphNormals,
  11638. maxMorphTargets: renderer.maxMorphTargets,
  11639. maxMorphNormals: renderer.maxMorphNormals,
  11640. numDirLights: lights.directional.length,
  11641. numPointLights: lights.point.length,
  11642. numSpotLights: lights.spot.length,
  11643. numRectAreaLights: lights.rectArea.length,
  11644. numHemiLights: lights.hemi.length,
  11645. numDirLightShadows: lights.directionalShadowMap.length,
  11646. numPointLightShadows: lights.pointShadowMap.length,
  11647. numSpotLightShadows: lights.spotShadowMap.length,
  11648. numClippingPlanes: nClipPlanes,
  11649. numClipIntersection: nClipIntersection,
  11650. dithering: material.dithering,
  11651. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11652. shadowMapType: renderer.shadowMap.type,
  11653. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11654. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11655. premultipliedAlpha: material.premultipliedAlpha,
  11656. alphaTest: material.alphaTest,
  11657. doubleSided: material.side === DoubleSide,
  11658. flipSided: material.side === BackSide,
  11659. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  11660. index0AttributeName: material.index0AttributeName,
  11661. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11662. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11663. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11664. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11665. rendererExtensionFragDepth: isWebGL2 || extensions.get( 'EXT_frag_depth' ) !== null,
  11666. rendererExtensionDrawBuffers: isWebGL2 || extensions.get( 'WEBGL_draw_buffers' ) !== null,
  11667. rendererExtensionShaderTextureLod: isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) !== null,
  11668. customProgramCacheKey: material.customProgramCacheKey()
  11669. };
  11670. return parameters;
  11671. }
  11672. function getProgramCacheKey( parameters ) {
  11673. const array = [];
  11674. if ( parameters.shaderID ) {
  11675. array.push( parameters.shaderID );
  11676. } else {
  11677. array.push( parameters.fragmentShader );
  11678. array.push( parameters.vertexShader );
  11679. }
  11680. if ( parameters.defines !== undefined ) {
  11681. for ( const name in parameters.defines ) {
  11682. array.push( name );
  11683. array.push( parameters.defines[ name ] );
  11684. }
  11685. }
  11686. if ( parameters.isRawShaderMaterial === undefined ) {
  11687. for ( let i = 0; i < parameterNames.length; i ++ ) {
  11688. array.push( parameters[ parameterNames[ i ] ] );
  11689. }
  11690. array.push( renderer.outputEncoding );
  11691. array.push( renderer.gammaFactor );
  11692. }
  11693. array.push( parameters.customProgramCacheKey );
  11694. return array.join();
  11695. }
  11696. function acquireProgram( parameters, cacheKey ) {
  11697. let program;
  11698. // Check if code has been already compiled
  11699. for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
  11700. const preexistingProgram = programs[ p ];
  11701. if ( preexistingProgram.cacheKey === cacheKey ) {
  11702. program = preexistingProgram;
  11703. ++ program.usedTimes;
  11704. break;
  11705. }
  11706. }
  11707. if ( program === undefined ) {
  11708. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  11709. programs.push( program );
  11710. }
  11711. return program;
  11712. }
  11713. function releaseProgram( program ) {
  11714. if ( -- program.usedTimes === 0 ) {
  11715. // Remove from unordered set
  11716. const i = programs.indexOf( program );
  11717. programs[ i ] = programs[ programs.length - 1 ];
  11718. programs.pop();
  11719. // Free WebGL resources
  11720. program.destroy();
  11721. }
  11722. }
  11723. return {
  11724. getParameters: getParameters,
  11725. getProgramCacheKey: getProgramCacheKey,
  11726. acquireProgram: acquireProgram,
  11727. releaseProgram: releaseProgram,
  11728. // Exposed for resource monitoring & error feedback via renderer.info:
  11729. programs: programs
  11730. };
  11731. }
  11732. /**
  11733. * @author fordacious / fordacious.github.io
  11734. */
  11735. function WebGLProperties() {
  11736. let properties = new WeakMap();
  11737. function get( object ) {
  11738. let map = properties.get( object );
  11739. if ( map === undefined ) {
  11740. map = {};
  11741. properties.set( object, map );
  11742. }
  11743. return map;
  11744. }
  11745. function remove( object ) {
  11746. properties.delete( object );
  11747. }
  11748. function update( object, key, value ) {
  11749. properties.get( object )[ key ] = value;
  11750. }
  11751. function dispose() {
  11752. properties = new WeakMap();
  11753. }
  11754. return {
  11755. get: get,
  11756. remove: remove,
  11757. update: update,
  11758. dispose: dispose
  11759. };
  11760. }
  11761. /**
  11762. * @author mrdoob / http://mrdoob.com/
  11763. */
  11764. function painterSortStable( a, b ) {
  11765. if ( a.groupOrder !== b.groupOrder ) {
  11766. return a.groupOrder - b.groupOrder;
  11767. } else if ( a.renderOrder !== b.renderOrder ) {
  11768. return a.renderOrder - b.renderOrder;
  11769. } else if ( a.program !== b.program ) {
  11770. return a.program.id - b.program.id;
  11771. } else if ( a.material.id !== b.material.id ) {
  11772. return a.material.id - b.material.id;
  11773. } else if ( a.z !== b.z ) {
  11774. return a.z - b.z;
  11775. } else {
  11776. return a.id - b.id;
  11777. }
  11778. }
  11779. function reversePainterSortStable( a, b ) {
  11780. if ( a.groupOrder !== b.groupOrder ) {
  11781. return a.groupOrder - b.groupOrder;
  11782. } else if ( a.renderOrder !== b.renderOrder ) {
  11783. return a.renderOrder - b.renderOrder;
  11784. } else if ( a.z !== b.z ) {
  11785. return b.z - a.z;
  11786. } else {
  11787. return a.id - b.id;
  11788. }
  11789. }
  11790. function WebGLRenderList() {
  11791. const renderItems = [];
  11792. let renderItemsIndex = 0;
  11793. const opaque = [];
  11794. const transparent = [];
  11795. const defaultProgram = { id: - 1 };
  11796. function init() {
  11797. renderItemsIndex = 0;
  11798. opaque.length = 0;
  11799. transparent.length = 0;
  11800. }
  11801. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11802. let renderItem = renderItems[ renderItemsIndex ];
  11803. if ( renderItem === undefined ) {
  11804. renderItem = {
  11805. id: object.id,
  11806. object: object,
  11807. geometry: geometry,
  11808. material: material,
  11809. program: material.program || defaultProgram,
  11810. groupOrder: groupOrder,
  11811. renderOrder: object.renderOrder,
  11812. z: z,
  11813. group: group
  11814. };
  11815. renderItems[ renderItemsIndex ] = renderItem;
  11816. } else {
  11817. renderItem.id = object.id;
  11818. renderItem.object = object;
  11819. renderItem.geometry = geometry;
  11820. renderItem.material = material;
  11821. renderItem.program = material.program || defaultProgram;
  11822. renderItem.groupOrder = groupOrder;
  11823. renderItem.renderOrder = object.renderOrder;
  11824. renderItem.z = z;
  11825. renderItem.group = group;
  11826. }
  11827. renderItemsIndex ++;
  11828. return renderItem;
  11829. }
  11830. function push( object, geometry, material, groupOrder, z, group ) {
  11831. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11832. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11833. }
  11834. function unshift( object, geometry, material, groupOrder, z, group ) {
  11835. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11836. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11837. }
  11838. function sort( customOpaqueSort, customTransparentSort ) {
  11839. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  11840. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  11841. }
  11842. function finish() {
  11843. // Clear references from inactive renderItems in the list
  11844. for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  11845. const renderItem = renderItems[ i ];
  11846. if ( renderItem.id === null ) break;
  11847. renderItem.id = null;
  11848. renderItem.object = null;
  11849. renderItem.geometry = null;
  11850. renderItem.material = null;
  11851. renderItem.program = null;
  11852. renderItem.group = null;
  11853. }
  11854. }
  11855. return {
  11856. opaque: opaque,
  11857. transparent: transparent,
  11858. init: init,
  11859. push: push,
  11860. unshift: unshift,
  11861. finish: finish,
  11862. sort: sort
  11863. };
  11864. }
  11865. function WebGLRenderLists() {
  11866. let lists = new WeakMap();
  11867. function onSceneDispose( event ) {
  11868. const scene = event.target;
  11869. scene.removeEventListener( 'dispose', onSceneDispose );
  11870. lists.delete( scene );
  11871. }
  11872. function get( scene, camera ) {
  11873. const cameras = lists.get( scene );
  11874. let list;
  11875. if ( cameras === undefined ) {
  11876. list = new WebGLRenderList();
  11877. lists.set( scene, new WeakMap() );
  11878. lists.get( scene ).set( camera, list );
  11879. scene.addEventListener( 'dispose', onSceneDispose );
  11880. } else {
  11881. list = cameras.get( camera );
  11882. if ( list === undefined ) {
  11883. list = new WebGLRenderList();
  11884. cameras.set( camera, list );
  11885. }
  11886. }
  11887. return list;
  11888. }
  11889. function dispose() {
  11890. lists = new WeakMap();
  11891. }
  11892. return {
  11893. get: get,
  11894. dispose: dispose
  11895. };
  11896. }
  11897. /**
  11898. * @author mrdoob / http://mrdoob.com/
  11899. */
  11900. function UniformsCache() {
  11901. const lights = {};
  11902. return {
  11903. get: function ( light ) {
  11904. if ( lights[ light.id ] !== undefined ) {
  11905. return lights[ light.id ];
  11906. }
  11907. let uniforms;
  11908. switch ( light.type ) {
  11909. case 'DirectionalLight':
  11910. uniforms = {
  11911. direction: new Vector3(),
  11912. color: new Color()
  11913. };
  11914. break;
  11915. case 'SpotLight':
  11916. uniforms = {
  11917. position: new Vector3(),
  11918. direction: new Vector3(),
  11919. color: new Color(),
  11920. distance: 0,
  11921. coneCos: 0,
  11922. penumbraCos: 0,
  11923. decay: 0
  11924. };
  11925. break;
  11926. case 'PointLight':
  11927. uniforms = {
  11928. position: new Vector3(),
  11929. color: new Color(),
  11930. distance: 0,
  11931. decay: 0
  11932. };
  11933. break;
  11934. case 'HemisphereLight':
  11935. uniforms = {
  11936. direction: new Vector3(),
  11937. skyColor: new Color(),
  11938. groundColor: new Color()
  11939. };
  11940. break;
  11941. case 'RectAreaLight':
  11942. uniforms = {
  11943. color: new Color(),
  11944. position: new Vector3(),
  11945. halfWidth: new Vector3(),
  11946. halfHeight: new Vector3()
  11947. };
  11948. break;
  11949. }
  11950. lights[ light.id ] = uniforms;
  11951. return uniforms;
  11952. }
  11953. };
  11954. }
  11955. function ShadowUniformsCache() {
  11956. const lights = {};
  11957. return {
  11958. get: function ( light ) {
  11959. if ( lights[ light.id ] !== undefined ) {
  11960. return lights[ light.id ];
  11961. }
  11962. let uniforms;
  11963. switch ( light.type ) {
  11964. case 'DirectionalLight':
  11965. uniforms = {
  11966. shadowBias: 0,
  11967. shadowNormalBias: 0,
  11968. shadowRadius: 1,
  11969. shadowMapSize: new Vector2()
  11970. };
  11971. break;
  11972. case 'SpotLight':
  11973. uniforms = {
  11974. shadowBias: 0,
  11975. shadowNormalBias: 0,
  11976. shadowRadius: 1,
  11977. shadowMapSize: new Vector2()
  11978. };
  11979. break;
  11980. case 'PointLight':
  11981. uniforms = {
  11982. shadowBias: 0,
  11983. shadowNormalBias: 0,
  11984. shadowRadius: 1,
  11985. shadowMapSize: new Vector2(),
  11986. shadowCameraNear: 1,
  11987. shadowCameraFar: 1000
  11988. };
  11989. break;
  11990. // TODO (abelnation): set RectAreaLight shadow uniforms
  11991. }
  11992. lights[ light.id ] = uniforms;
  11993. return uniforms;
  11994. }
  11995. };
  11996. }
  11997. let nextVersion = 0;
  11998. function shadowCastingLightsFirst( lightA, lightB ) {
  11999. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  12000. }
  12001. function WebGLLights() {
  12002. const cache = new UniformsCache();
  12003. const shadowCache = ShadowUniformsCache();
  12004. const state = {
  12005. version: 0,
  12006. hash: {
  12007. directionalLength: - 1,
  12008. pointLength: - 1,
  12009. spotLength: - 1,
  12010. rectAreaLength: - 1,
  12011. hemiLength: - 1,
  12012. numDirectionalShadows: - 1,
  12013. numPointShadows: - 1,
  12014. numSpotShadows: - 1
  12015. },
  12016. ambient: [ 0, 0, 0 ],
  12017. probe: [],
  12018. directional: [],
  12019. directionalShadow: [],
  12020. directionalShadowMap: [],
  12021. directionalShadowMatrix: [],
  12022. spot: [],
  12023. spotShadow: [],
  12024. spotShadowMap: [],
  12025. spotShadowMatrix: [],
  12026. rectArea: [],
  12027. point: [],
  12028. pointShadow: [],
  12029. pointShadowMap: [],
  12030. pointShadowMatrix: [],
  12031. hemi: []
  12032. };
  12033. for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  12034. const vector3 = new Vector3();
  12035. const matrix4 = new Matrix4();
  12036. const matrix42 = new Matrix4();
  12037. function setup( lights, shadows, camera ) {
  12038. let r = 0, g = 0, b = 0;
  12039. for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  12040. let directionalLength = 0;
  12041. let pointLength = 0;
  12042. let spotLength = 0;
  12043. let rectAreaLength = 0;
  12044. let hemiLength = 0;
  12045. let numDirectionalShadows = 0;
  12046. let numPointShadows = 0;
  12047. let numSpotShadows = 0;
  12048. const viewMatrix = camera.matrixWorldInverse;
  12049. lights.sort( shadowCastingLightsFirst );
  12050. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  12051. const light = lights[ i ];
  12052. const color = light.color;
  12053. const intensity = light.intensity;
  12054. const distance = light.distance;
  12055. const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  12056. if ( light.isAmbientLight ) {
  12057. r += color.r * intensity;
  12058. g += color.g * intensity;
  12059. b += color.b * intensity;
  12060. } else if ( light.isLightProbe ) {
  12061. for ( let j = 0; j < 9; j ++ ) {
  12062. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  12063. }
  12064. } else if ( light.isDirectionalLight ) {
  12065. const uniforms = cache.get( light );
  12066. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12067. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12068. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12069. uniforms.direction.sub( vector3 );
  12070. uniforms.direction.transformDirection( viewMatrix );
  12071. if ( light.castShadow ) {
  12072. const shadow = light.shadow;
  12073. const shadowUniforms = shadowCache.get( light );
  12074. shadowUniforms.shadowBias = shadow.bias;
  12075. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12076. shadowUniforms.shadowRadius = shadow.radius;
  12077. shadowUniforms.shadowMapSize = shadow.mapSize;
  12078. state.directionalShadow[ directionalLength ] = shadowUniforms;
  12079. state.directionalShadowMap[ directionalLength ] = shadowMap;
  12080. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  12081. numDirectionalShadows ++;
  12082. }
  12083. state.directional[ directionalLength ] = uniforms;
  12084. directionalLength ++;
  12085. } else if ( light.isSpotLight ) {
  12086. const uniforms = cache.get( light );
  12087. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12088. uniforms.position.applyMatrix4( viewMatrix );
  12089. uniforms.color.copy( color ).multiplyScalar( intensity );
  12090. uniforms.distance = distance;
  12091. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12092. vector3.setFromMatrixPosition( light.target.matrixWorld );
  12093. uniforms.direction.sub( vector3 );
  12094. uniforms.direction.transformDirection( viewMatrix );
  12095. uniforms.coneCos = Math.cos( light.angle );
  12096. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  12097. uniforms.decay = light.decay;
  12098. if ( light.castShadow ) {
  12099. const shadow = light.shadow;
  12100. const shadowUniforms = shadowCache.get( light );
  12101. shadowUniforms.shadowBias = shadow.bias;
  12102. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12103. shadowUniforms.shadowRadius = shadow.radius;
  12104. shadowUniforms.shadowMapSize = shadow.mapSize;
  12105. state.spotShadow[ spotLength ] = shadowUniforms;
  12106. state.spotShadowMap[ spotLength ] = shadowMap;
  12107. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  12108. numSpotShadows ++;
  12109. }
  12110. state.spot[ spotLength ] = uniforms;
  12111. spotLength ++;
  12112. } else if ( light.isRectAreaLight ) {
  12113. const uniforms = cache.get( light );
  12114. // (a) intensity is the total visible light emitted
  12115. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12116. // (b) intensity is the brightness of the light
  12117. uniforms.color.copy( color ).multiplyScalar( intensity );
  12118. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12119. uniforms.position.applyMatrix4( viewMatrix );
  12120. // extract local rotation of light to derive width/height half vectors
  12121. matrix42.identity();
  12122. matrix4.copy( light.matrixWorld );
  12123. matrix4.premultiply( viewMatrix );
  12124. matrix42.extractRotation( matrix4 );
  12125. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  12126. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  12127. uniforms.halfWidth.applyMatrix4( matrix42 );
  12128. uniforms.halfHeight.applyMatrix4( matrix42 );
  12129. // TODO (abelnation): RectAreaLight distance?
  12130. // uniforms.distance = distance;
  12131. state.rectArea[ rectAreaLength ] = uniforms;
  12132. rectAreaLength ++;
  12133. } else if ( light.isPointLight ) {
  12134. const uniforms = cache.get( light );
  12135. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  12136. uniforms.position.applyMatrix4( viewMatrix );
  12137. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  12138. uniforms.distance = light.distance;
  12139. uniforms.decay = light.decay;
  12140. if ( light.castShadow ) {
  12141. const shadow = light.shadow;
  12142. const shadowUniforms = shadowCache.get( light );
  12143. shadowUniforms.shadowBias = shadow.bias;
  12144. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12145. shadowUniforms.shadowRadius = shadow.radius;
  12146. shadowUniforms.shadowMapSize = shadow.mapSize;
  12147. shadowUniforms.shadowCameraNear = shadow.camera.near;
  12148. shadowUniforms.shadowCameraFar = shadow.camera.far;
  12149. state.pointShadow[ pointLength ] = shadowUniforms;
  12150. state.pointShadowMap[ pointLength ] = shadowMap;
  12151. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  12152. numPointShadows ++;
  12153. }
  12154. state.point[ pointLength ] = uniforms;
  12155. pointLength ++;
  12156. } else if ( light.isHemisphereLight ) {
  12157. const uniforms = cache.get( light );
  12158. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  12159. uniforms.direction.transformDirection( viewMatrix );
  12160. uniforms.direction.normalize();
  12161. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  12162. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  12163. state.hemi[ hemiLength ] = uniforms;
  12164. hemiLength ++;
  12165. }
  12166. }
  12167. state.ambient[ 0 ] = r;
  12168. state.ambient[ 1 ] = g;
  12169. state.ambient[ 2 ] = b;
  12170. const hash = state.hash;
  12171. if ( hash.directionalLength !== directionalLength ||
  12172. hash.pointLength !== pointLength ||
  12173. hash.spotLength !== spotLength ||
  12174. hash.rectAreaLength !== rectAreaLength ||
  12175. hash.hemiLength !== hemiLength ||
  12176. hash.numDirectionalShadows !== numDirectionalShadows ||
  12177. hash.numPointShadows !== numPointShadows ||
  12178. hash.numSpotShadows !== numSpotShadows ) {
  12179. state.directional.length = directionalLength;
  12180. state.spot.length = spotLength;
  12181. state.rectArea.length = rectAreaLength;
  12182. state.point.length = pointLength;
  12183. state.hemi.length = hemiLength;
  12184. state.directionalShadow.length = numDirectionalShadows;
  12185. state.directionalShadowMap.length = numDirectionalShadows;
  12186. state.pointShadow.length = numPointShadows;
  12187. state.pointShadowMap.length = numPointShadows;
  12188. state.spotShadow.length = numSpotShadows;
  12189. state.spotShadowMap.length = numSpotShadows;
  12190. state.directionalShadowMatrix.length = numDirectionalShadows;
  12191. state.pointShadowMatrix.length = numPointShadows;
  12192. state.spotShadowMatrix.length = numSpotShadows;
  12193. hash.directionalLength = directionalLength;
  12194. hash.pointLength = pointLength;
  12195. hash.spotLength = spotLength;
  12196. hash.rectAreaLength = rectAreaLength;
  12197. hash.hemiLength = hemiLength;
  12198. hash.numDirectionalShadows = numDirectionalShadows;
  12199. hash.numPointShadows = numPointShadows;
  12200. hash.numSpotShadows = numSpotShadows;
  12201. state.version = nextVersion ++;
  12202. }
  12203. }
  12204. return {
  12205. setup: setup,
  12206. state: state
  12207. };
  12208. }
  12209. /**
  12210. * @author Mugen87 / https://github.com/Mugen87
  12211. */
  12212. function WebGLRenderState() {
  12213. const lights = new WebGLLights();
  12214. const lightsArray = [];
  12215. const shadowsArray = [];
  12216. function init() {
  12217. lightsArray.length = 0;
  12218. shadowsArray.length = 0;
  12219. }
  12220. function pushLight( light ) {
  12221. lightsArray.push( light );
  12222. }
  12223. function pushShadow( shadowLight ) {
  12224. shadowsArray.push( shadowLight );
  12225. }
  12226. function setupLights( camera ) {
  12227. lights.setup( lightsArray, shadowsArray, camera );
  12228. }
  12229. const state = {
  12230. lightsArray: lightsArray,
  12231. shadowsArray: shadowsArray,
  12232. lights: lights
  12233. };
  12234. return {
  12235. init: init,
  12236. state: state,
  12237. setupLights: setupLights,
  12238. pushLight: pushLight,
  12239. pushShadow: pushShadow
  12240. };
  12241. }
  12242. function WebGLRenderStates() {
  12243. let renderStates = new WeakMap();
  12244. function onSceneDispose( event ) {
  12245. const scene = event.target;
  12246. scene.removeEventListener( 'dispose', onSceneDispose );
  12247. renderStates.delete( scene );
  12248. }
  12249. function get( scene, camera ) {
  12250. let renderState;
  12251. if ( renderStates.has( scene ) === false ) {
  12252. renderState = new WebGLRenderState();
  12253. renderStates.set( scene, new WeakMap() );
  12254. renderStates.get( scene ).set( camera, renderState );
  12255. scene.addEventListener( 'dispose', onSceneDispose );
  12256. } else {
  12257. if ( renderStates.get( scene ).has( camera ) === false ) {
  12258. renderState = new WebGLRenderState();
  12259. renderStates.get( scene ).set( camera, renderState );
  12260. } else {
  12261. renderState = renderStates.get( scene ).get( camera );
  12262. }
  12263. }
  12264. return renderState;
  12265. }
  12266. function dispose() {
  12267. renderStates = new WeakMap();
  12268. }
  12269. return {
  12270. get: get,
  12271. dispose: dispose
  12272. };
  12273. }
  12274. /**
  12275. * @author mrdoob / http://mrdoob.com/
  12276. * @author alteredq / http://alteredqualia.com/
  12277. * @author bhouston / https://clara.io
  12278. * @author WestLangley / http://github.com/WestLangley
  12279. *
  12280. * parameters = {
  12281. *
  12282. * opacity: <float>,
  12283. *
  12284. * map: new THREE.Texture( <Image> ),
  12285. *
  12286. * alphaMap: new THREE.Texture( <Image> ),
  12287. *
  12288. * displacementMap: new THREE.Texture( <Image> ),
  12289. * displacementScale: <float>,
  12290. * displacementBias: <float>,
  12291. *
  12292. * wireframe: <boolean>,
  12293. * wireframeLinewidth: <float>
  12294. * }
  12295. */
  12296. function MeshDepthMaterial( parameters ) {
  12297. Material.call( this );
  12298. this.type = 'MeshDepthMaterial';
  12299. this.depthPacking = BasicDepthPacking;
  12300. this.skinning = false;
  12301. this.morphTargets = false;
  12302. this.map = null;
  12303. this.alphaMap = null;
  12304. this.displacementMap = null;
  12305. this.displacementScale = 1;
  12306. this.displacementBias = 0;
  12307. this.wireframe = false;
  12308. this.wireframeLinewidth = 1;
  12309. this.fog = false;
  12310. this.setValues( parameters );
  12311. }
  12312. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  12313. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12314. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12315. MeshDepthMaterial.prototype.copy = function ( source ) {
  12316. Material.prototype.copy.call( this, source );
  12317. this.depthPacking = source.depthPacking;
  12318. this.skinning = source.skinning;
  12319. this.morphTargets = source.morphTargets;
  12320. this.map = source.map;
  12321. this.alphaMap = source.alphaMap;
  12322. this.displacementMap = source.displacementMap;
  12323. this.displacementScale = source.displacementScale;
  12324. this.displacementBias = source.displacementBias;
  12325. this.wireframe = source.wireframe;
  12326. this.wireframeLinewidth = source.wireframeLinewidth;
  12327. return this;
  12328. };
  12329. /**
  12330. * @author WestLangley / http://github.com/WestLangley
  12331. *
  12332. * parameters = {
  12333. *
  12334. * referencePosition: <float>,
  12335. * nearDistance: <float>,
  12336. * farDistance: <float>,
  12337. *
  12338. * skinning: <bool>,
  12339. * morphTargets: <bool>,
  12340. *
  12341. * map: new THREE.Texture( <Image> ),
  12342. *
  12343. * alphaMap: new THREE.Texture( <Image> ),
  12344. *
  12345. * displacementMap: new THREE.Texture( <Image> ),
  12346. * displacementScale: <float>,
  12347. * displacementBias: <float>
  12348. *
  12349. * }
  12350. */
  12351. function MeshDistanceMaterial( parameters ) {
  12352. Material.call( this );
  12353. this.type = 'MeshDistanceMaterial';
  12354. this.referencePosition = new Vector3();
  12355. this.nearDistance = 1;
  12356. this.farDistance = 1000;
  12357. this.skinning = false;
  12358. this.morphTargets = false;
  12359. this.map = null;
  12360. this.alphaMap = null;
  12361. this.displacementMap = null;
  12362. this.displacementScale = 1;
  12363. this.displacementBias = 0;
  12364. this.fog = false;
  12365. this.setValues( parameters );
  12366. }
  12367. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  12368. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12369. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12370. MeshDistanceMaterial.prototype.copy = function ( source ) {
  12371. Material.prototype.copy.call( this, source );
  12372. this.referencePosition.copy( source.referencePosition );
  12373. this.nearDistance = source.nearDistance;
  12374. this.farDistance = source.farDistance;
  12375. this.skinning = source.skinning;
  12376. this.morphTargets = source.morphTargets;
  12377. this.map = source.map;
  12378. this.alphaMap = source.alphaMap;
  12379. this.displacementMap = source.displacementMap;
  12380. this.displacementScale = source.displacementScale;
  12381. this.displacementBias = source.displacementBias;
  12382. return this;
  12383. };
  12384. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n float mean = 0.0;\n float squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n for ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n #ifdef HORIZONAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean * HALF_SAMPLE_RATE;\n squared_mean = squared_mean * HALF_SAMPLE_RATE;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12385. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12386. /**
  12387. * @author alteredq / http://alteredqualia.com/
  12388. * @author mrdoob / http://mrdoob.com/
  12389. */
  12390. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  12391. let _frustum = new Frustum();
  12392. const _shadowMapSize = new Vector2(),
  12393. _viewportSize = new Vector2(),
  12394. _viewport = new Vector4(),
  12395. _depthMaterials = [],
  12396. _distanceMaterials = [],
  12397. _materialCache = {};
  12398. const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  12399. const shadowMaterialVertical = new ShaderMaterial( {
  12400. defines: {
  12401. SAMPLE_RATE: 2.0 / 8.0,
  12402. HALF_SAMPLE_RATE: 1.0 / 8.0
  12403. },
  12404. uniforms: {
  12405. shadow_pass: { value: null },
  12406. resolution: { value: new Vector2() },
  12407. radius: { value: 4.0 }
  12408. },
  12409. vertexShader: vsm_vert,
  12410. fragmentShader: vsm_frag
  12411. } );
  12412. const shadowMaterialHorizonal = shadowMaterialVertical.clone();
  12413. shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1;
  12414. const fullScreenTri = new BufferGeometry();
  12415. fullScreenTri.setAttribute(
  12416. "position",
  12417. new BufferAttribute(
  12418. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  12419. 3
  12420. )
  12421. );
  12422. const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  12423. const scope = this;
  12424. this.enabled = false;
  12425. this.autoUpdate = true;
  12426. this.needsUpdate = false;
  12427. this.type = PCFShadowMap;
  12428. this.render = function ( lights, scene, camera ) {
  12429. if ( scope.enabled === false ) return;
  12430. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  12431. if ( lights.length === 0 ) return;
  12432. const currentRenderTarget = _renderer.getRenderTarget();
  12433. const activeCubeFace = _renderer.getActiveCubeFace();
  12434. const activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12435. const _state = _renderer.state;
  12436. // Set GL state for depth map.
  12437. _state.setBlending( NoBlending );
  12438. _state.buffers.color.setClear( 1, 1, 1, 1 );
  12439. _state.buffers.depth.setTest( true );
  12440. _state.setScissorTest( false );
  12441. // render depth map
  12442. for ( let i = 0, il = lights.length; i < il; i ++ ) {
  12443. const light = lights[ i ];
  12444. const shadow = light.shadow;
  12445. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;
  12446. if ( shadow === undefined ) {
  12447. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  12448. continue;
  12449. }
  12450. _shadowMapSize.copy( shadow.mapSize );
  12451. const shadowFrameExtents = shadow.getFrameExtents();
  12452. _shadowMapSize.multiply( shadowFrameExtents );
  12453. _viewportSize.copy( shadow.mapSize );
  12454. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  12455. if ( _shadowMapSize.x > maxTextureSize ) {
  12456. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  12457. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12458. shadow.mapSize.x = _viewportSize.x;
  12459. }
  12460. if ( _shadowMapSize.y > maxTextureSize ) {
  12461. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  12462. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12463. shadow.mapSize.y = _viewportSize.y;
  12464. }
  12465. }
  12466. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12467. const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  12468. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12469. shadow.map.texture.name = light.name + ".shadowMap";
  12470. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12471. shadow.camera.updateProjectionMatrix();
  12472. }
  12473. if ( shadow.map === null ) {
  12474. const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  12475. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  12476. shadow.map.texture.name = light.name + ".shadowMap";
  12477. shadow.camera.updateProjectionMatrix();
  12478. }
  12479. _renderer.setRenderTarget( shadow.map );
  12480. _renderer.clear();
  12481. const viewportCount = shadow.getViewportCount();
  12482. for ( let vp = 0; vp < viewportCount; vp ++ ) {
  12483. const viewport = shadow.getViewport( vp );
  12484. _viewport.set(
  12485. _viewportSize.x * viewport.x,
  12486. _viewportSize.y * viewport.y,
  12487. _viewportSize.x * viewport.z,
  12488. _viewportSize.y * viewport.w
  12489. );
  12490. _state.viewport( _viewport );
  12491. shadow.updateMatrices( light, vp );
  12492. _frustum = shadow.getFrustum();
  12493. renderObject( scene, camera, shadow.camera, light, this.type );
  12494. }
  12495. // do blur pass for VSM
  12496. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  12497. VSMPass( shadow, camera );
  12498. }
  12499. shadow.needsUpdate = false;
  12500. }
  12501. scope.needsUpdate = false;
  12502. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  12503. };
  12504. function VSMPass( shadow, camera ) {
  12505. const geometry = _objects.update( fullScreenMesh );
  12506. // vertical pass
  12507. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12508. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12509. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12510. _renderer.setRenderTarget( shadow.mapPass );
  12511. _renderer.clear();
  12512. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  12513. // horizonal pass
  12514. shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12515. shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize;
  12516. shadowMaterialHorizonal.uniforms.radius.value = shadow.radius;
  12517. _renderer.setRenderTarget( shadow.map );
  12518. _renderer.clear();
  12519. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null );
  12520. }
  12521. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12522. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12523. let material = _depthMaterials[ index ];
  12524. if ( material === undefined ) {
  12525. material = new MeshDepthMaterial( {
  12526. depthPacking: RGBADepthPacking,
  12527. morphTargets: useMorphing,
  12528. skinning: useSkinning
  12529. } );
  12530. _depthMaterials[ index ] = material;
  12531. }
  12532. return material;
  12533. }
  12534. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  12535. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12536. let material = _distanceMaterials[ index ];
  12537. if ( material === undefined ) {
  12538. material = new MeshDistanceMaterial( {
  12539. morphTargets: useMorphing,
  12540. skinning: useSkinning
  12541. } );
  12542. _distanceMaterials[ index ] = material;
  12543. }
  12544. return material;
  12545. }
  12546. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  12547. let result = null;
  12548. let getMaterialVariant = getDepthMaterialVariant;
  12549. let customMaterial = object.customDepthMaterial;
  12550. if ( light.isPointLight === true ) {
  12551. getMaterialVariant = getDistanceMaterialVariant;
  12552. customMaterial = object.customDistanceMaterial;
  12553. }
  12554. if ( customMaterial === undefined ) {
  12555. let useMorphing = false;
  12556. if ( material.morphTargets === true ) {
  12557. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12558. }
  12559. let useSkinning = false;
  12560. if ( object.isSkinnedMesh === true ) {
  12561. if ( material.skinning === true ) {
  12562. useSkinning = true;
  12563. } else {
  12564. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  12565. }
  12566. }
  12567. const useInstancing = object.isInstancedMesh === true;
  12568. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  12569. } else {
  12570. result = customMaterial;
  12571. }
  12572. if ( _renderer.localClippingEnabled &&
  12573. material.clipShadows === true &&
  12574. material.clippingPlanes.length !== 0 ) {
  12575. // in this case we need a unique material instance reflecting the
  12576. // appropriate state
  12577. const keyA = result.uuid, keyB = material.uuid;
  12578. let materialsForVariant = _materialCache[ keyA ];
  12579. if ( materialsForVariant === undefined ) {
  12580. materialsForVariant = {};
  12581. _materialCache[ keyA ] = materialsForVariant;
  12582. }
  12583. let cachedMaterial = materialsForVariant[ keyB ];
  12584. if ( cachedMaterial === undefined ) {
  12585. cachedMaterial = result.clone();
  12586. materialsForVariant[ keyB ] = cachedMaterial;
  12587. }
  12588. result = cachedMaterial;
  12589. }
  12590. result.visible = material.visible;
  12591. result.wireframe = material.wireframe;
  12592. if ( type === VSMShadowMap ) {
  12593. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  12594. } else {
  12595. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  12596. }
  12597. result.clipShadows = material.clipShadows;
  12598. result.clippingPlanes = material.clippingPlanes;
  12599. result.clipIntersection = material.clipIntersection;
  12600. result.wireframeLinewidth = material.wireframeLinewidth;
  12601. result.linewidth = material.linewidth;
  12602. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  12603. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  12604. result.nearDistance = shadowCameraNear;
  12605. result.farDistance = shadowCameraFar;
  12606. }
  12607. return result;
  12608. }
  12609. function renderObject( object, camera, shadowCamera, light, type ) {
  12610. if ( object.visible === false ) return;
  12611. const visible = object.layers.test( camera.layers );
  12612. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  12613. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  12614. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  12615. const geometry = _objects.update( object );
  12616. const material = object.material;
  12617. if ( Array.isArray( material ) ) {
  12618. const groups = geometry.groups;
  12619. for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
  12620. const group = groups[ k ];
  12621. const groupMaterial = material[ group.materialIndex ];
  12622. if ( groupMaterial && groupMaterial.visible ) {
  12623. const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  12624. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  12625. }
  12626. }
  12627. } else if ( material.visible ) {
  12628. const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  12629. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  12630. }
  12631. }
  12632. }
  12633. const children = object.children;
  12634. for ( let i = 0, l = children.length; i < l; i ++ ) {
  12635. renderObject( children[ i ], camera, shadowCamera, light, type );
  12636. }
  12637. }
  12638. }
  12639. /**
  12640. * @author mrdoob / http://mrdoob.com/
  12641. */
  12642. function WebGLState( gl, extensions, capabilities ) {
  12643. const isWebGL2 = capabilities.isWebGL2;
  12644. function ColorBuffer() {
  12645. let locked = false;
  12646. const color = new Vector4();
  12647. let currentColorMask = null;
  12648. const currentColorClear = new Vector4( 0, 0, 0, 0 );
  12649. return {
  12650. setMask: function ( colorMask ) {
  12651. if ( currentColorMask !== colorMask && ! locked ) {
  12652. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  12653. currentColorMask = colorMask;
  12654. }
  12655. },
  12656. setLocked: function ( lock ) {
  12657. locked = lock;
  12658. },
  12659. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  12660. if ( premultipliedAlpha === true ) {
  12661. r *= a; g *= a; b *= a;
  12662. }
  12663. color.set( r, g, b, a );
  12664. if ( currentColorClear.equals( color ) === false ) {
  12665. gl.clearColor( r, g, b, a );
  12666. currentColorClear.copy( color );
  12667. }
  12668. },
  12669. reset: function () {
  12670. locked = false;
  12671. currentColorMask = null;
  12672. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  12673. }
  12674. };
  12675. }
  12676. function DepthBuffer() {
  12677. let locked = false;
  12678. let currentDepthMask = null;
  12679. let currentDepthFunc = null;
  12680. let currentDepthClear = null;
  12681. return {
  12682. setTest: function ( depthTest ) {
  12683. if ( depthTest ) {
  12684. enable( 2929 );
  12685. } else {
  12686. disable( 2929 );
  12687. }
  12688. },
  12689. setMask: function ( depthMask ) {
  12690. if ( currentDepthMask !== depthMask && ! locked ) {
  12691. gl.depthMask( depthMask );
  12692. currentDepthMask = depthMask;
  12693. }
  12694. },
  12695. setFunc: function ( depthFunc ) {
  12696. if ( currentDepthFunc !== depthFunc ) {
  12697. if ( depthFunc ) {
  12698. switch ( depthFunc ) {
  12699. case NeverDepth:
  12700. gl.depthFunc( 512 );
  12701. break;
  12702. case AlwaysDepth:
  12703. gl.depthFunc( 519 );
  12704. break;
  12705. case LessDepth:
  12706. gl.depthFunc( 513 );
  12707. break;
  12708. case LessEqualDepth:
  12709. gl.depthFunc( 515 );
  12710. break;
  12711. case EqualDepth:
  12712. gl.depthFunc( 514 );
  12713. break;
  12714. case GreaterEqualDepth:
  12715. gl.depthFunc( 518 );
  12716. break;
  12717. case GreaterDepth:
  12718. gl.depthFunc( 516 );
  12719. break;
  12720. case NotEqualDepth:
  12721. gl.depthFunc( 517 );
  12722. break;
  12723. default:
  12724. gl.depthFunc( 515 );
  12725. }
  12726. } else {
  12727. gl.depthFunc( 515 );
  12728. }
  12729. currentDepthFunc = depthFunc;
  12730. }
  12731. },
  12732. setLocked: function ( lock ) {
  12733. locked = lock;
  12734. },
  12735. setClear: function ( depth ) {
  12736. if ( currentDepthClear !== depth ) {
  12737. gl.clearDepth( depth );
  12738. currentDepthClear = depth;
  12739. }
  12740. },
  12741. reset: function () {
  12742. locked = false;
  12743. currentDepthMask = null;
  12744. currentDepthFunc = null;
  12745. currentDepthClear = null;
  12746. }
  12747. };
  12748. }
  12749. function StencilBuffer() {
  12750. let locked = false;
  12751. let currentStencilMask = null;
  12752. let currentStencilFunc = null;
  12753. let currentStencilRef = null;
  12754. let currentStencilFuncMask = null;
  12755. let currentStencilFail = null;
  12756. let currentStencilZFail = null;
  12757. let currentStencilZPass = null;
  12758. let currentStencilClear = null;
  12759. return {
  12760. setTest: function ( stencilTest ) {
  12761. if ( ! locked ) {
  12762. if ( stencilTest ) {
  12763. enable( 2960 );
  12764. } else {
  12765. disable( 2960 );
  12766. }
  12767. }
  12768. },
  12769. setMask: function ( stencilMask ) {
  12770. if ( currentStencilMask !== stencilMask && ! locked ) {
  12771. gl.stencilMask( stencilMask );
  12772. currentStencilMask = stencilMask;
  12773. }
  12774. },
  12775. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12776. if ( currentStencilFunc !== stencilFunc ||
  12777. currentStencilRef !== stencilRef ||
  12778. currentStencilFuncMask !== stencilMask ) {
  12779. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12780. currentStencilFunc = stencilFunc;
  12781. currentStencilRef = stencilRef;
  12782. currentStencilFuncMask = stencilMask;
  12783. }
  12784. },
  12785. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12786. if ( currentStencilFail !== stencilFail ||
  12787. currentStencilZFail !== stencilZFail ||
  12788. currentStencilZPass !== stencilZPass ) {
  12789. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12790. currentStencilFail = stencilFail;
  12791. currentStencilZFail = stencilZFail;
  12792. currentStencilZPass = stencilZPass;
  12793. }
  12794. },
  12795. setLocked: function ( lock ) {
  12796. locked = lock;
  12797. },
  12798. setClear: function ( stencil ) {
  12799. if ( currentStencilClear !== stencil ) {
  12800. gl.clearStencil( stencil );
  12801. currentStencilClear = stencil;
  12802. }
  12803. },
  12804. reset: function () {
  12805. locked = false;
  12806. currentStencilMask = null;
  12807. currentStencilFunc = null;
  12808. currentStencilRef = null;
  12809. currentStencilFuncMask = null;
  12810. currentStencilFail = null;
  12811. currentStencilZFail = null;
  12812. currentStencilZPass = null;
  12813. currentStencilClear = null;
  12814. }
  12815. };
  12816. }
  12817. //
  12818. const colorBuffer = new ColorBuffer();
  12819. const depthBuffer = new DepthBuffer();
  12820. const stencilBuffer = new StencilBuffer();
  12821. let enabledCapabilities = {};
  12822. let currentProgram = null;
  12823. let currentBlendingEnabled = null;
  12824. let currentBlending = null;
  12825. let currentBlendEquation = null;
  12826. let currentBlendSrc = null;
  12827. let currentBlendDst = null;
  12828. let currentBlendEquationAlpha = null;
  12829. let currentBlendSrcAlpha = null;
  12830. let currentBlendDstAlpha = null;
  12831. let currentPremultipledAlpha = false;
  12832. let currentFlipSided = null;
  12833. let currentCullFace = null;
  12834. let currentLineWidth = null;
  12835. let currentPolygonOffsetFactor = null;
  12836. let currentPolygonOffsetUnits = null;
  12837. const maxTextures = gl.getParameter( 35661 );
  12838. let lineWidthAvailable = false;
  12839. let version = 0;
  12840. const glVersion = gl.getParameter( 7938 );
  12841. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12842. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12843. lineWidthAvailable = ( version >= 1.0 );
  12844. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12845. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12846. lineWidthAvailable = ( version >= 2.0 );
  12847. }
  12848. let currentTextureSlot = null;
  12849. let currentBoundTextures = {};
  12850. const currentScissor = new Vector4();
  12851. const currentViewport = new Vector4();
  12852. function createTexture( type, target, count ) {
  12853. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12854. const texture = gl.createTexture();
  12855. gl.bindTexture( type, texture );
  12856. gl.texParameteri( type, 10241, 9728 );
  12857. gl.texParameteri( type, 10240, 9728 );
  12858. for ( let i = 0; i < count; i ++ ) {
  12859. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12860. }
  12861. return texture;
  12862. }
  12863. const emptyTextures = {};
  12864. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12865. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12866. // init
  12867. colorBuffer.setClear( 0, 0, 0, 1 );
  12868. depthBuffer.setClear( 1 );
  12869. stencilBuffer.setClear( 0 );
  12870. enable( 2929 );
  12871. depthBuffer.setFunc( LessEqualDepth );
  12872. setFlipSided( false );
  12873. setCullFace( CullFaceBack );
  12874. enable( 2884 );
  12875. setBlending( NoBlending );
  12876. //
  12877. function enable( id ) {
  12878. if ( enabledCapabilities[ id ] !== true ) {
  12879. gl.enable( id );
  12880. enabledCapabilities[ id ] = true;
  12881. }
  12882. }
  12883. function disable( id ) {
  12884. if ( enabledCapabilities[ id ] !== false ) {
  12885. gl.disable( id );
  12886. enabledCapabilities[ id ] = false;
  12887. }
  12888. }
  12889. function useProgram( program ) {
  12890. if ( currentProgram !== program ) {
  12891. gl.useProgram( program );
  12892. currentProgram = program;
  12893. return true;
  12894. }
  12895. return false;
  12896. }
  12897. const equationToGL = {
  12898. [ AddEquation ]: 32774,
  12899. [ SubtractEquation ]: 32778,
  12900. [ ReverseSubtractEquation ]: 32779
  12901. };
  12902. if ( isWebGL2 ) {
  12903. equationToGL[ MinEquation ] = 32775;
  12904. equationToGL[ MaxEquation ] = 32776;
  12905. } else {
  12906. const extension = extensions.get( 'EXT_blend_minmax' );
  12907. if ( extension !== null ) {
  12908. equationToGL[ MinEquation ] = extension.MIN_EXT;
  12909. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  12910. }
  12911. }
  12912. const factorToGL = {
  12913. [ ZeroFactor ]: 0,
  12914. [ OneFactor ]: 1,
  12915. [ SrcColorFactor ]: 768,
  12916. [ SrcAlphaFactor ]: 770,
  12917. [ SrcAlphaSaturateFactor ]: 776,
  12918. [ DstColorFactor ]: 774,
  12919. [ DstAlphaFactor ]: 772,
  12920. [ OneMinusSrcColorFactor ]: 769,
  12921. [ OneMinusSrcAlphaFactor ]: 771,
  12922. [ OneMinusDstColorFactor ]: 775,
  12923. [ OneMinusDstAlphaFactor ]: 773
  12924. };
  12925. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12926. if ( blending === NoBlending ) {
  12927. if ( currentBlendingEnabled ) {
  12928. disable( 3042 );
  12929. currentBlendingEnabled = false;
  12930. }
  12931. return;
  12932. }
  12933. if ( ! currentBlendingEnabled ) {
  12934. enable( 3042 );
  12935. currentBlendingEnabled = true;
  12936. }
  12937. if ( blending !== CustomBlending ) {
  12938. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12939. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12940. gl.blendEquation( 32774 );
  12941. currentBlendEquation = AddEquation;
  12942. currentBlendEquationAlpha = AddEquation;
  12943. }
  12944. if ( premultipliedAlpha ) {
  12945. switch ( blending ) {
  12946. case NormalBlending:
  12947. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12948. break;
  12949. case AdditiveBlending:
  12950. gl.blendFunc( 1, 1 );
  12951. break;
  12952. case SubtractiveBlending:
  12953. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12954. break;
  12955. case MultiplyBlending:
  12956. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12957. break;
  12958. default:
  12959. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12960. break;
  12961. }
  12962. } else {
  12963. switch ( blending ) {
  12964. case NormalBlending:
  12965. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12966. break;
  12967. case AdditiveBlending:
  12968. gl.blendFunc( 770, 1 );
  12969. break;
  12970. case SubtractiveBlending:
  12971. gl.blendFunc( 0, 769 );
  12972. break;
  12973. case MultiplyBlending:
  12974. gl.blendFunc( 0, 768 );
  12975. break;
  12976. default:
  12977. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12978. break;
  12979. }
  12980. }
  12981. currentBlendSrc = null;
  12982. currentBlendDst = null;
  12983. currentBlendSrcAlpha = null;
  12984. currentBlendDstAlpha = null;
  12985. currentBlending = blending;
  12986. currentPremultipledAlpha = premultipliedAlpha;
  12987. }
  12988. return;
  12989. }
  12990. // custom blending
  12991. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12992. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12993. blendDstAlpha = blendDstAlpha || blendDst;
  12994. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12995. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12996. currentBlendEquation = blendEquation;
  12997. currentBlendEquationAlpha = blendEquationAlpha;
  12998. }
  12999. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  13000. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  13001. currentBlendSrc = blendSrc;
  13002. currentBlendDst = blendDst;
  13003. currentBlendSrcAlpha = blendSrcAlpha;
  13004. currentBlendDstAlpha = blendDstAlpha;
  13005. }
  13006. currentBlending = blending;
  13007. currentPremultipledAlpha = null;
  13008. }
  13009. function setMaterial( material, frontFaceCW ) {
  13010. material.side === DoubleSide
  13011. ? disable( 2884 )
  13012. : enable( 2884 );
  13013. let flipSided = ( material.side === BackSide );
  13014. if ( frontFaceCW ) flipSided = ! flipSided;
  13015. setFlipSided( flipSided );
  13016. ( material.blending === NormalBlending && material.transparent === false )
  13017. ? setBlending( NoBlending )
  13018. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  13019. depthBuffer.setFunc( material.depthFunc );
  13020. depthBuffer.setTest( material.depthTest );
  13021. depthBuffer.setMask( material.depthWrite );
  13022. colorBuffer.setMask( material.colorWrite );
  13023. const stencilWrite = material.stencilWrite;
  13024. stencilBuffer.setTest( stencilWrite );
  13025. if ( stencilWrite ) {
  13026. stencilBuffer.setMask( material.stencilWriteMask );
  13027. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  13028. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  13029. }
  13030. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13031. }
  13032. //
  13033. function setFlipSided( flipSided ) {
  13034. if ( currentFlipSided !== flipSided ) {
  13035. if ( flipSided ) {
  13036. gl.frontFace( 2304 );
  13037. } else {
  13038. gl.frontFace( 2305 );
  13039. }
  13040. currentFlipSided = flipSided;
  13041. }
  13042. }
  13043. function setCullFace( cullFace ) {
  13044. if ( cullFace !== CullFaceNone ) {
  13045. enable( 2884 );
  13046. if ( cullFace !== currentCullFace ) {
  13047. if ( cullFace === CullFaceBack ) {
  13048. gl.cullFace( 1029 );
  13049. } else if ( cullFace === CullFaceFront ) {
  13050. gl.cullFace( 1028 );
  13051. } else {
  13052. gl.cullFace( 1032 );
  13053. }
  13054. }
  13055. } else {
  13056. disable( 2884 );
  13057. }
  13058. currentCullFace = cullFace;
  13059. }
  13060. function setLineWidth( width ) {
  13061. if ( width !== currentLineWidth ) {
  13062. if ( lineWidthAvailable ) gl.lineWidth( width );
  13063. currentLineWidth = width;
  13064. }
  13065. }
  13066. function setPolygonOffset( polygonOffset, factor, units ) {
  13067. if ( polygonOffset ) {
  13068. enable( 32823 );
  13069. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  13070. gl.polygonOffset( factor, units );
  13071. currentPolygonOffsetFactor = factor;
  13072. currentPolygonOffsetUnits = units;
  13073. }
  13074. } else {
  13075. disable( 32823 );
  13076. }
  13077. }
  13078. function setScissorTest( scissorTest ) {
  13079. if ( scissorTest ) {
  13080. enable( 3089 );
  13081. } else {
  13082. disable( 3089 );
  13083. }
  13084. }
  13085. // texture
  13086. function activeTexture( webglSlot ) {
  13087. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  13088. if ( currentTextureSlot !== webglSlot ) {
  13089. gl.activeTexture( webglSlot );
  13090. currentTextureSlot = webglSlot;
  13091. }
  13092. }
  13093. function bindTexture( webglType, webglTexture ) {
  13094. if ( currentTextureSlot === null ) {
  13095. activeTexture();
  13096. }
  13097. let boundTexture = currentBoundTextures[ currentTextureSlot ];
  13098. if ( boundTexture === undefined ) {
  13099. boundTexture = { type: undefined, texture: undefined };
  13100. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  13101. }
  13102. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  13103. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  13104. boundTexture.type = webglType;
  13105. boundTexture.texture = webglTexture;
  13106. }
  13107. }
  13108. function unbindTexture() {
  13109. const boundTexture = currentBoundTextures[ currentTextureSlot ];
  13110. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  13111. gl.bindTexture( boundTexture.type, null );
  13112. boundTexture.type = undefined;
  13113. boundTexture.texture = undefined;
  13114. }
  13115. }
  13116. function compressedTexImage2D() {
  13117. try {
  13118. gl.compressedTexImage2D.apply( gl, arguments );
  13119. } catch ( error ) {
  13120. console.error( 'THREE.WebGLState:', error );
  13121. }
  13122. }
  13123. function texImage2D() {
  13124. try {
  13125. gl.texImage2D.apply( gl, arguments );
  13126. } catch ( error ) {
  13127. console.error( 'THREE.WebGLState:', error );
  13128. }
  13129. }
  13130. function texImage3D() {
  13131. try {
  13132. gl.texImage3D.apply( gl, arguments );
  13133. } catch ( error ) {
  13134. console.error( 'THREE.WebGLState:', error );
  13135. }
  13136. }
  13137. //
  13138. function scissor( scissor ) {
  13139. if ( currentScissor.equals( scissor ) === false ) {
  13140. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  13141. currentScissor.copy( scissor );
  13142. }
  13143. }
  13144. function viewport( viewport ) {
  13145. if ( currentViewport.equals( viewport ) === false ) {
  13146. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  13147. currentViewport.copy( viewport );
  13148. }
  13149. }
  13150. //
  13151. function reset() {
  13152. enabledCapabilities = {};
  13153. currentTextureSlot = null;
  13154. currentBoundTextures = {};
  13155. currentProgram = null;
  13156. currentBlending = null;
  13157. currentFlipSided = null;
  13158. currentCullFace = null;
  13159. colorBuffer.reset();
  13160. depthBuffer.reset();
  13161. stencilBuffer.reset();
  13162. }
  13163. return {
  13164. buffers: {
  13165. color: colorBuffer,
  13166. depth: depthBuffer,
  13167. stencil: stencilBuffer
  13168. },
  13169. enable: enable,
  13170. disable: disable,
  13171. useProgram: useProgram,
  13172. setBlending: setBlending,
  13173. setMaterial: setMaterial,
  13174. setFlipSided: setFlipSided,
  13175. setCullFace: setCullFace,
  13176. setLineWidth: setLineWidth,
  13177. setPolygonOffset: setPolygonOffset,
  13178. setScissorTest: setScissorTest,
  13179. activeTexture: activeTexture,
  13180. bindTexture: bindTexture,
  13181. unbindTexture: unbindTexture,
  13182. compressedTexImage2D: compressedTexImage2D,
  13183. texImage2D: texImage2D,
  13184. texImage3D: texImage3D,
  13185. scissor: scissor,
  13186. viewport: viewport,
  13187. reset: reset
  13188. };
  13189. }
  13190. /**
  13191. * @author mrdoob / http://mrdoob.com/
  13192. */
  13193. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  13194. const isWebGL2 = capabilities.isWebGL2;
  13195. const maxTextures = capabilities.maxTextures;
  13196. const maxCubemapSize = capabilities.maxCubemapSize;
  13197. const maxTextureSize = capabilities.maxTextureSize;
  13198. const maxSamples = capabilities.maxSamples;
  13199. const _videoTextures = new WeakMap();
  13200. let _canvas;
  13201. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13202. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13203. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13204. let useOffscreenCanvas = false;
  13205. try {
  13206. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  13207. && ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
  13208. } catch ( err ) {
  13209. // Ignore any errors
  13210. }
  13211. function createCanvas( width, height ) {
  13212. // Use OffscreenCanvas when available. Specially needed in web workers
  13213. return useOffscreenCanvas ?
  13214. new OffscreenCanvas( width, height ) :
  13215. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13216. }
  13217. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  13218. let scale = 1;
  13219. // handle case if texture exceeds max size
  13220. if ( image.width > maxSize || image.height > maxSize ) {
  13221. scale = maxSize / Math.max( image.width, image.height );
  13222. }
  13223. // only perform resize if necessary
  13224. if ( scale < 1 || needsPowerOfTwo === true ) {
  13225. // only perform resize for certain image types
  13226. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  13227. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  13228. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  13229. const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13230. const width = floor( scale * image.width );
  13231. const height = floor( scale * image.height );
  13232. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  13233. // cube textures can't reuse the same canvas
  13234. const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  13235. canvas.width = width;
  13236. canvas.height = height;
  13237. const context = canvas.getContext( '2d' );
  13238. context.drawImage( image, 0, 0, width, height );
  13239. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  13240. return canvas;
  13241. } else {
  13242. if ( 'data' in image ) {
  13243. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  13244. }
  13245. return image;
  13246. }
  13247. }
  13248. return image;
  13249. }
  13250. function isPowerOfTwo( image ) {
  13251. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  13252. }
  13253. function textureNeedsPowerOfTwo( texture ) {
  13254. if ( isWebGL2 ) return false;
  13255. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  13256. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  13257. }
  13258. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  13259. return texture.generateMipmaps && supportsMips &&
  13260. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13261. }
  13262. function generateMipmap( target, texture, width, height ) {
  13263. _gl.generateMipmap( target );
  13264. const textureProperties = properties.get( texture );
  13265. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13266. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  13267. }
  13268. function getInternalFormat( internalFormatName, glFormat, glType ) {
  13269. if ( isWebGL2 === false ) return glFormat;
  13270. if ( internalFormatName !== null ) {
  13271. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  13272. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  13273. }
  13274. let internalFormat = glFormat;
  13275. if ( glFormat === 6403 ) {
  13276. if ( glType === 5126 ) internalFormat = 33326;
  13277. if ( glType === 5131 ) internalFormat = 33325;
  13278. if ( glType === 5121 ) internalFormat = 33321;
  13279. }
  13280. if ( glFormat === 6407 ) {
  13281. if ( glType === 5126 ) internalFormat = 34837;
  13282. if ( glType === 5131 ) internalFormat = 34843;
  13283. if ( glType === 5121 ) internalFormat = 32849;
  13284. }
  13285. if ( glFormat === 6408 ) {
  13286. if ( glType === 5126 ) internalFormat = 34836;
  13287. if ( glType === 5131 ) internalFormat = 34842;
  13288. if ( glType === 5121 ) internalFormat = 32856;
  13289. }
  13290. if ( internalFormat === 33325 || internalFormat === 33326 ||
  13291. internalFormat === 34842 || internalFormat === 34836 ) {
  13292. extensions.get( 'EXT_color_buffer_float' );
  13293. }
  13294. return internalFormat;
  13295. }
  13296. // Fallback filters for non-power-of-2 textures
  13297. function filterFallback( f ) {
  13298. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  13299. return 9728;
  13300. }
  13301. return 9729;
  13302. }
  13303. //
  13304. function onTextureDispose( event ) {
  13305. const texture = event.target;
  13306. texture.removeEventListener( 'dispose', onTextureDispose );
  13307. deallocateTexture( texture );
  13308. if ( texture.isVideoTexture ) {
  13309. _videoTextures.delete( texture );
  13310. }
  13311. info.memory.textures --;
  13312. }
  13313. function onRenderTargetDispose( event ) {
  13314. const renderTarget = event.target;
  13315. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13316. deallocateRenderTarget( renderTarget );
  13317. info.memory.textures --;
  13318. }
  13319. //
  13320. function deallocateTexture( texture ) {
  13321. const textureProperties = properties.get( texture );
  13322. if ( textureProperties.__webglInit === undefined ) return;
  13323. _gl.deleteTexture( textureProperties.__webglTexture );
  13324. properties.remove( texture );
  13325. }
  13326. function deallocateRenderTarget( renderTarget ) {
  13327. const renderTargetProperties = properties.get( renderTarget );
  13328. const textureProperties = properties.get( renderTarget.texture );
  13329. if ( ! renderTarget ) return;
  13330. if ( textureProperties.__webglTexture !== undefined ) {
  13331. _gl.deleteTexture( textureProperties.__webglTexture );
  13332. }
  13333. if ( renderTarget.depthTexture ) {
  13334. renderTarget.depthTexture.dispose();
  13335. }
  13336. if ( renderTarget.isWebGLCubeRenderTarget ) {
  13337. for ( let i = 0; i < 6; i ++ ) {
  13338. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13339. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  13340. }
  13341. } else {
  13342. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13343. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  13344. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  13345. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  13346. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  13347. }
  13348. properties.remove( renderTarget.texture );
  13349. properties.remove( renderTarget );
  13350. }
  13351. //
  13352. let textureUnits = 0;
  13353. function resetTextureUnits() {
  13354. textureUnits = 0;
  13355. }
  13356. function allocateTextureUnit() {
  13357. const textureUnit = textureUnits;
  13358. if ( textureUnit >= maxTextures ) {
  13359. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  13360. }
  13361. textureUnits += 1;
  13362. return textureUnit;
  13363. }
  13364. //
  13365. function setTexture2D( texture, slot ) {
  13366. const textureProperties = properties.get( texture );
  13367. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  13368. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13369. const image = texture.image;
  13370. if ( image === undefined ) {
  13371. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  13372. } else if ( image.complete === false ) {
  13373. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  13374. } else {
  13375. uploadTexture( textureProperties, texture, slot );
  13376. return;
  13377. }
  13378. }
  13379. state.activeTexture( 33984 + slot );
  13380. state.bindTexture( 3553, textureProperties.__webglTexture );
  13381. }
  13382. function setTexture2DArray( texture, slot ) {
  13383. const textureProperties = properties.get( texture );
  13384. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13385. uploadTexture( textureProperties, texture, slot );
  13386. return;
  13387. }
  13388. state.activeTexture( 33984 + slot );
  13389. state.bindTexture( 35866, textureProperties.__webglTexture );
  13390. }
  13391. function setTexture3D( texture, slot ) {
  13392. const textureProperties = properties.get( texture );
  13393. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13394. uploadTexture( textureProperties, texture, slot );
  13395. return;
  13396. }
  13397. state.activeTexture( 33984 + slot );
  13398. state.bindTexture( 32879, textureProperties.__webglTexture );
  13399. }
  13400. function setTextureCube( texture, slot ) {
  13401. if ( texture.image.length !== 6 ) return;
  13402. const textureProperties = properties.get( texture );
  13403. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13404. initTexture( textureProperties, texture );
  13405. state.activeTexture( 33984 + slot );
  13406. state.bindTexture( 34067, textureProperties.__webglTexture );
  13407. _gl.pixelStorei( 37440, texture.flipY );
  13408. const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  13409. const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  13410. const cubeImage = [];
  13411. for ( let i = 0; i < 6; i ++ ) {
  13412. if ( ! isCompressed && ! isDataTexture ) {
  13413. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  13414. } else {
  13415. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13416. }
  13417. }
  13418. const image = cubeImage[ 0 ],
  13419. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13420. glFormat = utils.convert( texture.format ),
  13421. glType = utils.convert( texture.type ),
  13422. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13423. setTextureParameters( 34067, texture, supportsMips );
  13424. let mipmaps;
  13425. if ( isCompressed ) {
  13426. for ( let i = 0; i < 6; i ++ ) {
  13427. mipmaps = cubeImage[ i ].mipmaps;
  13428. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13429. const mipmap = mipmaps[ j ];
  13430. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13431. if ( glFormat !== null ) {
  13432. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13433. } else {
  13434. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  13435. }
  13436. } else {
  13437. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13438. }
  13439. }
  13440. }
  13441. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13442. } else {
  13443. mipmaps = texture.mipmaps;
  13444. for ( let i = 0; i < 6; i ++ ) {
  13445. if ( isDataTexture ) {
  13446. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13447. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13448. const mipmap = mipmaps[ j ];
  13449. const mipmapImage = mipmap.image[ i ].image;
  13450. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  13451. }
  13452. } else {
  13453. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  13454. for ( let j = 0; j < mipmaps.length; j ++ ) {
  13455. const mipmap = mipmaps[ j ];
  13456. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  13457. }
  13458. }
  13459. }
  13460. textureProperties.__maxMipLevel = mipmaps.length;
  13461. }
  13462. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13463. // We assume images for cube map have the same size.
  13464. generateMipmap( 34067, texture, image.width, image.height );
  13465. }
  13466. textureProperties.__version = texture.version;
  13467. if ( texture.onUpdate ) texture.onUpdate( texture );
  13468. } else {
  13469. state.activeTexture( 33984 + slot );
  13470. state.bindTexture( 34067, textureProperties.__webglTexture );
  13471. }
  13472. }
  13473. function setTextureCubeDynamic( texture, slot ) {
  13474. state.activeTexture( 33984 + slot );
  13475. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  13476. }
  13477. const wrappingToGL = {
  13478. [ RepeatWrapping ]: 10497,
  13479. [ ClampToEdgeWrapping ]: 33071,
  13480. [ MirroredRepeatWrapping ]: 33648
  13481. };
  13482. const filterToGL = {
  13483. [ NearestFilter ]: 9728,
  13484. [ NearestMipmapNearestFilter ]: 9984,
  13485. [ NearestMipmapLinearFilter ]: 9986,
  13486. [ LinearFilter ]: 9729,
  13487. [ LinearMipmapNearestFilter ]: 9985,
  13488. [ LinearMipmapLinearFilter ]: 9987
  13489. };
  13490. function setTextureParameters( textureType, texture, supportsMips ) {
  13491. if ( supportsMips ) {
  13492. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  13493. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  13494. if ( textureType === 32879 || textureType === 35866 ) {
  13495. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  13496. }
  13497. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  13498. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  13499. } else {
  13500. _gl.texParameteri( textureType, 10242, 33071 );
  13501. _gl.texParameteri( textureType, 10243, 33071 );
  13502. if ( textureType === 32879 || textureType === 35866 ) {
  13503. _gl.texParameteri( textureType, 32882, 33071 );
  13504. }
  13505. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  13506. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  13507. }
  13508. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  13509. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  13510. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  13511. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  13512. }
  13513. }
  13514. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13515. if ( extension ) {
  13516. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  13517. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  13518. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13519. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  13520. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13521. }
  13522. }
  13523. }
  13524. function initTexture( textureProperties, texture ) {
  13525. if ( textureProperties.__webglInit === undefined ) {
  13526. textureProperties.__webglInit = true;
  13527. texture.addEventListener( 'dispose', onTextureDispose );
  13528. textureProperties.__webglTexture = _gl.createTexture();
  13529. info.memory.textures ++;
  13530. }
  13531. }
  13532. function uploadTexture( textureProperties, texture, slot ) {
  13533. let textureType = 3553;
  13534. if ( texture.isDataTexture2DArray ) textureType = 35866;
  13535. if ( texture.isDataTexture3D ) textureType = 32879;
  13536. initTexture( textureProperties, texture );
  13537. state.activeTexture( 33984 + slot );
  13538. state.bindTexture( textureType, textureProperties.__webglTexture );
  13539. _gl.pixelStorei( 37440, texture.flipY );
  13540. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  13541. _gl.pixelStorei( 3317, texture.unpackAlignment );
  13542. const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  13543. const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  13544. const supportsMips = isPowerOfTwo( image ) || isWebGL2,
  13545. glFormat = utils.convert( texture.format );
  13546. let glType = utils.convert( texture.type ),
  13547. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  13548. setTextureParameters( textureType, texture, supportsMips );
  13549. let mipmap;
  13550. const mipmaps = texture.mipmaps;
  13551. if ( texture.isDepthTexture ) {
  13552. // populate depth texture with dummy data
  13553. glInternalFormat = 6402;
  13554. if ( isWebGL2 ) {
  13555. if ( texture.type === FloatType ) {
  13556. glInternalFormat = 36012;
  13557. } else if ( texture.type === UnsignedIntType ) {
  13558. glInternalFormat = 33190;
  13559. } else if ( texture.type === UnsignedInt248Type ) {
  13560. glInternalFormat = 35056;
  13561. } else {
  13562. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13563. }
  13564. } else {
  13565. if ( texture.type === FloatType ) {
  13566. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  13567. }
  13568. }
  13569. // validation checks for WebGL 1
  13570. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  13571. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13572. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13573. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13574. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  13575. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  13576. texture.type = UnsignedShortType;
  13577. glType = utils.convert( texture.type );
  13578. }
  13579. }
  13580. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  13581. // Depth stencil textures need the DEPTH_STENCIL internal format
  13582. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13583. glInternalFormat = 34041;
  13584. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13585. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13586. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13587. if ( texture.type !== UnsignedInt248Type ) {
  13588. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  13589. texture.type = UnsignedInt248Type;
  13590. glType = utils.convert( texture.type );
  13591. }
  13592. }
  13593. //
  13594. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  13595. } else if ( texture.isDataTexture ) {
  13596. // use manually created mipmaps if available
  13597. // if there are no manual mipmaps
  13598. // set 0 level mipmap and then use GL to generate other mipmap levels
  13599. if ( mipmaps.length > 0 && supportsMips ) {
  13600. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13601. mipmap = mipmaps[ i ];
  13602. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13603. }
  13604. texture.generateMipmaps = false;
  13605. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13606. } else {
  13607. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13608. textureProperties.__maxMipLevel = 0;
  13609. }
  13610. } else if ( texture.isCompressedTexture ) {
  13611. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13612. mipmap = mipmaps[ i ];
  13613. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  13614. if ( glFormat !== null ) {
  13615. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13616. } else {
  13617. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  13618. }
  13619. } else {
  13620. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13621. }
  13622. }
  13623. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13624. } else if ( texture.isDataTexture2DArray ) {
  13625. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13626. textureProperties.__maxMipLevel = 0;
  13627. } else if ( texture.isDataTexture3D ) {
  13628. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  13629. textureProperties.__maxMipLevel = 0;
  13630. } else {
  13631. // regular Texture (image, video, canvas)
  13632. // use manually created mipmaps if available
  13633. // if there are no manual mipmaps
  13634. // set 0 level mipmap and then use GL to generate other mipmap levels
  13635. if ( mipmaps.length > 0 && supportsMips ) {
  13636. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  13637. mipmap = mipmaps[ i ];
  13638. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  13639. }
  13640. texture.generateMipmaps = false;
  13641. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13642. } else {
  13643. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  13644. textureProperties.__maxMipLevel = 0;
  13645. }
  13646. }
  13647. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13648. generateMipmap( textureType, texture, image.width, image.height );
  13649. }
  13650. textureProperties.__version = texture.version;
  13651. if ( texture.onUpdate ) texture.onUpdate( texture );
  13652. }
  13653. // Render targets
  13654. // Setup storage for target texture and bind it to correct framebuffer
  13655. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  13656. const glFormat = utils.convert( renderTarget.texture.format );
  13657. const glType = utils.convert( renderTarget.texture.type );
  13658. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13659. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13660. _gl.bindFramebuffer( 36160, framebuffer );
  13661. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  13662. _gl.bindFramebuffer( 36160, null );
  13663. }
  13664. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13665. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  13666. _gl.bindRenderbuffer( 36161, renderbuffer );
  13667. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13668. let glInternalFormat = 33189;
  13669. if ( isMultisample ) {
  13670. const depthTexture = renderTarget.depthTexture;
  13671. if ( depthTexture && depthTexture.isDepthTexture ) {
  13672. if ( depthTexture.type === FloatType ) {
  13673. glInternalFormat = 36012;
  13674. } else if ( depthTexture.type === UnsignedIntType ) {
  13675. glInternalFormat = 33190;
  13676. }
  13677. }
  13678. const samples = getRenderTargetSamples( renderTarget );
  13679. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13680. } else {
  13681. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13682. }
  13683. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  13684. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13685. if ( isMultisample ) {
  13686. const samples = getRenderTargetSamples( renderTarget );
  13687. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  13688. } else {
  13689. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  13690. }
  13691. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  13692. } else {
  13693. const glFormat = utils.convert( renderTarget.texture.format );
  13694. const glType = utils.convert( renderTarget.texture.type );
  13695. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13696. if ( isMultisample ) {
  13697. const samples = getRenderTargetSamples( renderTarget );
  13698. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13699. } else {
  13700. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  13701. }
  13702. }
  13703. _gl.bindRenderbuffer( 36161, null );
  13704. }
  13705. // Setup resources for a Depth Texture for a FBO (needs an extension)
  13706. function setupDepthTexture( framebuffer, renderTarget ) {
  13707. const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  13708. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  13709. _gl.bindFramebuffer( 36160, framebuffer );
  13710. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  13711. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  13712. }
  13713. // upload an empty depth texture with framebuffer size
  13714. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  13715. renderTarget.depthTexture.image.width !== renderTarget.width ||
  13716. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13717. renderTarget.depthTexture.image.width = renderTarget.width;
  13718. renderTarget.depthTexture.image.height = renderTarget.height;
  13719. renderTarget.depthTexture.needsUpdate = true;
  13720. }
  13721. setTexture2D( renderTarget.depthTexture, 0 );
  13722. const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13723. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13724. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13725. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13726. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13727. } else {
  13728. throw new Error( 'Unknown depthTexture format' );
  13729. }
  13730. }
  13731. // Setup GL resources for a non-texture depth buffer
  13732. function setupDepthRenderbuffer( renderTarget ) {
  13733. const renderTargetProperties = properties.get( renderTarget );
  13734. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13735. if ( renderTarget.depthTexture ) {
  13736. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13737. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13738. } else {
  13739. if ( isCube ) {
  13740. renderTargetProperties.__webglDepthbuffer = [];
  13741. for ( let i = 0; i < 6; i ++ ) {
  13742. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13743. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13744. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  13745. }
  13746. } else {
  13747. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13748. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13749. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  13750. }
  13751. }
  13752. _gl.bindFramebuffer( 36160, null );
  13753. }
  13754. // Set up GL resources for the render target
  13755. function setupRenderTarget( renderTarget ) {
  13756. const renderTargetProperties = properties.get( renderTarget );
  13757. const textureProperties = properties.get( renderTarget.texture );
  13758. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13759. textureProperties.__webglTexture = _gl.createTexture();
  13760. info.memory.textures ++;
  13761. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  13762. const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13763. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13764. // Handles WebGL2 RGBFormat fallback - #18858
  13765. if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) {
  13766. renderTarget.texture.format = RGBAFormat;
  13767. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  13768. }
  13769. // Setup framebuffer
  13770. if ( isCube ) {
  13771. renderTargetProperties.__webglFramebuffer = [];
  13772. for ( let i = 0; i < 6; i ++ ) {
  13773. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13774. }
  13775. } else {
  13776. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13777. if ( isMultisample ) {
  13778. if ( isWebGL2 ) {
  13779. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13780. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13781. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13782. const glFormat = utils.convert( renderTarget.texture.format );
  13783. const glType = utils.convert( renderTarget.texture.type );
  13784. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  13785. const samples = getRenderTargetSamples( renderTarget );
  13786. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13787. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13788. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13789. _gl.bindRenderbuffer( 36161, null );
  13790. if ( renderTarget.depthBuffer ) {
  13791. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13792. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13793. }
  13794. _gl.bindFramebuffer( 36160, null );
  13795. } else {
  13796. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13797. }
  13798. }
  13799. }
  13800. // Setup color buffer
  13801. if ( isCube ) {
  13802. state.bindTexture( 34067, textureProperties.__webglTexture );
  13803. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13804. for ( let i = 0; i < 6; i ++ ) {
  13805. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13806. }
  13807. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13808. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13809. }
  13810. state.bindTexture( 34067, null );
  13811. } else {
  13812. state.bindTexture( 3553, textureProperties.__webglTexture );
  13813. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13814. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13815. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13816. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13817. }
  13818. state.bindTexture( 3553, null );
  13819. }
  13820. // Setup depth and stencil buffers
  13821. if ( renderTarget.depthBuffer ) {
  13822. setupDepthRenderbuffer( renderTarget );
  13823. }
  13824. }
  13825. function updateRenderTargetMipmap( renderTarget ) {
  13826. const texture = renderTarget.texture;
  13827. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  13828. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13829. const target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13830. const webglTexture = properties.get( texture ).__webglTexture;
  13831. state.bindTexture( target, webglTexture );
  13832. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13833. state.bindTexture( target, null );
  13834. }
  13835. }
  13836. function updateMultisampleRenderTarget( renderTarget ) {
  13837. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13838. if ( isWebGL2 ) {
  13839. const renderTargetProperties = properties.get( renderTarget );
  13840. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13841. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13842. const width = renderTarget.width;
  13843. const height = renderTarget.height;
  13844. let mask = 16384;
  13845. if ( renderTarget.depthBuffer ) mask |= 256;
  13846. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13847. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13848. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  13849. } else {
  13850. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13851. }
  13852. }
  13853. }
  13854. function getRenderTargetSamples( renderTarget ) {
  13855. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13856. Math.min( maxSamples, renderTarget.samples ) : 0;
  13857. }
  13858. function updateVideoTexture( texture ) {
  13859. const frame = info.render.frame;
  13860. // Check the last frame we updated the VideoTexture
  13861. if ( _videoTextures.get( texture ) !== frame ) {
  13862. _videoTextures.set( texture, frame );
  13863. texture.update();
  13864. }
  13865. }
  13866. // backwards compatibility
  13867. let warnedTexture2D = false;
  13868. let warnedTextureCube = false;
  13869. function safeSetTexture2D( texture, slot ) {
  13870. if ( texture && texture.isWebGLRenderTarget ) {
  13871. if ( warnedTexture2D === false ) {
  13872. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13873. warnedTexture2D = true;
  13874. }
  13875. texture = texture.texture;
  13876. }
  13877. setTexture2D( texture, slot );
  13878. }
  13879. function safeSetTextureCube( texture, slot ) {
  13880. if ( texture && texture.isWebGLCubeRenderTarget ) {
  13881. if ( warnedTextureCube === false ) {
  13882. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13883. warnedTextureCube = true;
  13884. }
  13885. texture = texture.texture;
  13886. }
  13887. // currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture
  13888. // TODO: unify these code paths
  13889. if ( ( texture && texture.isCubeTexture ) ||
  13890. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13891. // CompressedTexture can have Array in image :/
  13892. // this function alone should take care of cube textures
  13893. setTextureCube( texture, slot );
  13894. } else {
  13895. // assumed: texture property of THREE.WebGLCubeRenderTarget
  13896. setTextureCubeDynamic( texture, slot );
  13897. }
  13898. }
  13899. //
  13900. this.allocateTextureUnit = allocateTextureUnit;
  13901. this.resetTextureUnits = resetTextureUnits;
  13902. this.setTexture2D = setTexture2D;
  13903. this.setTexture2DArray = setTexture2DArray;
  13904. this.setTexture3D = setTexture3D;
  13905. this.setTextureCube = setTextureCube;
  13906. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13907. this.setupRenderTarget = setupRenderTarget;
  13908. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13909. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13910. this.safeSetTexture2D = safeSetTexture2D;
  13911. this.safeSetTextureCube = safeSetTextureCube;
  13912. }
  13913. /**
  13914. * @author thespite / http://www.twitter.com/thespite
  13915. */
  13916. function WebGLUtils( gl, extensions, capabilities ) {
  13917. const isWebGL2 = capabilities.isWebGL2;
  13918. function convert( p ) {
  13919. let extension;
  13920. if ( p === UnsignedByteType ) return 5121;
  13921. if ( p === UnsignedShort4444Type ) return 32819;
  13922. if ( p === UnsignedShort5551Type ) return 32820;
  13923. if ( p === UnsignedShort565Type ) return 33635;
  13924. if ( p === ByteType ) return 5120;
  13925. if ( p === ShortType ) return 5122;
  13926. if ( p === UnsignedShortType ) return 5123;
  13927. if ( p === IntType ) return 5124;
  13928. if ( p === UnsignedIntType ) return 5125;
  13929. if ( p === FloatType ) return 5126;
  13930. if ( p === HalfFloatType ) {
  13931. if ( isWebGL2 ) return 5131;
  13932. extension = extensions.get( 'OES_texture_half_float' );
  13933. if ( extension !== null ) {
  13934. return extension.HALF_FLOAT_OES;
  13935. } else {
  13936. return null;
  13937. }
  13938. }
  13939. if ( p === AlphaFormat ) return 6406;
  13940. if ( p === RGBFormat ) return 6407;
  13941. if ( p === RGBAFormat ) return 6408;
  13942. if ( p === LuminanceFormat ) return 6409;
  13943. if ( p === LuminanceAlphaFormat ) return 6410;
  13944. if ( p === DepthFormat ) return 6402;
  13945. if ( p === DepthStencilFormat ) return 34041;
  13946. if ( p === RedFormat ) return 6403;
  13947. // WebGL2 formats.
  13948. if ( p === RedIntegerFormat ) return 36244;
  13949. if ( p === RGFormat ) return 33319;
  13950. if ( p === RGIntegerFormat ) return 33320;
  13951. if ( p === RGBIntegerFormat ) return 36248;
  13952. if ( p === RGBAIntegerFormat ) return 36249;
  13953. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13954. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13955. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13956. if ( extension !== null ) {
  13957. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13958. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13959. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13960. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13961. } else {
  13962. return null;
  13963. }
  13964. }
  13965. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13966. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13967. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13968. if ( extension !== null ) {
  13969. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13970. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13971. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13972. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13973. } else {
  13974. return null;
  13975. }
  13976. }
  13977. if ( p === RGB_ETC1_Format ) {
  13978. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13979. if ( extension !== null ) {
  13980. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13981. } else {
  13982. return null;
  13983. }
  13984. }
  13985. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  13986. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  13987. if ( extension !== null ) {
  13988. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  13989. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13990. }
  13991. }
  13992. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13993. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13994. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13995. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13996. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  13997. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  13998. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  13999. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  14000. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  14001. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  14002. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  14003. if ( extension !== null ) {
  14004. // TODO Complete?
  14005. return p;
  14006. } else {
  14007. return null;
  14008. }
  14009. }
  14010. if ( p === RGBA_BPTC_Format ) {
  14011. extension = extensions.get( 'EXT_texture_compression_bptc' );
  14012. if ( extension !== null ) {
  14013. // TODO Complete?
  14014. return p;
  14015. } else {
  14016. return null;
  14017. }
  14018. }
  14019. if ( p === UnsignedInt248Type ) {
  14020. if ( isWebGL2 ) return 34042;
  14021. extension = extensions.get( 'WEBGL_depth_texture' );
  14022. if ( extension !== null ) {
  14023. return extension.UNSIGNED_INT_24_8_WEBGL;
  14024. } else {
  14025. return null;
  14026. }
  14027. }
  14028. }
  14029. return { convert: convert };
  14030. }
  14031. /**
  14032. * @author mrdoob / http://mrdoob.com/
  14033. */
  14034. function ArrayCamera( array ) {
  14035. PerspectiveCamera.call( this );
  14036. this.cameras = array || [];
  14037. }
  14038. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  14039. constructor: ArrayCamera,
  14040. isArrayCamera: true
  14041. } );
  14042. /**
  14043. * @author mrdoob / http://mrdoob.com/
  14044. */
  14045. function Group() {
  14046. Object3D.call( this );
  14047. this.type = 'Group';
  14048. }
  14049. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14050. constructor: Group,
  14051. isGroup: true
  14052. } );
  14053. /**
  14054. * @author Mugen87 / https://github.com/Mugen87
  14055. */
  14056. function WebXRController() {
  14057. this._targetRay = null;
  14058. this._grip = null;
  14059. }
  14060. Object.assign( WebXRController.prototype, {
  14061. constructor: WebXRController,
  14062. getTargetRaySpace: function () {
  14063. if ( this._targetRay === null ) {
  14064. this._targetRay = new Group();
  14065. this._targetRay.matrixAutoUpdate = false;
  14066. this._targetRay.visible = false;
  14067. }
  14068. return this._targetRay;
  14069. },
  14070. getGripSpace: function () {
  14071. if ( this._grip === null ) {
  14072. this._grip = new Group();
  14073. this._grip.matrixAutoUpdate = false;
  14074. this._grip.visible = false;
  14075. }
  14076. return this._grip;
  14077. },
  14078. dispatchEvent: function ( event ) {
  14079. if ( this._targetRay !== null ) {
  14080. this._targetRay.dispatchEvent( event );
  14081. }
  14082. if ( this._grip !== null ) {
  14083. this._grip.dispatchEvent( event );
  14084. }
  14085. return this;
  14086. },
  14087. disconnect: function ( inputSource ) {
  14088. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14089. if ( this._targetRay !== null ) {
  14090. this._targetRay.visible = false;
  14091. }
  14092. if ( this._grip !== null ) {
  14093. this._grip.visible = false;
  14094. }
  14095. return this;
  14096. },
  14097. update: function ( inputSource, frame, referenceSpace ) {
  14098. let inputPose = null;
  14099. let gripPose = null;
  14100. const targetRay = this._targetRay;
  14101. const grip = this._grip;
  14102. if ( inputSource ) {
  14103. if ( targetRay !== null ) {
  14104. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  14105. if ( inputPose !== null ) {
  14106. targetRay.matrix.fromArray( inputPose.transform.matrix );
  14107. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  14108. }
  14109. }
  14110. if ( grip !== null && inputSource.gripSpace ) {
  14111. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  14112. if ( gripPose !== null ) {
  14113. grip.matrix.fromArray( gripPose.transform.matrix );
  14114. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  14115. }
  14116. }
  14117. }
  14118. if ( targetRay !== null ) {
  14119. targetRay.visible = ( inputPose !== null );
  14120. }
  14121. if ( grip !== null ) {
  14122. grip.visible = ( gripPose !== null );
  14123. }
  14124. return this;
  14125. }
  14126. } );
  14127. /**
  14128. * @author mrdoob / http://mrdoob.com/
  14129. */
  14130. function WebXRManager( renderer, gl ) {
  14131. const scope = this;
  14132. let session = null;
  14133. let framebufferScaleFactor = 1.0;
  14134. let referenceSpace = null;
  14135. let referenceSpaceType = 'local-floor';
  14136. let pose = null;
  14137. const controllers = [];
  14138. const inputSourcesMap = new Map();
  14139. //
  14140. const cameraL = new PerspectiveCamera();
  14141. cameraL.layers.enable( 1 );
  14142. cameraL.viewport = new Vector4();
  14143. const cameraR = new PerspectiveCamera();
  14144. cameraR.layers.enable( 2 );
  14145. cameraR.viewport = new Vector4();
  14146. const cameras = [ cameraL, cameraR ];
  14147. const cameraVR = new ArrayCamera();
  14148. cameraVR.layers.enable( 1 );
  14149. cameraVR.layers.enable( 2 );
  14150. let _currentDepthNear = null;
  14151. let _currentDepthFar = null;
  14152. //
  14153. this.enabled = false;
  14154. this.isPresenting = false;
  14155. this.getController = function ( index ) {
  14156. let controller = controllers[ index ];
  14157. if ( controller === undefined ) {
  14158. controller = new WebXRController();
  14159. controllers[ index ] = controller;
  14160. }
  14161. return controller.getTargetRaySpace();
  14162. };
  14163. this.getControllerGrip = function ( index ) {
  14164. let controller = controllers[ index ];
  14165. if ( controller === undefined ) {
  14166. controller = new WebXRController();
  14167. controllers[ index ] = controller;
  14168. }
  14169. return controller.getGripSpace();
  14170. };
  14171. //
  14172. function onSessionEvent( event ) {
  14173. const controller = inputSourcesMap.get( event.inputSource );
  14174. if ( controller ) {
  14175. controller.dispatchEvent( { type: event.type } );
  14176. }
  14177. }
  14178. function onSessionEnd() {
  14179. inputSourcesMap.forEach( function ( controller, inputSource ) {
  14180. controller.disconnect( inputSource );
  14181. } );
  14182. inputSourcesMap.clear();
  14183. //
  14184. renderer.setFramebuffer( null );
  14185. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  14186. animation.stop();
  14187. scope.isPresenting = false;
  14188. scope.dispatchEvent( { type: 'sessionend' } );
  14189. }
  14190. function onRequestReferenceSpace( value ) {
  14191. referenceSpace = value;
  14192. animation.setContext( session );
  14193. animation.start();
  14194. scope.isPresenting = true;
  14195. scope.dispatchEvent( { type: 'sessionstart' } );
  14196. }
  14197. this.setFramebufferScaleFactor = function ( value ) {
  14198. framebufferScaleFactor = value;
  14199. if ( scope.isPresenting === true ) {
  14200. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  14201. }
  14202. };
  14203. this.setReferenceSpaceType = function ( value ) {
  14204. referenceSpaceType = value;
  14205. if ( scope.isPresenting === true ) {
  14206. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  14207. }
  14208. };
  14209. this.getReferenceSpace = function () {
  14210. return referenceSpace;
  14211. };
  14212. this.getSession = function () {
  14213. return session;
  14214. };
  14215. this.setSession = function ( value ) {
  14216. session = value;
  14217. if ( session !== null ) {
  14218. session.addEventListener( 'select', onSessionEvent );
  14219. session.addEventListener( 'selectstart', onSessionEvent );
  14220. session.addEventListener( 'selectend', onSessionEvent );
  14221. session.addEventListener( 'squeeze', onSessionEvent );
  14222. session.addEventListener( 'squeezestart', onSessionEvent );
  14223. session.addEventListener( 'squeezeend', onSessionEvent );
  14224. session.addEventListener( 'end', onSessionEnd );
  14225. const attributes = gl.getContextAttributes();
  14226. if ( attributes.xrCompatible !== true ) {
  14227. gl.makeXRCompatible();
  14228. }
  14229. const layerInit = {
  14230. antialias: attributes.antialias,
  14231. alpha: attributes.alpha,
  14232. depth: attributes.depth,
  14233. stencil: attributes.stencil,
  14234. framebufferScaleFactor: framebufferScaleFactor
  14235. };
  14236. // eslint-disable-next-line no-undef
  14237. const baseLayer = new XRWebGLLayer( session, gl, layerInit );
  14238. session.updateRenderState( { baseLayer: baseLayer } );
  14239. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  14240. //
  14241. session.addEventListener( 'inputsourceschange', updateInputSources );
  14242. }
  14243. };
  14244. function updateInputSources( event ) {
  14245. const inputSources = session.inputSources;
  14246. // Assign inputSources to available controllers
  14247. for ( let i = 0; i < controllers.length; i ++ ) {
  14248. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  14249. }
  14250. // Notify disconnected
  14251. for ( let i = 0; i < event.removed.length; i ++ ) {
  14252. const inputSource = event.removed[ i ];
  14253. const controller = inputSourcesMap.get( inputSource );
  14254. if ( controller ) {
  14255. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  14256. inputSourcesMap.delete( inputSource );
  14257. }
  14258. }
  14259. // Notify connected
  14260. for ( let i = 0; i < event.added.length; i ++ ) {
  14261. const inputSource = event.added[ i ];
  14262. const controller = inputSourcesMap.get( inputSource );
  14263. if ( controller ) {
  14264. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  14265. }
  14266. }
  14267. }
  14268. //
  14269. const cameraLPos = new Vector3();
  14270. const cameraRPos = new Vector3();
  14271. /**
  14272. * @author jsantell / https://www.jsantell.com/
  14273. *
  14274. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14275. * the cameras' projection and world matrices have already been set.
  14276. * And that near and far planes are identical for both cameras.
  14277. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14278. */
  14279. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  14280. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  14281. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  14282. const ipd = cameraLPos.distanceTo( cameraRPos );
  14283. const projL = cameraL.projectionMatrix.elements;
  14284. const projR = cameraR.projectionMatrix.elements;
  14285. // VR systems will have identical far and near planes, and
  14286. // most likely identical top and bottom frustum extents.
  14287. // Use the left camera for these values.
  14288. const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  14289. const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  14290. const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  14291. const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  14292. const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  14293. const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  14294. const left = near * leftFov;
  14295. const right = near * rightFov;
  14296. // Calculate the new camera's position offset from the
  14297. // left camera. xOffset should be roughly half `ipd`.
  14298. const zOffset = ipd / ( - leftFov + rightFov );
  14299. const xOffset = zOffset * - leftFov;
  14300. // TODO: Better way to apply this offset?
  14301. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  14302. camera.translateX( xOffset );
  14303. camera.translateZ( zOffset );
  14304. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  14305. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14306. // Find the union of the frustum values of the cameras and scale
  14307. // the values so that the near plane's position does not change in world space,
  14308. // although must now be relative to the new union camera.
  14309. const near2 = near + zOffset;
  14310. const far2 = far + zOffset;
  14311. const left2 = left - xOffset;
  14312. const right2 = right + ( ipd - xOffset );
  14313. const top2 = topFov * far / far2 * near2;
  14314. const bottom2 = bottomFov * far / far2 * near2;
  14315. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  14316. }
  14317. function updateCamera( camera, parent ) {
  14318. if ( parent === null ) {
  14319. camera.matrixWorld.copy( camera.matrix );
  14320. } else {
  14321. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  14322. }
  14323. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  14324. }
  14325. this.getCamera = function ( camera ) {
  14326. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14327. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14328. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  14329. // Note that the new renderState won't apply until the next frame. See #18320
  14330. session.updateRenderState( {
  14331. depthNear: cameraVR.near,
  14332. depthFar: cameraVR.far
  14333. } );
  14334. _currentDepthNear = cameraVR.near;
  14335. _currentDepthFar = cameraVR.far;
  14336. }
  14337. const parent = camera.parent;
  14338. const cameras = cameraVR.cameras;
  14339. updateCamera( cameraVR, parent );
  14340. for ( let i = 0; i < cameras.length; i ++ ) {
  14341. updateCamera( cameras[ i ], parent );
  14342. }
  14343. // update camera and its children
  14344. camera.matrixWorld.copy( cameraVR.matrixWorld );
  14345. const children = camera.children;
  14346. for ( let i = 0, l = children.length; i < l; i ++ ) {
  14347. children[ i ].updateMatrixWorld( true );
  14348. }
  14349. // update projection matrix for proper view frustum culling
  14350. if ( cameras.length === 2 ) {
  14351. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  14352. } else {
  14353. // assume single camera setup (AR)
  14354. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  14355. }
  14356. return cameraVR;
  14357. };
  14358. // Animation Loop
  14359. let onAnimationFrameCallback = null;
  14360. function onAnimationFrame( time, frame ) {
  14361. pose = frame.getViewerPose( referenceSpace );
  14362. if ( pose !== null ) {
  14363. const views = pose.views;
  14364. const baseLayer = session.renderState.baseLayer;
  14365. renderer.setFramebuffer( baseLayer.framebuffer );
  14366. let cameraVRNeedsUpdate = false;
  14367. // check if it's necessary to rebuild cameraVR's camera list
  14368. if ( views.length !== cameraVR.cameras.length ) {
  14369. cameraVR.cameras.length = 0;
  14370. cameraVRNeedsUpdate = true;
  14371. }
  14372. for ( let i = 0; i < views.length; i ++ ) {
  14373. const view = views[ i ];
  14374. const viewport = baseLayer.getViewport( view );
  14375. const camera = cameras[ i ];
  14376. camera.matrix.fromArray( view.transform.matrix );
  14377. camera.projectionMatrix.fromArray( view.projectionMatrix );
  14378. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  14379. if ( i === 0 ) {
  14380. cameraVR.matrix.copy( camera.matrix );
  14381. }
  14382. if ( cameraVRNeedsUpdate === true ) {
  14383. cameraVR.cameras.push( camera );
  14384. }
  14385. }
  14386. }
  14387. //
  14388. const inputSources = session.inputSources;
  14389. for ( let i = 0; i < controllers.length; i ++ ) {
  14390. const controller = controllers[ i ];
  14391. const inputSource = inputSources[ i ];
  14392. controller.update( inputSource, frame, referenceSpace );
  14393. }
  14394. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  14395. }
  14396. const animation = new WebGLAnimation();
  14397. animation.setAnimationLoop( onAnimationFrame );
  14398. this.setAnimationLoop = function ( callback ) {
  14399. onAnimationFrameCallback = callback;
  14400. };
  14401. this.dispose = function () {};
  14402. }
  14403. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  14404. /**
  14405. * @author mrdoob / http://mrdoob.com/
  14406. */
  14407. function WebGLMaterials( properties ) {
  14408. function refreshFogUniforms( uniforms, fog ) {
  14409. uniforms.fogColor.value.copy( fog.color );
  14410. if ( fog.isFog ) {
  14411. uniforms.fogNear.value = fog.near;
  14412. uniforms.fogFar.value = fog.far;
  14413. } else if ( fog.isFogExp2 ) {
  14414. uniforms.fogDensity.value = fog.density;
  14415. }
  14416. }
  14417. function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) {
  14418. if ( material.isMeshBasicMaterial ) {
  14419. refreshUniformsCommon( uniforms, material );
  14420. } else if ( material.isMeshLambertMaterial ) {
  14421. refreshUniformsCommon( uniforms, material );
  14422. refreshUniformsLambert( uniforms, material );
  14423. } else if ( material.isMeshToonMaterial ) {
  14424. refreshUniformsCommon( uniforms, material );
  14425. refreshUniformsToon( uniforms, material );
  14426. } else if ( material.isMeshPhongMaterial ) {
  14427. refreshUniformsCommon( uniforms, material );
  14428. refreshUniformsPhong( uniforms, material );
  14429. } else if ( material.isMeshStandardMaterial ) {
  14430. refreshUniformsCommon( uniforms, material, environment );
  14431. if ( material.isMeshPhysicalMaterial ) {
  14432. refreshUniformsPhysical( uniforms, material, environment );
  14433. } else {
  14434. refreshUniformsStandard( uniforms, material, environment );
  14435. }
  14436. } else if ( material.isMeshMatcapMaterial ) {
  14437. refreshUniformsCommon( uniforms, material );
  14438. refreshUniformsMatcap( uniforms, material );
  14439. } else if ( material.isMeshDepthMaterial ) {
  14440. refreshUniformsCommon( uniforms, material );
  14441. refreshUniformsDepth( uniforms, material );
  14442. } else if ( material.isMeshDistanceMaterial ) {
  14443. refreshUniformsCommon( uniforms, material );
  14444. refreshUniformsDistance( uniforms, material );
  14445. } else if ( material.isMeshNormalMaterial ) {
  14446. refreshUniformsCommon( uniforms, material );
  14447. refreshUniformsNormal( uniforms, material );
  14448. } else if ( material.isLineBasicMaterial ) {
  14449. refreshUniformsLine( uniforms, material );
  14450. if ( material.isLineDashedMaterial ) {
  14451. refreshUniformsDash( uniforms, material );
  14452. }
  14453. } else if ( material.isPointsMaterial ) {
  14454. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  14455. } else if ( material.isSpriteMaterial ) {
  14456. refreshUniformsSprites( uniforms, material );
  14457. } else if ( material.isShadowMaterial ) {
  14458. uniforms.color.value.copy( material.color );
  14459. uniforms.opacity.value = material.opacity;
  14460. } else if ( material.isShaderMaterial ) {
  14461. material.uniformsNeedUpdate = false; // #15581
  14462. }
  14463. }
  14464. function refreshUniformsCommon( uniforms, material, environment ) {
  14465. uniforms.opacity.value = material.opacity;
  14466. if ( material.color ) {
  14467. uniforms.diffuse.value.copy( material.color );
  14468. }
  14469. if ( material.emissive ) {
  14470. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14471. }
  14472. if ( material.map ) {
  14473. uniforms.map.value = material.map;
  14474. }
  14475. if ( material.alphaMap ) {
  14476. uniforms.alphaMap.value = material.alphaMap;
  14477. }
  14478. if ( material.specularMap ) {
  14479. uniforms.specularMap.value = material.specularMap;
  14480. }
  14481. const envMap = material.envMap || environment;
  14482. if ( envMap ) {
  14483. uniforms.envMap.value = envMap;
  14484. uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1;
  14485. uniforms.reflectivity.value = material.reflectivity;
  14486. uniforms.refractionRatio.value = material.refractionRatio;
  14487. uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel;
  14488. }
  14489. if ( material.lightMap ) {
  14490. uniforms.lightMap.value = material.lightMap;
  14491. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14492. }
  14493. if ( material.aoMap ) {
  14494. uniforms.aoMap.value = material.aoMap;
  14495. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14496. }
  14497. // uv repeat and offset setting priorities
  14498. // 1. color map
  14499. // 2. specular map
  14500. // 3. normal map
  14501. // 4. bump map
  14502. // 5. alpha map
  14503. // 6. emissive map
  14504. let uvScaleMap;
  14505. if ( material.map ) {
  14506. uvScaleMap = material.map;
  14507. } else if ( material.specularMap ) {
  14508. uvScaleMap = material.specularMap;
  14509. } else if ( material.displacementMap ) {
  14510. uvScaleMap = material.displacementMap;
  14511. } else if ( material.normalMap ) {
  14512. uvScaleMap = material.normalMap;
  14513. } else if ( material.bumpMap ) {
  14514. uvScaleMap = material.bumpMap;
  14515. } else if ( material.roughnessMap ) {
  14516. uvScaleMap = material.roughnessMap;
  14517. } else if ( material.metalnessMap ) {
  14518. uvScaleMap = material.metalnessMap;
  14519. } else if ( material.alphaMap ) {
  14520. uvScaleMap = material.alphaMap;
  14521. } else if ( material.emissiveMap ) {
  14522. uvScaleMap = material.emissiveMap;
  14523. }
  14524. if ( uvScaleMap !== undefined ) {
  14525. // backwards compatibility
  14526. if ( uvScaleMap.isWebGLRenderTarget ) {
  14527. uvScaleMap = uvScaleMap.texture;
  14528. }
  14529. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14530. uvScaleMap.updateMatrix();
  14531. }
  14532. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14533. }
  14534. // uv repeat and offset setting priorities for uv2
  14535. // 1. ao map
  14536. // 2. light map
  14537. let uv2ScaleMap;
  14538. if ( material.aoMap ) {
  14539. uv2ScaleMap = material.aoMap;
  14540. } else if ( material.lightMap ) {
  14541. uv2ScaleMap = material.lightMap;
  14542. }
  14543. if ( uv2ScaleMap !== undefined ) {
  14544. // backwards compatibility
  14545. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  14546. uv2ScaleMap = uv2ScaleMap.texture;
  14547. }
  14548. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  14549. uv2ScaleMap.updateMatrix();
  14550. }
  14551. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  14552. }
  14553. }
  14554. function refreshUniformsLine( uniforms, material ) {
  14555. uniforms.diffuse.value.copy( material.color );
  14556. uniforms.opacity.value = material.opacity;
  14557. }
  14558. function refreshUniformsDash( uniforms, material ) {
  14559. uniforms.dashSize.value = material.dashSize;
  14560. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14561. uniforms.scale.value = material.scale;
  14562. }
  14563. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  14564. uniforms.diffuse.value.copy( material.color );
  14565. uniforms.opacity.value = material.opacity;
  14566. uniforms.size.value = material.size * pixelRatio;
  14567. uniforms.scale.value = height * 0.5;
  14568. if ( material.map ) {
  14569. uniforms.map.value = material.map;
  14570. }
  14571. if ( material.alphaMap ) {
  14572. uniforms.alphaMap.value = material.alphaMap;
  14573. }
  14574. // uv repeat and offset setting priorities
  14575. // 1. color map
  14576. // 2. alpha map
  14577. let uvScaleMap;
  14578. if ( material.map ) {
  14579. uvScaleMap = material.map;
  14580. } else if ( material.alphaMap ) {
  14581. uvScaleMap = material.alphaMap;
  14582. }
  14583. if ( uvScaleMap !== undefined ) {
  14584. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14585. uvScaleMap.updateMatrix();
  14586. }
  14587. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14588. }
  14589. }
  14590. function refreshUniformsSprites( uniforms, material ) {
  14591. uniforms.diffuse.value.copy( material.color );
  14592. uniforms.opacity.value = material.opacity;
  14593. uniforms.rotation.value = material.rotation;
  14594. if ( material.map ) {
  14595. uniforms.map.value = material.map;
  14596. }
  14597. if ( material.alphaMap ) {
  14598. uniforms.alphaMap.value = material.alphaMap;
  14599. }
  14600. // uv repeat and offset setting priorities
  14601. // 1. color map
  14602. // 2. alpha map
  14603. let uvScaleMap;
  14604. if ( material.map ) {
  14605. uvScaleMap = material.map;
  14606. } else if ( material.alphaMap ) {
  14607. uvScaleMap = material.alphaMap;
  14608. }
  14609. if ( uvScaleMap !== undefined ) {
  14610. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14611. uvScaleMap.updateMatrix();
  14612. }
  14613. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14614. }
  14615. }
  14616. function refreshUniformsLambert( uniforms, material ) {
  14617. if ( material.emissiveMap ) {
  14618. uniforms.emissiveMap.value = material.emissiveMap;
  14619. }
  14620. }
  14621. function refreshUniformsPhong( uniforms, material ) {
  14622. uniforms.specular.value.copy( material.specular );
  14623. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14624. if ( material.emissiveMap ) {
  14625. uniforms.emissiveMap.value = material.emissiveMap;
  14626. }
  14627. if ( material.bumpMap ) {
  14628. uniforms.bumpMap.value = material.bumpMap;
  14629. uniforms.bumpScale.value = material.bumpScale;
  14630. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14631. }
  14632. if ( material.normalMap ) {
  14633. uniforms.normalMap.value = material.normalMap;
  14634. uniforms.normalScale.value.copy( material.normalScale );
  14635. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14636. }
  14637. if ( material.displacementMap ) {
  14638. uniforms.displacementMap.value = material.displacementMap;
  14639. uniforms.displacementScale.value = material.displacementScale;
  14640. uniforms.displacementBias.value = material.displacementBias;
  14641. }
  14642. }
  14643. function refreshUniformsToon( uniforms, material ) {
  14644. if ( material.gradientMap ) {
  14645. uniforms.gradientMap.value = material.gradientMap;
  14646. }
  14647. if ( material.emissiveMap ) {
  14648. uniforms.emissiveMap.value = material.emissiveMap;
  14649. }
  14650. if ( material.bumpMap ) {
  14651. uniforms.bumpMap.value = material.bumpMap;
  14652. uniforms.bumpScale.value = material.bumpScale;
  14653. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14654. }
  14655. if ( material.normalMap ) {
  14656. uniforms.normalMap.value = material.normalMap;
  14657. uniforms.normalScale.value.copy( material.normalScale );
  14658. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14659. }
  14660. if ( material.displacementMap ) {
  14661. uniforms.displacementMap.value = material.displacementMap;
  14662. uniforms.displacementScale.value = material.displacementScale;
  14663. uniforms.displacementBias.value = material.displacementBias;
  14664. }
  14665. }
  14666. function refreshUniformsStandard( uniforms, material, environment ) {
  14667. uniforms.roughness.value = material.roughness;
  14668. uniforms.metalness.value = material.metalness;
  14669. if ( material.roughnessMap ) {
  14670. uniforms.roughnessMap.value = material.roughnessMap;
  14671. }
  14672. if ( material.metalnessMap ) {
  14673. uniforms.metalnessMap.value = material.metalnessMap;
  14674. }
  14675. if ( material.emissiveMap ) {
  14676. uniforms.emissiveMap.value = material.emissiveMap;
  14677. }
  14678. if ( material.bumpMap ) {
  14679. uniforms.bumpMap.value = material.bumpMap;
  14680. uniforms.bumpScale.value = material.bumpScale;
  14681. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14682. }
  14683. if ( material.normalMap ) {
  14684. uniforms.normalMap.value = material.normalMap;
  14685. uniforms.normalScale.value.copy( material.normalScale );
  14686. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14687. }
  14688. if ( material.displacementMap ) {
  14689. uniforms.displacementMap.value = material.displacementMap;
  14690. uniforms.displacementScale.value = material.displacementScale;
  14691. uniforms.displacementBias.value = material.displacementBias;
  14692. }
  14693. if ( material.envMap || environment ) {
  14694. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14695. uniforms.envMapIntensity.value = material.envMapIntensity;
  14696. }
  14697. }
  14698. function refreshUniformsPhysical( uniforms, material, environment ) {
  14699. refreshUniformsStandard( uniforms, material, environment );
  14700. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14701. uniforms.clearcoat.value = material.clearcoat;
  14702. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14703. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  14704. if ( material.clearcoatMap ) {
  14705. uniforms.clearcoatMap.value = material.clearcoatMap;
  14706. }
  14707. if ( material.clearcoatRoughnessMap ) {
  14708. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14709. }
  14710. if ( material.clearcoatNormalMap ) {
  14711. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  14712. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14713. if ( material.side === BackSide ) {
  14714. uniforms.clearcoatNormalScale.value.negate();
  14715. }
  14716. }
  14717. uniforms.transparency.value = material.transparency;
  14718. }
  14719. function refreshUniformsMatcap( uniforms, material ) {
  14720. if ( material.matcap ) {
  14721. uniforms.matcap.value = material.matcap;
  14722. }
  14723. if ( material.bumpMap ) {
  14724. uniforms.bumpMap.value = material.bumpMap;
  14725. uniforms.bumpScale.value = material.bumpScale;
  14726. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14727. }
  14728. if ( material.normalMap ) {
  14729. uniforms.normalMap.value = material.normalMap;
  14730. uniforms.normalScale.value.copy( material.normalScale );
  14731. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14732. }
  14733. if ( material.displacementMap ) {
  14734. uniforms.displacementMap.value = material.displacementMap;
  14735. uniforms.displacementScale.value = material.displacementScale;
  14736. uniforms.displacementBias.value = material.displacementBias;
  14737. }
  14738. }
  14739. function refreshUniformsDepth( uniforms, material ) {
  14740. if ( material.displacementMap ) {
  14741. uniforms.displacementMap.value = material.displacementMap;
  14742. uniforms.displacementScale.value = material.displacementScale;
  14743. uniforms.displacementBias.value = material.displacementBias;
  14744. }
  14745. }
  14746. function refreshUniformsDistance( uniforms, material ) {
  14747. if ( material.displacementMap ) {
  14748. uniforms.displacementMap.value = material.displacementMap;
  14749. uniforms.displacementScale.value = material.displacementScale;
  14750. uniforms.displacementBias.value = material.displacementBias;
  14751. }
  14752. uniforms.referencePosition.value.copy( material.referencePosition );
  14753. uniforms.nearDistance.value = material.nearDistance;
  14754. uniforms.farDistance.value = material.farDistance;
  14755. }
  14756. function refreshUniformsNormal( uniforms, material ) {
  14757. if ( material.bumpMap ) {
  14758. uniforms.bumpMap.value = material.bumpMap;
  14759. uniforms.bumpScale.value = material.bumpScale;
  14760. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14761. }
  14762. if ( material.normalMap ) {
  14763. uniforms.normalMap.value = material.normalMap;
  14764. uniforms.normalScale.value.copy( material.normalScale );
  14765. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14766. }
  14767. if ( material.displacementMap ) {
  14768. uniforms.displacementMap.value = material.displacementMap;
  14769. uniforms.displacementScale.value = material.displacementScale;
  14770. uniforms.displacementBias.value = material.displacementBias;
  14771. }
  14772. }
  14773. return {
  14774. refreshFogUniforms: refreshFogUniforms,
  14775. refreshMaterialUniforms: refreshMaterialUniforms
  14776. };
  14777. }
  14778. /**
  14779. * @author supereggbert / http://www.paulbrunt.co.uk/
  14780. * @author mrdoob / http://mrdoob.com/
  14781. * @author alteredq / http://alteredqualia.com/
  14782. * @author szimek / https://github.com/szimek/
  14783. * @author tschw
  14784. */
  14785. function WebGLRenderer( parameters ) {
  14786. parameters = parameters || {};
  14787. const _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14788. _context = parameters.context !== undefined ? parameters.context : null,
  14789. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14790. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14791. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14792. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14793. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14794. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14795. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14796. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14797. let currentRenderList = null;
  14798. let currentRenderState = null;
  14799. // public properties
  14800. this.domElement = _canvas;
  14801. // Debug configuration container
  14802. this.debug = {
  14803. /**
  14804. * Enables error checking and reporting when shader programs are being compiled
  14805. * @type {boolean}
  14806. */
  14807. checkShaderErrors: true
  14808. };
  14809. // clearing
  14810. this.autoClear = true;
  14811. this.autoClearColor = true;
  14812. this.autoClearDepth = true;
  14813. this.autoClearStencil = true;
  14814. // scene graph
  14815. this.sortObjects = true;
  14816. // user-defined clipping
  14817. this.clippingPlanes = [];
  14818. this.localClippingEnabled = false;
  14819. // physically based shading
  14820. this.gammaFactor = 2.0; // for backwards compatibility
  14821. this.outputEncoding = LinearEncoding;
  14822. // physical lights
  14823. this.physicallyCorrectLights = false;
  14824. // tone mapping
  14825. this.toneMapping = NoToneMapping;
  14826. this.toneMappingExposure = 1.0;
  14827. // morphs
  14828. this.maxMorphTargets = 8;
  14829. this.maxMorphNormals = 4;
  14830. // internal properties
  14831. const _this = this;
  14832. let _isContextLost = false;
  14833. // internal state cache
  14834. let _framebuffer = null;
  14835. let _currentActiveCubeFace = 0;
  14836. let _currentActiveMipmapLevel = 0;
  14837. let _currentRenderTarget = null;
  14838. let _currentFramebuffer = null;
  14839. let _currentMaterialId = - 1;
  14840. let _currentCamera = null;
  14841. let _currentArrayCamera = null;
  14842. const _currentViewport = new Vector4();
  14843. const _currentScissor = new Vector4();
  14844. let _currentScissorTest = null;
  14845. //
  14846. let _width = _canvas.width;
  14847. let _height = _canvas.height;
  14848. let _pixelRatio = 1;
  14849. let _opaqueSort = null;
  14850. let _transparentSort = null;
  14851. const _viewport = new Vector4( 0, 0, _width, _height );
  14852. const _scissor = new Vector4( 0, 0, _width, _height );
  14853. let _scissorTest = false;
  14854. // frustum
  14855. const _frustum = new Frustum();
  14856. // clipping
  14857. const _clipping = new WebGLClipping();
  14858. let _clippingEnabled = false;
  14859. let _localClippingEnabled = false;
  14860. // camera matrices cache
  14861. const _projScreenMatrix = new Matrix4();
  14862. const _vector3 = new Vector3();
  14863. const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  14864. function getTargetPixelRatio() {
  14865. return _currentRenderTarget === null ? _pixelRatio : 1;
  14866. }
  14867. // initialize
  14868. let _gl = _context;
  14869. function getContext( contextNames, contextAttributes ) {
  14870. for ( let i = 0; i < contextNames.length; i ++ ) {
  14871. const contextName = contextNames[ i ];
  14872. const context = _canvas.getContext( contextName, contextAttributes );
  14873. if ( context !== null ) return context;
  14874. }
  14875. return null;
  14876. }
  14877. try {
  14878. const contextAttributes = {
  14879. alpha: _alpha,
  14880. depth: _depth,
  14881. stencil: _stencil,
  14882. antialias: _antialias,
  14883. premultipliedAlpha: _premultipliedAlpha,
  14884. preserveDrawingBuffer: _preserveDrawingBuffer,
  14885. powerPreference: _powerPreference,
  14886. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14887. };
  14888. // event listeners must be registered before WebGL context is created, see #12753
  14889. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14890. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14891. if ( _gl === null ) {
  14892. const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  14893. if ( _this.isWebGL1Renderer === true ) {
  14894. contextNames.shift();
  14895. }
  14896. _gl = getContext( contextNames, contextAttributes );
  14897. if ( _gl === null ) {
  14898. if ( getContext( contextNames ) ) {
  14899. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14900. } else {
  14901. throw new Error( 'Error creating WebGL context.' );
  14902. }
  14903. }
  14904. }
  14905. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14906. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14907. _gl.getShaderPrecisionFormat = function () {
  14908. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14909. };
  14910. }
  14911. } catch ( error ) {
  14912. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14913. throw error;
  14914. }
  14915. let extensions, capabilities, state, info;
  14916. let properties, textures, attributes, geometries, objects;
  14917. let programCache, materials, renderLists, renderStates;
  14918. let background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14919. let utils, bindingStates;
  14920. function initGLContext() {
  14921. extensions = new WebGLExtensions( _gl );
  14922. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14923. if ( capabilities.isWebGL2 === false ) {
  14924. extensions.get( 'WEBGL_depth_texture' );
  14925. extensions.get( 'OES_texture_float' );
  14926. extensions.get( 'OES_texture_half_float' );
  14927. extensions.get( 'OES_texture_half_float_linear' );
  14928. extensions.get( 'OES_standard_derivatives' );
  14929. extensions.get( 'OES_element_index_uint' );
  14930. extensions.get( 'OES_vertex_array_object' );
  14931. extensions.get( 'ANGLE_instanced_arrays' );
  14932. }
  14933. extensions.get( 'OES_texture_float_linear' );
  14934. utils = new WebGLUtils( _gl, extensions, capabilities );
  14935. state = new WebGLState( _gl, extensions, capabilities );
  14936. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14937. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14938. info = new WebGLInfo( _gl );
  14939. properties = new WebGLProperties();
  14940. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14941. attributes = new WebGLAttributes( _gl, capabilities );
  14942. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  14943. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  14944. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14945. morphtargets = new WebGLMorphtargets( _gl );
  14946. programCache = new WebGLPrograms( _this, extensions, capabilities, bindingStates );
  14947. materials = new WebGLMaterials( properties );
  14948. renderLists = new WebGLRenderLists();
  14949. renderStates = new WebGLRenderStates();
  14950. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  14951. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14952. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14953. info.programs = programCache.programs;
  14954. _this.capabilities = capabilities;
  14955. _this.extensions = extensions;
  14956. _this.properties = properties;
  14957. _this.renderLists = renderLists;
  14958. _this.state = state;
  14959. _this.info = info;
  14960. }
  14961. initGLContext();
  14962. // xr
  14963. const xr = new WebXRManager( _this, _gl );
  14964. this.xr = xr;
  14965. // shadow map
  14966. const shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14967. this.shadowMap = shadowMap;
  14968. // API
  14969. this.getContext = function () {
  14970. return _gl;
  14971. };
  14972. this.getContextAttributes = function () {
  14973. return _gl.getContextAttributes();
  14974. };
  14975. this.forceContextLoss = function () {
  14976. const extension = extensions.get( 'WEBGL_lose_context' );
  14977. if ( extension ) extension.loseContext();
  14978. };
  14979. this.forceContextRestore = function () {
  14980. const extension = extensions.get( 'WEBGL_lose_context' );
  14981. if ( extension ) extension.restoreContext();
  14982. };
  14983. this.getPixelRatio = function () {
  14984. return _pixelRatio;
  14985. };
  14986. this.setPixelRatio = function ( value ) {
  14987. if ( value === undefined ) return;
  14988. _pixelRatio = value;
  14989. this.setSize( _width, _height, false );
  14990. };
  14991. this.getSize = function ( target ) {
  14992. if ( target === undefined ) {
  14993. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14994. target = new Vector2();
  14995. }
  14996. return target.set( _width, _height );
  14997. };
  14998. this.setSize = function ( width, height, updateStyle ) {
  14999. if ( xr.isPresenting ) {
  15000. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  15001. return;
  15002. }
  15003. _width = width;
  15004. _height = height;
  15005. _canvas.width = Math.floor( width * _pixelRatio );
  15006. _canvas.height = Math.floor( height * _pixelRatio );
  15007. if ( updateStyle !== false ) {
  15008. _canvas.style.width = width + 'px';
  15009. _canvas.style.height = height + 'px';
  15010. }
  15011. this.setViewport( 0, 0, width, height );
  15012. };
  15013. this.getDrawingBufferSize = function ( target ) {
  15014. if ( target === undefined ) {
  15015. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  15016. target = new Vector2();
  15017. }
  15018. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  15019. };
  15020. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  15021. _width = width;
  15022. _height = height;
  15023. _pixelRatio = pixelRatio;
  15024. _canvas.width = Math.floor( width * pixelRatio );
  15025. _canvas.height = Math.floor( height * pixelRatio );
  15026. this.setViewport( 0, 0, width, height );
  15027. };
  15028. this.getCurrentViewport = function ( target ) {
  15029. if ( target === undefined ) {
  15030. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  15031. target = new Vector4();
  15032. }
  15033. return target.copy( _currentViewport );
  15034. };
  15035. this.getViewport = function ( target ) {
  15036. return target.copy( _viewport );
  15037. };
  15038. this.setViewport = function ( x, y, width, height ) {
  15039. if ( x.isVector4 ) {
  15040. _viewport.set( x.x, x.y, x.z, x.w );
  15041. } else {
  15042. _viewport.set( x, y, width, height );
  15043. }
  15044. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  15045. };
  15046. this.getScissor = function ( target ) {
  15047. return target.copy( _scissor );
  15048. };
  15049. this.setScissor = function ( x, y, width, height ) {
  15050. if ( x.isVector4 ) {
  15051. _scissor.set( x.x, x.y, x.z, x.w );
  15052. } else {
  15053. _scissor.set( x, y, width, height );
  15054. }
  15055. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  15056. };
  15057. this.getScissorTest = function () {
  15058. return _scissorTest;
  15059. };
  15060. this.setScissorTest = function ( boolean ) {
  15061. state.setScissorTest( _scissorTest = boolean );
  15062. };
  15063. this.setOpaqueSort = function ( method ) {
  15064. _opaqueSort = method;
  15065. };
  15066. this.setTransparentSort = function ( method ) {
  15067. _transparentSort = method;
  15068. };
  15069. // Clearing
  15070. this.getClearColor = function () {
  15071. return background.getClearColor();
  15072. };
  15073. this.setClearColor = function () {
  15074. background.setClearColor.apply( background, arguments );
  15075. };
  15076. this.getClearAlpha = function () {
  15077. return background.getClearAlpha();
  15078. };
  15079. this.setClearAlpha = function () {
  15080. background.setClearAlpha.apply( background, arguments );
  15081. };
  15082. this.clear = function ( color, depth, stencil ) {
  15083. let bits = 0;
  15084. if ( color === undefined || color ) bits |= 16384;
  15085. if ( depth === undefined || depth ) bits |= 256;
  15086. if ( stencil === undefined || stencil ) bits |= 1024;
  15087. _gl.clear( bits );
  15088. };
  15089. this.clearColor = function () {
  15090. this.clear( true, false, false );
  15091. };
  15092. this.clearDepth = function () {
  15093. this.clear( false, true, false );
  15094. };
  15095. this.clearStencil = function () {
  15096. this.clear( false, false, true );
  15097. };
  15098. //
  15099. this.dispose = function () {
  15100. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15101. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  15102. renderLists.dispose();
  15103. renderStates.dispose();
  15104. properties.dispose();
  15105. objects.dispose();
  15106. bindingStates.dispose();
  15107. xr.dispose();
  15108. animation.stop();
  15109. };
  15110. // Events
  15111. function onContextLost( event ) {
  15112. event.preventDefault();
  15113. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  15114. _isContextLost = true;
  15115. }
  15116. function onContextRestore( /* event */ ) {
  15117. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  15118. _isContextLost = false;
  15119. initGLContext();
  15120. }
  15121. function onMaterialDispose( event ) {
  15122. const material = event.target;
  15123. material.removeEventListener( 'dispose', onMaterialDispose );
  15124. deallocateMaterial( material );
  15125. }
  15126. // Buffer deallocation
  15127. function deallocateMaterial( material ) {
  15128. releaseMaterialProgramReference( material );
  15129. properties.remove( material );
  15130. }
  15131. function releaseMaterialProgramReference( material ) {
  15132. const programInfo = properties.get( material ).program;
  15133. material.program = undefined;
  15134. if ( programInfo !== undefined ) {
  15135. programCache.releaseProgram( programInfo );
  15136. }
  15137. }
  15138. // Buffer rendering
  15139. function renderObjectImmediate( object, program ) {
  15140. object.render( function ( object ) {
  15141. _this.renderBufferImmediate( object, program );
  15142. } );
  15143. }
  15144. this.renderBufferImmediate = function ( object, program ) {
  15145. bindingStates.initAttributes();
  15146. const buffers = properties.get( object );
  15147. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15148. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15149. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15150. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15151. const programAttributes = program.getAttributes();
  15152. if ( object.hasPositions ) {
  15153. _gl.bindBuffer( 34962, buffers.position );
  15154. _gl.bufferData( 34962, object.positionArray, 35048 );
  15155. bindingStates.enableAttribute( programAttributes.position );
  15156. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  15157. }
  15158. if ( object.hasNormals ) {
  15159. _gl.bindBuffer( 34962, buffers.normal );
  15160. _gl.bufferData( 34962, object.normalArray, 35048 );
  15161. bindingStates.enableAttribute( programAttributes.normal );
  15162. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  15163. }
  15164. if ( object.hasUvs ) {
  15165. _gl.bindBuffer( 34962, buffers.uv );
  15166. _gl.bufferData( 34962, object.uvArray, 35048 );
  15167. bindingStates.enableAttribute( programAttributes.uv );
  15168. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  15169. }
  15170. if ( object.hasColors ) {
  15171. _gl.bindBuffer( 34962, buffers.color );
  15172. _gl.bufferData( 34962, object.colorArray, 35048 );
  15173. bindingStates.enableAttribute( programAttributes.color );
  15174. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  15175. }
  15176. bindingStates.disableUnusedAttributes();
  15177. _gl.drawArrays( 4, 0, object.count );
  15178. object.count = 0;
  15179. };
  15180. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  15181. if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15182. const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  15183. const program = setProgram( camera, scene, material, object );
  15184. state.setMaterial( material, frontFaceCW );
  15185. //
  15186. let index = geometry.index;
  15187. const position = geometry.attributes.position;
  15188. //
  15189. if ( index === null ) {
  15190. if ( position === undefined || position.count === 0 ) return;
  15191. } else if ( index.count === 0 ) {
  15192. return;
  15193. }
  15194. //
  15195. let rangeFactor = 1;
  15196. if ( material.wireframe === true ) {
  15197. index = geometries.getWireframeAttribute( geometry );
  15198. rangeFactor = 2;
  15199. }
  15200. if ( material.morphTargets || material.morphNormals ) {
  15201. morphtargets.update( object, geometry, material, program );
  15202. }
  15203. bindingStates.setup( object, material, program, geometry, index );
  15204. let attribute;
  15205. let renderer = bufferRenderer;
  15206. if ( index !== null ) {
  15207. attribute = attributes.get( index );
  15208. renderer = indexedBufferRenderer;
  15209. renderer.setIndex( attribute );
  15210. }
  15211. //
  15212. const dataCount = ( index !== null ) ? index.count : position.count;
  15213. const rangeStart = geometry.drawRange.start * rangeFactor;
  15214. const rangeCount = geometry.drawRange.count * rangeFactor;
  15215. const groupStart = group !== null ? group.start * rangeFactor : 0;
  15216. const groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15217. const drawStart = Math.max( rangeStart, groupStart );
  15218. const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15219. const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15220. if ( drawCount === 0 ) return;
  15221. //
  15222. if ( object.isMesh ) {
  15223. if ( material.wireframe === true ) {
  15224. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15225. renderer.setMode( 1 );
  15226. } else {
  15227. renderer.setMode( 4 );
  15228. }
  15229. } else if ( object.isLine ) {
  15230. let lineWidth = material.linewidth;
  15231. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15232. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15233. if ( object.isLineSegments ) {
  15234. renderer.setMode( 1 );
  15235. } else if ( object.isLineLoop ) {
  15236. renderer.setMode( 2 );
  15237. } else {
  15238. renderer.setMode( 3 );
  15239. }
  15240. } else if ( object.isPoints ) {
  15241. renderer.setMode( 0 );
  15242. } else if ( object.isSprite ) {
  15243. renderer.setMode( 4 );
  15244. }
  15245. if ( object.isInstancedMesh ) {
  15246. renderer.renderInstances( geometry, drawStart, drawCount, object.count );
  15247. } else if ( geometry.isInstancedBufferGeometry ) {
  15248. const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  15249. renderer.renderInstances( geometry, drawStart, drawCount, instanceCount );
  15250. } else {
  15251. renderer.render( drawStart, drawCount );
  15252. }
  15253. };
  15254. // Compile
  15255. this.compile = function ( scene, camera ) {
  15256. currentRenderState = renderStates.get( scene, camera );
  15257. currentRenderState.init();
  15258. scene.traverse( function ( object ) {
  15259. if ( object.isLight ) {
  15260. currentRenderState.pushLight( object );
  15261. if ( object.castShadow ) {
  15262. currentRenderState.pushShadow( object );
  15263. }
  15264. }
  15265. } );
  15266. currentRenderState.setupLights( camera );
  15267. const compiled = new WeakMap();
  15268. scene.traverse( function ( object ) {
  15269. let material = object.material;
  15270. if ( material ) {
  15271. if ( Array.isArray( material ) ) {
  15272. for ( let i = 0; i < material.length; i ++ ) {
  15273. let material2 = material[ i ];
  15274. if ( compiled.has( material2 ) === false ) {
  15275. initMaterial( material2, scene, object );
  15276. compiled.set( material2 );
  15277. }
  15278. }
  15279. } else if ( compiled.has( material ) === false ) {
  15280. initMaterial( material, scene, object );
  15281. compiled.set( material );
  15282. }
  15283. }
  15284. } );
  15285. };
  15286. // Animation Loop
  15287. let onAnimationFrameCallback = null;
  15288. function onAnimationFrame( time ) {
  15289. if ( xr.isPresenting ) return;
  15290. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  15291. }
  15292. const animation = new WebGLAnimation();
  15293. animation.setAnimationLoop( onAnimationFrame );
  15294. if ( typeof window !== 'undefined' ) animation.setContext( window );
  15295. this.setAnimationLoop = function ( callback ) {
  15296. onAnimationFrameCallback = callback;
  15297. xr.setAnimationLoop( callback );
  15298. ( callback === null ) ? animation.stop() : animation.start();
  15299. };
  15300. // Rendering
  15301. this.render = function ( scene, camera ) {
  15302. let renderTarget, forceClear;
  15303. if ( arguments[ 2 ] !== undefined ) {
  15304. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  15305. renderTarget = arguments[ 2 ];
  15306. }
  15307. if ( arguments[ 3 ] !== undefined ) {
  15308. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  15309. forceClear = arguments[ 3 ];
  15310. }
  15311. if ( camera !== undefined && camera.isCamera !== true ) {
  15312. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15313. return;
  15314. }
  15315. if ( _isContextLost === true ) return;
  15316. // reset caching for this frame
  15317. bindingStates.resetDefaultState();
  15318. _currentMaterialId = - 1;
  15319. _currentCamera = null;
  15320. // update scene graph
  15321. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15322. // update camera matrices and frustum
  15323. if ( camera.parent === null ) camera.updateMatrixWorld();
  15324. if ( xr.enabled === true && xr.isPresenting === true ) {
  15325. camera = xr.getCamera( camera );
  15326. }
  15327. //
  15328. if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  15329. currentRenderState = renderStates.get( scene, camera );
  15330. currentRenderState.init();
  15331. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15332. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  15333. _localClippingEnabled = this.localClippingEnabled;
  15334. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15335. currentRenderList = renderLists.get( scene, camera );
  15336. currentRenderList.init();
  15337. projectObject( scene, camera, 0, _this.sortObjects );
  15338. currentRenderList.finish();
  15339. if ( _this.sortObjects === true ) {
  15340. currentRenderList.sort( _opaqueSort, _transparentSort );
  15341. }
  15342. //
  15343. if ( _clippingEnabled === true ) _clipping.beginShadows();
  15344. const shadowsArray = currentRenderState.state.shadowsArray;
  15345. shadowMap.render( shadowsArray, scene, camera );
  15346. currentRenderState.setupLights( camera );
  15347. if ( _clippingEnabled === true ) _clipping.endShadows();
  15348. //
  15349. if ( this.info.autoReset === true ) this.info.reset();
  15350. if ( renderTarget !== undefined ) {
  15351. this.setRenderTarget( renderTarget );
  15352. }
  15353. //
  15354. background.render( currentRenderList, scene, camera, forceClear );
  15355. // render scene
  15356. const opaqueObjects = currentRenderList.opaque;
  15357. const transparentObjects = currentRenderList.transparent;
  15358. if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
  15359. if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
  15360. //
  15361. if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
  15362. //
  15363. if ( _currentRenderTarget !== null ) {
  15364. // Generate mipmap if we're using any kind of mipmap filtering
  15365. textures.updateRenderTargetMipmap( _currentRenderTarget );
  15366. // resolve multisample renderbuffers to a single-sample texture if necessary
  15367. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  15368. }
  15369. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15370. state.buffers.depth.setTest( true );
  15371. state.buffers.depth.setMask( true );
  15372. state.buffers.color.setMask( true );
  15373. state.setPolygonOffset( false );
  15374. // _gl.finish();
  15375. currentRenderList = null;
  15376. currentRenderState = null;
  15377. };
  15378. function projectObject( object, camera, groupOrder, sortObjects ) {
  15379. if ( object.visible === false ) return;
  15380. const visible = object.layers.test( camera.layers );
  15381. if ( visible ) {
  15382. if ( object.isGroup ) {
  15383. groupOrder = object.renderOrder;
  15384. } else if ( object.isLOD ) {
  15385. if ( object.autoUpdate === true ) object.update( camera );
  15386. } else if ( object.isLight ) {
  15387. currentRenderState.pushLight( object );
  15388. if ( object.castShadow ) {
  15389. currentRenderState.pushShadow( object );
  15390. }
  15391. } else if ( object.isSprite ) {
  15392. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  15393. if ( sortObjects ) {
  15394. _vector3.setFromMatrixPosition( object.matrixWorld )
  15395. .applyMatrix4( _projScreenMatrix );
  15396. }
  15397. const geometry = objects.update( object );
  15398. const material = object.material;
  15399. if ( material.visible ) {
  15400. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15401. }
  15402. }
  15403. } else if ( object.isImmediateRenderObject ) {
  15404. if ( sortObjects ) {
  15405. _vector3.setFromMatrixPosition( object.matrixWorld )
  15406. .applyMatrix4( _projScreenMatrix );
  15407. }
  15408. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  15409. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  15410. if ( object.isSkinnedMesh ) {
  15411. // update skeleton only once in a frame
  15412. if ( object.skeleton.frame !== info.render.frame ) {
  15413. object.skeleton.update();
  15414. object.skeleton.frame = info.render.frame;
  15415. }
  15416. }
  15417. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  15418. if ( sortObjects ) {
  15419. _vector3.setFromMatrixPosition( object.matrixWorld )
  15420. .applyMatrix4( _projScreenMatrix );
  15421. }
  15422. const geometry = objects.update( object );
  15423. const material = object.material;
  15424. if ( Array.isArray( material ) ) {
  15425. const groups = geometry.groups;
  15426. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  15427. const group = groups[ i ];
  15428. const groupMaterial = material[ group.materialIndex ];
  15429. if ( groupMaterial && groupMaterial.visible ) {
  15430. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  15431. }
  15432. }
  15433. } else if ( material.visible ) {
  15434. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  15435. }
  15436. }
  15437. }
  15438. }
  15439. const children = object.children;
  15440. for ( let i = 0, l = children.length; i < l; i ++ ) {
  15441. projectObject( children[ i ], camera, groupOrder, sortObjects );
  15442. }
  15443. }
  15444. function renderObjects( renderList, scene, camera ) {
  15445. const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15446. for ( let i = 0, l = renderList.length; i < l; i ++ ) {
  15447. const renderItem = renderList[ i ];
  15448. const object = renderItem.object;
  15449. const geometry = renderItem.geometry;
  15450. const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15451. const group = renderItem.group;
  15452. if ( camera.isArrayCamera ) {
  15453. _currentArrayCamera = camera;
  15454. const cameras = camera.cameras;
  15455. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  15456. const camera2 = cameras[ j ];
  15457. if ( object.layers.test( camera2.layers ) ) {
  15458. state.viewport( _currentViewport.copy( camera2.viewport ) );
  15459. currentRenderState.setupLights( camera2 );
  15460. renderObject( object, scene, camera2, geometry, material, group );
  15461. }
  15462. }
  15463. } else {
  15464. _currentArrayCamera = null;
  15465. renderObject( object, scene, camera, geometry, material, group );
  15466. }
  15467. }
  15468. }
  15469. function renderObject( object, scene, camera, geometry, material, group ) {
  15470. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  15471. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15472. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15473. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15474. if ( object.isImmediateRenderObject ) {
  15475. const program = setProgram( camera, scene, material, object );
  15476. state.setMaterial( material );
  15477. bindingStates.reset();
  15478. renderObjectImmediate( object, program );
  15479. } else {
  15480. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  15481. }
  15482. object.onAfterRender( _this, scene, camera, geometry, material, group );
  15483. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  15484. }
  15485. function initMaterial( material, scene, object ) {
  15486. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15487. const materialProperties = properties.get( material );
  15488. const lights = currentRenderState.state.lights;
  15489. const shadowsArray = currentRenderState.state.shadowsArray;
  15490. const lightsStateVersion = lights.state.version;
  15491. const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
  15492. const programCacheKey = programCache.getProgramCacheKey( parameters );
  15493. let program = materialProperties.program;
  15494. let programChange = true;
  15495. if ( program === undefined ) {
  15496. // new material
  15497. material.addEventListener( 'dispose', onMaterialDispose );
  15498. } else if ( program.cacheKey !== programCacheKey ) {
  15499. // changed glsl or parameters
  15500. releaseMaterialProgramReference( material );
  15501. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  15502. materialProperties.lightsStateVersion = lightsStateVersion;
  15503. programChange = false;
  15504. } else if ( parameters.shaderID !== undefined ) {
  15505. // same glsl and uniform list
  15506. return;
  15507. } else {
  15508. // only rebuild uniform list
  15509. programChange = false;
  15510. }
  15511. if ( programChange ) {
  15512. program = programCache.acquireProgram( parameters, programCacheKey );
  15513. materialProperties.program = program;
  15514. materialProperties.uniforms = parameters.uniforms;
  15515. materialProperties.outputEncoding = parameters.outputEncoding;
  15516. material.program = program;
  15517. }
  15518. const programAttributes = program.getAttributes();
  15519. if ( material.morphTargets ) {
  15520. material.numSupportedMorphTargets = 0;
  15521. for ( let i = 0; i < _this.maxMorphTargets; i ++ ) {
  15522. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  15523. material.numSupportedMorphTargets ++;
  15524. }
  15525. }
  15526. }
  15527. if ( material.morphNormals ) {
  15528. material.numSupportedMorphNormals = 0;
  15529. for ( let i = 0; i < _this.maxMorphNormals; i ++ ) {
  15530. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  15531. material.numSupportedMorphNormals ++;
  15532. }
  15533. }
  15534. }
  15535. const uniforms = materialProperties.uniforms;
  15536. if ( ! material.isShaderMaterial &&
  15537. ! material.isRawShaderMaterial ||
  15538. material.clipping === true ) {
  15539. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15540. materialProperties.numIntersection = _clipping.numIntersection;
  15541. uniforms.clippingPlanes = _clipping.uniform;
  15542. }
  15543. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15544. materialProperties.fog = scene.fog;
  15545. // store the light setup it was created for
  15546. materialProperties.needsLights = materialNeedsLights( material );
  15547. materialProperties.lightsStateVersion = lightsStateVersion;
  15548. if ( materialProperties.needsLights ) {
  15549. // wire up the material to this renderer's lighting state
  15550. uniforms.ambientLightColor.value = lights.state.ambient;
  15551. uniforms.lightProbe.value = lights.state.probe;
  15552. uniforms.directionalLights.value = lights.state.directional;
  15553. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15554. uniforms.spotLights.value = lights.state.spot;
  15555. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15556. uniforms.rectAreaLights.value = lights.state.rectArea;
  15557. uniforms.pointLights.value = lights.state.point;
  15558. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15559. uniforms.hemisphereLights.value = lights.state.hemi;
  15560. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15561. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15562. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15563. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15564. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15565. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  15566. // TODO (abelnation): add area lights shadow info to uniforms
  15567. }
  15568. const progUniforms = materialProperties.program.getUniforms(),
  15569. uniformsList =
  15570. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15571. materialProperties.uniformsList = uniformsList;
  15572. }
  15573. function setProgram( camera, scene, material, object ) {
  15574. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15575. textures.resetTextureUnits();
  15576. const fog = scene.fog;
  15577. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  15578. const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15579. const materialProperties = properties.get( material );
  15580. const lights = currentRenderState.state.lights;
  15581. if ( _clippingEnabled === true ) {
  15582. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  15583. const useCache =
  15584. camera === _currentCamera &&
  15585. material.id === _currentMaterialId;
  15586. // we might want to call this function with some ClippingGroup
  15587. // object instead of the material, once it becomes feasible
  15588. // (#8465, #8379)
  15589. _clipping.setState(
  15590. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  15591. camera, materialProperties, useCache );
  15592. }
  15593. }
  15594. if ( material.version === materialProperties.__version ) {
  15595. if ( materialProperties.program === undefined ) {
  15596. initMaterial( material, scene, object );
  15597. } else if ( material.fog && materialProperties.fog !== fog ) {
  15598. initMaterial( material, scene, object );
  15599. } else if ( materialProperties.environment !== environment ) {
  15600. initMaterial( material, scene, object );
  15601. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  15602. initMaterial( material, scene, object );
  15603. } else if ( materialProperties.numClippingPlanes !== undefined &&
  15604. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  15605. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  15606. initMaterial( material, scene, object );
  15607. } else if ( materialProperties.outputEncoding !== encoding ) {
  15608. initMaterial( material, scene, object );
  15609. }
  15610. } else {
  15611. initMaterial( material, scene, object );
  15612. materialProperties.__version = material.version;
  15613. }
  15614. let refreshProgram = false;
  15615. let refreshMaterial = false;
  15616. let refreshLights = false;
  15617. const program = materialProperties.program,
  15618. p_uniforms = program.getUniforms(),
  15619. m_uniforms = materialProperties.uniforms;
  15620. if ( state.useProgram( program.program ) ) {
  15621. refreshProgram = true;
  15622. refreshMaterial = true;
  15623. refreshLights = true;
  15624. }
  15625. if ( material.id !== _currentMaterialId ) {
  15626. _currentMaterialId = material.id;
  15627. refreshMaterial = true;
  15628. }
  15629. if ( refreshProgram || _currentCamera !== camera ) {
  15630. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  15631. if ( capabilities.logarithmicDepthBuffer ) {
  15632. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15633. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15634. }
  15635. if ( _currentCamera !== camera ) {
  15636. _currentCamera = camera;
  15637. // lighting uniforms depend on the camera so enforce an update
  15638. // now, in case this material supports lights - or later, when
  15639. // the next material that does gets activated:
  15640. refreshMaterial = true; // set to true on material change
  15641. refreshLights = true; // remains set until update done
  15642. }
  15643. // load material specific uniforms
  15644. // (shader material also gets them for the sake of genericity)
  15645. if ( material.isShaderMaterial ||
  15646. material.isMeshPhongMaterial ||
  15647. material.isMeshToonMaterial ||
  15648. material.isMeshStandardMaterial ||
  15649. material.envMap ) {
  15650. const uCamPos = p_uniforms.map.cameraPosition;
  15651. if ( uCamPos !== undefined ) {
  15652. uCamPos.setValue( _gl,
  15653. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15654. }
  15655. }
  15656. if ( material.isMeshPhongMaterial ||
  15657. material.isMeshToonMaterial ||
  15658. material.isMeshLambertMaterial ||
  15659. material.isMeshBasicMaterial ||
  15660. material.isMeshStandardMaterial ||
  15661. material.isShaderMaterial ) {
  15662. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  15663. }
  15664. if ( material.isMeshPhongMaterial ||
  15665. material.isMeshToonMaterial ||
  15666. material.isMeshLambertMaterial ||
  15667. material.isMeshBasicMaterial ||
  15668. material.isMeshStandardMaterial ||
  15669. material.isShaderMaterial ||
  15670. material.isShadowMaterial ||
  15671. material.skinning ) {
  15672. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15673. }
  15674. }
  15675. // skinning uniforms must be set even if material didn't change
  15676. // auto-setting of texture unit for bone texture must go before other textures
  15677. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15678. if ( material.skinning ) {
  15679. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15680. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15681. const skeleton = object.skeleton;
  15682. if ( skeleton ) {
  15683. const bones = skeleton.bones;
  15684. if ( capabilities.floatVertexTextures ) {
  15685. if ( skeleton.boneTexture === undefined ) {
  15686. // layout (1 matrix = 4 pixels)
  15687. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15688. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15689. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15690. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15691. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15692. let size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  15693. size = MathUtils.ceilPowerOfTwo( size );
  15694. size = Math.max( size, 4 );
  15695. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  15696. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  15697. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  15698. skeleton.boneMatrices = boneMatrices;
  15699. skeleton.boneTexture = boneTexture;
  15700. skeleton.boneTextureSize = size;
  15701. }
  15702. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  15703. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  15704. } else {
  15705. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15706. }
  15707. }
  15708. }
  15709. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  15710. materialProperties.receiveShadow = object.receiveShadow;
  15711. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  15712. }
  15713. if ( refreshMaterial ) {
  15714. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  15715. if ( materialProperties.needsLights ) {
  15716. // the current material requires lighting info
  15717. // note: all lighting uniforms are always set correctly
  15718. // they simply reference the renderer's state for their
  15719. // values
  15720. //
  15721. // use the current material's .needsUpdate flags to set
  15722. // the GL state when required
  15723. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15724. }
  15725. // refresh uniforms common to several materials
  15726. if ( fog && material.fog ) {
  15727. materials.refreshFogUniforms( m_uniforms, fog );
  15728. }
  15729. materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height );
  15730. // RectAreaLight Texture
  15731. // TODO (mrdoob): Find a nicer implementation
  15732. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  15733. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  15734. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15735. }
  15736. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  15737. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  15738. material.uniformsNeedUpdate = false;
  15739. }
  15740. if ( material.isSpriteMaterial ) {
  15741. p_uniforms.setValue( _gl, 'center', object.center );
  15742. }
  15743. // common matrices
  15744. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  15745. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  15746. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15747. return program;
  15748. }
  15749. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15750. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15751. uniforms.ambientLightColor.needsUpdate = value;
  15752. uniforms.lightProbe.needsUpdate = value;
  15753. uniforms.directionalLights.needsUpdate = value;
  15754. uniforms.directionalLightShadows.needsUpdate = value;
  15755. uniforms.pointLights.needsUpdate = value;
  15756. uniforms.pointLightShadows.needsUpdate = value;
  15757. uniforms.spotLights.needsUpdate = value;
  15758. uniforms.spotLightShadows.needsUpdate = value;
  15759. uniforms.rectAreaLights.needsUpdate = value;
  15760. uniforms.hemisphereLights.needsUpdate = value;
  15761. }
  15762. function materialNeedsLights( material ) {
  15763. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  15764. material.isMeshStandardMaterial || material.isShadowMaterial ||
  15765. ( material.isShaderMaterial && material.lights === true );
  15766. }
  15767. //
  15768. this.setFramebuffer = function ( value ) {
  15769. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  15770. _framebuffer = value;
  15771. };
  15772. this.getActiveCubeFace = function () {
  15773. return _currentActiveCubeFace;
  15774. };
  15775. this.getActiveMipmapLevel = function () {
  15776. return _currentActiveMipmapLevel;
  15777. };
  15778. this.getRenderTarget = function () {
  15779. return _currentRenderTarget;
  15780. };
  15781. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15782. _currentRenderTarget = renderTarget;
  15783. _currentActiveCubeFace = activeCubeFace;
  15784. _currentActiveMipmapLevel = activeMipmapLevel;
  15785. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15786. textures.setupRenderTarget( renderTarget );
  15787. }
  15788. let framebuffer = _framebuffer;
  15789. let isCube = false;
  15790. if ( renderTarget ) {
  15791. const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15792. if ( renderTarget.isWebGLCubeRenderTarget ) {
  15793. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15794. isCube = true;
  15795. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15796. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15797. } else {
  15798. framebuffer = __webglFramebuffer;
  15799. }
  15800. _currentViewport.copy( renderTarget.viewport );
  15801. _currentScissor.copy( renderTarget.scissor );
  15802. _currentScissorTest = renderTarget.scissorTest;
  15803. } else {
  15804. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15805. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15806. _currentScissorTest = _scissorTest;
  15807. }
  15808. if ( _currentFramebuffer !== framebuffer ) {
  15809. _gl.bindFramebuffer( 36160, framebuffer );
  15810. _currentFramebuffer = framebuffer;
  15811. }
  15812. state.viewport( _currentViewport );
  15813. state.scissor( _currentScissor );
  15814. state.setScissorTest( _currentScissorTest );
  15815. if ( isCube ) {
  15816. const textureProperties = properties.get( renderTarget.texture );
  15817. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15818. }
  15819. };
  15820. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15821. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15822. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15823. return;
  15824. }
  15825. let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15826. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  15827. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15828. }
  15829. if ( framebuffer ) {
  15830. let restore = false;
  15831. if ( framebuffer !== _currentFramebuffer ) {
  15832. _gl.bindFramebuffer( 36160, framebuffer );
  15833. restore = true;
  15834. }
  15835. try {
  15836. const texture = renderTarget.texture;
  15837. const textureFormat = texture.format;
  15838. const textureType = texture.type;
  15839. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15840. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15841. return;
  15842. }
  15843. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15844. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15845. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15846. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15847. return;
  15848. }
  15849. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15850. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15851. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15852. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15853. }
  15854. } else {
  15855. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15856. }
  15857. } finally {
  15858. if ( restore ) {
  15859. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15860. }
  15861. }
  15862. }
  15863. };
  15864. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15865. if ( level === undefined ) level = 0;
  15866. const levelScale = Math.pow( 2, - level );
  15867. const width = Math.floor( texture.image.width * levelScale );
  15868. const height = Math.floor( texture.image.height * levelScale );
  15869. const glFormat = utils.convert( texture.format );
  15870. textures.setTexture2D( texture, 0 );
  15871. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  15872. state.unbindTexture();
  15873. };
  15874. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15875. if ( level === undefined ) level = 0;
  15876. const width = srcTexture.image.width;
  15877. const height = srcTexture.image.height;
  15878. const glFormat = utils.convert( dstTexture.format );
  15879. const glType = utils.convert( dstTexture.type );
  15880. textures.setTexture2D( dstTexture, 0 );
  15881. // As another texture upload may have changed pixelStorei
  15882. // parameters, make sure they are correct for the dstTexture
  15883. _gl.pixelStorei( 37440, dstTexture.flipY );
  15884. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  15885. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  15886. if ( srcTexture.isDataTexture ) {
  15887. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15888. } else {
  15889. if ( srcTexture.isCompressedTexture ) {
  15890. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  15891. } else {
  15892. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  15893. }
  15894. }
  15895. // Generate mipmaps only when copying level 0
  15896. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  15897. state.unbindTexture();
  15898. };
  15899. this.initTexture = function ( texture ) {
  15900. textures.setTexture2D( texture, 0 );
  15901. state.unbindTexture();
  15902. };
  15903. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15904. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15905. }
  15906. }
  15907. /**
  15908. * @author Mugen87 / https://github.com/Mugen87
  15909. */
  15910. function WebGL1Renderer( parameters ) {
  15911. WebGLRenderer.call( this, parameters );
  15912. }
  15913. WebGL1Renderer.prototype = Object.assign( Object.create( WebGLRenderer.prototype ), {
  15914. constructor: WebGL1Renderer,
  15915. isWebGL1Renderer: true
  15916. } );
  15917. /**
  15918. * @author mrdoob / http://mrdoob.com/
  15919. * @author alteredq / http://alteredqualia.com/
  15920. */
  15921. function FogExp2( color, density ) {
  15922. this.name = '';
  15923. this.color = new Color( color );
  15924. this.density = ( density !== undefined ) ? density : 0.00025;
  15925. }
  15926. Object.assign( FogExp2.prototype, {
  15927. isFogExp2: true,
  15928. clone: function () {
  15929. return new FogExp2( this.color, this.density );
  15930. },
  15931. toJSON: function ( /* meta */ ) {
  15932. return {
  15933. type: 'FogExp2',
  15934. color: this.color.getHex(),
  15935. density: this.density
  15936. };
  15937. }
  15938. } );
  15939. /**
  15940. * @author mrdoob / http://mrdoob.com/
  15941. * @author alteredq / http://alteredqualia.com/
  15942. */
  15943. function Fog( color, near, far ) {
  15944. this.name = '';
  15945. this.color = new Color( color );
  15946. this.near = ( near !== undefined ) ? near : 1;
  15947. this.far = ( far !== undefined ) ? far : 1000;
  15948. }
  15949. Object.assign( Fog.prototype, {
  15950. isFog: true,
  15951. clone: function () {
  15952. return new Fog( this.color, this.near, this.far );
  15953. },
  15954. toJSON: function ( /* meta */ ) {
  15955. return {
  15956. type: 'Fog',
  15957. color: this.color.getHex(),
  15958. near: this.near,
  15959. far: this.far
  15960. };
  15961. }
  15962. } );
  15963. /**
  15964. * @author benaadams / https://twitter.com/ben_a_adams
  15965. */
  15966. function InterleavedBuffer( array, stride ) {
  15967. this.array = array;
  15968. this.stride = stride;
  15969. this.count = array !== undefined ? array.length / stride : 0;
  15970. this.usage = StaticDrawUsage;
  15971. this.updateRange = { offset: 0, count: - 1 };
  15972. this.version = 0;
  15973. this.uuid = MathUtils.generateUUID();
  15974. }
  15975. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15976. set: function ( value ) {
  15977. if ( value === true ) this.version ++;
  15978. }
  15979. } );
  15980. Object.assign( InterleavedBuffer.prototype, {
  15981. isInterleavedBuffer: true,
  15982. onUploadCallback: function () {},
  15983. setUsage: function ( value ) {
  15984. this.usage = value;
  15985. return this;
  15986. },
  15987. copy: function ( source ) {
  15988. this.array = new source.array.constructor( source.array );
  15989. this.count = source.count;
  15990. this.stride = source.stride;
  15991. this.usage = source.usage;
  15992. return this;
  15993. },
  15994. copyAt: function ( index1, attribute, index2 ) {
  15995. index1 *= this.stride;
  15996. index2 *= attribute.stride;
  15997. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  15998. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15999. }
  16000. return this;
  16001. },
  16002. set: function ( value, offset ) {
  16003. if ( offset === undefined ) offset = 0;
  16004. this.array.set( value, offset );
  16005. return this;
  16006. },
  16007. clone: function ( data ) {
  16008. if ( data.arrayBuffers === undefined ) {
  16009. data.arrayBuffers = {};
  16010. }
  16011. if ( this.array.buffer._uuid === undefined ) {
  16012. this.array.buffer._uuid = MathUtils.generateUUID();
  16013. }
  16014. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16015. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  16016. }
  16017. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  16018. const ib = new InterleavedBuffer( array, this.stride );
  16019. ib.setUsage( this.usage );
  16020. return ib;
  16021. },
  16022. onUpload: function ( callback ) {
  16023. this.onUploadCallback = callback;
  16024. return this;
  16025. },
  16026. toJSON: function ( data ) {
  16027. if ( data.arrayBuffers === undefined ) {
  16028. data.arrayBuffers = {};
  16029. }
  16030. // generate UUID for array buffer if necessary
  16031. if ( this.array.buffer._uuid === undefined ) {
  16032. this.array.buffer._uuid = MathUtils.generateUUID();
  16033. }
  16034. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  16035. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  16036. }
  16037. //
  16038. return {
  16039. uuid: this.uuid,
  16040. buffer: this.array.buffer._uuid,
  16041. type: this.array.constructor.name,
  16042. stride: this.stride
  16043. };
  16044. }
  16045. } );
  16046. /**
  16047. * @author benaadams / https://twitter.com/ben_a_adams
  16048. */
  16049. const _vector$6 = new Vector3();
  16050. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  16051. this.name = '';
  16052. this.data = interleavedBuffer;
  16053. this.itemSize = itemSize;
  16054. this.offset = offset;
  16055. this.normalized = normalized === true;
  16056. }
  16057. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  16058. count: {
  16059. get: function () {
  16060. return this.data.count;
  16061. }
  16062. },
  16063. array: {
  16064. get: function () {
  16065. return this.data.array;
  16066. }
  16067. }
  16068. } );
  16069. Object.assign( InterleavedBufferAttribute.prototype, {
  16070. isInterleavedBufferAttribute: true,
  16071. applyMatrix4: function ( m ) {
  16072. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  16073. _vector$6.x = this.getX( i );
  16074. _vector$6.y = this.getY( i );
  16075. _vector$6.z = this.getZ( i );
  16076. _vector$6.applyMatrix4( m );
  16077. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  16078. }
  16079. return this;
  16080. },
  16081. setX: function ( index, x ) {
  16082. this.data.array[ index * this.data.stride + this.offset ] = x;
  16083. return this;
  16084. },
  16085. setY: function ( index, y ) {
  16086. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16087. return this;
  16088. },
  16089. setZ: function ( index, z ) {
  16090. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16091. return this;
  16092. },
  16093. setW: function ( index, w ) {
  16094. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16095. return this;
  16096. },
  16097. getX: function ( index ) {
  16098. return this.data.array[ index * this.data.stride + this.offset ];
  16099. },
  16100. getY: function ( index ) {
  16101. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16102. },
  16103. getZ: function ( index ) {
  16104. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16105. },
  16106. getW: function ( index ) {
  16107. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16108. },
  16109. setXY: function ( index, x, y ) {
  16110. index = index * this.data.stride + this.offset;
  16111. this.data.array[ index + 0 ] = x;
  16112. this.data.array[ index + 1 ] = y;
  16113. return this;
  16114. },
  16115. setXYZ: function ( index, x, y, z ) {
  16116. index = index * this.data.stride + this.offset;
  16117. this.data.array[ index + 0 ] = x;
  16118. this.data.array[ index + 1 ] = y;
  16119. this.data.array[ index + 2 ] = z;
  16120. return this;
  16121. },
  16122. setXYZW: function ( index, x, y, z, w ) {
  16123. index = index * this.data.stride + this.offset;
  16124. this.data.array[ index + 0 ] = x;
  16125. this.data.array[ index + 1 ] = y;
  16126. this.data.array[ index + 2 ] = z;
  16127. this.data.array[ index + 3 ] = w;
  16128. return this;
  16129. },
  16130. clone: function ( data ) {
  16131. if ( data === undefined ) {
  16132. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  16133. const array = [];
  16134. for ( let i = 0; i < this.count; i ++ ) {
  16135. const index = i * this.data.stride + this.offset;
  16136. for ( let j = 0; j < this.itemSize; j ++ ) {
  16137. array.push( this.data.array[ index + j ] );
  16138. }
  16139. }
  16140. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  16141. } else {
  16142. if ( data.interleavedBuffers === undefined ) {
  16143. data.interleavedBuffers = {};
  16144. }
  16145. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16146. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  16147. }
  16148. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  16149. }
  16150. },
  16151. toJSON: function ( data ) {
  16152. if ( data === undefined ) {
  16153. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  16154. const array = [];
  16155. for ( let i = 0; i < this.count; i ++ ) {
  16156. const index = i * this.data.stride + this.offset;
  16157. for ( let j = 0; j < this.itemSize; j ++ ) {
  16158. array.push( this.data.array[ index + j ] );
  16159. }
  16160. }
  16161. // deinterleave data and save it as an ordinary buffer attribute for now
  16162. return {
  16163. itemSize: this.itemSize,
  16164. type: this.array.constructor.name,
  16165. array: array,
  16166. normalized: this.normalized
  16167. };
  16168. } else {
  16169. // save as true interlaved attribtue
  16170. if ( data.interleavedBuffers === undefined ) {
  16171. data.interleavedBuffers = {};
  16172. }
  16173. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  16174. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  16175. }
  16176. return {
  16177. isInterleavedBufferAttribute: true,
  16178. itemSize: this.itemSize,
  16179. data: this.data.uuid,
  16180. offset: this.offset,
  16181. normalized: this.normalized
  16182. };
  16183. }
  16184. }
  16185. } );
  16186. /**
  16187. * @author alteredq / http://alteredqualia.com/
  16188. *
  16189. * parameters = {
  16190. * color: <hex>,
  16191. * map: new THREE.Texture( <Image> ),
  16192. * alphaMap: new THREE.Texture( <Image> ),
  16193. * rotation: <float>,
  16194. * sizeAttenuation: <bool>
  16195. * }
  16196. */
  16197. function SpriteMaterial( parameters ) {
  16198. Material.call( this );
  16199. this.type = 'SpriteMaterial';
  16200. this.color = new Color( 0xffffff );
  16201. this.map = null;
  16202. this.alphaMap = null;
  16203. this.rotation = 0;
  16204. this.sizeAttenuation = true;
  16205. this.transparent = true;
  16206. this.setValues( parameters );
  16207. }
  16208. SpriteMaterial.prototype = Object.create( Material.prototype );
  16209. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16210. SpriteMaterial.prototype.isSpriteMaterial = true;
  16211. SpriteMaterial.prototype.copy = function ( source ) {
  16212. Material.prototype.copy.call( this, source );
  16213. this.color.copy( source.color );
  16214. this.map = source.map;
  16215. this.alphaMap = source.alphaMap;
  16216. this.rotation = source.rotation;
  16217. this.sizeAttenuation = source.sizeAttenuation;
  16218. return this;
  16219. };
  16220. /**
  16221. * @author mikael emtinger / http://gomo.se/
  16222. * @author alteredq / http://alteredqualia.com/
  16223. */
  16224. let _geometry;
  16225. const _intersectPoint = new Vector3();
  16226. const _worldScale = new Vector3();
  16227. const _mvPosition = new Vector3();
  16228. const _alignedPosition = new Vector2();
  16229. const _rotatedPosition = new Vector2();
  16230. const _viewWorldMatrix = new Matrix4();
  16231. const _vA$1 = new Vector3();
  16232. const _vB$1 = new Vector3();
  16233. const _vC$1 = new Vector3();
  16234. const _uvA$1 = new Vector2();
  16235. const _uvB$1 = new Vector2();
  16236. const _uvC$1 = new Vector2();
  16237. function Sprite( material ) {
  16238. Object3D.call( this );
  16239. this.type = 'Sprite';
  16240. if ( _geometry === undefined ) {
  16241. _geometry = new BufferGeometry();
  16242. const float32Array = new Float32Array( [
  16243. - 0.5, - 0.5, 0, 0, 0,
  16244. 0.5, - 0.5, 0, 1, 0,
  16245. 0.5, 0.5, 0, 1, 1,
  16246. - 0.5, 0.5, 0, 0, 1
  16247. ] );
  16248. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  16249. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  16250. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  16251. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  16252. }
  16253. this.geometry = _geometry;
  16254. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  16255. this.center = new Vector2( 0.5, 0.5 );
  16256. }
  16257. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16258. constructor: Sprite,
  16259. isSprite: true,
  16260. raycast: function ( raycaster, intersects ) {
  16261. if ( raycaster.camera === null ) {
  16262. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  16263. }
  16264. _worldScale.setFromMatrixScale( this.matrixWorld );
  16265. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  16266. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  16267. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  16268. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  16269. _worldScale.multiplyScalar( - _mvPosition.z );
  16270. }
  16271. const rotation = this.material.rotation;
  16272. let sin, cos;
  16273. if ( rotation !== 0 ) {
  16274. cos = Math.cos( rotation );
  16275. sin = Math.sin( rotation );
  16276. }
  16277. const center = this.center;
  16278. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16279. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16280. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16281. _uvA$1.set( 0, 0 );
  16282. _uvB$1.set( 1, 0 );
  16283. _uvC$1.set( 1, 1 );
  16284. // check first triangle
  16285. let intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  16286. if ( intersect === null ) {
  16287. // check second triangle
  16288. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  16289. _uvB$1.set( 0, 1 );
  16290. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  16291. if ( intersect === null ) {
  16292. return;
  16293. }
  16294. }
  16295. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  16296. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16297. intersects.push( {
  16298. distance: distance,
  16299. point: _intersectPoint.clone(),
  16300. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  16301. face: null,
  16302. object: this
  16303. } );
  16304. },
  16305. copy: function ( source ) {
  16306. Object3D.prototype.copy.call( this, source );
  16307. if ( source.center !== undefined ) this.center.copy( source.center );
  16308. this.material = source.material;
  16309. return this;
  16310. }
  16311. } );
  16312. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  16313. // compute position in camera space
  16314. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  16315. // to check if rotation is not zero
  16316. if ( sin !== undefined ) {
  16317. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  16318. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  16319. } else {
  16320. _rotatedPosition.copy( _alignedPosition );
  16321. }
  16322. vertexPosition.copy( mvPosition );
  16323. vertexPosition.x += _rotatedPosition.x;
  16324. vertexPosition.y += _rotatedPosition.y;
  16325. // transform to world space
  16326. vertexPosition.applyMatrix4( _viewWorldMatrix );
  16327. }
  16328. /**
  16329. * @author mikael emtinger / http://gomo.se/
  16330. * @author alteredq / http://alteredqualia.com/
  16331. * @author mrdoob / http://mrdoob.com/
  16332. */
  16333. const _v1$4 = new Vector3();
  16334. const _v2$2 = new Vector3();
  16335. function LOD() {
  16336. Object3D.call( this );
  16337. this._currentLevel = 0;
  16338. this.type = 'LOD';
  16339. Object.defineProperties( this, {
  16340. levels: {
  16341. enumerable: true,
  16342. value: []
  16343. }
  16344. } );
  16345. this.autoUpdate = true;
  16346. }
  16347. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16348. constructor: LOD,
  16349. isLOD: true,
  16350. copy: function ( source ) {
  16351. Object3D.prototype.copy.call( this, source, false );
  16352. const levels = source.levels;
  16353. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  16354. const level = levels[ i ];
  16355. this.addLevel( level.object.clone(), level.distance );
  16356. }
  16357. this.autoUpdate = source.autoUpdate;
  16358. return this;
  16359. },
  16360. addLevel: function ( object, distance ) {
  16361. if ( distance === undefined ) distance = 0;
  16362. distance = Math.abs( distance );
  16363. const levels = this.levels;
  16364. let l;
  16365. for ( l = 0; l < levels.length; l ++ ) {
  16366. if ( distance < levels[ l ].distance ) {
  16367. break;
  16368. }
  16369. }
  16370. levels.splice( l, 0, { distance: distance, object: object } );
  16371. this.add( object );
  16372. return this;
  16373. },
  16374. getCurrentLevel: function () {
  16375. return this._currentLevel;
  16376. },
  16377. getObjectForDistance: function ( distance ) {
  16378. const levels = this.levels;
  16379. if ( levels.length > 0 ) {
  16380. let i, l;
  16381. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16382. if ( distance < levels[ i ].distance ) {
  16383. break;
  16384. }
  16385. }
  16386. return levels[ i - 1 ].object;
  16387. }
  16388. return null;
  16389. },
  16390. raycast: function ( raycaster, intersects ) {
  16391. const levels = this.levels;
  16392. if ( levels.length > 0 ) {
  16393. _v1$4.setFromMatrixPosition( this.matrixWorld );
  16394. const distance = raycaster.ray.origin.distanceTo( _v1$4 );
  16395. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  16396. }
  16397. },
  16398. update: function ( camera ) {
  16399. const levels = this.levels;
  16400. if ( levels.length > 1 ) {
  16401. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  16402. _v2$2.setFromMatrixPosition( this.matrixWorld );
  16403. const distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  16404. levels[ 0 ].object.visible = true;
  16405. let i, l;
  16406. for ( i = 1, l = levels.length; i < l; i ++ ) {
  16407. if ( distance >= levels[ i ].distance ) {
  16408. levels[ i - 1 ].object.visible = false;
  16409. levels[ i ].object.visible = true;
  16410. } else {
  16411. break;
  16412. }
  16413. }
  16414. this._currentLevel = i - 1;
  16415. for ( ; i < l; i ++ ) {
  16416. levels[ i ].object.visible = false;
  16417. }
  16418. }
  16419. },
  16420. toJSON: function ( meta ) {
  16421. const data = Object3D.prototype.toJSON.call( this, meta );
  16422. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  16423. data.object.levels = [];
  16424. const levels = this.levels;
  16425. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  16426. const level = levels[ i ];
  16427. data.object.levels.push( {
  16428. object: level.object.uuid,
  16429. distance: level.distance
  16430. } );
  16431. }
  16432. return data;
  16433. }
  16434. } );
  16435. /**
  16436. * @author mikael emtinger / http://gomo.se/
  16437. * @author alteredq / http://alteredqualia.com/
  16438. * @author ikerr / http://verold.com
  16439. */
  16440. function SkinnedMesh( geometry, material ) {
  16441. if ( geometry && geometry.isGeometry ) {
  16442. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16443. }
  16444. Mesh.call( this, geometry, material );
  16445. this.type = 'SkinnedMesh';
  16446. this.bindMode = 'attached';
  16447. this.bindMatrix = new Matrix4();
  16448. this.bindMatrixInverse = new Matrix4();
  16449. }
  16450. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16451. constructor: SkinnedMesh,
  16452. isSkinnedMesh: true,
  16453. copy: function ( source ) {
  16454. Mesh.prototype.copy.call( this, source );
  16455. this.bindMode = source.bindMode;
  16456. this.bindMatrix.copy( source.bindMatrix );
  16457. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  16458. this.skeleton = source.skeleton;
  16459. return this;
  16460. },
  16461. bind: function ( skeleton, bindMatrix ) {
  16462. this.skeleton = skeleton;
  16463. if ( bindMatrix === undefined ) {
  16464. this.updateMatrixWorld( true );
  16465. this.skeleton.calculateInverses();
  16466. bindMatrix = this.matrixWorld;
  16467. }
  16468. this.bindMatrix.copy( bindMatrix );
  16469. this.bindMatrixInverse.getInverse( bindMatrix );
  16470. },
  16471. pose: function () {
  16472. this.skeleton.pose();
  16473. },
  16474. normalizeSkinWeights: function () {
  16475. const vector = new Vector4();
  16476. const skinWeight = this.geometry.attributes.skinWeight;
  16477. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  16478. vector.x = skinWeight.getX( i );
  16479. vector.y = skinWeight.getY( i );
  16480. vector.z = skinWeight.getZ( i );
  16481. vector.w = skinWeight.getW( i );
  16482. const scale = 1.0 / vector.manhattanLength();
  16483. if ( scale !== Infinity ) {
  16484. vector.multiplyScalar( scale );
  16485. } else {
  16486. vector.set( 1, 0, 0, 0 ); // do something reasonable
  16487. }
  16488. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  16489. }
  16490. },
  16491. updateMatrixWorld: function ( force ) {
  16492. Mesh.prototype.updateMatrixWorld.call( this, force );
  16493. if ( this.bindMode === 'attached' ) {
  16494. this.bindMatrixInverse.getInverse( this.matrixWorld );
  16495. } else if ( this.bindMode === 'detached' ) {
  16496. this.bindMatrixInverse.getInverse( this.bindMatrix );
  16497. } else {
  16498. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  16499. }
  16500. },
  16501. boneTransform: ( function () {
  16502. const basePosition = new Vector3();
  16503. const skinIndex = new Vector4();
  16504. const skinWeight = new Vector4();
  16505. const vector = new Vector3();
  16506. const matrix = new Matrix4();
  16507. return function ( index, target ) {
  16508. const skeleton = this.skeleton;
  16509. const geometry = this.geometry;
  16510. skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  16511. skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  16512. basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  16513. target.set( 0, 0, 0 );
  16514. for ( let i = 0; i < 4; i ++ ) {
  16515. const weight = skinWeight.getComponent( i );
  16516. if ( weight !== 0 ) {
  16517. const boneIndex = skinIndex.getComponent( i );
  16518. matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  16519. target.addScaledVector( vector.copy( basePosition ).applyMatrix4( matrix ), weight );
  16520. }
  16521. }
  16522. return target.applyMatrix4( this.bindMatrixInverse );
  16523. };
  16524. }() )
  16525. } );
  16526. /**
  16527. * @author mikael emtinger / http://gomo.se/
  16528. * @author alteredq / http://alteredqualia.com/
  16529. * @author michael guerrero / http://realitymeltdown.com
  16530. * @author ikerr / http://verold.com
  16531. */
  16532. const _offsetMatrix = new Matrix4();
  16533. const _identityMatrix = new Matrix4();
  16534. function Skeleton( bones, boneInverses ) {
  16535. // copy the bone array
  16536. bones = bones || [];
  16537. this.bones = bones.slice( 0 );
  16538. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  16539. this.frame = - 1;
  16540. // use the supplied bone inverses or calculate the inverses
  16541. if ( boneInverses === undefined ) {
  16542. this.calculateInverses();
  16543. } else {
  16544. if ( this.bones.length === boneInverses.length ) {
  16545. this.boneInverses = boneInverses.slice( 0 );
  16546. } else {
  16547. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  16548. this.boneInverses = [];
  16549. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16550. this.boneInverses.push( new Matrix4() );
  16551. }
  16552. }
  16553. }
  16554. }
  16555. Object.assign( Skeleton.prototype, {
  16556. calculateInverses: function () {
  16557. this.boneInverses = [];
  16558. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16559. const inverse = new Matrix4();
  16560. if ( this.bones[ i ] ) {
  16561. inverse.getInverse( this.bones[ i ].matrixWorld );
  16562. }
  16563. this.boneInverses.push( inverse );
  16564. }
  16565. },
  16566. pose: function () {
  16567. // recover the bind-time world matrices
  16568. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16569. const bone = this.bones[ i ];
  16570. if ( bone ) {
  16571. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  16572. }
  16573. }
  16574. // compute the local matrices, positions, rotations and scales
  16575. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16576. const bone = this.bones[ i ];
  16577. if ( bone ) {
  16578. if ( bone.parent && bone.parent.isBone ) {
  16579. bone.matrix.getInverse( bone.parent.matrixWorld );
  16580. bone.matrix.multiply( bone.matrixWorld );
  16581. } else {
  16582. bone.matrix.copy( bone.matrixWorld );
  16583. }
  16584. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  16585. }
  16586. }
  16587. },
  16588. update: function () {
  16589. const bones = this.bones;
  16590. const boneInverses = this.boneInverses;
  16591. const boneMatrices = this.boneMatrices;
  16592. const boneTexture = this.boneTexture;
  16593. // flatten bone matrices to array
  16594. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  16595. // compute the offset between the current and the original transform
  16596. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  16597. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  16598. _offsetMatrix.toArray( boneMatrices, i * 16 );
  16599. }
  16600. if ( boneTexture !== undefined ) {
  16601. boneTexture.needsUpdate = true;
  16602. }
  16603. },
  16604. clone: function () {
  16605. return new Skeleton( this.bones, this.boneInverses );
  16606. },
  16607. getBoneByName: function ( name ) {
  16608. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  16609. const bone = this.bones[ i ];
  16610. if ( bone.name === name ) {
  16611. return bone;
  16612. }
  16613. }
  16614. return undefined;
  16615. },
  16616. dispose: function ( ) {
  16617. if ( this.boneTexture ) {
  16618. this.boneTexture.dispose();
  16619. this.boneTexture = undefined;
  16620. }
  16621. }
  16622. } );
  16623. /**
  16624. * @author mikael emtinger / http://gomo.se/
  16625. * @author alteredq / http://alteredqualia.com/
  16626. * @author ikerr / http://verold.com
  16627. */
  16628. function Bone() {
  16629. Object3D.call( this );
  16630. this.type = 'Bone';
  16631. }
  16632. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16633. constructor: Bone,
  16634. isBone: true
  16635. } );
  16636. /**
  16637. * @author mrdoob / http://mrdoob.com/
  16638. */
  16639. const _instanceLocalMatrix = new Matrix4();
  16640. const _instanceWorldMatrix = new Matrix4();
  16641. const _instanceIntersects = [];
  16642. const _mesh = new Mesh();
  16643. function InstancedMesh( geometry, material, count ) {
  16644. Mesh.call( this, geometry, material );
  16645. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  16646. this.count = count;
  16647. this.frustumCulled = false;
  16648. }
  16649. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  16650. constructor: InstancedMesh,
  16651. isInstancedMesh: true,
  16652. copy: function ( source ) {
  16653. Mesh.prototype.copy.call( this, source );
  16654. this.instanceMatrix.copy( source.instanceMatrix );
  16655. this.count = source.count;
  16656. return this;
  16657. },
  16658. getMatrixAt: function ( index, matrix ) {
  16659. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  16660. },
  16661. raycast: function ( raycaster, intersects ) {
  16662. const matrixWorld = this.matrixWorld;
  16663. const raycastTimes = this.count;
  16664. _mesh.geometry = this.geometry;
  16665. _mesh.material = this.material;
  16666. if ( _mesh.material === undefined ) return;
  16667. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  16668. // calculate the world matrix for each instance
  16669. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  16670. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  16671. // the mesh represents this single instance
  16672. _mesh.matrixWorld = _instanceWorldMatrix;
  16673. _mesh.raycast( raycaster, _instanceIntersects );
  16674. // process the result of raycast
  16675. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  16676. const intersect = _instanceIntersects[ i ];
  16677. intersect.instanceId = instanceId;
  16678. intersect.object = this;
  16679. intersects.push( intersect );
  16680. }
  16681. _instanceIntersects.length = 0;
  16682. }
  16683. },
  16684. setMatrixAt: function ( index, matrix ) {
  16685. matrix.toArray( this.instanceMatrix.array, index * 16 );
  16686. },
  16687. updateMorphTargets: function () {
  16688. }
  16689. } );
  16690. /**
  16691. * @author mrdoob / http://mrdoob.com/
  16692. * @author alteredq / http://alteredqualia.com/
  16693. *
  16694. * parameters = {
  16695. * color: <hex>,
  16696. * opacity: <float>,
  16697. *
  16698. * linewidth: <float>,
  16699. * linecap: "round",
  16700. * linejoin: "round"
  16701. * }
  16702. */
  16703. function LineBasicMaterial( parameters ) {
  16704. Material.call( this );
  16705. this.type = 'LineBasicMaterial';
  16706. this.color = new Color( 0xffffff );
  16707. this.linewidth = 1;
  16708. this.linecap = 'round';
  16709. this.linejoin = 'round';
  16710. this.morphTargets = false;
  16711. this.setValues( parameters );
  16712. }
  16713. LineBasicMaterial.prototype = Object.create( Material.prototype );
  16714. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16715. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16716. LineBasicMaterial.prototype.copy = function ( source ) {
  16717. Material.prototype.copy.call( this, source );
  16718. this.color.copy( source.color );
  16719. this.linewidth = source.linewidth;
  16720. this.linecap = source.linecap;
  16721. this.linejoin = source.linejoin;
  16722. this.morphTargets = source.morphTargets;
  16723. return this;
  16724. };
  16725. /**
  16726. * @author mrdoob / http://mrdoob.com/
  16727. */
  16728. const _start = new Vector3();
  16729. const _end = new Vector3();
  16730. const _inverseMatrix$1 = new Matrix4();
  16731. const _ray$1 = new Ray();
  16732. const _sphere$2 = new Sphere();
  16733. function Line( geometry, material, mode ) {
  16734. if ( mode === 1 ) {
  16735. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  16736. }
  16737. Object3D.call( this );
  16738. this.type = 'Line';
  16739. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16740. this.material = material !== undefined ? material : new LineBasicMaterial();
  16741. this.updateMorphTargets();
  16742. }
  16743. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16744. constructor: Line,
  16745. isLine: true,
  16746. copy: function ( source ) {
  16747. Object3D.prototype.copy.call( this, source );
  16748. this.material = source.material;
  16749. this.geometry = source.geometry;
  16750. return this;
  16751. },
  16752. computeLineDistances: function () {
  16753. const geometry = this.geometry;
  16754. if ( geometry.isBufferGeometry ) {
  16755. // we assume non-indexed geometry
  16756. if ( geometry.index === null ) {
  16757. const positionAttribute = geometry.attributes.position;
  16758. const lineDistances = [ 0 ];
  16759. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  16760. _start.fromBufferAttribute( positionAttribute, i - 1 );
  16761. _end.fromBufferAttribute( positionAttribute, i );
  16762. lineDistances[ i ] = lineDistances[ i - 1 ];
  16763. lineDistances[ i ] += _start.distanceTo( _end );
  16764. }
  16765. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16766. } else {
  16767. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16768. }
  16769. } else if ( geometry.isGeometry ) {
  16770. const vertices = geometry.vertices;
  16771. const lineDistances = geometry.lineDistances;
  16772. lineDistances[ 0 ] = 0;
  16773. for ( let i = 1, l = vertices.length; i < l; i ++ ) {
  16774. lineDistances[ i ] = lineDistances[ i - 1 ];
  16775. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  16776. }
  16777. }
  16778. return this;
  16779. },
  16780. raycast: function ( raycaster, intersects ) {
  16781. const geometry = this.geometry;
  16782. const matrixWorld = this.matrixWorld;
  16783. const threshold = raycaster.params.Line.threshold;
  16784. // Checking boundingSphere distance to ray
  16785. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16786. _sphere$2.copy( geometry.boundingSphere );
  16787. _sphere$2.applyMatrix4( matrixWorld );
  16788. _sphere$2.radius += threshold;
  16789. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  16790. //
  16791. _inverseMatrix$1.getInverse( matrixWorld );
  16792. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  16793. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16794. const localThresholdSq = localThreshold * localThreshold;
  16795. const vStart = new Vector3();
  16796. const vEnd = new Vector3();
  16797. const interSegment = new Vector3();
  16798. const interRay = new Vector3();
  16799. const step = ( this && this.isLineSegments ) ? 2 : 1;
  16800. if ( geometry.isBufferGeometry ) {
  16801. const index = geometry.index;
  16802. const attributes = geometry.attributes;
  16803. const positions = attributes.position.array;
  16804. if ( index !== null ) {
  16805. const indices = index.array;
  16806. for ( let i = 0, l = indices.length - 1; i < l; i += step ) {
  16807. const a = indices[ i ];
  16808. const b = indices[ i + 1 ];
  16809. vStart.fromArray( positions, a * 3 );
  16810. vEnd.fromArray( positions, b * 3 );
  16811. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16812. if ( distSq > localThresholdSq ) continue;
  16813. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16814. const distance = raycaster.ray.origin.distanceTo( interRay );
  16815. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16816. intersects.push( {
  16817. distance: distance,
  16818. // What do we want? intersection point on the ray or on the segment??
  16819. // point: raycaster.ray.at( distance ),
  16820. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16821. index: i,
  16822. face: null,
  16823. faceIndex: null,
  16824. object: this
  16825. } );
  16826. }
  16827. } else {
  16828. for ( let i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  16829. vStart.fromArray( positions, 3 * i );
  16830. vEnd.fromArray( positions, 3 * i + 3 );
  16831. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  16832. if ( distSq > localThresholdSq ) continue;
  16833. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16834. const distance = raycaster.ray.origin.distanceTo( interRay );
  16835. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16836. intersects.push( {
  16837. distance: distance,
  16838. // What do we want? intersection point on the ray or on the segment??
  16839. // point: raycaster.ray.at( distance ),
  16840. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16841. index: i,
  16842. face: null,
  16843. faceIndex: null,
  16844. object: this
  16845. } );
  16846. }
  16847. }
  16848. } else if ( geometry.isGeometry ) {
  16849. const vertices = geometry.vertices;
  16850. const nbVertices = vertices.length;
  16851. for ( let i = 0; i < nbVertices - 1; i += step ) {
  16852. const distSq = _ray$1.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  16853. if ( distSq > localThresholdSq ) continue;
  16854. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  16855. const distance = raycaster.ray.origin.distanceTo( interRay );
  16856. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  16857. intersects.push( {
  16858. distance: distance,
  16859. // What do we want? intersection point on the ray or on the segment??
  16860. // point: raycaster.ray.at( distance ),
  16861. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16862. index: i,
  16863. face: null,
  16864. faceIndex: null,
  16865. object: this
  16866. } );
  16867. }
  16868. }
  16869. },
  16870. updateMorphTargets: function () {
  16871. const geometry = this.geometry;
  16872. if ( geometry.isBufferGeometry ) {
  16873. const morphAttributes = geometry.morphAttributes;
  16874. const keys = Object.keys( morphAttributes );
  16875. if ( keys.length > 0 ) {
  16876. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  16877. if ( morphAttribute !== undefined ) {
  16878. this.morphTargetInfluences = [];
  16879. this.morphTargetDictionary = {};
  16880. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16881. const name = morphAttribute[ m ].name || String( m );
  16882. this.morphTargetInfluences.push( 0 );
  16883. this.morphTargetDictionary[ name ] = m;
  16884. }
  16885. }
  16886. }
  16887. } else {
  16888. const morphTargets = geometry.morphTargets;
  16889. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16890. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16891. }
  16892. }
  16893. }
  16894. } );
  16895. /**
  16896. * @author mrdoob / http://mrdoob.com/
  16897. */
  16898. const _start$1 = new Vector3();
  16899. const _end$1 = new Vector3();
  16900. function LineSegments( geometry, material ) {
  16901. Line.call( this, geometry, material );
  16902. this.type = 'LineSegments';
  16903. }
  16904. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16905. constructor: LineSegments,
  16906. isLineSegments: true,
  16907. computeLineDistances: function () {
  16908. const geometry = this.geometry;
  16909. if ( geometry.isBufferGeometry ) {
  16910. // we assume non-indexed geometry
  16911. if ( geometry.index === null ) {
  16912. const positionAttribute = geometry.attributes.position;
  16913. const lineDistances = [];
  16914. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16915. _start$1.fromBufferAttribute( positionAttribute, i );
  16916. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16917. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16918. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16919. }
  16920. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16921. } else {
  16922. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16923. }
  16924. } else if ( geometry.isGeometry ) {
  16925. const vertices = geometry.vertices;
  16926. const lineDistances = geometry.lineDistances;
  16927. for ( let i = 0, l = vertices.length; i < l; i += 2 ) {
  16928. _start$1.copy( vertices[ i ] );
  16929. _end$1.copy( vertices[ i + 1 ] );
  16930. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16931. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16932. }
  16933. }
  16934. return this;
  16935. }
  16936. } );
  16937. /**
  16938. * @author mgreter / http://github.com/mgreter
  16939. */
  16940. function LineLoop( geometry, material ) {
  16941. Line.call( this, geometry, material );
  16942. this.type = 'LineLoop';
  16943. }
  16944. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16945. constructor: LineLoop,
  16946. isLineLoop: true,
  16947. } );
  16948. /**
  16949. * @author mrdoob / http://mrdoob.com/
  16950. * @author alteredq / http://alteredqualia.com/
  16951. *
  16952. * parameters = {
  16953. * color: <hex>,
  16954. * opacity: <float>,
  16955. * map: new THREE.Texture( <Image> ),
  16956. * alphaMap: new THREE.Texture( <Image> ),
  16957. *
  16958. * size: <float>,
  16959. * sizeAttenuation: <bool>
  16960. *
  16961. * morphTargets: <bool>
  16962. * }
  16963. */
  16964. function PointsMaterial( parameters ) {
  16965. Material.call( this );
  16966. this.type = 'PointsMaterial';
  16967. this.color = new Color( 0xffffff );
  16968. this.map = null;
  16969. this.alphaMap = null;
  16970. this.size = 1;
  16971. this.sizeAttenuation = true;
  16972. this.morphTargets = false;
  16973. this.setValues( parameters );
  16974. }
  16975. PointsMaterial.prototype = Object.create( Material.prototype );
  16976. PointsMaterial.prototype.constructor = PointsMaterial;
  16977. PointsMaterial.prototype.isPointsMaterial = true;
  16978. PointsMaterial.prototype.copy = function ( source ) {
  16979. Material.prototype.copy.call( this, source );
  16980. this.color.copy( source.color );
  16981. this.map = source.map;
  16982. this.alphaMap = source.alphaMap;
  16983. this.size = source.size;
  16984. this.sizeAttenuation = source.sizeAttenuation;
  16985. this.morphTargets = source.morphTargets;
  16986. return this;
  16987. };
  16988. /**
  16989. * @author alteredq / http://alteredqualia.com/
  16990. */
  16991. const _inverseMatrix$2 = new Matrix4();
  16992. const _ray$2 = new Ray();
  16993. const _sphere$3 = new Sphere();
  16994. const _position$1 = new Vector3();
  16995. function Points( geometry, material ) {
  16996. Object3D.call( this );
  16997. this.type = 'Points';
  16998. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16999. this.material = material !== undefined ? material : new PointsMaterial();
  17000. this.updateMorphTargets();
  17001. }
  17002. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  17003. constructor: Points,
  17004. isPoints: true,
  17005. copy: function ( source ) {
  17006. Object3D.prototype.copy.call( this, source );
  17007. this.material = source.material;
  17008. this.geometry = source.geometry;
  17009. return this;
  17010. },
  17011. raycast: function ( raycaster, intersects ) {
  17012. const geometry = this.geometry;
  17013. const matrixWorld = this.matrixWorld;
  17014. const threshold = raycaster.params.Points.threshold;
  17015. // Checking boundingSphere distance to ray
  17016. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  17017. _sphere$3.copy( geometry.boundingSphere );
  17018. _sphere$3.applyMatrix4( matrixWorld );
  17019. _sphere$3.radius += threshold;
  17020. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  17021. //
  17022. _inverseMatrix$2.getInverse( matrixWorld );
  17023. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  17024. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  17025. const localThresholdSq = localThreshold * localThreshold;
  17026. if ( geometry.isBufferGeometry ) {
  17027. const index = geometry.index;
  17028. const attributes = geometry.attributes;
  17029. const positions = attributes.position.array;
  17030. if ( index !== null ) {
  17031. const indices = index.array;
  17032. for ( let i = 0, il = indices.length; i < il; i ++ ) {
  17033. const a = indices[ i ];
  17034. _position$1.fromArray( positions, a * 3 );
  17035. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17036. }
  17037. } else {
  17038. for ( let i = 0, l = positions.length / 3; i < l; i ++ ) {
  17039. _position$1.fromArray( positions, i * 3 );
  17040. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17041. }
  17042. }
  17043. } else {
  17044. const vertices = geometry.vertices;
  17045. for ( let i = 0, l = vertices.length; i < l; i ++ ) {
  17046. testPoint( vertices[ i ], i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  17047. }
  17048. }
  17049. },
  17050. updateMorphTargets: function () {
  17051. const geometry = this.geometry;
  17052. if ( geometry.isBufferGeometry ) {
  17053. const morphAttributes = geometry.morphAttributes;
  17054. const keys = Object.keys( morphAttributes );
  17055. if ( keys.length > 0 ) {
  17056. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  17057. if ( morphAttribute !== undefined ) {
  17058. this.morphTargetInfluences = [];
  17059. this.morphTargetDictionary = {};
  17060. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  17061. const name = morphAttribute[ m ].name || String( m );
  17062. this.morphTargetInfluences.push( 0 );
  17063. this.morphTargetDictionary[ name ] = m;
  17064. }
  17065. }
  17066. }
  17067. } else {
  17068. const morphTargets = geometry.morphTargets;
  17069. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  17070. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  17071. }
  17072. }
  17073. }
  17074. } );
  17075. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  17076. const rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  17077. if ( rayPointDistanceSq < localThresholdSq ) {
  17078. const intersectPoint = new Vector3();
  17079. _ray$2.closestPointToPoint( point, intersectPoint );
  17080. intersectPoint.applyMatrix4( matrixWorld );
  17081. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  17082. if ( distance < raycaster.near || distance > raycaster.far ) return;
  17083. intersects.push( {
  17084. distance: distance,
  17085. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  17086. point: intersectPoint,
  17087. index: index,
  17088. face: null,
  17089. object: object
  17090. } );
  17091. }
  17092. }
  17093. /**
  17094. * @author mrdoob / http://mrdoob.com/
  17095. */
  17096. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17097. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17098. this.format = format !== undefined ? format : RGBFormat;
  17099. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17100. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17101. this.generateMipmaps = false;
  17102. }
  17103. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  17104. constructor: VideoTexture,
  17105. isVideoTexture: true,
  17106. update: function () {
  17107. const video = this.image;
  17108. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  17109. this.needsUpdate = true;
  17110. }
  17111. }
  17112. } );
  17113. /**
  17114. * @author alteredq / http://alteredqualia.com/
  17115. */
  17116. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  17117. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  17118. this.image = { width: width, height: height };
  17119. this.mipmaps = mipmaps;
  17120. // no flipping for cube textures
  17121. // (also flipping doesn't work for compressed textures )
  17122. this.flipY = false;
  17123. // can't generate mipmaps for compressed textures
  17124. // mips must be embedded in DDS files
  17125. this.generateMipmaps = false;
  17126. }
  17127. CompressedTexture.prototype = Object.create( Texture.prototype );
  17128. CompressedTexture.prototype.constructor = CompressedTexture;
  17129. CompressedTexture.prototype.isCompressedTexture = true;
  17130. /**
  17131. * @author mrdoob / http://mrdoob.com/
  17132. */
  17133. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  17134. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17135. this.needsUpdate = true;
  17136. }
  17137. CanvasTexture.prototype = Object.create( Texture.prototype );
  17138. CanvasTexture.prototype.constructor = CanvasTexture;
  17139. CanvasTexture.prototype.isCanvasTexture = true;
  17140. /**
  17141. * @author Matt DesLauriers / @mattdesl
  17142. * @author atix / arthursilber.de
  17143. */
  17144. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  17145. format = format !== undefined ? format : DepthFormat;
  17146. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  17147. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  17148. }
  17149. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  17150. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  17151. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  17152. this.image = { width: width, height: height };
  17153. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17154. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17155. this.flipY = false;
  17156. this.generateMipmaps = false;
  17157. }
  17158. DepthTexture.prototype = Object.create( Texture.prototype );
  17159. DepthTexture.prototype.constructor = DepthTexture;
  17160. DepthTexture.prototype.isDepthTexture = true;
  17161. /**
  17162. * @author mrdoob / http://mrdoob.com/
  17163. * @author Mugen87 / https://github.com/Mugen87
  17164. */
  17165. function WireframeGeometry( geometry ) {
  17166. BufferGeometry.call( this );
  17167. this.type = 'WireframeGeometry';
  17168. // buffer
  17169. const vertices = [];
  17170. // helper variables
  17171. const edge = [ 0, 0 ], edges = {};
  17172. const keys = [ 'a', 'b', 'c' ];
  17173. // different logic for Geometry and BufferGeometry
  17174. if ( geometry && geometry.isGeometry ) {
  17175. // create a data structure that contains all edges without duplicates
  17176. const faces = geometry.faces;
  17177. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  17178. const face = faces[ i ];
  17179. for ( let j = 0; j < 3; j ++ ) {
  17180. const edge1 = face[ keys[ j ] ];
  17181. const edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  17182. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  17183. edge[ 1 ] = Math.max( edge1, edge2 );
  17184. const key = edge[ 0 ] + ',' + edge[ 1 ];
  17185. if ( edges[ key ] === undefined ) {
  17186. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17187. }
  17188. }
  17189. }
  17190. // generate vertices
  17191. for ( const key in edges ) {
  17192. const e = edges[ key ];
  17193. let vertex = geometry.vertices[ e.index1 ];
  17194. vertices.push( vertex.x, vertex.y, vertex.z );
  17195. vertex = geometry.vertices[ e.index2 ];
  17196. vertices.push( vertex.x, vertex.y, vertex.z );
  17197. }
  17198. } else if ( geometry && geometry.isBufferGeometry ) {
  17199. let vertex = new Vector3();
  17200. if ( geometry.index !== null ) {
  17201. // indexed BufferGeometry
  17202. const position = geometry.attributes.position;
  17203. const indices = geometry.index;
  17204. let groups = geometry.groups;
  17205. if ( groups.length === 0 ) {
  17206. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  17207. }
  17208. // create a data structure that contains all eges without duplicates
  17209. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  17210. const group = groups[ o ];
  17211. const start = group.start;
  17212. const count = group.count;
  17213. for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
  17214. for ( let j = 0; j < 3; j ++ ) {
  17215. const edge1 = indices.getX( i + j );
  17216. const edge2 = indices.getX( i + ( j + 1 ) % 3 );
  17217. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  17218. edge[ 1 ] = Math.max( edge1, edge2 );
  17219. const key = edge[ 0 ] + ',' + edge[ 1 ];
  17220. if ( edges[ key ] === undefined ) {
  17221. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  17222. }
  17223. }
  17224. }
  17225. }
  17226. // generate vertices
  17227. for ( const key in edges ) {
  17228. const e = edges[ key ];
  17229. vertex.fromBufferAttribute( position, e.index1 );
  17230. vertices.push( vertex.x, vertex.y, vertex.z );
  17231. vertex.fromBufferAttribute( position, e.index2 );
  17232. vertices.push( vertex.x, vertex.y, vertex.z );
  17233. }
  17234. } else {
  17235. // non-indexed BufferGeometry
  17236. const position = geometry.attributes.position;
  17237. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  17238. for ( let j = 0; j < 3; j ++ ) {
  17239. // three edges per triangle, an edge is represented as (index1, index2)
  17240. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  17241. const index1 = 3 * i + j;
  17242. vertex.fromBufferAttribute( position, index1 );
  17243. vertices.push( vertex.x, vertex.y, vertex.z );
  17244. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  17245. vertex.fromBufferAttribute( position, index2 );
  17246. vertices.push( vertex.x, vertex.y, vertex.z );
  17247. }
  17248. }
  17249. }
  17250. }
  17251. // build geometry
  17252. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17253. }
  17254. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  17255. WireframeGeometry.prototype.constructor = WireframeGeometry;
  17256. /**
  17257. * @author zz85 / https://github.com/zz85
  17258. * @author Mugen87 / https://github.com/Mugen87
  17259. *
  17260. * Parametric Surfaces Geometry
  17261. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  17262. */
  17263. // ParametricGeometry
  17264. function ParametricGeometry( func, slices, stacks ) {
  17265. Geometry.call( this );
  17266. this.type = 'ParametricGeometry';
  17267. this.parameters = {
  17268. func: func,
  17269. slices: slices,
  17270. stacks: stacks
  17271. };
  17272. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  17273. this.mergeVertices();
  17274. }
  17275. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  17276. ParametricGeometry.prototype.constructor = ParametricGeometry;
  17277. // ParametricBufferGeometry
  17278. function ParametricBufferGeometry( func, slices, stacks ) {
  17279. BufferGeometry.call( this );
  17280. this.type = 'ParametricBufferGeometry';
  17281. this.parameters = {
  17282. func: func,
  17283. slices: slices,
  17284. stacks: stacks
  17285. };
  17286. // buffers
  17287. const indices = [];
  17288. const vertices = [];
  17289. const normals = [];
  17290. const uvs = [];
  17291. const EPS = 0.00001;
  17292. const normal = new Vector3();
  17293. const p0 = new Vector3(), p1 = new Vector3();
  17294. const pu = new Vector3(), pv = new Vector3();
  17295. if ( func.length < 3 ) {
  17296. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  17297. }
  17298. // generate vertices, normals and uvs
  17299. const sliceCount = slices + 1;
  17300. for ( let i = 0; i <= stacks; i ++ ) {
  17301. const v = i / stacks;
  17302. for ( let j = 0; j <= slices; j ++ ) {
  17303. const u = j / slices;
  17304. // vertex
  17305. func( u, v, p0 );
  17306. vertices.push( p0.x, p0.y, p0.z );
  17307. // normal
  17308. // approximate tangent vectors via finite differences
  17309. if ( u - EPS >= 0 ) {
  17310. func( u - EPS, v, p1 );
  17311. pu.subVectors( p0, p1 );
  17312. } else {
  17313. func( u + EPS, v, p1 );
  17314. pu.subVectors( p1, p0 );
  17315. }
  17316. if ( v - EPS >= 0 ) {
  17317. func( u, v - EPS, p1 );
  17318. pv.subVectors( p0, p1 );
  17319. } else {
  17320. func( u, v + EPS, p1 );
  17321. pv.subVectors( p1, p0 );
  17322. }
  17323. // cross product of tangent vectors returns surface normal
  17324. normal.crossVectors( pu, pv ).normalize();
  17325. normals.push( normal.x, normal.y, normal.z );
  17326. // uv
  17327. uvs.push( u, v );
  17328. }
  17329. }
  17330. // generate indices
  17331. for ( let i = 0; i < stacks; i ++ ) {
  17332. for ( let j = 0; j < slices; j ++ ) {
  17333. const a = i * sliceCount + j;
  17334. const b = i * sliceCount + j + 1;
  17335. const c = ( i + 1 ) * sliceCount + j + 1;
  17336. const d = ( i + 1 ) * sliceCount + j;
  17337. // faces one and two
  17338. indices.push( a, b, d );
  17339. indices.push( b, c, d );
  17340. }
  17341. }
  17342. // build geometry
  17343. this.setIndex( indices );
  17344. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17345. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17346. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17347. }
  17348. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17349. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  17350. /**
  17351. * @author clockworkgeek / https://github.com/clockworkgeek
  17352. * @author timothypratley / https://github.com/timothypratley
  17353. * @author WestLangley / http://github.com/WestLangley
  17354. * @author Mugen87 / https://github.com/Mugen87
  17355. */
  17356. // PolyhedronGeometry
  17357. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  17358. Geometry.call( this );
  17359. this.type = 'PolyhedronGeometry';
  17360. this.parameters = {
  17361. vertices: vertices,
  17362. indices: indices,
  17363. radius: radius,
  17364. detail: detail
  17365. };
  17366. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  17367. this.mergeVertices();
  17368. }
  17369. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  17370. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  17371. // PolyhedronBufferGeometry
  17372. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  17373. BufferGeometry.call( this );
  17374. this.type = 'PolyhedronBufferGeometry';
  17375. this.parameters = {
  17376. vertices: vertices,
  17377. indices: indices,
  17378. radius: radius,
  17379. detail: detail
  17380. };
  17381. radius = radius || 1;
  17382. detail = detail || 0;
  17383. // default buffer data
  17384. const vertexBuffer = [];
  17385. const uvBuffer = [];
  17386. // the subdivision creates the vertex buffer data
  17387. subdivide( detail );
  17388. // all vertices should lie on a conceptual sphere with a given radius
  17389. applyRadius( radius );
  17390. // finally, create the uv data
  17391. generateUVs();
  17392. // build non-indexed geometry
  17393. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17394. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17395. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17396. if ( detail === 0 ) {
  17397. this.computeVertexNormals(); // flat normals
  17398. } else {
  17399. this.normalizeNormals(); // smooth normals
  17400. }
  17401. // helper functions
  17402. function subdivide( detail ) {
  17403. const a = new Vector3();
  17404. const b = new Vector3();
  17405. const c = new Vector3();
  17406. // iterate over all faces and apply a subdivison with the given detail value
  17407. for ( let i = 0; i < indices.length; i += 3 ) {
  17408. // get the vertices of the face
  17409. getVertexByIndex( indices[ i + 0 ], a );
  17410. getVertexByIndex( indices[ i + 1 ], b );
  17411. getVertexByIndex( indices[ i + 2 ], c );
  17412. // perform subdivision
  17413. subdivideFace( a, b, c, detail );
  17414. }
  17415. }
  17416. function subdivideFace( a, b, c, detail ) {
  17417. const cols = Math.pow( 2, detail );
  17418. // we use this multidimensional array as a data structure for creating the subdivision
  17419. const v = [];
  17420. // construct all of the vertices for this subdivision
  17421. for ( let i = 0; i <= cols; i ++ ) {
  17422. v[ i ] = [];
  17423. const aj = a.clone().lerp( c, i / cols );
  17424. const bj = b.clone().lerp( c, i / cols );
  17425. const rows = cols - i;
  17426. for ( let j = 0; j <= rows; j ++ ) {
  17427. if ( j === 0 && i === cols ) {
  17428. v[ i ][ j ] = aj;
  17429. } else {
  17430. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17431. }
  17432. }
  17433. }
  17434. // construct all of the faces
  17435. for ( let i = 0; i < cols; i ++ ) {
  17436. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  17437. const k = Math.floor( j / 2 );
  17438. if ( j % 2 === 0 ) {
  17439. pushVertex( v[ i ][ k + 1 ] );
  17440. pushVertex( v[ i + 1 ][ k ] );
  17441. pushVertex( v[ i ][ k ] );
  17442. } else {
  17443. pushVertex( v[ i ][ k + 1 ] );
  17444. pushVertex( v[ i + 1 ][ k + 1 ] );
  17445. pushVertex( v[ i + 1 ][ k ] );
  17446. }
  17447. }
  17448. }
  17449. }
  17450. function applyRadius( radius ) {
  17451. const vertex = new Vector3();
  17452. // iterate over the entire buffer and apply the radius to each vertex
  17453. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17454. vertex.x = vertexBuffer[ i + 0 ];
  17455. vertex.y = vertexBuffer[ i + 1 ];
  17456. vertex.z = vertexBuffer[ i + 2 ];
  17457. vertex.normalize().multiplyScalar( radius );
  17458. vertexBuffer[ i + 0 ] = vertex.x;
  17459. vertexBuffer[ i + 1 ] = vertex.y;
  17460. vertexBuffer[ i + 2 ] = vertex.z;
  17461. }
  17462. }
  17463. function generateUVs() {
  17464. const vertex = new Vector3();
  17465. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17466. vertex.x = vertexBuffer[ i + 0 ];
  17467. vertex.y = vertexBuffer[ i + 1 ];
  17468. vertex.z = vertexBuffer[ i + 2 ];
  17469. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17470. const v = inclination( vertex ) / Math.PI + 0.5;
  17471. uvBuffer.push( u, 1 - v );
  17472. }
  17473. correctUVs();
  17474. correctSeam();
  17475. }
  17476. function correctSeam() {
  17477. // handle case when face straddles the seam, see #3269
  17478. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  17479. // uv data of a single face
  17480. const x0 = uvBuffer[ i + 0 ];
  17481. const x1 = uvBuffer[ i + 2 ];
  17482. const x2 = uvBuffer[ i + 4 ];
  17483. const max = Math.max( x0, x1, x2 );
  17484. const min = Math.min( x0, x1, x2 );
  17485. // 0.9 is somewhat arbitrary
  17486. if ( max > 0.9 && min < 0.1 ) {
  17487. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17488. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17489. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17490. }
  17491. }
  17492. }
  17493. function pushVertex( vertex ) {
  17494. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17495. }
  17496. function getVertexByIndex( index, vertex ) {
  17497. const stride = index * 3;
  17498. vertex.x = vertices[ stride + 0 ];
  17499. vertex.y = vertices[ stride + 1 ];
  17500. vertex.z = vertices[ stride + 2 ];
  17501. }
  17502. function correctUVs() {
  17503. const a = new Vector3();
  17504. const b = new Vector3();
  17505. const c = new Vector3();
  17506. const centroid = new Vector3();
  17507. const uvA = new Vector2();
  17508. const uvB = new Vector2();
  17509. const uvC = new Vector2();
  17510. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17511. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17512. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17513. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17514. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17515. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17516. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17517. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17518. const azi = azimuth( centroid );
  17519. correctUV( uvA, j + 0, a, azi );
  17520. correctUV( uvB, j + 2, b, azi );
  17521. correctUV( uvC, j + 4, c, azi );
  17522. }
  17523. }
  17524. function correctUV( uv, stride, vector, azimuth ) {
  17525. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17526. uvBuffer[ stride ] = uv.x - 1;
  17527. }
  17528. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17529. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17530. }
  17531. }
  17532. // Angle around the Y axis, counter-clockwise when looking from above.
  17533. function azimuth( vector ) {
  17534. return Math.atan2( vector.z, - vector.x );
  17535. }
  17536. // Angle above the XZ plane.
  17537. function inclination( vector ) {
  17538. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17539. }
  17540. }
  17541. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17542. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  17543. /**
  17544. * @author timothypratley / https://github.com/timothypratley
  17545. * @author Mugen87 / https://github.com/Mugen87
  17546. */
  17547. // TetrahedronGeometry
  17548. function TetrahedronGeometry( radius, detail ) {
  17549. Geometry.call( this );
  17550. this.type = 'TetrahedronGeometry';
  17551. this.parameters = {
  17552. radius: radius,
  17553. detail: detail
  17554. };
  17555. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  17556. this.mergeVertices();
  17557. }
  17558. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  17559. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  17560. // TetrahedronBufferGeometry
  17561. function TetrahedronBufferGeometry( radius, detail ) {
  17562. const vertices = [
  17563. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  17564. ];
  17565. const indices = [
  17566. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  17567. ];
  17568. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17569. this.type = 'TetrahedronBufferGeometry';
  17570. this.parameters = {
  17571. radius: radius,
  17572. detail: detail
  17573. };
  17574. }
  17575. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17576. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  17577. /**
  17578. * @author timothypratley / https://github.com/timothypratley
  17579. * @author Mugen87 / https://github.com/Mugen87
  17580. */
  17581. // OctahedronGeometry
  17582. function OctahedronGeometry( radius, detail ) {
  17583. Geometry.call( this );
  17584. this.type = 'OctahedronGeometry';
  17585. this.parameters = {
  17586. radius: radius,
  17587. detail: detail
  17588. };
  17589. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  17590. this.mergeVertices();
  17591. }
  17592. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  17593. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  17594. // OctahedronBufferGeometry
  17595. function OctahedronBufferGeometry( radius, detail ) {
  17596. const vertices = [
  17597. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  17598. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  17599. ];
  17600. const indices = [
  17601. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  17602. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  17603. 1, 3, 4, 1, 4, 2
  17604. ];
  17605. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17606. this.type = 'OctahedronBufferGeometry';
  17607. this.parameters = {
  17608. radius: radius,
  17609. detail: detail
  17610. };
  17611. }
  17612. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17613. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  17614. /**
  17615. * @author timothypratley / https://github.com/timothypratley
  17616. * @author Mugen87 / https://github.com/Mugen87
  17617. */
  17618. // IcosahedronGeometry
  17619. function IcosahedronGeometry( radius, detail ) {
  17620. Geometry.call( this );
  17621. this.type = 'IcosahedronGeometry';
  17622. this.parameters = {
  17623. radius: radius,
  17624. detail: detail
  17625. };
  17626. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  17627. this.mergeVertices();
  17628. }
  17629. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  17630. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  17631. // IcosahedronBufferGeometry
  17632. function IcosahedronBufferGeometry( radius, detail ) {
  17633. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17634. const vertices = [
  17635. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  17636. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  17637. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  17638. ];
  17639. const indices = [
  17640. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  17641. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  17642. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  17643. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  17644. ];
  17645. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17646. this.type = 'IcosahedronBufferGeometry';
  17647. this.parameters = {
  17648. radius: radius,
  17649. detail: detail
  17650. };
  17651. }
  17652. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17653. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  17654. /**
  17655. * @author Abe Pazos / https://hamoid.com
  17656. * @author Mugen87 / https://github.com/Mugen87
  17657. */
  17658. // DodecahedronGeometry
  17659. function DodecahedronGeometry( radius, detail ) {
  17660. Geometry.call( this );
  17661. this.type = 'DodecahedronGeometry';
  17662. this.parameters = {
  17663. radius: radius,
  17664. detail: detail
  17665. };
  17666. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17667. this.mergeVertices();
  17668. }
  17669. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  17670. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  17671. // DodecahedronBufferGeometry
  17672. function DodecahedronBufferGeometry( radius, detail ) {
  17673. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17674. const r = 1 / t;
  17675. const vertices = [
  17676. // (±1, ±1, ±1)
  17677. - 1, - 1, - 1, - 1, - 1, 1,
  17678. - 1, 1, - 1, - 1, 1, 1,
  17679. 1, - 1, - 1, 1, - 1, 1,
  17680. 1, 1, - 1, 1, 1, 1,
  17681. // (0, ±1/φ, ±φ)
  17682. 0, - r, - t, 0, - r, t,
  17683. 0, r, - t, 0, r, t,
  17684. // (±1/φ, ±φ, 0)
  17685. - r, - t, 0, - r, t, 0,
  17686. r, - t, 0, r, t, 0,
  17687. // (±φ, 0, ±1/φ)
  17688. - t, 0, - r, t, 0, - r,
  17689. - t, 0, r, t, 0, r
  17690. ];
  17691. const indices = [
  17692. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17693. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17694. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17695. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17696. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17697. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17698. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17699. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17700. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17701. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17702. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17703. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17704. ];
  17705. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  17706. this.type = 'DodecahedronBufferGeometry';
  17707. this.parameters = {
  17708. radius: radius,
  17709. detail: detail
  17710. };
  17711. }
  17712. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  17713. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  17714. /**
  17715. * @author oosmoxiecode / https://github.com/oosmoxiecode
  17716. * @author WestLangley / https://github.com/WestLangley
  17717. * @author zz85 / https://github.com/zz85
  17718. * @author miningold / https://github.com/miningold
  17719. * @author jonobr1 / https://github.com/jonobr1
  17720. * @author Mugen87 / https://github.com/Mugen87
  17721. *
  17722. */
  17723. // TubeGeometry
  17724. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  17725. Geometry.call( this );
  17726. this.type = 'TubeGeometry';
  17727. this.parameters = {
  17728. path: path,
  17729. tubularSegments: tubularSegments,
  17730. radius: radius,
  17731. radialSegments: radialSegments,
  17732. closed: closed
  17733. };
  17734. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  17735. const bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  17736. // expose internals
  17737. this.tangents = bufferGeometry.tangents;
  17738. this.normals = bufferGeometry.normals;
  17739. this.binormals = bufferGeometry.binormals;
  17740. // create geometry
  17741. this.fromBufferGeometry( bufferGeometry );
  17742. this.mergeVertices();
  17743. }
  17744. TubeGeometry.prototype = Object.create( Geometry.prototype );
  17745. TubeGeometry.prototype.constructor = TubeGeometry;
  17746. // TubeBufferGeometry
  17747. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  17748. BufferGeometry.call( this );
  17749. this.type = 'TubeBufferGeometry';
  17750. this.parameters = {
  17751. path: path,
  17752. tubularSegments: tubularSegments,
  17753. radius: radius,
  17754. radialSegments: radialSegments,
  17755. closed: closed
  17756. };
  17757. tubularSegments = tubularSegments || 64;
  17758. radius = radius || 1;
  17759. radialSegments = radialSegments || 8;
  17760. closed = closed || false;
  17761. const frames = path.computeFrenetFrames( tubularSegments, closed );
  17762. // expose internals
  17763. this.tangents = frames.tangents;
  17764. this.normals = frames.normals;
  17765. this.binormals = frames.binormals;
  17766. // helper variables
  17767. const vertex = new Vector3();
  17768. const normal = new Vector3();
  17769. const uv = new Vector2();
  17770. let P = new Vector3();
  17771. // buffer
  17772. const vertices = [];
  17773. const normals = [];
  17774. const uvs = [];
  17775. const indices = [];
  17776. // create buffer data
  17777. generateBufferData();
  17778. // build geometry
  17779. this.setIndex( indices );
  17780. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17781. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17782. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17783. // functions
  17784. function generateBufferData() {
  17785. for ( let i = 0; i < tubularSegments; i ++ ) {
  17786. generateSegment( i );
  17787. }
  17788. // if the geometry is not closed, generate the last row of vertices and normals
  17789. // at the regular position on the given path
  17790. //
  17791. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  17792. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  17793. // uvs are generated in a separate function.
  17794. // this makes it easy compute correct values for closed geometries
  17795. generateUVs();
  17796. // finally create faces
  17797. generateIndices();
  17798. }
  17799. function generateSegment( i ) {
  17800. // we use getPointAt to sample evenly distributed points from the given path
  17801. P = path.getPointAt( i / tubularSegments, P );
  17802. // retrieve corresponding normal and binormal
  17803. const N = frames.normals[ i ];
  17804. const B = frames.binormals[ i ];
  17805. // generate normals and vertices for the current segment
  17806. for ( let j = 0; j <= radialSegments; j ++ ) {
  17807. const v = j / radialSegments * Math.PI * 2;
  17808. const sin = Math.sin( v );
  17809. const cos = - Math.cos( v );
  17810. // normal
  17811. normal.x = ( cos * N.x + sin * B.x );
  17812. normal.y = ( cos * N.y + sin * B.y );
  17813. normal.z = ( cos * N.z + sin * B.z );
  17814. normal.normalize();
  17815. normals.push( normal.x, normal.y, normal.z );
  17816. // vertex
  17817. vertex.x = P.x + radius * normal.x;
  17818. vertex.y = P.y + radius * normal.y;
  17819. vertex.z = P.z + radius * normal.z;
  17820. vertices.push( vertex.x, vertex.y, vertex.z );
  17821. }
  17822. }
  17823. function generateIndices() {
  17824. for ( let j = 1; j <= tubularSegments; j ++ ) {
  17825. for ( let i = 1; i <= radialSegments; i ++ ) {
  17826. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17827. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  17828. const c = ( radialSegments + 1 ) * j + i;
  17829. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17830. // faces
  17831. indices.push( a, b, d );
  17832. indices.push( b, c, d );
  17833. }
  17834. }
  17835. }
  17836. function generateUVs() {
  17837. for ( let i = 0; i <= tubularSegments; i ++ ) {
  17838. for ( let j = 0; j <= radialSegments; j ++ ) {
  17839. uv.x = i / tubularSegments;
  17840. uv.y = j / radialSegments;
  17841. uvs.push( uv.x, uv.y );
  17842. }
  17843. }
  17844. }
  17845. }
  17846. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17847. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  17848. TubeBufferGeometry.prototype.toJSON = function () {
  17849. const data = BufferGeometry.prototype.toJSON.call( this );
  17850. data.path = this.parameters.path.toJSON();
  17851. return data;
  17852. };
  17853. /**
  17854. * @author oosmoxiecode
  17855. * @author Mugen87 / https://github.com/Mugen87
  17856. *
  17857. * based on http://www.blackpawn.com/texts/pqtorus/
  17858. */
  17859. // TorusKnotGeometry
  17860. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  17861. Geometry.call( this );
  17862. this.type = 'TorusKnotGeometry';
  17863. this.parameters = {
  17864. radius: radius,
  17865. tube: tube,
  17866. tubularSegments: tubularSegments,
  17867. radialSegments: radialSegments,
  17868. p: p,
  17869. q: q
  17870. };
  17871. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  17872. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  17873. this.mergeVertices();
  17874. }
  17875. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  17876. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  17877. // TorusKnotBufferGeometry
  17878. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  17879. BufferGeometry.call( this );
  17880. this.type = 'TorusKnotBufferGeometry';
  17881. this.parameters = {
  17882. radius: radius,
  17883. tube: tube,
  17884. tubularSegments: tubularSegments,
  17885. radialSegments: radialSegments,
  17886. p: p,
  17887. q: q
  17888. };
  17889. radius = radius || 1;
  17890. tube = tube || 0.4;
  17891. tubularSegments = Math.floor( tubularSegments ) || 64;
  17892. radialSegments = Math.floor( radialSegments ) || 8;
  17893. p = p || 2;
  17894. q = q || 3;
  17895. // buffers
  17896. const indices = [];
  17897. const vertices = [];
  17898. const normals = [];
  17899. const uvs = [];
  17900. // helper variables
  17901. const vertex = new Vector3();
  17902. const normal = new Vector3();
  17903. const P1 = new Vector3();
  17904. const P2 = new Vector3();
  17905. const B = new Vector3();
  17906. const T = new Vector3();
  17907. const N = new Vector3();
  17908. // generate vertices, normals and uvs
  17909. for ( let i = 0; i <= tubularSegments; ++ i ) {
  17910. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17911. const u = i / tubularSegments * p * Math.PI * 2;
  17912. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17913. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17914. calculatePositionOnCurve( u, p, q, radius, P1 );
  17915. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17916. // calculate orthonormal basis
  17917. T.subVectors( P2, P1 );
  17918. N.addVectors( P2, P1 );
  17919. B.crossVectors( T, N );
  17920. N.crossVectors( B, T );
  17921. // normalize B, N. T can be ignored, we don't use it
  17922. B.normalize();
  17923. N.normalize();
  17924. for ( let j = 0; j <= radialSegments; ++ j ) {
  17925. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17926. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17927. const v = j / radialSegments * Math.PI * 2;
  17928. const cx = - tube * Math.cos( v );
  17929. const cy = tube * Math.sin( v );
  17930. // now calculate the final vertex position.
  17931. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17932. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17933. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17934. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17935. vertices.push( vertex.x, vertex.y, vertex.z );
  17936. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17937. normal.subVectors( vertex, P1 ).normalize();
  17938. normals.push( normal.x, normal.y, normal.z );
  17939. // uv
  17940. uvs.push( i / tubularSegments );
  17941. uvs.push( j / radialSegments );
  17942. }
  17943. }
  17944. // generate indices
  17945. for ( let j = 1; j <= tubularSegments; j ++ ) {
  17946. for ( let i = 1; i <= radialSegments; i ++ ) {
  17947. // indices
  17948. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17949. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  17950. const c = ( radialSegments + 1 ) * j + i;
  17951. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17952. // faces
  17953. indices.push( a, b, d );
  17954. indices.push( b, c, d );
  17955. }
  17956. }
  17957. // build geometry
  17958. this.setIndex( indices );
  17959. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17960. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17961. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17962. // this function calculates the current position on the torus curve
  17963. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17964. const cu = Math.cos( u );
  17965. const su = Math.sin( u );
  17966. const quOverP = q / p * u;
  17967. const cs = Math.cos( quOverP );
  17968. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17969. position.y = radius * ( 2 + cs ) * su * 0.5;
  17970. position.z = radius * Math.sin( quOverP ) * 0.5;
  17971. }
  17972. }
  17973. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17974. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17975. /**
  17976. * @author oosmoxiecode
  17977. * @author mrdoob / http://mrdoob.com/
  17978. * @author Mugen87 / https://github.com/Mugen87
  17979. */
  17980. // TorusGeometry
  17981. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17982. Geometry.call( this );
  17983. this.type = 'TorusGeometry';
  17984. this.parameters = {
  17985. radius: radius,
  17986. tube: tube,
  17987. radialSegments: radialSegments,
  17988. tubularSegments: tubularSegments,
  17989. arc: arc
  17990. };
  17991. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17992. this.mergeVertices();
  17993. }
  17994. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17995. TorusGeometry.prototype.constructor = TorusGeometry;
  17996. // TorusBufferGeometry
  17997. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17998. BufferGeometry.call( this );
  17999. this.type = 'TorusBufferGeometry';
  18000. this.parameters = {
  18001. radius: radius,
  18002. tube: tube,
  18003. radialSegments: radialSegments,
  18004. tubularSegments: tubularSegments,
  18005. arc: arc
  18006. };
  18007. radius = radius || 1;
  18008. tube = tube || 0.4;
  18009. radialSegments = Math.floor( radialSegments ) || 8;
  18010. tubularSegments = Math.floor( tubularSegments ) || 6;
  18011. arc = arc || Math.PI * 2;
  18012. // buffers
  18013. const indices = [];
  18014. const vertices = [];
  18015. const normals = [];
  18016. const uvs = [];
  18017. // helper variables
  18018. const center = new Vector3();
  18019. const vertex = new Vector3();
  18020. const normal = new Vector3();
  18021. // generate vertices, normals and uvs
  18022. for ( let j = 0; j <= radialSegments; j ++ ) {
  18023. for ( let i = 0; i <= tubularSegments; i ++ ) {
  18024. const u = i / tubularSegments * arc;
  18025. const v = j / radialSegments * Math.PI * 2;
  18026. // vertex
  18027. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  18028. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  18029. vertex.z = tube * Math.sin( v );
  18030. vertices.push( vertex.x, vertex.y, vertex.z );
  18031. // normal
  18032. center.x = radius * Math.cos( u );
  18033. center.y = radius * Math.sin( u );
  18034. normal.subVectors( vertex, center ).normalize();
  18035. normals.push( normal.x, normal.y, normal.z );
  18036. // uv
  18037. uvs.push( i / tubularSegments );
  18038. uvs.push( j / radialSegments );
  18039. }
  18040. }
  18041. // generate indices
  18042. for ( let j = 1; j <= radialSegments; j ++ ) {
  18043. for ( let i = 1; i <= tubularSegments; i ++ ) {
  18044. // indices
  18045. const a = ( tubularSegments + 1 ) * j + i - 1;
  18046. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  18047. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  18048. const d = ( tubularSegments + 1 ) * j + i;
  18049. // faces
  18050. indices.push( a, b, d );
  18051. indices.push( b, c, d );
  18052. }
  18053. }
  18054. // build geometry
  18055. this.setIndex( indices );
  18056. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18057. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18058. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18059. }
  18060. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18061. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  18062. /**
  18063. * @author Mugen87 / https://github.com/Mugen87
  18064. * Port from https://github.com/mapbox/earcut (v2.2.2)
  18065. */
  18066. const Earcut = {
  18067. triangulate: function ( data, holeIndices, dim ) {
  18068. dim = dim || 2;
  18069. let hasHoles = holeIndices && holeIndices.length,
  18070. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  18071. outerNode = linkedList( data, 0, outerLen, dim, true ),
  18072. triangles = [];
  18073. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  18074. let minX, minY, maxX, maxY, x, y, invSize;
  18075. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  18076. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  18077. if ( data.length > 80 * dim ) {
  18078. minX = maxX = data[ 0 ];
  18079. minY = maxY = data[ 1 ];
  18080. for ( let i = dim; i < outerLen; i += dim ) {
  18081. x = data[ i ];
  18082. y = data[ i + 1 ];
  18083. if ( x < minX ) minX = x;
  18084. if ( y < minY ) minY = y;
  18085. if ( x > maxX ) maxX = x;
  18086. if ( y > maxY ) maxY = y;
  18087. }
  18088. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  18089. invSize = Math.max( maxX - minX, maxY - minY );
  18090. invSize = invSize !== 0 ? 1 / invSize : 0;
  18091. }
  18092. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  18093. return triangles;
  18094. }
  18095. };
  18096. // create a circular doubly linked list from polygon points in the specified winding order
  18097. function linkedList( data, start, end, dim, clockwise ) {
  18098. let i, last;
  18099. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  18100. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  18101. } else {
  18102. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  18103. }
  18104. if ( last && equals( last, last.next ) ) {
  18105. removeNode( last );
  18106. last = last.next;
  18107. }
  18108. return last;
  18109. }
  18110. // eliminate colinear or duplicate points
  18111. function filterPoints( start, end ) {
  18112. if ( ! start ) return start;
  18113. if ( ! end ) end = start;
  18114. let p = start,
  18115. again;
  18116. do {
  18117. again = false;
  18118. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  18119. removeNode( p );
  18120. p = end = p.prev;
  18121. if ( p === p.next ) break;
  18122. again = true;
  18123. } else {
  18124. p = p.next;
  18125. }
  18126. } while ( again || p !== end );
  18127. return end;
  18128. }
  18129. // main ear slicing loop which triangulates a polygon (given as a linked list)
  18130. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  18131. if ( ! ear ) return;
  18132. // interlink polygon nodes in z-order
  18133. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  18134. let stop = ear,
  18135. prev, next;
  18136. // iterate through ears, slicing them one by one
  18137. while ( ear.prev !== ear.next ) {
  18138. prev = ear.prev;
  18139. next = ear.next;
  18140. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  18141. // cut off the triangle
  18142. triangles.push( prev.i / dim );
  18143. triangles.push( ear.i / dim );
  18144. triangles.push( next.i / dim );
  18145. removeNode( ear );
  18146. // skipping the next vertex leads to less sliver triangles
  18147. ear = next.next;
  18148. stop = next.next;
  18149. continue;
  18150. }
  18151. ear = next;
  18152. // if we looped through the whole remaining polygon and can't find any more ears
  18153. if ( ear === stop ) {
  18154. // try filtering points and slicing again
  18155. if ( ! pass ) {
  18156. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  18157. // if this didn't work, try curing all small self-intersections locally
  18158. } else if ( pass === 1 ) {
  18159. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  18160. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  18161. // as a last resort, try splitting the remaining polygon into two
  18162. } else if ( pass === 2 ) {
  18163. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  18164. }
  18165. break;
  18166. }
  18167. }
  18168. }
  18169. // check whether a polygon node forms a valid ear with adjacent nodes
  18170. function isEar( ear ) {
  18171. let a = ear.prev,
  18172. b = ear,
  18173. c = ear.next;
  18174. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  18175. // now make sure we don't have other points inside the potential ear
  18176. let p = ear.next.next;
  18177. while ( p !== ear.prev ) {
  18178. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18179. area( p.prev, p, p.next ) >= 0 ) return false;
  18180. p = p.next;
  18181. }
  18182. return true;
  18183. }
  18184. function isEarHashed( ear, minX, minY, invSize ) {
  18185. let a = ear.prev,
  18186. b = ear,
  18187. c = ear.next;
  18188. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  18189. // triangle bbox; min & max are calculated like this for speed
  18190. let minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  18191. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  18192. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  18193. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  18194. // z-order range for the current triangle bbox;
  18195. let minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  18196. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  18197. let p = ear.prevZ,
  18198. n = ear.nextZ;
  18199. // look for points inside the triangle in both directions
  18200. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  18201. if ( p !== ear.prev && p !== ear.next &&
  18202. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18203. area( p.prev, p, p.next ) >= 0 ) return false;
  18204. p = p.prevZ;
  18205. if ( n !== ear.prev && n !== ear.next &&
  18206. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18207. area( n.prev, n, n.next ) >= 0 ) return false;
  18208. n = n.nextZ;
  18209. }
  18210. // look for remaining points in decreasing z-order
  18211. while ( p && p.z >= minZ ) {
  18212. if ( p !== ear.prev && p !== ear.next &&
  18213. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  18214. area( p.prev, p, p.next ) >= 0 ) return false;
  18215. p = p.prevZ;
  18216. }
  18217. // look for remaining points in increasing z-order
  18218. while ( n && n.z <= maxZ ) {
  18219. if ( n !== ear.prev && n !== ear.next &&
  18220. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  18221. area( n.prev, n, n.next ) >= 0 ) return false;
  18222. n = n.nextZ;
  18223. }
  18224. return true;
  18225. }
  18226. // go through all polygon nodes and cure small local self-intersections
  18227. function cureLocalIntersections( start, triangles, dim ) {
  18228. let p = start;
  18229. do {
  18230. let a = p.prev,
  18231. b = p.next.next;
  18232. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  18233. triangles.push( a.i / dim );
  18234. triangles.push( p.i / dim );
  18235. triangles.push( b.i / dim );
  18236. // remove two nodes involved
  18237. removeNode( p );
  18238. removeNode( p.next );
  18239. p = start = b;
  18240. }
  18241. p = p.next;
  18242. } while ( p !== start );
  18243. return filterPoints( p );
  18244. }
  18245. // try splitting polygon into two and triangulate them independently
  18246. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  18247. // look for a valid diagonal that divides the polygon into two
  18248. let a = start;
  18249. do {
  18250. let b = a.next.next;
  18251. while ( b !== a.prev ) {
  18252. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  18253. // split the polygon in two by the diagonal
  18254. let c = splitPolygon( a, b );
  18255. // filter colinear points around the cuts
  18256. a = filterPoints( a, a.next );
  18257. c = filterPoints( c, c.next );
  18258. // run earcut on each half
  18259. earcutLinked( a, triangles, dim, minX, minY, invSize );
  18260. earcutLinked( c, triangles, dim, minX, minY, invSize );
  18261. return;
  18262. }
  18263. b = b.next;
  18264. }
  18265. a = a.next;
  18266. } while ( a !== start );
  18267. }
  18268. // link every hole into the outer loop, producing a single-ring polygon without holes
  18269. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  18270. let queue = [],
  18271. i, len, start, end, list;
  18272. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  18273. start = holeIndices[ i ] * dim;
  18274. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  18275. list = linkedList( data, start, end, dim, false );
  18276. if ( list === list.next ) list.steiner = true;
  18277. queue.push( getLeftmost( list ) );
  18278. }
  18279. queue.sort( compareX );
  18280. // process holes from left to right
  18281. for ( i = 0; i < queue.length; i ++ ) {
  18282. eliminateHole( queue[ i ], outerNode );
  18283. outerNode = filterPoints( outerNode, outerNode.next );
  18284. }
  18285. return outerNode;
  18286. }
  18287. function compareX( a, b ) {
  18288. return a.x - b.x;
  18289. }
  18290. // find a bridge between vertices that connects hole with an outer ring and and link it
  18291. function eliminateHole( hole, outerNode ) {
  18292. outerNode = findHoleBridge( hole, outerNode );
  18293. if ( outerNode ) {
  18294. const b = splitPolygon( outerNode, hole );
  18295. // filter collinear points around the cuts
  18296. filterPoints( outerNode, outerNode.next );
  18297. filterPoints( b, b.next );
  18298. }
  18299. }
  18300. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18301. function findHoleBridge( hole, outerNode ) {
  18302. let p = outerNode,
  18303. hx = hole.x,
  18304. hy = hole.y,
  18305. qx = - Infinity,
  18306. m;
  18307. // find a segment intersected by a ray from the hole's leftmost point to the left;
  18308. // segment's endpoint with lesser x will be potential connection point
  18309. do {
  18310. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  18311. let x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  18312. if ( x <= hx && x > qx ) {
  18313. qx = x;
  18314. if ( x === hx ) {
  18315. if ( hy === p.y ) return p;
  18316. if ( hy === p.next.y ) return p.next;
  18317. }
  18318. m = p.x < p.next.x ? p : p.next;
  18319. }
  18320. }
  18321. p = p.next;
  18322. } while ( p !== outerNode );
  18323. if ( ! m ) return null;
  18324. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  18325. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18326. // if there are no points found, we have a valid connection;
  18327. // otherwise choose the point of the minimum angle with the ray as connection point
  18328. let stop = m,
  18329. mx = m.x,
  18330. my = m.y,
  18331. tanMin = Infinity,
  18332. tan;
  18333. p = m;
  18334. do {
  18335. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  18336. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  18337. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  18338. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  18339. m = p;
  18340. tanMin = tan;
  18341. }
  18342. }
  18343. p = p.next;
  18344. } while ( p !== stop );
  18345. return m;
  18346. }
  18347. // whether sector in vertex m contains sector in vertex p in the same coordinates
  18348. function sectorContainsSector( m, p ) {
  18349. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  18350. }
  18351. // interlink polygon nodes in z-order
  18352. function indexCurve( start, minX, minY, invSize ) {
  18353. let p = start;
  18354. do {
  18355. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  18356. p.prevZ = p.prev;
  18357. p.nextZ = p.next;
  18358. p = p.next;
  18359. } while ( p !== start );
  18360. p.prevZ.nextZ = null;
  18361. p.prevZ = null;
  18362. sortLinked( p );
  18363. }
  18364. // Simon Tatham's linked list merge sort algorithm
  18365. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18366. function sortLinked( list ) {
  18367. let i, p, q, e, tail, numMerges, pSize, qSize,
  18368. inSize = 1;
  18369. do {
  18370. p = list;
  18371. list = null;
  18372. tail = null;
  18373. numMerges = 0;
  18374. while ( p ) {
  18375. numMerges ++;
  18376. q = p;
  18377. pSize = 0;
  18378. for ( i = 0; i < inSize; i ++ ) {
  18379. pSize ++;
  18380. q = q.nextZ;
  18381. if ( ! q ) break;
  18382. }
  18383. qSize = inSize;
  18384. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  18385. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  18386. e = p;
  18387. p = p.nextZ;
  18388. pSize --;
  18389. } else {
  18390. e = q;
  18391. q = q.nextZ;
  18392. qSize --;
  18393. }
  18394. if ( tail ) tail.nextZ = e;
  18395. else list = e;
  18396. e.prevZ = tail;
  18397. tail = e;
  18398. }
  18399. p = q;
  18400. }
  18401. tail.nextZ = null;
  18402. inSize *= 2;
  18403. } while ( numMerges > 1 );
  18404. return list;
  18405. }
  18406. // z-order of a point given coords and inverse of the longer side of data bbox
  18407. function zOrder( x, y, minX, minY, invSize ) {
  18408. // coords are transformed into non-negative 15-bit integer range
  18409. x = 32767 * ( x - minX ) * invSize;
  18410. y = 32767 * ( y - minY ) * invSize;
  18411. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  18412. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  18413. x = ( x | ( x << 2 ) ) & 0x33333333;
  18414. x = ( x | ( x << 1 ) ) & 0x55555555;
  18415. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  18416. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  18417. y = ( y | ( y << 2 ) ) & 0x33333333;
  18418. y = ( y | ( y << 1 ) ) & 0x55555555;
  18419. return x | ( y << 1 );
  18420. }
  18421. // find the leftmost node of a polygon ring
  18422. function getLeftmost( start ) {
  18423. let p = start,
  18424. leftmost = start;
  18425. do {
  18426. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  18427. p = p.next;
  18428. } while ( p !== start );
  18429. return leftmost;
  18430. }
  18431. // check if a point lies within a convex triangle
  18432. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  18433. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  18434. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  18435. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  18436. }
  18437. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18438. function isValidDiagonal( a, b ) {
  18439. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  18440. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  18441. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  18442. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  18443. }
  18444. // signed area of a triangle
  18445. function area( p, q, r ) {
  18446. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  18447. }
  18448. // check if two points are equal
  18449. function equals( p1, p2 ) {
  18450. return p1.x === p2.x && p1.y === p2.y;
  18451. }
  18452. // check if two segments intersect
  18453. function intersects( p1, q1, p2, q2 ) {
  18454. const o1 = sign( area( p1, q1, p2 ) );
  18455. const o2 = sign( area( p1, q1, q2 ) );
  18456. const o3 = sign( area( p2, q2, p1 ) );
  18457. const o4 = sign( area( p2, q2, q1 ) );
  18458. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  18459. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18460. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18461. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18462. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18463. return false;
  18464. }
  18465. // for collinear points p, q, r, check if point q lies on segment pr
  18466. function onSegment( p, q, r ) {
  18467. 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 );
  18468. }
  18469. function sign( num ) {
  18470. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  18471. }
  18472. // check if a polygon diagonal intersects any polygon segments
  18473. function intersectsPolygon( a, b ) {
  18474. let p = a;
  18475. do {
  18476. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18477. intersects( p, p.next, a, b ) ) return true;
  18478. p = p.next;
  18479. } while ( p !== a );
  18480. return false;
  18481. }
  18482. // check if a polygon diagonal is locally inside the polygon
  18483. function locallyInside( a, b ) {
  18484. return area( a.prev, a, a.next ) < 0 ?
  18485. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18486. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18487. }
  18488. // check if the middle point of a polygon diagonal is inside the polygon
  18489. function middleInside( a, b ) {
  18490. let p = a,
  18491. inside = false,
  18492. px = ( a.x + b.x ) / 2,
  18493. py = ( a.y + b.y ) / 2;
  18494. do {
  18495. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18496. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18497. inside = ! inside;
  18498. p = p.next;
  18499. } while ( p !== a );
  18500. return inside;
  18501. }
  18502. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18503. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18504. function splitPolygon( a, b ) {
  18505. let a2 = new Node( a.i, a.x, a.y ),
  18506. b2 = new Node( b.i, b.x, b.y ),
  18507. an = a.next,
  18508. bp = b.prev;
  18509. a.next = b;
  18510. b.prev = a;
  18511. a2.next = an;
  18512. an.prev = a2;
  18513. b2.next = a2;
  18514. a2.prev = b2;
  18515. bp.next = b2;
  18516. b2.prev = bp;
  18517. return b2;
  18518. }
  18519. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18520. function insertNode( i, x, y, last ) {
  18521. const p = new Node( i, x, y );
  18522. if ( ! last ) {
  18523. p.prev = p;
  18524. p.next = p;
  18525. } else {
  18526. p.next = last.next;
  18527. p.prev = last;
  18528. last.next.prev = p;
  18529. last.next = p;
  18530. }
  18531. return p;
  18532. }
  18533. function removeNode( p ) {
  18534. p.next.prev = p.prev;
  18535. p.prev.next = p.next;
  18536. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  18537. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  18538. }
  18539. function Node( i, x, y ) {
  18540. // vertex index in coordinates array
  18541. this.i = i;
  18542. // vertex coordinates
  18543. this.x = x;
  18544. this.y = y;
  18545. // previous and next vertex nodes in a polygon ring
  18546. this.prev = null;
  18547. this.next = null;
  18548. // z-order curve value
  18549. this.z = null;
  18550. // previous and next nodes in z-order
  18551. this.prevZ = null;
  18552. this.nextZ = null;
  18553. // indicates whether this is a steiner point
  18554. this.steiner = false;
  18555. }
  18556. function signedArea( data, start, end, dim ) {
  18557. let sum = 0;
  18558. for ( let i = start, j = end - dim; i < end; i += dim ) {
  18559. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18560. j = i;
  18561. }
  18562. return sum;
  18563. }
  18564. /**
  18565. * @author zz85 / http://www.lab4games.net/zz85/blog
  18566. */
  18567. const ShapeUtils = {
  18568. // calculate area of the contour polygon
  18569. area: function ( contour ) {
  18570. const n = contour.length;
  18571. let a = 0.0;
  18572. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  18573. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18574. }
  18575. return a * 0.5;
  18576. },
  18577. isClockWise: function ( pts ) {
  18578. return ShapeUtils.area( pts ) < 0;
  18579. },
  18580. triangulateShape: function ( contour, holes ) {
  18581. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18582. const holeIndices = []; // array of hole indices
  18583. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18584. removeDupEndPts( contour );
  18585. addContour( vertices, contour );
  18586. //
  18587. let holeIndex = contour.length;
  18588. holes.forEach( removeDupEndPts );
  18589. for ( let i = 0; i < holes.length; i ++ ) {
  18590. holeIndices.push( holeIndex );
  18591. holeIndex += holes[ i ].length;
  18592. addContour( vertices, holes[ i ] );
  18593. }
  18594. //
  18595. const triangles = Earcut.triangulate( vertices, holeIndices );
  18596. //
  18597. for ( let i = 0; i < triangles.length; i += 3 ) {
  18598. faces.push( triangles.slice( i, i + 3 ) );
  18599. }
  18600. return faces;
  18601. }
  18602. };
  18603. function removeDupEndPts( points ) {
  18604. const l = points.length;
  18605. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18606. points.pop();
  18607. }
  18608. }
  18609. function addContour( vertices, contour ) {
  18610. for ( let i = 0; i < contour.length; i ++ ) {
  18611. vertices.push( contour[ i ].x );
  18612. vertices.push( contour[ i ].y );
  18613. }
  18614. }
  18615. /**
  18616. * @author zz85 / http://www.lab4games.net/zz85/blog
  18617. *
  18618. * Creates extruded geometry from a path shape.
  18619. *
  18620. * parameters = {
  18621. *
  18622. * curveSegments: <int>, // number of points on the curves
  18623. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18624. * depth: <float>, // Depth to extrude the shape
  18625. *
  18626. * bevelEnabled: <bool>, // turn on bevel
  18627. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18628. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18629. * bevelOffset: <float>, // how far from shape outline does bevel start
  18630. * bevelSegments: <int>, // number of bevel layers
  18631. *
  18632. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18633. *
  18634. * UVGenerator: <Object> // object that provides UV generator functions
  18635. *
  18636. * }
  18637. */
  18638. // ExtrudeGeometry
  18639. function ExtrudeGeometry( shapes, options ) {
  18640. Geometry.call( this );
  18641. this.type = 'ExtrudeGeometry';
  18642. this.parameters = {
  18643. shapes: shapes,
  18644. options: options
  18645. };
  18646. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18647. this.mergeVertices();
  18648. }
  18649. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  18650. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  18651. ExtrudeGeometry.prototype.toJSON = function () {
  18652. const data = Geometry.prototype.toJSON.call( this );
  18653. const shapes = this.parameters.shapes;
  18654. const options = this.parameters.options;
  18655. return toJSON( shapes, options, data );
  18656. };
  18657. // ExtrudeBufferGeometry
  18658. function ExtrudeBufferGeometry( shapes, options ) {
  18659. BufferGeometry.call( this );
  18660. this.type = 'ExtrudeBufferGeometry';
  18661. this.parameters = {
  18662. shapes: shapes,
  18663. options: options
  18664. };
  18665. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18666. const scope = this;
  18667. const verticesArray = [];
  18668. const uvArray = [];
  18669. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18670. const shape = shapes[ i ];
  18671. addShape( shape );
  18672. }
  18673. // build geometry
  18674. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18675. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18676. this.computeVertexNormals();
  18677. // functions
  18678. function addShape( shape ) {
  18679. const placeholder = [];
  18680. // options
  18681. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18682. const steps = options.steps !== undefined ? options.steps : 1;
  18683. let depth = options.depth !== undefined ? options.depth : 100;
  18684. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18685. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18686. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18687. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18688. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18689. const extrudePath = options.extrudePath;
  18690. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18691. // deprecated options
  18692. if ( options.amount !== undefined ) {
  18693. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18694. depth = options.amount;
  18695. }
  18696. //
  18697. let extrudePts, extrudeByPath = false;
  18698. let splineTube, binormal, normal, position2;
  18699. if ( extrudePath ) {
  18700. extrudePts = extrudePath.getSpacedPoints( steps );
  18701. extrudeByPath = true;
  18702. bevelEnabled = false; // bevels not supported for path extrusion
  18703. // SETUP TNB variables
  18704. // TODO1 - have a .isClosed in spline?
  18705. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18706. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18707. binormal = new Vector3();
  18708. normal = new Vector3();
  18709. position2 = new Vector3();
  18710. }
  18711. // Safeguards if bevels are not enabled
  18712. if ( ! bevelEnabled ) {
  18713. bevelSegments = 0;
  18714. bevelThickness = 0;
  18715. bevelSize = 0;
  18716. bevelOffset = 0;
  18717. }
  18718. // Variables initialization
  18719. const shapePoints = shape.extractPoints( curveSegments );
  18720. let vertices = shapePoints.shape;
  18721. const holes = shapePoints.holes;
  18722. const reverse = ! ShapeUtils.isClockWise( vertices );
  18723. if ( reverse ) {
  18724. vertices = vertices.reverse();
  18725. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18726. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18727. const ahole = holes[ h ];
  18728. if ( ShapeUtils.isClockWise( ahole ) ) {
  18729. holes[ h ] = ahole.reverse();
  18730. }
  18731. }
  18732. }
  18733. const faces = ShapeUtils.triangulateShape( vertices, holes );
  18734. /* Vertices */
  18735. const contour = vertices; // vertices has all points but contour has only points of circumference
  18736. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18737. const ahole = holes[ h ];
  18738. vertices = vertices.concat( ahole );
  18739. }
  18740. function scalePt2( pt, vec, size ) {
  18741. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18742. return vec.clone().multiplyScalar( size ).add( pt );
  18743. }
  18744. const vlen = vertices.length, flen = faces.length;
  18745. // Find directions for point movement
  18746. function getBevelVec( inPt, inPrev, inNext ) {
  18747. // computes for inPt the corresponding point inPt' on a new contour
  18748. // shifted by 1 unit (length of normalized vector) to the left
  18749. // if we walk along contour clockwise, this new contour is outside the old one
  18750. //
  18751. // inPt' is the intersection of the two lines parallel to the two
  18752. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18753. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18754. // good reading for geometry algorithms (here: line-line intersection)
  18755. // http://geomalgorithms.com/a05-_intersect-1.html
  18756. const v_prev_x = inPt.x - inPrev.x,
  18757. v_prev_y = inPt.y - inPrev.y;
  18758. const v_next_x = inNext.x - inPt.x,
  18759. v_next_y = inNext.y - inPt.y;
  18760. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18761. // check for collinear edges
  18762. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18763. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18764. // not collinear
  18765. // length of vectors for normalizing
  18766. const v_prev_len = Math.sqrt( v_prev_lensq );
  18767. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18768. // shift adjacent points by unit vectors to the left
  18769. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18770. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18771. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18772. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18773. // scaling factor for v_prev to intersection point
  18774. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18775. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18776. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18777. // vector from inPt to intersection point
  18778. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18779. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18780. // Don't normalize!, otherwise sharp corners become ugly
  18781. // but prevent crazy spikes
  18782. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18783. if ( v_trans_lensq <= 2 ) {
  18784. return new Vector2( v_trans_x, v_trans_y );
  18785. } else {
  18786. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18787. }
  18788. } else {
  18789. // handle special case of collinear edges
  18790. let direction_eq = false; // assumes: opposite
  18791. if ( v_prev_x > Number.EPSILON ) {
  18792. if ( v_next_x > Number.EPSILON ) {
  18793. direction_eq = true;
  18794. }
  18795. } else {
  18796. if ( v_prev_x < - Number.EPSILON ) {
  18797. if ( v_next_x < - Number.EPSILON ) {
  18798. direction_eq = true;
  18799. }
  18800. } else {
  18801. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18802. direction_eq = true;
  18803. }
  18804. }
  18805. }
  18806. if ( direction_eq ) {
  18807. // console.log("Warning: lines are a straight sequence");
  18808. v_trans_x = - v_prev_y;
  18809. v_trans_y = v_prev_x;
  18810. shrink_by = Math.sqrt( v_prev_lensq );
  18811. } else {
  18812. // console.log("Warning: lines are a straight spike");
  18813. v_trans_x = v_prev_x;
  18814. v_trans_y = v_prev_y;
  18815. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18816. }
  18817. }
  18818. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18819. }
  18820. const contourMovements = [];
  18821. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18822. if ( j === il ) j = 0;
  18823. if ( k === il ) k = 0;
  18824. // (j)---(i)---(k)
  18825. // console.log('i,j,k', i, j , k)
  18826. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18827. }
  18828. const holesMovements = [];
  18829. let oneHoleMovements, verticesMovements = contourMovements.concat();
  18830. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18831. const ahole = holes[ h ];
  18832. oneHoleMovements = [];
  18833. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18834. if ( j === il ) j = 0;
  18835. if ( k === il ) k = 0;
  18836. // (j)---(i)---(k)
  18837. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18838. }
  18839. holesMovements.push( oneHoleMovements );
  18840. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18841. }
  18842. // Loop bevelSegments, 1 for the front, 1 for the back
  18843. for ( let b = 0; b < bevelSegments; b ++ ) {
  18844. //for ( b = bevelSegments; b > 0; b -- ) {
  18845. const t = b / bevelSegments;
  18846. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18847. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18848. // contract shape
  18849. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  18850. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18851. v( vert.x, vert.y, - z );
  18852. }
  18853. // expand holes
  18854. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18855. const ahole = holes[ h ];
  18856. oneHoleMovements = holesMovements[ h ];
  18857. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  18858. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18859. v( vert.x, vert.y, - z );
  18860. }
  18861. }
  18862. }
  18863. const bs = bevelSize + bevelOffset;
  18864. // Back facing vertices
  18865. for ( let i = 0; i < vlen; i ++ ) {
  18866. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18867. if ( ! extrudeByPath ) {
  18868. v( vert.x, vert.y, 0 );
  18869. } else {
  18870. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18871. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18872. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18873. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18874. v( position2.x, position2.y, position2.z );
  18875. }
  18876. }
  18877. // Add stepped vertices...
  18878. // Including front facing vertices
  18879. for ( let s = 1; s <= steps; s ++ ) {
  18880. for ( let i = 0; i < vlen; i ++ ) {
  18881. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18882. if ( ! extrudeByPath ) {
  18883. v( vert.x, vert.y, depth / steps * s );
  18884. } else {
  18885. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18886. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18887. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18888. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18889. v( position2.x, position2.y, position2.z );
  18890. }
  18891. }
  18892. }
  18893. // Add bevel segments planes
  18894. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18895. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  18896. const t = b / bevelSegments;
  18897. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18898. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18899. // contract shape
  18900. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  18901. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18902. v( vert.x, vert.y, depth + z );
  18903. }
  18904. // expand holes
  18905. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18906. const ahole = holes[ h ];
  18907. oneHoleMovements = holesMovements[ h ];
  18908. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  18909. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18910. if ( ! extrudeByPath ) {
  18911. v( vert.x, vert.y, depth + z );
  18912. } else {
  18913. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18914. }
  18915. }
  18916. }
  18917. }
  18918. /* Faces */
  18919. // Top and bottom faces
  18920. buildLidFaces();
  18921. // Sides faces
  18922. buildSideFaces();
  18923. ///// Internal functions
  18924. function buildLidFaces() {
  18925. const start = verticesArray.length / 3;
  18926. if ( bevelEnabled ) {
  18927. let layer = 0; // steps + 1
  18928. let offset = vlen * layer;
  18929. // Bottom faces
  18930. for ( let i = 0; i < flen; i ++ ) {
  18931. const face = faces[ i ];
  18932. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18933. }
  18934. layer = steps + bevelSegments * 2;
  18935. offset = vlen * layer;
  18936. // Top faces
  18937. for ( let i = 0; i < flen; i ++ ) {
  18938. const face = faces[ i ];
  18939. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18940. }
  18941. } else {
  18942. // Bottom faces
  18943. for ( let i = 0; i < flen; i ++ ) {
  18944. const face = faces[ i ];
  18945. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18946. }
  18947. // Top faces
  18948. for ( let i = 0; i < flen; i ++ ) {
  18949. const face = faces[ i ];
  18950. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18951. }
  18952. }
  18953. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18954. }
  18955. // Create faces for the z-sides of the shape
  18956. function buildSideFaces() {
  18957. const start = verticesArray.length / 3;
  18958. let layeroffset = 0;
  18959. sidewalls( contour, layeroffset );
  18960. layeroffset += contour.length;
  18961. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18962. const ahole = holes[ h ];
  18963. sidewalls( ahole, layeroffset );
  18964. //, true
  18965. layeroffset += ahole.length;
  18966. }
  18967. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18968. }
  18969. function sidewalls( contour, layeroffset ) {
  18970. let i = contour.length;
  18971. while ( -- i >= 0 ) {
  18972. const j = i;
  18973. let k = i - 1;
  18974. if ( k < 0 ) k = contour.length - 1;
  18975. //console.log('b', i,j, i-1, k,vertices.length);
  18976. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  18977. const slen1 = vlen * s;
  18978. const slen2 = vlen * ( s + 1 );
  18979. const a = layeroffset + j + slen1,
  18980. b = layeroffset + k + slen1,
  18981. c = layeroffset + k + slen2,
  18982. d = layeroffset + j + slen2;
  18983. f4( a, b, c, d );
  18984. }
  18985. }
  18986. }
  18987. function v( x, y, z ) {
  18988. placeholder.push( x );
  18989. placeholder.push( y );
  18990. placeholder.push( z );
  18991. }
  18992. function f3( a, b, c ) {
  18993. addVertex( a );
  18994. addVertex( b );
  18995. addVertex( c );
  18996. const nextIndex = verticesArray.length / 3;
  18997. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18998. addUV( uvs[ 0 ] );
  18999. addUV( uvs[ 1 ] );
  19000. addUV( uvs[ 2 ] );
  19001. }
  19002. function f4( a, b, c, d ) {
  19003. addVertex( a );
  19004. addVertex( b );
  19005. addVertex( d );
  19006. addVertex( b );
  19007. addVertex( c );
  19008. addVertex( d );
  19009. const nextIndex = verticesArray.length / 3;
  19010. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  19011. addUV( uvs[ 0 ] );
  19012. addUV( uvs[ 1 ] );
  19013. addUV( uvs[ 3 ] );
  19014. addUV( uvs[ 1 ] );
  19015. addUV( uvs[ 2 ] );
  19016. addUV( uvs[ 3 ] );
  19017. }
  19018. function addVertex( index ) {
  19019. verticesArray.push( placeholder[ index * 3 + 0 ] );
  19020. verticesArray.push( placeholder[ index * 3 + 1 ] );
  19021. verticesArray.push( placeholder[ index * 3 + 2 ] );
  19022. }
  19023. function addUV( vector2 ) {
  19024. uvArray.push( vector2.x );
  19025. uvArray.push( vector2.y );
  19026. }
  19027. }
  19028. }
  19029. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19030. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  19031. ExtrudeBufferGeometry.prototype.toJSON = function () {
  19032. const data = BufferGeometry.prototype.toJSON.call( this );
  19033. const shapes = this.parameters.shapes;
  19034. const options = this.parameters.options;
  19035. return toJSON( shapes, options, data );
  19036. };
  19037. //
  19038. const WorldUVGenerator = {
  19039. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  19040. const a_x = vertices[ indexA * 3 ];
  19041. const a_y = vertices[ indexA * 3 + 1 ];
  19042. const b_x = vertices[ indexB * 3 ];
  19043. const b_y = vertices[ indexB * 3 + 1 ];
  19044. const c_x = vertices[ indexC * 3 ];
  19045. const c_y = vertices[ indexC * 3 + 1 ];
  19046. return [
  19047. new Vector2( a_x, a_y ),
  19048. new Vector2( b_x, b_y ),
  19049. new Vector2( c_x, c_y )
  19050. ];
  19051. },
  19052. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  19053. const a_x = vertices[ indexA * 3 ];
  19054. const a_y = vertices[ indexA * 3 + 1 ];
  19055. const a_z = vertices[ indexA * 3 + 2 ];
  19056. const b_x = vertices[ indexB * 3 ];
  19057. const b_y = vertices[ indexB * 3 + 1 ];
  19058. const b_z = vertices[ indexB * 3 + 2 ];
  19059. const c_x = vertices[ indexC * 3 ];
  19060. const c_y = vertices[ indexC * 3 + 1 ];
  19061. const c_z = vertices[ indexC * 3 + 2 ];
  19062. const d_x = vertices[ indexD * 3 ];
  19063. const d_y = vertices[ indexD * 3 + 1 ];
  19064. const d_z = vertices[ indexD * 3 + 2 ];
  19065. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  19066. return [
  19067. new Vector2( a_x, 1 - a_z ),
  19068. new Vector2( b_x, 1 - b_z ),
  19069. new Vector2( c_x, 1 - c_z ),
  19070. new Vector2( d_x, 1 - d_z )
  19071. ];
  19072. } else {
  19073. return [
  19074. new Vector2( a_y, 1 - a_z ),
  19075. new Vector2( b_y, 1 - b_z ),
  19076. new Vector2( c_y, 1 - c_z ),
  19077. new Vector2( d_y, 1 - d_z )
  19078. ];
  19079. }
  19080. }
  19081. };
  19082. function toJSON( shapes, options, data ) {
  19083. //
  19084. data.shapes = [];
  19085. if ( Array.isArray( shapes ) ) {
  19086. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  19087. const shape = shapes[ i ];
  19088. data.shapes.push( shape.uuid );
  19089. }
  19090. } else {
  19091. data.shapes.push( shapes.uuid );
  19092. }
  19093. //
  19094. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  19095. return data;
  19096. }
  19097. /**
  19098. * @author zz85 / http://www.lab4games.net/zz85/blog
  19099. * @author alteredq / http://alteredqualia.com/
  19100. *
  19101. * Text = 3D Text
  19102. *
  19103. * parameters = {
  19104. * font: <THREE.Font>, // font
  19105. *
  19106. * size: <float>, // size of the text
  19107. * height: <float>, // thickness to extrude text
  19108. * curveSegments: <int>, // number of points on the curves
  19109. *
  19110. * bevelEnabled: <bool>, // turn on bevel
  19111. * bevelThickness: <float>, // how deep into text bevel goes
  19112. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  19113. * bevelOffset: <float> // how far from text outline does bevel start
  19114. * }
  19115. */
  19116. // TextGeometry
  19117. function TextGeometry( text, parameters ) {
  19118. Geometry.call( this );
  19119. this.type = 'TextGeometry';
  19120. this.parameters = {
  19121. text: text,
  19122. parameters: parameters
  19123. };
  19124. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  19125. this.mergeVertices();
  19126. }
  19127. TextGeometry.prototype = Object.create( Geometry.prototype );
  19128. TextGeometry.prototype.constructor = TextGeometry;
  19129. // TextBufferGeometry
  19130. function TextBufferGeometry( text, parameters ) {
  19131. parameters = parameters || {};
  19132. const font = parameters.font;
  19133. if ( ! ( font && font.isFont ) ) {
  19134. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  19135. return new Geometry();
  19136. }
  19137. const shapes = font.generateShapes( text, parameters.size );
  19138. // translate parameters to ExtrudeGeometry API
  19139. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  19140. // defaults
  19141. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19142. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19143. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19144. ExtrudeBufferGeometry.call( this, shapes, parameters );
  19145. this.type = 'TextBufferGeometry';
  19146. }
  19147. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  19148. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  19149. /**
  19150. * @author mrdoob / http://mrdoob.com/
  19151. * @author benaadams / https://twitter.com/ben_a_adams
  19152. * @author Mugen87 / https://github.com/Mugen87
  19153. */
  19154. // SphereGeometry
  19155. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19156. Geometry.call( this );
  19157. this.type = 'SphereGeometry';
  19158. this.parameters = {
  19159. radius: radius,
  19160. widthSegments: widthSegments,
  19161. heightSegments: heightSegments,
  19162. phiStart: phiStart,
  19163. phiLength: phiLength,
  19164. thetaStart: thetaStart,
  19165. thetaLength: thetaLength
  19166. };
  19167. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  19168. this.mergeVertices();
  19169. }
  19170. SphereGeometry.prototype = Object.create( Geometry.prototype );
  19171. SphereGeometry.prototype.constructor = SphereGeometry;
  19172. // SphereBufferGeometry
  19173. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19174. BufferGeometry.call( this );
  19175. this.type = 'SphereBufferGeometry';
  19176. this.parameters = {
  19177. radius: radius,
  19178. widthSegments: widthSegments,
  19179. heightSegments: heightSegments,
  19180. phiStart: phiStart,
  19181. phiLength: phiLength,
  19182. thetaStart: thetaStart,
  19183. thetaLength: thetaLength
  19184. };
  19185. radius = radius || 1;
  19186. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19187. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19188. phiStart = phiStart !== undefined ? phiStart : 0;
  19189. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19190. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19191. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19192. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  19193. let index = 0;
  19194. const grid = [];
  19195. const vertex = new Vector3();
  19196. const normal = new Vector3();
  19197. // buffers
  19198. const indices = [];
  19199. const vertices = [];
  19200. const normals = [];
  19201. const uvs = [];
  19202. // generate vertices, normals and uvs
  19203. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  19204. const verticesRow = [];
  19205. const v = iy / heightSegments;
  19206. // special case for the poles
  19207. let uOffset = 0;
  19208. if ( iy == 0 && thetaStart == 0 ) {
  19209. uOffset = 0.5 / widthSegments;
  19210. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  19211. uOffset = - 0.5 / widthSegments;
  19212. }
  19213. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  19214. const u = ix / widthSegments;
  19215. // vertex
  19216. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19217. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19218. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19219. vertices.push( vertex.x, vertex.y, vertex.z );
  19220. // normal
  19221. normal.copy( vertex ).normalize();
  19222. normals.push( normal.x, normal.y, normal.z );
  19223. // uv
  19224. uvs.push( u + uOffset, 1 - v );
  19225. verticesRow.push( index ++ );
  19226. }
  19227. grid.push( verticesRow );
  19228. }
  19229. // indices
  19230. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  19231. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  19232. const a = grid[ iy ][ ix + 1 ];
  19233. const b = grid[ iy ][ ix ];
  19234. const c = grid[ iy + 1 ][ ix ];
  19235. const d = grid[ iy + 1 ][ ix + 1 ];
  19236. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  19237. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  19238. }
  19239. }
  19240. // build geometry
  19241. this.setIndex( indices );
  19242. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19243. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19244. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19245. }
  19246. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19247. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  19248. /**
  19249. * @author Kaleb Murphy
  19250. * @author Mugen87 / https://github.com/Mugen87
  19251. */
  19252. // RingGeometry
  19253. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19254. Geometry.call( this );
  19255. this.type = 'RingGeometry';
  19256. this.parameters = {
  19257. innerRadius: innerRadius,
  19258. outerRadius: outerRadius,
  19259. thetaSegments: thetaSegments,
  19260. phiSegments: phiSegments,
  19261. thetaStart: thetaStart,
  19262. thetaLength: thetaLength
  19263. };
  19264. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  19265. this.mergeVertices();
  19266. }
  19267. RingGeometry.prototype = Object.create( Geometry.prototype );
  19268. RingGeometry.prototype.constructor = RingGeometry;
  19269. // RingBufferGeometry
  19270. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19271. BufferGeometry.call( this );
  19272. this.type = 'RingBufferGeometry';
  19273. this.parameters = {
  19274. innerRadius: innerRadius,
  19275. outerRadius: outerRadius,
  19276. thetaSegments: thetaSegments,
  19277. phiSegments: phiSegments,
  19278. thetaStart: thetaStart,
  19279. thetaLength: thetaLength
  19280. };
  19281. innerRadius = innerRadius || 0.5;
  19282. outerRadius = outerRadius || 1;
  19283. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19284. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19285. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19286. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  19287. // buffers
  19288. const indices = [];
  19289. const vertices = [];
  19290. const normals = [];
  19291. const uvs = [];
  19292. // some helper variables
  19293. let radius = innerRadius;
  19294. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19295. const vertex = new Vector3();
  19296. const uv = new Vector2();
  19297. // generate vertices, normals and uvs
  19298. for ( let j = 0; j <= phiSegments; j ++ ) {
  19299. for ( let i = 0; i <= thetaSegments; i ++ ) {
  19300. // values are generate from the inside of the ring to the outside
  19301. const segment = thetaStart + i / thetaSegments * thetaLength;
  19302. // vertex
  19303. vertex.x = radius * Math.cos( segment );
  19304. vertex.y = radius * Math.sin( segment );
  19305. vertices.push( vertex.x, vertex.y, vertex.z );
  19306. // normal
  19307. normals.push( 0, 0, 1 );
  19308. // uv
  19309. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  19310. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  19311. uvs.push( uv.x, uv.y );
  19312. }
  19313. // increase the radius for next row of vertices
  19314. radius += radiusStep;
  19315. }
  19316. // indices
  19317. for ( let j = 0; j < phiSegments; j ++ ) {
  19318. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  19319. for ( let i = 0; i < thetaSegments; i ++ ) {
  19320. const segment = i + thetaSegmentLevel;
  19321. const a = segment;
  19322. const b = segment + thetaSegments + 1;
  19323. const c = segment + thetaSegments + 2;
  19324. const d = segment + 1;
  19325. // faces
  19326. indices.push( a, b, d );
  19327. indices.push( b, c, d );
  19328. }
  19329. }
  19330. // build geometry
  19331. this.setIndex( indices );
  19332. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19333. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19334. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19335. }
  19336. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19337. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  19338. /**
  19339. * @author zz85 / https://github.com/zz85
  19340. * @author bhouston / http://clara.io
  19341. * @author Mugen87 / https://github.com/Mugen87
  19342. */
  19343. // LatheGeometry
  19344. function LatheGeometry( points, segments, phiStart, phiLength ) {
  19345. Geometry.call( this );
  19346. this.type = 'LatheGeometry';
  19347. this.parameters = {
  19348. points: points,
  19349. segments: segments,
  19350. phiStart: phiStart,
  19351. phiLength: phiLength
  19352. };
  19353. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  19354. this.mergeVertices();
  19355. }
  19356. LatheGeometry.prototype = Object.create( Geometry.prototype );
  19357. LatheGeometry.prototype.constructor = LatheGeometry;
  19358. // LatheBufferGeometry
  19359. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  19360. BufferGeometry.call( this );
  19361. this.type = 'LatheBufferGeometry';
  19362. this.parameters = {
  19363. points: points,
  19364. segments: segments,
  19365. phiStart: phiStart,
  19366. phiLength: phiLength
  19367. };
  19368. segments = Math.floor( segments ) || 12;
  19369. phiStart = phiStart || 0;
  19370. phiLength = phiLength || Math.PI * 2;
  19371. // clamp phiLength so it's in range of [ 0, 2PI ]
  19372. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  19373. // buffers
  19374. const indices = [];
  19375. const vertices = [];
  19376. const uvs = [];
  19377. // helper variables
  19378. const inverseSegments = 1.0 / segments;
  19379. const vertex = new Vector3();
  19380. const uv = new Vector2();
  19381. // generate vertices and uvs
  19382. for ( let i = 0; i <= segments; i ++ ) {
  19383. const phi = phiStart + i * inverseSegments * phiLength;
  19384. const sin = Math.sin( phi );
  19385. const cos = Math.cos( phi );
  19386. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  19387. // vertex
  19388. vertex.x = points[ j ].x * sin;
  19389. vertex.y = points[ j ].y;
  19390. vertex.z = points[ j ].x * cos;
  19391. vertices.push( vertex.x, vertex.y, vertex.z );
  19392. // uv
  19393. uv.x = i / segments;
  19394. uv.y = j / ( points.length - 1 );
  19395. uvs.push( uv.x, uv.y );
  19396. }
  19397. }
  19398. // indices
  19399. for ( let i = 0; i < segments; i ++ ) {
  19400. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  19401. const base = j + i * points.length;
  19402. const a = base;
  19403. const b = base + points.length;
  19404. const c = base + points.length + 1;
  19405. const d = base + 1;
  19406. // faces
  19407. indices.push( a, b, d );
  19408. indices.push( b, c, d );
  19409. }
  19410. }
  19411. // build geometry
  19412. this.setIndex( indices );
  19413. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19414. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19415. // generate normals
  19416. this.computeVertexNormals();
  19417. // if the geometry is closed, we need to average the normals along the seam.
  19418. // because the corresponding vertices are identical (but still have different UVs).
  19419. if ( phiLength === Math.PI * 2 ) {
  19420. const normals = this.attributes.normal.array;
  19421. const n1 = new Vector3();
  19422. const n2 = new Vector3();
  19423. const n = new Vector3();
  19424. // this is the buffer offset for the last line of vertices
  19425. const base = segments * points.length * 3;
  19426. for ( let i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  19427. // select the normal of the vertex in the first line
  19428. n1.x = normals[ j + 0 ];
  19429. n1.y = normals[ j + 1 ];
  19430. n1.z = normals[ j + 2 ];
  19431. // select the normal of the vertex in the last line
  19432. n2.x = normals[ base + j + 0 ];
  19433. n2.y = normals[ base + j + 1 ];
  19434. n2.z = normals[ base + j + 2 ];
  19435. // average normals
  19436. n.addVectors( n1, n2 ).normalize();
  19437. // assign the new values to both normals
  19438. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  19439. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  19440. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  19441. }
  19442. }
  19443. }
  19444. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19445. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  19446. /**
  19447. * @author jonobr1 / http://jonobr1.com
  19448. * @author Mugen87 / https://github.com/Mugen87
  19449. */
  19450. // ShapeGeometry
  19451. function ShapeGeometry( shapes, curveSegments ) {
  19452. Geometry.call( this );
  19453. this.type = 'ShapeGeometry';
  19454. if ( typeof curveSegments === 'object' ) {
  19455. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  19456. curveSegments = curveSegments.curveSegments;
  19457. }
  19458. this.parameters = {
  19459. shapes: shapes,
  19460. curveSegments: curveSegments
  19461. };
  19462. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19463. this.mergeVertices();
  19464. }
  19465. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  19466. ShapeGeometry.prototype.constructor = ShapeGeometry;
  19467. ShapeGeometry.prototype.toJSON = function () {
  19468. const data = Geometry.prototype.toJSON.call( this );
  19469. const shapes = this.parameters.shapes;
  19470. return toJSON$1( shapes, data );
  19471. };
  19472. // ShapeBufferGeometry
  19473. function ShapeBufferGeometry( shapes, curveSegments ) {
  19474. BufferGeometry.call( this );
  19475. this.type = 'ShapeBufferGeometry';
  19476. this.parameters = {
  19477. shapes: shapes,
  19478. curveSegments: curveSegments
  19479. };
  19480. curveSegments = curveSegments || 12;
  19481. // buffers
  19482. const indices = [];
  19483. const vertices = [];
  19484. const normals = [];
  19485. const uvs = [];
  19486. // helper variables
  19487. let groupStart = 0;
  19488. let groupCount = 0;
  19489. // allow single and array values for "shapes" parameter
  19490. if ( Array.isArray( shapes ) === false ) {
  19491. addShape( shapes );
  19492. } else {
  19493. for ( let i = 0; i < shapes.length; i ++ ) {
  19494. addShape( shapes[ i ] );
  19495. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19496. groupStart += groupCount;
  19497. groupCount = 0;
  19498. }
  19499. }
  19500. // build geometry
  19501. this.setIndex( indices );
  19502. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19503. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19504. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19505. // helper functions
  19506. function addShape( shape ) {
  19507. const indexOffset = vertices.length / 3;
  19508. const points = shape.extractPoints( curveSegments );
  19509. let shapeVertices = points.shape;
  19510. const shapeHoles = points.holes;
  19511. // check direction of vertices
  19512. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19513. shapeVertices = shapeVertices.reverse();
  19514. }
  19515. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19516. const shapeHole = shapeHoles[ i ];
  19517. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19518. shapeHoles[ i ] = shapeHole.reverse();
  19519. }
  19520. }
  19521. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19522. // join vertices of inner and outer paths to a single array
  19523. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19524. const shapeHole = shapeHoles[ i ];
  19525. shapeVertices = shapeVertices.concat( shapeHole );
  19526. }
  19527. // vertices, normals, uvs
  19528. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  19529. const vertex = shapeVertices[ i ];
  19530. vertices.push( vertex.x, vertex.y, 0 );
  19531. normals.push( 0, 0, 1 );
  19532. uvs.push( vertex.x, vertex.y ); // world uvs
  19533. }
  19534. // incides
  19535. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  19536. const face = faces[ i ];
  19537. const a = face[ 0 ] + indexOffset;
  19538. const b = face[ 1 ] + indexOffset;
  19539. const c = face[ 2 ] + indexOffset;
  19540. indices.push( a, b, c );
  19541. groupCount += 3;
  19542. }
  19543. }
  19544. }
  19545. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19546. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  19547. ShapeBufferGeometry.prototype.toJSON = function () {
  19548. const data = BufferGeometry.prototype.toJSON.call( this );
  19549. const shapes = this.parameters.shapes;
  19550. return toJSON$1( shapes, data );
  19551. };
  19552. //
  19553. function toJSON$1( shapes, data ) {
  19554. data.shapes = [];
  19555. if ( Array.isArray( shapes ) ) {
  19556. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  19557. const shape = shapes[ i ];
  19558. data.shapes.push( shape.uuid );
  19559. }
  19560. } else {
  19561. data.shapes.push( shapes.uuid );
  19562. }
  19563. return data;
  19564. }
  19565. /**
  19566. * @author WestLangley / http://github.com/WestLangley
  19567. * @author Mugen87 / https://github.com/Mugen87
  19568. */
  19569. function EdgesGeometry( geometry, thresholdAngle ) {
  19570. BufferGeometry.call( this );
  19571. this.type = 'EdgesGeometry';
  19572. this.parameters = {
  19573. thresholdAngle: thresholdAngle
  19574. };
  19575. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19576. // buffer
  19577. const vertices = [];
  19578. // helper variables
  19579. const thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  19580. const edge = [ 0, 0 ], edges = {};
  19581. let edge1, edge2, key;
  19582. const keys = [ 'a', 'b', 'c' ];
  19583. // prepare source geometry
  19584. let geometry2;
  19585. if ( geometry.isBufferGeometry ) {
  19586. geometry2 = new Geometry();
  19587. geometry2.fromBufferGeometry( geometry );
  19588. } else {
  19589. geometry2 = geometry.clone();
  19590. }
  19591. geometry2.mergeVertices();
  19592. geometry2.computeFaceNormals();
  19593. const sourceVertices = geometry2.vertices;
  19594. const faces = geometry2.faces;
  19595. // now create a data structure where each entry represents an edge with its adjoining faces
  19596. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  19597. const face = faces[ i ];
  19598. for ( let j = 0; j < 3; j ++ ) {
  19599. edge1 = face[ keys[ j ] ];
  19600. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19601. edge[ 0 ] = Math.min( edge1, edge2 );
  19602. edge[ 1 ] = Math.max( edge1, edge2 );
  19603. key = edge[ 0 ] + ',' + edge[ 1 ];
  19604. if ( edges[ key ] === undefined ) {
  19605. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  19606. } else {
  19607. edges[ key ].face2 = i;
  19608. }
  19609. }
  19610. }
  19611. // generate vertices
  19612. for ( key in edges ) {
  19613. const e = edges[ key ];
  19614. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  19615. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  19616. let vertex = sourceVertices[ e.index1 ];
  19617. vertices.push( vertex.x, vertex.y, vertex.z );
  19618. vertex = sourceVertices[ e.index2 ];
  19619. vertices.push( vertex.x, vertex.y, vertex.z );
  19620. }
  19621. }
  19622. // build geometry
  19623. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19624. }
  19625. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  19626. EdgesGeometry.prototype.constructor = EdgesGeometry;
  19627. /**
  19628. * @author mrdoob / http://mrdoob.com/
  19629. * @author Mugen87 / https://github.com/Mugen87
  19630. */
  19631. // CylinderGeometry
  19632. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19633. Geometry.call( this );
  19634. this.type = 'CylinderGeometry';
  19635. this.parameters = {
  19636. radiusTop: radiusTop,
  19637. radiusBottom: radiusBottom,
  19638. height: height,
  19639. radialSegments: radialSegments,
  19640. heightSegments: heightSegments,
  19641. openEnded: openEnded,
  19642. thetaStart: thetaStart,
  19643. thetaLength: thetaLength
  19644. };
  19645. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  19646. this.mergeVertices();
  19647. }
  19648. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  19649. CylinderGeometry.prototype.constructor = CylinderGeometry;
  19650. // CylinderBufferGeometry
  19651. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19652. BufferGeometry.call( this );
  19653. this.type = 'CylinderBufferGeometry';
  19654. this.parameters = {
  19655. radiusTop: radiusTop,
  19656. radiusBottom: radiusBottom,
  19657. height: height,
  19658. radialSegments: radialSegments,
  19659. heightSegments: heightSegments,
  19660. openEnded: openEnded,
  19661. thetaStart: thetaStart,
  19662. thetaLength: thetaLength
  19663. };
  19664. const scope = this;
  19665. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  19666. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  19667. height = height || 1;
  19668. radialSegments = Math.floor( radialSegments ) || 8;
  19669. heightSegments = Math.floor( heightSegments ) || 1;
  19670. openEnded = openEnded !== undefined ? openEnded : false;
  19671. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  19672. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19673. // buffers
  19674. const indices = [];
  19675. const vertices = [];
  19676. const normals = [];
  19677. const uvs = [];
  19678. // helper variables
  19679. let index = 0;
  19680. const indexArray = [];
  19681. const halfHeight = height / 2;
  19682. let groupStart = 0;
  19683. // generate geometry
  19684. generateTorso();
  19685. if ( openEnded === false ) {
  19686. if ( radiusTop > 0 ) generateCap( true );
  19687. if ( radiusBottom > 0 ) generateCap( false );
  19688. }
  19689. // build geometry
  19690. this.setIndex( indices );
  19691. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19692. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19693. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19694. function generateTorso() {
  19695. const normal = new Vector3();
  19696. const vertex = new Vector3();
  19697. let groupCount = 0;
  19698. // this will be used to calculate the normal
  19699. const slope = ( radiusBottom - radiusTop ) / height;
  19700. // generate vertices, normals and uvs
  19701. for ( let y = 0; y <= heightSegments; y ++ ) {
  19702. const indexRow = [];
  19703. const v = y / heightSegments;
  19704. // calculate the radius of the current row
  19705. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19706. for ( let x = 0; x <= radialSegments; x ++ ) {
  19707. const u = x / radialSegments;
  19708. const theta = u * thetaLength + thetaStart;
  19709. const sinTheta = Math.sin( theta );
  19710. const cosTheta = Math.cos( theta );
  19711. // vertex
  19712. vertex.x = radius * sinTheta;
  19713. vertex.y = - v * height + halfHeight;
  19714. vertex.z = radius * cosTheta;
  19715. vertices.push( vertex.x, vertex.y, vertex.z );
  19716. // normal
  19717. normal.set( sinTheta, slope, cosTheta ).normalize();
  19718. normals.push( normal.x, normal.y, normal.z );
  19719. // uv
  19720. uvs.push( u, 1 - v );
  19721. // save index of vertex in respective row
  19722. indexRow.push( index ++ );
  19723. }
  19724. // now save vertices of the row in our index array
  19725. indexArray.push( indexRow );
  19726. }
  19727. // generate indices
  19728. for ( let x = 0; x < radialSegments; x ++ ) {
  19729. for ( let y = 0; y < heightSegments; y ++ ) {
  19730. // we use the index array to access the correct indices
  19731. const a = indexArray[ y ][ x ];
  19732. const b = indexArray[ y + 1 ][ x ];
  19733. const c = indexArray[ y + 1 ][ x + 1 ];
  19734. const d = indexArray[ y ][ x + 1 ];
  19735. // faces
  19736. indices.push( a, b, d );
  19737. indices.push( b, c, d );
  19738. // update group counter
  19739. groupCount += 6;
  19740. }
  19741. }
  19742. // add a group to the geometry. this will ensure multi material support
  19743. scope.addGroup( groupStart, groupCount, 0 );
  19744. // calculate new start value for groups
  19745. groupStart += groupCount;
  19746. }
  19747. function generateCap( top ) {
  19748. let centerIndexStart, centerIndexEnd;
  19749. const uv = new Vector2();
  19750. const vertex = new Vector3();
  19751. let groupCount = 0;
  19752. const radius = ( top === true ) ? radiusTop : radiusBottom;
  19753. const sign = ( top === true ) ? 1 : - 1;
  19754. // save the index of the first center vertex
  19755. centerIndexStart = index;
  19756. // first we generate the center vertex data of the cap.
  19757. // because the geometry needs one set of uvs per face,
  19758. // we must generate a center vertex per face/segment
  19759. for ( let x = 1; x <= radialSegments; x ++ ) {
  19760. // vertex
  19761. vertices.push( 0, halfHeight * sign, 0 );
  19762. // normal
  19763. normals.push( 0, sign, 0 );
  19764. // uv
  19765. uvs.push( 0.5, 0.5 );
  19766. // increase index
  19767. index ++;
  19768. }
  19769. // save the index of the last center vertex
  19770. centerIndexEnd = index;
  19771. // now we generate the surrounding vertices, normals and uvs
  19772. for ( let x = 0; x <= radialSegments; x ++ ) {
  19773. const u = x / radialSegments;
  19774. const theta = u * thetaLength + thetaStart;
  19775. const cosTheta = Math.cos( theta );
  19776. const sinTheta = Math.sin( theta );
  19777. // vertex
  19778. vertex.x = radius * sinTheta;
  19779. vertex.y = halfHeight * sign;
  19780. vertex.z = radius * cosTheta;
  19781. vertices.push( vertex.x, vertex.y, vertex.z );
  19782. // normal
  19783. normals.push( 0, sign, 0 );
  19784. // uv
  19785. uv.x = ( cosTheta * 0.5 ) + 0.5;
  19786. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  19787. uvs.push( uv.x, uv.y );
  19788. // increase index
  19789. index ++;
  19790. }
  19791. // generate indices
  19792. for ( let x = 0; x < radialSegments; x ++ ) {
  19793. const c = centerIndexStart + x;
  19794. const i = centerIndexEnd + x;
  19795. if ( top === true ) {
  19796. // face top
  19797. indices.push( i, i + 1, c );
  19798. } else {
  19799. // face bottom
  19800. indices.push( i + 1, i, c );
  19801. }
  19802. groupCount += 3;
  19803. }
  19804. // add a group to the geometry. this will ensure multi material support
  19805. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  19806. // calculate new start value for groups
  19807. groupStart += groupCount;
  19808. }
  19809. }
  19810. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19811. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  19812. /**
  19813. * @author abelnation / http://github.com/abelnation
  19814. */
  19815. // ConeGeometry
  19816. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19817. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19818. this.type = 'ConeGeometry';
  19819. this.parameters = {
  19820. radius: radius,
  19821. height: height,
  19822. radialSegments: radialSegments,
  19823. heightSegments: heightSegments,
  19824. openEnded: openEnded,
  19825. thetaStart: thetaStart,
  19826. thetaLength: thetaLength
  19827. };
  19828. }
  19829. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  19830. ConeGeometry.prototype.constructor = ConeGeometry;
  19831. // ConeBufferGeometry
  19832. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19833. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  19834. this.type = 'ConeBufferGeometry';
  19835. this.parameters = {
  19836. radius: radius,
  19837. height: height,
  19838. radialSegments: radialSegments,
  19839. heightSegments: heightSegments,
  19840. openEnded: openEnded,
  19841. thetaStart: thetaStart,
  19842. thetaLength: thetaLength
  19843. };
  19844. }
  19845. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  19846. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  19847. /**
  19848. * @author benaadams / https://twitter.com/ben_a_adams
  19849. * @author Mugen87 / https://github.com/Mugen87
  19850. * @author hughes
  19851. */
  19852. // CircleGeometry
  19853. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  19854. Geometry.call( this );
  19855. this.type = 'CircleGeometry';
  19856. this.parameters = {
  19857. radius: radius,
  19858. segments: segments,
  19859. thetaStart: thetaStart,
  19860. thetaLength: thetaLength
  19861. };
  19862. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19863. this.mergeVertices();
  19864. }
  19865. CircleGeometry.prototype = Object.create( Geometry.prototype );
  19866. CircleGeometry.prototype.constructor = CircleGeometry;
  19867. // CircleBufferGeometry
  19868. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  19869. BufferGeometry.call( this );
  19870. this.type = 'CircleBufferGeometry';
  19871. this.parameters = {
  19872. radius: radius,
  19873. segments: segments,
  19874. thetaStart: thetaStart,
  19875. thetaLength: thetaLength
  19876. };
  19877. radius = radius || 1;
  19878. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19879. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19880. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19881. // buffers
  19882. const indices = [];
  19883. const vertices = [];
  19884. const normals = [];
  19885. const uvs = [];
  19886. // helper variables
  19887. const vertex = new Vector3();
  19888. const uv = new Vector2();
  19889. // center point
  19890. vertices.push( 0, 0, 0 );
  19891. normals.push( 0, 0, 1 );
  19892. uvs.push( 0.5, 0.5 );
  19893. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  19894. const segment = thetaStart + s / segments * thetaLength;
  19895. // vertex
  19896. vertex.x = radius * Math.cos( segment );
  19897. vertex.y = radius * Math.sin( segment );
  19898. vertices.push( vertex.x, vertex.y, vertex.z );
  19899. // normal
  19900. normals.push( 0, 0, 1 );
  19901. // uvs
  19902. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19903. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19904. uvs.push( uv.x, uv.y );
  19905. }
  19906. // indices
  19907. for ( let i = 1; i <= segments; i ++ ) {
  19908. indices.push( i, i + 1, 0 );
  19909. }
  19910. // build geometry
  19911. this.setIndex( indices );
  19912. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19913. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19914. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19915. }
  19916. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19917. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19918. var Geometries = /*#__PURE__*/Object.freeze({
  19919. __proto__: null,
  19920. WireframeGeometry: WireframeGeometry,
  19921. ParametricGeometry: ParametricGeometry,
  19922. ParametricBufferGeometry: ParametricBufferGeometry,
  19923. TetrahedronGeometry: TetrahedronGeometry,
  19924. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19925. OctahedronGeometry: OctahedronGeometry,
  19926. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19927. IcosahedronGeometry: IcosahedronGeometry,
  19928. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19929. DodecahedronGeometry: DodecahedronGeometry,
  19930. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19931. PolyhedronGeometry: PolyhedronGeometry,
  19932. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19933. TubeGeometry: TubeGeometry,
  19934. TubeBufferGeometry: TubeBufferGeometry,
  19935. TorusKnotGeometry: TorusKnotGeometry,
  19936. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19937. TorusGeometry: TorusGeometry,
  19938. TorusBufferGeometry: TorusBufferGeometry,
  19939. TextGeometry: TextGeometry,
  19940. TextBufferGeometry: TextBufferGeometry,
  19941. SphereGeometry: SphereGeometry,
  19942. SphereBufferGeometry: SphereBufferGeometry,
  19943. RingGeometry: RingGeometry,
  19944. RingBufferGeometry: RingBufferGeometry,
  19945. PlaneGeometry: PlaneGeometry,
  19946. PlaneBufferGeometry: PlaneBufferGeometry,
  19947. LatheGeometry: LatheGeometry,
  19948. LatheBufferGeometry: LatheBufferGeometry,
  19949. ShapeGeometry: ShapeGeometry,
  19950. ShapeBufferGeometry: ShapeBufferGeometry,
  19951. ExtrudeGeometry: ExtrudeGeometry,
  19952. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19953. EdgesGeometry: EdgesGeometry,
  19954. ConeGeometry: ConeGeometry,
  19955. ConeBufferGeometry: ConeBufferGeometry,
  19956. CylinderGeometry: CylinderGeometry,
  19957. CylinderBufferGeometry: CylinderBufferGeometry,
  19958. CircleGeometry: CircleGeometry,
  19959. CircleBufferGeometry: CircleBufferGeometry,
  19960. BoxGeometry: BoxGeometry,
  19961. BoxBufferGeometry: BoxBufferGeometry
  19962. });
  19963. /**
  19964. * @author mrdoob / http://mrdoob.com/
  19965. *
  19966. * parameters = {
  19967. * color: <THREE.Color>
  19968. * }
  19969. */
  19970. function ShadowMaterial( parameters ) {
  19971. Material.call( this );
  19972. this.type = 'ShadowMaterial';
  19973. this.color = new Color( 0x000000 );
  19974. this.transparent = true;
  19975. this.setValues( parameters );
  19976. }
  19977. ShadowMaterial.prototype = Object.create( Material.prototype );
  19978. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19979. ShadowMaterial.prototype.isShadowMaterial = true;
  19980. ShadowMaterial.prototype.copy = function ( source ) {
  19981. Material.prototype.copy.call( this, source );
  19982. this.color.copy( source.color );
  19983. return this;
  19984. };
  19985. /**
  19986. * @author mrdoob / http://mrdoob.com/
  19987. */
  19988. function RawShaderMaterial( parameters ) {
  19989. ShaderMaterial.call( this, parameters );
  19990. this.type = 'RawShaderMaterial';
  19991. }
  19992. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19993. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19994. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19995. /**
  19996. * @author WestLangley / http://github.com/WestLangley
  19997. *
  19998. * parameters = {
  19999. * color: <hex>,
  20000. * roughness: <float>,
  20001. * metalness: <float>,
  20002. * opacity: <float>,
  20003. *
  20004. * map: new THREE.Texture( <Image> ),
  20005. *
  20006. * lightMap: new THREE.Texture( <Image> ),
  20007. * lightMapIntensity: <float>
  20008. *
  20009. * aoMap: new THREE.Texture( <Image> ),
  20010. * aoMapIntensity: <float>
  20011. *
  20012. * emissive: <hex>,
  20013. * emissiveIntensity: <float>
  20014. * emissiveMap: new THREE.Texture( <Image> ),
  20015. *
  20016. * bumpMap: new THREE.Texture( <Image> ),
  20017. * bumpScale: <float>,
  20018. *
  20019. * normalMap: new THREE.Texture( <Image> ),
  20020. * normalMapType: THREE.TangentSpaceNormalMap,
  20021. * normalScale: <Vector2>,
  20022. *
  20023. * displacementMap: new THREE.Texture( <Image> ),
  20024. * displacementScale: <float>,
  20025. * displacementBias: <float>,
  20026. *
  20027. * roughnessMap: new THREE.Texture( <Image> ),
  20028. *
  20029. * metalnessMap: new THREE.Texture( <Image> ),
  20030. *
  20031. * alphaMap: new THREE.Texture( <Image> ),
  20032. *
  20033. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20034. * envMapIntensity: <float>
  20035. *
  20036. * refractionRatio: <float>,
  20037. *
  20038. * wireframe: <boolean>,
  20039. * wireframeLinewidth: <float>,
  20040. *
  20041. * skinning: <bool>,
  20042. * morphTargets: <bool>,
  20043. * morphNormals: <bool>
  20044. * }
  20045. */
  20046. function MeshStandardMaterial( parameters ) {
  20047. Material.call( this );
  20048. this.defines = { 'STANDARD': '' };
  20049. this.type = 'MeshStandardMaterial';
  20050. this.color = new Color( 0xffffff ); // diffuse
  20051. this.roughness = 1.0;
  20052. this.metalness = 0.0;
  20053. this.map = null;
  20054. this.lightMap = null;
  20055. this.lightMapIntensity = 1.0;
  20056. this.aoMap = null;
  20057. this.aoMapIntensity = 1.0;
  20058. this.emissive = new Color( 0x000000 );
  20059. this.emissiveIntensity = 1.0;
  20060. this.emissiveMap = null;
  20061. this.bumpMap = null;
  20062. this.bumpScale = 1;
  20063. this.normalMap = null;
  20064. this.normalMapType = TangentSpaceNormalMap;
  20065. this.normalScale = new Vector2( 1, 1 );
  20066. this.displacementMap = null;
  20067. this.displacementScale = 1;
  20068. this.displacementBias = 0;
  20069. this.roughnessMap = null;
  20070. this.metalnessMap = null;
  20071. this.alphaMap = null;
  20072. this.envMap = null;
  20073. this.envMapIntensity = 1.0;
  20074. this.refractionRatio = 0.98;
  20075. this.wireframe = false;
  20076. this.wireframeLinewidth = 1;
  20077. this.wireframeLinecap = 'round';
  20078. this.wireframeLinejoin = 'round';
  20079. this.skinning = false;
  20080. this.morphTargets = false;
  20081. this.morphNormals = false;
  20082. this.vertexTangents = false;
  20083. this.setValues( parameters );
  20084. }
  20085. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  20086. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  20087. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  20088. MeshStandardMaterial.prototype.copy = function ( source ) {
  20089. Material.prototype.copy.call( this, source );
  20090. this.defines = { 'STANDARD': '' };
  20091. this.color.copy( source.color );
  20092. this.roughness = source.roughness;
  20093. this.metalness = source.metalness;
  20094. this.map = source.map;
  20095. this.lightMap = source.lightMap;
  20096. this.lightMapIntensity = source.lightMapIntensity;
  20097. this.aoMap = source.aoMap;
  20098. this.aoMapIntensity = source.aoMapIntensity;
  20099. this.emissive.copy( source.emissive );
  20100. this.emissiveMap = source.emissiveMap;
  20101. this.emissiveIntensity = source.emissiveIntensity;
  20102. this.bumpMap = source.bumpMap;
  20103. this.bumpScale = source.bumpScale;
  20104. this.normalMap = source.normalMap;
  20105. this.normalMapType = source.normalMapType;
  20106. this.normalScale.copy( source.normalScale );
  20107. this.displacementMap = source.displacementMap;
  20108. this.displacementScale = source.displacementScale;
  20109. this.displacementBias = source.displacementBias;
  20110. this.roughnessMap = source.roughnessMap;
  20111. this.metalnessMap = source.metalnessMap;
  20112. this.alphaMap = source.alphaMap;
  20113. this.envMap = source.envMap;
  20114. this.envMapIntensity = source.envMapIntensity;
  20115. this.refractionRatio = source.refractionRatio;
  20116. this.wireframe = source.wireframe;
  20117. this.wireframeLinewidth = source.wireframeLinewidth;
  20118. this.wireframeLinecap = source.wireframeLinecap;
  20119. this.wireframeLinejoin = source.wireframeLinejoin;
  20120. this.skinning = source.skinning;
  20121. this.morphTargets = source.morphTargets;
  20122. this.morphNormals = source.morphNormals;
  20123. this.vertexTangents = source.vertexTangents;
  20124. return this;
  20125. };
  20126. /**
  20127. * @author WestLangley / http://github.com/WestLangley
  20128. *
  20129. * parameters = {
  20130. * clearcoat: <float>,
  20131. * clearcoatMap: new THREE.Texture( <Image> ),
  20132. * clearcoatRoughness: <float>,
  20133. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  20134. * clearcoatNormalScale: <Vector2>,
  20135. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  20136. *
  20137. * reflectivity: <float>,
  20138. *
  20139. * sheen: <Color>,
  20140. *
  20141. * transparency: <float>
  20142. * }
  20143. */
  20144. function MeshPhysicalMaterial( parameters ) {
  20145. MeshStandardMaterial.call( this );
  20146. this.defines = {
  20147. 'STANDARD': '',
  20148. 'PHYSICAL': ''
  20149. };
  20150. this.type = 'MeshPhysicalMaterial';
  20151. this.clearcoat = 0.0;
  20152. this.clearcoatMap = null;
  20153. this.clearcoatRoughness = 0.0;
  20154. this.clearcoatRoughnessMap = null;
  20155. this.clearcoatNormalScale = new Vector2( 1, 1 );
  20156. this.clearcoatNormalMap = null;
  20157. this.reflectivity = 0.5; // maps to F0 = 0.04
  20158. this.sheen = null; // null will disable sheen bsdf
  20159. this.transparency = 0.0;
  20160. this.setValues( parameters );
  20161. }
  20162. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  20163. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20164. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20165. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  20166. MeshStandardMaterial.prototype.copy.call( this, source );
  20167. this.defines = {
  20168. 'STANDARD': '',
  20169. 'PHYSICAL': ''
  20170. };
  20171. this.clearcoat = source.clearcoat;
  20172. this.clearcoatMap = source.clearcoatMap;
  20173. this.clearcoatRoughness = source.clearcoatRoughness;
  20174. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20175. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20176. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  20177. this.reflectivity = source.reflectivity;
  20178. if ( source.sheen ) {
  20179. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  20180. } else {
  20181. this.sheen = null;
  20182. }
  20183. this.transparency = source.transparency;
  20184. return this;
  20185. };
  20186. /**
  20187. * @author mrdoob / http://mrdoob.com/
  20188. * @author alteredq / http://alteredqualia.com/
  20189. *
  20190. * parameters = {
  20191. * color: <hex>,
  20192. * specular: <hex>,
  20193. * shininess: <float>,
  20194. * opacity: <float>,
  20195. *
  20196. * map: new THREE.Texture( <Image> ),
  20197. *
  20198. * lightMap: new THREE.Texture( <Image> ),
  20199. * lightMapIntensity: <float>
  20200. *
  20201. * aoMap: new THREE.Texture( <Image> ),
  20202. * aoMapIntensity: <float>
  20203. *
  20204. * emissive: <hex>,
  20205. * emissiveIntensity: <float>
  20206. * emissiveMap: new THREE.Texture( <Image> ),
  20207. *
  20208. * bumpMap: new THREE.Texture( <Image> ),
  20209. * bumpScale: <float>,
  20210. *
  20211. * normalMap: new THREE.Texture( <Image> ),
  20212. * normalMapType: THREE.TangentSpaceNormalMap,
  20213. * normalScale: <Vector2>,
  20214. *
  20215. * displacementMap: new THREE.Texture( <Image> ),
  20216. * displacementScale: <float>,
  20217. * displacementBias: <float>,
  20218. *
  20219. * specularMap: new THREE.Texture( <Image> ),
  20220. *
  20221. * alphaMap: new THREE.Texture( <Image> ),
  20222. *
  20223. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20224. * combine: THREE.MultiplyOperation,
  20225. * reflectivity: <float>,
  20226. * refractionRatio: <float>,
  20227. *
  20228. * wireframe: <boolean>,
  20229. * wireframeLinewidth: <float>,
  20230. *
  20231. * skinning: <bool>,
  20232. * morphTargets: <bool>,
  20233. * morphNormals: <bool>
  20234. * }
  20235. */
  20236. function MeshPhongMaterial( parameters ) {
  20237. Material.call( this );
  20238. this.type = 'MeshPhongMaterial';
  20239. this.color = new Color( 0xffffff ); // diffuse
  20240. this.specular = new Color( 0x111111 );
  20241. this.shininess = 30;
  20242. this.map = null;
  20243. this.lightMap = null;
  20244. this.lightMapIntensity = 1.0;
  20245. this.aoMap = null;
  20246. this.aoMapIntensity = 1.0;
  20247. this.emissive = new Color( 0x000000 );
  20248. this.emissiveIntensity = 1.0;
  20249. this.emissiveMap = null;
  20250. this.bumpMap = null;
  20251. this.bumpScale = 1;
  20252. this.normalMap = null;
  20253. this.normalMapType = TangentSpaceNormalMap;
  20254. this.normalScale = new Vector2( 1, 1 );
  20255. this.displacementMap = null;
  20256. this.displacementScale = 1;
  20257. this.displacementBias = 0;
  20258. this.specularMap = null;
  20259. this.alphaMap = null;
  20260. this.envMap = null;
  20261. this.combine = MultiplyOperation;
  20262. this.reflectivity = 1;
  20263. this.refractionRatio = 0.98;
  20264. this.wireframe = false;
  20265. this.wireframeLinewidth = 1;
  20266. this.wireframeLinecap = 'round';
  20267. this.wireframeLinejoin = 'round';
  20268. this.skinning = false;
  20269. this.morphTargets = false;
  20270. this.morphNormals = false;
  20271. this.setValues( parameters );
  20272. }
  20273. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  20274. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20275. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20276. MeshPhongMaterial.prototype.copy = function ( source ) {
  20277. Material.prototype.copy.call( this, source );
  20278. this.color.copy( source.color );
  20279. this.specular.copy( source.specular );
  20280. this.shininess = source.shininess;
  20281. this.map = source.map;
  20282. this.lightMap = source.lightMap;
  20283. this.lightMapIntensity = source.lightMapIntensity;
  20284. this.aoMap = source.aoMap;
  20285. this.aoMapIntensity = source.aoMapIntensity;
  20286. this.emissive.copy( source.emissive );
  20287. this.emissiveMap = source.emissiveMap;
  20288. this.emissiveIntensity = source.emissiveIntensity;
  20289. this.bumpMap = source.bumpMap;
  20290. this.bumpScale = source.bumpScale;
  20291. this.normalMap = source.normalMap;
  20292. this.normalMapType = source.normalMapType;
  20293. this.normalScale.copy( source.normalScale );
  20294. this.displacementMap = source.displacementMap;
  20295. this.displacementScale = source.displacementScale;
  20296. this.displacementBias = source.displacementBias;
  20297. this.specularMap = source.specularMap;
  20298. this.alphaMap = source.alphaMap;
  20299. this.envMap = source.envMap;
  20300. this.combine = source.combine;
  20301. this.reflectivity = source.reflectivity;
  20302. this.refractionRatio = source.refractionRatio;
  20303. this.wireframe = source.wireframe;
  20304. this.wireframeLinewidth = source.wireframeLinewidth;
  20305. this.wireframeLinecap = source.wireframeLinecap;
  20306. this.wireframeLinejoin = source.wireframeLinejoin;
  20307. this.skinning = source.skinning;
  20308. this.morphTargets = source.morphTargets;
  20309. this.morphNormals = source.morphNormals;
  20310. return this;
  20311. };
  20312. /**
  20313. * @author takahirox / http://github.com/takahirox
  20314. *
  20315. * parameters = {
  20316. * color: <hex>,
  20317. *
  20318. * map: new THREE.Texture( <Image> ),
  20319. * gradientMap: new THREE.Texture( <Image> ),
  20320. *
  20321. * lightMap: new THREE.Texture( <Image> ),
  20322. * lightMapIntensity: <float>
  20323. *
  20324. * aoMap: new THREE.Texture( <Image> ),
  20325. * aoMapIntensity: <float>
  20326. *
  20327. * emissive: <hex>,
  20328. * emissiveIntensity: <float>
  20329. * emissiveMap: new THREE.Texture( <Image> ),
  20330. *
  20331. * bumpMap: new THREE.Texture( <Image> ),
  20332. * bumpScale: <float>,
  20333. *
  20334. * normalMap: new THREE.Texture( <Image> ),
  20335. * normalMapType: THREE.TangentSpaceNormalMap,
  20336. * normalScale: <Vector2>,
  20337. *
  20338. * displacementMap: new THREE.Texture( <Image> ),
  20339. * displacementScale: <float>,
  20340. * displacementBias: <float>,
  20341. *
  20342. * alphaMap: new THREE.Texture( <Image> ),
  20343. *
  20344. * wireframe: <boolean>,
  20345. * wireframeLinewidth: <float>,
  20346. *
  20347. * skinning: <bool>,
  20348. * morphTargets: <bool>,
  20349. * morphNormals: <bool>
  20350. * }
  20351. */
  20352. function MeshToonMaterial( parameters ) {
  20353. Material.call( this );
  20354. this.defines = { 'TOON': '' };
  20355. this.type = 'MeshToonMaterial';
  20356. this.color = new Color( 0xffffff );
  20357. this.map = null;
  20358. this.gradientMap = null;
  20359. this.lightMap = null;
  20360. this.lightMapIntensity = 1.0;
  20361. this.aoMap = null;
  20362. this.aoMapIntensity = 1.0;
  20363. this.emissive = new Color( 0x000000 );
  20364. this.emissiveIntensity = 1.0;
  20365. this.emissiveMap = null;
  20366. this.bumpMap = null;
  20367. this.bumpScale = 1;
  20368. this.normalMap = null;
  20369. this.normalMapType = TangentSpaceNormalMap;
  20370. this.normalScale = new Vector2( 1, 1 );
  20371. this.displacementMap = null;
  20372. this.displacementScale = 1;
  20373. this.displacementBias = 0;
  20374. this.alphaMap = null;
  20375. this.wireframe = false;
  20376. this.wireframeLinewidth = 1;
  20377. this.wireframeLinecap = 'round';
  20378. this.wireframeLinejoin = 'round';
  20379. this.skinning = false;
  20380. this.morphTargets = false;
  20381. this.morphNormals = false;
  20382. this.setValues( parameters );
  20383. }
  20384. MeshToonMaterial.prototype = Object.create( Material.prototype );
  20385. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20386. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20387. MeshToonMaterial.prototype.copy = function ( source ) {
  20388. Material.prototype.copy.call( this, source );
  20389. this.color.copy( source.color );
  20390. this.map = source.map;
  20391. this.gradientMap = source.gradientMap;
  20392. this.lightMap = source.lightMap;
  20393. this.lightMapIntensity = source.lightMapIntensity;
  20394. this.aoMap = source.aoMap;
  20395. this.aoMapIntensity = source.aoMapIntensity;
  20396. this.emissive.copy( source.emissive );
  20397. this.emissiveMap = source.emissiveMap;
  20398. this.emissiveIntensity = source.emissiveIntensity;
  20399. this.bumpMap = source.bumpMap;
  20400. this.bumpScale = source.bumpScale;
  20401. this.normalMap = source.normalMap;
  20402. this.normalMapType = source.normalMapType;
  20403. this.normalScale.copy( source.normalScale );
  20404. this.displacementMap = source.displacementMap;
  20405. this.displacementScale = source.displacementScale;
  20406. this.displacementBias = source.displacementBias;
  20407. this.alphaMap = source.alphaMap;
  20408. this.wireframe = source.wireframe;
  20409. this.wireframeLinewidth = source.wireframeLinewidth;
  20410. this.wireframeLinecap = source.wireframeLinecap;
  20411. this.wireframeLinejoin = source.wireframeLinejoin;
  20412. this.skinning = source.skinning;
  20413. this.morphTargets = source.morphTargets;
  20414. this.morphNormals = source.morphNormals;
  20415. return this;
  20416. };
  20417. /**
  20418. * @author mrdoob / http://mrdoob.com/
  20419. * @author WestLangley / http://github.com/WestLangley
  20420. *
  20421. * parameters = {
  20422. * opacity: <float>,
  20423. *
  20424. * bumpMap: new THREE.Texture( <Image> ),
  20425. * bumpScale: <float>,
  20426. *
  20427. * normalMap: new THREE.Texture( <Image> ),
  20428. * normalMapType: THREE.TangentSpaceNormalMap,
  20429. * normalScale: <Vector2>,
  20430. *
  20431. * displacementMap: new THREE.Texture( <Image> ),
  20432. * displacementScale: <float>,
  20433. * displacementBias: <float>,
  20434. *
  20435. * wireframe: <boolean>,
  20436. * wireframeLinewidth: <float>
  20437. *
  20438. * skinning: <bool>,
  20439. * morphTargets: <bool>,
  20440. * morphNormals: <bool>
  20441. * }
  20442. */
  20443. function MeshNormalMaterial( parameters ) {
  20444. Material.call( this );
  20445. this.type = 'MeshNormalMaterial';
  20446. this.bumpMap = null;
  20447. this.bumpScale = 1;
  20448. this.normalMap = null;
  20449. this.normalMapType = TangentSpaceNormalMap;
  20450. this.normalScale = new Vector2( 1, 1 );
  20451. this.displacementMap = null;
  20452. this.displacementScale = 1;
  20453. this.displacementBias = 0;
  20454. this.wireframe = false;
  20455. this.wireframeLinewidth = 1;
  20456. this.fog = false;
  20457. this.skinning = false;
  20458. this.morphTargets = false;
  20459. this.morphNormals = false;
  20460. this.setValues( parameters );
  20461. }
  20462. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  20463. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20464. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20465. MeshNormalMaterial.prototype.copy = function ( source ) {
  20466. Material.prototype.copy.call( this, source );
  20467. this.bumpMap = source.bumpMap;
  20468. this.bumpScale = source.bumpScale;
  20469. this.normalMap = source.normalMap;
  20470. this.normalMapType = source.normalMapType;
  20471. this.normalScale.copy( source.normalScale );
  20472. this.displacementMap = source.displacementMap;
  20473. this.displacementScale = source.displacementScale;
  20474. this.displacementBias = source.displacementBias;
  20475. this.wireframe = source.wireframe;
  20476. this.wireframeLinewidth = source.wireframeLinewidth;
  20477. this.skinning = source.skinning;
  20478. this.morphTargets = source.morphTargets;
  20479. this.morphNormals = source.morphNormals;
  20480. return this;
  20481. };
  20482. /**
  20483. * @author mrdoob / http://mrdoob.com/
  20484. * @author alteredq / http://alteredqualia.com/
  20485. *
  20486. * parameters = {
  20487. * color: <hex>,
  20488. * opacity: <float>,
  20489. *
  20490. * map: new THREE.Texture( <Image> ),
  20491. *
  20492. * lightMap: new THREE.Texture( <Image> ),
  20493. * lightMapIntensity: <float>
  20494. *
  20495. * aoMap: new THREE.Texture( <Image> ),
  20496. * aoMapIntensity: <float>
  20497. *
  20498. * emissive: <hex>,
  20499. * emissiveIntensity: <float>
  20500. * emissiveMap: new THREE.Texture( <Image> ),
  20501. *
  20502. * specularMap: new THREE.Texture( <Image> ),
  20503. *
  20504. * alphaMap: new THREE.Texture( <Image> ),
  20505. *
  20506. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20507. * combine: THREE.Multiply,
  20508. * reflectivity: <float>,
  20509. * refractionRatio: <float>,
  20510. *
  20511. * wireframe: <boolean>,
  20512. * wireframeLinewidth: <float>,
  20513. *
  20514. * skinning: <bool>,
  20515. * morphTargets: <bool>,
  20516. * morphNormals: <bool>
  20517. * }
  20518. */
  20519. function MeshLambertMaterial( parameters ) {
  20520. Material.call( this );
  20521. this.type = 'MeshLambertMaterial';
  20522. this.color = new Color( 0xffffff ); // diffuse
  20523. this.map = null;
  20524. this.lightMap = null;
  20525. this.lightMapIntensity = 1.0;
  20526. this.aoMap = null;
  20527. this.aoMapIntensity = 1.0;
  20528. this.emissive = new Color( 0x000000 );
  20529. this.emissiveIntensity = 1.0;
  20530. this.emissiveMap = null;
  20531. this.specularMap = null;
  20532. this.alphaMap = null;
  20533. this.envMap = null;
  20534. this.combine = MultiplyOperation;
  20535. this.reflectivity = 1;
  20536. this.refractionRatio = 0.98;
  20537. this.wireframe = false;
  20538. this.wireframeLinewidth = 1;
  20539. this.wireframeLinecap = 'round';
  20540. this.wireframeLinejoin = 'round';
  20541. this.skinning = false;
  20542. this.morphTargets = false;
  20543. this.morphNormals = false;
  20544. this.setValues( parameters );
  20545. }
  20546. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  20547. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20548. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20549. MeshLambertMaterial.prototype.copy = function ( source ) {
  20550. Material.prototype.copy.call( this, source );
  20551. this.color.copy( source.color );
  20552. this.map = source.map;
  20553. this.lightMap = source.lightMap;
  20554. this.lightMapIntensity = source.lightMapIntensity;
  20555. this.aoMap = source.aoMap;
  20556. this.aoMapIntensity = source.aoMapIntensity;
  20557. this.emissive.copy( source.emissive );
  20558. this.emissiveMap = source.emissiveMap;
  20559. this.emissiveIntensity = source.emissiveIntensity;
  20560. this.specularMap = source.specularMap;
  20561. this.alphaMap = source.alphaMap;
  20562. this.envMap = source.envMap;
  20563. this.combine = source.combine;
  20564. this.reflectivity = source.reflectivity;
  20565. this.refractionRatio = source.refractionRatio;
  20566. this.wireframe = source.wireframe;
  20567. this.wireframeLinewidth = source.wireframeLinewidth;
  20568. this.wireframeLinecap = source.wireframeLinecap;
  20569. this.wireframeLinejoin = source.wireframeLinejoin;
  20570. this.skinning = source.skinning;
  20571. this.morphTargets = source.morphTargets;
  20572. this.morphNormals = source.morphNormals;
  20573. return this;
  20574. };
  20575. /**
  20576. * @author WestLangley / http://github.com/WestLangley
  20577. *
  20578. * parameters = {
  20579. * color: <hex>,
  20580. * opacity: <float>,
  20581. *
  20582. * matcap: new THREE.Texture( <Image> ),
  20583. *
  20584. * map: new THREE.Texture( <Image> ),
  20585. *
  20586. * bumpMap: new THREE.Texture( <Image> ),
  20587. * bumpScale: <float>,
  20588. *
  20589. * normalMap: new THREE.Texture( <Image> ),
  20590. * normalMapType: THREE.TangentSpaceNormalMap,
  20591. * normalScale: <Vector2>,
  20592. *
  20593. * displacementMap: new THREE.Texture( <Image> ),
  20594. * displacementScale: <float>,
  20595. * displacementBias: <float>,
  20596. *
  20597. * alphaMap: new THREE.Texture( <Image> ),
  20598. *
  20599. * skinning: <bool>,
  20600. * morphTargets: <bool>,
  20601. * morphNormals: <bool>
  20602. * }
  20603. */
  20604. function MeshMatcapMaterial( parameters ) {
  20605. Material.call( this );
  20606. this.defines = { 'MATCAP': '' };
  20607. this.type = 'MeshMatcapMaterial';
  20608. this.color = new Color( 0xffffff ); // diffuse
  20609. this.matcap = null;
  20610. this.map = null;
  20611. this.bumpMap = null;
  20612. this.bumpScale = 1;
  20613. this.normalMap = null;
  20614. this.normalMapType = TangentSpaceNormalMap;
  20615. this.normalScale = new Vector2( 1, 1 );
  20616. this.displacementMap = null;
  20617. this.displacementScale = 1;
  20618. this.displacementBias = 0;
  20619. this.alphaMap = null;
  20620. this.skinning = false;
  20621. this.morphTargets = false;
  20622. this.morphNormals = false;
  20623. this.setValues( parameters );
  20624. }
  20625. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20626. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20627. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20628. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20629. Material.prototype.copy.call( this, source );
  20630. this.defines = { 'MATCAP': '' };
  20631. this.color.copy( source.color );
  20632. this.matcap = source.matcap;
  20633. this.map = source.map;
  20634. this.bumpMap = source.bumpMap;
  20635. this.bumpScale = source.bumpScale;
  20636. this.normalMap = source.normalMap;
  20637. this.normalMapType = source.normalMapType;
  20638. this.normalScale.copy( source.normalScale );
  20639. this.displacementMap = source.displacementMap;
  20640. this.displacementScale = source.displacementScale;
  20641. this.displacementBias = source.displacementBias;
  20642. this.alphaMap = source.alphaMap;
  20643. this.skinning = source.skinning;
  20644. this.morphTargets = source.morphTargets;
  20645. this.morphNormals = source.morphNormals;
  20646. return this;
  20647. };
  20648. /**
  20649. * @author alteredq / http://alteredqualia.com/
  20650. *
  20651. * parameters = {
  20652. * color: <hex>,
  20653. * opacity: <float>,
  20654. *
  20655. * linewidth: <float>,
  20656. *
  20657. * scale: <float>,
  20658. * dashSize: <float>,
  20659. * gapSize: <float>
  20660. * }
  20661. */
  20662. function LineDashedMaterial( parameters ) {
  20663. LineBasicMaterial.call( this );
  20664. this.type = 'LineDashedMaterial';
  20665. this.scale = 1;
  20666. this.dashSize = 3;
  20667. this.gapSize = 1;
  20668. this.setValues( parameters );
  20669. }
  20670. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20671. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20672. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20673. LineDashedMaterial.prototype.copy = function ( source ) {
  20674. LineBasicMaterial.prototype.copy.call( this, source );
  20675. this.scale = source.scale;
  20676. this.dashSize = source.dashSize;
  20677. this.gapSize = source.gapSize;
  20678. return this;
  20679. };
  20680. var Materials = /*#__PURE__*/Object.freeze({
  20681. __proto__: null,
  20682. ShadowMaterial: ShadowMaterial,
  20683. SpriteMaterial: SpriteMaterial,
  20684. RawShaderMaterial: RawShaderMaterial,
  20685. ShaderMaterial: ShaderMaterial,
  20686. PointsMaterial: PointsMaterial,
  20687. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20688. MeshStandardMaterial: MeshStandardMaterial,
  20689. MeshPhongMaterial: MeshPhongMaterial,
  20690. MeshToonMaterial: MeshToonMaterial,
  20691. MeshNormalMaterial: MeshNormalMaterial,
  20692. MeshLambertMaterial: MeshLambertMaterial,
  20693. MeshDepthMaterial: MeshDepthMaterial,
  20694. MeshDistanceMaterial: MeshDistanceMaterial,
  20695. MeshBasicMaterial: MeshBasicMaterial,
  20696. MeshMatcapMaterial: MeshMatcapMaterial,
  20697. LineDashedMaterial: LineDashedMaterial,
  20698. LineBasicMaterial: LineBasicMaterial,
  20699. Material: Material
  20700. });
  20701. /**
  20702. * @author tschw
  20703. * @author Ben Houston / http://clara.io/
  20704. * @author David Sarno / http://lighthaus.us/
  20705. */
  20706. const AnimationUtils = {
  20707. // same as Array.prototype.slice, but also works on typed arrays
  20708. arraySlice: function ( array, from, to ) {
  20709. if ( AnimationUtils.isTypedArray( array ) ) {
  20710. // in ios9 array.subarray(from, undefined) will return empty array
  20711. // but array.subarray(from) or array.subarray(from, len) is correct
  20712. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20713. }
  20714. return array.slice( from, to );
  20715. },
  20716. // converts an array to a specific type
  20717. convertArray: function ( array, type, forceClone ) {
  20718. if ( ! array || // let 'undefined' and 'null' pass
  20719. ! forceClone && array.constructor === type ) return array;
  20720. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20721. return new type( array ); // create typed array
  20722. }
  20723. return Array.prototype.slice.call( array ); // create Array
  20724. },
  20725. isTypedArray: function ( object ) {
  20726. return ArrayBuffer.isView( object ) &&
  20727. ! ( object instanceof DataView );
  20728. },
  20729. // returns an array by which times and values can be sorted
  20730. getKeyframeOrder: function ( times ) {
  20731. function compareTime( i, j ) {
  20732. return times[ i ] - times[ j ];
  20733. }
  20734. const n = times.length;
  20735. const result = new Array( n );
  20736. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  20737. result.sort( compareTime );
  20738. return result;
  20739. },
  20740. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20741. sortedArray: function ( values, stride, order ) {
  20742. const nValues = values.length;
  20743. const result = new values.constructor( nValues );
  20744. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20745. const srcOffset = order[ i ] * stride;
  20746. for ( let j = 0; j !== stride; ++ j ) {
  20747. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20748. }
  20749. }
  20750. return result;
  20751. },
  20752. // function for parsing AOS keyframe formats
  20753. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20754. let i = 1, key = jsonKeys[ 0 ];
  20755. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20756. key = jsonKeys[ i ++ ];
  20757. }
  20758. if ( key === undefined ) return; // no data
  20759. let value = key[ valuePropertyName ];
  20760. if ( value === undefined ) return; // no data
  20761. if ( Array.isArray( value ) ) {
  20762. do {
  20763. value = key[ valuePropertyName ];
  20764. if ( value !== undefined ) {
  20765. times.push( key.time );
  20766. values.push.apply( values, value ); // push all elements
  20767. }
  20768. key = jsonKeys[ i ++ ];
  20769. } while ( key !== undefined );
  20770. } else if ( value.toArray !== undefined ) {
  20771. // ...assume THREE.Math-ish
  20772. do {
  20773. value = key[ valuePropertyName ];
  20774. if ( value !== undefined ) {
  20775. times.push( key.time );
  20776. value.toArray( values, values.length );
  20777. }
  20778. key = jsonKeys[ i ++ ];
  20779. } while ( key !== undefined );
  20780. } else {
  20781. // otherwise push as-is
  20782. do {
  20783. value = key[ valuePropertyName ];
  20784. if ( value !== undefined ) {
  20785. times.push( key.time );
  20786. values.push( value );
  20787. }
  20788. key = jsonKeys[ i ++ ];
  20789. } while ( key !== undefined );
  20790. }
  20791. },
  20792. subclip: function ( sourceClip, name, startFrame, endFrame, fps ) {
  20793. fps = fps || 30;
  20794. const clip = sourceClip.clone();
  20795. clip.name = name;
  20796. const tracks = [];
  20797. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20798. const track = clip.tracks[ i ];
  20799. const valueSize = track.getValueSize();
  20800. const times = [];
  20801. const values = [];
  20802. for ( let j = 0; j < track.times.length; ++ j ) {
  20803. const frame = track.times[ j ] * fps;
  20804. if ( frame < startFrame || frame >= endFrame ) continue;
  20805. times.push( track.times[ j ] );
  20806. for ( let k = 0; k < valueSize; ++ k ) {
  20807. values.push( track.values[ j * valueSize + k ] );
  20808. }
  20809. }
  20810. if ( times.length === 0 ) continue;
  20811. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  20812. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  20813. tracks.push( track );
  20814. }
  20815. clip.tracks = tracks;
  20816. // find minimum .times value across all tracks in the trimmed clip
  20817. let minStartTime = Infinity;
  20818. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20819. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  20820. minStartTime = clip.tracks[ i ].times[ 0 ];
  20821. }
  20822. }
  20823. // shift all tracks such that clip begins at t=0
  20824. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20825. clip.tracks[ i ].shift( - 1 * minStartTime );
  20826. }
  20827. clip.resetDuration();
  20828. return clip;
  20829. },
  20830. makeClipAdditive: function ( targetClip, referenceFrame, referenceClip, fps ) {
  20831. if ( referenceFrame === undefined ) referenceFrame = 0;
  20832. if ( referenceClip === undefined ) referenceClip = targetClip;
  20833. if ( fps === undefined || fps <= 0 ) fps = 30;
  20834. const numTracks = targetClip.tracks.length;
  20835. const referenceTime = referenceFrame / fps;
  20836. // Make each track's values relative to the values at the reference frame
  20837. for ( let i = 0; i < numTracks; ++ i ) {
  20838. const referenceTrack = referenceClip.tracks[ i ];
  20839. const referenceTrackType = referenceTrack.ValueTypeName;
  20840. // Skip this track if it's non-numeric
  20841. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  20842. // Find the track in the target clip whose name and type matches the reference track
  20843. const targetTrack = targetClip.tracks.find( function ( track ) {
  20844. return track.name === referenceTrack.name
  20845. && track.ValueTypeName === referenceTrackType;
  20846. } );
  20847. if ( targetTrack === undefined ) continue;
  20848. const valueSize = referenceTrack.getValueSize();
  20849. const lastIndex = referenceTrack.times.length - 1;
  20850. let referenceValue;
  20851. // Find the value to subtract out of the track
  20852. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  20853. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20854. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, 0, referenceTrack.valueSize );
  20855. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  20856. // Reference frame is after the last keyframe, so just use the last keyframe
  20857. const startIndex = lastIndex * valueSize;
  20858. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex );
  20859. } else {
  20860. // Interpolate to the reference value
  20861. const interpolant = referenceTrack.createInterpolant();
  20862. interpolant.evaluate( referenceTime );
  20863. referenceValue = interpolant.resultBuffer;
  20864. }
  20865. // Conjugate the quaternion
  20866. if ( referenceTrackType === 'quaternion' ) {
  20867. const referenceQuat = new Quaternion(
  20868. referenceValue[ 0 ],
  20869. referenceValue[ 1 ],
  20870. referenceValue[ 2 ],
  20871. referenceValue[ 3 ]
  20872. ).normalize().conjugate();
  20873. referenceQuat.toArray( referenceValue );
  20874. }
  20875. // Subtract the reference value from all of the track values
  20876. const numTimes = targetTrack.times.length;
  20877. for ( let j = 0; j < numTimes; ++ j ) {
  20878. const valueStart = j * valueSize;
  20879. if ( referenceTrackType === 'quaternion' ) {
  20880. // Multiply the conjugate for quaternion track types
  20881. Quaternion.multiplyQuaternionsFlat(
  20882. targetTrack.values,
  20883. valueStart,
  20884. referenceValue,
  20885. 0,
  20886. targetTrack.values,
  20887. valueStart
  20888. );
  20889. } else {
  20890. // Subtract each value for all other numeric track types
  20891. for ( let k = 0; k < valueSize; ++ k ) {
  20892. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  20893. }
  20894. }
  20895. }
  20896. }
  20897. targetClip.blendMode = AdditiveAnimationBlendMode;
  20898. return targetClip;
  20899. }
  20900. };
  20901. /**
  20902. * Abstract base class of interpolants over parametric samples.
  20903. *
  20904. * The parameter domain is one dimensional, typically the time or a path
  20905. * along a curve defined by the data.
  20906. *
  20907. * The sample values can have any dimensionality and derived classes may
  20908. * apply special interpretations to the data.
  20909. *
  20910. * This class provides the interval seek in a Template Method, deferring
  20911. * the actual interpolation to derived classes.
  20912. *
  20913. * Time complexity is O(1) for linear access crossing at most two points
  20914. * and O(log N) for random access, where N is the number of positions.
  20915. *
  20916. * References:
  20917. *
  20918. * http://www.oodesign.com/template-method-pattern.html
  20919. *
  20920. * @author tschw
  20921. */
  20922. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20923. this.parameterPositions = parameterPositions;
  20924. this._cachedIndex = 0;
  20925. this.resultBuffer = resultBuffer !== undefined ?
  20926. resultBuffer : new sampleValues.constructor( sampleSize );
  20927. this.sampleValues = sampleValues;
  20928. this.valueSize = sampleSize;
  20929. }
  20930. Object.assign( Interpolant.prototype, {
  20931. evaluate: function ( t ) {
  20932. let pp = this.parameterPositions,
  20933. i1 = this._cachedIndex,
  20934. t1 = pp[ i1 ],
  20935. t0 = pp[ i1 - 1 ];
  20936. validate_interval: {
  20937. seek: {
  20938. let right;
  20939. linear_scan: {
  20940. //- See http://jsperf.com/comparison-to-undefined/3
  20941. //- slower code:
  20942. //-
  20943. //- if ( t >= t1 || t1 === undefined ) {
  20944. forward_scan: if ( ! ( t < t1 ) ) {
  20945. for ( let giveUpAt = i1 + 2; ; ) {
  20946. if ( t1 === undefined ) {
  20947. if ( t < t0 ) break forward_scan;
  20948. // after end
  20949. i1 = pp.length;
  20950. this._cachedIndex = i1;
  20951. return this.afterEnd_( i1 - 1, t, t0 );
  20952. }
  20953. if ( i1 === giveUpAt ) break; // this loop
  20954. t0 = t1;
  20955. t1 = pp[ ++ i1 ];
  20956. if ( t < t1 ) {
  20957. // we have arrived at the sought interval
  20958. break seek;
  20959. }
  20960. }
  20961. // prepare binary search on the right side of the index
  20962. right = pp.length;
  20963. break linear_scan;
  20964. }
  20965. //- slower code:
  20966. //- if ( t < t0 || t0 === undefined ) {
  20967. if ( ! ( t >= t0 ) ) {
  20968. // looping?
  20969. const t1global = pp[ 1 ];
  20970. if ( t < t1global ) {
  20971. i1 = 2; // + 1, using the scan for the details
  20972. t0 = t1global;
  20973. }
  20974. // linear reverse scan
  20975. for ( let giveUpAt = i1 - 2; ; ) {
  20976. if ( t0 === undefined ) {
  20977. // before start
  20978. this._cachedIndex = 0;
  20979. return this.beforeStart_( 0, t, t1 );
  20980. }
  20981. if ( i1 === giveUpAt ) break; // this loop
  20982. t1 = t0;
  20983. t0 = pp[ -- i1 - 1 ];
  20984. if ( t >= t0 ) {
  20985. // we have arrived at the sought interval
  20986. break seek;
  20987. }
  20988. }
  20989. // prepare binary search on the left side of the index
  20990. right = i1;
  20991. i1 = 0;
  20992. break linear_scan;
  20993. }
  20994. // the interval is valid
  20995. break validate_interval;
  20996. } // linear scan
  20997. // binary search
  20998. while ( i1 < right ) {
  20999. const mid = ( i1 + right ) >>> 1;
  21000. if ( t < pp[ mid ] ) {
  21001. right = mid;
  21002. } else {
  21003. i1 = mid + 1;
  21004. }
  21005. }
  21006. t1 = pp[ i1 ];
  21007. t0 = pp[ i1 - 1 ];
  21008. // check boundary cases, again
  21009. if ( t0 === undefined ) {
  21010. this._cachedIndex = 0;
  21011. return this.beforeStart_( 0, t, t1 );
  21012. }
  21013. if ( t1 === undefined ) {
  21014. i1 = pp.length;
  21015. this._cachedIndex = i1;
  21016. return this.afterEnd_( i1 - 1, t0, t );
  21017. }
  21018. } // seek
  21019. this._cachedIndex = i1;
  21020. this.intervalChanged_( i1, t0, t1 );
  21021. } // validate_interval
  21022. return this.interpolate_( i1, t0, t, t1 );
  21023. },
  21024. settings: null, // optional, subclass-specific settings structure
  21025. // Note: The indirection allows central control of many interpolants.
  21026. // --- Protected interface
  21027. DefaultSettings_: {},
  21028. getSettings_: function () {
  21029. return this.settings || this.DefaultSettings_;
  21030. },
  21031. copySampleValue_: function ( index ) {
  21032. // copies a sample value to the result buffer
  21033. const result = this.resultBuffer,
  21034. values = this.sampleValues,
  21035. stride = this.valueSize,
  21036. offset = index * stride;
  21037. for ( let i = 0; i !== stride; ++ i ) {
  21038. result[ i ] = values[ offset + i ];
  21039. }
  21040. return result;
  21041. },
  21042. // Template methods for derived classes:
  21043. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  21044. throw new Error( 'call to abstract method' );
  21045. // implementations shall return this.resultBuffer
  21046. },
  21047. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  21048. // empty
  21049. }
  21050. } );
  21051. // DECLARE ALIAS AFTER assign prototype
  21052. Object.assign( Interpolant.prototype, {
  21053. //( 0, t, t0 ), returns this.resultBuffer
  21054. beforeStart_: Interpolant.prototype.copySampleValue_,
  21055. //( N-1, tN-1, t ), returns this.resultBuffer
  21056. afterEnd_: Interpolant.prototype.copySampleValue_,
  21057. } );
  21058. /**
  21059. * Fast and simple cubic spline interpolant.
  21060. *
  21061. * It was derived from a Hermitian construction setting the first derivative
  21062. * at each sample position to the linear slope between neighboring positions
  21063. * over their parameter interval.
  21064. *
  21065. * @author tschw
  21066. */
  21067. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21068. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21069. this._weightPrev = - 0;
  21070. this._offsetPrev = - 0;
  21071. this._weightNext = - 0;
  21072. this._offsetNext = - 0;
  21073. }
  21074. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21075. constructor: CubicInterpolant,
  21076. DefaultSettings_: {
  21077. endingStart: ZeroCurvatureEnding,
  21078. endingEnd: ZeroCurvatureEnding
  21079. },
  21080. intervalChanged_: function ( i1, t0, t1 ) {
  21081. let pp = this.parameterPositions,
  21082. iPrev = i1 - 2,
  21083. iNext = i1 + 1,
  21084. tPrev = pp[ iPrev ],
  21085. tNext = pp[ iNext ];
  21086. if ( tPrev === undefined ) {
  21087. switch ( this.getSettings_().endingStart ) {
  21088. case ZeroSlopeEnding:
  21089. // f'(t0) = 0
  21090. iPrev = i1;
  21091. tPrev = 2 * t0 - t1;
  21092. break;
  21093. case WrapAroundEnding:
  21094. // use the other end of the curve
  21095. iPrev = pp.length - 2;
  21096. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  21097. break;
  21098. default: // ZeroCurvatureEnding
  21099. // f''(t0) = 0 a.k.a. Natural Spline
  21100. iPrev = i1;
  21101. tPrev = t1;
  21102. }
  21103. }
  21104. if ( tNext === undefined ) {
  21105. switch ( this.getSettings_().endingEnd ) {
  21106. case ZeroSlopeEnding:
  21107. // f'(tN) = 0
  21108. iNext = i1;
  21109. tNext = 2 * t1 - t0;
  21110. break;
  21111. case WrapAroundEnding:
  21112. // use the other end of the curve
  21113. iNext = 1;
  21114. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  21115. break;
  21116. default: // ZeroCurvatureEnding
  21117. // f''(tN) = 0, a.k.a. Natural Spline
  21118. iNext = i1 - 1;
  21119. tNext = t0;
  21120. }
  21121. }
  21122. const halfDt = ( t1 - t0 ) * 0.5,
  21123. stride = this.valueSize;
  21124. this._weightPrev = halfDt / ( t0 - tPrev );
  21125. this._weightNext = halfDt / ( tNext - t1 );
  21126. this._offsetPrev = iPrev * stride;
  21127. this._offsetNext = iNext * stride;
  21128. },
  21129. interpolate_: function ( i1, t0, t, t1 ) {
  21130. const result = this.resultBuffer,
  21131. values = this.sampleValues,
  21132. stride = this.valueSize,
  21133. o1 = i1 * stride, o0 = o1 - stride,
  21134. oP = this._offsetPrev, oN = this._offsetNext,
  21135. wP = this._weightPrev, wN = this._weightNext,
  21136. p = ( t - t0 ) / ( t1 - t0 ),
  21137. pp = p * p,
  21138. ppp = pp * p;
  21139. // evaluate polynomials
  21140. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  21141. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  21142. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  21143. const sN = wN * ppp - wN * pp;
  21144. // combine data linearly
  21145. for ( let i = 0; i !== stride; ++ i ) {
  21146. result[ i ] =
  21147. sP * values[ oP + i ] +
  21148. s0 * values[ o0 + i ] +
  21149. s1 * values[ o1 + i ] +
  21150. sN * values[ oN + i ];
  21151. }
  21152. return result;
  21153. }
  21154. } );
  21155. /**
  21156. * @author tschw
  21157. */
  21158. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21159. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21160. }
  21161. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21162. constructor: LinearInterpolant,
  21163. interpolate_: function ( i1, t0, t, t1 ) {
  21164. const result = this.resultBuffer,
  21165. values = this.sampleValues,
  21166. stride = this.valueSize,
  21167. offset1 = i1 * stride,
  21168. offset0 = offset1 - stride,
  21169. weight1 = ( t - t0 ) / ( t1 - t0 ),
  21170. weight0 = 1 - weight1;
  21171. for ( let i = 0; i !== stride; ++ i ) {
  21172. result[ i ] =
  21173. values[ offset0 + i ] * weight0 +
  21174. values[ offset1 + i ] * weight1;
  21175. }
  21176. return result;
  21177. }
  21178. } );
  21179. /**
  21180. *
  21181. * Interpolant that evaluates to the sample value at the position preceeding
  21182. * the parameter.
  21183. *
  21184. * @author tschw
  21185. */
  21186. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21187. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21188. }
  21189. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21190. constructor: DiscreteInterpolant,
  21191. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  21192. return this.copySampleValue_( i1 - 1 );
  21193. }
  21194. } );
  21195. /**
  21196. *
  21197. * A timed sequence of keyframes for a specific property.
  21198. *
  21199. *
  21200. * @author Ben Houston / http://clara.io/
  21201. * @author David Sarno / http://lighthaus.us/
  21202. * @author tschw
  21203. */
  21204. function KeyframeTrack( name, times, values, interpolation ) {
  21205. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  21206. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  21207. this.name = name;
  21208. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  21209. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  21210. this.setInterpolation( interpolation || this.DefaultInterpolation );
  21211. }
  21212. // Static methods
  21213. Object.assign( KeyframeTrack, {
  21214. // Serialization (in static context, because of constructor invocation
  21215. // and automatic invocation of .toJSON):
  21216. toJSON: function ( track ) {
  21217. const trackType = track.constructor;
  21218. let json;
  21219. // derived classes can define a static toJSON method
  21220. if ( trackType.toJSON !== undefined ) {
  21221. json = trackType.toJSON( track );
  21222. } else {
  21223. // by default, we assume the data can be serialized as-is
  21224. json = {
  21225. 'name': track.name,
  21226. 'times': AnimationUtils.convertArray( track.times, Array ),
  21227. 'values': AnimationUtils.convertArray( track.values, Array )
  21228. };
  21229. const interpolation = track.getInterpolation();
  21230. if ( interpolation !== track.DefaultInterpolation ) {
  21231. json.interpolation = interpolation;
  21232. }
  21233. }
  21234. json.type = track.ValueTypeName; // mandatory
  21235. return json;
  21236. }
  21237. } );
  21238. Object.assign( KeyframeTrack.prototype, {
  21239. constructor: KeyframeTrack,
  21240. TimeBufferType: Float32Array,
  21241. ValueBufferType: Float32Array,
  21242. DefaultInterpolation: InterpolateLinear,
  21243. InterpolantFactoryMethodDiscrete: function ( result ) {
  21244. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  21245. },
  21246. InterpolantFactoryMethodLinear: function ( result ) {
  21247. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21248. },
  21249. InterpolantFactoryMethodSmooth: function ( result ) {
  21250. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21251. },
  21252. setInterpolation: function ( interpolation ) {
  21253. let factoryMethod;
  21254. switch ( interpolation ) {
  21255. case InterpolateDiscrete:
  21256. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21257. break;
  21258. case InterpolateLinear:
  21259. factoryMethod = this.InterpolantFactoryMethodLinear;
  21260. break;
  21261. case InterpolateSmooth:
  21262. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21263. break;
  21264. }
  21265. if ( factoryMethod === undefined ) {
  21266. const message = "unsupported interpolation for " +
  21267. this.ValueTypeName + " keyframe track named " + this.name;
  21268. if ( this.createInterpolant === undefined ) {
  21269. // fall back to default, unless the default itself is messed up
  21270. if ( interpolation !== this.DefaultInterpolation ) {
  21271. this.setInterpolation( this.DefaultInterpolation );
  21272. } else {
  21273. throw new Error( message ); // fatal, in this case
  21274. }
  21275. }
  21276. console.warn( 'THREE.KeyframeTrack:', message );
  21277. return this;
  21278. }
  21279. this.createInterpolant = factoryMethod;
  21280. return this;
  21281. },
  21282. getInterpolation: function () {
  21283. switch ( this.createInterpolant ) {
  21284. case this.InterpolantFactoryMethodDiscrete:
  21285. return InterpolateDiscrete;
  21286. case this.InterpolantFactoryMethodLinear:
  21287. return InterpolateLinear;
  21288. case this.InterpolantFactoryMethodSmooth:
  21289. return InterpolateSmooth;
  21290. }
  21291. },
  21292. getValueSize: function () {
  21293. return this.values.length / this.times.length;
  21294. },
  21295. // move all keyframes either forwards or backwards in time
  21296. shift: function ( timeOffset ) {
  21297. if ( timeOffset !== 0.0 ) {
  21298. const times = this.times;
  21299. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  21300. times[ i ] += timeOffset;
  21301. }
  21302. }
  21303. return this;
  21304. },
  21305. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21306. scale: function ( timeScale ) {
  21307. if ( timeScale !== 1.0 ) {
  21308. const times = this.times;
  21309. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  21310. times[ i ] *= timeScale;
  21311. }
  21312. }
  21313. return this;
  21314. },
  21315. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21316. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21317. trim: function ( startTime, endTime ) {
  21318. const times = this.times,
  21319. nKeys = times.length;
  21320. let from = 0,
  21321. to = nKeys - 1;
  21322. while ( from !== nKeys && times[ from ] < startTime ) {
  21323. ++ from;
  21324. }
  21325. while ( to !== - 1 && times[ to ] > endTime ) {
  21326. -- to;
  21327. }
  21328. ++ to; // inclusive -> exclusive bound
  21329. if ( from !== 0 || to !== nKeys ) {
  21330. // empty tracks are forbidden, so keep at least one keyframe
  21331. if ( from >= to ) {
  21332. to = Math.max( to, 1 );
  21333. from = to - 1;
  21334. }
  21335. const stride = this.getValueSize();
  21336. this.times = AnimationUtils.arraySlice( times, from, to );
  21337. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21338. }
  21339. return this;
  21340. },
  21341. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21342. validate: function () {
  21343. let valid = true;
  21344. const valueSize = this.getValueSize();
  21345. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21346. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21347. valid = false;
  21348. }
  21349. const times = this.times,
  21350. values = this.values,
  21351. nKeys = times.length;
  21352. if ( nKeys === 0 ) {
  21353. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21354. valid = false;
  21355. }
  21356. let prevTime = null;
  21357. for ( let i = 0; i !== nKeys; i ++ ) {
  21358. const currTime = times[ i ];
  21359. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21360. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21361. valid = false;
  21362. break;
  21363. }
  21364. if ( prevTime !== null && prevTime > currTime ) {
  21365. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21366. valid = false;
  21367. break;
  21368. }
  21369. prevTime = currTime;
  21370. }
  21371. if ( values !== undefined ) {
  21372. if ( AnimationUtils.isTypedArray( values ) ) {
  21373. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  21374. const value = values[ i ];
  21375. if ( isNaN( value ) ) {
  21376. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21377. valid = false;
  21378. break;
  21379. }
  21380. }
  21381. }
  21382. }
  21383. return valid;
  21384. },
  21385. // removes equivalent sequential keys as common in morph target sequences
  21386. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21387. optimize: function () {
  21388. // times or values may be shared with other tracks, so overwriting is unsafe
  21389. const times = AnimationUtils.arraySlice( this.times ),
  21390. values = AnimationUtils.arraySlice( this.values ),
  21391. stride = this.getValueSize(),
  21392. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21393. lastIndex = times.length - 1;
  21394. let writeIndex = 1;
  21395. for ( let i = 1; i < lastIndex; ++ i ) {
  21396. let keep = false;
  21397. const time = times[ i ];
  21398. const timeNext = times[ i + 1 ];
  21399. // remove adjacent keyframes scheduled at the same time
  21400. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21401. if ( ! smoothInterpolation ) {
  21402. // remove unnecessary keyframes same as their neighbors
  21403. const offset = i * stride,
  21404. offsetP = offset - stride,
  21405. offsetN = offset + stride;
  21406. for ( let j = 0; j !== stride; ++ j ) {
  21407. const value = values[ offset + j ];
  21408. if ( value !== values[ offsetP + j ] ||
  21409. value !== values[ offsetN + j ] ) {
  21410. keep = true;
  21411. break;
  21412. }
  21413. }
  21414. } else {
  21415. keep = true;
  21416. }
  21417. }
  21418. // in-place compaction
  21419. if ( keep ) {
  21420. if ( i !== writeIndex ) {
  21421. times[ writeIndex ] = times[ i ];
  21422. const readOffset = i * stride,
  21423. writeOffset = writeIndex * stride;
  21424. for ( let j = 0; j !== stride; ++ j ) {
  21425. values[ writeOffset + j ] = values[ readOffset + j ];
  21426. }
  21427. }
  21428. ++ writeIndex;
  21429. }
  21430. }
  21431. // flush last keyframe (compaction looks ahead)
  21432. if ( lastIndex > 0 ) {
  21433. times[ writeIndex ] = times[ lastIndex ];
  21434. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21435. values[ writeOffset + j ] = values[ readOffset + j ];
  21436. }
  21437. ++ writeIndex;
  21438. }
  21439. if ( writeIndex !== times.length ) {
  21440. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21441. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21442. } else {
  21443. this.times = times;
  21444. this.values = values;
  21445. }
  21446. return this;
  21447. },
  21448. clone: function () {
  21449. const times = AnimationUtils.arraySlice( this.times, 0 );
  21450. const values = AnimationUtils.arraySlice( this.values, 0 );
  21451. const TypedKeyframeTrack = this.constructor;
  21452. const track = new TypedKeyframeTrack( this.name, times, values );
  21453. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21454. track.createInterpolant = this.createInterpolant;
  21455. return track;
  21456. }
  21457. } );
  21458. /**
  21459. *
  21460. * A Track of Boolean keyframe values.
  21461. *
  21462. *
  21463. * @author Ben Houston / http://clara.io/
  21464. * @author David Sarno / http://lighthaus.us/
  21465. * @author tschw
  21466. */
  21467. function BooleanKeyframeTrack( name, times, values ) {
  21468. KeyframeTrack.call( this, name, times, values );
  21469. }
  21470. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21471. constructor: BooleanKeyframeTrack,
  21472. ValueTypeName: 'bool',
  21473. ValueBufferType: Array,
  21474. DefaultInterpolation: InterpolateDiscrete,
  21475. InterpolantFactoryMethodLinear: undefined,
  21476. InterpolantFactoryMethodSmooth: undefined
  21477. // Note: Actually this track could have a optimized / compressed
  21478. // representation of a single value and a custom interpolant that
  21479. // computes "firstValue ^ isOdd( index )".
  21480. } );
  21481. /**
  21482. *
  21483. * A Track of keyframe values that represent color.
  21484. *
  21485. *
  21486. * @author Ben Houston / http://clara.io/
  21487. * @author David Sarno / http://lighthaus.us/
  21488. * @author tschw
  21489. */
  21490. function ColorKeyframeTrack( name, times, values, interpolation ) {
  21491. KeyframeTrack.call( this, name, times, values, interpolation );
  21492. }
  21493. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21494. constructor: ColorKeyframeTrack,
  21495. ValueTypeName: 'color'
  21496. // ValueBufferType is inherited
  21497. // DefaultInterpolation is inherited
  21498. // Note: Very basic implementation and nothing special yet.
  21499. // However, this is the place for color space parameterization.
  21500. } );
  21501. /**
  21502. *
  21503. * A Track of numeric keyframe values.
  21504. *
  21505. * @author Ben Houston / http://clara.io/
  21506. * @author David Sarno / http://lighthaus.us/
  21507. * @author tschw
  21508. */
  21509. function NumberKeyframeTrack( name, times, values, interpolation ) {
  21510. KeyframeTrack.call( this, name, times, values, interpolation );
  21511. }
  21512. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21513. constructor: NumberKeyframeTrack,
  21514. ValueTypeName: 'number'
  21515. // ValueBufferType is inherited
  21516. // DefaultInterpolation is inherited
  21517. } );
  21518. /**
  21519. * Spherical linear unit quaternion interpolant.
  21520. *
  21521. * @author tschw
  21522. */
  21523. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21524. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21525. }
  21526. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21527. constructor: QuaternionLinearInterpolant,
  21528. interpolate_: function ( i1, t0, t, t1 ) {
  21529. const result = this.resultBuffer,
  21530. values = this.sampleValues,
  21531. stride = this.valueSize,
  21532. alpha = ( t - t0 ) / ( t1 - t0 );
  21533. let offset = i1 * stride;
  21534. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  21535. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  21536. }
  21537. return result;
  21538. }
  21539. } );
  21540. /**
  21541. *
  21542. * A Track of quaternion keyframe values.
  21543. *
  21544. * @author Ben Houston / http://clara.io/
  21545. * @author David Sarno / http://lighthaus.us/
  21546. * @author tschw
  21547. */
  21548. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  21549. KeyframeTrack.call( this, name, times, values, interpolation );
  21550. }
  21551. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21552. constructor: QuaternionKeyframeTrack,
  21553. ValueTypeName: 'quaternion',
  21554. // ValueBufferType is inherited
  21555. DefaultInterpolation: InterpolateLinear,
  21556. InterpolantFactoryMethodLinear: function ( result ) {
  21557. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21558. },
  21559. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21560. } );
  21561. /**
  21562. *
  21563. * A Track that interpolates Strings
  21564. *
  21565. *
  21566. * @author Ben Houston / http://clara.io/
  21567. * @author David Sarno / http://lighthaus.us/
  21568. * @author tschw
  21569. */
  21570. function StringKeyframeTrack( name, times, values, interpolation ) {
  21571. KeyframeTrack.call( this, name, times, values, interpolation );
  21572. }
  21573. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21574. constructor: StringKeyframeTrack,
  21575. ValueTypeName: 'string',
  21576. ValueBufferType: Array,
  21577. DefaultInterpolation: InterpolateDiscrete,
  21578. InterpolantFactoryMethodLinear: undefined,
  21579. InterpolantFactoryMethodSmooth: undefined
  21580. } );
  21581. /**
  21582. *
  21583. * A Track of vectored keyframe values.
  21584. *
  21585. *
  21586. * @author Ben Houston / http://clara.io/
  21587. * @author David Sarno / http://lighthaus.us/
  21588. * @author tschw
  21589. */
  21590. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21591. KeyframeTrack.call( this, name, times, values, interpolation );
  21592. }
  21593. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21594. constructor: VectorKeyframeTrack,
  21595. ValueTypeName: 'vector'
  21596. // ValueBufferType is inherited
  21597. // DefaultInterpolation is inherited
  21598. } );
  21599. /**
  21600. *
  21601. * Reusable set of Tracks that represent an animation.
  21602. *
  21603. * @author Ben Houston / http://clara.io/
  21604. * @author David Sarno / http://lighthaus.us/
  21605. */
  21606. function AnimationClip( name, duration, tracks, blendMode ) {
  21607. this.name = name;
  21608. this.tracks = tracks;
  21609. this.duration = ( duration !== undefined ) ? duration : - 1;
  21610. this.blendMode = ( blendMode !== undefined ) ? blendMode : NormalAnimationBlendMode;
  21611. this.uuid = MathUtils.generateUUID();
  21612. // this means it should figure out its duration by scanning the tracks
  21613. if ( this.duration < 0 ) {
  21614. this.resetDuration();
  21615. }
  21616. }
  21617. function getTrackTypeForValueTypeName( typeName ) {
  21618. switch ( typeName.toLowerCase() ) {
  21619. case 'scalar':
  21620. case 'double':
  21621. case 'float':
  21622. case 'number':
  21623. case 'integer':
  21624. return NumberKeyframeTrack;
  21625. case 'vector':
  21626. case 'vector2':
  21627. case 'vector3':
  21628. case 'vector4':
  21629. return VectorKeyframeTrack;
  21630. case 'color':
  21631. return ColorKeyframeTrack;
  21632. case 'quaternion':
  21633. return QuaternionKeyframeTrack;
  21634. case 'bool':
  21635. case 'boolean':
  21636. return BooleanKeyframeTrack;
  21637. case 'string':
  21638. return StringKeyframeTrack;
  21639. }
  21640. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21641. }
  21642. function parseKeyframeTrack( json ) {
  21643. if ( json.type === undefined ) {
  21644. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21645. }
  21646. const trackType = getTrackTypeForValueTypeName( json.type );
  21647. if ( json.times === undefined ) {
  21648. const times = [], values = [];
  21649. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21650. json.times = times;
  21651. json.values = values;
  21652. }
  21653. // derived classes can define a static parse method
  21654. if ( trackType.parse !== undefined ) {
  21655. return trackType.parse( json );
  21656. } else {
  21657. // by default, we assume a constructor compatible with the base
  21658. return new trackType( json.name, json.times, json.values, json.interpolation );
  21659. }
  21660. }
  21661. Object.assign( AnimationClip, {
  21662. parse: function ( json ) {
  21663. const tracks = [],
  21664. jsonTracks = json.tracks,
  21665. frameTime = 1.0 / ( json.fps || 1.0 );
  21666. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21667. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21668. }
  21669. return new AnimationClip( json.name, json.duration, tracks, json.blendMode );
  21670. },
  21671. toJSON: function ( clip ) {
  21672. const tracks = [],
  21673. clipTracks = clip.tracks;
  21674. const json = {
  21675. 'name': clip.name,
  21676. 'duration': clip.duration,
  21677. 'tracks': tracks,
  21678. 'uuid': clip.uuid,
  21679. 'blendMode': clip.blendMode
  21680. };
  21681. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21682. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21683. }
  21684. return json;
  21685. },
  21686. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21687. const numMorphTargets = morphTargetSequence.length;
  21688. const tracks = [];
  21689. for ( let i = 0; i < numMorphTargets; i ++ ) {
  21690. let times = [];
  21691. let values = [];
  21692. times.push(
  21693. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21694. i,
  21695. ( i + 1 ) % numMorphTargets );
  21696. values.push( 0, 1, 0 );
  21697. const order = AnimationUtils.getKeyframeOrder( times );
  21698. times = AnimationUtils.sortedArray( times, 1, order );
  21699. values = AnimationUtils.sortedArray( values, 1, order );
  21700. // if there is a key at the first frame, duplicate it as the
  21701. // last frame as well for perfect loop.
  21702. if ( ! noLoop && times[ 0 ] === 0 ) {
  21703. times.push( numMorphTargets );
  21704. values.push( values[ 0 ] );
  21705. }
  21706. tracks.push(
  21707. new NumberKeyframeTrack(
  21708. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21709. times, values
  21710. ).scale( 1.0 / fps ) );
  21711. }
  21712. return new AnimationClip( name, - 1, tracks );
  21713. },
  21714. findByName: function ( objectOrClipArray, name ) {
  21715. let clipArray = objectOrClipArray;
  21716. if ( ! Array.isArray( objectOrClipArray ) ) {
  21717. const o = objectOrClipArray;
  21718. clipArray = o.geometry && o.geometry.animations || o.animations;
  21719. }
  21720. for ( let i = 0; i < clipArray.length; i ++ ) {
  21721. if ( clipArray[ i ].name === name ) {
  21722. return clipArray[ i ];
  21723. }
  21724. }
  21725. return null;
  21726. },
  21727. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21728. const animationToMorphTargets = {};
  21729. // tested with https://regex101.com/ on trick sequences
  21730. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21731. const pattern = /^([\w-]*?)([\d]+)$/;
  21732. // sort morph target names into animation groups based
  21733. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21734. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  21735. const morphTarget = morphTargets[ i ];
  21736. const parts = morphTarget.name.match( pattern );
  21737. if ( parts && parts.length > 1 ) {
  21738. const name = parts[ 1 ];
  21739. let animationMorphTargets = animationToMorphTargets[ name ];
  21740. if ( ! animationMorphTargets ) {
  21741. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21742. }
  21743. animationMorphTargets.push( morphTarget );
  21744. }
  21745. }
  21746. const clips = [];
  21747. for ( const name in animationToMorphTargets ) {
  21748. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21749. }
  21750. return clips;
  21751. },
  21752. // parse the animation.hierarchy format
  21753. parseAnimation: function ( animation, bones ) {
  21754. if ( ! animation ) {
  21755. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21756. return null;
  21757. }
  21758. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21759. // only return track if there are actually keys.
  21760. if ( animationKeys.length !== 0 ) {
  21761. const times = [];
  21762. const values = [];
  21763. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21764. // empty keys are filtered out, so check again
  21765. if ( times.length !== 0 ) {
  21766. destTracks.push( new trackType( trackName, times, values ) );
  21767. }
  21768. }
  21769. };
  21770. const tracks = [];
  21771. const clipName = animation.name || 'default';
  21772. const fps = animation.fps || 30;
  21773. const blendMode = animation.blendMode;
  21774. // automatic length determination in AnimationClip.
  21775. let duration = animation.length || - 1;
  21776. const hierarchyTracks = animation.hierarchy || [];
  21777. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  21778. const animationKeys = hierarchyTracks[ h ].keys;
  21779. // skip empty tracks
  21780. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21781. // process morph targets
  21782. if ( animationKeys[ 0 ].morphTargets ) {
  21783. // figure out all morph targets used in this track
  21784. const morphTargetNames = {};
  21785. let k;
  21786. for ( k = 0; k < animationKeys.length; k ++ ) {
  21787. if ( animationKeys[ k ].morphTargets ) {
  21788. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21789. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21790. }
  21791. }
  21792. }
  21793. // create a track for each morph target with all zero
  21794. // morphTargetInfluences except for the keys in which
  21795. // the morphTarget is named.
  21796. for ( const morphTargetName in morphTargetNames ) {
  21797. const times = [];
  21798. const values = [];
  21799. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21800. const animationKey = animationKeys[ k ];
  21801. times.push( animationKey.time );
  21802. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21803. }
  21804. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21805. }
  21806. duration = morphTargetNames.length * ( fps || 1.0 );
  21807. } else {
  21808. // ...assume skeletal animation
  21809. const boneName = '.bones[' + bones[ h ].name + ']';
  21810. addNonemptyTrack(
  21811. VectorKeyframeTrack, boneName + '.position',
  21812. animationKeys, 'pos', tracks );
  21813. addNonemptyTrack(
  21814. QuaternionKeyframeTrack, boneName + '.quaternion',
  21815. animationKeys, 'rot', tracks );
  21816. addNonemptyTrack(
  21817. VectorKeyframeTrack, boneName + '.scale',
  21818. animationKeys, 'scl', tracks );
  21819. }
  21820. }
  21821. if ( tracks.length === 0 ) {
  21822. return null;
  21823. }
  21824. const clip = new AnimationClip( clipName, duration, tracks, blendMode );
  21825. return clip;
  21826. }
  21827. } );
  21828. Object.assign( AnimationClip.prototype, {
  21829. resetDuration: function () {
  21830. const tracks = this.tracks;
  21831. let duration = 0;
  21832. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  21833. const track = this.tracks[ i ];
  21834. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21835. }
  21836. this.duration = duration;
  21837. return this;
  21838. },
  21839. trim: function () {
  21840. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21841. this.tracks[ i ].trim( 0, this.duration );
  21842. }
  21843. return this;
  21844. },
  21845. validate: function () {
  21846. let valid = true;
  21847. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21848. valid = valid && this.tracks[ i ].validate();
  21849. }
  21850. return valid;
  21851. },
  21852. optimize: function () {
  21853. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21854. this.tracks[ i ].optimize();
  21855. }
  21856. return this;
  21857. },
  21858. clone: function () {
  21859. const tracks = [];
  21860. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21861. tracks.push( this.tracks[ i ].clone() );
  21862. }
  21863. return new AnimationClip( this.name, this.duration, tracks, this.blendMode );
  21864. }
  21865. } );
  21866. /**
  21867. * @author mrdoob / http://mrdoob.com/
  21868. */
  21869. const Cache = {
  21870. enabled: false,
  21871. files: {},
  21872. add: function ( key, file ) {
  21873. if ( this.enabled === false ) return;
  21874. // console.log( 'THREE.Cache', 'Adding key:', key );
  21875. this.files[ key ] = file;
  21876. },
  21877. get: function ( key ) {
  21878. if ( this.enabled === false ) return;
  21879. // console.log( 'THREE.Cache', 'Checking key:', key );
  21880. return this.files[ key ];
  21881. },
  21882. remove: function ( key ) {
  21883. delete this.files[ key ];
  21884. },
  21885. clear: function () {
  21886. this.files = {};
  21887. }
  21888. };
  21889. /**
  21890. * @author mrdoob / http://mrdoob.com/
  21891. */
  21892. function LoadingManager( onLoad, onProgress, onError ) {
  21893. const scope = this;
  21894. let isLoading = false;
  21895. let itemsLoaded = 0;
  21896. let itemsTotal = 0;
  21897. let urlModifier = undefined;
  21898. const handlers = [];
  21899. // Refer to #5689 for the reason why we don't set .onStart
  21900. // in the constructor
  21901. this.onStart = undefined;
  21902. this.onLoad = onLoad;
  21903. this.onProgress = onProgress;
  21904. this.onError = onError;
  21905. this.itemStart = function ( url ) {
  21906. itemsTotal ++;
  21907. if ( isLoading === false ) {
  21908. if ( scope.onStart !== undefined ) {
  21909. scope.onStart( url, itemsLoaded, itemsTotal );
  21910. }
  21911. }
  21912. isLoading = true;
  21913. };
  21914. this.itemEnd = function ( url ) {
  21915. itemsLoaded ++;
  21916. if ( scope.onProgress !== undefined ) {
  21917. scope.onProgress( url, itemsLoaded, itemsTotal );
  21918. }
  21919. if ( itemsLoaded === itemsTotal ) {
  21920. isLoading = false;
  21921. if ( scope.onLoad !== undefined ) {
  21922. scope.onLoad();
  21923. }
  21924. }
  21925. };
  21926. this.itemError = function ( url ) {
  21927. if ( scope.onError !== undefined ) {
  21928. scope.onError( url );
  21929. }
  21930. };
  21931. this.resolveURL = function ( url ) {
  21932. if ( urlModifier ) {
  21933. return urlModifier( url );
  21934. }
  21935. return url;
  21936. };
  21937. this.setURLModifier = function ( transform ) {
  21938. urlModifier = transform;
  21939. return this;
  21940. };
  21941. this.addHandler = function ( regex, loader ) {
  21942. handlers.push( regex, loader );
  21943. return this;
  21944. };
  21945. this.removeHandler = function ( regex ) {
  21946. const index = handlers.indexOf( regex );
  21947. if ( index !== - 1 ) {
  21948. handlers.splice( index, 2 );
  21949. }
  21950. return this;
  21951. };
  21952. this.getHandler = function ( file ) {
  21953. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  21954. const regex = handlers[ i ];
  21955. const loader = handlers[ i + 1 ];
  21956. if ( regex.global ) regex.lastIndex = 0; // see #17920
  21957. if ( regex.test( file ) ) {
  21958. return loader;
  21959. }
  21960. }
  21961. return null;
  21962. };
  21963. }
  21964. const DefaultLoadingManager = new LoadingManager();
  21965. /**
  21966. * @author alteredq / http://alteredqualia.com/
  21967. */
  21968. function Loader( manager ) {
  21969. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21970. this.crossOrigin = 'anonymous';
  21971. this.path = '';
  21972. this.resourcePath = '';
  21973. this.requestHeader = {};
  21974. }
  21975. Object.assign( Loader.prototype, {
  21976. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  21977. loadAsync: function ( url, onProgress ) {
  21978. const scope = this;
  21979. return new Promise( function ( resolve, reject ) {
  21980. scope.load( url, resolve, onProgress, reject );
  21981. } );
  21982. },
  21983. parse: function ( /* data */ ) {},
  21984. setCrossOrigin: function ( crossOrigin ) {
  21985. this.crossOrigin = crossOrigin;
  21986. return this;
  21987. },
  21988. setPath: function ( path ) {
  21989. this.path = path;
  21990. return this;
  21991. },
  21992. setResourcePath: function ( resourcePath ) {
  21993. this.resourcePath = resourcePath;
  21994. return this;
  21995. },
  21996. setRequestHeader: function ( requestHeader ) {
  21997. this.requestHeader = requestHeader;
  21998. return this;
  21999. }
  22000. } );
  22001. /**
  22002. * @author mrdoob / http://mrdoob.com/
  22003. */
  22004. const loading = {};
  22005. function FileLoader( manager ) {
  22006. Loader.call( this, manager );
  22007. }
  22008. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22009. constructor: FileLoader,
  22010. load: function ( url, onLoad, onProgress, onError ) {
  22011. if ( url === undefined ) url = '';
  22012. if ( this.path !== undefined ) url = this.path + url;
  22013. url = this.manager.resolveURL( url );
  22014. const scope = this;
  22015. const cached = Cache.get( url );
  22016. if ( cached !== undefined ) {
  22017. scope.manager.itemStart( url );
  22018. setTimeout( function () {
  22019. if ( onLoad ) onLoad( cached );
  22020. scope.manager.itemEnd( url );
  22021. }, 0 );
  22022. return cached;
  22023. }
  22024. // Check if request is duplicate
  22025. if ( loading[ url ] !== undefined ) {
  22026. loading[ url ].push( {
  22027. onLoad: onLoad,
  22028. onProgress: onProgress,
  22029. onError: onError
  22030. } );
  22031. return;
  22032. }
  22033. // Check for data: URI
  22034. const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  22035. const dataUriRegexResult = url.match( dataUriRegex );
  22036. let request;
  22037. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  22038. if ( dataUriRegexResult ) {
  22039. const mimeType = dataUriRegexResult[ 1 ];
  22040. const isBase64 = !! dataUriRegexResult[ 2 ];
  22041. let data = dataUriRegexResult[ 3 ];
  22042. data = decodeURIComponent( data );
  22043. if ( isBase64 ) data = atob( data );
  22044. try {
  22045. let response;
  22046. const responseType = ( this.responseType || '' ).toLowerCase();
  22047. switch ( responseType ) {
  22048. case 'arraybuffer':
  22049. case 'blob':
  22050. const view = new Uint8Array( data.length );
  22051. for ( let i = 0; i < data.length; i ++ ) {
  22052. view[ i ] = data.charCodeAt( i );
  22053. }
  22054. if ( responseType === 'blob' ) {
  22055. response = new Blob( [ view.buffer ], { type: mimeType } );
  22056. } else {
  22057. response = view.buffer;
  22058. }
  22059. break;
  22060. case 'document':
  22061. const parser = new DOMParser();
  22062. response = parser.parseFromString( data, mimeType );
  22063. break;
  22064. case 'json':
  22065. response = JSON.parse( data );
  22066. break;
  22067. default: // 'text' or other
  22068. response = data;
  22069. break;
  22070. }
  22071. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22072. setTimeout( function () {
  22073. if ( onLoad ) onLoad( response );
  22074. scope.manager.itemEnd( url );
  22075. }, 0 );
  22076. } catch ( error ) {
  22077. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  22078. setTimeout( function () {
  22079. if ( onError ) onError( error );
  22080. scope.manager.itemError( url );
  22081. scope.manager.itemEnd( url );
  22082. }, 0 );
  22083. }
  22084. } else {
  22085. // Initialise array for duplicate requests
  22086. loading[ url ] = [];
  22087. loading[ url ].push( {
  22088. onLoad: onLoad,
  22089. onProgress: onProgress,
  22090. onError: onError
  22091. } );
  22092. request = new XMLHttpRequest();
  22093. request.open( 'GET', url, true );
  22094. request.addEventListener( 'load', function ( event ) {
  22095. const response = this.response;
  22096. const callbacks = loading[ url ];
  22097. delete loading[ url ];
  22098. if ( this.status === 200 || this.status === 0 ) {
  22099. // Some browsers return HTTP Status 0 when using non-http protocol
  22100. // e.g. 'file://' or 'data://'. Handle as success.
  22101. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  22102. // Add to cache only on HTTP success, so that we do not cache
  22103. // error response bodies as proper responses to requests.
  22104. Cache.add( url, response );
  22105. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  22106. const callback = callbacks[ i ];
  22107. if ( callback.onLoad ) callback.onLoad( response );
  22108. }
  22109. scope.manager.itemEnd( url );
  22110. } else {
  22111. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  22112. const callback = callbacks[ i ];
  22113. if ( callback.onError ) callback.onError( event );
  22114. }
  22115. scope.manager.itemError( url );
  22116. scope.manager.itemEnd( url );
  22117. }
  22118. }, false );
  22119. request.addEventListener( 'progress', function ( event ) {
  22120. const callbacks = loading[ url ];
  22121. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  22122. const callback = callbacks[ i ];
  22123. if ( callback.onProgress ) callback.onProgress( event );
  22124. }
  22125. }, false );
  22126. request.addEventListener( 'error', function ( event ) {
  22127. const callbacks = loading[ url ];
  22128. delete loading[ url ];
  22129. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  22130. const callback = callbacks[ i ];
  22131. if ( callback.onError ) callback.onError( event );
  22132. }
  22133. scope.manager.itemError( url );
  22134. scope.manager.itemEnd( url );
  22135. }, false );
  22136. request.addEventListener( 'abort', function ( event ) {
  22137. const callbacks = loading[ url ];
  22138. delete loading[ url ];
  22139. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  22140. const callback = callbacks[ i ];
  22141. if ( callback.onError ) callback.onError( event );
  22142. }
  22143. scope.manager.itemError( url );
  22144. scope.manager.itemEnd( url );
  22145. }, false );
  22146. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  22147. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  22148. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  22149. for ( const header in this.requestHeader ) {
  22150. request.setRequestHeader( header, this.requestHeader[ header ] );
  22151. }
  22152. request.send( null );
  22153. }
  22154. scope.manager.itemStart( url );
  22155. return request;
  22156. },
  22157. setResponseType: function ( value ) {
  22158. this.responseType = value;
  22159. return this;
  22160. },
  22161. setWithCredentials: function ( value ) {
  22162. this.withCredentials = value;
  22163. return this;
  22164. },
  22165. setMimeType: function ( value ) {
  22166. this.mimeType = value;
  22167. return this;
  22168. }
  22169. } );
  22170. /**
  22171. * @author bhouston / http://clara.io/
  22172. */
  22173. function AnimationLoader( manager ) {
  22174. Loader.call( this, manager );
  22175. }
  22176. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22177. constructor: AnimationLoader,
  22178. load: function ( url, onLoad, onProgress, onError ) {
  22179. const scope = this;
  22180. const loader = new FileLoader( scope.manager );
  22181. loader.setPath( scope.path );
  22182. loader.load( url, function ( text ) {
  22183. try {
  22184. onLoad( scope.parse( JSON.parse( text ) ) );
  22185. } catch ( e ) {
  22186. if ( onError ) {
  22187. onError( e );
  22188. } else {
  22189. console.error( e );
  22190. }
  22191. scope.manager.itemError( url );
  22192. }
  22193. }, onProgress, onError );
  22194. },
  22195. parse: function ( json ) {
  22196. const animations = [];
  22197. for ( let i = 0; i < json.length; i ++ ) {
  22198. const clip = AnimationClip.parse( json[ i ] );
  22199. animations.push( clip );
  22200. }
  22201. return animations;
  22202. }
  22203. } );
  22204. /**
  22205. * @author mrdoob / http://mrdoob.com/
  22206. *
  22207. * Abstract Base class to block based textures loader (dds, pvr, ...)
  22208. *
  22209. * Sub classes have to implement the parse() method which will be used in load().
  22210. */
  22211. function CompressedTextureLoader( manager ) {
  22212. Loader.call( this, manager );
  22213. }
  22214. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22215. constructor: CompressedTextureLoader,
  22216. load: function ( url, onLoad, onProgress, onError ) {
  22217. const scope = this;
  22218. const images = [];
  22219. const texture = new CompressedTexture();
  22220. texture.image = images;
  22221. const loader = new FileLoader( this.manager );
  22222. loader.setPath( this.path );
  22223. loader.setResponseType( 'arraybuffer' );
  22224. let loaded = 0;
  22225. function loadTexture( i ) {
  22226. loader.load( url[ i ], function ( buffer ) {
  22227. const texDatas = scope.parse( buffer, true );
  22228. images[ i ] = {
  22229. width: texDatas.width,
  22230. height: texDatas.height,
  22231. format: texDatas.format,
  22232. mipmaps: texDatas.mipmaps
  22233. };
  22234. loaded += 1;
  22235. if ( loaded === 6 ) {
  22236. if ( texDatas.mipmapCount === 1 )
  22237. texture.minFilter = LinearFilter;
  22238. texture.format = texDatas.format;
  22239. texture.needsUpdate = true;
  22240. if ( onLoad ) onLoad( texture );
  22241. }
  22242. }, onProgress, onError );
  22243. }
  22244. if ( Array.isArray( url ) ) {
  22245. for ( let i = 0, il = url.length; i < il; ++ i ) {
  22246. loadTexture( i );
  22247. }
  22248. } else {
  22249. // compressed cubemap texture stored in a single DDS file
  22250. loader.load( url, function ( buffer ) {
  22251. const texDatas = scope.parse( buffer, true );
  22252. if ( texDatas.isCubemap ) {
  22253. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22254. for ( let f = 0; f < faces; f ++ ) {
  22255. images[ f ] = { mipmaps: [] };
  22256. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  22257. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  22258. images[ f ].format = texDatas.format;
  22259. images[ f ].width = texDatas.width;
  22260. images[ f ].height = texDatas.height;
  22261. }
  22262. }
  22263. } else {
  22264. texture.image.width = texDatas.width;
  22265. texture.image.height = texDatas.height;
  22266. texture.mipmaps = texDatas.mipmaps;
  22267. }
  22268. if ( texDatas.mipmapCount === 1 ) {
  22269. texture.minFilter = LinearFilter;
  22270. }
  22271. texture.format = texDatas.format;
  22272. texture.needsUpdate = true;
  22273. if ( onLoad ) onLoad( texture );
  22274. }, onProgress, onError );
  22275. }
  22276. return texture;
  22277. }
  22278. } );
  22279. /**
  22280. * @author Nikos M. / https://github.com/foo123/
  22281. *
  22282. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22283. *
  22284. * Sub classes have to implement the parse() method which will be used in load().
  22285. */
  22286. function DataTextureLoader( manager ) {
  22287. Loader.call( this, manager );
  22288. }
  22289. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22290. constructor: DataTextureLoader,
  22291. load: function ( url, onLoad, onProgress, onError ) {
  22292. const scope = this;
  22293. const texture = new DataTexture();
  22294. const loader = new FileLoader( this.manager );
  22295. loader.setResponseType( 'arraybuffer' );
  22296. loader.setPath( this.path );
  22297. loader.load( url, function ( buffer ) {
  22298. const texData = scope.parse( buffer );
  22299. if ( ! texData ) return;
  22300. if ( texData.image !== undefined ) {
  22301. texture.image = texData.image;
  22302. } else if ( texData.data !== undefined ) {
  22303. texture.image.width = texData.width;
  22304. texture.image.height = texData.height;
  22305. texture.image.data = texData.data;
  22306. }
  22307. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22308. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22309. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22310. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22311. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22312. if ( texData.format !== undefined ) {
  22313. texture.format = texData.format;
  22314. }
  22315. if ( texData.type !== undefined ) {
  22316. texture.type = texData.type;
  22317. }
  22318. if ( texData.mipmaps !== undefined ) {
  22319. texture.mipmaps = texData.mipmaps;
  22320. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22321. }
  22322. if ( texData.mipmapCount === 1 ) {
  22323. texture.minFilter = LinearFilter;
  22324. }
  22325. texture.needsUpdate = true;
  22326. if ( onLoad ) onLoad( texture, texData );
  22327. }, onProgress, onError );
  22328. return texture;
  22329. }
  22330. } );
  22331. /**
  22332. * @author mrdoob / http://mrdoob.com/
  22333. */
  22334. function ImageLoader( manager ) {
  22335. Loader.call( this, manager );
  22336. }
  22337. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22338. constructor: ImageLoader,
  22339. load: function ( url, onLoad, onProgress, onError ) {
  22340. if ( this.path !== undefined ) url = this.path + url;
  22341. url = this.manager.resolveURL( url );
  22342. const scope = this;
  22343. const cached = Cache.get( url );
  22344. if ( cached !== undefined ) {
  22345. scope.manager.itemStart( url );
  22346. setTimeout( function () {
  22347. if ( onLoad ) onLoad( cached );
  22348. scope.manager.itemEnd( url );
  22349. }, 0 );
  22350. return cached;
  22351. }
  22352. const image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  22353. function onImageLoad() {
  22354. image.removeEventListener( 'load', onImageLoad, false );
  22355. image.removeEventListener( 'error', onImageError, false );
  22356. Cache.add( url, this );
  22357. if ( onLoad ) onLoad( this );
  22358. scope.manager.itemEnd( url );
  22359. }
  22360. function onImageError( event ) {
  22361. image.removeEventListener( 'load', onImageLoad, false );
  22362. image.removeEventListener( 'error', onImageError, false );
  22363. if ( onError ) onError( event );
  22364. scope.manager.itemError( url );
  22365. scope.manager.itemEnd( url );
  22366. }
  22367. image.addEventListener( 'load', onImageLoad, false );
  22368. image.addEventListener( 'error', onImageError, false );
  22369. if ( url.substr( 0, 5 ) !== 'data:' ) {
  22370. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  22371. }
  22372. scope.manager.itemStart( url );
  22373. image.src = url;
  22374. return image;
  22375. }
  22376. } );
  22377. /**
  22378. * @author mrdoob / http://mrdoob.com/
  22379. */
  22380. function CubeTextureLoader( manager ) {
  22381. Loader.call( this, manager );
  22382. }
  22383. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22384. constructor: CubeTextureLoader,
  22385. load: function ( urls, onLoad, onProgress, onError ) {
  22386. const texture = new CubeTexture();
  22387. const loader = new ImageLoader( this.manager );
  22388. loader.setCrossOrigin( this.crossOrigin );
  22389. loader.setPath( this.path );
  22390. let loaded = 0;
  22391. function loadTexture( i ) {
  22392. loader.load( urls[ i ], function ( image ) {
  22393. texture.images[ i ] = image;
  22394. loaded ++;
  22395. if ( loaded === 6 ) {
  22396. texture.needsUpdate = true;
  22397. if ( onLoad ) onLoad( texture );
  22398. }
  22399. }, undefined, onError );
  22400. }
  22401. for ( let i = 0; i < urls.length; ++ i ) {
  22402. loadTexture( i );
  22403. }
  22404. return texture;
  22405. }
  22406. } );
  22407. /**
  22408. * @author mrdoob / http://mrdoob.com/
  22409. */
  22410. function TextureLoader( manager ) {
  22411. Loader.call( this, manager );
  22412. }
  22413. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22414. constructor: TextureLoader,
  22415. load: function ( url, onLoad, onProgress, onError ) {
  22416. const texture = new Texture();
  22417. const loader = new ImageLoader( this.manager );
  22418. loader.setCrossOrigin( this.crossOrigin );
  22419. loader.setPath( this.path );
  22420. loader.load( url, function ( image ) {
  22421. texture.image = image;
  22422. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22423. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22424. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22425. texture.needsUpdate = true;
  22426. if ( onLoad !== undefined ) {
  22427. onLoad( texture );
  22428. }
  22429. }, onProgress, onError );
  22430. return texture;
  22431. }
  22432. } );
  22433. /**
  22434. * @author zz85 / http://www.lab4games.net/zz85/blog
  22435. * Extensible curve object
  22436. *
  22437. * Some common of curve methods:
  22438. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22439. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22440. * .getPoints(), .getSpacedPoints()
  22441. * .getLength()
  22442. * .updateArcLengths()
  22443. *
  22444. * This following curves inherit from THREE.Curve:
  22445. *
  22446. * -- 2D curves --
  22447. * THREE.ArcCurve
  22448. * THREE.CubicBezierCurve
  22449. * THREE.EllipseCurve
  22450. * THREE.LineCurve
  22451. * THREE.QuadraticBezierCurve
  22452. * THREE.SplineCurve
  22453. *
  22454. * -- 3D curves --
  22455. * THREE.CatmullRomCurve3
  22456. * THREE.CubicBezierCurve3
  22457. * THREE.LineCurve3
  22458. * THREE.QuadraticBezierCurve3
  22459. *
  22460. * A series of curves can be represented as a THREE.CurvePath.
  22461. *
  22462. **/
  22463. /**************************************************************
  22464. * Abstract Curve base class
  22465. **************************************************************/
  22466. function Curve() {
  22467. this.type = 'Curve';
  22468. this.arcLengthDivisions = 200;
  22469. }
  22470. Object.assign( Curve.prototype, {
  22471. // Virtual base class method to overwrite and implement in subclasses
  22472. // - t [0 .. 1]
  22473. getPoint: function ( /* t, optionalTarget */ ) {
  22474. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  22475. return null;
  22476. },
  22477. // Get point at relative position in curve according to arc length
  22478. // - u [0 .. 1]
  22479. getPointAt: function ( u, optionalTarget ) {
  22480. const t = this.getUtoTmapping( u );
  22481. return this.getPoint( t, optionalTarget );
  22482. },
  22483. // Get sequence of points using getPoint( t )
  22484. getPoints: function ( divisions ) {
  22485. if ( divisions === undefined ) divisions = 5;
  22486. const points = [];
  22487. for ( let d = 0; d <= divisions; d ++ ) {
  22488. points.push( this.getPoint( d / divisions ) );
  22489. }
  22490. return points;
  22491. },
  22492. // Get sequence of points using getPointAt( u )
  22493. getSpacedPoints: function ( divisions ) {
  22494. if ( divisions === undefined ) divisions = 5;
  22495. const points = [];
  22496. for ( let d = 0; d <= divisions; d ++ ) {
  22497. points.push( this.getPointAt( d / divisions ) );
  22498. }
  22499. return points;
  22500. },
  22501. // Get total curve arc length
  22502. getLength: function () {
  22503. const lengths = this.getLengths();
  22504. return lengths[ lengths.length - 1 ];
  22505. },
  22506. // Get list of cumulative segment lengths
  22507. getLengths: function ( divisions ) {
  22508. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  22509. if ( this.cacheArcLengths &&
  22510. ( this.cacheArcLengths.length === divisions + 1 ) &&
  22511. ! this.needsUpdate ) {
  22512. return this.cacheArcLengths;
  22513. }
  22514. this.needsUpdate = false;
  22515. const cache = [];
  22516. let current, last = this.getPoint( 0 );
  22517. let sum = 0;
  22518. cache.push( 0 );
  22519. for ( let p = 1; p <= divisions; p ++ ) {
  22520. current = this.getPoint( p / divisions );
  22521. sum += current.distanceTo( last );
  22522. cache.push( sum );
  22523. last = current;
  22524. }
  22525. this.cacheArcLengths = cache;
  22526. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22527. },
  22528. updateArcLengths: function () {
  22529. this.needsUpdate = true;
  22530. this.getLengths();
  22531. },
  22532. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22533. getUtoTmapping: function ( u, distance ) {
  22534. const arcLengths = this.getLengths();
  22535. let i = 0, il = arcLengths.length;
  22536. let targetArcLength; // The targeted u distance value to get
  22537. if ( distance ) {
  22538. targetArcLength = distance;
  22539. } else {
  22540. targetArcLength = u * arcLengths[ il - 1 ];
  22541. }
  22542. // binary search for the index with largest value smaller than target u distance
  22543. let low = 0, high = il - 1, comparison;
  22544. while ( low <= high ) {
  22545. 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
  22546. comparison = arcLengths[ i ] - targetArcLength;
  22547. if ( comparison < 0 ) {
  22548. low = i + 1;
  22549. } else if ( comparison > 0 ) {
  22550. high = i - 1;
  22551. } else {
  22552. high = i;
  22553. break;
  22554. // DONE
  22555. }
  22556. }
  22557. i = high;
  22558. if ( arcLengths[ i ] === targetArcLength ) {
  22559. return i / ( il - 1 );
  22560. }
  22561. // we could get finer grain at lengths, or use simple interpolation between two points
  22562. const lengthBefore = arcLengths[ i ];
  22563. const lengthAfter = arcLengths[ i + 1 ];
  22564. const segmentLength = lengthAfter - lengthBefore;
  22565. // determine where we are between the 'before' and 'after' points
  22566. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  22567. // add that fractional amount to t
  22568. const t = ( i + segmentFraction ) / ( il - 1 );
  22569. return t;
  22570. },
  22571. // Returns a unit vector tangent at t
  22572. // In case any sub curve does not implement its tangent derivation,
  22573. // 2 points a small delta apart will be used to find its gradient
  22574. // which seems to give a reasonable approximation
  22575. getTangent: function ( t, optionalTarget ) {
  22576. const delta = 0.0001;
  22577. let t1 = t - delta;
  22578. let t2 = t + delta;
  22579. // Capping in case of danger
  22580. if ( t1 < 0 ) t1 = 0;
  22581. if ( t2 > 1 ) t2 = 1;
  22582. const pt1 = this.getPoint( t1 );
  22583. const pt2 = this.getPoint( t2 );
  22584. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  22585. tangent.copy( pt2 ).sub( pt1 ).normalize();
  22586. return tangent;
  22587. },
  22588. getTangentAt: function ( u, optionalTarget ) {
  22589. const t = this.getUtoTmapping( u );
  22590. return this.getTangent( t, optionalTarget );
  22591. },
  22592. computeFrenetFrames: function ( segments, closed ) {
  22593. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22594. const normal = new Vector3();
  22595. const tangents = [];
  22596. const normals = [];
  22597. const binormals = [];
  22598. const vec = new Vector3();
  22599. const mat = new Matrix4();
  22600. // compute the tangent vectors for each segment on the curve
  22601. for ( let i = 0; i <= segments; i ++ ) {
  22602. const u = i / segments;
  22603. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  22604. tangents[ i ].normalize();
  22605. }
  22606. // select an initial normal vector perpendicular to the first tangent vector,
  22607. // and in the direction of the minimum tangent xyz component
  22608. normals[ 0 ] = new Vector3();
  22609. binormals[ 0 ] = new Vector3();
  22610. let min = Number.MAX_VALUE;
  22611. const tx = Math.abs( tangents[ 0 ].x );
  22612. const ty = Math.abs( tangents[ 0 ].y );
  22613. const tz = Math.abs( tangents[ 0 ].z );
  22614. if ( tx <= min ) {
  22615. min = tx;
  22616. normal.set( 1, 0, 0 );
  22617. }
  22618. if ( ty <= min ) {
  22619. min = ty;
  22620. normal.set( 0, 1, 0 );
  22621. }
  22622. if ( tz <= min ) {
  22623. normal.set( 0, 0, 1 );
  22624. }
  22625. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22626. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22627. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22628. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22629. for ( let i = 1; i <= segments; i ++ ) {
  22630. normals[ i ] = normals[ i - 1 ].clone();
  22631. binormals[ i ] = binormals[ i - 1 ].clone();
  22632. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22633. if ( vec.length() > Number.EPSILON ) {
  22634. vec.normalize();
  22635. const theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22636. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22637. }
  22638. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22639. }
  22640. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22641. if ( closed === true ) {
  22642. let theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  22643. theta /= segments;
  22644. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  22645. theta = - theta;
  22646. }
  22647. for ( let i = 1; i <= segments; i ++ ) {
  22648. // twist a little...
  22649. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22650. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22651. }
  22652. }
  22653. return {
  22654. tangents: tangents,
  22655. normals: normals,
  22656. binormals: binormals
  22657. };
  22658. },
  22659. clone: function () {
  22660. return new this.constructor().copy( this );
  22661. },
  22662. copy: function ( source ) {
  22663. this.arcLengthDivisions = source.arcLengthDivisions;
  22664. return this;
  22665. },
  22666. toJSON: function () {
  22667. const data = {
  22668. metadata: {
  22669. version: 4.5,
  22670. type: 'Curve',
  22671. generator: 'Curve.toJSON'
  22672. }
  22673. };
  22674. data.arcLengthDivisions = this.arcLengthDivisions;
  22675. data.type = this.type;
  22676. return data;
  22677. },
  22678. fromJSON: function ( json ) {
  22679. this.arcLengthDivisions = json.arcLengthDivisions;
  22680. return this;
  22681. }
  22682. } );
  22683. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22684. Curve.call( this );
  22685. this.type = 'EllipseCurve';
  22686. this.aX = aX || 0;
  22687. this.aY = aY || 0;
  22688. this.xRadius = xRadius || 1;
  22689. this.yRadius = yRadius || 1;
  22690. this.aStartAngle = aStartAngle || 0;
  22691. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22692. this.aClockwise = aClockwise || false;
  22693. this.aRotation = aRotation || 0;
  22694. }
  22695. EllipseCurve.prototype = Object.create( Curve.prototype );
  22696. EllipseCurve.prototype.constructor = EllipseCurve;
  22697. EllipseCurve.prototype.isEllipseCurve = true;
  22698. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22699. const point = optionalTarget || new Vector2();
  22700. const twoPi = Math.PI * 2;
  22701. let deltaAngle = this.aEndAngle - this.aStartAngle;
  22702. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22703. // ensures that deltaAngle is 0 .. 2 PI
  22704. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  22705. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  22706. if ( deltaAngle < Number.EPSILON ) {
  22707. if ( samePoints ) {
  22708. deltaAngle = 0;
  22709. } else {
  22710. deltaAngle = twoPi;
  22711. }
  22712. }
  22713. if ( this.aClockwise === true && ! samePoints ) {
  22714. if ( deltaAngle === twoPi ) {
  22715. deltaAngle = - twoPi;
  22716. } else {
  22717. deltaAngle = deltaAngle - twoPi;
  22718. }
  22719. }
  22720. const angle = this.aStartAngle + t * deltaAngle;
  22721. let x = this.aX + this.xRadius * Math.cos( angle );
  22722. let y = this.aY + this.yRadius * Math.sin( angle );
  22723. if ( this.aRotation !== 0 ) {
  22724. const cos = Math.cos( this.aRotation );
  22725. const sin = Math.sin( this.aRotation );
  22726. const tx = x - this.aX;
  22727. const ty = y - this.aY;
  22728. // Rotate the point about the center of the ellipse.
  22729. x = tx * cos - ty * sin + this.aX;
  22730. y = tx * sin + ty * cos + this.aY;
  22731. }
  22732. return point.set( x, y );
  22733. };
  22734. EllipseCurve.prototype.copy = function ( source ) {
  22735. Curve.prototype.copy.call( this, source );
  22736. this.aX = source.aX;
  22737. this.aY = source.aY;
  22738. this.xRadius = source.xRadius;
  22739. this.yRadius = source.yRadius;
  22740. this.aStartAngle = source.aStartAngle;
  22741. this.aEndAngle = source.aEndAngle;
  22742. this.aClockwise = source.aClockwise;
  22743. this.aRotation = source.aRotation;
  22744. return this;
  22745. };
  22746. EllipseCurve.prototype.toJSON = function () {
  22747. const data = Curve.prototype.toJSON.call( this );
  22748. data.aX = this.aX;
  22749. data.aY = this.aY;
  22750. data.xRadius = this.xRadius;
  22751. data.yRadius = this.yRadius;
  22752. data.aStartAngle = this.aStartAngle;
  22753. data.aEndAngle = this.aEndAngle;
  22754. data.aClockwise = this.aClockwise;
  22755. data.aRotation = this.aRotation;
  22756. return data;
  22757. };
  22758. EllipseCurve.prototype.fromJSON = function ( json ) {
  22759. Curve.prototype.fromJSON.call( this, json );
  22760. this.aX = json.aX;
  22761. this.aY = json.aY;
  22762. this.xRadius = json.xRadius;
  22763. this.yRadius = json.yRadius;
  22764. this.aStartAngle = json.aStartAngle;
  22765. this.aEndAngle = json.aEndAngle;
  22766. this.aClockwise = json.aClockwise;
  22767. this.aRotation = json.aRotation;
  22768. return this;
  22769. };
  22770. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22771. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22772. this.type = 'ArcCurve';
  22773. }
  22774. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22775. ArcCurve.prototype.constructor = ArcCurve;
  22776. ArcCurve.prototype.isArcCurve = true;
  22777. /**
  22778. * @author zz85 https://github.com/zz85
  22779. *
  22780. * Centripetal CatmullRom Curve - which is useful for avoiding
  22781. * cusps and self-intersections in non-uniform catmull rom curves.
  22782. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22783. *
  22784. * curve.type accepts centripetal(default), chordal and catmullrom
  22785. * curve.tension is used for catmullrom which defaults to 0.5
  22786. */
  22787. /*
  22788. Based on an optimized c++ solution in
  22789. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22790. - http://ideone.com/NoEbVM
  22791. This CubicPoly class could be used for reusing some variables and calculations,
  22792. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22793. which can be placed in CurveUtils.
  22794. */
  22795. function CubicPoly() {
  22796. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22797. /*
  22798. * Compute coefficients for a cubic polynomial
  22799. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22800. * such that
  22801. * p(0) = x0, p(1) = x1
  22802. * and
  22803. * p'(0) = t0, p'(1) = t1.
  22804. */
  22805. function init( x0, x1, t0, t1 ) {
  22806. c0 = x0;
  22807. c1 = t0;
  22808. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22809. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22810. }
  22811. return {
  22812. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22813. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22814. },
  22815. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22816. // compute tangents when parameterized in [t1,t2]
  22817. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22818. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22819. // rescale tangents for parametrization in [0,1]
  22820. t1 *= dt1;
  22821. t2 *= dt1;
  22822. init( x1, x2, t1, t2 );
  22823. },
  22824. calc: function ( t ) {
  22825. const t2 = t * t;
  22826. const t3 = t2 * t;
  22827. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22828. }
  22829. };
  22830. }
  22831. //
  22832. const tmp = new Vector3();
  22833. const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22834. function CatmullRomCurve3( points, closed, curveType, tension ) {
  22835. Curve.call( this );
  22836. this.type = 'CatmullRomCurve3';
  22837. this.points = points || [];
  22838. this.closed = closed || false;
  22839. this.curveType = curveType || 'centripetal';
  22840. this.tension = tension || 0.5;
  22841. }
  22842. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22843. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22844. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22845. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22846. const point = optionalTarget || new Vector3();
  22847. const points = this.points;
  22848. const l = points.length;
  22849. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22850. let intPoint = Math.floor( p );
  22851. let weight = p - intPoint;
  22852. if ( this.closed ) {
  22853. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22854. } else if ( weight === 0 && intPoint === l - 1 ) {
  22855. intPoint = l - 2;
  22856. weight = 1;
  22857. }
  22858. let p0, p1, p2, p3; // 4 points
  22859. if ( this.closed || intPoint > 0 ) {
  22860. p0 = points[ ( intPoint - 1 ) % l ];
  22861. } else {
  22862. // extrapolate first point
  22863. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22864. p0 = tmp;
  22865. }
  22866. p1 = points[ intPoint % l ];
  22867. p2 = points[ ( intPoint + 1 ) % l ];
  22868. if ( this.closed || intPoint + 2 < l ) {
  22869. p3 = points[ ( intPoint + 2 ) % l ];
  22870. } else {
  22871. // extrapolate last point
  22872. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22873. p3 = tmp;
  22874. }
  22875. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22876. // init Centripetal / Chordal Catmull-Rom
  22877. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22878. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22879. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22880. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22881. // safety check for repeated points
  22882. if ( dt1 < 1e-4 ) dt1 = 1.0;
  22883. if ( dt0 < 1e-4 ) dt0 = dt1;
  22884. if ( dt2 < 1e-4 ) dt2 = dt1;
  22885. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22886. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22887. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22888. } else if ( this.curveType === 'catmullrom' ) {
  22889. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22890. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22891. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22892. }
  22893. point.set(
  22894. px.calc( weight ),
  22895. py.calc( weight ),
  22896. pz.calc( weight )
  22897. );
  22898. return point;
  22899. };
  22900. CatmullRomCurve3.prototype.copy = function ( source ) {
  22901. Curve.prototype.copy.call( this, source );
  22902. this.points = [];
  22903. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  22904. const point = source.points[ i ];
  22905. this.points.push( point.clone() );
  22906. }
  22907. this.closed = source.closed;
  22908. this.curveType = source.curveType;
  22909. this.tension = source.tension;
  22910. return this;
  22911. };
  22912. CatmullRomCurve3.prototype.toJSON = function () {
  22913. const data = Curve.prototype.toJSON.call( this );
  22914. data.points = [];
  22915. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  22916. const point = this.points[ i ];
  22917. data.points.push( point.toArray() );
  22918. }
  22919. data.closed = this.closed;
  22920. data.curveType = this.curveType;
  22921. data.tension = this.tension;
  22922. return data;
  22923. };
  22924. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22925. Curve.prototype.fromJSON.call( this, json );
  22926. this.points = [];
  22927. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  22928. const point = json.points[ i ];
  22929. this.points.push( new Vector3().fromArray( point ) );
  22930. }
  22931. this.closed = json.closed;
  22932. this.curveType = json.curveType;
  22933. this.tension = json.tension;
  22934. return this;
  22935. };
  22936. /**
  22937. * @author zz85 / http://www.lab4games.net/zz85/blog
  22938. *
  22939. * Bezier Curves formulas obtained from
  22940. * http://en.wikipedia.org/wiki/Bézier_curve
  22941. */
  22942. function CatmullRom( t, p0, p1, p2, p3 ) {
  22943. const v0 = ( p2 - p0 ) * 0.5;
  22944. const v1 = ( p3 - p1 ) * 0.5;
  22945. const t2 = t * t;
  22946. const t3 = t * t2;
  22947. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22948. }
  22949. //
  22950. function QuadraticBezierP0( t, p ) {
  22951. const k = 1 - t;
  22952. return k * k * p;
  22953. }
  22954. function QuadraticBezierP1( t, p ) {
  22955. return 2 * ( 1 - t ) * t * p;
  22956. }
  22957. function QuadraticBezierP2( t, p ) {
  22958. return t * t * p;
  22959. }
  22960. function QuadraticBezier( t, p0, p1, p2 ) {
  22961. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22962. QuadraticBezierP2( t, p2 );
  22963. }
  22964. //
  22965. function CubicBezierP0( t, p ) {
  22966. const k = 1 - t;
  22967. return k * k * k * p;
  22968. }
  22969. function CubicBezierP1( t, p ) {
  22970. const k = 1 - t;
  22971. return 3 * k * k * t * p;
  22972. }
  22973. function CubicBezierP2( t, p ) {
  22974. return 3 * ( 1 - t ) * t * t * p;
  22975. }
  22976. function CubicBezierP3( t, p ) {
  22977. return t * t * t * p;
  22978. }
  22979. function CubicBezier( t, p0, p1, p2, p3 ) {
  22980. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  22981. CubicBezierP3( t, p3 );
  22982. }
  22983. function CubicBezierCurve( v0, v1, v2, v3 ) {
  22984. Curve.call( this );
  22985. this.type = 'CubicBezierCurve';
  22986. this.v0 = v0 || new Vector2();
  22987. this.v1 = v1 || new Vector2();
  22988. this.v2 = v2 || new Vector2();
  22989. this.v3 = v3 || new Vector2();
  22990. }
  22991. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  22992. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22993. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22994. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22995. const point = optionalTarget || new Vector2();
  22996. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22997. point.set(
  22998. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22999. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  23000. );
  23001. return point;
  23002. };
  23003. CubicBezierCurve.prototype.copy = function ( source ) {
  23004. Curve.prototype.copy.call( this, source );
  23005. this.v0.copy( source.v0 );
  23006. this.v1.copy( source.v1 );
  23007. this.v2.copy( source.v2 );
  23008. this.v3.copy( source.v3 );
  23009. return this;
  23010. };
  23011. CubicBezierCurve.prototype.toJSON = function () {
  23012. const data = Curve.prototype.toJSON.call( this );
  23013. data.v0 = this.v0.toArray();
  23014. data.v1 = this.v1.toArray();
  23015. data.v2 = this.v2.toArray();
  23016. data.v3 = this.v3.toArray();
  23017. return data;
  23018. };
  23019. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  23020. Curve.prototype.fromJSON.call( this, json );
  23021. this.v0.fromArray( json.v0 );
  23022. this.v1.fromArray( json.v1 );
  23023. this.v2.fromArray( json.v2 );
  23024. this.v3.fromArray( json.v3 );
  23025. return this;
  23026. };
  23027. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  23028. Curve.call( this );
  23029. this.type = 'CubicBezierCurve3';
  23030. this.v0 = v0 || new Vector3();
  23031. this.v1 = v1 || new Vector3();
  23032. this.v2 = v2 || new Vector3();
  23033. this.v3 = v3 || new Vector3();
  23034. }
  23035. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  23036. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  23037. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  23038. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23039. const point = optionalTarget || new Vector3();
  23040. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  23041. point.set(
  23042. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  23043. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  23044. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  23045. );
  23046. return point;
  23047. };
  23048. CubicBezierCurve3.prototype.copy = function ( source ) {
  23049. Curve.prototype.copy.call( this, source );
  23050. this.v0.copy( source.v0 );
  23051. this.v1.copy( source.v1 );
  23052. this.v2.copy( source.v2 );
  23053. this.v3.copy( source.v3 );
  23054. return this;
  23055. };
  23056. CubicBezierCurve3.prototype.toJSON = function () {
  23057. const data = Curve.prototype.toJSON.call( this );
  23058. data.v0 = this.v0.toArray();
  23059. data.v1 = this.v1.toArray();
  23060. data.v2 = this.v2.toArray();
  23061. data.v3 = this.v3.toArray();
  23062. return data;
  23063. };
  23064. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  23065. Curve.prototype.fromJSON.call( this, json );
  23066. this.v0.fromArray( json.v0 );
  23067. this.v1.fromArray( json.v1 );
  23068. this.v2.fromArray( json.v2 );
  23069. this.v3.fromArray( json.v3 );
  23070. return this;
  23071. };
  23072. function LineCurve( v1, v2 ) {
  23073. Curve.call( this );
  23074. this.type = 'LineCurve';
  23075. this.v1 = v1 || new Vector2();
  23076. this.v2 = v2 || new Vector2();
  23077. }
  23078. LineCurve.prototype = Object.create( Curve.prototype );
  23079. LineCurve.prototype.constructor = LineCurve;
  23080. LineCurve.prototype.isLineCurve = true;
  23081. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23082. const point = optionalTarget || new Vector2();
  23083. if ( t === 1 ) {
  23084. point.copy( this.v2 );
  23085. } else {
  23086. point.copy( this.v2 ).sub( this.v1 );
  23087. point.multiplyScalar( t ).add( this.v1 );
  23088. }
  23089. return point;
  23090. };
  23091. // Line curve is linear, so we can overwrite default getPointAt
  23092. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  23093. return this.getPoint( u, optionalTarget );
  23094. };
  23095. LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
  23096. const tangent = optionalTarget || new Vector2();
  23097. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  23098. return tangent;
  23099. };
  23100. LineCurve.prototype.copy = function ( source ) {
  23101. Curve.prototype.copy.call( this, source );
  23102. this.v1.copy( source.v1 );
  23103. this.v2.copy( source.v2 );
  23104. return this;
  23105. };
  23106. LineCurve.prototype.toJSON = function () {
  23107. const data = Curve.prototype.toJSON.call( this );
  23108. data.v1 = this.v1.toArray();
  23109. data.v2 = this.v2.toArray();
  23110. return data;
  23111. };
  23112. LineCurve.prototype.fromJSON = function ( json ) {
  23113. Curve.prototype.fromJSON.call( this, json );
  23114. this.v1.fromArray( json.v1 );
  23115. this.v2.fromArray( json.v2 );
  23116. return this;
  23117. };
  23118. function LineCurve3( v1, v2 ) {
  23119. Curve.call( this );
  23120. this.type = 'LineCurve3';
  23121. this.v1 = v1 || new Vector3();
  23122. this.v2 = v2 || new Vector3();
  23123. }
  23124. LineCurve3.prototype = Object.create( Curve.prototype );
  23125. LineCurve3.prototype.constructor = LineCurve3;
  23126. LineCurve3.prototype.isLineCurve3 = true;
  23127. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23128. const point = optionalTarget || new Vector3();
  23129. if ( t === 1 ) {
  23130. point.copy( this.v2 );
  23131. } else {
  23132. point.copy( this.v2 ).sub( this.v1 );
  23133. point.multiplyScalar( t ).add( this.v1 );
  23134. }
  23135. return point;
  23136. };
  23137. // Line curve is linear, so we can overwrite default getPointAt
  23138. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  23139. return this.getPoint( u, optionalTarget );
  23140. };
  23141. LineCurve3.prototype.copy = function ( source ) {
  23142. Curve.prototype.copy.call( this, source );
  23143. this.v1.copy( source.v1 );
  23144. this.v2.copy( source.v2 );
  23145. return this;
  23146. };
  23147. LineCurve3.prototype.toJSON = function () {
  23148. const data = Curve.prototype.toJSON.call( this );
  23149. data.v1 = this.v1.toArray();
  23150. data.v2 = this.v2.toArray();
  23151. return data;
  23152. };
  23153. LineCurve3.prototype.fromJSON = function ( json ) {
  23154. Curve.prototype.fromJSON.call( this, json );
  23155. this.v1.fromArray( json.v1 );
  23156. this.v2.fromArray( json.v2 );
  23157. return this;
  23158. };
  23159. function QuadraticBezierCurve( v0, v1, v2 ) {
  23160. Curve.call( this );
  23161. this.type = 'QuadraticBezierCurve';
  23162. this.v0 = v0 || new Vector2();
  23163. this.v1 = v1 || new Vector2();
  23164. this.v2 = v2 || new Vector2();
  23165. }
  23166. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  23167. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  23168. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  23169. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23170. const point = optionalTarget || new Vector2();
  23171. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  23172. point.set(
  23173. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  23174. QuadraticBezier( t, v0.y, v1.y, v2.y )
  23175. );
  23176. return point;
  23177. };
  23178. QuadraticBezierCurve.prototype.copy = function ( source ) {
  23179. Curve.prototype.copy.call( this, source );
  23180. this.v0.copy( source.v0 );
  23181. this.v1.copy( source.v1 );
  23182. this.v2.copy( source.v2 );
  23183. return this;
  23184. };
  23185. QuadraticBezierCurve.prototype.toJSON = function () {
  23186. const data = Curve.prototype.toJSON.call( this );
  23187. data.v0 = this.v0.toArray();
  23188. data.v1 = this.v1.toArray();
  23189. data.v2 = this.v2.toArray();
  23190. return data;
  23191. };
  23192. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  23193. Curve.prototype.fromJSON.call( this, json );
  23194. this.v0.fromArray( json.v0 );
  23195. this.v1.fromArray( json.v1 );
  23196. this.v2.fromArray( json.v2 );
  23197. return this;
  23198. };
  23199. function QuadraticBezierCurve3( v0, v1, v2 ) {
  23200. Curve.call( this );
  23201. this.type = 'QuadraticBezierCurve3';
  23202. this.v0 = v0 || new Vector3();
  23203. this.v1 = v1 || new Vector3();
  23204. this.v2 = v2 || new Vector3();
  23205. }
  23206. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  23207. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  23208. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23209. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  23210. const point = optionalTarget || new Vector3();
  23211. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  23212. point.set(
  23213. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  23214. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  23215. QuadraticBezier( t, v0.z, v1.z, v2.z )
  23216. );
  23217. return point;
  23218. };
  23219. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  23220. Curve.prototype.copy.call( this, source );
  23221. this.v0.copy( source.v0 );
  23222. this.v1.copy( source.v1 );
  23223. this.v2.copy( source.v2 );
  23224. return this;
  23225. };
  23226. QuadraticBezierCurve3.prototype.toJSON = function () {
  23227. const data = Curve.prototype.toJSON.call( this );
  23228. data.v0 = this.v0.toArray();
  23229. data.v1 = this.v1.toArray();
  23230. data.v2 = this.v2.toArray();
  23231. return data;
  23232. };
  23233. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  23234. Curve.prototype.fromJSON.call( this, json );
  23235. this.v0.fromArray( json.v0 );
  23236. this.v1.fromArray( json.v1 );
  23237. this.v2.fromArray( json.v2 );
  23238. return this;
  23239. };
  23240. function SplineCurve( points /* array of Vector2 */ ) {
  23241. Curve.call( this );
  23242. this.type = 'SplineCurve';
  23243. this.points = points || [];
  23244. }
  23245. SplineCurve.prototype = Object.create( Curve.prototype );
  23246. SplineCurve.prototype.constructor = SplineCurve;
  23247. SplineCurve.prototype.isSplineCurve = true;
  23248. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  23249. const point = optionalTarget || new Vector2();
  23250. const points = this.points;
  23251. const p = ( points.length - 1 ) * t;
  23252. const intPoint = Math.floor( p );
  23253. const weight = p - intPoint;
  23254. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  23255. const p1 = points[ intPoint ];
  23256. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  23257. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  23258. point.set(
  23259. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  23260. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  23261. );
  23262. return point;
  23263. };
  23264. SplineCurve.prototype.copy = function ( source ) {
  23265. Curve.prototype.copy.call( this, source );
  23266. this.points = [];
  23267. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  23268. const point = source.points[ i ];
  23269. this.points.push( point.clone() );
  23270. }
  23271. return this;
  23272. };
  23273. SplineCurve.prototype.toJSON = function () {
  23274. const data = Curve.prototype.toJSON.call( this );
  23275. data.points = [];
  23276. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  23277. const point = this.points[ i ];
  23278. data.points.push( point.toArray() );
  23279. }
  23280. return data;
  23281. };
  23282. SplineCurve.prototype.fromJSON = function ( json ) {
  23283. Curve.prototype.fromJSON.call( this, json );
  23284. this.points = [];
  23285. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  23286. const point = json.points[ i ];
  23287. this.points.push( new Vector2().fromArray( point ) );
  23288. }
  23289. return this;
  23290. };
  23291. var Curves = /*#__PURE__*/Object.freeze({
  23292. __proto__: null,
  23293. ArcCurve: ArcCurve,
  23294. CatmullRomCurve3: CatmullRomCurve3,
  23295. CubicBezierCurve: CubicBezierCurve,
  23296. CubicBezierCurve3: CubicBezierCurve3,
  23297. EllipseCurve: EllipseCurve,
  23298. LineCurve: LineCurve,
  23299. LineCurve3: LineCurve3,
  23300. QuadraticBezierCurve: QuadraticBezierCurve,
  23301. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23302. SplineCurve: SplineCurve
  23303. });
  23304. /**
  23305. * @author zz85 / http://www.lab4games.net/zz85/blog
  23306. *
  23307. **/
  23308. /**************************************************************
  23309. * Curved Path - a curve path is simply a array of connected
  23310. * curves, but retains the api of a curve
  23311. **************************************************************/
  23312. function CurvePath() {
  23313. Curve.call( this );
  23314. this.type = 'CurvePath';
  23315. this.curves = [];
  23316. this.autoClose = false; // Automatically closes the path
  23317. }
  23318. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  23319. constructor: CurvePath,
  23320. add: function ( curve ) {
  23321. this.curves.push( curve );
  23322. },
  23323. closePath: function () {
  23324. // Add a line curve if start and end of lines are not connected
  23325. const startPoint = this.curves[ 0 ].getPoint( 0 );
  23326. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  23327. if ( ! startPoint.equals( endPoint ) ) {
  23328. this.curves.push( new LineCurve( endPoint, startPoint ) );
  23329. }
  23330. },
  23331. // To get accurate point with reference to
  23332. // entire path distance at time t,
  23333. // following has to be done:
  23334. // 1. Length of each sub path have to be known
  23335. // 2. Locate and identify type of curve
  23336. // 3. Get t for the curve
  23337. // 4. Return curve.getPointAt(t')
  23338. getPoint: function ( t ) {
  23339. const d = t * this.getLength();
  23340. const curveLengths = this.getCurveLengths();
  23341. let i = 0;
  23342. // To think about boundaries points.
  23343. while ( i < curveLengths.length ) {
  23344. if ( curveLengths[ i ] >= d ) {
  23345. const diff = curveLengths[ i ] - d;
  23346. const curve = this.curves[ i ];
  23347. const segmentLength = curve.getLength();
  23348. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23349. return curve.getPointAt( u );
  23350. }
  23351. i ++;
  23352. }
  23353. return null;
  23354. // loop where sum != 0, sum > d , sum+1 <d
  23355. },
  23356. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23357. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23358. // getPoint() depends on getLength
  23359. getLength: function () {
  23360. const lens = this.getCurveLengths();
  23361. return lens[ lens.length - 1 ];
  23362. },
  23363. // cacheLengths must be recalculated.
  23364. updateArcLengths: function () {
  23365. this.needsUpdate = true;
  23366. this.cacheLengths = null;
  23367. this.getCurveLengths();
  23368. },
  23369. // Compute lengths and cache them
  23370. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23371. getCurveLengths: function () {
  23372. // We use cache values if curves and cache array are same length
  23373. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  23374. return this.cacheLengths;
  23375. }
  23376. // Get length of sub-curve
  23377. // Push sums into cached array
  23378. const lengths = [];
  23379. let sums = 0;
  23380. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  23381. sums += this.curves[ i ].getLength();
  23382. lengths.push( sums );
  23383. }
  23384. this.cacheLengths = lengths;
  23385. return lengths;
  23386. },
  23387. getSpacedPoints: function ( divisions ) {
  23388. if ( divisions === undefined ) divisions = 40;
  23389. const points = [];
  23390. for ( let i = 0; i <= divisions; i ++ ) {
  23391. points.push( this.getPoint( i / divisions ) );
  23392. }
  23393. if ( this.autoClose ) {
  23394. points.push( points[ 0 ] );
  23395. }
  23396. return points;
  23397. },
  23398. getPoints: function ( divisions ) {
  23399. divisions = divisions || 12;
  23400. const points = [];
  23401. let last;
  23402. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  23403. const curve = curves[ i ];
  23404. const resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  23405. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  23406. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  23407. : divisions;
  23408. const pts = curve.getPoints( resolution );
  23409. for ( let j = 0; j < pts.length; j ++ ) {
  23410. const point = pts[ j ];
  23411. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  23412. points.push( point );
  23413. last = point;
  23414. }
  23415. }
  23416. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  23417. points.push( points[ 0 ] );
  23418. }
  23419. return points;
  23420. },
  23421. copy: function ( source ) {
  23422. Curve.prototype.copy.call( this, source );
  23423. this.curves = [];
  23424. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  23425. const curve = source.curves[ i ];
  23426. this.curves.push( curve.clone() );
  23427. }
  23428. this.autoClose = source.autoClose;
  23429. return this;
  23430. },
  23431. toJSON: function () {
  23432. const data = Curve.prototype.toJSON.call( this );
  23433. data.autoClose = this.autoClose;
  23434. data.curves = [];
  23435. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  23436. const curve = this.curves[ i ];
  23437. data.curves.push( curve.toJSON() );
  23438. }
  23439. return data;
  23440. },
  23441. fromJSON: function ( json ) {
  23442. Curve.prototype.fromJSON.call( this, json );
  23443. this.autoClose = json.autoClose;
  23444. this.curves = [];
  23445. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  23446. const curve = json.curves[ i ];
  23447. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  23448. }
  23449. return this;
  23450. }
  23451. } );
  23452. /**
  23453. * @author zz85 / http://www.lab4games.net/zz85/blog
  23454. * Creates free form 2d path using series of points, lines or curves.
  23455. **/
  23456. function Path( points ) {
  23457. CurvePath.call( this );
  23458. this.type = 'Path';
  23459. this.currentPoint = new Vector2();
  23460. if ( points ) {
  23461. this.setFromPoints( points );
  23462. }
  23463. }
  23464. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  23465. constructor: Path,
  23466. setFromPoints: function ( points ) {
  23467. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  23468. for ( let i = 1, l = points.length; i < l; i ++ ) {
  23469. this.lineTo( points[ i ].x, points[ i ].y );
  23470. }
  23471. return this;
  23472. },
  23473. moveTo: function ( x, y ) {
  23474. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  23475. return this;
  23476. },
  23477. lineTo: function ( x, y ) {
  23478. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  23479. this.curves.push( curve );
  23480. this.currentPoint.set( x, y );
  23481. return this;
  23482. },
  23483. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23484. const curve = new QuadraticBezierCurve(
  23485. this.currentPoint.clone(),
  23486. new Vector2( aCPx, aCPy ),
  23487. new Vector2( aX, aY )
  23488. );
  23489. this.curves.push( curve );
  23490. this.currentPoint.set( aX, aY );
  23491. return this;
  23492. },
  23493. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23494. const curve = new CubicBezierCurve(
  23495. this.currentPoint.clone(),
  23496. new Vector2( aCP1x, aCP1y ),
  23497. new Vector2( aCP2x, aCP2y ),
  23498. new Vector2( aX, aY )
  23499. );
  23500. this.curves.push( curve );
  23501. this.currentPoint.set( aX, aY );
  23502. return this;
  23503. },
  23504. splineThru: function ( pts /*Array of Vector*/ ) {
  23505. const npts = [ this.currentPoint.clone() ].concat( pts );
  23506. const curve = new SplineCurve( npts );
  23507. this.curves.push( curve );
  23508. this.currentPoint.copy( pts[ pts.length - 1 ] );
  23509. return this;
  23510. },
  23511. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23512. const x0 = this.currentPoint.x;
  23513. const y0 = this.currentPoint.y;
  23514. this.absarc( aX + x0, aY + y0, aRadius,
  23515. aStartAngle, aEndAngle, aClockwise );
  23516. return this;
  23517. },
  23518. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23519. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  23520. return this;
  23521. },
  23522. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23523. const x0 = this.currentPoint.x;
  23524. const y0 = this.currentPoint.y;
  23525. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23526. return this;
  23527. },
  23528. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23529. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23530. if ( this.curves.length > 0 ) {
  23531. // if a previous curve is present, attempt to join
  23532. const firstPoint = curve.getPoint( 0 );
  23533. if ( ! firstPoint.equals( this.currentPoint ) ) {
  23534. this.lineTo( firstPoint.x, firstPoint.y );
  23535. }
  23536. }
  23537. this.curves.push( curve );
  23538. const lastPoint = curve.getPoint( 1 );
  23539. this.currentPoint.copy( lastPoint );
  23540. return this;
  23541. },
  23542. copy: function ( source ) {
  23543. CurvePath.prototype.copy.call( this, source );
  23544. this.currentPoint.copy( source.currentPoint );
  23545. return this;
  23546. },
  23547. toJSON: function () {
  23548. const data = CurvePath.prototype.toJSON.call( this );
  23549. data.currentPoint = this.currentPoint.toArray();
  23550. return data;
  23551. },
  23552. fromJSON: function ( json ) {
  23553. CurvePath.prototype.fromJSON.call( this, json );
  23554. this.currentPoint.fromArray( json.currentPoint );
  23555. return this;
  23556. }
  23557. } );
  23558. /**
  23559. * @author zz85 / http://www.lab4games.net/zz85/blog
  23560. * Defines a 2d shape plane using paths.
  23561. **/
  23562. // STEP 1 Create a path.
  23563. // STEP 2 Turn path into shape.
  23564. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  23565. // STEP 3a - Extract points from each shape, turn to vertices
  23566. // STEP 3b - Triangulate each shape, add faces.
  23567. function Shape( points ) {
  23568. Path.call( this, points );
  23569. this.uuid = MathUtils.generateUUID();
  23570. this.type = 'Shape';
  23571. this.holes = [];
  23572. }
  23573. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  23574. constructor: Shape,
  23575. getPointsHoles: function ( divisions ) {
  23576. const holesPts = [];
  23577. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  23578. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23579. }
  23580. return holesPts;
  23581. },
  23582. // get points of shape and holes (keypoints based on segments parameter)
  23583. extractPoints: function ( divisions ) {
  23584. return {
  23585. shape: this.getPoints( divisions ),
  23586. holes: this.getPointsHoles( divisions )
  23587. };
  23588. },
  23589. copy: function ( source ) {
  23590. Path.prototype.copy.call( this, source );
  23591. this.holes = [];
  23592. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  23593. const hole = source.holes[ i ];
  23594. this.holes.push( hole.clone() );
  23595. }
  23596. return this;
  23597. },
  23598. toJSON: function () {
  23599. const data = Path.prototype.toJSON.call( this );
  23600. data.uuid = this.uuid;
  23601. data.holes = [];
  23602. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  23603. const hole = this.holes[ i ];
  23604. data.holes.push( hole.toJSON() );
  23605. }
  23606. return data;
  23607. },
  23608. fromJSON: function ( json ) {
  23609. Path.prototype.fromJSON.call( this, json );
  23610. this.uuid = json.uuid;
  23611. this.holes = [];
  23612. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  23613. const hole = json.holes[ i ];
  23614. this.holes.push( new Path().fromJSON( hole ) );
  23615. }
  23616. return this;
  23617. }
  23618. } );
  23619. /**
  23620. * @author mrdoob / http://mrdoob.com/
  23621. * @author alteredq / http://alteredqualia.com/
  23622. */
  23623. function Light( color, intensity ) {
  23624. Object3D.call( this );
  23625. this.type = 'Light';
  23626. this.color = new Color( color );
  23627. this.intensity = intensity !== undefined ? intensity : 1;
  23628. this.receiveShadow = undefined;
  23629. }
  23630. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23631. constructor: Light,
  23632. isLight: true,
  23633. copy: function ( source ) {
  23634. Object3D.prototype.copy.call( this, source );
  23635. this.color.copy( source.color );
  23636. this.intensity = source.intensity;
  23637. return this;
  23638. },
  23639. toJSON: function ( meta ) {
  23640. const data = Object3D.prototype.toJSON.call( this, meta );
  23641. data.object.color = this.color.getHex();
  23642. data.object.intensity = this.intensity;
  23643. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  23644. if ( this.distance !== undefined ) data.object.distance = this.distance;
  23645. if ( this.angle !== undefined ) data.object.angle = this.angle;
  23646. if ( this.decay !== undefined ) data.object.decay = this.decay;
  23647. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  23648. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  23649. return data;
  23650. }
  23651. } );
  23652. /**
  23653. * @author alteredq / http://alteredqualia.com/
  23654. */
  23655. function HemisphereLight( skyColor, groundColor, intensity ) {
  23656. Light.call( this, skyColor, intensity );
  23657. this.type = 'HemisphereLight';
  23658. this.castShadow = undefined;
  23659. this.position.copy( Object3D.DefaultUp );
  23660. this.updateMatrix();
  23661. this.groundColor = new Color( groundColor );
  23662. }
  23663. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23664. constructor: HemisphereLight,
  23665. isHemisphereLight: true,
  23666. copy: function ( source ) {
  23667. Light.prototype.copy.call( this, source );
  23668. this.groundColor.copy( source.groundColor );
  23669. return this;
  23670. }
  23671. } );
  23672. /**
  23673. * @author mrdoob / http://mrdoob.com/
  23674. */
  23675. function LightShadow( camera ) {
  23676. this.camera = camera;
  23677. this.bias = 0;
  23678. this.normalBias = 0;
  23679. this.radius = 1;
  23680. this.mapSize = new Vector2( 512, 512 );
  23681. this.map = null;
  23682. this.mapPass = null;
  23683. this.matrix = new Matrix4();
  23684. this.autoUpdate = true;
  23685. this.needsUpdate = false;
  23686. this._frustum = new Frustum();
  23687. this._frameExtents = new Vector2( 1, 1 );
  23688. this._viewportCount = 1;
  23689. this._viewports = [
  23690. new Vector4( 0, 0, 1, 1 )
  23691. ];
  23692. }
  23693. Object.assign( LightShadow.prototype, {
  23694. _projScreenMatrix: new Matrix4(),
  23695. _lightPositionWorld: new Vector3(),
  23696. _lookTarget: new Vector3(),
  23697. getViewportCount: function () {
  23698. return this._viewportCount;
  23699. },
  23700. getFrustum: function () {
  23701. return this._frustum;
  23702. },
  23703. updateMatrices: function ( light ) {
  23704. const shadowCamera = this.camera,
  23705. shadowMatrix = this.matrix,
  23706. projScreenMatrix = this._projScreenMatrix,
  23707. lookTarget = this._lookTarget,
  23708. lightPositionWorld = this._lightPositionWorld;
  23709. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23710. shadowCamera.position.copy( lightPositionWorld );
  23711. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23712. shadowCamera.lookAt( lookTarget );
  23713. shadowCamera.updateMatrixWorld();
  23714. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23715. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23716. shadowMatrix.set(
  23717. 0.5, 0.0, 0.0, 0.5,
  23718. 0.0, 0.5, 0.0, 0.5,
  23719. 0.0, 0.0, 0.5, 0.5,
  23720. 0.0, 0.0, 0.0, 1.0
  23721. );
  23722. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23723. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23724. },
  23725. getViewport: function ( viewportIndex ) {
  23726. return this._viewports[ viewportIndex ];
  23727. },
  23728. getFrameExtents: function () {
  23729. return this._frameExtents;
  23730. },
  23731. copy: function ( source ) {
  23732. this.camera = source.camera.clone();
  23733. this.bias = source.bias;
  23734. this.radius = source.radius;
  23735. this.mapSize.copy( source.mapSize );
  23736. return this;
  23737. },
  23738. clone: function () {
  23739. return new this.constructor().copy( this );
  23740. },
  23741. toJSON: function () {
  23742. const object = {};
  23743. if ( this.bias !== 0 ) object.bias = this.bias;
  23744. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  23745. if ( this.radius !== 1 ) object.radius = this.radius;
  23746. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23747. object.camera = this.camera.toJSON( false ).object;
  23748. delete object.camera.matrix;
  23749. return object;
  23750. }
  23751. } );
  23752. /**
  23753. * @author mrdoob / http://mrdoob.com/
  23754. */
  23755. function SpotLightShadow() {
  23756. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23757. }
  23758. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23759. constructor: SpotLightShadow,
  23760. isSpotLightShadow: true,
  23761. updateMatrices: function ( light ) {
  23762. const camera = this.camera;
  23763. const fov = MathUtils.RAD2DEG * 2 * light.angle;
  23764. const aspect = this.mapSize.width / this.mapSize.height;
  23765. const far = light.distance || camera.far;
  23766. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23767. camera.fov = fov;
  23768. camera.aspect = aspect;
  23769. camera.far = far;
  23770. camera.updateProjectionMatrix();
  23771. }
  23772. LightShadow.prototype.updateMatrices.call( this, light );
  23773. }
  23774. } );
  23775. /**
  23776. * @author alteredq / http://alteredqualia.com/
  23777. */
  23778. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23779. Light.call( this, color, intensity );
  23780. this.type = 'SpotLight';
  23781. this.position.copy( Object3D.DefaultUp );
  23782. this.updateMatrix();
  23783. this.target = new Object3D();
  23784. Object.defineProperty( this, 'power', {
  23785. get: function () {
  23786. // intensity = power per solid angle.
  23787. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23788. return this.intensity * Math.PI;
  23789. },
  23790. set: function ( power ) {
  23791. // intensity = power per solid angle.
  23792. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23793. this.intensity = power / Math.PI;
  23794. }
  23795. } );
  23796. this.distance = ( distance !== undefined ) ? distance : 0;
  23797. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23798. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23799. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23800. this.shadow = new SpotLightShadow();
  23801. }
  23802. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23803. constructor: SpotLight,
  23804. isSpotLight: true,
  23805. copy: function ( source ) {
  23806. Light.prototype.copy.call( this, source );
  23807. this.distance = source.distance;
  23808. this.angle = source.angle;
  23809. this.penumbra = source.penumbra;
  23810. this.decay = source.decay;
  23811. this.target = source.target.clone();
  23812. this.shadow = source.shadow.clone();
  23813. return this;
  23814. }
  23815. } );
  23816. function PointLightShadow() {
  23817. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23818. this._frameExtents = new Vector2( 4, 2 );
  23819. this._viewportCount = 6;
  23820. this._viewports = [
  23821. // These viewports map a cube-map onto a 2D texture with the
  23822. // following orientation:
  23823. //
  23824. // xzXZ
  23825. // y Y
  23826. //
  23827. // X - Positive x direction
  23828. // x - Negative x direction
  23829. // Y - Positive y direction
  23830. // y - Negative y direction
  23831. // Z - Positive z direction
  23832. // z - Negative z direction
  23833. // positive X
  23834. new Vector4( 2, 1, 1, 1 ),
  23835. // negative X
  23836. new Vector4( 0, 1, 1, 1 ),
  23837. // positive Z
  23838. new Vector4( 3, 1, 1, 1 ),
  23839. // negative Z
  23840. new Vector4( 1, 1, 1, 1 ),
  23841. // positive Y
  23842. new Vector4( 3, 0, 1, 1 ),
  23843. // negative Y
  23844. new Vector4( 1, 0, 1, 1 )
  23845. ];
  23846. this._cubeDirections = [
  23847. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23848. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23849. ];
  23850. this._cubeUps = [
  23851. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23852. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23853. ];
  23854. }
  23855. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23856. constructor: PointLightShadow,
  23857. isPointLightShadow: true,
  23858. updateMatrices: function ( light, viewportIndex ) {
  23859. if ( viewportIndex === undefined ) viewportIndex = 0;
  23860. const camera = this.camera,
  23861. shadowMatrix = this.matrix,
  23862. lightPositionWorld = this._lightPositionWorld,
  23863. lookTarget = this._lookTarget,
  23864. projScreenMatrix = this._projScreenMatrix;
  23865. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23866. camera.position.copy( lightPositionWorld );
  23867. lookTarget.copy( camera.position );
  23868. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23869. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23870. camera.lookAt( lookTarget );
  23871. camera.updateMatrixWorld();
  23872. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  23873. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23874. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23875. }
  23876. } );
  23877. /**
  23878. * @author mrdoob / http://mrdoob.com/
  23879. */
  23880. function PointLight( color, intensity, distance, decay ) {
  23881. Light.call( this, color, intensity );
  23882. this.type = 'PointLight';
  23883. Object.defineProperty( this, 'power', {
  23884. get: function () {
  23885. // intensity = power per solid angle.
  23886. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23887. return this.intensity * 4 * Math.PI;
  23888. },
  23889. set: function ( power ) {
  23890. // intensity = power per solid angle.
  23891. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23892. this.intensity = power / ( 4 * Math.PI );
  23893. }
  23894. } );
  23895. this.distance = ( distance !== undefined ) ? distance : 0;
  23896. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23897. this.shadow = new PointLightShadow();
  23898. }
  23899. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23900. constructor: PointLight,
  23901. isPointLight: true,
  23902. copy: function ( source ) {
  23903. Light.prototype.copy.call( this, source );
  23904. this.distance = source.distance;
  23905. this.decay = source.decay;
  23906. this.shadow = source.shadow.clone();
  23907. return this;
  23908. }
  23909. } );
  23910. /**
  23911. * @author alteredq / http://alteredqualia.com/
  23912. * @author arose / http://github.com/arose
  23913. */
  23914. function OrthographicCamera( left, right, top, bottom, near, far ) {
  23915. Camera.call( this );
  23916. this.type = 'OrthographicCamera';
  23917. this.zoom = 1;
  23918. this.view = null;
  23919. this.left = ( left !== undefined ) ? left : - 1;
  23920. this.right = ( right !== undefined ) ? right : 1;
  23921. this.top = ( top !== undefined ) ? top : 1;
  23922. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  23923. this.near = ( near !== undefined ) ? near : 0.1;
  23924. this.far = ( far !== undefined ) ? far : 2000;
  23925. this.updateProjectionMatrix();
  23926. }
  23927. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23928. constructor: OrthographicCamera,
  23929. isOrthographicCamera: true,
  23930. copy: function ( source, recursive ) {
  23931. Camera.prototype.copy.call( this, source, recursive );
  23932. this.left = source.left;
  23933. this.right = source.right;
  23934. this.top = source.top;
  23935. this.bottom = source.bottom;
  23936. this.near = source.near;
  23937. this.far = source.far;
  23938. this.zoom = source.zoom;
  23939. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23940. return this;
  23941. },
  23942. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23943. if ( this.view === null ) {
  23944. this.view = {
  23945. enabled: true,
  23946. fullWidth: 1,
  23947. fullHeight: 1,
  23948. offsetX: 0,
  23949. offsetY: 0,
  23950. width: 1,
  23951. height: 1
  23952. };
  23953. }
  23954. this.view.enabled = true;
  23955. this.view.fullWidth = fullWidth;
  23956. this.view.fullHeight = fullHeight;
  23957. this.view.offsetX = x;
  23958. this.view.offsetY = y;
  23959. this.view.width = width;
  23960. this.view.height = height;
  23961. this.updateProjectionMatrix();
  23962. },
  23963. clearViewOffset: function () {
  23964. if ( this.view !== null ) {
  23965. this.view.enabled = false;
  23966. }
  23967. this.updateProjectionMatrix();
  23968. },
  23969. updateProjectionMatrix: function () {
  23970. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23971. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23972. const cx = ( this.right + this.left ) / 2;
  23973. const cy = ( this.top + this.bottom ) / 2;
  23974. let left = cx - dx;
  23975. let right = cx + dx;
  23976. let top = cy + dy;
  23977. let bottom = cy - dy;
  23978. if ( this.view !== null && this.view.enabled ) {
  23979. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  23980. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  23981. left += scaleW * this.view.offsetX;
  23982. right = left + scaleW * this.view.width;
  23983. top -= scaleH * this.view.offsetY;
  23984. bottom = top - scaleH * this.view.height;
  23985. }
  23986. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  23987. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  23988. },
  23989. toJSON: function ( meta ) {
  23990. const data = Object3D.prototype.toJSON.call( this, meta );
  23991. data.object.zoom = this.zoom;
  23992. data.object.left = this.left;
  23993. data.object.right = this.right;
  23994. data.object.top = this.top;
  23995. data.object.bottom = this.bottom;
  23996. data.object.near = this.near;
  23997. data.object.far = this.far;
  23998. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  23999. return data;
  24000. }
  24001. } );
  24002. /**
  24003. * @author mrdoob / http://mrdoob.com/
  24004. */
  24005. function DirectionalLightShadow() {
  24006. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  24007. }
  24008. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  24009. constructor: DirectionalLightShadow,
  24010. isDirectionalLightShadow: true,
  24011. updateMatrices: function ( light ) {
  24012. LightShadow.prototype.updateMatrices.call( this, light );
  24013. }
  24014. } );
  24015. /**
  24016. * @author mrdoob / http://mrdoob.com/
  24017. * @author alteredq / http://alteredqualia.com/
  24018. */
  24019. function DirectionalLight( color, intensity ) {
  24020. Light.call( this, color, intensity );
  24021. this.type = 'DirectionalLight';
  24022. this.position.copy( Object3D.DefaultUp );
  24023. this.updateMatrix();
  24024. this.target = new Object3D();
  24025. this.shadow = new DirectionalLightShadow();
  24026. }
  24027. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24028. constructor: DirectionalLight,
  24029. isDirectionalLight: true,
  24030. copy: function ( source ) {
  24031. Light.prototype.copy.call( this, source );
  24032. this.target = source.target.clone();
  24033. this.shadow = source.shadow.clone();
  24034. return this;
  24035. }
  24036. } );
  24037. /**
  24038. * @author mrdoob / http://mrdoob.com/
  24039. */
  24040. function AmbientLight( color, intensity ) {
  24041. Light.call( this, color, intensity );
  24042. this.type = 'AmbientLight';
  24043. this.castShadow = undefined;
  24044. }
  24045. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24046. constructor: AmbientLight,
  24047. isAmbientLight: true
  24048. } );
  24049. /**
  24050. * @author abelnation / http://github.com/abelnation
  24051. */
  24052. function RectAreaLight( color, intensity, width, height ) {
  24053. Light.call( this, color, intensity );
  24054. this.type = 'RectAreaLight';
  24055. this.width = ( width !== undefined ) ? width : 10;
  24056. this.height = ( height !== undefined ) ? height : 10;
  24057. }
  24058. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  24059. constructor: RectAreaLight,
  24060. isRectAreaLight: true,
  24061. copy: function ( source ) {
  24062. Light.prototype.copy.call( this, source );
  24063. this.width = source.width;
  24064. this.height = source.height;
  24065. return this;
  24066. },
  24067. toJSON: function ( meta ) {
  24068. const data = Light.prototype.toJSON.call( this, meta );
  24069. data.object.width = this.width;
  24070. data.object.height = this.height;
  24071. return data;
  24072. }
  24073. } );
  24074. /**
  24075. * @author bhouston / http://clara.io
  24076. * @author WestLangley / http://github.com/WestLangley
  24077. *
  24078. * Primary reference:
  24079. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24080. *
  24081. * Secondary reference:
  24082. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24083. */
  24084. // 3-band SH defined by 9 coefficients
  24085. function SphericalHarmonics3() {
  24086. this.coefficients = [];
  24087. for ( let i = 0; i < 9; i ++ ) {
  24088. this.coefficients.push( new Vector3() );
  24089. }
  24090. }
  24091. Object.assign( SphericalHarmonics3.prototype, {
  24092. isSphericalHarmonics3: true,
  24093. set: function ( coefficients ) {
  24094. for ( let i = 0; i < 9; i ++ ) {
  24095. this.coefficients[ i ].copy( coefficients[ i ] );
  24096. }
  24097. return this;
  24098. },
  24099. zero: function () {
  24100. for ( let i = 0; i < 9; i ++ ) {
  24101. this.coefficients[ i ].set( 0, 0, 0 );
  24102. }
  24103. return this;
  24104. },
  24105. // get the radiance in the direction of the normal
  24106. // target is a Vector3
  24107. getAt: function ( normal, target ) {
  24108. // normal is assumed to be unit length
  24109. const x = normal.x, y = normal.y, z = normal.z;
  24110. const coeff = this.coefficients;
  24111. // band 0
  24112. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24113. // band 1
  24114. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  24115. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  24116. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  24117. // band 2
  24118. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  24119. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  24120. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24121. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  24122. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24123. return target;
  24124. },
  24125. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24126. // target is a Vector3
  24127. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24128. getIrradianceAt: function ( normal, target ) {
  24129. // normal is assumed to be unit length
  24130. const x = normal.x, y = normal.y, z = normal.z;
  24131. const coeff = this.coefficients;
  24132. // band 0
  24133. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24134. // band 1
  24135. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24136. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  24137. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  24138. // band 2
  24139. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24140. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24141. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24142. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24143. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24144. return target;
  24145. },
  24146. add: function ( sh ) {
  24147. for ( let i = 0; i < 9; i ++ ) {
  24148. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24149. }
  24150. return this;
  24151. },
  24152. addScaledSH: function ( sh, s ) {
  24153. for ( let i = 0; i < 9; i ++ ) {
  24154. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  24155. }
  24156. return this;
  24157. },
  24158. scale: function ( s ) {
  24159. for ( let i = 0; i < 9; i ++ ) {
  24160. this.coefficients[ i ].multiplyScalar( s );
  24161. }
  24162. return this;
  24163. },
  24164. lerp: function ( sh, alpha ) {
  24165. for ( let i = 0; i < 9; i ++ ) {
  24166. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24167. }
  24168. return this;
  24169. },
  24170. equals: function ( sh ) {
  24171. for ( let i = 0; i < 9; i ++ ) {
  24172. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24173. return false;
  24174. }
  24175. }
  24176. return true;
  24177. },
  24178. copy: function ( sh ) {
  24179. return this.set( sh.coefficients );
  24180. },
  24181. clone: function () {
  24182. return new this.constructor().copy( this );
  24183. },
  24184. fromArray: function ( array, offset ) {
  24185. if ( offset === undefined ) offset = 0;
  24186. const coefficients = this.coefficients;
  24187. for ( let i = 0; i < 9; i ++ ) {
  24188. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  24189. }
  24190. return this;
  24191. },
  24192. toArray: function ( array, offset ) {
  24193. if ( array === undefined ) array = [];
  24194. if ( offset === undefined ) offset = 0;
  24195. const coefficients = this.coefficients;
  24196. for ( let i = 0; i < 9; i ++ ) {
  24197. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  24198. }
  24199. return array;
  24200. }
  24201. } );
  24202. Object.assign( SphericalHarmonics3, {
  24203. // evaluate the basis functions
  24204. // shBasis is an Array[ 9 ]
  24205. getBasisAt: function ( normal, shBasis ) {
  24206. // normal is assumed to be unit length
  24207. const x = normal.x, y = normal.y, z = normal.z;
  24208. // band 0
  24209. shBasis[ 0 ] = 0.282095;
  24210. // band 1
  24211. shBasis[ 1 ] = 0.488603 * y;
  24212. shBasis[ 2 ] = 0.488603 * z;
  24213. shBasis[ 3 ] = 0.488603 * x;
  24214. // band 2
  24215. shBasis[ 4 ] = 1.092548 * x * y;
  24216. shBasis[ 5 ] = 1.092548 * y * z;
  24217. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24218. shBasis[ 7 ] = 1.092548 * x * z;
  24219. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24220. }
  24221. } );
  24222. /**
  24223. * @author WestLangley / http://github.com/WestLangley
  24224. *
  24225. * A LightProbe is a source of indirect-diffuse light
  24226. */
  24227. function LightProbe( sh, intensity ) {
  24228. Light.call( this, undefined, intensity );
  24229. this.type = 'LightProbe';
  24230. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24231. }
  24232. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24233. constructor: LightProbe,
  24234. isLightProbe: true,
  24235. copy: function ( source ) {
  24236. Light.prototype.copy.call( this, source );
  24237. this.sh.copy( source.sh );
  24238. return this;
  24239. },
  24240. fromJSON: function ( json ) {
  24241. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24242. this.sh.fromArray( json.sh );
  24243. return this;
  24244. },
  24245. toJSON: function ( meta ) {
  24246. const data = Light.prototype.toJSON.call( this, meta );
  24247. data.object.sh = this.sh.toArray();
  24248. return data;
  24249. }
  24250. } );
  24251. /**
  24252. * @author mrdoob / http://mrdoob.com/
  24253. */
  24254. function MaterialLoader( manager ) {
  24255. Loader.call( this, manager );
  24256. this.textures = {};
  24257. }
  24258. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24259. constructor: MaterialLoader,
  24260. load: function ( url, onLoad, onProgress, onError ) {
  24261. const scope = this;
  24262. const loader = new FileLoader( scope.manager );
  24263. loader.setPath( scope.path );
  24264. loader.load( url, function ( text ) {
  24265. try {
  24266. onLoad( scope.parse( JSON.parse( text ) ) );
  24267. } catch ( e ) {
  24268. if ( onError ) {
  24269. onError( e );
  24270. } else {
  24271. console.error( e );
  24272. }
  24273. scope.manager.itemError( url );
  24274. }
  24275. }, onProgress, onError );
  24276. },
  24277. parse: function ( json ) {
  24278. const textures = this.textures;
  24279. function getTexture( name ) {
  24280. if ( textures[ name ] === undefined ) {
  24281. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  24282. }
  24283. return textures[ name ];
  24284. }
  24285. const material = new Materials[ json.type ]();
  24286. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  24287. if ( json.name !== undefined ) material.name = json.name;
  24288. if ( json.color !== undefined ) material.color.setHex( json.color );
  24289. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  24290. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  24291. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  24292. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  24293. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  24294. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  24295. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  24296. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  24297. if ( json.fog !== undefined ) material.fog = json.fog;
  24298. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  24299. if ( json.blending !== undefined ) material.blending = json.blending;
  24300. if ( json.combine !== undefined ) material.combine = json.combine;
  24301. if ( json.side !== undefined ) material.side = json.side;
  24302. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  24303. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  24304. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  24305. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  24306. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  24307. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  24308. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  24309. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  24310. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  24311. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  24312. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  24313. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  24314. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  24315. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  24316. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  24317. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  24318. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  24319. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  24320. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  24321. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  24322. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  24323. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  24324. if ( json.scale !== undefined ) material.scale = json.scale;
  24325. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  24326. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24327. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24328. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  24329. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  24330. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  24331. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  24332. if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents;
  24333. if ( json.visible !== undefined ) material.visible = json.visible;
  24334. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  24335. if ( json.userData !== undefined ) material.userData = json.userData;
  24336. if ( json.vertexColors !== undefined ) {
  24337. if ( typeof json.vertexColors === 'number' ) {
  24338. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  24339. } else {
  24340. material.vertexColors = json.vertexColors;
  24341. }
  24342. }
  24343. // Shader Material
  24344. if ( json.uniforms !== undefined ) {
  24345. for ( const name in json.uniforms ) {
  24346. const uniform = json.uniforms[ name ];
  24347. material.uniforms[ name ] = {};
  24348. switch ( uniform.type ) {
  24349. case 't':
  24350. material.uniforms[ name ].value = getTexture( uniform.value );
  24351. break;
  24352. case 'c':
  24353. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  24354. break;
  24355. case 'v2':
  24356. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  24357. break;
  24358. case 'v3':
  24359. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  24360. break;
  24361. case 'v4':
  24362. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  24363. break;
  24364. case 'm3':
  24365. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  24366. case 'm4':
  24367. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  24368. break;
  24369. default:
  24370. material.uniforms[ name ].value = uniform.value;
  24371. }
  24372. }
  24373. }
  24374. if ( json.defines !== undefined ) material.defines = json.defines;
  24375. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  24376. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  24377. if ( json.extensions !== undefined ) {
  24378. for ( const key in json.extensions ) {
  24379. material.extensions[ key ] = json.extensions[ key ];
  24380. }
  24381. }
  24382. // Deprecated
  24383. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  24384. // for PointsMaterial
  24385. if ( json.size !== undefined ) material.size = json.size;
  24386. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  24387. // maps
  24388. if ( json.map !== undefined ) material.map = getTexture( json.map );
  24389. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  24390. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  24391. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  24392. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  24393. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  24394. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  24395. if ( json.normalScale !== undefined ) {
  24396. let normalScale = json.normalScale;
  24397. if ( Array.isArray( normalScale ) === false ) {
  24398. // Blender exporter used to export a scalar. See #7459
  24399. normalScale = [ normalScale, normalScale ];
  24400. }
  24401. material.normalScale = new Vector2().fromArray( normalScale );
  24402. }
  24403. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  24404. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  24405. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  24406. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  24407. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  24408. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  24409. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  24410. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  24411. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  24412. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  24413. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  24414. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  24415. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  24416. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  24417. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  24418. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  24419. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  24420. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  24421. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  24422. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  24423. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  24424. return material;
  24425. },
  24426. setTextures: function ( value ) {
  24427. this.textures = value;
  24428. return this;
  24429. }
  24430. } );
  24431. /**
  24432. * @author Don McCurdy / https://www.donmccurdy.com
  24433. */
  24434. const LoaderUtils = {
  24435. decodeText: function ( array ) {
  24436. if ( typeof TextDecoder !== 'undefined' ) {
  24437. return new TextDecoder().decode( array );
  24438. }
  24439. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24440. // throws a "maximum call stack size exceeded" error for large arrays.
  24441. let s = '';
  24442. for ( let i = 0, il = array.length; i < il; i ++ ) {
  24443. // Implicitly assumes little-endian.
  24444. s += String.fromCharCode( array[ i ] );
  24445. }
  24446. try {
  24447. // merges multi-byte utf-8 characters.
  24448. return decodeURIComponent( escape( s ) );
  24449. } catch ( e ) { // see #16358
  24450. return s;
  24451. }
  24452. },
  24453. extractUrlBase: function ( url ) {
  24454. const index = url.lastIndexOf( '/' );
  24455. if ( index === - 1 ) return './';
  24456. return url.substr( 0, index + 1 );
  24457. }
  24458. };
  24459. /**
  24460. * @author benaadams / https://twitter.com/ben_a_adams
  24461. */
  24462. function InstancedBufferGeometry() {
  24463. BufferGeometry.call( this );
  24464. this.type = 'InstancedBufferGeometry';
  24465. this.instanceCount = Infinity;
  24466. }
  24467. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24468. constructor: InstancedBufferGeometry,
  24469. isInstancedBufferGeometry: true,
  24470. copy: function ( source ) {
  24471. BufferGeometry.prototype.copy.call( this, source );
  24472. this.instanceCount = source.instanceCount;
  24473. return this;
  24474. },
  24475. clone: function () {
  24476. return new this.constructor().copy( this );
  24477. },
  24478. toJSON: function () {
  24479. const data = BufferGeometry.prototype.toJSON.call( this );
  24480. data.instanceCount = this.instanceCount;
  24481. data.isInstancedBufferGeometry = true;
  24482. return data;
  24483. }
  24484. } );
  24485. /**
  24486. * @author benaadams / https://twitter.com/ben_a_adams
  24487. */
  24488. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  24489. if ( typeof ( normalized ) === 'number' ) {
  24490. meshPerAttribute = normalized;
  24491. normalized = false;
  24492. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  24493. }
  24494. BufferAttribute.call( this, array, itemSize, normalized );
  24495. this.meshPerAttribute = meshPerAttribute || 1;
  24496. }
  24497. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  24498. constructor: InstancedBufferAttribute,
  24499. isInstancedBufferAttribute: true,
  24500. copy: function ( source ) {
  24501. BufferAttribute.prototype.copy.call( this, source );
  24502. this.meshPerAttribute = source.meshPerAttribute;
  24503. return this;
  24504. },
  24505. toJSON: function () {
  24506. const data = BufferAttribute.prototype.toJSON.call( this );
  24507. data.meshPerAttribute = this.meshPerAttribute;
  24508. data.isInstancedBufferAttribute = true;
  24509. return data;
  24510. }
  24511. } );
  24512. /**
  24513. * @author mrdoob / http://mrdoob.com/
  24514. */
  24515. function BufferGeometryLoader( manager ) {
  24516. Loader.call( this, manager );
  24517. }
  24518. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24519. constructor: BufferGeometryLoader,
  24520. load: function ( url, onLoad, onProgress, onError ) {
  24521. const scope = this;
  24522. const loader = new FileLoader( scope.manager );
  24523. loader.setPath( scope.path );
  24524. loader.load( url, function ( text ) {
  24525. try {
  24526. onLoad( scope.parse( JSON.parse( text ) ) );
  24527. } catch ( e ) {
  24528. if ( onError ) {
  24529. onError( e );
  24530. } else {
  24531. console.error( e );
  24532. }
  24533. scope.manager.itemError( url );
  24534. }
  24535. }, onProgress, onError );
  24536. },
  24537. parse: function ( json ) {
  24538. const interleavedBufferMap = {};
  24539. const arrayBufferMap = {};
  24540. function getInterleavedBuffer( json, uuid ) {
  24541. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  24542. const interleavedBuffers = json.interleavedBuffers;
  24543. const interleavedBuffer = interleavedBuffers[ uuid ];
  24544. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  24545. const array = new TYPED_ARRAYS[ interleavedBuffer.type ]( buffer );
  24546. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  24547. ib.uuid = interleavedBuffer.uuid;
  24548. interleavedBufferMap[ uuid ] = ib;
  24549. return ib;
  24550. }
  24551. function getArrayBuffer( json, uuid ) {
  24552. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  24553. const arrayBuffers = json.arrayBuffers;
  24554. const arrayBuffer = arrayBuffers[ uuid ];
  24555. const ab = new Uint32Array( arrayBuffer ).buffer;
  24556. arrayBufferMap[ uuid ] = ab;
  24557. return ab;
  24558. }
  24559. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24560. const index = json.data.index;
  24561. if ( index !== undefined ) {
  24562. const typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  24563. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  24564. }
  24565. const attributes = json.data.attributes;
  24566. for ( const key in attributes ) {
  24567. const attribute = attributes[ key ];
  24568. let bufferAttribute;
  24569. if ( attribute.isInterleavedBufferAttribute ) {
  24570. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24571. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24572. } else {
  24573. const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  24574. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24575. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  24576. }
  24577. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24578. geometry.setAttribute( key, bufferAttribute );
  24579. }
  24580. const morphAttributes = json.data.morphAttributes;
  24581. if ( morphAttributes ) {
  24582. for ( const key in morphAttributes ) {
  24583. const attributeArray = morphAttributes[ key ];
  24584. const array = [];
  24585. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  24586. const attribute = attributeArray[ i ];
  24587. let bufferAttribute;
  24588. if ( attribute.isInterleavedBufferAttribute ) {
  24589. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24590. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24591. } else {
  24592. const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  24593. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  24594. }
  24595. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24596. array.push( bufferAttribute );
  24597. }
  24598. geometry.morphAttributes[ key ] = array;
  24599. }
  24600. }
  24601. const morphTargetsRelative = json.data.morphTargetsRelative;
  24602. if ( morphTargetsRelative ) {
  24603. geometry.morphTargetsRelative = true;
  24604. }
  24605. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24606. if ( groups !== undefined ) {
  24607. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  24608. const group = groups[ i ];
  24609. geometry.addGroup( group.start, group.count, group.materialIndex );
  24610. }
  24611. }
  24612. const boundingSphere = json.data.boundingSphere;
  24613. if ( boundingSphere !== undefined ) {
  24614. const center = new Vector3();
  24615. if ( boundingSphere.center !== undefined ) {
  24616. center.fromArray( boundingSphere.center );
  24617. }
  24618. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  24619. }
  24620. if ( json.name ) geometry.name = json.name;
  24621. if ( json.userData ) geometry.userData = json.userData;
  24622. return geometry;
  24623. }
  24624. } );
  24625. const TYPED_ARRAYS = {
  24626. Int8Array: Int8Array,
  24627. Uint8Array: Uint8Array,
  24628. // Workaround for IE11 pre KB2929437. See #11440
  24629. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  24630. Int16Array: Int16Array,
  24631. Uint16Array: Uint16Array,
  24632. Int32Array: Int32Array,
  24633. Uint32Array: Uint32Array,
  24634. Float32Array: Float32Array,
  24635. Float64Array: Float64Array
  24636. };
  24637. /**
  24638. * @author mrdoob / http://mrdoob.com/
  24639. */
  24640. function ObjectLoader( manager ) {
  24641. Loader.call( this, manager );
  24642. }
  24643. ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24644. constructor: ObjectLoader,
  24645. load: function ( url, onLoad, onProgress, onError ) {
  24646. const scope = this;
  24647. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24648. this.resourcePath = this.resourcePath || path;
  24649. const loader = new FileLoader( scope.manager );
  24650. loader.setPath( this.path );
  24651. loader.load( url, function ( text ) {
  24652. let json = null;
  24653. try {
  24654. json = JSON.parse( text );
  24655. } catch ( error ) {
  24656. if ( onError !== undefined ) onError( error );
  24657. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  24658. return;
  24659. }
  24660. const metadata = json.metadata;
  24661. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24662. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24663. return;
  24664. }
  24665. scope.parse( json, onLoad );
  24666. }, onProgress, onError );
  24667. },
  24668. parse: function ( json, onLoad ) {
  24669. const shapes = this.parseShape( json.shapes );
  24670. const geometries = this.parseGeometries( json.geometries, shapes );
  24671. const images = this.parseImages( json.images, function () {
  24672. if ( onLoad !== undefined ) onLoad( object );
  24673. } );
  24674. const textures = this.parseTextures( json.textures, images );
  24675. const materials = this.parseMaterials( json.materials, textures );
  24676. const object = this.parseObject( json.object, geometries, materials );
  24677. if ( json.animations ) {
  24678. object.animations = this.parseAnimations( json.animations );
  24679. }
  24680. if ( json.images === undefined || json.images.length === 0 ) {
  24681. if ( onLoad !== undefined ) onLoad( object );
  24682. }
  24683. return object;
  24684. },
  24685. parseShape: function ( json ) {
  24686. const shapes = {};
  24687. if ( json !== undefined ) {
  24688. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24689. const shape = new Shape().fromJSON( json[ i ] );
  24690. shapes[ shape.uuid ] = shape;
  24691. }
  24692. }
  24693. return shapes;
  24694. },
  24695. parseGeometries: function ( json, shapes ) {
  24696. const geometries = {};
  24697. let geometryShapes;
  24698. if ( json !== undefined ) {
  24699. const bufferGeometryLoader = new BufferGeometryLoader();
  24700. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24701. let geometry;
  24702. const data = json[ i ];
  24703. switch ( data.type ) {
  24704. case 'PlaneGeometry':
  24705. case 'PlaneBufferGeometry':
  24706. geometry = new Geometries[ data.type ](
  24707. data.width,
  24708. data.height,
  24709. data.widthSegments,
  24710. data.heightSegments
  24711. );
  24712. break;
  24713. case 'BoxGeometry':
  24714. case 'BoxBufferGeometry':
  24715. case 'CubeGeometry': // backwards compatible
  24716. geometry = new Geometries[ data.type ](
  24717. data.width,
  24718. data.height,
  24719. data.depth,
  24720. data.widthSegments,
  24721. data.heightSegments,
  24722. data.depthSegments
  24723. );
  24724. break;
  24725. case 'CircleGeometry':
  24726. case 'CircleBufferGeometry':
  24727. geometry = new Geometries[ data.type ](
  24728. data.radius,
  24729. data.segments,
  24730. data.thetaStart,
  24731. data.thetaLength
  24732. );
  24733. break;
  24734. case 'CylinderGeometry':
  24735. case 'CylinderBufferGeometry':
  24736. geometry = new Geometries[ data.type ](
  24737. data.radiusTop,
  24738. data.radiusBottom,
  24739. data.height,
  24740. data.radialSegments,
  24741. data.heightSegments,
  24742. data.openEnded,
  24743. data.thetaStart,
  24744. data.thetaLength
  24745. );
  24746. break;
  24747. case 'ConeGeometry':
  24748. case 'ConeBufferGeometry':
  24749. geometry = new Geometries[ data.type ](
  24750. data.radius,
  24751. data.height,
  24752. data.radialSegments,
  24753. data.heightSegments,
  24754. data.openEnded,
  24755. data.thetaStart,
  24756. data.thetaLength
  24757. );
  24758. break;
  24759. case 'SphereGeometry':
  24760. case 'SphereBufferGeometry':
  24761. geometry = new Geometries[ data.type ](
  24762. data.radius,
  24763. data.widthSegments,
  24764. data.heightSegments,
  24765. data.phiStart,
  24766. data.phiLength,
  24767. data.thetaStart,
  24768. data.thetaLength
  24769. );
  24770. break;
  24771. case 'DodecahedronGeometry':
  24772. case 'DodecahedronBufferGeometry':
  24773. case 'IcosahedronGeometry':
  24774. case 'IcosahedronBufferGeometry':
  24775. case 'OctahedronGeometry':
  24776. case 'OctahedronBufferGeometry':
  24777. case 'TetrahedronGeometry':
  24778. case 'TetrahedronBufferGeometry':
  24779. geometry = new Geometries[ data.type ](
  24780. data.radius,
  24781. data.detail
  24782. );
  24783. break;
  24784. case 'RingGeometry':
  24785. case 'RingBufferGeometry':
  24786. geometry = new Geometries[ data.type ](
  24787. data.innerRadius,
  24788. data.outerRadius,
  24789. data.thetaSegments,
  24790. data.phiSegments,
  24791. data.thetaStart,
  24792. data.thetaLength
  24793. );
  24794. break;
  24795. case 'TorusGeometry':
  24796. case 'TorusBufferGeometry':
  24797. geometry = new Geometries[ data.type ](
  24798. data.radius,
  24799. data.tube,
  24800. data.radialSegments,
  24801. data.tubularSegments,
  24802. data.arc
  24803. );
  24804. break;
  24805. case 'TorusKnotGeometry':
  24806. case 'TorusKnotBufferGeometry':
  24807. geometry = new Geometries[ data.type ](
  24808. data.radius,
  24809. data.tube,
  24810. data.tubularSegments,
  24811. data.radialSegments,
  24812. data.p,
  24813. data.q
  24814. );
  24815. break;
  24816. case 'TubeGeometry':
  24817. case 'TubeBufferGeometry':
  24818. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24819. // User defined curves or instances of CurvePath will not be deserialized.
  24820. geometry = new Geometries[ data.type ](
  24821. new Curves[ data.path.type ]().fromJSON( data.path ),
  24822. data.tubularSegments,
  24823. data.radius,
  24824. data.radialSegments,
  24825. data.closed
  24826. );
  24827. break;
  24828. case 'LatheGeometry':
  24829. case 'LatheBufferGeometry':
  24830. geometry = new Geometries[ data.type ](
  24831. data.points,
  24832. data.segments,
  24833. data.phiStart,
  24834. data.phiLength
  24835. );
  24836. break;
  24837. case 'PolyhedronGeometry':
  24838. case 'PolyhedronBufferGeometry':
  24839. geometry = new Geometries[ data.type ](
  24840. data.vertices,
  24841. data.indices,
  24842. data.radius,
  24843. data.details
  24844. );
  24845. break;
  24846. case 'ShapeGeometry':
  24847. case 'ShapeBufferGeometry':
  24848. geometryShapes = [];
  24849. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24850. const shape = shapes[ data.shapes[ j ] ];
  24851. geometryShapes.push( shape );
  24852. }
  24853. geometry = new Geometries[ data.type ](
  24854. geometryShapes,
  24855. data.curveSegments
  24856. );
  24857. break;
  24858. case 'ExtrudeGeometry':
  24859. case 'ExtrudeBufferGeometry':
  24860. geometryShapes = [];
  24861. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24862. const shape = shapes[ data.shapes[ j ] ];
  24863. geometryShapes.push( shape );
  24864. }
  24865. const extrudePath = data.options.extrudePath;
  24866. if ( extrudePath !== undefined ) {
  24867. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  24868. }
  24869. geometry = new Geometries[ data.type ](
  24870. geometryShapes,
  24871. data.options
  24872. );
  24873. break;
  24874. case 'BufferGeometry':
  24875. case 'InstancedBufferGeometry':
  24876. geometry = bufferGeometryLoader.parse( data );
  24877. break;
  24878. case 'Geometry':
  24879. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  24880. break;
  24881. default:
  24882. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  24883. continue;
  24884. }
  24885. geometry.uuid = data.uuid;
  24886. if ( data.name !== undefined ) geometry.name = data.name;
  24887. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  24888. geometries[ data.uuid ] = geometry;
  24889. }
  24890. }
  24891. return geometries;
  24892. },
  24893. parseMaterials: function ( json, textures ) {
  24894. const cache = {}; // MultiMaterial
  24895. const materials = {};
  24896. if ( json !== undefined ) {
  24897. const loader = new MaterialLoader();
  24898. loader.setTextures( textures );
  24899. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24900. const data = json[ i ];
  24901. if ( data.type === 'MultiMaterial' ) {
  24902. // Deprecated
  24903. const array = [];
  24904. for ( let j = 0; j < data.materials.length; j ++ ) {
  24905. const material = data.materials[ j ];
  24906. if ( cache[ material.uuid ] === undefined ) {
  24907. cache[ material.uuid ] = loader.parse( material );
  24908. }
  24909. array.push( cache[ material.uuid ] );
  24910. }
  24911. materials[ data.uuid ] = array;
  24912. } else {
  24913. if ( cache[ data.uuid ] === undefined ) {
  24914. cache[ data.uuid ] = loader.parse( data );
  24915. }
  24916. materials[ data.uuid ] = cache[ data.uuid ];
  24917. }
  24918. }
  24919. }
  24920. return materials;
  24921. },
  24922. parseAnimations: function ( json ) {
  24923. const animations = [];
  24924. for ( let i = 0; i < json.length; i ++ ) {
  24925. const data = json[ i ];
  24926. const clip = AnimationClip.parse( data );
  24927. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  24928. animations.push( clip );
  24929. }
  24930. return animations;
  24931. },
  24932. parseImages: function ( json, onLoad ) {
  24933. const scope = this;
  24934. const images = {};
  24935. let loader;
  24936. function loadImage( url ) {
  24937. scope.manager.itemStart( url );
  24938. return loader.load( url, function () {
  24939. scope.manager.itemEnd( url );
  24940. }, undefined, function () {
  24941. scope.manager.itemError( url );
  24942. scope.manager.itemEnd( url );
  24943. } );
  24944. }
  24945. if ( json !== undefined && json.length > 0 ) {
  24946. const manager = new LoadingManager( onLoad );
  24947. loader = new ImageLoader( manager );
  24948. loader.setCrossOrigin( this.crossOrigin );
  24949. for ( let i = 0, il = json.length; i < il; i ++ ) {
  24950. const image = json[ i ];
  24951. const url = image.url;
  24952. if ( Array.isArray( url ) ) {
  24953. // load array of images e.g CubeTexture
  24954. images[ image.uuid ] = [];
  24955. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  24956. const currentUrl = url[ j ];
  24957. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  24958. images[ image.uuid ].push( loadImage( path ) );
  24959. }
  24960. } else {
  24961. // load single image
  24962. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  24963. images[ image.uuid ] = loadImage( path );
  24964. }
  24965. }
  24966. }
  24967. return images;
  24968. },
  24969. parseTextures: function ( json, images ) {
  24970. function parseConstant( value, type ) {
  24971. if ( typeof value === 'number' ) return value;
  24972. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24973. return type[ value ];
  24974. }
  24975. const textures = {};
  24976. if ( json !== undefined ) {
  24977. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24978. const data = json[ i ];
  24979. if ( data.image === undefined ) {
  24980. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24981. }
  24982. if ( images[ data.image ] === undefined ) {
  24983. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24984. }
  24985. let texture;
  24986. if ( Array.isArray( images[ data.image ] ) ) {
  24987. texture = new CubeTexture( images[ data.image ] );
  24988. } else {
  24989. texture = new Texture( images[ data.image ] );
  24990. }
  24991. texture.needsUpdate = true;
  24992. texture.uuid = data.uuid;
  24993. if ( data.name !== undefined ) texture.name = data.name;
  24994. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24995. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24996. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24997. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24998. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24999. if ( data.wrap !== undefined ) {
  25000. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  25001. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  25002. }
  25003. if ( data.format !== undefined ) texture.format = data.format;
  25004. if ( data.type !== undefined ) texture.type = data.type;
  25005. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  25006. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  25007. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  25008. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  25009. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  25010. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  25011. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  25012. textures[ data.uuid ] = texture;
  25013. }
  25014. }
  25015. return textures;
  25016. },
  25017. parseObject: function ( data, geometries, materials ) {
  25018. let object;
  25019. function getGeometry( name ) {
  25020. if ( geometries[ name ] === undefined ) {
  25021. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  25022. }
  25023. return geometries[ name ];
  25024. }
  25025. function getMaterial( name ) {
  25026. if ( name === undefined ) return undefined;
  25027. if ( Array.isArray( name ) ) {
  25028. const array = [];
  25029. for ( let i = 0, l = name.length; i < l; i ++ ) {
  25030. const uuid = name[ i ];
  25031. if ( materials[ uuid ] === undefined ) {
  25032. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  25033. }
  25034. array.push( materials[ uuid ] );
  25035. }
  25036. return array;
  25037. }
  25038. if ( materials[ name ] === undefined ) {
  25039. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  25040. }
  25041. return materials[ name ];
  25042. }
  25043. let geometry, material;
  25044. switch ( data.type ) {
  25045. case 'Scene':
  25046. object = new Scene();
  25047. if ( data.background !== undefined ) {
  25048. if ( Number.isInteger( data.background ) ) {
  25049. object.background = new Color( data.background );
  25050. }
  25051. }
  25052. if ( data.fog !== undefined ) {
  25053. if ( data.fog.type === 'Fog' ) {
  25054. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  25055. } else if ( data.fog.type === 'FogExp2' ) {
  25056. object.fog = new FogExp2( data.fog.color, data.fog.density );
  25057. }
  25058. }
  25059. break;
  25060. case 'PerspectiveCamera':
  25061. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  25062. if ( data.focus !== undefined ) object.focus = data.focus;
  25063. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  25064. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  25065. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  25066. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  25067. break;
  25068. case 'OrthographicCamera':
  25069. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  25070. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  25071. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  25072. break;
  25073. case 'AmbientLight':
  25074. object = new AmbientLight( data.color, data.intensity );
  25075. break;
  25076. case 'DirectionalLight':
  25077. object = new DirectionalLight( data.color, data.intensity );
  25078. break;
  25079. case 'PointLight':
  25080. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  25081. break;
  25082. case 'RectAreaLight':
  25083. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  25084. break;
  25085. case 'SpotLight':
  25086. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  25087. break;
  25088. case 'HemisphereLight':
  25089. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  25090. break;
  25091. case 'LightProbe':
  25092. object = new LightProbe().fromJSON( data );
  25093. break;
  25094. case 'SkinnedMesh':
  25095. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  25096. case 'Mesh':
  25097. geometry = getGeometry( data.geometry );
  25098. material = getMaterial( data.material );
  25099. object = new Mesh( geometry, material );
  25100. break;
  25101. case 'InstancedMesh':
  25102. geometry = getGeometry( data.geometry );
  25103. material = getMaterial( data.material );
  25104. const count = data.count;
  25105. const instanceMatrix = data.instanceMatrix;
  25106. object = new InstancedMesh( geometry, material, count );
  25107. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  25108. break;
  25109. case 'LOD':
  25110. object = new LOD();
  25111. break;
  25112. case 'Line':
  25113. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  25114. break;
  25115. case 'LineLoop':
  25116. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  25117. break;
  25118. case 'LineSegments':
  25119. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  25120. break;
  25121. case 'PointCloud':
  25122. case 'Points':
  25123. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  25124. break;
  25125. case 'Sprite':
  25126. object = new Sprite( getMaterial( data.material ) );
  25127. break;
  25128. case 'Group':
  25129. object = new Group();
  25130. break;
  25131. default:
  25132. object = new Object3D();
  25133. }
  25134. object.uuid = data.uuid;
  25135. if ( data.name !== undefined ) object.name = data.name;
  25136. if ( data.matrix !== undefined ) {
  25137. object.matrix.fromArray( data.matrix );
  25138. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  25139. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  25140. } else {
  25141. if ( data.position !== undefined ) object.position.fromArray( data.position );
  25142. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  25143. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  25144. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  25145. }
  25146. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  25147. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  25148. if ( data.shadow ) {
  25149. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  25150. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  25151. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  25152. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  25153. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  25154. }
  25155. if ( data.visible !== undefined ) object.visible = data.visible;
  25156. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  25157. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  25158. if ( data.userData !== undefined ) object.userData = data.userData;
  25159. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  25160. if ( data.children !== undefined ) {
  25161. const children = data.children;
  25162. for ( let i = 0; i < children.length; i ++ ) {
  25163. object.add( this.parseObject( children[ i ], geometries, materials ) );
  25164. }
  25165. }
  25166. if ( data.type === 'LOD' ) {
  25167. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  25168. const levels = data.levels;
  25169. for ( let l = 0; l < levels.length; l ++ ) {
  25170. const level = levels[ l ];
  25171. const child = object.getObjectByProperty( 'uuid', level.object );
  25172. if ( child !== undefined ) {
  25173. object.addLevel( child, level.distance );
  25174. }
  25175. }
  25176. }
  25177. return object;
  25178. }
  25179. } );
  25180. const TEXTURE_MAPPING = {
  25181. UVMapping: UVMapping,
  25182. CubeReflectionMapping: CubeReflectionMapping,
  25183. CubeRefractionMapping: CubeRefractionMapping,
  25184. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25185. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25186. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25187. CubeUVRefractionMapping: CubeUVRefractionMapping
  25188. };
  25189. const TEXTURE_WRAPPING = {
  25190. RepeatWrapping: RepeatWrapping,
  25191. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25192. MirroredRepeatWrapping: MirroredRepeatWrapping
  25193. };
  25194. const TEXTURE_FILTER = {
  25195. NearestFilter: NearestFilter,
  25196. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25197. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25198. LinearFilter: LinearFilter,
  25199. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25200. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25201. };
  25202. /**
  25203. * @author thespite / http://clicktorelease.com/
  25204. */
  25205. function ImageBitmapLoader( manager ) {
  25206. if ( typeof createImageBitmap === 'undefined' ) {
  25207. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  25208. }
  25209. if ( typeof fetch === 'undefined' ) {
  25210. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  25211. }
  25212. Loader.call( this, manager );
  25213. this.options = { premultiplyAlpha: 'none' };
  25214. }
  25215. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25216. constructor: ImageBitmapLoader,
  25217. isImageBitmapLoader: true,
  25218. setOptions: function setOptions( options ) {
  25219. this.options = options;
  25220. return this;
  25221. },
  25222. load: function ( url, onLoad, onProgress, onError ) {
  25223. if ( url === undefined ) url = '';
  25224. if ( this.path !== undefined ) url = this.path + url;
  25225. url = this.manager.resolveURL( url );
  25226. const scope = this;
  25227. const cached = Cache.get( url );
  25228. if ( cached !== undefined ) {
  25229. scope.manager.itemStart( url );
  25230. setTimeout( function () {
  25231. if ( onLoad ) onLoad( cached );
  25232. scope.manager.itemEnd( url );
  25233. }, 0 );
  25234. return cached;
  25235. }
  25236. fetch( url ).then( function ( res ) {
  25237. return res.blob();
  25238. } ).then( function ( blob ) {
  25239. return createImageBitmap( blob, scope.options );
  25240. } ).then( function ( imageBitmap ) {
  25241. Cache.add( url, imageBitmap );
  25242. if ( onLoad ) onLoad( imageBitmap );
  25243. scope.manager.itemEnd( url );
  25244. } ).catch( function ( e ) {
  25245. if ( onError ) onError( e );
  25246. scope.manager.itemError( url );
  25247. scope.manager.itemEnd( url );
  25248. } );
  25249. scope.manager.itemStart( url );
  25250. }
  25251. } );
  25252. /**
  25253. * @author zz85 / http://www.lab4games.net/zz85/blog
  25254. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  25255. **/
  25256. function ShapePath() {
  25257. this.type = 'ShapePath';
  25258. this.color = new Color();
  25259. this.subPaths = [];
  25260. this.currentPath = null;
  25261. }
  25262. Object.assign( ShapePath.prototype, {
  25263. moveTo: function ( x, y ) {
  25264. this.currentPath = new Path();
  25265. this.subPaths.push( this.currentPath );
  25266. this.currentPath.moveTo( x, y );
  25267. return this;
  25268. },
  25269. lineTo: function ( x, y ) {
  25270. this.currentPath.lineTo( x, y );
  25271. return this;
  25272. },
  25273. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  25274. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  25275. return this;
  25276. },
  25277. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  25278. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  25279. return this;
  25280. },
  25281. splineThru: function ( pts ) {
  25282. this.currentPath.splineThru( pts );
  25283. return this;
  25284. },
  25285. toShapes: function ( isCCW, noHoles ) {
  25286. function toShapesNoHoles( inSubpaths ) {
  25287. const shapes = [];
  25288. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  25289. const tmpPath = inSubpaths[ i ];
  25290. const tmpShape = new Shape();
  25291. tmpShape.curves = tmpPath.curves;
  25292. shapes.push( tmpShape );
  25293. }
  25294. return shapes;
  25295. }
  25296. function isPointInsidePolygon( inPt, inPolygon ) {
  25297. const polyLen = inPolygon.length;
  25298. // inPt on polygon contour => immediate success or
  25299. // toggling of inside/outside at every single! intersection point of an edge
  25300. // with the horizontal line through inPt, left of inPt
  25301. // not counting lowerY endpoints of edges and whole edges on that line
  25302. let inside = false;
  25303. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  25304. let edgeLowPt = inPolygon[ p ];
  25305. let edgeHighPt = inPolygon[ q ];
  25306. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  25307. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  25308. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  25309. // not parallel
  25310. if ( edgeDy < 0 ) {
  25311. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  25312. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  25313. }
  25314. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  25315. if ( inPt.y === edgeLowPt.y ) {
  25316. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  25317. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25318. } else {
  25319. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  25320. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  25321. if ( perpEdge < 0 ) continue;
  25322. inside = ! inside; // true intersection left of inPt
  25323. }
  25324. } else {
  25325. // parallel or collinear
  25326. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  25327. // edge lies on the same horizontal line as inPt
  25328. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  25329. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  25330. // continue;
  25331. }
  25332. }
  25333. return inside;
  25334. }
  25335. const isClockWise = ShapeUtils.isClockWise;
  25336. const subPaths = this.subPaths;
  25337. if ( subPaths.length === 0 ) return [];
  25338. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  25339. let solid, tmpPath, tmpShape, shapes = [];
  25340. if ( subPaths.length === 1 ) {
  25341. tmpPath = subPaths[ 0 ];
  25342. tmpShape = new Shape();
  25343. tmpShape.curves = tmpPath.curves;
  25344. shapes.push( tmpShape );
  25345. return shapes;
  25346. }
  25347. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  25348. holesFirst = isCCW ? ! holesFirst : holesFirst;
  25349. // console.log("Holes first", holesFirst);
  25350. const betterShapeHoles = [];
  25351. const newShapes = [];
  25352. let newShapeHoles = [];
  25353. let mainIdx = 0;
  25354. let tmpPoints;
  25355. newShapes[ mainIdx ] = undefined;
  25356. newShapeHoles[ mainIdx ] = [];
  25357. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  25358. tmpPath = subPaths[ i ];
  25359. tmpPoints = tmpPath.getPoints();
  25360. solid = isClockWise( tmpPoints );
  25361. solid = isCCW ? ! solid : solid;
  25362. if ( solid ) {
  25363. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  25364. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  25365. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  25366. if ( holesFirst ) mainIdx ++;
  25367. newShapeHoles[ mainIdx ] = [];
  25368. //console.log('cw', i);
  25369. } else {
  25370. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  25371. //console.log('ccw', i);
  25372. }
  25373. }
  25374. // only Holes? -> probably all Shapes with wrong orientation
  25375. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  25376. if ( newShapes.length > 1 ) {
  25377. let ambiguous = false;
  25378. const toChange = [];
  25379. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25380. betterShapeHoles[ sIdx ] = [];
  25381. }
  25382. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25383. const sho = newShapeHoles[ sIdx ];
  25384. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  25385. const ho = sho[ hIdx ];
  25386. let hole_unassigned = true;
  25387. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  25388. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  25389. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  25390. if ( hole_unassigned ) {
  25391. hole_unassigned = false;
  25392. betterShapeHoles[ s2Idx ].push( ho );
  25393. } else {
  25394. ambiguous = true;
  25395. }
  25396. }
  25397. }
  25398. if ( hole_unassigned ) {
  25399. betterShapeHoles[ sIdx ].push( ho );
  25400. }
  25401. }
  25402. }
  25403. // console.log("ambiguous: ", ambiguous);
  25404. if ( toChange.length > 0 ) {
  25405. // console.log("to change: ", toChange);
  25406. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  25407. }
  25408. }
  25409. let tmpHoles;
  25410. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  25411. tmpShape = newShapes[ i ].s;
  25412. shapes.push( tmpShape );
  25413. tmpHoles = newShapeHoles[ i ];
  25414. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  25415. tmpShape.holes.push( tmpHoles[ j ].h );
  25416. }
  25417. }
  25418. //console.log("shape", shapes);
  25419. return shapes;
  25420. }
  25421. } );
  25422. /**
  25423. * @author zz85 / http://www.lab4games.net/zz85/blog
  25424. * @author mrdoob / http://mrdoob.com/
  25425. */
  25426. function Font( data ) {
  25427. this.type = 'Font';
  25428. this.data = data;
  25429. }
  25430. Object.assign( Font.prototype, {
  25431. isFont: true,
  25432. generateShapes: function ( text, size ) {
  25433. if ( size === undefined ) size = 100;
  25434. const shapes = [];
  25435. const paths = createPaths( text, size, this.data );
  25436. for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
  25437. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  25438. }
  25439. return shapes;
  25440. }
  25441. } );
  25442. function createPaths( text, size, data ) {
  25443. const chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988
  25444. const scale = size / data.resolution;
  25445. const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  25446. const paths = [];
  25447. let offsetX = 0, offsetY = 0;
  25448. for ( let i = 0; i < chars.length; i ++ ) {
  25449. const char = chars[ i ];
  25450. if ( char === '\n' ) {
  25451. offsetX = 0;
  25452. offsetY -= line_height;
  25453. } else {
  25454. const ret = createPath( char, scale, offsetX, offsetY, data );
  25455. offsetX += ret.offsetX;
  25456. paths.push( ret.path );
  25457. }
  25458. }
  25459. return paths;
  25460. }
  25461. function createPath( char, scale, offsetX, offsetY, data ) {
  25462. const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  25463. if ( ! glyph ) {
  25464. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  25465. return;
  25466. }
  25467. const path = new ShapePath();
  25468. let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25469. if ( glyph.o ) {
  25470. const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  25471. for ( let i = 0, l = outline.length; i < l; ) {
  25472. const action = outline[ i ++ ];
  25473. switch ( action ) {
  25474. case 'm': // moveTo
  25475. x = outline[ i ++ ] * scale + offsetX;
  25476. y = outline[ i ++ ] * scale + offsetY;
  25477. path.moveTo( x, y );
  25478. break;
  25479. case 'l': // lineTo
  25480. x = outline[ i ++ ] * scale + offsetX;
  25481. y = outline[ i ++ ] * scale + offsetY;
  25482. path.lineTo( x, y );
  25483. break;
  25484. case 'q': // quadraticCurveTo
  25485. cpx = outline[ i ++ ] * scale + offsetX;
  25486. cpy = outline[ i ++ ] * scale + offsetY;
  25487. cpx1 = outline[ i ++ ] * scale + offsetX;
  25488. cpy1 = outline[ i ++ ] * scale + offsetY;
  25489. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  25490. break;
  25491. case 'b': // bezierCurveTo
  25492. cpx = outline[ i ++ ] * scale + offsetX;
  25493. cpy = outline[ i ++ ] * scale + offsetY;
  25494. cpx1 = outline[ i ++ ] * scale + offsetX;
  25495. cpy1 = outline[ i ++ ] * scale + offsetY;
  25496. cpx2 = outline[ i ++ ] * scale + offsetX;
  25497. cpy2 = outline[ i ++ ] * scale + offsetY;
  25498. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  25499. break;
  25500. }
  25501. }
  25502. }
  25503. return { offsetX: glyph.ha * scale, path: path };
  25504. }
  25505. /**
  25506. * @author mrdoob / http://mrdoob.com/
  25507. */
  25508. function FontLoader( manager ) {
  25509. Loader.call( this, manager );
  25510. }
  25511. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25512. constructor: FontLoader,
  25513. load: function ( url, onLoad, onProgress, onError ) {
  25514. const scope = this;
  25515. const loader = new FileLoader( this.manager );
  25516. loader.setPath( this.path );
  25517. loader.load( url, function ( text ) {
  25518. let json;
  25519. try {
  25520. json = JSON.parse( text );
  25521. } catch ( e ) {
  25522. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  25523. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  25524. }
  25525. const font = scope.parse( json );
  25526. if ( onLoad ) onLoad( font );
  25527. }, onProgress, onError );
  25528. },
  25529. parse: function ( json ) {
  25530. return new Font( json );
  25531. }
  25532. } );
  25533. /**
  25534. * @author mrdoob / http://mrdoob.com/
  25535. */
  25536. let _context;
  25537. const AudioContext = {
  25538. getContext: function () {
  25539. if ( _context === undefined ) {
  25540. _context = new ( window.AudioContext || window.webkitAudioContext )();
  25541. }
  25542. return _context;
  25543. },
  25544. setContext: function ( value ) {
  25545. _context = value;
  25546. }
  25547. };
  25548. /**
  25549. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25550. */
  25551. function AudioLoader( manager ) {
  25552. Loader.call( this, manager );
  25553. }
  25554. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25555. constructor: AudioLoader,
  25556. load: function ( url, onLoad, onProgress, onError ) {
  25557. const scope = this;
  25558. const loader = new FileLoader( scope.manager );
  25559. loader.setResponseType( 'arraybuffer' );
  25560. loader.setPath( scope.path );
  25561. loader.load( url, function ( buffer ) {
  25562. try {
  25563. // Create a copy of the buffer. The `decodeAudioData` method
  25564. // detaches the buffer when complete, preventing reuse.
  25565. const bufferCopy = buffer.slice( 0 );
  25566. const context = AudioContext.getContext();
  25567. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25568. onLoad( audioBuffer );
  25569. } );
  25570. } catch ( e ) {
  25571. if ( onError ) {
  25572. onError( e );
  25573. } else {
  25574. console.error( e );
  25575. }
  25576. scope.manager.itemError( url );
  25577. }
  25578. }, onProgress, onError );
  25579. }
  25580. } );
  25581. /**
  25582. * @author WestLangley / http://github.com/WestLangley
  25583. */
  25584. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  25585. LightProbe.call( this, undefined, intensity );
  25586. const color1 = new Color().set( skyColor );
  25587. const color2 = new Color().set( groundColor );
  25588. const sky = new Vector3( color1.r, color1.g, color1.b );
  25589. const ground = new Vector3( color2.r, color2.g, color2.b );
  25590. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25591. const c0 = Math.sqrt( Math.PI );
  25592. const c1 = c0 * Math.sqrt( 0.75 );
  25593. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25594. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25595. }
  25596. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25597. constructor: HemisphereLightProbe,
  25598. isHemisphereLightProbe: true,
  25599. copy: function ( source ) { // modifying colors not currently supported
  25600. LightProbe.prototype.copy.call( this, source );
  25601. return this;
  25602. },
  25603. toJSON: function ( meta ) {
  25604. const data = LightProbe.prototype.toJSON.call( this, meta );
  25605. // data.sh = this.sh.toArray(); // todo
  25606. return data;
  25607. }
  25608. } );
  25609. /**
  25610. * @author WestLangley / http://github.com/WestLangley
  25611. */
  25612. function AmbientLightProbe( color, intensity ) {
  25613. LightProbe.call( this, undefined, intensity );
  25614. const color1 = new Color().set( color );
  25615. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25616. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25617. }
  25618. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25619. constructor: AmbientLightProbe,
  25620. isAmbientLightProbe: true,
  25621. copy: function ( source ) { // modifying color not currently supported
  25622. LightProbe.prototype.copy.call( this, source );
  25623. return this;
  25624. },
  25625. toJSON: function ( meta ) {
  25626. const data = LightProbe.prototype.toJSON.call( this, meta );
  25627. // data.sh = this.sh.toArray(); // todo
  25628. return data;
  25629. }
  25630. } );
  25631. const _eyeRight = new Matrix4();
  25632. const _eyeLeft = new Matrix4();
  25633. /**
  25634. * @author mrdoob / http://mrdoob.com/
  25635. */
  25636. function StereoCamera() {
  25637. this.type = 'StereoCamera';
  25638. this.aspect = 1;
  25639. this.eyeSep = 0.064;
  25640. this.cameraL = new PerspectiveCamera();
  25641. this.cameraL.layers.enable( 1 );
  25642. this.cameraL.matrixAutoUpdate = false;
  25643. this.cameraR = new PerspectiveCamera();
  25644. this.cameraR.layers.enable( 2 );
  25645. this.cameraR.matrixAutoUpdate = false;
  25646. this._cache = {
  25647. focus: null,
  25648. fov: null,
  25649. aspect: null,
  25650. near: null,
  25651. far: null,
  25652. zoom: null,
  25653. eyeSep: null
  25654. };
  25655. }
  25656. Object.assign( StereoCamera.prototype, {
  25657. update: function ( camera ) {
  25658. const cache = this._cache;
  25659. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  25660. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  25661. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25662. if ( needsUpdate ) {
  25663. cache.focus = camera.focus;
  25664. cache.fov = camera.fov;
  25665. cache.aspect = camera.aspect * this.aspect;
  25666. cache.near = camera.near;
  25667. cache.far = camera.far;
  25668. cache.zoom = camera.zoom;
  25669. cache.eyeSep = this.eyeSep;
  25670. // Off-axis stereoscopic effect based on
  25671. // http://paulbourke.net/stereographics/stereorender/
  25672. const projectionMatrix = camera.projectionMatrix.clone();
  25673. const eyeSepHalf = cache.eyeSep / 2;
  25674. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25675. const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  25676. let xmin, xmax;
  25677. // translate xOffset
  25678. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  25679. _eyeRight.elements[ 12 ] = eyeSepHalf;
  25680. // for left eye
  25681. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  25682. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25683. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25684. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25685. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25686. // for right eye
  25687. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  25688. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25689. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25690. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25691. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25692. }
  25693. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  25694. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  25695. }
  25696. } );
  25697. /**
  25698. * @author alteredq / http://alteredqualia.com/
  25699. */
  25700. function Clock( autoStart ) {
  25701. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25702. this.startTime = 0;
  25703. this.oldTime = 0;
  25704. this.elapsedTime = 0;
  25705. this.running = false;
  25706. }
  25707. Object.assign( Clock.prototype, {
  25708. start: function () {
  25709. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25710. this.oldTime = this.startTime;
  25711. this.elapsedTime = 0;
  25712. this.running = true;
  25713. },
  25714. stop: function () {
  25715. this.getElapsedTime();
  25716. this.running = false;
  25717. this.autoStart = false;
  25718. },
  25719. getElapsedTime: function () {
  25720. this.getDelta();
  25721. return this.elapsedTime;
  25722. },
  25723. getDelta: function () {
  25724. let diff = 0;
  25725. if ( this.autoStart && ! this.running ) {
  25726. this.start();
  25727. return 0;
  25728. }
  25729. if ( this.running ) {
  25730. const newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  25731. diff = ( newTime - this.oldTime ) / 1000;
  25732. this.oldTime = newTime;
  25733. this.elapsedTime += diff;
  25734. }
  25735. return diff;
  25736. }
  25737. } );
  25738. /**
  25739. * @author mrdoob / http://mrdoob.com/
  25740. */
  25741. const _position$2 = new Vector3();
  25742. const _quaternion$3 = new Quaternion();
  25743. const _scale$1 = new Vector3();
  25744. const _orientation = new Vector3();
  25745. function AudioListener() {
  25746. Object3D.call( this );
  25747. this.type = 'AudioListener';
  25748. this.context = AudioContext.getContext();
  25749. this.gain = this.context.createGain();
  25750. this.gain.connect( this.context.destination );
  25751. this.filter = null;
  25752. this.timeDelta = 0;
  25753. // private
  25754. this._clock = new Clock();
  25755. }
  25756. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25757. constructor: AudioListener,
  25758. getInput: function () {
  25759. return this.gain;
  25760. },
  25761. removeFilter: function ( ) {
  25762. if ( this.filter !== null ) {
  25763. this.gain.disconnect( this.filter );
  25764. this.filter.disconnect( this.context.destination );
  25765. this.gain.connect( this.context.destination );
  25766. this.filter = null;
  25767. }
  25768. return this;
  25769. },
  25770. getFilter: function () {
  25771. return this.filter;
  25772. },
  25773. setFilter: function ( value ) {
  25774. if ( this.filter !== null ) {
  25775. this.gain.disconnect( this.filter );
  25776. this.filter.disconnect( this.context.destination );
  25777. } else {
  25778. this.gain.disconnect( this.context.destination );
  25779. }
  25780. this.filter = value;
  25781. this.gain.connect( this.filter );
  25782. this.filter.connect( this.context.destination );
  25783. return this;
  25784. },
  25785. getMasterVolume: function () {
  25786. return this.gain.gain.value;
  25787. },
  25788. setMasterVolume: function ( value ) {
  25789. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25790. return this;
  25791. },
  25792. updateMatrixWorld: function ( force ) {
  25793. Object3D.prototype.updateMatrixWorld.call( this, force );
  25794. const listener = this.context.listener;
  25795. const up = this.up;
  25796. this.timeDelta = this._clock.getDelta();
  25797. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  25798. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  25799. if ( listener.positionX ) {
  25800. // code path for Chrome (see #14393)
  25801. const endTime = this.context.currentTime + this.timeDelta;
  25802. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  25803. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  25804. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  25805. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  25806. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  25807. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  25808. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25809. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25810. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25811. } else {
  25812. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  25813. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  25814. }
  25815. }
  25816. } );
  25817. /**
  25818. * @author mrdoob / http://mrdoob.com/
  25819. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  25820. */
  25821. function Audio( listener ) {
  25822. Object3D.call( this );
  25823. this.type = 'Audio';
  25824. this.listener = listener;
  25825. this.context = listener.context;
  25826. this.gain = this.context.createGain();
  25827. this.gain.connect( listener.getInput() );
  25828. this.autoplay = false;
  25829. this.buffer = null;
  25830. this.detune = 0;
  25831. this.loop = false;
  25832. this.loopStart = 0;
  25833. this.loopEnd = 0;
  25834. this.offset = 0;
  25835. this.duration = undefined;
  25836. this.playbackRate = 1;
  25837. this.isPlaying = false;
  25838. this.hasPlaybackControl = true;
  25839. this.sourceType = 'empty';
  25840. this._startedAt = 0;
  25841. this._progress = 0;
  25842. this.filters = [];
  25843. }
  25844. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  25845. constructor: Audio,
  25846. getOutput: function () {
  25847. return this.gain;
  25848. },
  25849. setNodeSource: function ( audioNode ) {
  25850. this.hasPlaybackControl = false;
  25851. this.sourceType = 'audioNode';
  25852. this.source = audioNode;
  25853. this.connect();
  25854. return this;
  25855. },
  25856. setMediaElementSource: function ( mediaElement ) {
  25857. this.hasPlaybackControl = false;
  25858. this.sourceType = 'mediaNode';
  25859. this.source = this.context.createMediaElementSource( mediaElement );
  25860. this.connect();
  25861. return this;
  25862. },
  25863. setMediaStreamSource: function ( mediaStream ) {
  25864. this.hasPlaybackControl = false;
  25865. this.sourceType = 'mediaStreamNode';
  25866. this.source = this.context.createMediaStreamSource( mediaStream );
  25867. this.connect();
  25868. return this;
  25869. },
  25870. setBuffer: function ( audioBuffer ) {
  25871. this.buffer = audioBuffer;
  25872. this.sourceType = 'buffer';
  25873. if ( this.autoplay ) this.play();
  25874. return this;
  25875. },
  25876. play: function ( delay ) {
  25877. if ( delay === undefined ) delay = 0;
  25878. if ( this.isPlaying === true ) {
  25879. console.warn( 'THREE.Audio: Audio is already playing.' );
  25880. return;
  25881. }
  25882. if ( this.hasPlaybackControl === false ) {
  25883. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25884. return;
  25885. }
  25886. this._startedAt = this.context.currentTime + delay;
  25887. const source = this.context.createBufferSource();
  25888. source.buffer = this.buffer;
  25889. source.loop = this.loop;
  25890. source.loopStart = this.loopStart;
  25891. source.loopEnd = this.loopEnd;
  25892. source.onended = this.onEnded.bind( this );
  25893. source.start( this._startedAt, this._progress + this.offset, this.duration );
  25894. this.isPlaying = true;
  25895. this.source = source;
  25896. this.setDetune( this.detune );
  25897. this.setPlaybackRate( this.playbackRate );
  25898. return this.connect();
  25899. },
  25900. pause: function () {
  25901. if ( this.hasPlaybackControl === false ) {
  25902. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25903. return;
  25904. }
  25905. if ( this.isPlaying === true ) {
  25906. // update current progress
  25907. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  25908. if ( this.loop === true ) {
  25909. // ensure _progress does not exceed duration with looped audios
  25910. this._progress = this._progress % ( this.duration || this.buffer.duration );
  25911. }
  25912. this.source.stop();
  25913. this.source.onended = null;
  25914. this.isPlaying = false;
  25915. }
  25916. return this;
  25917. },
  25918. stop: function () {
  25919. if ( this.hasPlaybackControl === false ) {
  25920. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25921. return;
  25922. }
  25923. this._progress = 0;
  25924. this.source.stop();
  25925. this.source.onended = null;
  25926. this.isPlaying = false;
  25927. return this;
  25928. },
  25929. connect: function () {
  25930. if ( this.filters.length > 0 ) {
  25931. this.source.connect( this.filters[ 0 ] );
  25932. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25933. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25934. }
  25935. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25936. } else {
  25937. this.source.connect( this.getOutput() );
  25938. }
  25939. return this;
  25940. },
  25941. disconnect: function () {
  25942. if ( this.filters.length > 0 ) {
  25943. this.source.disconnect( this.filters[ 0 ] );
  25944. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25945. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25946. }
  25947. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25948. } else {
  25949. this.source.disconnect( this.getOutput() );
  25950. }
  25951. return this;
  25952. },
  25953. getFilters: function () {
  25954. return this.filters;
  25955. },
  25956. setFilters: function ( value ) {
  25957. if ( ! value ) value = [];
  25958. if ( this.isPlaying === true ) {
  25959. this.disconnect();
  25960. this.filters = value;
  25961. this.connect();
  25962. } else {
  25963. this.filters = value;
  25964. }
  25965. return this;
  25966. },
  25967. setDetune: function ( value ) {
  25968. this.detune = value;
  25969. if ( this.source.detune === undefined ) return; // only set detune when available
  25970. if ( this.isPlaying === true ) {
  25971. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25972. }
  25973. return this;
  25974. },
  25975. getDetune: function () {
  25976. return this.detune;
  25977. },
  25978. getFilter: function () {
  25979. return this.getFilters()[ 0 ];
  25980. },
  25981. setFilter: function ( filter ) {
  25982. return this.setFilters( filter ? [ filter ] : [] );
  25983. },
  25984. setPlaybackRate: function ( value ) {
  25985. if ( this.hasPlaybackControl === false ) {
  25986. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25987. return;
  25988. }
  25989. this.playbackRate = value;
  25990. if ( this.isPlaying === true ) {
  25991. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25992. }
  25993. return this;
  25994. },
  25995. getPlaybackRate: function () {
  25996. return this.playbackRate;
  25997. },
  25998. onEnded: function () {
  25999. this.isPlaying = false;
  26000. },
  26001. getLoop: function () {
  26002. if ( this.hasPlaybackControl === false ) {
  26003. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  26004. return false;
  26005. }
  26006. return this.loop;
  26007. },
  26008. setLoop: function ( value ) {
  26009. if ( this.hasPlaybackControl === false ) {
  26010. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  26011. return;
  26012. }
  26013. this.loop = value;
  26014. if ( this.isPlaying === true ) {
  26015. this.source.loop = this.loop;
  26016. }
  26017. return this;
  26018. },
  26019. setLoopStart: function ( value ) {
  26020. this.loopStart = value;
  26021. return this;
  26022. },
  26023. setLoopEnd: function ( value ) {
  26024. this.loopEnd = value;
  26025. return this;
  26026. },
  26027. getVolume: function () {
  26028. return this.gain.gain.value;
  26029. },
  26030. setVolume: function ( value ) {
  26031. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  26032. return this;
  26033. }
  26034. } );
  26035. /**
  26036. * @author mrdoob / http://mrdoob.com/
  26037. */
  26038. const _position$3 = new Vector3();
  26039. const _quaternion$4 = new Quaternion();
  26040. const _scale$2 = new Vector3();
  26041. const _orientation$1 = new Vector3();
  26042. function PositionalAudio( listener ) {
  26043. Audio.call( this, listener );
  26044. this.panner = this.context.createPanner();
  26045. this.panner.panningModel = 'HRTF';
  26046. this.panner.connect( this.gain );
  26047. }
  26048. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  26049. constructor: PositionalAudio,
  26050. getOutput: function () {
  26051. return this.panner;
  26052. },
  26053. getRefDistance: function () {
  26054. return this.panner.refDistance;
  26055. },
  26056. setRefDistance: function ( value ) {
  26057. this.panner.refDistance = value;
  26058. return this;
  26059. },
  26060. getRolloffFactor: function () {
  26061. return this.panner.rolloffFactor;
  26062. },
  26063. setRolloffFactor: function ( value ) {
  26064. this.panner.rolloffFactor = value;
  26065. return this;
  26066. },
  26067. getDistanceModel: function () {
  26068. return this.panner.distanceModel;
  26069. },
  26070. setDistanceModel: function ( value ) {
  26071. this.panner.distanceModel = value;
  26072. return this;
  26073. },
  26074. getMaxDistance: function () {
  26075. return this.panner.maxDistance;
  26076. },
  26077. setMaxDistance: function ( value ) {
  26078. this.panner.maxDistance = value;
  26079. return this;
  26080. },
  26081. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  26082. this.panner.coneInnerAngle = coneInnerAngle;
  26083. this.panner.coneOuterAngle = coneOuterAngle;
  26084. this.panner.coneOuterGain = coneOuterGain;
  26085. return this;
  26086. },
  26087. updateMatrixWorld: function ( force ) {
  26088. Object3D.prototype.updateMatrixWorld.call( this, force );
  26089. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  26090. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  26091. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  26092. const panner = this.panner;
  26093. if ( panner.positionX ) {
  26094. // code path for Chrome and Firefox (see #14393)
  26095. const endTime = this.context.currentTime + this.listener.timeDelta;
  26096. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  26097. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  26098. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  26099. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  26100. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  26101. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  26102. } else {
  26103. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  26104. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  26105. }
  26106. }
  26107. } );
  26108. /**
  26109. * @author mrdoob / http://mrdoob.com/
  26110. */
  26111. function AudioAnalyser( audio, fftSize ) {
  26112. this.analyser = audio.context.createAnalyser();
  26113. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  26114. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  26115. audio.getOutput().connect( this.analyser );
  26116. }
  26117. Object.assign( AudioAnalyser.prototype, {
  26118. getFrequencyData: function () {
  26119. this.analyser.getByteFrequencyData( this.data );
  26120. return this.data;
  26121. },
  26122. getAverageFrequency: function () {
  26123. let value = 0;
  26124. const data = this.getFrequencyData();
  26125. for ( let i = 0; i < data.length; i ++ ) {
  26126. value += data[ i ];
  26127. }
  26128. return value / data.length;
  26129. }
  26130. } );
  26131. /**
  26132. *
  26133. * Buffered scene graph property that allows weighted accumulation.
  26134. *
  26135. *
  26136. * @author Ben Houston / http://clara.io/
  26137. * @author David Sarno / http://lighthaus.us/
  26138. * @author tschw
  26139. */
  26140. function PropertyMixer( binding, typeName, valueSize ) {
  26141. this.binding = binding;
  26142. this.valueSize = valueSize;
  26143. let mixFunction,
  26144. mixFunctionAdditive,
  26145. setIdentity;
  26146. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  26147. //
  26148. // interpolators can use .buffer as their .result
  26149. // the data then goes to 'incoming'
  26150. //
  26151. // 'accu0' and 'accu1' are used frame-interleaved for
  26152. // the cumulative result and are compared to detect
  26153. // changes
  26154. //
  26155. // 'orig' stores the original state of the property
  26156. //
  26157. // 'add' is used for additive cumulative results
  26158. //
  26159. // 'work' is optional and is only present for quaternion types. It is used
  26160. // to store intermediate quaternion multiplication results
  26161. switch ( typeName ) {
  26162. case 'quaternion':
  26163. mixFunction = this._slerp;
  26164. mixFunctionAdditive = this._slerpAdditive;
  26165. setIdentity = this._setAdditiveIdentityQuaternion;
  26166. this.buffer = new Float64Array( valueSize * 6 );
  26167. this._workIndex = 5;
  26168. break;
  26169. case 'string':
  26170. case 'bool':
  26171. mixFunction = this._select;
  26172. // Use the regular mix function and for additive on these types,
  26173. // additive is not relevant for non-numeric types
  26174. mixFunctionAdditive = this._select;
  26175. setIdentity = this._setAdditiveIdentityOther;
  26176. this.buffer = new Array( valueSize * 5 );
  26177. break;
  26178. default:
  26179. mixFunction = this._lerp;
  26180. mixFunctionAdditive = this._lerpAdditive;
  26181. setIdentity = this._setAdditiveIdentityNumeric;
  26182. this.buffer = new Float64Array( valueSize * 5 );
  26183. }
  26184. this._mixBufferRegion = mixFunction;
  26185. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26186. this._setIdentity = setIdentity;
  26187. this._origIndex = 3;
  26188. this._addIndex = 4;
  26189. this.cumulativeWeight = 0;
  26190. this.cumulativeWeightAdditive = 0;
  26191. this.useCount = 0;
  26192. this.referenceCount = 0;
  26193. }
  26194. Object.assign( PropertyMixer.prototype, {
  26195. // accumulate data in the 'incoming' region into 'accu<i>'
  26196. accumulate: function ( accuIndex, weight ) {
  26197. // note: happily accumulating nothing when weight = 0, the caller knows
  26198. // the weight and shouldn't have made the call in the first place
  26199. const buffer = this.buffer,
  26200. stride = this.valueSize,
  26201. offset = accuIndex * stride + stride;
  26202. let currentWeight = this.cumulativeWeight;
  26203. if ( currentWeight === 0 ) {
  26204. // accuN := incoming * weight
  26205. for ( let i = 0; i !== stride; ++ i ) {
  26206. buffer[ offset + i ] = buffer[ i ];
  26207. }
  26208. currentWeight = weight;
  26209. } else {
  26210. // accuN := accuN + incoming * weight
  26211. currentWeight += weight;
  26212. const mix = weight / currentWeight;
  26213. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  26214. }
  26215. this.cumulativeWeight = currentWeight;
  26216. },
  26217. // accumulate data in the 'incoming' region into 'add'
  26218. accumulateAdditive: function ( weight ) {
  26219. const buffer = this.buffer,
  26220. stride = this.valueSize,
  26221. offset = stride * this._addIndex;
  26222. if ( this.cumulativeWeightAdditive === 0 ) {
  26223. // add = identity
  26224. this._setIdentity();
  26225. }
  26226. // add := add + incoming * weight
  26227. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  26228. this.cumulativeWeightAdditive += weight;
  26229. },
  26230. // apply the state of 'accu<i>' to the binding when accus differ
  26231. apply: function ( accuIndex ) {
  26232. const stride = this.valueSize,
  26233. buffer = this.buffer,
  26234. offset = accuIndex * stride + stride,
  26235. weight = this.cumulativeWeight,
  26236. weightAdditive = this.cumulativeWeightAdditive,
  26237. binding = this.binding;
  26238. this.cumulativeWeight = 0;
  26239. this.cumulativeWeightAdditive = 0;
  26240. if ( weight < 1 ) {
  26241. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26242. const originalValueOffset = stride * this._origIndex;
  26243. this._mixBufferRegion(
  26244. buffer, offset, originalValueOffset, 1 - weight, stride );
  26245. }
  26246. if ( weightAdditive > 0 ) {
  26247. // accuN := accuN + additive accuN
  26248. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  26249. }
  26250. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  26251. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  26252. // value has changed -> update scene graph
  26253. binding.setValue( buffer, offset );
  26254. break;
  26255. }
  26256. }
  26257. },
  26258. // remember the state of the bound property and copy it to both accus
  26259. saveOriginalState: function () {
  26260. const binding = this.binding;
  26261. const buffer = this.buffer,
  26262. stride = this.valueSize,
  26263. originalValueOffset = stride * this._origIndex;
  26264. binding.getValue( buffer, originalValueOffset );
  26265. // accu[0..1] := orig -- initially detect changes against the original
  26266. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  26267. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  26268. }
  26269. // Add to identity for additive
  26270. this._setIdentity();
  26271. this.cumulativeWeight = 0;
  26272. this.cumulativeWeightAdditive = 0;
  26273. },
  26274. // apply the state previously taken via 'saveOriginalState' to the binding
  26275. restoreOriginalState: function () {
  26276. const originalValueOffset = this.valueSize * 3;
  26277. this.binding.setValue( this.buffer, originalValueOffset );
  26278. },
  26279. _setAdditiveIdentityNumeric: function () {
  26280. const startIndex = this._addIndex * this.valueSize;
  26281. const endIndex = startIndex + this.valueSize;
  26282. for ( let i = startIndex; i < endIndex; i ++ ) {
  26283. this.buffer[ i ] = 0;
  26284. }
  26285. },
  26286. _setAdditiveIdentityQuaternion: function () {
  26287. this._setAdditiveIdentityNumeric();
  26288. this.buffer[ this._addIndex * 4 + 3 ] = 1;
  26289. },
  26290. _setAdditiveIdentityOther: function () {
  26291. const startIndex = this._origIndex * this.valueSize;
  26292. const targetIndex = this._addIndex * this.valueSize;
  26293. for ( let i = 0; i < this.valueSize; i ++ ) {
  26294. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  26295. }
  26296. },
  26297. // mix functions
  26298. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26299. if ( t >= 0.5 ) {
  26300. for ( let i = 0; i !== stride; ++ i ) {
  26301. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  26302. }
  26303. }
  26304. },
  26305. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  26306. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  26307. },
  26308. _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26309. const workOffset = this._workIndex * stride;
  26310. // Store result in intermediate buffer offset
  26311. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  26312. // Slerp to the intermediate result
  26313. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  26314. },
  26315. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26316. const s = 1 - t;
  26317. for ( let i = 0; i !== stride; ++ i ) {
  26318. const j = dstOffset + i;
  26319. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  26320. }
  26321. },
  26322. _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26323. for ( let i = 0; i !== stride; ++ i ) {
  26324. const j = dstOffset + i;
  26325. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  26326. }
  26327. }
  26328. } );
  26329. /**
  26330. *
  26331. * A reference to a real property in the scene graph.
  26332. *
  26333. *
  26334. * @author Ben Houston / http://clara.io/
  26335. * @author David Sarno / http://lighthaus.us/
  26336. * @author tschw
  26337. */
  26338. // Characters [].:/ are reserved for track binding syntax.
  26339. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26340. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  26341. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26342. // only latin characters, and the unicode \p{L} is not yet supported. So
  26343. // instead, we exclude reserved characters and match everything else.
  26344. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26345. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26346. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26347. // be matched to parse the rest of the track name.
  26348. const _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  26349. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26350. const _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  26351. // Object on target node, and accessor. May not contain reserved
  26352. // characters. Accessor may contain any character except closing bracket.
  26353. const _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  26354. // Property and accessor. May not contain reserved characters. Accessor may
  26355. // contain any non-bracket characters.
  26356. const _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  26357. const _trackRe = new RegExp( ''
  26358. + '^'
  26359. + _directoryRe
  26360. + _nodeRe
  26361. + _objectRe
  26362. + _propertyRe
  26363. + '$'
  26364. );
  26365. const _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26366. function Composite( targetGroup, path, optionalParsedPath ) {
  26367. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  26368. this._targetGroup = targetGroup;
  26369. this._bindings = targetGroup.subscribe_( path, parsedPath );
  26370. }
  26371. Object.assign( Composite.prototype, {
  26372. getValue: function ( array, offset ) {
  26373. this.bind(); // bind all binding
  26374. const firstValidIndex = this._targetGroup.nCachedObjects_,
  26375. binding = this._bindings[ firstValidIndex ];
  26376. // and only call .getValue on the first
  26377. if ( binding !== undefined ) binding.getValue( array, offset );
  26378. },
  26379. setValue: function ( array, offset ) {
  26380. const bindings = this._bindings;
  26381. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26382. bindings[ i ].setValue( array, offset );
  26383. }
  26384. },
  26385. bind: function () {
  26386. const bindings = this._bindings;
  26387. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26388. bindings[ i ].bind();
  26389. }
  26390. },
  26391. unbind: function () {
  26392. const bindings = this._bindings;
  26393. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26394. bindings[ i ].unbind();
  26395. }
  26396. }
  26397. } );
  26398. function PropertyBinding( rootNode, path, parsedPath ) {
  26399. this.path = path;
  26400. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26401. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26402. this.rootNode = rootNode;
  26403. }
  26404. Object.assign( PropertyBinding, {
  26405. Composite: Composite,
  26406. create: function ( root, path, parsedPath ) {
  26407. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26408. return new PropertyBinding( root, path, parsedPath );
  26409. } else {
  26410. return new PropertyBinding.Composite( root, path, parsedPath );
  26411. }
  26412. },
  26413. /**
  26414. * Replaces spaces with underscores and removes unsupported characters from
  26415. * node names, to ensure compatibility with parseTrackName().
  26416. *
  26417. * @param {string} name Node name to be sanitized.
  26418. * @return {string}
  26419. */
  26420. sanitizeNodeName: function ( name ) {
  26421. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  26422. },
  26423. parseTrackName: function ( trackName ) {
  26424. const matches = _trackRe.exec( trackName );
  26425. if ( ! matches ) {
  26426. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26427. }
  26428. const results = {
  26429. // directoryName: matches[ 1 ], // (tschw) currently unused
  26430. nodeName: matches[ 2 ],
  26431. objectName: matches[ 3 ],
  26432. objectIndex: matches[ 4 ],
  26433. propertyName: matches[ 5 ], // required
  26434. propertyIndex: matches[ 6 ]
  26435. };
  26436. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26437. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26438. const objectName = results.nodeName.substring( lastDot + 1 );
  26439. // Object names must be checked against an allowlist. Otherwise, there
  26440. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26441. // 'bar' could be the objectName, or part of a nodeName (which can
  26442. // include '.' characters).
  26443. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26444. results.nodeName = results.nodeName.substring( 0, lastDot );
  26445. results.objectName = objectName;
  26446. }
  26447. }
  26448. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26449. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26450. }
  26451. return results;
  26452. },
  26453. findNode: function ( root, nodeName ) {
  26454. if ( ! nodeName || nodeName === "" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26455. return root;
  26456. }
  26457. // search into skeleton bones.
  26458. if ( root.skeleton ) {
  26459. const bone = root.skeleton.getBoneByName( nodeName );
  26460. if ( bone !== undefined ) {
  26461. return bone;
  26462. }
  26463. }
  26464. // search into node subtree.
  26465. if ( root.children ) {
  26466. const searchNodeSubtree = function ( children ) {
  26467. for ( let i = 0; i < children.length; i ++ ) {
  26468. const childNode = children[ i ];
  26469. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26470. return childNode;
  26471. }
  26472. const result = searchNodeSubtree( childNode.children );
  26473. if ( result ) return result;
  26474. }
  26475. return null;
  26476. };
  26477. const subTreeNode = searchNodeSubtree( root.children );
  26478. if ( subTreeNode ) {
  26479. return subTreeNode;
  26480. }
  26481. }
  26482. return null;
  26483. }
  26484. } );
  26485. Object.assign( PropertyBinding.prototype, { // prototype, continued
  26486. // these are used to "bind" a nonexistent property
  26487. _getValue_unavailable: function () {},
  26488. _setValue_unavailable: function () {},
  26489. BindingType: {
  26490. Direct: 0,
  26491. EntireArray: 1,
  26492. ArrayElement: 2,
  26493. HasFromToArray: 3
  26494. },
  26495. Versioning: {
  26496. None: 0,
  26497. NeedsUpdate: 1,
  26498. MatrixWorldNeedsUpdate: 2
  26499. },
  26500. GetterByBindingType: [
  26501. function getValue_direct( buffer, offset ) {
  26502. buffer[ offset ] = this.node[ this.propertyName ];
  26503. },
  26504. function getValue_array( buffer, offset ) {
  26505. const source = this.resolvedProperty;
  26506. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  26507. buffer[ offset ++ ] = source[ i ];
  26508. }
  26509. },
  26510. function getValue_arrayElement( buffer, offset ) {
  26511. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26512. },
  26513. function getValue_toArray( buffer, offset ) {
  26514. this.resolvedProperty.toArray( buffer, offset );
  26515. }
  26516. ],
  26517. SetterByBindingTypeAndVersioning: [
  26518. [
  26519. // Direct
  26520. function setValue_direct( buffer, offset ) {
  26521. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26522. },
  26523. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  26524. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26525. this.targetObject.needsUpdate = true;
  26526. },
  26527. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26528. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26529. this.targetObject.matrixWorldNeedsUpdate = true;
  26530. }
  26531. ], [
  26532. // EntireArray
  26533. function setValue_array( buffer, offset ) {
  26534. const dest = this.resolvedProperty;
  26535. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26536. dest[ i ] = buffer[ offset ++ ];
  26537. }
  26538. },
  26539. function setValue_array_setNeedsUpdate( buffer, offset ) {
  26540. const dest = this.resolvedProperty;
  26541. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26542. dest[ i ] = buffer[ offset ++ ];
  26543. }
  26544. this.targetObject.needsUpdate = true;
  26545. },
  26546. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26547. const dest = this.resolvedProperty;
  26548. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26549. dest[ i ] = buffer[ offset ++ ];
  26550. }
  26551. this.targetObject.matrixWorldNeedsUpdate = true;
  26552. }
  26553. ], [
  26554. // ArrayElement
  26555. function setValue_arrayElement( buffer, offset ) {
  26556. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26557. },
  26558. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26559. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26560. this.targetObject.needsUpdate = true;
  26561. },
  26562. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26563. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26564. this.targetObject.matrixWorldNeedsUpdate = true;
  26565. }
  26566. ], [
  26567. // HasToFromArray
  26568. function setValue_fromArray( buffer, offset ) {
  26569. this.resolvedProperty.fromArray( buffer, offset );
  26570. },
  26571. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26572. this.resolvedProperty.fromArray( buffer, offset );
  26573. this.targetObject.needsUpdate = true;
  26574. },
  26575. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26576. this.resolvedProperty.fromArray( buffer, offset );
  26577. this.targetObject.matrixWorldNeedsUpdate = true;
  26578. }
  26579. ]
  26580. ],
  26581. getValue: function getValue_unbound( targetArray, offset ) {
  26582. this.bind();
  26583. this.getValue( targetArray, offset );
  26584. // Note: This class uses a State pattern on a per-method basis:
  26585. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26586. // prototype version of these methods with one that represents
  26587. // the bound state. When the property is not found, the methods
  26588. // become no-ops.
  26589. },
  26590. setValue: function getValue_unbound( sourceArray, offset ) {
  26591. this.bind();
  26592. this.setValue( sourceArray, offset );
  26593. },
  26594. // create getter / setter pair for a property in the scene graph
  26595. bind: function () {
  26596. let targetObject = this.node,
  26597. parsedPath = this.parsedPath,
  26598. objectName = parsedPath.objectName,
  26599. propertyName = parsedPath.propertyName,
  26600. propertyIndex = parsedPath.propertyIndex;
  26601. if ( ! targetObject ) {
  26602. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26603. this.node = targetObject;
  26604. }
  26605. // set fail state so we can just 'return' on error
  26606. this.getValue = this._getValue_unavailable;
  26607. this.setValue = this._setValue_unavailable;
  26608. // ensure there is a value node
  26609. if ( ! targetObject ) {
  26610. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26611. return;
  26612. }
  26613. if ( objectName ) {
  26614. let objectIndex = parsedPath.objectIndex;
  26615. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26616. switch ( objectName ) {
  26617. case 'materials':
  26618. if ( ! targetObject.material ) {
  26619. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26620. return;
  26621. }
  26622. if ( ! targetObject.material.materials ) {
  26623. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26624. return;
  26625. }
  26626. targetObject = targetObject.material.materials;
  26627. break;
  26628. case 'bones':
  26629. if ( ! targetObject.skeleton ) {
  26630. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26631. return;
  26632. }
  26633. // potential future optimization: skip this if propertyIndex is already an integer
  26634. // and convert the integer string to a true integer.
  26635. targetObject = targetObject.skeleton.bones;
  26636. // support resolving morphTarget names into indices.
  26637. for ( let i = 0; i < targetObject.length; i ++ ) {
  26638. if ( targetObject[ i ].name === objectIndex ) {
  26639. objectIndex = i;
  26640. break;
  26641. }
  26642. }
  26643. break;
  26644. default:
  26645. if ( targetObject[ objectName ] === undefined ) {
  26646. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26647. return;
  26648. }
  26649. targetObject = targetObject[ objectName ];
  26650. }
  26651. if ( objectIndex !== undefined ) {
  26652. if ( targetObject[ objectIndex ] === undefined ) {
  26653. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26654. return;
  26655. }
  26656. targetObject = targetObject[ objectIndex ];
  26657. }
  26658. }
  26659. // resolve property
  26660. const nodeProperty = targetObject[ propertyName ];
  26661. if ( nodeProperty === undefined ) {
  26662. const nodeName = parsedPath.nodeName;
  26663. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26664. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26665. return;
  26666. }
  26667. // determine versioning scheme
  26668. let versioning = this.Versioning.None;
  26669. this.targetObject = targetObject;
  26670. if ( targetObject.needsUpdate !== undefined ) { // material
  26671. versioning = this.Versioning.NeedsUpdate;
  26672. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26673. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26674. }
  26675. // determine how the property gets bound
  26676. let bindingType = this.BindingType.Direct;
  26677. if ( propertyIndex !== undefined ) {
  26678. // access a sub element of the property array (only primitives are supported right now)
  26679. if ( propertyName === "morphTargetInfluences" ) {
  26680. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26681. // support resolving morphTarget names into indices.
  26682. if ( ! targetObject.geometry ) {
  26683. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26684. return;
  26685. }
  26686. if ( targetObject.geometry.isBufferGeometry ) {
  26687. if ( ! targetObject.geometry.morphAttributes ) {
  26688. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26689. return;
  26690. }
  26691. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  26692. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  26693. }
  26694. } else {
  26695. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  26696. return;
  26697. }
  26698. }
  26699. bindingType = this.BindingType.ArrayElement;
  26700. this.resolvedProperty = nodeProperty;
  26701. this.propertyIndex = propertyIndex;
  26702. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26703. // must use copy for Object3D.Euler/Quaternion
  26704. bindingType = this.BindingType.HasFromToArray;
  26705. this.resolvedProperty = nodeProperty;
  26706. } else if ( Array.isArray( nodeProperty ) ) {
  26707. bindingType = this.BindingType.EntireArray;
  26708. this.resolvedProperty = nodeProperty;
  26709. } else {
  26710. this.propertyName = propertyName;
  26711. }
  26712. // select getter / setter
  26713. this.getValue = this.GetterByBindingType[ bindingType ];
  26714. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26715. },
  26716. unbind: function () {
  26717. this.node = null;
  26718. // back to the prototype version of getValue / setValue
  26719. // note: avoiding to mutate the shape of 'this' via 'delete'
  26720. this.getValue = this._getValue_unbound;
  26721. this.setValue = this._setValue_unbound;
  26722. }
  26723. } );
  26724. // DECLARE ALIAS AFTER assign prototype
  26725. Object.assign( PropertyBinding.prototype, {
  26726. // initial state of these methods that calls 'bind'
  26727. _getValue_unbound: PropertyBinding.prototype.getValue,
  26728. _setValue_unbound: PropertyBinding.prototype.setValue,
  26729. } );
  26730. /**
  26731. *
  26732. * A group of objects that receives a shared animation state.
  26733. *
  26734. * Usage:
  26735. *
  26736. * - Add objects you would otherwise pass as 'root' to the
  26737. * constructor or the .clipAction method of AnimationMixer.
  26738. *
  26739. * - Instead pass this object as 'root'.
  26740. *
  26741. * - You can also add and remove objects later when the mixer
  26742. * is running.
  26743. *
  26744. * Note:
  26745. *
  26746. * Objects of this class appear as one object to the mixer,
  26747. * so cache control of the individual objects must be done
  26748. * on the group.
  26749. *
  26750. * Limitation:
  26751. *
  26752. * - The animated properties must be compatible among the
  26753. * all objects in the group.
  26754. *
  26755. * - A single property can either be controlled through a
  26756. * target group or directly, but not both.
  26757. *
  26758. * @author tschw
  26759. */
  26760. function AnimationObjectGroup() {
  26761. this.uuid = MathUtils.generateUUID();
  26762. // cached objects followed by the active ones
  26763. this._objects = Array.prototype.slice.call( arguments );
  26764. this.nCachedObjects_ = 0; // threshold
  26765. // note: read by PropertyBinding.Composite
  26766. const indices = {};
  26767. this._indicesByUUID = indices; // for bookkeeping
  26768. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26769. indices[ arguments[ i ].uuid ] = i;
  26770. }
  26771. this._paths = []; // inside: string
  26772. this._parsedPaths = []; // inside: { we don't care, here }
  26773. this._bindings = []; // inside: Array< PropertyBinding >
  26774. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26775. const scope = this;
  26776. this.stats = {
  26777. objects: {
  26778. get total() {
  26779. return scope._objects.length;
  26780. },
  26781. get inUse() {
  26782. return this.total - scope.nCachedObjects_;
  26783. }
  26784. },
  26785. get bindingsPerObject() {
  26786. return scope._bindings.length;
  26787. }
  26788. };
  26789. }
  26790. Object.assign( AnimationObjectGroup.prototype, {
  26791. isAnimationObjectGroup: true,
  26792. add: function () {
  26793. const objects = this._objects,
  26794. indicesByUUID = this._indicesByUUID,
  26795. paths = this._paths,
  26796. parsedPaths = this._parsedPaths,
  26797. bindings = this._bindings,
  26798. nBindings = bindings.length;
  26799. let knownObject = undefined,
  26800. nObjects = objects.length,
  26801. nCachedObjects = this.nCachedObjects_;
  26802. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26803. const object = arguments[ i ],
  26804. uuid = object.uuid;
  26805. let index = indicesByUUID[ uuid ];
  26806. if ( index === undefined ) {
  26807. // unknown object -> add it to the ACTIVE region
  26808. index = nObjects ++;
  26809. indicesByUUID[ uuid ] = index;
  26810. objects.push( object );
  26811. // accounting is done, now do the same for all bindings
  26812. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26813. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26814. }
  26815. } else if ( index < nCachedObjects ) {
  26816. knownObject = objects[ index ];
  26817. // move existing object to the ACTIVE region
  26818. const firstActiveIndex = -- nCachedObjects,
  26819. lastCachedObject = objects[ firstActiveIndex ];
  26820. indicesByUUID[ lastCachedObject.uuid ] = index;
  26821. objects[ index ] = lastCachedObject;
  26822. indicesByUUID[ uuid ] = firstActiveIndex;
  26823. objects[ firstActiveIndex ] = object;
  26824. // accounting is done, now do the same for all bindings
  26825. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26826. const bindingsForPath = bindings[ j ],
  26827. lastCached = bindingsForPath[ firstActiveIndex ];
  26828. let binding = bindingsForPath[ index ];
  26829. bindingsForPath[ index ] = lastCached;
  26830. if ( binding === undefined ) {
  26831. // since we do not bother to create new bindings
  26832. // for objects that are cached, the binding may
  26833. // or may not exist
  26834. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26835. }
  26836. bindingsForPath[ firstActiveIndex ] = binding;
  26837. }
  26838. } else if ( objects[ index ] !== knownObject ) {
  26839. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26840. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26841. } // else the object is already where we want it to be
  26842. } // for arguments
  26843. this.nCachedObjects_ = nCachedObjects;
  26844. },
  26845. remove: function () {
  26846. const objects = this._objects,
  26847. indicesByUUID = this._indicesByUUID,
  26848. bindings = this._bindings,
  26849. nBindings = bindings.length;
  26850. let nCachedObjects = this.nCachedObjects_;
  26851. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26852. const object = arguments[ i ],
  26853. uuid = object.uuid,
  26854. index = indicesByUUID[ uuid ];
  26855. if ( index !== undefined && index >= nCachedObjects ) {
  26856. // move existing object into the CACHED region
  26857. const lastCachedIndex = nCachedObjects ++,
  26858. firstActiveObject = objects[ lastCachedIndex ];
  26859. indicesByUUID[ firstActiveObject.uuid ] = index;
  26860. objects[ index ] = firstActiveObject;
  26861. indicesByUUID[ uuid ] = lastCachedIndex;
  26862. objects[ lastCachedIndex ] = object;
  26863. // accounting is done, now do the same for all bindings
  26864. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26865. const bindingsForPath = bindings[ j ],
  26866. firstActive = bindingsForPath[ lastCachedIndex ],
  26867. binding = bindingsForPath[ index ];
  26868. bindingsForPath[ index ] = firstActive;
  26869. bindingsForPath[ lastCachedIndex ] = binding;
  26870. }
  26871. }
  26872. } // for arguments
  26873. this.nCachedObjects_ = nCachedObjects;
  26874. },
  26875. // remove & forget
  26876. uncache: function () {
  26877. const objects = this._objects,
  26878. indicesByUUID = this._indicesByUUID,
  26879. bindings = this._bindings,
  26880. nBindings = bindings.length;
  26881. let nCachedObjects = this.nCachedObjects_,
  26882. nObjects = objects.length;
  26883. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26884. const object = arguments[ i ],
  26885. uuid = object.uuid,
  26886. index = indicesByUUID[ uuid ];
  26887. if ( index !== undefined ) {
  26888. delete indicesByUUID[ uuid ];
  26889. if ( index < nCachedObjects ) {
  26890. // object is cached, shrink the CACHED region
  26891. const firstActiveIndex = -- nCachedObjects,
  26892. lastCachedObject = objects[ firstActiveIndex ],
  26893. lastIndex = -- nObjects,
  26894. lastObject = objects[ lastIndex ];
  26895. // last cached object takes this object's place
  26896. indicesByUUID[ lastCachedObject.uuid ] = index;
  26897. objects[ index ] = lastCachedObject;
  26898. // last object goes to the activated slot and pop
  26899. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26900. objects[ firstActiveIndex ] = lastObject;
  26901. objects.pop();
  26902. // accounting is done, now do the same for all bindings
  26903. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26904. const bindingsForPath = bindings[ j ],
  26905. lastCached = bindingsForPath[ firstActiveIndex ],
  26906. last = bindingsForPath[ lastIndex ];
  26907. bindingsForPath[ index ] = lastCached;
  26908. bindingsForPath[ firstActiveIndex ] = last;
  26909. bindingsForPath.pop();
  26910. }
  26911. } else {
  26912. // object is active, just swap with the last and pop
  26913. const lastIndex = -- nObjects,
  26914. lastObject = objects[ lastIndex ];
  26915. indicesByUUID[ lastObject.uuid ] = index;
  26916. objects[ index ] = lastObject;
  26917. objects.pop();
  26918. // accounting is done, now do the same for all bindings
  26919. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26920. const bindingsForPath = bindings[ j ];
  26921. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26922. bindingsForPath.pop();
  26923. }
  26924. } // cached or active
  26925. } // if object is known
  26926. } // for arguments
  26927. this.nCachedObjects_ = nCachedObjects;
  26928. },
  26929. // Internal interface used by befriended PropertyBinding.Composite:
  26930. subscribe_: function ( path, parsedPath ) {
  26931. // returns an array of bindings for the given path that is changed
  26932. // according to the contained objects in the group
  26933. let indicesByPath = this._bindingsIndicesByPath,
  26934. index = indicesByPath[ path ],
  26935. bindings = this._bindings;
  26936. if ( index !== undefined ) return bindings[ index ];
  26937. const paths = this._paths,
  26938. parsedPaths = this._parsedPaths,
  26939. objects = this._objects,
  26940. nObjects = objects.length,
  26941. nCachedObjects = this.nCachedObjects_,
  26942. bindingsForPath = new Array( nObjects );
  26943. index = bindings.length;
  26944. indicesByPath[ path ] = index;
  26945. paths.push( path );
  26946. parsedPaths.push( parsedPath );
  26947. bindings.push( bindingsForPath );
  26948. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26949. const object = objects[ i ];
  26950. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26951. }
  26952. return bindingsForPath;
  26953. },
  26954. unsubscribe_: function ( path ) {
  26955. // tells the group to forget about a property path and no longer
  26956. // update the array previously obtained with 'subscribe_'
  26957. const indicesByPath = this._bindingsIndicesByPath,
  26958. index = indicesByPath[ path ];
  26959. if ( index !== undefined ) {
  26960. const paths = this._paths,
  26961. parsedPaths = this._parsedPaths,
  26962. bindings = this._bindings,
  26963. lastBindingsIndex = bindings.length - 1,
  26964. lastBindings = bindings[ lastBindingsIndex ],
  26965. lastBindingsPath = path[ lastBindingsIndex ];
  26966. indicesByPath[ lastBindingsPath ] = index;
  26967. bindings[ index ] = lastBindings;
  26968. bindings.pop();
  26969. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26970. parsedPaths.pop();
  26971. paths[ index ] = paths[ lastBindingsIndex ];
  26972. paths.pop();
  26973. }
  26974. }
  26975. } );
  26976. /**
  26977. *
  26978. * Action provided by AnimationMixer for scheduling clip playback on specific
  26979. * objects.
  26980. *
  26981. * @author Ben Houston / http://clara.io/
  26982. * @author David Sarno / http://lighthaus.us/
  26983. * @author tschw
  26984. *
  26985. */
  26986. function AnimationAction( mixer, clip, localRoot, blendMode ) {
  26987. this._mixer = mixer;
  26988. this._clip = clip;
  26989. this._localRoot = localRoot || null;
  26990. this.blendMode = blendMode || clip.blendMode;
  26991. const tracks = clip.tracks,
  26992. nTracks = tracks.length,
  26993. interpolants = new Array( nTracks );
  26994. const interpolantSettings = {
  26995. endingStart: ZeroCurvatureEnding,
  26996. endingEnd: ZeroCurvatureEnding
  26997. };
  26998. for ( let i = 0; i !== nTracks; ++ i ) {
  26999. const interpolant = tracks[ i ].createInterpolant( null );
  27000. interpolants[ i ] = interpolant;
  27001. interpolant.settings = interpolantSettings;
  27002. }
  27003. this._interpolantSettings = interpolantSettings;
  27004. this._interpolants = interpolants; // bound by the mixer
  27005. // inside: PropertyMixer (managed by the mixer)
  27006. this._propertyBindings = new Array( nTracks );
  27007. this._cacheIndex = null; // for the memory manager
  27008. this._byClipCacheIndex = null; // for the memory manager
  27009. this._timeScaleInterpolant = null;
  27010. this._weightInterpolant = null;
  27011. this.loop = LoopRepeat;
  27012. this._loopCount = - 1;
  27013. // global mixer time when the action is to be started
  27014. // it's set back to 'null' upon start of the action
  27015. this._startTime = null;
  27016. // scaled local time of the action
  27017. // gets clamped or wrapped to 0..clip.duration according to loop
  27018. this.time = 0;
  27019. this.timeScale = 1;
  27020. this._effectiveTimeScale = 1;
  27021. this.weight = 1;
  27022. this._effectiveWeight = 1;
  27023. this.repetitions = Infinity; // no. of repetitions when looping
  27024. this.paused = false; // true -> zero effective time scale
  27025. this.enabled = true; // false -> zero effective weight
  27026. this.clampWhenFinished = false;// keep feeding the last frame?
  27027. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  27028. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  27029. }
  27030. Object.assign( AnimationAction.prototype, {
  27031. // State & Scheduling
  27032. play: function () {
  27033. this._mixer._activateAction( this );
  27034. return this;
  27035. },
  27036. stop: function () {
  27037. this._mixer._deactivateAction( this );
  27038. return this.reset();
  27039. },
  27040. reset: function () {
  27041. this.paused = false;
  27042. this.enabled = true;
  27043. this.time = 0; // restart clip
  27044. this._loopCount = - 1;// forget previous loops
  27045. this._startTime = null;// forget scheduling
  27046. return this.stopFading().stopWarping();
  27047. },
  27048. isRunning: function () {
  27049. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  27050. this._startTime === null && this._mixer._isActiveAction( this );
  27051. },
  27052. // return true when play has been called
  27053. isScheduled: function () {
  27054. return this._mixer._isActiveAction( this );
  27055. },
  27056. startAt: function ( time ) {
  27057. this._startTime = time;
  27058. return this;
  27059. },
  27060. setLoop: function ( mode, repetitions ) {
  27061. this.loop = mode;
  27062. this.repetitions = repetitions;
  27063. return this;
  27064. },
  27065. // Weight
  27066. // set the weight stopping any scheduled fading
  27067. // although .enabled = false yields an effective weight of zero, this
  27068. // method does *not* change .enabled, because it would be confusing
  27069. setEffectiveWeight: function ( weight ) {
  27070. this.weight = weight;
  27071. // note: same logic as when updated at runtime
  27072. this._effectiveWeight = this.enabled ? weight : 0;
  27073. return this.stopFading();
  27074. },
  27075. // return the weight considering fading and .enabled
  27076. getEffectiveWeight: function () {
  27077. return this._effectiveWeight;
  27078. },
  27079. fadeIn: function ( duration ) {
  27080. return this._scheduleFading( duration, 0, 1 );
  27081. },
  27082. fadeOut: function ( duration ) {
  27083. return this._scheduleFading( duration, 1, 0 );
  27084. },
  27085. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  27086. fadeOutAction.fadeOut( duration );
  27087. this.fadeIn( duration );
  27088. if ( warp ) {
  27089. const fadeInDuration = this._clip.duration,
  27090. fadeOutDuration = fadeOutAction._clip.duration,
  27091. startEndRatio = fadeOutDuration / fadeInDuration,
  27092. endStartRatio = fadeInDuration / fadeOutDuration;
  27093. fadeOutAction.warp( 1.0, startEndRatio, duration );
  27094. this.warp( endStartRatio, 1.0, duration );
  27095. }
  27096. return this;
  27097. },
  27098. crossFadeTo: function ( fadeInAction, duration, warp ) {
  27099. return fadeInAction.crossFadeFrom( this, duration, warp );
  27100. },
  27101. stopFading: function () {
  27102. let weightInterpolant = this._weightInterpolant;
  27103. if ( weightInterpolant !== null ) {
  27104. this._weightInterpolant = null;
  27105. this._mixer._takeBackControlInterpolant( weightInterpolant );
  27106. }
  27107. return this;
  27108. },
  27109. // Time Scale Control
  27110. // set the time scale stopping any scheduled warping
  27111. // although .paused = true yields an effective time scale of zero, this
  27112. // method does *not* change .paused, because it would be confusing
  27113. setEffectiveTimeScale: function ( timeScale ) {
  27114. this.timeScale = timeScale;
  27115. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  27116. return this.stopWarping();
  27117. },
  27118. // return the time scale considering warping and .paused
  27119. getEffectiveTimeScale: function () {
  27120. return this._effectiveTimeScale;
  27121. },
  27122. setDuration: function ( duration ) {
  27123. this.timeScale = this._clip.duration / duration;
  27124. return this.stopWarping();
  27125. },
  27126. syncWith: function ( action ) {
  27127. this.time = action.time;
  27128. this.timeScale = action.timeScale;
  27129. return this.stopWarping();
  27130. },
  27131. halt: function ( duration ) {
  27132. return this.warp( this._effectiveTimeScale, 0, duration );
  27133. },
  27134. warp: function ( startTimeScale, endTimeScale, duration ) {
  27135. const mixer = this._mixer,
  27136. now = mixer.time,
  27137. timeScale = this.timeScale;
  27138. let interpolant = this._timeScaleInterpolant;
  27139. if ( interpolant === null ) {
  27140. interpolant = mixer._lendControlInterpolant();
  27141. this._timeScaleInterpolant = interpolant;
  27142. }
  27143. const times = interpolant.parameterPositions,
  27144. values = interpolant.sampleValues;
  27145. times[ 0 ] = now;
  27146. times[ 1 ] = now + duration;
  27147. values[ 0 ] = startTimeScale / timeScale;
  27148. values[ 1 ] = endTimeScale / timeScale;
  27149. return this;
  27150. },
  27151. stopWarping: function () {
  27152. let timeScaleInterpolant = this._timeScaleInterpolant;
  27153. if ( timeScaleInterpolant !== null ) {
  27154. this._timeScaleInterpolant = null;
  27155. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  27156. }
  27157. return this;
  27158. },
  27159. // Object Accessors
  27160. getMixer: function () {
  27161. return this._mixer;
  27162. },
  27163. getClip: function () {
  27164. return this._clip;
  27165. },
  27166. getRoot: function () {
  27167. return this._localRoot || this._mixer._root;
  27168. },
  27169. // Interna
  27170. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  27171. // called by the mixer
  27172. if ( ! this.enabled ) {
  27173. // call ._updateWeight() to update ._effectiveWeight
  27174. this._updateWeight( time );
  27175. return;
  27176. }
  27177. const startTime = this._startTime;
  27178. if ( startTime !== null ) {
  27179. // check for scheduled start of action
  27180. const timeRunning = ( time - startTime ) * timeDirection;
  27181. if ( timeRunning < 0 || timeDirection === 0 ) {
  27182. return; // yet to come / don't decide when delta = 0
  27183. }
  27184. // start
  27185. this._startTime = null; // unschedule
  27186. deltaTime = timeDirection * timeRunning;
  27187. }
  27188. // apply time scale and advance time
  27189. deltaTime *= this._updateTimeScale( time );
  27190. const clipTime = this._updateTime( deltaTime );
  27191. // note: _updateTime may disable the action resulting in
  27192. // an effective weight of 0
  27193. const weight = this._updateWeight( time );
  27194. if ( weight > 0 ) {
  27195. const interpolants = this._interpolants;
  27196. const propertyMixers = this._propertyBindings;
  27197. switch ( this.blendMode ) {
  27198. case AdditiveAnimationBlendMode:
  27199. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  27200. interpolants[ j ].evaluate( clipTime );
  27201. propertyMixers[ j ].accumulateAdditive( weight );
  27202. }
  27203. break;
  27204. case NormalAnimationBlendMode:
  27205. default:
  27206. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  27207. interpolants[ j ].evaluate( clipTime );
  27208. propertyMixers[ j ].accumulate( accuIndex, weight );
  27209. }
  27210. }
  27211. }
  27212. },
  27213. _updateWeight: function ( time ) {
  27214. let weight = 0;
  27215. if ( this.enabled ) {
  27216. weight = this.weight;
  27217. const interpolant = this._weightInterpolant;
  27218. if ( interpolant !== null ) {
  27219. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  27220. weight *= interpolantValue;
  27221. if ( time > interpolant.parameterPositions[ 1 ] ) {
  27222. this.stopFading();
  27223. if ( interpolantValue === 0 ) {
  27224. // faded out, disable
  27225. this.enabled = false;
  27226. }
  27227. }
  27228. }
  27229. }
  27230. this._effectiveWeight = weight;
  27231. return weight;
  27232. },
  27233. _updateTimeScale: function ( time ) {
  27234. let timeScale = 0;
  27235. if ( ! this.paused ) {
  27236. timeScale = this.timeScale;
  27237. const interpolant = this._timeScaleInterpolant;
  27238. if ( interpolant !== null ) {
  27239. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  27240. timeScale *= interpolantValue;
  27241. if ( time > interpolant.parameterPositions[ 1 ] ) {
  27242. this.stopWarping();
  27243. if ( timeScale === 0 ) {
  27244. // motion has halted, pause
  27245. this.paused = true;
  27246. } else {
  27247. // warp done - apply final time scale
  27248. this.timeScale = timeScale;
  27249. }
  27250. }
  27251. }
  27252. }
  27253. this._effectiveTimeScale = timeScale;
  27254. return timeScale;
  27255. },
  27256. _updateTime: function ( deltaTime ) {
  27257. const duration = this._clip.duration;
  27258. const loop = this.loop;
  27259. let time = this.time + deltaTime;
  27260. let loopCount = this._loopCount;
  27261. const pingPong = ( loop === LoopPingPong );
  27262. if ( deltaTime === 0 ) {
  27263. if ( loopCount === - 1 ) return time;
  27264. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  27265. }
  27266. if ( loop === LoopOnce ) {
  27267. if ( loopCount === - 1 ) {
  27268. // just started
  27269. this._loopCount = 0;
  27270. this._setEndings( true, true, false );
  27271. }
  27272. handle_stop: {
  27273. if ( time >= duration ) {
  27274. time = duration;
  27275. } else if ( time < 0 ) {
  27276. time = 0;
  27277. } else {
  27278. this.time = time;
  27279. break handle_stop;
  27280. }
  27281. if ( this.clampWhenFinished ) this.paused = true;
  27282. else this.enabled = false;
  27283. this.time = time;
  27284. this._mixer.dispatchEvent( {
  27285. type: 'finished', action: this,
  27286. direction: deltaTime < 0 ? - 1 : 1
  27287. } );
  27288. }
  27289. } else { // repetitive Repeat or PingPong
  27290. if ( loopCount === - 1 ) {
  27291. // just started
  27292. if ( deltaTime >= 0 ) {
  27293. loopCount = 0;
  27294. this._setEndings( true, this.repetitions === 0, pingPong );
  27295. } else {
  27296. // when looping in reverse direction, the initial
  27297. // transition through zero counts as a repetition,
  27298. // so leave loopCount at -1
  27299. this._setEndings( this.repetitions === 0, true, pingPong );
  27300. }
  27301. }
  27302. if ( time >= duration || time < 0 ) {
  27303. // wrap around
  27304. const loopDelta = Math.floor( time / duration ); // signed
  27305. time -= duration * loopDelta;
  27306. loopCount += Math.abs( loopDelta );
  27307. const pending = this.repetitions - loopCount;
  27308. if ( pending <= 0 ) {
  27309. // have to stop (switch state, clamp time, fire event)
  27310. if ( this.clampWhenFinished ) this.paused = true;
  27311. else this.enabled = false;
  27312. time = deltaTime > 0 ? duration : 0;
  27313. this.time = time;
  27314. this._mixer.dispatchEvent( {
  27315. type: 'finished', action: this,
  27316. direction: deltaTime > 0 ? 1 : - 1
  27317. } );
  27318. } else {
  27319. // keep running
  27320. if ( pending === 1 ) {
  27321. // entering the last round
  27322. const atStart = deltaTime < 0;
  27323. this._setEndings( atStart, ! atStart, pingPong );
  27324. } else {
  27325. this._setEndings( false, false, pingPong );
  27326. }
  27327. this._loopCount = loopCount;
  27328. this.time = time;
  27329. this._mixer.dispatchEvent( {
  27330. type: 'loop', action: this, loopDelta: loopDelta
  27331. } );
  27332. }
  27333. } else {
  27334. this.time = time;
  27335. }
  27336. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  27337. // invert time for the "pong round"
  27338. return duration - time;
  27339. }
  27340. }
  27341. return time;
  27342. },
  27343. _setEndings: function ( atStart, atEnd, pingPong ) {
  27344. const settings = this._interpolantSettings;
  27345. if ( pingPong ) {
  27346. settings.endingStart = ZeroSlopeEnding;
  27347. settings.endingEnd = ZeroSlopeEnding;
  27348. } else {
  27349. // assuming for LoopOnce atStart == atEnd == true
  27350. if ( atStart ) {
  27351. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27352. } else {
  27353. settings.endingStart = WrapAroundEnding;
  27354. }
  27355. if ( atEnd ) {
  27356. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27357. } else {
  27358. settings.endingEnd = WrapAroundEnding;
  27359. }
  27360. }
  27361. },
  27362. _scheduleFading: function ( duration, weightNow, weightThen ) {
  27363. const mixer = this._mixer, now = mixer.time;
  27364. let interpolant = this._weightInterpolant;
  27365. if ( interpolant === null ) {
  27366. interpolant = mixer._lendControlInterpolant();
  27367. this._weightInterpolant = interpolant;
  27368. }
  27369. const times = interpolant.parameterPositions,
  27370. values = interpolant.sampleValues;
  27371. times[ 0 ] = now;
  27372. values[ 0 ] = weightNow;
  27373. times[ 1 ] = now + duration;
  27374. values[ 1 ] = weightThen;
  27375. return this;
  27376. }
  27377. } );
  27378. /**
  27379. *
  27380. * Player for AnimationClips.
  27381. *
  27382. *
  27383. * @author Ben Houston / http://clara.io/
  27384. * @author David Sarno / http://lighthaus.us/
  27385. * @author tschw
  27386. */
  27387. function AnimationMixer( root ) {
  27388. this._root = root;
  27389. this._initMemoryManager();
  27390. this._accuIndex = 0;
  27391. this.time = 0;
  27392. this.timeScale = 1.0;
  27393. }
  27394. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  27395. constructor: AnimationMixer,
  27396. _bindAction: function ( action, prototypeAction ) {
  27397. const root = action._localRoot || this._root,
  27398. tracks = action._clip.tracks,
  27399. nTracks = tracks.length,
  27400. bindings = action._propertyBindings,
  27401. interpolants = action._interpolants,
  27402. rootUuid = root.uuid,
  27403. bindingsByRoot = this._bindingsByRootAndName;
  27404. let bindingsByName = bindingsByRoot[ rootUuid ];
  27405. if ( bindingsByName === undefined ) {
  27406. bindingsByName = {};
  27407. bindingsByRoot[ rootUuid ] = bindingsByName;
  27408. }
  27409. for ( let i = 0; i !== nTracks; ++ i ) {
  27410. const track = tracks[ i ],
  27411. trackName = track.name;
  27412. let binding = bindingsByName[ trackName ];
  27413. if ( binding !== undefined ) {
  27414. bindings[ i ] = binding;
  27415. } else {
  27416. binding = bindings[ i ];
  27417. if ( binding !== undefined ) {
  27418. // existing binding, make sure the cache knows
  27419. if ( binding._cacheIndex === null ) {
  27420. ++ binding.referenceCount;
  27421. this._addInactiveBinding( binding, rootUuid, trackName );
  27422. }
  27423. continue;
  27424. }
  27425. const path = prototypeAction && prototypeAction.
  27426. _propertyBindings[ i ].binding.parsedPath;
  27427. binding = new PropertyMixer(
  27428. PropertyBinding.create( root, trackName, path ),
  27429. track.ValueTypeName, track.getValueSize() );
  27430. ++ binding.referenceCount;
  27431. this._addInactiveBinding( binding, rootUuid, trackName );
  27432. bindings[ i ] = binding;
  27433. }
  27434. interpolants[ i ].resultBuffer = binding.buffer;
  27435. }
  27436. },
  27437. _activateAction: function ( action ) {
  27438. if ( ! this._isActiveAction( action ) ) {
  27439. if ( action._cacheIndex === null ) {
  27440. // this action has been forgotten by the cache, but the user
  27441. // appears to be still using it -> rebind
  27442. const rootUuid = ( action._localRoot || this._root ).uuid,
  27443. clipUuid = action._clip.uuid,
  27444. actionsForClip = this._actionsByClip[ clipUuid ];
  27445. this._bindAction( action,
  27446. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27447. this._addInactiveAction( action, clipUuid, rootUuid );
  27448. }
  27449. const bindings = action._propertyBindings;
  27450. // increment reference counts / sort out state
  27451. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27452. const binding = bindings[ i ];
  27453. if ( binding.useCount ++ === 0 ) {
  27454. this._lendBinding( binding );
  27455. binding.saveOriginalState();
  27456. }
  27457. }
  27458. this._lendAction( action );
  27459. }
  27460. },
  27461. _deactivateAction: function ( action ) {
  27462. if ( this._isActiveAction( action ) ) {
  27463. const bindings = action._propertyBindings;
  27464. // decrement reference counts / sort out state
  27465. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27466. const binding = bindings[ i ];
  27467. if ( -- binding.useCount === 0 ) {
  27468. binding.restoreOriginalState();
  27469. this._takeBackBinding( binding );
  27470. }
  27471. }
  27472. this._takeBackAction( action );
  27473. }
  27474. },
  27475. // Memory manager
  27476. _initMemoryManager: function () {
  27477. this._actions = []; // 'nActiveActions' followed by inactive ones
  27478. this._nActiveActions = 0;
  27479. this._actionsByClip = {};
  27480. // inside:
  27481. // {
  27482. // knownActions: Array< AnimationAction > - used as prototypes
  27483. // actionByRoot: AnimationAction - lookup
  27484. // }
  27485. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27486. this._nActiveBindings = 0;
  27487. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27488. this._controlInterpolants = []; // same game as above
  27489. this._nActiveControlInterpolants = 0;
  27490. const scope = this;
  27491. this.stats = {
  27492. actions: {
  27493. get total() {
  27494. return scope._actions.length;
  27495. },
  27496. get inUse() {
  27497. return scope._nActiveActions;
  27498. }
  27499. },
  27500. bindings: {
  27501. get total() {
  27502. return scope._bindings.length;
  27503. },
  27504. get inUse() {
  27505. return scope._nActiveBindings;
  27506. }
  27507. },
  27508. controlInterpolants: {
  27509. get total() {
  27510. return scope._controlInterpolants.length;
  27511. },
  27512. get inUse() {
  27513. return scope._nActiveControlInterpolants;
  27514. }
  27515. }
  27516. };
  27517. },
  27518. // Memory management for AnimationAction objects
  27519. _isActiveAction: function ( action ) {
  27520. const index = action._cacheIndex;
  27521. return index !== null && index < this._nActiveActions;
  27522. },
  27523. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  27524. const actions = this._actions,
  27525. actionsByClip = this._actionsByClip;
  27526. let actionsForClip = actionsByClip[ clipUuid ];
  27527. if ( actionsForClip === undefined ) {
  27528. actionsForClip = {
  27529. knownActions: [ action ],
  27530. actionByRoot: {}
  27531. };
  27532. action._byClipCacheIndex = 0;
  27533. actionsByClip[ clipUuid ] = actionsForClip;
  27534. } else {
  27535. const knownActions = actionsForClip.knownActions;
  27536. action._byClipCacheIndex = knownActions.length;
  27537. knownActions.push( action );
  27538. }
  27539. action._cacheIndex = actions.length;
  27540. actions.push( action );
  27541. actionsForClip.actionByRoot[ rootUuid ] = action;
  27542. },
  27543. _removeInactiveAction: function ( action ) {
  27544. const actions = this._actions,
  27545. lastInactiveAction = actions[ actions.length - 1 ],
  27546. cacheIndex = action._cacheIndex;
  27547. lastInactiveAction._cacheIndex = cacheIndex;
  27548. actions[ cacheIndex ] = lastInactiveAction;
  27549. actions.pop();
  27550. action._cacheIndex = null;
  27551. const clipUuid = action._clip.uuid,
  27552. actionsByClip = this._actionsByClip,
  27553. actionsForClip = actionsByClip[ clipUuid ],
  27554. knownActionsForClip = actionsForClip.knownActions,
  27555. lastKnownAction =
  27556. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27557. byClipCacheIndex = action._byClipCacheIndex;
  27558. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27559. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27560. knownActionsForClip.pop();
  27561. action._byClipCacheIndex = null;
  27562. const actionByRoot = actionsForClip.actionByRoot,
  27563. rootUuid = ( action._localRoot || this._root ).uuid;
  27564. delete actionByRoot[ rootUuid ];
  27565. if ( knownActionsForClip.length === 0 ) {
  27566. delete actionsByClip[ clipUuid ];
  27567. }
  27568. this._removeInactiveBindingsForAction( action );
  27569. },
  27570. _removeInactiveBindingsForAction: function ( action ) {
  27571. const bindings = action._propertyBindings;
  27572. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27573. const binding = bindings[ i ];
  27574. if ( -- binding.referenceCount === 0 ) {
  27575. this._removeInactiveBinding( binding );
  27576. }
  27577. }
  27578. },
  27579. _lendAction: function ( action ) {
  27580. // [ active actions | inactive actions ]
  27581. // [ active actions >| inactive actions ]
  27582. // s a
  27583. // <-swap->
  27584. // a s
  27585. const actions = this._actions,
  27586. prevIndex = action._cacheIndex,
  27587. lastActiveIndex = this._nActiveActions ++,
  27588. firstInactiveAction = actions[ lastActiveIndex ];
  27589. action._cacheIndex = lastActiveIndex;
  27590. actions[ lastActiveIndex ] = action;
  27591. firstInactiveAction._cacheIndex = prevIndex;
  27592. actions[ prevIndex ] = firstInactiveAction;
  27593. },
  27594. _takeBackAction: function ( action ) {
  27595. // [ active actions | inactive actions ]
  27596. // [ active actions |< inactive actions ]
  27597. // a s
  27598. // <-swap->
  27599. // s a
  27600. const actions = this._actions,
  27601. prevIndex = action._cacheIndex,
  27602. firstInactiveIndex = -- this._nActiveActions,
  27603. lastActiveAction = actions[ firstInactiveIndex ];
  27604. action._cacheIndex = firstInactiveIndex;
  27605. actions[ firstInactiveIndex ] = action;
  27606. lastActiveAction._cacheIndex = prevIndex;
  27607. actions[ prevIndex ] = lastActiveAction;
  27608. },
  27609. // Memory management for PropertyMixer objects
  27610. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  27611. const bindingsByRoot = this._bindingsByRootAndName,
  27612. bindings = this._bindings;
  27613. let bindingByName = bindingsByRoot[ rootUuid ];
  27614. if ( bindingByName === undefined ) {
  27615. bindingByName = {};
  27616. bindingsByRoot[ rootUuid ] = bindingByName;
  27617. }
  27618. bindingByName[ trackName ] = binding;
  27619. binding._cacheIndex = bindings.length;
  27620. bindings.push( binding );
  27621. },
  27622. _removeInactiveBinding: function ( binding ) {
  27623. const bindings = this._bindings,
  27624. propBinding = binding.binding,
  27625. rootUuid = propBinding.rootNode.uuid,
  27626. trackName = propBinding.path,
  27627. bindingsByRoot = this._bindingsByRootAndName,
  27628. bindingByName = bindingsByRoot[ rootUuid ],
  27629. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27630. cacheIndex = binding._cacheIndex;
  27631. lastInactiveBinding._cacheIndex = cacheIndex;
  27632. bindings[ cacheIndex ] = lastInactiveBinding;
  27633. bindings.pop();
  27634. delete bindingByName[ trackName ];
  27635. if ( Object.keys( bindingByName ).length === 0 ) {
  27636. delete bindingsByRoot[ rootUuid ];
  27637. }
  27638. },
  27639. _lendBinding: function ( binding ) {
  27640. const bindings = this._bindings,
  27641. prevIndex = binding._cacheIndex,
  27642. lastActiveIndex = this._nActiveBindings ++,
  27643. firstInactiveBinding = bindings[ lastActiveIndex ];
  27644. binding._cacheIndex = lastActiveIndex;
  27645. bindings[ lastActiveIndex ] = binding;
  27646. firstInactiveBinding._cacheIndex = prevIndex;
  27647. bindings[ prevIndex ] = firstInactiveBinding;
  27648. },
  27649. _takeBackBinding: function ( binding ) {
  27650. const bindings = this._bindings,
  27651. prevIndex = binding._cacheIndex,
  27652. firstInactiveIndex = -- this._nActiveBindings,
  27653. lastActiveBinding = bindings[ firstInactiveIndex ];
  27654. binding._cacheIndex = firstInactiveIndex;
  27655. bindings[ firstInactiveIndex ] = binding;
  27656. lastActiveBinding._cacheIndex = prevIndex;
  27657. bindings[ prevIndex ] = lastActiveBinding;
  27658. },
  27659. // Memory management of Interpolants for weight and time scale
  27660. _lendControlInterpolant: function () {
  27661. const interpolants = this._controlInterpolants,
  27662. lastActiveIndex = this._nActiveControlInterpolants ++;
  27663. let interpolant = interpolants[ lastActiveIndex ];
  27664. if ( interpolant === undefined ) {
  27665. interpolant = new LinearInterpolant(
  27666. new Float32Array( 2 ), new Float32Array( 2 ),
  27667. 1, this._controlInterpolantsResultBuffer );
  27668. interpolant.__cacheIndex = lastActiveIndex;
  27669. interpolants[ lastActiveIndex ] = interpolant;
  27670. }
  27671. return interpolant;
  27672. },
  27673. _takeBackControlInterpolant: function ( interpolant ) {
  27674. const interpolants = this._controlInterpolants,
  27675. prevIndex = interpolant.__cacheIndex,
  27676. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27677. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27678. interpolant.__cacheIndex = firstInactiveIndex;
  27679. interpolants[ firstInactiveIndex ] = interpolant;
  27680. lastActiveInterpolant.__cacheIndex = prevIndex;
  27681. interpolants[ prevIndex ] = lastActiveInterpolant;
  27682. },
  27683. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  27684. // return an action for a clip optionally using a custom root target
  27685. // object (this method allocates a lot of dynamic memory in case a
  27686. // previously unknown clip/root combination is specified)
  27687. clipAction: function ( clip, optionalRoot, blendMode ) {
  27688. const root = optionalRoot || this._root,
  27689. rootUuid = root.uuid;
  27690. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  27691. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27692. let actionsForClip = this._actionsByClip[ clipUuid ],
  27693. prototypeAction = null;
  27694. if ( blendMode === undefined ) {
  27695. if ( clipObject !== null ) {
  27696. blendMode = clipObject.blendMode;
  27697. } else {
  27698. blendMode = NormalAnimationBlendMode;
  27699. }
  27700. }
  27701. if ( actionsForClip !== undefined ) {
  27702. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  27703. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  27704. return existingAction;
  27705. }
  27706. // we know the clip, so we don't have to parse all
  27707. // the bindings again but can just copy
  27708. prototypeAction = actionsForClip.knownActions[ 0 ];
  27709. // also, take the clip from the prototype action
  27710. if ( clipObject === null )
  27711. clipObject = prototypeAction._clip;
  27712. }
  27713. // clip must be known when specified via string
  27714. if ( clipObject === null ) return null;
  27715. // allocate all resources required to run it
  27716. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  27717. this._bindAction( newAction, prototypeAction );
  27718. // and make the action known to the memory manager
  27719. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27720. return newAction;
  27721. },
  27722. // get an existing action
  27723. existingAction: function ( clip, optionalRoot ) {
  27724. const root = optionalRoot || this._root,
  27725. rootUuid = root.uuid,
  27726. clipObject = typeof clip === 'string' ?
  27727. AnimationClip.findByName( root, clip ) : clip,
  27728. clipUuid = clipObject ? clipObject.uuid : clip,
  27729. actionsForClip = this._actionsByClip[ clipUuid ];
  27730. if ( actionsForClip !== undefined ) {
  27731. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27732. }
  27733. return null;
  27734. },
  27735. // deactivates all previously scheduled actions
  27736. stopAllAction: function () {
  27737. const actions = this._actions,
  27738. nActions = this._nActiveActions;
  27739. for ( let i = nActions - 1; i >= 0; -- i ) {
  27740. actions[ i ].stop();
  27741. }
  27742. return this;
  27743. },
  27744. // advance the time and update apply the animation
  27745. update: function ( deltaTime ) {
  27746. deltaTime *= this.timeScale;
  27747. const actions = this._actions,
  27748. nActions = this._nActiveActions,
  27749. time = this.time += deltaTime,
  27750. timeDirection = Math.sign( deltaTime ),
  27751. accuIndex = this._accuIndex ^= 1;
  27752. // run active actions
  27753. for ( let i = 0; i !== nActions; ++ i ) {
  27754. const action = actions[ i ];
  27755. action._update( time, deltaTime, timeDirection, accuIndex );
  27756. }
  27757. // update scene graph
  27758. const bindings = this._bindings,
  27759. nBindings = this._nActiveBindings;
  27760. for ( let i = 0; i !== nBindings; ++ i ) {
  27761. bindings[ i ].apply( accuIndex );
  27762. }
  27763. return this;
  27764. },
  27765. // Allows you to seek to a specific time in an animation.
  27766. setTime: function ( timeInSeconds ) {
  27767. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27768. for ( let i = 0; i < this._actions.length; i ++ ) {
  27769. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27770. }
  27771. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  27772. },
  27773. // return this mixer's root target object
  27774. getRoot: function () {
  27775. return this._root;
  27776. },
  27777. // free all resources specific to a particular clip
  27778. uncacheClip: function ( clip ) {
  27779. const actions = this._actions,
  27780. clipUuid = clip.uuid,
  27781. actionsByClip = this._actionsByClip,
  27782. actionsForClip = actionsByClip[ clipUuid ];
  27783. if ( actionsForClip !== undefined ) {
  27784. // note: just calling _removeInactiveAction would mess up the
  27785. // iteration state and also require updating the state we can
  27786. // just throw away
  27787. const actionsToRemove = actionsForClip.knownActions;
  27788. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27789. const action = actionsToRemove[ i ];
  27790. this._deactivateAction( action );
  27791. const cacheIndex = action._cacheIndex,
  27792. lastInactiveAction = actions[ actions.length - 1 ];
  27793. action._cacheIndex = null;
  27794. action._byClipCacheIndex = null;
  27795. lastInactiveAction._cacheIndex = cacheIndex;
  27796. actions[ cacheIndex ] = lastInactiveAction;
  27797. actions.pop();
  27798. this._removeInactiveBindingsForAction( action );
  27799. }
  27800. delete actionsByClip[ clipUuid ];
  27801. }
  27802. },
  27803. // free all resources specific to a particular root target object
  27804. uncacheRoot: function ( root ) {
  27805. const rootUuid = root.uuid,
  27806. actionsByClip = this._actionsByClip;
  27807. for ( const clipUuid in actionsByClip ) {
  27808. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27809. action = actionByRoot[ rootUuid ];
  27810. if ( action !== undefined ) {
  27811. this._deactivateAction( action );
  27812. this._removeInactiveAction( action );
  27813. }
  27814. }
  27815. const bindingsByRoot = this._bindingsByRootAndName,
  27816. bindingByName = bindingsByRoot[ rootUuid ];
  27817. if ( bindingByName !== undefined ) {
  27818. for ( const trackName in bindingByName ) {
  27819. const binding = bindingByName[ trackName ];
  27820. binding.restoreOriginalState();
  27821. this._removeInactiveBinding( binding );
  27822. }
  27823. }
  27824. },
  27825. // remove a targeted clip from the cache
  27826. uncacheAction: function ( clip, optionalRoot ) {
  27827. const action = this.existingAction( clip, optionalRoot );
  27828. if ( action !== null ) {
  27829. this._deactivateAction( action );
  27830. this._removeInactiveAction( action );
  27831. }
  27832. }
  27833. } );
  27834. /**
  27835. * @author mrdoob / http://mrdoob.com/
  27836. */
  27837. function Uniform( value ) {
  27838. if ( typeof value === 'string' ) {
  27839. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27840. value = arguments[ 1 ];
  27841. }
  27842. this.value = value;
  27843. }
  27844. Uniform.prototype.clone = function () {
  27845. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27846. };
  27847. /**
  27848. * @author benaadams / https://twitter.com/ben_a_adams
  27849. */
  27850. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27851. InterleavedBuffer.call( this, array, stride );
  27852. this.meshPerAttribute = meshPerAttribute || 1;
  27853. }
  27854. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27855. constructor: InstancedInterleavedBuffer,
  27856. isInstancedInterleavedBuffer: true,
  27857. copy: function ( source ) {
  27858. InterleavedBuffer.prototype.copy.call( this, source );
  27859. this.meshPerAttribute = source.meshPerAttribute;
  27860. return this;
  27861. },
  27862. clone: function ( data ) {
  27863. const ib = InterleavedBuffer.prototype.clone.call( this, data );
  27864. ib.meshPerAttribute = this.meshPerAttribute;
  27865. return ib;
  27866. },
  27867. toJSON: function ( data ) {
  27868. const json = InterleavedBuffer.prototype.toJSON.call( this, data );
  27869. json.isInstancedInterleavedBuffer = true;
  27870. json.meshPerAttribute = this.meshPerAttribute;
  27871. return json;
  27872. }
  27873. } );
  27874. /**
  27875. * @author mrdoob / http://mrdoob.com/
  27876. * @author bhouston / http://clara.io/
  27877. * @author stephomi / http://stephaneginier.com/
  27878. */
  27879. function Raycaster( origin, direction, near, far ) {
  27880. this.ray = new Ray( origin, direction );
  27881. // direction is assumed to be normalized (for accurate distance calculations)
  27882. this.near = near || 0;
  27883. this.far = far || Infinity;
  27884. this.camera = null;
  27885. this.layers = new Layers();
  27886. this.params = {
  27887. Mesh: {},
  27888. Line: { threshold: 1 },
  27889. LOD: {},
  27890. Points: { threshold: 1 },
  27891. Sprite: {}
  27892. };
  27893. Object.defineProperties( this.params, {
  27894. PointCloud: {
  27895. get: function () {
  27896. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27897. return this.Points;
  27898. }
  27899. }
  27900. } );
  27901. }
  27902. function ascSort( a, b ) {
  27903. return a.distance - b.distance;
  27904. }
  27905. function intersectObject( object, raycaster, intersects, recursive ) {
  27906. if ( object.layers.test( raycaster.layers ) ) {
  27907. object.raycast( raycaster, intersects );
  27908. }
  27909. if ( recursive === true ) {
  27910. const children = object.children;
  27911. for ( let i = 0, l = children.length; i < l; i ++ ) {
  27912. intersectObject( children[ i ], raycaster, intersects, true );
  27913. }
  27914. }
  27915. }
  27916. Object.assign( Raycaster.prototype, {
  27917. set: function ( origin, direction ) {
  27918. // direction is assumed to be normalized (for accurate distance calculations)
  27919. this.ray.set( origin, direction );
  27920. },
  27921. setFromCamera: function ( coords, camera ) {
  27922. if ( ( camera && camera.isPerspectiveCamera ) ) {
  27923. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27924. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27925. this.camera = camera;
  27926. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  27927. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27928. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27929. this.camera = camera;
  27930. } else {
  27931. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  27932. }
  27933. },
  27934. intersectObject: function ( object, recursive, optionalTarget ) {
  27935. const intersects = optionalTarget || [];
  27936. intersectObject( object, this, intersects, recursive );
  27937. intersects.sort( ascSort );
  27938. return intersects;
  27939. },
  27940. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27941. const intersects = optionalTarget || [];
  27942. if ( Array.isArray( objects ) === false ) {
  27943. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27944. return intersects;
  27945. }
  27946. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  27947. intersectObject( objects[ i ], this, intersects, recursive );
  27948. }
  27949. intersects.sort( ascSort );
  27950. return intersects;
  27951. }
  27952. } );
  27953. /**
  27954. * @author bhouston / http://clara.io
  27955. * @author WestLangley / http://github.com/WestLangley
  27956. *
  27957. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27958. *
  27959. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27960. * The azimuthal angle (theta) is measured from the positive z-axis.
  27961. */
  27962. function Spherical( radius, phi, theta ) {
  27963. this.radius = ( radius !== undefined ) ? radius : 1.0;
  27964. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  27965. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  27966. return this;
  27967. }
  27968. Object.assign( Spherical.prototype, {
  27969. set: function ( radius, phi, theta ) {
  27970. this.radius = radius;
  27971. this.phi = phi;
  27972. this.theta = theta;
  27973. return this;
  27974. },
  27975. clone: function () {
  27976. return new this.constructor().copy( this );
  27977. },
  27978. copy: function ( other ) {
  27979. this.radius = other.radius;
  27980. this.phi = other.phi;
  27981. this.theta = other.theta;
  27982. return this;
  27983. },
  27984. // restrict phi to be betwee EPS and PI-EPS
  27985. makeSafe: function () {
  27986. const EPS = 0.000001;
  27987. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27988. return this;
  27989. },
  27990. setFromVector3: function ( v ) {
  27991. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27992. },
  27993. setFromCartesianCoords: function ( x, y, z ) {
  27994. this.radius = Math.sqrt( x * x + y * y + z * z );
  27995. if ( this.radius === 0 ) {
  27996. this.theta = 0;
  27997. this.phi = 0;
  27998. } else {
  27999. this.theta = Math.atan2( x, z );
  28000. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  28001. }
  28002. return this;
  28003. }
  28004. } );
  28005. /**
  28006. * @author Mugen87 / https://github.com/Mugen87
  28007. *
  28008. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  28009. *
  28010. */
  28011. function Cylindrical( radius, theta, y ) {
  28012. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  28013. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  28014. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  28015. return this;
  28016. }
  28017. Object.assign( Cylindrical.prototype, {
  28018. set: function ( radius, theta, y ) {
  28019. this.radius = radius;
  28020. this.theta = theta;
  28021. this.y = y;
  28022. return this;
  28023. },
  28024. clone: function () {
  28025. return new this.constructor().copy( this );
  28026. },
  28027. copy: function ( other ) {
  28028. this.radius = other.radius;
  28029. this.theta = other.theta;
  28030. this.y = other.y;
  28031. return this;
  28032. },
  28033. setFromVector3: function ( v ) {
  28034. return this.setFromCartesianCoords( v.x, v.y, v.z );
  28035. },
  28036. setFromCartesianCoords: function ( x, y, z ) {
  28037. this.radius = Math.sqrt( x * x + z * z );
  28038. this.theta = Math.atan2( x, z );
  28039. this.y = y;
  28040. return this;
  28041. }
  28042. } );
  28043. /**
  28044. * @author bhouston / http://clara.io
  28045. */
  28046. const _vector$7 = new Vector2();
  28047. function Box2( min, max ) {
  28048. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  28049. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  28050. }
  28051. Object.assign( Box2.prototype, {
  28052. set: function ( min, max ) {
  28053. this.min.copy( min );
  28054. this.max.copy( max );
  28055. return this;
  28056. },
  28057. setFromPoints: function ( points ) {
  28058. this.makeEmpty();
  28059. for ( let i = 0, il = points.length; i < il; i ++ ) {
  28060. this.expandByPoint( points[ i ] );
  28061. }
  28062. return this;
  28063. },
  28064. setFromCenterAndSize: function ( center, size ) {
  28065. const halfSize = _vector$7.copy( size ).multiplyScalar( 0.5 );
  28066. this.min.copy( center ).sub( halfSize );
  28067. this.max.copy( center ).add( halfSize );
  28068. return this;
  28069. },
  28070. clone: function () {
  28071. return new this.constructor().copy( this );
  28072. },
  28073. copy: function ( box ) {
  28074. this.min.copy( box.min );
  28075. this.max.copy( box.max );
  28076. return this;
  28077. },
  28078. makeEmpty: function () {
  28079. this.min.x = this.min.y = + Infinity;
  28080. this.max.x = this.max.y = - Infinity;
  28081. return this;
  28082. },
  28083. isEmpty: function () {
  28084. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  28085. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  28086. },
  28087. getCenter: function ( target ) {
  28088. if ( target === undefined ) {
  28089. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  28090. target = new Vector2();
  28091. }
  28092. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  28093. },
  28094. getSize: function ( target ) {
  28095. if ( target === undefined ) {
  28096. console.warn( 'THREE.Box2: .getSize() target is now required' );
  28097. target = new Vector2();
  28098. }
  28099. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  28100. },
  28101. expandByPoint: function ( point ) {
  28102. this.min.min( point );
  28103. this.max.max( point );
  28104. return this;
  28105. },
  28106. expandByVector: function ( vector ) {
  28107. this.min.sub( vector );
  28108. this.max.add( vector );
  28109. return this;
  28110. },
  28111. expandByScalar: function ( scalar ) {
  28112. this.min.addScalar( - scalar );
  28113. this.max.addScalar( scalar );
  28114. return this;
  28115. },
  28116. containsPoint: function ( point ) {
  28117. return point.x < this.min.x || point.x > this.max.x ||
  28118. point.y < this.min.y || point.y > this.max.y ? false : true;
  28119. },
  28120. containsBox: function ( box ) {
  28121. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  28122. this.min.y <= box.min.y && box.max.y <= this.max.y;
  28123. },
  28124. getParameter: function ( point, target ) {
  28125. // This can potentially have a divide by zero if the box
  28126. // has a size dimension of 0.
  28127. if ( target === undefined ) {
  28128. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  28129. target = new Vector2();
  28130. }
  28131. return target.set(
  28132. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  28133. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  28134. );
  28135. },
  28136. intersectsBox: function ( box ) {
  28137. // using 4 splitting planes to rule out intersections
  28138. return box.max.x < this.min.x || box.min.x > this.max.x ||
  28139. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  28140. },
  28141. clampPoint: function ( point, target ) {
  28142. if ( target === undefined ) {
  28143. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  28144. target = new Vector2();
  28145. }
  28146. return target.copy( point ).clamp( this.min, this.max );
  28147. },
  28148. distanceToPoint: function ( point ) {
  28149. const clampedPoint = _vector$7.copy( point ).clamp( this.min, this.max );
  28150. return clampedPoint.sub( point ).length();
  28151. },
  28152. intersect: function ( box ) {
  28153. this.min.max( box.min );
  28154. this.max.min( box.max );
  28155. return this;
  28156. },
  28157. union: function ( box ) {
  28158. this.min.min( box.min );
  28159. this.max.max( box.max );
  28160. return this;
  28161. },
  28162. translate: function ( offset ) {
  28163. this.min.add( offset );
  28164. this.max.add( offset );
  28165. return this;
  28166. },
  28167. equals: function ( box ) {
  28168. return box.min.equals( this.min ) && box.max.equals( this.max );
  28169. }
  28170. } );
  28171. /**
  28172. * @author bhouston / http://clara.io
  28173. */
  28174. const _startP = new Vector3();
  28175. const _startEnd = new Vector3();
  28176. function Line3( start, end ) {
  28177. this.start = ( start !== undefined ) ? start : new Vector3();
  28178. this.end = ( end !== undefined ) ? end : new Vector3();
  28179. }
  28180. Object.assign( Line3.prototype, {
  28181. set: function ( start, end ) {
  28182. this.start.copy( start );
  28183. this.end.copy( end );
  28184. return this;
  28185. },
  28186. clone: function () {
  28187. return new this.constructor().copy( this );
  28188. },
  28189. copy: function ( line ) {
  28190. this.start.copy( line.start );
  28191. this.end.copy( line.end );
  28192. return this;
  28193. },
  28194. getCenter: function ( target ) {
  28195. if ( target === undefined ) {
  28196. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  28197. target = new Vector3();
  28198. }
  28199. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  28200. },
  28201. delta: function ( target ) {
  28202. if ( target === undefined ) {
  28203. console.warn( 'THREE.Line3: .delta() target is now required' );
  28204. target = new Vector3();
  28205. }
  28206. return target.subVectors( this.end, this.start );
  28207. },
  28208. distanceSq: function () {
  28209. return this.start.distanceToSquared( this.end );
  28210. },
  28211. distance: function () {
  28212. return this.start.distanceTo( this.end );
  28213. },
  28214. at: function ( t, target ) {
  28215. if ( target === undefined ) {
  28216. console.warn( 'THREE.Line3: .at() target is now required' );
  28217. target = new Vector3();
  28218. }
  28219. return this.delta( target ).multiplyScalar( t ).add( this.start );
  28220. },
  28221. closestPointToPointParameter: function ( point, clampToLine ) {
  28222. _startP.subVectors( point, this.start );
  28223. _startEnd.subVectors( this.end, this.start );
  28224. const startEnd2 = _startEnd.dot( _startEnd );
  28225. const startEnd_startP = _startEnd.dot( _startP );
  28226. let t = startEnd_startP / startEnd2;
  28227. if ( clampToLine ) {
  28228. t = MathUtils.clamp( t, 0, 1 );
  28229. }
  28230. return t;
  28231. },
  28232. closestPointToPoint: function ( point, clampToLine, target ) {
  28233. const t = this.closestPointToPointParameter( point, clampToLine );
  28234. if ( target === undefined ) {
  28235. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  28236. target = new Vector3();
  28237. }
  28238. return this.delta( target ).multiplyScalar( t ).add( this.start );
  28239. },
  28240. applyMatrix4: function ( matrix ) {
  28241. this.start.applyMatrix4( matrix );
  28242. this.end.applyMatrix4( matrix );
  28243. return this;
  28244. },
  28245. equals: function ( line ) {
  28246. return line.start.equals( this.start ) && line.end.equals( this.end );
  28247. }
  28248. } );
  28249. /**
  28250. * @author alteredq / http://alteredqualia.com/
  28251. */
  28252. function ImmediateRenderObject( material ) {
  28253. Object3D.call( this );
  28254. this.material = material;
  28255. this.render = function ( /* renderCallback */ ) {};
  28256. this.hasPositions = false;
  28257. this.hasNormals = false;
  28258. this.hasColors = false;
  28259. this.hasUvs = false;
  28260. this.positionArray = null;
  28261. this.normalArray = null;
  28262. this.colorArray = null;
  28263. this.uvArray = null;
  28264. this.count = 0;
  28265. }
  28266. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  28267. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28268. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28269. /**
  28270. * @author alteredq / http://alteredqualia.com/
  28271. * @author mrdoob / http://mrdoob.com/
  28272. * @author WestLangley / http://github.com/WestLangley
  28273. */
  28274. const _vector$8 = new Vector3();
  28275. function SpotLightHelper( light, color ) {
  28276. Object3D.call( this );
  28277. this.light = light;
  28278. this.light.updateMatrixWorld();
  28279. this.matrix = light.matrixWorld;
  28280. this.matrixAutoUpdate = false;
  28281. this.color = color;
  28282. const geometry = new BufferGeometry();
  28283. const positions = [
  28284. 0, 0, 0, 0, 0, 1,
  28285. 0, 0, 0, 1, 0, 1,
  28286. 0, 0, 0, - 1, 0, 1,
  28287. 0, 0, 0, 0, 1, 1,
  28288. 0, 0, 0, 0, - 1, 1
  28289. ];
  28290. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  28291. const p1 = ( i / l ) * Math.PI * 2;
  28292. const p2 = ( j / l ) * Math.PI * 2;
  28293. positions.push(
  28294. Math.cos( p1 ), Math.sin( p1 ), 1,
  28295. Math.cos( p2 ), Math.sin( p2 ), 1
  28296. );
  28297. }
  28298. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28299. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28300. this.cone = new LineSegments( geometry, material );
  28301. this.add( this.cone );
  28302. this.update();
  28303. }
  28304. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  28305. SpotLightHelper.prototype.constructor = SpotLightHelper;
  28306. SpotLightHelper.prototype.dispose = function () {
  28307. this.cone.geometry.dispose();
  28308. this.cone.material.dispose();
  28309. };
  28310. SpotLightHelper.prototype.update = function () {
  28311. this.light.updateMatrixWorld();
  28312. const coneLength = this.light.distance ? this.light.distance : 1000;
  28313. const coneWidth = coneLength * Math.tan( this.light.angle );
  28314. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  28315. _vector$8.setFromMatrixPosition( this.light.target.matrixWorld );
  28316. this.cone.lookAt( _vector$8 );
  28317. if ( this.color !== undefined ) {
  28318. this.cone.material.color.set( this.color );
  28319. } else {
  28320. this.cone.material.color.copy( this.light.color );
  28321. }
  28322. };
  28323. /**
  28324. * @author Sean Griffin / http://twitter.com/sgrif
  28325. * @author Michael Guerrero / http://realitymeltdown.com
  28326. * @author mrdoob / http://mrdoob.com/
  28327. * @author ikerr / http://verold.com
  28328. * @author Mugen87 / https://github.com/Mugen87
  28329. */
  28330. const _vector$9 = new Vector3();
  28331. const _boneMatrix = new Matrix4();
  28332. const _matrixWorldInv = new Matrix4();
  28333. function getBoneList( object ) {
  28334. const boneList = [];
  28335. if ( object && object.isBone ) {
  28336. boneList.push( object );
  28337. }
  28338. for ( let i = 0; i < object.children.length; i ++ ) {
  28339. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28340. }
  28341. return boneList;
  28342. }
  28343. function SkeletonHelper( object ) {
  28344. const bones = getBoneList( object );
  28345. const geometry = new BufferGeometry();
  28346. const vertices = [];
  28347. const colors = [];
  28348. const color1 = new Color( 0, 0, 1 );
  28349. const color2 = new Color( 0, 1, 0 );
  28350. for ( let i = 0; i < bones.length; i ++ ) {
  28351. const bone = bones[ i ];
  28352. if ( bone.parent && bone.parent.isBone ) {
  28353. vertices.push( 0, 0, 0 );
  28354. vertices.push( 0, 0, 0 );
  28355. colors.push( color1.r, color1.g, color1.b );
  28356. colors.push( color2.r, color2.g, color2.b );
  28357. }
  28358. }
  28359. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28360. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28361. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  28362. LineSegments.call( this, geometry, material );
  28363. this.type = 'SkeletonHelper';
  28364. this.root = object;
  28365. this.bones = bones;
  28366. this.matrix = object.matrixWorld;
  28367. this.matrixAutoUpdate = false;
  28368. }
  28369. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  28370. SkeletonHelper.prototype.constructor = SkeletonHelper;
  28371. SkeletonHelper.prototype.isSkeletonHelper = true;
  28372. SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
  28373. const bones = this.bones;
  28374. const geometry = this.geometry;
  28375. const position = geometry.getAttribute( 'position' );
  28376. _matrixWorldInv.getInverse( this.root.matrixWorld );
  28377. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  28378. const bone = bones[ i ];
  28379. if ( bone.parent && bone.parent.isBone ) {
  28380. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  28381. _vector$9.setFromMatrixPosition( _boneMatrix );
  28382. position.setXYZ( j, _vector$9.x, _vector$9.y, _vector$9.z );
  28383. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  28384. _vector$9.setFromMatrixPosition( _boneMatrix );
  28385. position.setXYZ( j + 1, _vector$9.x, _vector$9.y, _vector$9.z );
  28386. j += 2;
  28387. }
  28388. }
  28389. geometry.getAttribute( 'position' ).needsUpdate = true;
  28390. Object3D.prototype.updateMatrixWorld.call( this, force );
  28391. };
  28392. /**
  28393. * @author alteredq / http://alteredqualia.com/
  28394. * @author mrdoob / http://mrdoob.com/
  28395. */
  28396. function PointLightHelper( light, sphereSize, color ) {
  28397. this.light = light;
  28398. this.light.updateMatrixWorld();
  28399. this.color = color;
  28400. const geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  28401. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28402. Mesh.call( this, geometry, material );
  28403. this.type = 'PointLightHelper';
  28404. this.matrix = this.light.matrixWorld;
  28405. this.matrixAutoUpdate = false;
  28406. this.update();
  28407. /*
  28408. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28409. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28410. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28411. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28412. const d = light.distance;
  28413. if ( d === 0.0 ) {
  28414. this.lightDistance.visible = false;
  28415. } else {
  28416. this.lightDistance.scale.set( d, d, d );
  28417. }
  28418. this.add( this.lightDistance );
  28419. */
  28420. }
  28421. PointLightHelper.prototype = Object.create( Mesh.prototype );
  28422. PointLightHelper.prototype.constructor = PointLightHelper;
  28423. PointLightHelper.prototype.dispose = function () {
  28424. this.geometry.dispose();
  28425. this.material.dispose();
  28426. };
  28427. PointLightHelper.prototype.update = function () {
  28428. if ( this.color !== undefined ) {
  28429. this.material.color.set( this.color );
  28430. } else {
  28431. this.material.color.copy( this.light.color );
  28432. }
  28433. /*
  28434. const d = this.light.distance;
  28435. if ( d === 0.0 ) {
  28436. this.lightDistance.visible = false;
  28437. } else {
  28438. this.lightDistance.visible = true;
  28439. this.lightDistance.scale.set( d, d, d );
  28440. }
  28441. */
  28442. };
  28443. /**
  28444. * @author alteredq / http://alteredqualia.com/
  28445. * @author mrdoob / http://mrdoob.com/
  28446. * @author Mugen87 / https://github.com/Mugen87
  28447. */
  28448. const _vector$a = new Vector3();
  28449. const _color1 = new Color();
  28450. const _color2 = new Color();
  28451. function HemisphereLightHelper( light, size, color ) {
  28452. Object3D.call( this );
  28453. this.light = light;
  28454. this.light.updateMatrixWorld();
  28455. this.matrix = light.matrixWorld;
  28456. this.matrixAutoUpdate = false;
  28457. this.color = color;
  28458. const geometry = new OctahedronBufferGeometry( size );
  28459. geometry.rotateY( Math.PI * 0.5 );
  28460. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28461. if ( this.color === undefined ) this.material.vertexColors = true;
  28462. const position = geometry.getAttribute( 'position' );
  28463. const colors = new Float32Array( position.count * 3 );
  28464. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28465. this.add( new Mesh( geometry, this.material ) );
  28466. this.update();
  28467. }
  28468. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  28469. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  28470. HemisphereLightHelper.prototype.dispose = function () {
  28471. this.children[ 0 ].geometry.dispose();
  28472. this.children[ 0 ].material.dispose();
  28473. };
  28474. HemisphereLightHelper.prototype.update = function () {
  28475. const mesh = this.children[ 0 ];
  28476. if ( this.color !== undefined ) {
  28477. this.material.color.set( this.color );
  28478. } else {
  28479. const colors = mesh.geometry.getAttribute( 'color' );
  28480. _color1.copy( this.light.color );
  28481. _color2.copy( this.light.groundColor );
  28482. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  28483. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  28484. colors.setXYZ( i, color.r, color.g, color.b );
  28485. }
  28486. colors.needsUpdate = true;
  28487. }
  28488. mesh.lookAt( _vector$a.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28489. };
  28490. /**
  28491. * @author mrdoob / http://mrdoob.com/
  28492. */
  28493. function GridHelper( size, divisions, color1, color2 ) {
  28494. size = size || 10;
  28495. divisions = divisions || 10;
  28496. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28497. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28498. const center = divisions / 2;
  28499. const step = size / divisions;
  28500. const halfSize = size / 2;
  28501. const vertices = [], colors = [];
  28502. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28503. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28504. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28505. const color = i === center ? color1 : color2;
  28506. color.toArray( colors, j ); j += 3;
  28507. color.toArray( colors, j ); j += 3;
  28508. color.toArray( colors, j ); j += 3;
  28509. color.toArray( colors, j ); j += 3;
  28510. }
  28511. const geometry = new BufferGeometry();
  28512. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28513. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28514. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28515. LineSegments.call( this, geometry, material );
  28516. this.type = 'GridHelper';
  28517. }
  28518. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  28519. constructor: GridHelper,
  28520. copy: function ( source ) {
  28521. LineSegments.prototype.copy.call( this, source );
  28522. this.geometry.copy( source.geometry );
  28523. this.material.copy( source.material );
  28524. return this;
  28525. },
  28526. clone: function () {
  28527. return new this.constructor().copy( this );
  28528. }
  28529. } );
  28530. /**
  28531. * @author mrdoob / http://mrdoob.com/
  28532. * @author Mugen87 / http://github.com/Mugen87
  28533. * @author Hectate / http://www.github.com/Hectate
  28534. */
  28535. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  28536. radius = radius || 10;
  28537. radials = radials || 16;
  28538. circles = circles || 8;
  28539. divisions = divisions || 64;
  28540. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  28541. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  28542. const vertices = [];
  28543. const colors = [];
  28544. // create the radials
  28545. for ( let i = 0; i <= radials; i ++ ) {
  28546. const v = ( i / radials ) * ( Math.PI * 2 );
  28547. const x = Math.sin( v ) * radius;
  28548. const z = Math.cos( v ) * radius;
  28549. vertices.push( 0, 0, 0 );
  28550. vertices.push( x, 0, z );
  28551. const color = ( i & 1 ) ? color1 : color2;
  28552. colors.push( color.r, color.g, color.b );
  28553. colors.push( color.r, color.g, color.b );
  28554. }
  28555. // create the circles
  28556. for ( let i = 0; i <= circles; i ++ ) {
  28557. const color = ( i & 1 ) ? color1 : color2;
  28558. const r = radius - ( radius / circles * i );
  28559. for ( let j = 0; j < divisions; j ++ ) {
  28560. // first vertex
  28561. let v = ( j / divisions ) * ( Math.PI * 2 );
  28562. let x = Math.sin( v ) * r;
  28563. let z = Math.cos( v ) * r;
  28564. vertices.push( x, 0, z );
  28565. colors.push( color.r, color.g, color.b );
  28566. // second vertex
  28567. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28568. x = Math.sin( v ) * r;
  28569. z = Math.cos( v ) * r;
  28570. vertices.push( x, 0, z );
  28571. colors.push( color.r, color.g, color.b );
  28572. }
  28573. }
  28574. const geometry = new BufferGeometry();
  28575. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28576. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28577. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28578. LineSegments.call( this, geometry, material );
  28579. this.type = 'PolarGridHelper';
  28580. }
  28581. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  28582. PolarGridHelper.prototype.constructor = PolarGridHelper;
  28583. /**
  28584. * @author alteredq / http://alteredqualia.com/
  28585. * @author mrdoob / http://mrdoob.com/
  28586. * @author WestLangley / http://github.com/WestLangley
  28587. */
  28588. const _v1$5 = new Vector3();
  28589. const _v2$3 = new Vector3();
  28590. const _v3$1 = new Vector3();
  28591. function DirectionalLightHelper( light, size, color ) {
  28592. Object3D.call( this );
  28593. this.light = light;
  28594. this.light.updateMatrixWorld();
  28595. this.matrix = light.matrixWorld;
  28596. this.matrixAutoUpdate = false;
  28597. this.color = color;
  28598. if ( size === undefined ) size = 1;
  28599. let geometry = new BufferGeometry();
  28600. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28601. - size, size, 0,
  28602. size, size, 0,
  28603. size, - size, 0,
  28604. - size, - size, 0,
  28605. - size, size, 0
  28606. ], 3 ) );
  28607. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28608. this.lightPlane = new Line( geometry, material );
  28609. this.add( this.lightPlane );
  28610. geometry = new BufferGeometry();
  28611. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28612. this.targetLine = new Line( geometry, material );
  28613. this.add( this.targetLine );
  28614. this.update();
  28615. }
  28616. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  28617. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  28618. DirectionalLightHelper.prototype.dispose = function () {
  28619. this.lightPlane.geometry.dispose();
  28620. this.lightPlane.material.dispose();
  28621. this.targetLine.geometry.dispose();
  28622. this.targetLine.material.dispose();
  28623. };
  28624. DirectionalLightHelper.prototype.update = function () {
  28625. _v1$5.setFromMatrixPosition( this.light.matrixWorld );
  28626. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  28627. _v3$1.subVectors( _v2$3, _v1$5 );
  28628. this.lightPlane.lookAt( _v2$3 );
  28629. if ( this.color !== undefined ) {
  28630. this.lightPlane.material.color.set( this.color );
  28631. this.targetLine.material.color.set( this.color );
  28632. } else {
  28633. this.lightPlane.material.color.copy( this.light.color );
  28634. this.targetLine.material.color.copy( this.light.color );
  28635. }
  28636. this.targetLine.lookAt( _v2$3 );
  28637. this.targetLine.scale.z = _v3$1.length();
  28638. };
  28639. /**
  28640. * @author alteredq / http://alteredqualia.com/
  28641. * @author Mugen87 / https://github.com/Mugen87
  28642. *
  28643. * - shows frustum, line of sight and up of the camera
  28644. * - suitable for fast updates
  28645. * - based on frustum visualization in lightgl.js shadowmap example
  28646. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28647. */
  28648. const _vector$b = new Vector3();
  28649. const _camera = new Camera();
  28650. function CameraHelper( camera ) {
  28651. const geometry = new BufferGeometry();
  28652. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  28653. const vertices = [];
  28654. const colors = [];
  28655. const pointMap = {};
  28656. // colors
  28657. const colorFrustum = new Color( 0xffaa00 );
  28658. const colorCone = new Color( 0xff0000 );
  28659. const colorUp = new Color( 0x00aaff );
  28660. const colorTarget = new Color( 0xffffff );
  28661. const colorCross = new Color( 0x333333 );
  28662. // near
  28663. addLine( 'n1', 'n2', colorFrustum );
  28664. addLine( 'n2', 'n4', colorFrustum );
  28665. addLine( 'n4', 'n3', colorFrustum );
  28666. addLine( 'n3', 'n1', colorFrustum );
  28667. // far
  28668. addLine( 'f1', 'f2', colorFrustum );
  28669. addLine( 'f2', 'f4', colorFrustum );
  28670. addLine( 'f4', 'f3', colorFrustum );
  28671. addLine( 'f3', 'f1', colorFrustum );
  28672. // sides
  28673. addLine( 'n1', 'f1', colorFrustum );
  28674. addLine( 'n2', 'f2', colorFrustum );
  28675. addLine( 'n3', 'f3', colorFrustum );
  28676. addLine( 'n4', 'f4', colorFrustum );
  28677. // cone
  28678. addLine( 'p', 'n1', colorCone );
  28679. addLine( 'p', 'n2', colorCone );
  28680. addLine( 'p', 'n3', colorCone );
  28681. addLine( 'p', 'n4', colorCone );
  28682. // up
  28683. addLine( 'u1', 'u2', colorUp );
  28684. addLine( 'u2', 'u3', colorUp );
  28685. addLine( 'u3', 'u1', colorUp );
  28686. // target
  28687. addLine( 'c', 't', colorTarget );
  28688. addLine( 'p', 'c', colorCross );
  28689. // cross
  28690. addLine( 'cn1', 'cn2', colorCross );
  28691. addLine( 'cn3', 'cn4', colorCross );
  28692. addLine( 'cf1', 'cf2', colorCross );
  28693. addLine( 'cf3', 'cf4', colorCross );
  28694. function addLine( a, b, color ) {
  28695. addPoint( a, color );
  28696. addPoint( b, color );
  28697. }
  28698. function addPoint( id, color ) {
  28699. vertices.push( 0, 0, 0 );
  28700. colors.push( color.r, color.g, color.b );
  28701. if ( pointMap[ id ] === undefined ) {
  28702. pointMap[ id ] = [];
  28703. }
  28704. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28705. }
  28706. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28707. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28708. LineSegments.call( this, geometry, material );
  28709. this.type = 'CameraHelper';
  28710. this.camera = camera;
  28711. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28712. this.matrix = camera.matrixWorld;
  28713. this.matrixAutoUpdate = false;
  28714. this.pointMap = pointMap;
  28715. this.update();
  28716. }
  28717. CameraHelper.prototype = Object.create( LineSegments.prototype );
  28718. CameraHelper.prototype.constructor = CameraHelper;
  28719. CameraHelper.prototype.update = function () {
  28720. const geometry = this.geometry;
  28721. const pointMap = this.pointMap;
  28722. const w = 1, h = 1;
  28723. // we need just camera projection matrix inverse
  28724. // world matrix must be identity
  28725. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28726. // center / target
  28727. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28728. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28729. // near
  28730. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28731. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28732. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28733. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28734. // far
  28735. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28736. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28737. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28738. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28739. // up
  28740. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28741. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28742. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28743. // cross
  28744. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28745. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28746. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28747. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28748. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28749. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28750. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28751. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28752. geometry.getAttribute( 'position' ).needsUpdate = true;
  28753. };
  28754. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28755. _vector$b.set( x, y, z ).unproject( camera );
  28756. const points = pointMap[ point ];
  28757. if ( points !== undefined ) {
  28758. const position = geometry.getAttribute( 'position' );
  28759. for ( let i = 0, l = points.length; i < l; i ++ ) {
  28760. position.setXYZ( points[ i ], _vector$b.x, _vector$b.y, _vector$b.z );
  28761. }
  28762. }
  28763. }
  28764. /**
  28765. * @author mrdoob / http://mrdoob.com/
  28766. * @author Mugen87 / http://github.com/Mugen87
  28767. */
  28768. const _box$3 = new Box3();
  28769. function BoxHelper( object, color ) {
  28770. this.object = object;
  28771. if ( color === undefined ) color = 0xffff00;
  28772. 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 ] );
  28773. const positions = new Float32Array( 8 * 3 );
  28774. const geometry = new BufferGeometry();
  28775. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28776. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28777. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28778. this.type = 'BoxHelper';
  28779. this.matrixAutoUpdate = false;
  28780. this.update();
  28781. }
  28782. BoxHelper.prototype = Object.create( LineSegments.prototype );
  28783. BoxHelper.prototype.constructor = BoxHelper;
  28784. BoxHelper.prototype.update = function ( object ) {
  28785. if ( object !== undefined ) {
  28786. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28787. }
  28788. if ( this.object !== undefined ) {
  28789. _box$3.setFromObject( this.object );
  28790. }
  28791. if ( _box$3.isEmpty() ) return;
  28792. const min = _box$3.min;
  28793. const max = _box$3.max;
  28794. /*
  28795. 5____4
  28796. 1/___0/|
  28797. | 6__|_7
  28798. 2/___3/
  28799. 0: max.x, max.y, max.z
  28800. 1: min.x, max.y, max.z
  28801. 2: min.x, min.y, max.z
  28802. 3: max.x, min.y, max.z
  28803. 4: max.x, max.y, min.z
  28804. 5: min.x, max.y, min.z
  28805. 6: min.x, min.y, min.z
  28806. 7: max.x, min.y, min.z
  28807. */
  28808. const position = this.geometry.attributes.position;
  28809. const array = position.array;
  28810. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28811. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28812. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28813. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28814. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28815. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28816. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28817. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28818. position.needsUpdate = true;
  28819. this.geometry.computeBoundingSphere();
  28820. };
  28821. BoxHelper.prototype.setFromObject = function ( object ) {
  28822. this.object = object;
  28823. this.update();
  28824. return this;
  28825. };
  28826. BoxHelper.prototype.copy = function ( source ) {
  28827. LineSegments.prototype.copy.call( this, source );
  28828. this.object = source.object;
  28829. return this;
  28830. };
  28831. BoxHelper.prototype.clone = function () {
  28832. return new this.constructor().copy( this );
  28833. };
  28834. /**
  28835. * @author WestLangley / http://github.com/WestLangley
  28836. */
  28837. function Box3Helper( box, color ) {
  28838. this.type = 'Box3Helper';
  28839. this.box = box;
  28840. color = color || 0xffff00;
  28841. 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 ] );
  28842. 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 ];
  28843. const geometry = new BufferGeometry();
  28844. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28845. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28846. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28847. this.type = 'Box3Helper';
  28848. this.geometry.computeBoundingSphere();
  28849. }
  28850. Box3Helper.prototype = Object.create( LineSegments.prototype );
  28851. Box3Helper.prototype.constructor = Box3Helper;
  28852. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  28853. const box = this.box;
  28854. if ( box.isEmpty() ) return;
  28855. box.getCenter( this.position );
  28856. box.getSize( this.scale );
  28857. this.scale.multiplyScalar( 0.5 );
  28858. Object3D.prototype.updateMatrixWorld.call( this, force );
  28859. };
  28860. /**
  28861. * @author WestLangley / http://github.com/WestLangley
  28862. */
  28863. function PlaneHelper( plane, size, hex ) {
  28864. this.plane = plane;
  28865. this.size = ( size === undefined ) ? 1 : size;
  28866. const color = ( hex !== undefined ) ? hex : 0xffff00;
  28867. 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 ];
  28868. const geometry = new BufferGeometry();
  28869. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28870. geometry.computeBoundingSphere();
  28871. Line.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28872. this.type = 'PlaneHelper';
  28873. //
  28874. const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28875. const geometry2 = new BufferGeometry();
  28876. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28877. geometry2.computeBoundingSphere();
  28878. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28879. }
  28880. PlaneHelper.prototype = Object.create( Line.prototype );
  28881. PlaneHelper.prototype.constructor = PlaneHelper;
  28882. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  28883. let scale = - this.plane.constant;
  28884. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28885. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28886. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28887. this.lookAt( this.plane.normal );
  28888. Object3D.prototype.updateMatrixWorld.call( this, force );
  28889. };
  28890. /**
  28891. * @author WestLangley / http://github.com/WestLangley
  28892. * @author zz85 / http://github.com/zz85
  28893. * @author bhouston / http://clara.io
  28894. *
  28895. * Creates an arrow for visualizing directions
  28896. *
  28897. * Parameters:
  28898. * dir - Vector3
  28899. * origin - Vector3
  28900. * length - Number
  28901. * color - color in hex value
  28902. * headLength - Number
  28903. * headWidth - Number
  28904. */
  28905. const _axis = new Vector3();
  28906. let _lineGeometry, _coneGeometry;
  28907. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  28908. // dir is assumed to be normalized
  28909. Object3D.call( this );
  28910. this.type = 'ArrowHelper';
  28911. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28912. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28913. if ( length === undefined ) length = 1;
  28914. if ( color === undefined ) color = 0xffff00;
  28915. if ( headLength === undefined ) headLength = 0.2 * length;
  28916. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28917. if ( _lineGeometry === undefined ) {
  28918. _lineGeometry = new BufferGeometry();
  28919. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28920. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28921. _coneGeometry.translate( 0, - 0.5, 0 );
  28922. }
  28923. this.position.copy( origin );
  28924. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28925. this.line.matrixAutoUpdate = false;
  28926. this.add( this.line );
  28927. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28928. this.cone.matrixAutoUpdate = false;
  28929. this.add( this.cone );
  28930. this.setDirection( dir );
  28931. this.setLength( length, headLength, headWidth );
  28932. }
  28933. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28934. ArrowHelper.prototype.constructor = ArrowHelper;
  28935. ArrowHelper.prototype.setDirection = function ( dir ) {
  28936. // dir is assumed to be normalized
  28937. if ( dir.y > 0.99999 ) {
  28938. this.quaternion.set( 0, 0, 0, 1 );
  28939. } else if ( dir.y < - 0.99999 ) {
  28940. this.quaternion.set( 1, 0, 0, 0 );
  28941. } else {
  28942. _axis.set( dir.z, 0, - dir.x ).normalize();
  28943. const radians = Math.acos( dir.y );
  28944. this.quaternion.setFromAxisAngle( _axis, radians );
  28945. }
  28946. };
  28947. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28948. if ( headLength === undefined ) headLength = 0.2 * length;
  28949. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28950. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28951. this.line.updateMatrix();
  28952. this.cone.scale.set( headWidth, headLength, headWidth );
  28953. this.cone.position.y = length;
  28954. this.cone.updateMatrix();
  28955. };
  28956. ArrowHelper.prototype.setColor = function ( color ) {
  28957. this.line.material.color.set( color );
  28958. this.cone.material.color.set( color );
  28959. };
  28960. ArrowHelper.prototype.copy = function ( source ) {
  28961. Object3D.prototype.copy.call( this, source, false );
  28962. this.line.copy( source.line );
  28963. this.cone.copy( source.cone );
  28964. return this;
  28965. };
  28966. ArrowHelper.prototype.clone = function () {
  28967. return new this.constructor().copy( this );
  28968. };
  28969. /**
  28970. * @author sroucheray / http://sroucheray.org/
  28971. * @author mrdoob / http://mrdoob.com/
  28972. */
  28973. function AxesHelper( size ) {
  28974. size = size || 1;
  28975. const vertices = [
  28976. 0, 0, 0, size, 0, 0,
  28977. 0, 0, 0, 0, size, 0,
  28978. 0, 0, 0, 0, 0, size
  28979. ];
  28980. const colors = [
  28981. 1, 0, 0, 1, 0.6, 0,
  28982. 0, 1, 0, 0.6, 1, 0,
  28983. 0, 0, 1, 0, 0.6, 1
  28984. ];
  28985. const geometry = new BufferGeometry();
  28986. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28987. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28988. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28989. LineSegments.call( this, geometry, material );
  28990. this.type = 'AxesHelper';
  28991. }
  28992. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28993. AxesHelper.prototype.constructor = AxesHelper;
  28994. /**
  28995. * @author Emmett Lalish / elalish
  28996. *
  28997. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28998. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28999. * blur to be quickly accessed based on material roughness. It is packed into a
  29000. * special CubeUV format that allows us to perform custom interpolation so that
  29001. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  29002. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  29003. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  29004. * higher roughness levels. In this way we maintain resolution to smoothly
  29005. * interpolate diffuse lighting while limiting sampling computation.
  29006. */
  29007. const LOD_MIN = 4;
  29008. const LOD_MAX = 8;
  29009. const SIZE_MAX = Math.pow( 2, LOD_MAX );
  29010. // The standard deviations (radians) associated with the extra mips. These are
  29011. // chosen to approximate a Trowbridge-Reitz distribution function times the
  29012. // geometric shadowing function. These sigma values squared must match the
  29013. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  29014. const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  29015. const TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  29016. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  29017. // samples and exit early, but not recompile the shader.
  29018. const MAX_SAMPLES = 20;
  29019. const ENCODINGS = {
  29020. [ LinearEncoding ]: 0,
  29021. [ sRGBEncoding ]: 1,
  29022. [ RGBEEncoding ]: 2,
  29023. [ RGBM7Encoding ]: 3,
  29024. [ RGBM16Encoding ]: 4,
  29025. [ RGBDEncoding ]: 5,
  29026. [ GammaEncoding ]: 6
  29027. };
  29028. const _flatCamera = new OrthographicCamera();
  29029. const { _lodPlanes, _sizeLods, _sigmas } = _createPlanes();
  29030. let _oldTarget = null;
  29031. // Golden Ratio
  29032. const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  29033. const INV_PHI = 1 / PHI;
  29034. // Vertices of a dodecahedron (except the opposites, which represent the
  29035. // same axis), used as axis directions evenly spread on a sphere.
  29036. const _axisDirections = [
  29037. new Vector3( 1, 1, 1 ),
  29038. new Vector3( - 1, 1, 1 ),
  29039. new Vector3( 1, 1, - 1 ),
  29040. new Vector3( - 1, 1, - 1 ),
  29041. new Vector3( 0, PHI, INV_PHI ),
  29042. new Vector3( 0, PHI, - INV_PHI ),
  29043. new Vector3( INV_PHI, 0, PHI ),
  29044. new Vector3( - INV_PHI, 0, PHI ),
  29045. new Vector3( PHI, INV_PHI, 0 ),
  29046. new Vector3( - PHI, INV_PHI, 0 ) ];
  29047. function PMREMGenerator( renderer ) {
  29048. this._renderer = renderer;
  29049. this._pingPongRenderTarget = null;
  29050. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  29051. this._equirectShader = null;
  29052. this._cubemapShader = null;
  29053. this._compileMaterial( this._blurMaterial );
  29054. }
  29055. PMREMGenerator.prototype = {
  29056. constructor: PMREMGenerator,
  29057. /**
  29058. * Generates a PMREM from a supplied Scene, which can be faster than using an
  29059. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  29060. * in radians to be applied to the scene before PMREM generation. Optional near
  29061. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  29062. * is placed at the origin).
  29063. */
  29064. fromScene: function ( scene, sigma = 0, near = 0.1, far = 100 ) {
  29065. _oldTarget = this._renderer.getRenderTarget();
  29066. const cubeUVRenderTarget = this._allocateTargets();
  29067. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  29068. if ( sigma > 0 ) {
  29069. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  29070. }
  29071. this._applyPMREM( cubeUVRenderTarget );
  29072. this._cleanup( cubeUVRenderTarget );
  29073. return cubeUVRenderTarget;
  29074. },
  29075. /**
  29076. * Generates a PMREM from an equirectangular texture, which can be either LDR
  29077. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  29078. * as this matches best with the 256 x 256 cubemap output.
  29079. */
  29080. fromEquirectangular: function ( equirectangular ) {
  29081. return this._fromTexture( equirectangular );
  29082. },
  29083. /**
  29084. * Generates a PMREM from an cubemap texture, which can be either LDR
  29085. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  29086. * as this matches best with the 256 x 256 cubemap output.
  29087. */
  29088. fromCubemap: function ( cubemap ) {
  29089. return this._fromTexture( cubemap );
  29090. },
  29091. /**
  29092. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  29093. * your texture's network fetch for increased concurrency.
  29094. */
  29095. compileCubemapShader: function () {
  29096. if ( this._cubemapShader === null ) {
  29097. this._cubemapShader = _getCubemapShader();
  29098. this._compileMaterial( this._cubemapShader );
  29099. }
  29100. },
  29101. /**
  29102. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  29103. * your texture's network fetch for increased concurrency.
  29104. */
  29105. compileEquirectangularShader: function () {
  29106. if ( this._equirectShader === null ) {
  29107. this._equirectShader = _getEquirectShader();
  29108. this._compileMaterial( this._equirectShader );
  29109. }
  29110. },
  29111. /**
  29112. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29113. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29114. * one of them will cause any others to also become unusable.
  29115. */
  29116. dispose: function () {
  29117. this._blurMaterial.dispose();
  29118. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  29119. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  29120. for ( let i = 0; i < _lodPlanes.length; i ++ ) {
  29121. _lodPlanes[ i ].dispose();
  29122. }
  29123. },
  29124. // private interface
  29125. _cleanup: function ( outputTarget ) {
  29126. this._pingPongRenderTarget.dispose();
  29127. this._renderer.setRenderTarget( _oldTarget );
  29128. outputTarget.scissorTest = false;
  29129. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  29130. },
  29131. _fromTexture: function ( texture ) {
  29132. _oldTarget = this._renderer.getRenderTarget();
  29133. const cubeUVRenderTarget = this._allocateTargets( texture );
  29134. this._textureToCubeUV( texture, cubeUVRenderTarget );
  29135. this._applyPMREM( cubeUVRenderTarget );
  29136. this._cleanup( cubeUVRenderTarget );
  29137. return cubeUVRenderTarget;
  29138. },
  29139. _allocateTargets: function ( texture ) { // warning: null texture is valid
  29140. const params = {
  29141. magFilter: NearestFilter,
  29142. minFilter: NearestFilter,
  29143. generateMipmaps: false,
  29144. type: UnsignedByteType,
  29145. format: RGBEFormat,
  29146. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  29147. depthBuffer: false,
  29148. stencilBuffer: false
  29149. };
  29150. const cubeUVRenderTarget = _createRenderTarget( params );
  29151. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29152. this._pingPongRenderTarget = _createRenderTarget( params );
  29153. return cubeUVRenderTarget;
  29154. },
  29155. _compileMaterial: function ( material ) {
  29156. const tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  29157. this._renderer.compile( tmpMesh, _flatCamera );
  29158. },
  29159. _sceneToCubeUV: function ( scene, near, far, cubeUVRenderTarget ) {
  29160. const fov = 90;
  29161. const aspect = 1;
  29162. const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  29163. const upSign = [ 1, - 1, 1, 1, 1, 1 ];
  29164. const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  29165. const renderer = this._renderer;
  29166. const outputEncoding = renderer.outputEncoding;
  29167. const toneMapping = renderer.toneMapping;
  29168. const clearColor = renderer.getClearColor();
  29169. const clearAlpha = renderer.getClearAlpha();
  29170. renderer.toneMapping = NoToneMapping;
  29171. renderer.outputEncoding = LinearEncoding;
  29172. let background = scene.background;
  29173. if ( background && background.isColor ) {
  29174. background.convertSRGBToLinear();
  29175. // Convert linear to RGBE
  29176. const maxComponent = Math.max( background.r, background.g, background.b );
  29177. const fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  29178. background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
  29179. const alpha = ( fExp + 128.0 ) / 255.0;
  29180. renderer.setClearColor( background, alpha );
  29181. scene.background = null;
  29182. }
  29183. for ( let i = 0; i < 6; i ++ ) {
  29184. const col = i % 3;
  29185. if ( col == 0 ) {
  29186. cubeCamera.up.set( 0, upSign[ i ], 0 );
  29187. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  29188. } else if ( col == 1 ) {
  29189. cubeCamera.up.set( 0, 0, upSign[ i ] );
  29190. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  29191. } else {
  29192. cubeCamera.up.set( 0, upSign[ i ], 0 );
  29193. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  29194. }
  29195. _setViewport( cubeUVRenderTarget,
  29196. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  29197. renderer.setRenderTarget( cubeUVRenderTarget );
  29198. renderer.render( scene, cubeCamera );
  29199. }
  29200. renderer.toneMapping = toneMapping;
  29201. renderer.outputEncoding = outputEncoding;
  29202. renderer.setClearColor( clearColor, clearAlpha );
  29203. },
  29204. _textureToCubeUV: function ( texture, cubeUVRenderTarget ) {
  29205. const renderer = this._renderer;
  29206. if ( texture.isCubeTexture ) {
  29207. if ( this._cubemapShader == null ) {
  29208. this._cubemapShader = _getCubemapShader();
  29209. }
  29210. } else {
  29211. if ( this._equirectShader == null ) {
  29212. this._equirectShader = _getEquirectShader();
  29213. }
  29214. }
  29215. const material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29216. const mesh = new Mesh( _lodPlanes[ 0 ], material );
  29217. const uniforms = material.uniforms;
  29218. uniforms[ 'envMap' ].value = texture;
  29219. if ( ! texture.isCubeTexture ) {
  29220. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  29221. }
  29222. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  29223. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  29224. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  29225. renderer.setRenderTarget( cubeUVRenderTarget );
  29226. renderer.render( mesh, _flatCamera );
  29227. },
  29228. _applyPMREM: function ( cubeUVRenderTarget ) {
  29229. const renderer = this._renderer;
  29230. const autoClear = renderer.autoClear;
  29231. renderer.autoClear = false;
  29232. for ( let i = 1; i < TOTAL_LODS; i ++ ) {
  29233. const sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  29234. const poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  29235. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  29236. }
  29237. renderer.autoClear = autoClear;
  29238. },
  29239. /**
  29240. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29241. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29242. * the blur latitudinally (around the poles), and then longitudinally (towards
  29243. * the poles) to approximate the orthogonally-separable blur. It is least
  29244. * accurate at the poles, but still does a decent job.
  29245. */
  29246. _blur: function ( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  29247. const pingPongRenderTarget = this._pingPongRenderTarget;
  29248. this._halfBlur(
  29249. cubeUVRenderTarget,
  29250. pingPongRenderTarget,
  29251. lodIn,
  29252. lodOut,
  29253. sigma,
  29254. 'latitudinal',
  29255. poleAxis );
  29256. this._halfBlur(
  29257. pingPongRenderTarget,
  29258. cubeUVRenderTarget,
  29259. lodOut,
  29260. lodOut,
  29261. sigma,
  29262. 'longitudinal',
  29263. poleAxis );
  29264. },
  29265. _halfBlur: function ( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  29266. const renderer = this._renderer;
  29267. const blurMaterial = this._blurMaterial;
  29268. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  29269. console.error(
  29270. 'blur direction must be either latitudinal or longitudinal!' );
  29271. }
  29272. // Number of standard deviations at which to cut off the discrete approximation.
  29273. const STANDARD_DEVIATIONS = 3;
  29274. const blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  29275. const blurUniforms = blurMaterial.uniforms;
  29276. const pixels = _sizeLods[ lodIn ] - 1;
  29277. const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  29278. const sigmaPixels = sigmaRadians / radiansPerPixel;
  29279. const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  29280. if ( samples > MAX_SAMPLES ) {
  29281. console.warn( `sigmaRadians, ${
  29282. sigmaRadians}, is too large and will clip, as it requested ${
  29283. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  29284. }
  29285. const weights = [];
  29286. let sum = 0;
  29287. for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
  29288. const x = i / sigmaPixels;
  29289. const weight = Math.exp( - x * x / 2 );
  29290. weights.push( weight );
  29291. if ( i == 0 ) {
  29292. sum += weight;
  29293. } else if ( i < samples ) {
  29294. sum += 2 * weight;
  29295. }
  29296. }
  29297. for ( let i = 0; i < weights.length; i ++ ) {
  29298. weights[ i ] = weights[ i ] / sum;
  29299. }
  29300. blurUniforms[ 'envMap' ].value = targetIn.texture;
  29301. blurUniforms[ 'samples' ].value = samples;
  29302. blurUniforms[ 'weights' ].value = weights;
  29303. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  29304. if ( poleAxis ) {
  29305. blurUniforms[ 'poleAxis' ].value = poleAxis;
  29306. }
  29307. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  29308. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  29309. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29310. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  29311. const outputSize = _sizeLods[ lodOut ];
  29312. const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  29313. const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  29314. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  29315. renderer.setRenderTarget( targetOut );
  29316. renderer.render( blurMesh, _flatCamera );
  29317. }
  29318. };
  29319. function _isLDR( texture ) {
  29320. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  29321. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29322. }
  29323. function _createPlanes() {
  29324. const _lodPlanes = [];
  29325. const _sizeLods = [];
  29326. const _sigmas = [];
  29327. let lod = LOD_MAX;
  29328. for ( let i = 0; i < TOTAL_LODS; i ++ ) {
  29329. const sizeLod = Math.pow( 2, lod );
  29330. _sizeLods.push( sizeLod );
  29331. let sigma = 1.0 / sizeLod;
  29332. if ( i > LOD_MAX - LOD_MIN ) {
  29333. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  29334. } else if ( i == 0 ) {
  29335. sigma = 0;
  29336. }
  29337. _sigmas.push( sigma );
  29338. const texelSize = 1.0 / ( sizeLod - 1 );
  29339. const min = - texelSize / 2;
  29340. const max = 1 + texelSize / 2;
  29341. const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  29342. const cubeFaces = 6;
  29343. const vertices = 6;
  29344. const positionSize = 3;
  29345. const uvSize = 2;
  29346. const faceIndexSize = 1;
  29347. const position = new Float32Array( positionSize * vertices * cubeFaces );
  29348. const uv = new Float32Array( uvSize * vertices * cubeFaces );
  29349. const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  29350. for ( let face = 0; face < cubeFaces; face ++ ) {
  29351. const x = ( face % 3 ) * 2 / 3 - 1;
  29352. const y = face > 2 ? 0 : - 1;
  29353. const coordinates = [
  29354. x, y, 0,
  29355. x + 2 / 3, y, 0,
  29356. x + 2 / 3, y + 1, 0,
  29357. x, y, 0,
  29358. x + 2 / 3, y + 1, 0,
  29359. x, y + 1, 0
  29360. ];
  29361. position.set( coordinates, positionSize * vertices * face );
  29362. uv.set( uv1, uvSize * vertices * face );
  29363. const fill = [ face, face, face, face, face, face ];
  29364. faceIndex.set( fill, faceIndexSize * vertices * face );
  29365. }
  29366. const planes = new BufferGeometry();
  29367. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  29368. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  29369. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  29370. _lodPlanes.push( planes );
  29371. if ( lod > LOD_MIN ) {
  29372. lod --;
  29373. }
  29374. }
  29375. return { _lodPlanes, _sizeLods, _sigmas };
  29376. }
  29377. function _createRenderTarget( params ) {
  29378. const cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  29379. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29380. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29381. cubeUVRenderTarget.scissorTest = true;
  29382. return cubeUVRenderTarget;
  29383. }
  29384. function _setViewport( target, x, y, width, height ) {
  29385. target.viewport.set( x, y, width, height );
  29386. target.scissor.set( x, y, width, height );
  29387. }
  29388. function _getBlurShader( maxSamples ) {
  29389. const weights = new Float32Array( maxSamples );
  29390. const poleAxis = new Vector3( 0, 1, 0 );
  29391. const shaderMaterial = new RawShaderMaterial( {
  29392. name: 'SphericalGaussianBlur',
  29393. defines: { 'n': maxSamples },
  29394. uniforms: {
  29395. 'envMap': { value: null },
  29396. 'samples': { value: 1 },
  29397. 'weights': { value: weights },
  29398. 'latitudinal': { value: false },
  29399. 'dTheta': { value: 0 },
  29400. 'mipInt': { value: 0 },
  29401. 'poleAxis': { value: poleAxis },
  29402. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29403. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29404. },
  29405. vertexShader: _getCommonVertexShader(),
  29406. fragmentShader: `
  29407. precision mediump float;
  29408. precision mediump int;
  29409. varying vec3 vOutputDirection;
  29410. uniform sampler2D envMap;
  29411. uniform int samples;
  29412. uniform float weights[n];
  29413. uniform bool latitudinal;
  29414. uniform float dTheta;
  29415. uniform float mipInt;
  29416. uniform vec3 poleAxis;
  29417. ${_getEncodings()}
  29418. #define ENVMAP_TYPE_CUBE_UV
  29419. #include <cube_uv_reflection_fragment>
  29420. vec3 getSample(float theta, vec3 axis) {
  29421. float cosTheta = cos(theta);
  29422. // Rodrigues' axis-angle rotation
  29423. vec3 sampleDirection = vOutputDirection * cosTheta
  29424. + cross(axis, vOutputDirection) * sin(theta)
  29425. + axis * dot(axis, vOutputDirection) * (1.0 - cosTheta);
  29426. return bilinearCubeUV(envMap, sampleDirection, mipInt);
  29427. }
  29428. void main() {
  29429. vec3 axis = latitudinal ? poleAxis : cross(poleAxis, vOutputDirection);
  29430. if (all(equal(axis, vec3(0.0))))
  29431. axis = vec3(vOutputDirection.z, 0.0, - vOutputDirection.x);
  29432. axis = normalize(axis);
  29433. gl_FragColor = vec4(0.0);
  29434. gl_FragColor.rgb += weights[0] * getSample(0.0, axis);
  29435. for (int i = 1; i < n; i++) {
  29436. if (i >= samples)
  29437. break;
  29438. float theta = dTheta * float(i);
  29439. gl_FragColor.rgb += weights[i] * getSample(-1.0 * theta, axis);
  29440. gl_FragColor.rgb += weights[i] * getSample(theta, axis);
  29441. }
  29442. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29443. }
  29444. `,
  29445. blending: NoBlending,
  29446. depthTest: false,
  29447. depthWrite: false
  29448. } );
  29449. return shaderMaterial;
  29450. }
  29451. function _getEquirectShader() {
  29452. const texelSize = new Vector2( 1, 1 );
  29453. const shaderMaterial = new RawShaderMaterial( {
  29454. name: 'EquirectangularToCubeUV',
  29455. uniforms: {
  29456. 'envMap': { value: null },
  29457. 'texelSize': { value: texelSize },
  29458. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29459. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29460. },
  29461. vertexShader: _getCommonVertexShader(),
  29462. fragmentShader: `
  29463. precision mediump float;
  29464. precision mediump int;
  29465. varying vec3 vOutputDirection;
  29466. uniform sampler2D envMap;
  29467. uniform vec2 texelSize;
  29468. ${_getEncodings()}
  29469. #include <common>
  29470. void main() {
  29471. gl_FragColor = vec4(0.0);
  29472. vec3 outputDirection = normalize(vOutputDirection);
  29473. vec2 uv = equirectUv( outputDirection );
  29474. vec2 f = fract(uv / texelSize - 0.5);
  29475. uv -= f * texelSize;
  29476. vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29477. uv.x += texelSize.x;
  29478. vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29479. uv.y += texelSize.y;
  29480. vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29481. uv.x -= texelSize.x;
  29482. vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
  29483. vec3 tm = mix(tl, tr, f.x);
  29484. vec3 bm = mix(bl, br, f.x);
  29485. gl_FragColor.rgb = mix(tm, bm, f.y);
  29486. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29487. }
  29488. `,
  29489. blending: NoBlending,
  29490. depthTest: false,
  29491. depthWrite: false
  29492. } );
  29493. return shaderMaterial;
  29494. }
  29495. function _getCubemapShader() {
  29496. const shaderMaterial = new RawShaderMaterial( {
  29497. name: 'CubemapToCubeUV',
  29498. uniforms: {
  29499. 'envMap': { value: null },
  29500. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29501. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29502. },
  29503. vertexShader: _getCommonVertexShader(),
  29504. fragmentShader: `
  29505. precision mediump float;
  29506. precision mediump int;
  29507. varying vec3 vOutputDirection;
  29508. uniform samplerCube envMap;
  29509. ${_getEncodings()}
  29510. void main() {
  29511. gl_FragColor = vec4(0.0);
  29512. gl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ))).rgb;
  29513. gl_FragColor = linearToOutputTexel(gl_FragColor);
  29514. }
  29515. `,
  29516. blending: NoBlending,
  29517. depthTest: false,
  29518. depthWrite: false
  29519. } );
  29520. return shaderMaterial;
  29521. }
  29522. function _getCommonVertexShader() {
  29523. return `
  29524. precision mediump float;
  29525. precision mediump int;
  29526. attribute vec3 position;
  29527. attribute vec2 uv;
  29528. attribute float faceIndex;
  29529. varying vec3 vOutputDirection;
  29530. // RH coordinate system; PMREM face-indexing convention
  29531. vec3 getDirection(vec2 uv, float face) {
  29532. uv = 2.0 * uv - 1.0;
  29533. vec3 direction = vec3(uv, 1.0);
  29534. if (face == 0.0) {
  29535. direction = direction.zyx; // ( 1, v, u ) pos x
  29536. } else if (face == 1.0) {
  29537. direction = direction.xzy;
  29538. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  29539. } else if (face == 2.0) {
  29540. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  29541. } else if (face == 3.0) {
  29542. direction = direction.zyx;
  29543. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  29544. } else if (face == 4.0) {
  29545. direction = direction.xzy;
  29546. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  29547. } else if (face == 5.0) {
  29548. direction.z *= -1.0; // ( u, v, -1 ) neg z
  29549. }
  29550. return direction;
  29551. }
  29552. void main() {
  29553. vOutputDirection = getDirection(uv, faceIndex);
  29554. gl_Position = vec4( position, 1.0 );
  29555. }
  29556. `;
  29557. }
  29558. function _getEncodings() {
  29559. return `
  29560. uniform int inputEncoding;
  29561. uniform int outputEncoding;
  29562. #include <encodings_pars_fragment>
  29563. vec4 inputTexelToLinear(vec4 value){
  29564. if(inputEncoding == 0){
  29565. return value;
  29566. }else if(inputEncoding == 1){
  29567. return sRGBToLinear(value);
  29568. }else if(inputEncoding == 2){
  29569. return RGBEToLinear(value);
  29570. }else if(inputEncoding == 3){
  29571. return RGBMToLinear(value, 7.0);
  29572. }else if(inputEncoding == 4){
  29573. return RGBMToLinear(value, 16.0);
  29574. }else if(inputEncoding == 5){
  29575. return RGBDToLinear(value, 256.0);
  29576. }else{
  29577. return GammaToLinear(value, 2.2);
  29578. }
  29579. }
  29580. vec4 linearToOutputTexel(vec4 value){
  29581. if(outputEncoding == 0){
  29582. return value;
  29583. }else if(outputEncoding == 1){
  29584. return LinearTosRGB(value);
  29585. }else if(outputEncoding == 2){
  29586. return LinearToRGBE(value);
  29587. }else if(outputEncoding == 3){
  29588. return LinearToRGBM(value, 7.0);
  29589. }else if(outputEncoding == 4){
  29590. return LinearToRGBM(value, 16.0);
  29591. }else if(outputEncoding == 5){
  29592. return LinearToRGBD(value, 256.0);
  29593. }else{
  29594. return LinearToGamma(value, 2.2);
  29595. }
  29596. }
  29597. vec4 envMapTexelToLinear(vec4 color) {
  29598. return inputTexelToLinear(color);
  29599. }
  29600. `;
  29601. }
  29602. /**
  29603. * @author mrdoob / http://mrdoob.com/
  29604. */
  29605. function Face4( a, b, c, d, normal, color, materialIndex ) {
  29606. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  29607. return new Face3( a, b, c, normal, color, materialIndex );
  29608. }
  29609. const LineStrip = 0;
  29610. const LinePieces = 1;
  29611. const NoColors = 0;
  29612. const FaceColors = 1;
  29613. const VertexColors = 2;
  29614. function MeshFaceMaterial( materials ) {
  29615. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  29616. return materials;
  29617. }
  29618. function MultiMaterial( materials ) {
  29619. if ( materials === undefined ) materials = [];
  29620. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  29621. materials.isMultiMaterial = true;
  29622. materials.materials = materials;
  29623. materials.clone = function () {
  29624. return materials.slice();
  29625. };
  29626. return materials;
  29627. }
  29628. function PointCloud( geometry, material ) {
  29629. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  29630. return new Points( geometry, material );
  29631. }
  29632. function Particle( material ) {
  29633. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  29634. return new Sprite( material );
  29635. }
  29636. function ParticleSystem( geometry, material ) {
  29637. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  29638. return new Points( geometry, material );
  29639. }
  29640. function PointCloudMaterial( parameters ) {
  29641. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  29642. return new PointsMaterial( parameters );
  29643. }
  29644. function ParticleBasicMaterial( parameters ) {
  29645. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  29646. return new PointsMaterial( parameters );
  29647. }
  29648. function ParticleSystemMaterial( parameters ) {
  29649. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  29650. return new PointsMaterial( parameters );
  29651. }
  29652. function Vertex( x, y, z ) {
  29653. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  29654. return new Vector3( x, y, z );
  29655. }
  29656. //
  29657. function DynamicBufferAttribute( array, itemSize ) {
  29658. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  29659. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  29660. }
  29661. function Int8Attribute( array, itemSize ) {
  29662. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  29663. return new Int8BufferAttribute( array, itemSize );
  29664. }
  29665. function Uint8Attribute( array, itemSize ) {
  29666. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  29667. return new Uint8BufferAttribute( array, itemSize );
  29668. }
  29669. function Uint8ClampedAttribute( array, itemSize ) {
  29670. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  29671. return new Uint8ClampedBufferAttribute( array, itemSize );
  29672. }
  29673. function Int16Attribute( array, itemSize ) {
  29674. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  29675. return new Int16BufferAttribute( array, itemSize );
  29676. }
  29677. function Uint16Attribute( array, itemSize ) {
  29678. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  29679. return new Uint16BufferAttribute( array, itemSize );
  29680. }
  29681. function Int32Attribute( array, itemSize ) {
  29682. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  29683. return new Int32BufferAttribute( array, itemSize );
  29684. }
  29685. function Uint32Attribute( array, itemSize ) {
  29686. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  29687. return new Uint32BufferAttribute( array, itemSize );
  29688. }
  29689. function Float32Attribute( array, itemSize ) {
  29690. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  29691. return new Float32BufferAttribute( array, itemSize );
  29692. }
  29693. function Float64Attribute( array, itemSize ) {
  29694. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  29695. return new Float64BufferAttribute( array, itemSize );
  29696. }
  29697. //
  29698. Curve.create = function ( construct, getPoint ) {
  29699. console.log( 'THREE.Curve.create() has been deprecated' );
  29700. construct.prototype = Object.create( Curve.prototype );
  29701. construct.prototype.constructor = construct;
  29702. construct.prototype.getPoint = getPoint;
  29703. return construct;
  29704. };
  29705. //
  29706. Object.assign( CurvePath.prototype, {
  29707. createPointsGeometry: function ( divisions ) {
  29708. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29709. // generate geometry from path points (for Line or Points objects)
  29710. const pts = this.getPoints( divisions );
  29711. return this.createGeometry( pts );
  29712. },
  29713. createSpacedPointsGeometry: function ( divisions ) {
  29714. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29715. // generate geometry from equidistant sampling along the path
  29716. const pts = this.getSpacedPoints( divisions );
  29717. return this.createGeometry( pts );
  29718. },
  29719. createGeometry: function ( points ) {
  29720. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29721. const geometry = new Geometry();
  29722. for ( let i = 0, l = points.length; i < l; i ++ ) {
  29723. const point = points[ i ];
  29724. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  29725. }
  29726. return geometry;
  29727. }
  29728. } );
  29729. //
  29730. Object.assign( Path.prototype, {
  29731. fromPoints: function ( points ) {
  29732. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  29733. return this.setFromPoints( points );
  29734. }
  29735. } );
  29736. //
  29737. function ClosedSplineCurve3( points ) {
  29738. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29739. CatmullRomCurve3.call( this, points );
  29740. this.type = 'catmullrom';
  29741. this.closed = true;
  29742. }
  29743. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29744. //
  29745. function SplineCurve3( points ) {
  29746. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29747. CatmullRomCurve3.call( this, points );
  29748. this.type = 'catmullrom';
  29749. }
  29750. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29751. //
  29752. function Spline( points ) {
  29753. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  29754. CatmullRomCurve3.call( this, points );
  29755. this.type = 'catmullrom';
  29756. }
  29757. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  29758. Object.assign( Spline.prototype, {
  29759. initFromArray: function ( /* a */ ) {
  29760. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  29761. },
  29762. getControlPointsArray: function ( /* optionalTarget */ ) {
  29763. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  29764. },
  29765. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29766. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29767. }
  29768. } );
  29769. //
  29770. function AxisHelper( size ) {
  29771. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29772. return new AxesHelper( size );
  29773. }
  29774. function BoundingBoxHelper( object, color ) {
  29775. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29776. return new BoxHelper( object, color );
  29777. }
  29778. function EdgesHelper( object, hex ) {
  29779. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29780. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29781. }
  29782. GridHelper.prototype.setColors = function () {
  29783. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29784. };
  29785. SkeletonHelper.prototype.update = function () {
  29786. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29787. };
  29788. function WireframeHelper( object, hex ) {
  29789. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29790. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29791. }
  29792. //
  29793. Object.assign( Loader.prototype, {
  29794. extractUrlBase: function ( url ) {
  29795. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29796. return LoaderUtils.extractUrlBase( url );
  29797. }
  29798. } );
  29799. Loader.Handlers = {
  29800. add: function ( /* regex, loader */ ) {
  29801. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  29802. },
  29803. get: function ( /* file */ ) {
  29804. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  29805. }
  29806. };
  29807. function XHRLoader( manager ) {
  29808. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29809. return new FileLoader( manager );
  29810. }
  29811. function BinaryTextureLoader( manager ) {
  29812. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29813. return new DataTextureLoader( manager );
  29814. }
  29815. Object.assign( ObjectLoader.prototype, {
  29816. setTexturePath: function ( value ) {
  29817. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  29818. return this.setResourcePath( value );
  29819. }
  29820. } );
  29821. //
  29822. Object.assign( Box2.prototype, {
  29823. center: function ( optionalTarget ) {
  29824. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29825. return this.getCenter( optionalTarget );
  29826. },
  29827. empty: function () {
  29828. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29829. return this.isEmpty();
  29830. },
  29831. isIntersectionBox: function ( box ) {
  29832. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29833. return this.intersectsBox( box );
  29834. },
  29835. size: function ( optionalTarget ) {
  29836. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29837. return this.getSize( optionalTarget );
  29838. }
  29839. } );
  29840. Object.assign( Box3.prototype, {
  29841. center: function ( optionalTarget ) {
  29842. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29843. return this.getCenter( optionalTarget );
  29844. },
  29845. empty: function () {
  29846. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29847. return this.isEmpty();
  29848. },
  29849. isIntersectionBox: function ( box ) {
  29850. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29851. return this.intersectsBox( box );
  29852. },
  29853. isIntersectionSphere: function ( sphere ) {
  29854. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29855. return this.intersectsSphere( sphere );
  29856. },
  29857. size: function ( optionalTarget ) {
  29858. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29859. return this.getSize( optionalTarget );
  29860. }
  29861. } );
  29862. Object.assign( Sphere.prototype, {
  29863. empty: function () {
  29864. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  29865. return this.isEmpty();
  29866. },
  29867. } );
  29868. Frustum.prototype.setFromMatrix = function ( m ) {
  29869. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  29870. return this.setFromProjectionMatrix( m );
  29871. };
  29872. Line3.prototype.center = function ( optionalTarget ) {
  29873. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29874. return this.getCenter( optionalTarget );
  29875. };
  29876. Object.assign( MathUtils, {
  29877. random16: function () {
  29878. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29879. return Math.random();
  29880. },
  29881. nearestPowerOfTwo: function ( value ) {
  29882. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29883. return MathUtils.floorPowerOfTwo( value );
  29884. },
  29885. nextPowerOfTwo: function ( value ) {
  29886. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29887. return MathUtils.ceilPowerOfTwo( value );
  29888. }
  29889. } );
  29890. Object.assign( Matrix3.prototype, {
  29891. flattenToArrayOffset: function ( array, offset ) {
  29892. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29893. return this.toArray( array, offset );
  29894. },
  29895. multiplyVector3: function ( vector ) {
  29896. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29897. return vector.applyMatrix3( this );
  29898. },
  29899. multiplyVector3Array: function ( /* a */ ) {
  29900. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29901. },
  29902. applyToBufferAttribute: function ( attribute ) {
  29903. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  29904. return attribute.applyMatrix3( this );
  29905. },
  29906. applyToVector3Array: function ( /* array, offset, length */ ) {
  29907. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29908. }
  29909. } );
  29910. Object.assign( Matrix4.prototype, {
  29911. extractPosition: function ( m ) {
  29912. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29913. return this.copyPosition( m );
  29914. },
  29915. flattenToArrayOffset: function ( array, offset ) {
  29916. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  29917. return this.toArray( array, offset );
  29918. },
  29919. getPosition: function () {
  29920. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29921. return new Vector3().setFromMatrixColumn( this, 3 );
  29922. },
  29923. setRotationFromQuaternion: function ( q ) {
  29924. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29925. return this.makeRotationFromQuaternion( q );
  29926. },
  29927. multiplyToArray: function () {
  29928. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29929. },
  29930. multiplyVector3: function ( vector ) {
  29931. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29932. return vector.applyMatrix4( this );
  29933. },
  29934. multiplyVector4: function ( vector ) {
  29935. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29936. return vector.applyMatrix4( this );
  29937. },
  29938. multiplyVector3Array: function ( /* a */ ) {
  29939. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29940. },
  29941. rotateAxis: function ( v ) {
  29942. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29943. v.transformDirection( this );
  29944. },
  29945. crossVector: function ( vector ) {
  29946. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29947. return vector.applyMatrix4( this );
  29948. },
  29949. translate: function () {
  29950. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29951. },
  29952. rotateX: function () {
  29953. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29954. },
  29955. rotateY: function () {
  29956. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29957. },
  29958. rotateZ: function () {
  29959. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29960. },
  29961. rotateByAxis: function () {
  29962. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29963. },
  29964. applyToBufferAttribute: function ( attribute ) {
  29965. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  29966. return attribute.applyMatrix4( this );
  29967. },
  29968. applyToVector3Array: function ( /* array, offset, length */ ) {
  29969. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29970. },
  29971. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29972. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29973. return this.makePerspective( left, right, top, bottom, near, far );
  29974. }
  29975. } );
  29976. Plane.prototype.isIntersectionLine = function ( line ) {
  29977. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29978. return this.intersectsLine( line );
  29979. };
  29980. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  29981. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29982. return vector.applyQuaternion( this );
  29983. };
  29984. Object.assign( Ray.prototype, {
  29985. isIntersectionBox: function ( box ) {
  29986. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29987. return this.intersectsBox( box );
  29988. },
  29989. isIntersectionPlane: function ( plane ) {
  29990. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29991. return this.intersectsPlane( plane );
  29992. },
  29993. isIntersectionSphere: function ( sphere ) {
  29994. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29995. return this.intersectsSphere( sphere );
  29996. }
  29997. } );
  29998. Object.assign( Triangle.prototype, {
  29999. area: function () {
  30000. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  30001. return this.getArea();
  30002. },
  30003. barycoordFromPoint: function ( point, target ) {
  30004. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  30005. return this.getBarycoord( point, target );
  30006. },
  30007. midpoint: function ( target ) {
  30008. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  30009. return this.getMidpoint( target );
  30010. },
  30011. normal: function ( target ) {
  30012. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  30013. return this.getNormal( target );
  30014. },
  30015. plane: function ( target ) {
  30016. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  30017. return this.getPlane( target );
  30018. }
  30019. } );
  30020. Object.assign( Triangle, {
  30021. barycoordFromPoint: function ( point, a, b, c, target ) {
  30022. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  30023. return Triangle.getBarycoord( point, a, b, c, target );
  30024. },
  30025. normal: function ( a, b, c, target ) {
  30026. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  30027. return Triangle.getNormal( a, b, c, target );
  30028. }
  30029. } );
  30030. Object.assign( Shape.prototype, {
  30031. extractAllPoints: function ( divisions ) {
  30032. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  30033. return this.extractPoints( divisions );
  30034. },
  30035. extrude: function ( options ) {
  30036. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  30037. return new ExtrudeGeometry( this, options );
  30038. },
  30039. makeGeometry: function ( options ) {
  30040. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  30041. return new ShapeGeometry( this, options );
  30042. }
  30043. } );
  30044. Object.assign( Vector2.prototype, {
  30045. fromAttribute: function ( attribute, index, offset ) {
  30046. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  30047. return this.fromBufferAttribute( attribute, index, offset );
  30048. },
  30049. distanceToManhattan: function ( v ) {
  30050. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  30051. return this.manhattanDistanceTo( v );
  30052. },
  30053. lengthManhattan: function () {
  30054. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  30055. return this.manhattanLength();
  30056. }
  30057. } );
  30058. Object.assign( Vector3.prototype, {
  30059. setEulerFromRotationMatrix: function () {
  30060. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  30061. },
  30062. setEulerFromQuaternion: function () {
  30063. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  30064. },
  30065. getPositionFromMatrix: function ( m ) {
  30066. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  30067. return this.setFromMatrixPosition( m );
  30068. },
  30069. getScaleFromMatrix: function ( m ) {
  30070. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  30071. return this.setFromMatrixScale( m );
  30072. },
  30073. getColumnFromMatrix: function ( index, matrix ) {
  30074. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  30075. return this.setFromMatrixColumn( matrix, index );
  30076. },
  30077. applyProjection: function ( m ) {
  30078. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  30079. return this.applyMatrix4( m );
  30080. },
  30081. fromAttribute: function ( attribute, index, offset ) {
  30082. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  30083. return this.fromBufferAttribute( attribute, index, offset );
  30084. },
  30085. distanceToManhattan: function ( v ) {
  30086. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  30087. return this.manhattanDistanceTo( v );
  30088. },
  30089. lengthManhattan: function () {
  30090. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  30091. return this.manhattanLength();
  30092. }
  30093. } );
  30094. Object.assign( Vector4.prototype, {
  30095. fromAttribute: function ( attribute, index, offset ) {
  30096. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  30097. return this.fromBufferAttribute( attribute, index, offset );
  30098. },
  30099. lengthManhattan: function () {
  30100. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  30101. return this.manhattanLength();
  30102. }
  30103. } );
  30104. //
  30105. Object.assign( Geometry.prototype, {
  30106. computeTangents: function () {
  30107. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  30108. },
  30109. computeLineDistances: function () {
  30110. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  30111. },
  30112. applyMatrix: function ( matrix ) {
  30113. console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  30114. return this.applyMatrix4( matrix );
  30115. }
  30116. } );
  30117. Object.assign( Object3D.prototype, {
  30118. getChildByName: function ( name ) {
  30119. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  30120. return this.getObjectByName( name );
  30121. },
  30122. renderDepth: function () {
  30123. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  30124. },
  30125. translate: function ( distance, axis ) {
  30126. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  30127. return this.translateOnAxis( axis, distance );
  30128. },
  30129. getWorldRotation: function () {
  30130. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  30131. },
  30132. applyMatrix: function ( matrix ) {
  30133. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  30134. return this.applyMatrix4( matrix );
  30135. }
  30136. } );
  30137. Object.defineProperties( Object3D.prototype, {
  30138. eulerOrder: {
  30139. get: function () {
  30140. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  30141. return this.rotation.order;
  30142. },
  30143. set: function ( value ) {
  30144. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  30145. this.rotation.order = value;
  30146. }
  30147. },
  30148. useQuaternion: {
  30149. get: function () {
  30150. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  30151. },
  30152. set: function () {
  30153. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  30154. }
  30155. }
  30156. } );
  30157. Object.assign( Mesh.prototype, {
  30158. setDrawMode: function () {
  30159. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  30160. },
  30161. } );
  30162. Object.defineProperties( Mesh.prototype, {
  30163. drawMode: {
  30164. get: function () {
  30165. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  30166. return TrianglesDrawMode;
  30167. },
  30168. set: function () {
  30169. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  30170. }
  30171. }
  30172. } );
  30173. Object.defineProperties( LOD.prototype, {
  30174. objects: {
  30175. get: function () {
  30176. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  30177. return this.levels;
  30178. }
  30179. }
  30180. } );
  30181. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  30182. get: function () {
  30183. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  30184. },
  30185. set: function () {
  30186. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  30187. }
  30188. } );
  30189. SkinnedMesh.prototype.initBones = function () {
  30190. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  30191. };
  30192. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  30193. get: function () {
  30194. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  30195. return this.arcLengthDivisions;
  30196. },
  30197. set: function ( value ) {
  30198. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  30199. this.arcLengthDivisions = value;
  30200. }
  30201. } );
  30202. //
  30203. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  30204. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  30205. "Use .setFocalLength and .filmGauge for a photographic setup." );
  30206. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  30207. this.setFocalLength( focalLength );
  30208. };
  30209. //
  30210. Object.defineProperties( Light.prototype, {
  30211. onlyShadow: {
  30212. set: function () {
  30213. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  30214. }
  30215. },
  30216. shadowCameraFov: {
  30217. set: function ( value ) {
  30218. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  30219. this.shadow.camera.fov = value;
  30220. }
  30221. },
  30222. shadowCameraLeft: {
  30223. set: function ( value ) {
  30224. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  30225. this.shadow.camera.left = value;
  30226. }
  30227. },
  30228. shadowCameraRight: {
  30229. set: function ( value ) {
  30230. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  30231. this.shadow.camera.right = value;
  30232. }
  30233. },
  30234. shadowCameraTop: {
  30235. set: function ( value ) {
  30236. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  30237. this.shadow.camera.top = value;
  30238. }
  30239. },
  30240. shadowCameraBottom: {
  30241. set: function ( value ) {
  30242. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  30243. this.shadow.camera.bottom = value;
  30244. }
  30245. },
  30246. shadowCameraNear: {
  30247. set: function ( value ) {
  30248. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  30249. this.shadow.camera.near = value;
  30250. }
  30251. },
  30252. shadowCameraFar: {
  30253. set: function ( value ) {
  30254. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  30255. this.shadow.camera.far = value;
  30256. }
  30257. },
  30258. shadowCameraVisible: {
  30259. set: function () {
  30260. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  30261. }
  30262. },
  30263. shadowBias: {
  30264. set: function ( value ) {
  30265. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  30266. this.shadow.bias = value;
  30267. }
  30268. },
  30269. shadowDarkness: {
  30270. set: function () {
  30271. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  30272. }
  30273. },
  30274. shadowMapWidth: {
  30275. set: function ( value ) {
  30276. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  30277. this.shadow.mapSize.width = value;
  30278. }
  30279. },
  30280. shadowMapHeight: {
  30281. set: function ( value ) {
  30282. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  30283. this.shadow.mapSize.height = value;
  30284. }
  30285. }
  30286. } );
  30287. //
  30288. Object.defineProperties( BufferAttribute.prototype, {
  30289. length: {
  30290. get: function () {
  30291. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  30292. return this.array.length;
  30293. }
  30294. },
  30295. dynamic: {
  30296. get: function () {
  30297. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30298. return this.usage === DynamicDrawUsage;
  30299. },
  30300. set: function ( /* value */ ) {
  30301. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  30302. this.setUsage( DynamicDrawUsage );
  30303. }
  30304. }
  30305. } );
  30306. Object.assign( BufferAttribute.prototype, {
  30307. setDynamic: function ( value ) {
  30308. console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30309. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30310. return this;
  30311. },
  30312. copyIndicesArray: function ( /* indices */ ) {
  30313. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  30314. },
  30315. setArray: function ( /* array */ ) {
  30316. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30317. }
  30318. } );
  30319. Object.assign( BufferGeometry.prototype, {
  30320. addIndex: function ( index ) {
  30321. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  30322. this.setIndex( index );
  30323. },
  30324. addAttribute: function ( name, attribute ) {
  30325. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  30326. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  30327. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  30328. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  30329. }
  30330. if ( name === 'index' ) {
  30331. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  30332. this.setIndex( attribute );
  30333. return this;
  30334. }
  30335. return this.setAttribute( name, attribute );
  30336. },
  30337. addDrawCall: function ( start, count, indexOffset ) {
  30338. if ( indexOffset !== undefined ) {
  30339. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  30340. }
  30341. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  30342. this.addGroup( start, count );
  30343. },
  30344. clearDrawCalls: function () {
  30345. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  30346. this.clearGroups();
  30347. },
  30348. computeTangents: function () {
  30349. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  30350. },
  30351. computeOffsets: function () {
  30352. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  30353. },
  30354. removeAttribute: function ( name ) {
  30355. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  30356. return this.deleteAttribute( name );
  30357. },
  30358. applyMatrix: function ( matrix ) {
  30359. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  30360. return this.applyMatrix4( matrix );
  30361. }
  30362. } );
  30363. Object.defineProperties( BufferGeometry.prototype, {
  30364. drawcalls: {
  30365. get: function () {
  30366. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  30367. return this.groups;
  30368. }
  30369. },
  30370. offsets: {
  30371. get: function () {
  30372. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  30373. return this.groups;
  30374. }
  30375. }
  30376. } );
  30377. Object.defineProperties( InstancedBufferGeometry.prototype, {
  30378. maxInstancedCount: {
  30379. get: function () {
  30380. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30381. return this.instanceCount;
  30382. },
  30383. set: function ( value ) {
  30384. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30385. this.instanceCount = value;
  30386. }
  30387. }
  30388. } );
  30389. Object.defineProperties( Raycaster.prototype, {
  30390. linePrecision: {
  30391. get: function () {
  30392. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30393. return this.params.Line.threshold;
  30394. },
  30395. set: function ( value ) {
  30396. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30397. this.params.Line.threshold = value;
  30398. }
  30399. }
  30400. } );
  30401. Object.defineProperties( InterleavedBuffer.prototype, {
  30402. dynamic: {
  30403. get: function () {
  30404. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30405. return this.usage === DynamicDrawUsage;
  30406. },
  30407. set: function ( value ) {
  30408. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30409. this.setUsage( value );
  30410. }
  30411. }
  30412. } );
  30413. Object.assign( InterleavedBuffer.prototype, {
  30414. setDynamic: function ( value ) {
  30415. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30416. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30417. return this;
  30418. },
  30419. setArray: function ( /* array */ ) {
  30420. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30421. }
  30422. } );
  30423. //
  30424. Object.assign( ExtrudeBufferGeometry.prototype, {
  30425. getArrays: function () {
  30426. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  30427. },
  30428. addShapeList: function () {
  30429. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  30430. },
  30431. addShape: function () {
  30432. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  30433. }
  30434. } );
  30435. //
  30436. Object.defineProperties( Uniform.prototype, {
  30437. dynamic: {
  30438. set: function () {
  30439. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  30440. }
  30441. },
  30442. onUpdate: {
  30443. value: function () {
  30444. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  30445. return this;
  30446. }
  30447. }
  30448. } );
  30449. //
  30450. Object.defineProperties( Material.prototype, {
  30451. wrapAround: {
  30452. get: function () {
  30453. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30454. },
  30455. set: function () {
  30456. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30457. }
  30458. },
  30459. overdraw: {
  30460. get: function () {
  30461. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30462. },
  30463. set: function () {
  30464. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30465. }
  30466. },
  30467. wrapRGB: {
  30468. get: function () {
  30469. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  30470. return new Color();
  30471. }
  30472. },
  30473. shading: {
  30474. get: function () {
  30475. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30476. },
  30477. set: function ( value ) {
  30478. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30479. this.flatShading = ( value === FlatShading );
  30480. }
  30481. },
  30482. stencilMask: {
  30483. get: function () {
  30484. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30485. return this.stencilFuncMask;
  30486. },
  30487. set: function ( value ) {
  30488. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30489. this.stencilFuncMask = value;
  30490. }
  30491. }
  30492. } );
  30493. Object.defineProperties( MeshPhongMaterial.prototype, {
  30494. metal: {
  30495. get: function () {
  30496. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  30497. return false;
  30498. },
  30499. set: function () {
  30500. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  30501. }
  30502. }
  30503. } );
  30504. Object.defineProperties( ShaderMaterial.prototype, {
  30505. derivatives: {
  30506. get: function () {
  30507. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30508. return this.extensions.derivatives;
  30509. },
  30510. set: function ( value ) {
  30511. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30512. this.extensions.derivatives = value;
  30513. }
  30514. }
  30515. } );
  30516. //
  30517. Object.assign( WebGLRenderer.prototype, {
  30518. clearTarget: function ( renderTarget, color, depth, stencil ) {
  30519. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  30520. this.setRenderTarget( renderTarget );
  30521. this.clear( color, depth, stencil );
  30522. },
  30523. animate: function ( callback ) {
  30524. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  30525. this.setAnimationLoop( callback );
  30526. },
  30527. getCurrentRenderTarget: function () {
  30528. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  30529. return this.getRenderTarget();
  30530. },
  30531. getMaxAnisotropy: function () {
  30532. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  30533. return this.capabilities.getMaxAnisotropy();
  30534. },
  30535. getPrecision: function () {
  30536. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  30537. return this.capabilities.precision;
  30538. },
  30539. resetGLState: function () {
  30540. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  30541. return this.state.reset();
  30542. },
  30543. supportsFloatTextures: function () {
  30544. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  30545. return this.extensions.get( 'OES_texture_float' );
  30546. },
  30547. supportsHalfFloatTextures: function () {
  30548. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  30549. return this.extensions.get( 'OES_texture_half_float' );
  30550. },
  30551. supportsStandardDerivatives: function () {
  30552. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  30553. return this.extensions.get( 'OES_standard_derivatives' );
  30554. },
  30555. supportsCompressedTextureS3TC: function () {
  30556. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  30557. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  30558. },
  30559. supportsCompressedTexturePVRTC: function () {
  30560. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  30561. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  30562. },
  30563. supportsBlendMinMax: function () {
  30564. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  30565. return this.extensions.get( 'EXT_blend_minmax' );
  30566. },
  30567. supportsVertexTextures: function () {
  30568. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  30569. return this.capabilities.vertexTextures;
  30570. },
  30571. supportsInstancedArrays: function () {
  30572. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  30573. return this.extensions.get( 'ANGLE_instanced_arrays' );
  30574. },
  30575. enableScissorTest: function ( boolean ) {
  30576. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  30577. this.setScissorTest( boolean );
  30578. },
  30579. initMaterial: function () {
  30580. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  30581. },
  30582. addPrePlugin: function () {
  30583. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  30584. },
  30585. addPostPlugin: function () {
  30586. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  30587. },
  30588. updateShadowMap: function () {
  30589. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  30590. },
  30591. setFaceCulling: function () {
  30592. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  30593. },
  30594. allocTextureUnit: function () {
  30595. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  30596. },
  30597. setTexture: function () {
  30598. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  30599. },
  30600. setTexture2D: function () {
  30601. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  30602. },
  30603. setTextureCube: function () {
  30604. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  30605. },
  30606. getActiveMipMapLevel: function () {
  30607. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  30608. return this.getActiveMipmapLevel();
  30609. }
  30610. } );
  30611. Object.defineProperties( WebGLRenderer.prototype, {
  30612. shadowMapEnabled: {
  30613. get: function () {
  30614. return this.shadowMap.enabled;
  30615. },
  30616. set: function ( value ) {
  30617. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  30618. this.shadowMap.enabled = value;
  30619. }
  30620. },
  30621. shadowMapType: {
  30622. get: function () {
  30623. return this.shadowMap.type;
  30624. },
  30625. set: function ( value ) {
  30626. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  30627. this.shadowMap.type = value;
  30628. }
  30629. },
  30630. shadowMapCullFace: {
  30631. get: function () {
  30632. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30633. return undefined;
  30634. },
  30635. set: function ( /* value */ ) {
  30636. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30637. }
  30638. },
  30639. context: {
  30640. get: function () {
  30641. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  30642. return this.getContext();
  30643. }
  30644. },
  30645. vr: {
  30646. get: function () {
  30647. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  30648. return this.xr;
  30649. }
  30650. },
  30651. gammaInput: {
  30652. get: function () {
  30653. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30654. return false;
  30655. },
  30656. set: function () {
  30657. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30658. }
  30659. },
  30660. gammaOutput: {
  30661. get: function () {
  30662. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30663. return false;
  30664. },
  30665. set: function ( value ) {
  30666. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30667. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  30668. }
  30669. },
  30670. toneMappingWhitePoint: {
  30671. get: function () {
  30672. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30673. return 1.0;
  30674. },
  30675. set: function () {
  30676. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30677. }
  30678. },
  30679. } );
  30680. Object.defineProperties( WebGLShadowMap.prototype, {
  30681. cullFace: {
  30682. get: function () {
  30683. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30684. return undefined;
  30685. },
  30686. set: function ( /* cullFace */ ) {
  30687. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30688. }
  30689. },
  30690. renderReverseSided: {
  30691. get: function () {
  30692. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30693. return undefined;
  30694. },
  30695. set: function () {
  30696. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30697. }
  30698. },
  30699. renderSingleSided: {
  30700. get: function () {
  30701. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30702. return undefined;
  30703. },
  30704. set: function () {
  30705. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30706. }
  30707. }
  30708. } );
  30709. function WebGLRenderTargetCube( width, height, options ) {
  30710. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  30711. return new WebGLCubeRenderTarget( width, options );
  30712. }
  30713. //
  30714. Object.defineProperties( WebGLRenderTarget.prototype, {
  30715. wrapS: {
  30716. get: function () {
  30717. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30718. return this.texture.wrapS;
  30719. },
  30720. set: function ( value ) {
  30721. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30722. this.texture.wrapS = value;
  30723. }
  30724. },
  30725. wrapT: {
  30726. get: function () {
  30727. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30728. return this.texture.wrapT;
  30729. },
  30730. set: function ( value ) {
  30731. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30732. this.texture.wrapT = value;
  30733. }
  30734. },
  30735. magFilter: {
  30736. get: function () {
  30737. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30738. return this.texture.magFilter;
  30739. },
  30740. set: function ( value ) {
  30741. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30742. this.texture.magFilter = value;
  30743. }
  30744. },
  30745. minFilter: {
  30746. get: function () {
  30747. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30748. return this.texture.minFilter;
  30749. },
  30750. set: function ( value ) {
  30751. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30752. this.texture.minFilter = value;
  30753. }
  30754. },
  30755. anisotropy: {
  30756. get: function () {
  30757. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30758. return this.texture.anisotropy;
  30759. },
  30760. set: function ( value ) {
  30761. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30762. this.texture.anisotropy = value;
  30763. }
  30764. },
  30765. offset: {
  30766. get: function () {
  30767. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30768. return this.texture.offset;
  30769. },
  30770. set: function ( value ) {
  30771. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30772. this.texture.offset = value;
  30773. }
  30774. },
  30775. repeat: {
  30776. get: function () {
  30777. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30778. return this.texture.repeat;
  30779. },
  30780. set: function ( value ) {
  30781. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30782. this.texture.repeat = value;
  30783. }
  30784. },
  30785. format: {
  30786. get: function () {
  30787. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30788. return this.texture.format;
  30789. },
  30790. set: function ( value ) {
  30791. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30792. this.texture.format = value;
  30793. }
  30794. },
  30795. type: {
  30796. get: function () {
  30797. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30798. return this.texture.type;
  30799. },
  30800. set: function ( value ) {
  30801. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30802. this.texture.type = value;
  30803. }
  30804. },
  30805. generateMipmaps: {
  30806. get: function () {
  30807. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30808. return this.texture.generateMipmaps;
  30809. },
  30810. set: function ( value ) {
  30811. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30812. this.texture.generateMipmaps = value;
  30813. }
  30814. }
  30815. } );
  30816. //
  30817. Object.defineProperties( Audio.prototype, {
  30818. load: {
  30819. value: function ( file ) {
  30820. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30821. const scope = this;
  30822. const audioLoader = new AudioLoader();
  30823. audioLoader.load( file, function ( buffer ) {
  30824. scope.setBuffer( buffer );
  30825. } );
  30826. return this;
  30827. }
  30828. },
  30829. startTime: {
  30830. set: function () {
  30831. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  30832. }
  30833. }
  30834. } );
  30835. AudioAnalyser.prototype.getData = function () {
  30836. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30837. return this.getFrequencyData();
  30838. };
  30839. //
  30840. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30841. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30842. return this.update( renderer, scene );
  30843. };
  30844. //
  30845. const GeometryUtils = {
  30846. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30847. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30848. let matrix;
  30849. if ( geometry2.isMesh ) {
  30850. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30851. matrix = geometry2.matrix;
  30852. geometry2 = geometry2.geometry;
  30853. }
  30854. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30855. },
  30856. center: function ( geometry ) {
  30857. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30858. return geometry.center();
  30859. }
  30860. };
  30861. ImageUtils.crossOrigin = undefined;
  30862. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30863. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30864. const loader = new TextureLoader();
  30865. loader.setCrossOrigin( this.crossOrigin );
  30866. const texture = loader.load( url, onLoad, undefined, onError );
  30867. if ( mapping ) texture.mapping = mapping;
  30868. return texture;
  30869. };
  30870. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30871. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30872. const loader = new CubeTextureLoader();
  30873. loader.setCrossOrigin( this.crossOrigin );
  30874. const texture = loader.load( urls, onLoad, undefined, onError );
  30875. if ( mapping ) texture.mapping = mapping;
  30876. return texture;
  30877. };
  30878. ImageUtils.loadCompressedTexture = function () {
  30879. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30880. };
  30881. ImageUtils.loadCompressedTextureCube = function () {
  30882. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30883. };
  30884. //
  30885. function CanvasRenderer() {
  30886. console.error( 'THREE.CanvasRenderer has been removed' );
  30887. }
  30888. //
  30889. function JSONLoader() {
  30890. console.error( 'THREE.JSONLoader has been removed.' );
  30891. }
  30892. //
  30893. const SceneUtils = {
  30894. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30895. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30896. },
  30897. detach: function ( /* child, parent, scene */ ) {
  30898. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30899. },
  30900. attach: function ( /* child, scene, parent */ ) {
  30901. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30902. }
  30903. };
  30904. //
  30905. function LensFlare() {
  30906. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  30907. }
  30908. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  30909. /* eslint-disable no-undef */
  30910. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  30911. revision: REVISION,
  30912. } } ) );
  30913. /* eslint-enable no-undef */
  30914. }
  30915. 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, BoxBufferGeometry, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasRenderer, CanvasTexture, CatmullRomCurve3, CineonToneMapping, CircleBufferGeometry, CircleGeometry, ClampToEdgeWrapping, Clock, ClosedSplineCurve3, Color, ColorKeyframeTrack, CompressedTexture, CompressedTextureLoader, ConeBufferGeometry, ConeGeometry, CubeCamera, BoxGeometry as CubeGeometry, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubeUVRefractionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderBufferGeometry, CylinderGeometry, Cylindrical, DataTexture, DataTexture2DArray, DataTexture3D, DataTextureLoader, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightHelper, DirectionalLightShadow, DiscreteInterpolant, DodecahedronBufferGeometry, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicBufferAttribute, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EdgesHelper, EllipseCurve, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeBufferGeometry, ExtrudeGeometry, Face3, Face4, FaceColors, FileLoader, FlatShading, Float32Attribute, Float32BufferAttribute, Float64Attribute, Float64BufferAttribute, FloatType, Fog, FogExp2, Font, FontLoader, FrontFaceDirectionCCW, FrontFaceDirectionCW, FrontSide, Frustum, GammaEncoding, Geometry, GeometryUtils, GreaterDepth, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, HemisphereLightProbe, 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, LatheBufferGeometry, LatheGeometry, Layers, LensFlare, LessDepth, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, LightShadow, 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, OctahedronBufferGeometry, OctahedronGeometry, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, ParametricBufferGeometry, ParametricGeometry, Particle, ParticleBasicMaterial, ParticleSystem, ParticleSystemMaterial, Path, PerspectiveCamera, Plane, PlaneBufferGeometry, PlaneGeometry, PlaneHelper, PointCloud, PointCloudMaterial, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, 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, 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, ShapeBufferGeometry, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, SmoothShading, Sphere, SphereBufferGeometry, SphereGeometry, Spherical, SphericalHarmonics3, Spline, SplineCurve, SplineCurve3, SpotLight, SpotLightHelper, SpotLightShadow, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronBufferGeometry, TetrahedronGeometry, TextBufferGeometry, TextGeometry, Texture, TextureLoader, TorusBufferGeometry, TorusGeometry, TorusKnotBufferGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, 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 };